Skip to content

Commit

Permalink
added user config page
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmaturen committed May 20, 2012
1 parent d9f3867 commit e88b1c9
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 22 deletions.
18 changes: 18 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
#
# Configuration file for ResourceSpace plugin "Sample"
#
# These are the default values. They can be overridden by using /plugins/sample/pages/setup.php
# which is invoked by choosing Team Centre > Manage Plugins and then clicking on Options for the
# sample plugin once it has been activated.

# $sample_pets_owned = array(2); // Indices to the list of pets type giving types owned
// 0=Cat, 1=Bird, 2=Dog, 3=Fish, 4=Horse, 5=Lizard, 6=Monkey
# $sample_favorite_pet_type = 2; // Index in the list of pet types giving type of favorite pet
# $sample_favorite_pet_name = ""; // Typed in text giving the name of the favorite pet
# $sample_favorite_pet_living = -1; // Boolean specifying whether favorite pet is alive or not

$inline_keywords_usertype = 'a';
$inline_keywords_background_colour = 'hotPink';
$inline_keywords_use_jQuery_ui = True;
$inline_keywords_use_legacy_jQuery = True;
49 changes: 29 additions & 20 deletions hooks/search.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
<?php
function HookInline_keywordsSearchSearchbarbottomtoolbar()
{
global $lang;
?>
<div id="SearchBoxPanel" class="keywordPanel">
<div class="SearchSpace">
<h2><?php echo $lang["addkeywords"]; ?></h2>
<p><?php echo $lang['keywordstoresource']; ?></p>
global $lang, $inline_keywords_usertype;
if(checkperm($inline_keywords_usertype))
{
?>
<div id="SearchBoxPanel" class="keywordPanel">
<div class="SearchSpace">
<h2><?php echo $lang["addkeywords"]; ?></h2>
<p><?php echo $lang['keywordstoresource']; ?></p>

<form id="manipulateKeywords">
<input id="newKeywordsForSelectedResources" class="SearchWidth"/>
<input type="button" id="selectAllResourceButton" value="<?php echo $lang["selectall"]; ?>">
<input type="button" id="clearSelectedResourceButton" value="<?php echo $lang["unselectall"]; ?>">
<input type="button" id="submitSelectedResourceButton" value="<?php echo $lang["addkeywords"]; ?>">
</form>
</div>
</div>
<?php
<form id="manipulateKeywords">
<input id="newKeywordsForSelectedResources" class="SearchWidth"/>
<input type="button" id="selectAllResourceButton" value="<?php echo $lang["selectall"]; ?>">
<input type="button" id="clearSelectedResourceButton" value="<?php echo $lang["unselectall"]; ?>">
<input type="button" id="submitSelectedResourceButton" value="<?php echo $lang["addkeywords"]; ?>">
</form>
</div>
</div>
<?php
}
}
function HookInline_keywordsSearchAdditionalheaderjs()
{
global $baseurl;
if(checkperm('a'))
global $baseurl, $inline_keywords_usertype, $inline_keywords_background_colour;
if(checkperm($inline_keywords_usertype))
{ ?>
<script type='text/javascript'>
jQuery(document).ready(function() {
jQuery('.ResourcePanelShell, .ResourcePanelShellSmall').on('click', function() {
jQuery(this).toggleClass('chosen');
jQuery('.ResourcePanel, .ResourcePanelSmall').css('border-color','');
jQuery('.chosen .ResourcePanel, .chosen .ResourcePanelSmall').css('border-color','<?php echo $inline_keywords_background_colour; ?>');
});

jQuery('.ResourcePanelShell, .ResourcePanelShellSmall').on('click','a',function(event){event.stopPropagation();});

jQuery('#clearSelectedResourceButton').on('click', function() {
jQuery('.chosen').removeClass('chosen');
jQuery('#newKeywordsForSelectedResources').val('');
jQuery('.chosen').removeClass('chosen');
jQuery('#newKeywordsForSelectedResources').val('');
jQuery('.ResourcePanel, .ResourcePanelSmall').css('border-color','');
jQuery('.chosen .ResourcePanel, .chosen .ResourcePanelSmall').css('border-color','<?php echo $inline_keywords_background_colour; ?>');
});

jQuery('#selectAllResourceButton').on('click', function() {
jQuery('.ResourcePanelShell, .ResourcePanelShellSmall').addClass('chosen');
jQuery('.ResourcePanel, .ResourcePanelSmall').css('border-color','');
jQuery('.chosen .ResourcePanel, .chosen .ResourcePanelSmall').css('border-color','<?php echo $inline_keywords_background_colour; ?>');
});

jQuery('#submitSelectedResourceButton').on('click', function() {
Expand All @@ -46,7 +55,7 @@ function HookInline_keywordsSearchAdditionalheaderjs()
}).join('+');
jQuery.ajax({
type: "POST",
url: "<?php echo $baseurl; ?>/plugins/simple_keywords/pages/add_keywords.php",
url: "<?php echo $baseurl; ?>/plugins/inline_keywords/pages/add_keywords.php",
data: { refs: resourceIds, keywords: jQuery('#newKeywordsForSelectedResources').val().replace(/ /g,'+') }
}).done(function( msg ) {
if(msg !== ''){alert( "Data Saved: " + msg );}
Expand Down
Binary file removed inline_keywords.rsp
Binary file not shown.
2 changes: 1 addition & 1 deletion inline_keywords.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ author: Aaron T. Maturen
version: 0.1
desc: Enable Adding Keywords on Search Result Page
info_url: https://github.com/aaronmaturen/rs_inline_keywords
config_url: /plugins/simple_keywords/pages/setup.php
config_url: /plugins/inline_keywords/pages/setup.php
default_priority: 999
19 changes: 19 additions & 0 deletions languages/en.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
<?php
#
# English Language File for the sample plugin
#

$lang['selectall'] = 'Select All';
$lang['unselectall'] = 'Unselect All';
$lang['addkeywords'] = 'Add Keyword(s)';
$lang['keywordstoresource'] = 'Add keyword(s) to selected resources.';

$lang['inline_keywords_heading'] = 'Inline Keywords Plugin Configuration';
$lang['inline_keywords_frontm']='This is a sample configuration page for a plugin. It doesn\'t actually modify ' .
'the behavior of RS since it has no hooks, but it does show how to build a simple plugin setup page. ' .
'Using this page you can set the values of the configuration variables. To do so, make the ' .
'desired adjustments and click \'Save Configuration\'.';

$lang['inline_keywords_usertype'] = 'Type of user that should have access to this:';
$lang['inline_keywords_background_colour'] = 'What colour should the border of selected resource(s) be:';
$lang['inline_keywords_use_jQuery_ui'] = 'Should jQuery UI be used for notifications:';
$lang['inline_keywords_use_legacy_jQuery'] = 'Should legacy jQuery functions be used for versions of jQuery less than 1.7.x :';


$lang['no-yes'] = array('No', 'Yes');

?>
2 changes: 1 addition & 1 deletion pages/add_keywords.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

include_once "../../../include/db.php";
include_once "../../../include/authenticate.php";if (!checkperm("a")) {exit("Permission denied");}
include_once "../../../include/authenticate.php";if (!checkperm(checkperm($inline_keywords_usertype))) {exit("Permission denied");}
include_once "../../../include/general.php";
include_once "../../../include/resource_functions.php";

Expand Down
53 changes: 53 additions & 0 deletions pages/setup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
#
# Setup page for the sample plugin
#
# This page can be displayed by choosing Team Centre > Manage Plugins and clicking on Options
# for the sample plugin after it has been activated. It is used to override the default values
# of the plugin's configuration variables.
#
# In addition to this sample, there's also a template in the same directory as this file. You
# may find it an easier starting point for writing a setup page for your own plugin.
#

// Do the include and authorization checking ritual
include '../../../include/db.php';
include '../../../include/authenticate.php'; if (!checkperm('a')) {exit ($lang['error-permissiondenied']);}
include '../../../include/general.php';

// Specify the name of this plugin, the heading to display for the page and the
// optional introductory text.
$plugin_name = 'inline_keywords';
$page_heading = $lang['inline_keywords_heading'];
$page_intro = '<p>' . $lang['inline_keywords_frontm'] . '</p>';

// Build the $page_def array of descriptions of each configuration variable the sample uses.
// Each element of $page_def describes one configuration variable. Each description is
// created by one of the config_add_xxxx helper functions. See their definitions and
// descriptions in include/plugin_functions for more information.
//
// The sample plugin has four configuration variables:
//
// 1) $inline_keywords_pets_owned is a string array variable whose values are drawn from
// the indices of the array $lang['inline_keywords_pet_type_list']. For the UI the textual
// description for this variable is in $lang['inline_keywords_pets_owned']. We use
// config_add_multi_select() because we want a multi-select UI for this variable.
// 2) $inline_keywords_favorite_pet_type is a string variable whose value is drawn from the indices
// of the array $lang['inline_keywords_pet_type_list']. Its UI description is in
// $lang['inline_keywords_favorite_pet_type']. We want a single-select UI.
// 3) $inline_keywords_favorite_pet_name is a string variable whose value is typed by the user.
// The description for the UI is in $lang['inline_keywords_favorite_pet_name']
// 4) $inline_keywords_favorite_pet_living is a boolean variable. Normally the UI for a boolean
// displays the choices "False" and "True" (in the local language) but here we
// specify we want it to show "No" and "Yes" (in the local language).

$page_def[] = config_add_text_input('inline_keywords_usertype', $lang['inline_keywords_usertype'] );
$page_def[] = config_add_text_input('inline_keywords_background_colour', $lang['inline_keywords_background_colour']);
$page_def[] = config_add_boolean_select('inline_keywords_use_legacy_jQuery',$lang['inline_keywords_use_jQuery_ui'], $lang['no-yes']);
$page_def[] = config_add_boolean_select('inline_keywords_use_jQuery_ui',$lang['inline_keywords_use_jQuery_ui'], $lang['no-yes']);

// Do the page generation ritual
$upload_status = config_gen_setup_post($page_def, $plugin_name);
include '../../../include/header.php';
config_gen_setup_html($page_def, $plugin_name, $upload_status, $page_heading, $page_intro);
include '../../../include/footer.php';
32 changes: 32 additions & 0 deletions pages/setup.template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
#
# Setup page template
#
# You can 'crib' from this code to easily create a setup.php file for a new plugin.
#

// Do the include and authorization checking ritual -- don't change this section.
include '../../../include/db.php';
include '../../../include/authenticate.php'; if (!checkperm('a')) {exit ($lang['error-permissiondenied']);}
include '../../../include/general.php';

// Specify the name of this plugin, the heading to display for the page and the
// optional introductory text. Set $page_intro to "" for no intro text
// Change to match your plugin.
$plugin_name = 'plugin_name_goes_here'; // Usually a string literal
$page_heading = $lang['plugin_name_plugin_heading_goes_here']; // Usually a $lang[] string
$page_intro = '<p>html_content_goes_here</p>'; // Usually either a $lang[] string or ''

// Build the $page_def array of descriptions of each configuration variable the plugin uses.
// Each element of $page_def describes one configuration variable. Each description is
// created by one of the config_add_xxxx helper functions. See their definitions and
// descriptions in include/plugin_functions for more information.

$page_def[] = config_add_xxxx(...);
$page_def[] = config_add_yyyy(....);
...
// Do the page generation ritual -- don't change this section.
$upload_status = config_gen_setup_post($page_def, $plugin_name);
include '../../../include/header.php';
config_gen_setup_html($page_def, $plugin_name, $upload_status, $page_heading, $page_intro);
include '../../../include/footer.php';

0 comments on commit e88b1c9

Please sign in to comment.