Skip to content

Commit

Permalink
added option to choose multiple fields for editing
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron T. Maturen committed May 24, 2012
1 parent 091b1bc commit e2c2b41
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 38 deletions.
4 changes: 3 additions & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
$inline_keywords_background_colour = 'hotPink';
$inline_keywords_use_jQuery_ui = True;
$inline_keywords_use_legacy_jQuery = True;
$inline_keywords_clear_fields_on_submit = True;
$inline_keywords_clear_fields_on_submit = True;
$inline_keywords_sticky_panel = True;
$inline_keywords_editable_fields = Array('Keywords');
44 changes: 30 additions & 14 deletions hooks/search.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
function HookInline_keywordsSearchSearchbarbottomtoolbar()
{
global $lang, $inline_keywords_usertype;
global $lang, $inline_keywords_usertype, $inline_keywords_editable_fields;
if(checkperm($inline_keywords_usertype))
{
?>
Expand All @@ -12,14 +12,17 @@ function HookInline_keywordsSearchSearchbarbottomtoolbar()

<form id="manipulateKeywords">
<span class="wrap">
<p>
<label for='newKeywordsForSelectedResources'>Keywords</label>
<input id='newKeywordsForSelectedResources' class='SearchWidth'/>
</p>
<p>
<label for='newNamedPersonsForSelectedResources'>Named Persons</label>
<input id='newNamedPersonsForSelectedResources' class='SearchWidth'/>
</p>
<?php
foreach($inline_keywords_editable_fields as $field)
{
$label_result = sql_query("select title from resource_type_field where ref = '$field'");
$label = ($label_result[0]['title']);

echo "<p>";
echo "<label for='ref_$field'>$label</label>";
echo "<input id='ref_$field' name='ref_$field' class='SearchWidth'/>";
echo "</p>";
} ?>
</span>
<input type="button" id="selectAllResourceButton" value="<?php echo $lang["selectall"]; ?>">
<input type="button" id="clearSelectedResourceButton" value="<?php echo $lang["unselectall"]; ?>">
Expand All @@ -32,19 +35,31 @@ function HookInline_keywordsSearchSearchbarbottomtoolbar()
}
function HookInline_keywordsSearchAdditionalheaderjs()
{
global $baseurl, $inline_keywords_usertype, $inline_keywords_background_colour, $inline_keywords_clear_fields_on_submit;
global $baseurl, $inline_keywords_usertype, $inline_keywords_background_colour, $inline_keywords_clear_fields_on_submit, $inline_keywords_sticky_panel;
if(checkperm($inline_keywords_usertype))
{ ?>
<script src="../plugins/inline_keywords/js/jquery.infieldlabel.min.js" type="text/javascript" charset="utf-8"></script>
<script type='text/javascript'>
jQuery(document).ready(function() {
jQuery('form#manipulateKeywords label').each(function(){
if(jQuery(this.siblings(':text')).val('aaaa')!==""){
if(jQuery(this.siblings(':text')).val()!==""){
this.hide();
}
});
<?php if($inline_keywords_sticky_panel)
{ ?>
var panelTop = jQuery('.keywordPanel').eq(0).offset().top;

jQuery(window).scroll(function(){
if(jQuery(window).scrollTop() > (panelTop - 20)){
jQuery('.keywordPanel').css({'position':'fixed','top':'20px'});
}else{
jQuery('.keywordPanel').css({'position':'static','top':'20px'});
}
});
<?php
} ?>

jQuery('form#manipulateKeywords :text').focus(function(event){
jQuery('form#manipulateKeywords :text').focus(function(event){
jQuery(this).siblings('label').fadeOut('fast');
});

Expand Down Expand Up @@ -77,13 +92,14 @@ function HookInline_keywordsSearchAdditionalheaderjs()
});

jQuery('#submitSelectedResourceButton').on('click', function() {
var form_values = jQuery('form#manipulateKeywords').serialize();
resourceIds = jQuery.map(jQuery('.chosen'), function(a, b){
return jQuery(a).attr('id').replace('ResourceShell','');
}).join('+');
jQuery.ajax({
type: "POST",
url: "<?php echo $baseurl; ?>/plugins/inline_keywords/pages/add_keywords.php",
data: { refs: resourceIds, keywords: jQuery('#newKeywordsForSelectedResources').val().replace(/ /g,'+') }
data: 'refs=' + resourceIds + '&' + form_values
}).done(function( msg ) {
if(msg !== ''){alert( "Data Saved: " + msg );}
//jQuery(".keywordPanel").effect("highlight", {}, 3000);
Expand Down
2 changes: 1 addition & 1 deletion inline_keywords.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: inline_keywords
author: Aaron T. Maturen
version: 0.6
desc: Enable Adding Keywords on Search Result Page
desc: Enable Editing Fields on Search Result Page
info_url: https://github.com/aaronmaturen/rs_inline_keywords
config_url: /plugins/inline_keywords/pages/setup.php
default_priority: 999
3 changes: 2 additions & 1 deletion languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

$lang['selectall'] = 'Select All';
$lang['unselectall'] = 'Unselect All';
$lang['editfields'] = 'Edit Field(s)';
$lang['editfields'] = 'Update Resource';
$lang['submitchanges'] = 'Submit Changes';
$lang['keywordstoresource'] = 'Change fields on selected resources.';
$lang['inline_keywords_clear_fields_on_submit'] = "Clear fields after submitting.";
$lang['inline_keywords_sticky_panel'] = "Should edit panel stay on the screen while scrolling?";

$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 ' .
Expand Down
57 changes: 36 additions & 21 deletions pages/add_keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,41 @@
include_once "../../../include/general.php";
include_once "../../../include/resource_functions.php";

$fields = sql_query("select ref from resource_type_field where title = 'Keywords'");
$type = ($fields[0]['ref']);
$refs = explode(' ',str_replace('+',' ',$_POST['refs']));
unset($_POST['refs']);

$keywords = explode(',',str_replace('+',' ',$_REQUEST['keywords']));
$refs = explode(' ',str_replace('+',' ',$_REQUEST['refs']));
foreach($refs as $ref)
{
foreach($keywords as $keyword){
add_keyword_mappings($ref, $keyword,$type);
}
$inline_keyword_data = sql_query("SELECT * FROM resource_data WHERE resource_type_field = '$type' AND resource = '$ref'");
if($inline_keyword_data)
{
$keywordstring = implode(', ',array_unique(array_merge($keywords, explode(', ',$inline_keyword_data[0]['value']))));
sql_query("UPDATE resource_data SET value = '$keywordstring' WHERE resource_type_field = '$type' AND resource = '$ref'");
}
else
{
$keywordstring = implode(' ',$keywords);
sql_query("INSERT INTO resource_data(resource, resource_type_field, value) VALUES($ref, $type, '$keywordstring')");
}
}
//$fields = sql_query("select ref from resource_type_field where title = 'Keywords'");
//$type = ($fields[0]['ref']);

foreach($_POST as $request => $values)
{
$formdata = explode('_', $request);

if($formdata[0] == 'ref')
{
$type = $formdata[1];
if($values != "")
{
$keywords = explode(',',$values);
foreach($refs as $ref)
{
foreach($keywords as $keyword)
{
add_keyword_mappings($ref, $keyword,$type);
}
$inline_keyword_data = sql_query("SELECT * FROM resource_data WHERE resource_type_field = '$type' AND resource = '$ref'");
if($inline_keyword_data)
{
$keywordstring = implode(', ',array_unique(array_merge($keywords, explode(', ',$inline_keyword_data[0]['value']))));
sql_query("UPDATE resource_data SET value = '$keywordstring' WHERE resource_type_field = '$type' AND resource = '$ref'");
}
else
{
$keywordstring = implode(' ',$keywords);
sql_query("INSERT INTO resource_data(resource, resource_type_field, value) VALUES($ref, $type, '$keywordstring')");
}
}
}
}
}
?>
4 changes: 4 additions & 0 deletions pages/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
$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_clear_fields_on_submit',$lang['inline_keywords_clear_fields_on_submit'], $lang['no-yes']);
$page_def[] = config_add_boolean_select('inline_keywords_sticky_panel',$lang['inline_keywords_sticky_panel'], $lang['no-yes']);

$page_def[] = config_add_multi_ftype_select('inline_keywords_editable_fields', 'label');

// Do the page generation ritual
$upload_status = config_gen_setup_post($page_def, $plugin_name);
include '../../../include/header.php';
Expand Down

0 comments on commit e2c2b41

Please sign in to comment.