[geeklog-hg] geeklog: Added jQuery to Topic Control so inherited and default ...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Fri Jul 5 23:25:02 EDT 2013


changeset 9167:97a355431797
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/97a355431797
user: Tom <websitemaster at cogeco.net>
date: Fri Jul 05 23:24:45 2013 -0400
description:
Added jQuery to Topic Control so inherited and default select boxes auto fill when topic selections are done.

diffstat:

 public_html/javascript/topic_control.js                            |  77 ++++++++++
 public_html/layout/denim/admin/common/edit_topics.thtml            |  25 +-
 public_html/layout/modern_curve/admin/common/edit_topics.thtml     |  20 +-
 public_html/layout/professional/admin/common/edit_topics.thtml     |  38 ++--
 public_html/layout/professional_css/admin/common/edit_topics.thtml |  25 +-
 system/lib-topic.php                                               |   5 +-
 6 files changed, 136 insertions(+), 54 deletions(-)

diffs (295 lines):

diff -r b568b60e6f2c -r 97a355431797 public_html/javascript/topic_control.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/public_html/javascript/topic_control.js	Fri Jul 05 23:24:45 2013 -0400
@@ -0,0 +1,77 @@
+// jQuery handles adding what is selected/unselected in tid[] and adds it selected to (or deletes from) inherit_tid[] as well as default_tid (not selected)
+// This only happens if these 2 select boxes are visible
+
+// On all radio selected, clear selection of tids
+$('#topic_option_all').change( function () {
+    // Clear all selections
+    $('select#tid option').attr('selected',false);
+});
+// On homeonly radio option selected, clear selection of tids
+$('#topic_option_homeonly').change( function () {
+    // Clear all selections
+    $('select#tid option').attr('selected',false);
+});
+        
+
+$('#tid').change( function () {
+    
+    if($("#panel_radio_options").is(':visible')) {
+        // On selecting a tid make sure selecttopics radio option is selected
+        $('#topic_option_selectedtopics').attr('checked',true);
+        $('#topic_option_all').attr('checked',false);
+        $('#topic_option_homeonly').attr('checked',false);        
+    } else {
+        // *********************************************
+        // Inherited tids Multi-Selection Box
+        // Get all selected tids and the not selected inherited
+        var options_inherited = $('select#tid option:selected').sort().clone();
+        var options_inherited_not_selected = $('select#inherit_tid option:not(:selected)').sort().clone();
+        
+        // Cleanup tids and trim spaces and select everything
+        $(options_inherited).each(function(){
+            $(this).text($.trim($(this).text()));
+            $(this).attr('selected', true);
+        });
+       
+        // Now add in inherited
+        $('select#inherit_tid').empty();
+        $('select#inherit_tid').append(options_inherited);
+        $('select#inherit_tid').sortSelect();
+        
+        // Now deselect anything that has been before
+        $(options_inherited_not_selected).each(function(){
+                $("#inherit_tid option[value='"+$(this).val()+"']").attr("selected",false);
+        });    
+    
+    
+        // *********************************************
+        // Default tid Selection Box
+        // Figure out Default tid. Grab all selected tids
+        var options_default = $('select#tid option:selected').sort().clone();
+        // Grab previous selection
+        var option_default_tid = $('select#default_tid option:selected').sort().clone();
+        
+        // Trim spaces and find which one was selected before if it still exists and select it again
+        $(options_default).each(function(){
+            $(this).text($.trim($(this).text()));
+        });    
+        
+        $('select#default_tid').empty();
+        $('select#default_tid').append(options_default);
+         $('select#default_tid').sortSelect();
+        
+        // Clear all selections
+        $('select#default_tid option').attr('selected',false);
+        // Set Selection as before if still exist
+        $('#default_tid').val($(option_default_tid).val());
+    }
+});
+
+// Sorting function for Select
+$.fn.sortSelect = function() {
+    var op = this.children("option");
+    op.sort(function(a, b) {
+        return a.text.toLowerCase() > b.text.toLowerCase() ? 1 : -1;
+    })
+    return this.empty().append(op);
+}
diff -r b568b60e6f2c -r 97a355431797 public_html/layout/denim/admin/common/edit_topics.thtml
--- a/public_html/layout/denim/admin/common/edit_topics.thtml	Thu Jul 04 15:19:09 2013 -0400
+++ b/public_html/layout/denim/admin/common/edit_topics.thtml	Fri Jul 05 23:24:45 2013 -0400
@@ -1,28 +1,27 @@
+{# begin {templatelocation} #}
 
-<!-- admin/common/edit_topics.thtml { -->
-
-<div style="vertical-align:top;display:inline-block;{options_hide}">
+<div id="panel_radio_options" style="vertical-align:top;display:inline-block;{options_hide}">
     <input type="hidden" name="topic_options_hide" value="{topic_options_hide}"{xhtml}>
-    <input type="radio" name="topic_option" value="all" {all_checked}{xhtml}> {lang_all}
-    <input type="radio" name="topic_option" value="homeonly" {homeonly_checked}{xhtml}> {lang_homeonly}
-    <span style="{topic_option_hide}"><input type="radio" name="topic_option" value="selectedtopics" {selectedtopics_checked}{xhtml}></span>
+    <input type="radio" name="topic_option" value="all" id="topic_option_all" {all_checked}{xhtml}> {lang_all}
+    <input type="radio" name="topic_option" value="homeonly" id="topic_option_homeonly" {homeonly_checked}{xhtml}> {lang_homeonly}
+    <span style="{topic_option_hide}"><input type="radio" name="topic_option" id="topic_option_selectedtopics" value="selectedtopics" {selectedtopics_checked}{xhtml}></span>
 </div>
-<div style="vertical-align:top;display:inline-block;{topic_hide}">
-    <select name="tid[]" multiple="multiple" class="multiple" size="4">
+<div id="panel_topic_options" style="vertical-align:top;display:inline-block;{topic_hide}">
+    <select name="tid[]" multiple="multiple" class="multiple" size="4" id="tid">
         {topic_options}
     </select>
 </div>
-<div style="vertical-align:top;display:inline-block;{inherit_hide}">
+<div id="panel_inherit_options" style="vertical-align:top;display:inline-block;{inherit_hide}">
     <input type="hidden" name="topic_inherit_hide" value="{topic_inherit_hide}"{xhtml}>
     <span style="vertical-align:top;">{lang_inherit}:</span>
-    <select name="inherit_tid[]" multiple="multiple" class="multiple" size="4">
+    <select name="inherit_tid[]" multiple="multiple" class="multiple" size="4" id="inherit_tid">
         {inherit_options}
     </select>
 </div>
-<div style="vertical-align:top;display:inline-block;{default_hide}">
+<div id="panel_default_options" style="vertical-align:top;display:inline-block;{default_hide}">
     <input type="hidden" name="topic_default_hide" value="{topic_default_hide}"{xhtml}>
     <span style="vertical-align:top;">{lang_default}:</span>
-    <select name="default_tid">
+    <select name="default_tid" id="default_tid">
         {default_options}
     </select>
 </div>
@@ -30,4 +29,4 @@
     <p>{topic_info}</p>
 </div>
 
-<!-- } admin/common/edit_topics.thtml -->
+{# end {templatelocation} #}
diff -r b568b60e6f2c -r 97a355431797 public_html/layout/modern_curve/admin/common/edit_topics.thtml
--- a/public_html/layout/modern_curve/admin/common/edit_topics.thtml	Thu Jul 04 15:19:09 2013 -0400
+++ b/public_html/layout/modern_curve/admin/common/edit_topics.thtml	Fri Jul 05 23:24:45 2013 -0400
@@ -1,27 +1,27 @@
 {# begin {templatelocation} #}
 
-<div style="vertical-align:top;display:inline-block;{options_hide}">
+<div id="panel_radio_options" style="vertical-align:top;display:inline-block;{options_hide}">
     <input type="hidden" name="topic_options_hide" value="{topic_options_hide}"{xhtml}>
-    <input type="radio" name="topic_option" value="all" {all_checked}{xhtml}> {lang_all}
-    <input type="radio" name="topic_option" value="homeonly" {homeonly_checked}{xhtml}> {lang_homeonly}
-    <span style="{topic_option_hide}"><input type="radio" name="topic_option" value="selectedtopics" {selectedtopics_checked}{xhtml}></span>
+    <input type="radio" name="topic_option" value="all" id="topic_option_all" {all_checked}{xhtml}> {lang_all}
+    <input type="radio" name="topic_option" value="homeonly" id="topic_option_homeonly" {homeonly_checked}{xhtml}> {lang_homeonly}
+    <span style="{topic_option_hide}"><input type="radio" name="topic_option" id="topic_option_selectedtopics" value="selectedtopics" {selectedtopics_checked}{xhtml}></span>
 </div>
-<div style="vertical-align:top;display:inline-block;{topic_hide}">
-    <select name="tid[]" multiple="multiple" class="multiple" size="4">
+<div id="panel_topic_options" style="vertical-align:top;display:inline-block;{topic_hide}">
+    <select name="tid[]" multiple="multiple" class="multiple" size="4" id="tid">
         {topic_options}
     </select>
 </div>
-<div style="vertical-align:top;display:inline-block;{inherit_hide}">
+<div id="panel_inherit_options" style="vertical-align:top;display:inline-block;{inherit_hide}">
     <input type="hidden" name="topic_inherit_hide" value="{topic_inherit_hide}"{xhtml}>
     <span style="vertical-align:top;">{lang_inherit}:</span>
-    <select name="inherit_tid[]" multiple="multiple" class="multiple" size="4">
+    <select name="inherit_tid[]" multiple="multiple" class="multiple" size="4" id="inherit_tid">
         {inherit_options}
     </select>
 </div>
-<div style="vertical-align:top;display:inline-block;{default_hide}">
+<div id="panel_default_options" style="vertical-align:top;display:inline-block;{default_hide}">
     <input type="hidden" name="topic_default_hide" value="{topic_default_hide}"{xhtml}>
     <span style="vertical-align:top;">{lang_default}:</span>
-    <select name="default_tid">
+    <select name="default_tid" id="default_tid">
         {default_options}
     </select>
 </div>
diff -r b568b60e6f2c -r 97a355431797 public_html/layout/professional/admin/common/edit_topics.thtml
--- a/public_html/layout/professional/admin/common/edit_topics.thtml	Thu Jul 04 15:19:09 2013 -0400
+++ b/public_html/layout/professional/admin/common/edit_topics.thtml	Fri Jul 05 23:24:45 2013 -0400
@@ -1,28 +1,32 @@
-<span style="vertical-align:top;{options_hide}">                 
+{# begin {templatelocation} #}
+
+<div id="panel_radio_options" style="vertical-align:top;display:inline-block;{options_hide}">
     <input type="hidden" name="topic_options_hide" value="{topic_options_hide}"{xhtml}>
-    <input type="radio" name="topic_option" value="all" {all_checked}> {lang_all} 
-    <input type="radio" name="topic_option" value="homeonly" {homeonly_checked}> {lang_homeonly}
-    <span style="{topic_option_hide}"><input type="radio" name="topic_option" value="selectedtopics" {selectedtopics_checked}></span> 
-</span>
-<span style="vertical-align:top;{topic_hide}">
-    <select name="tid[]" multiple="multiple" size="4">
+    <input type="radio" name="topic_option" value="all" id="topic_option_all" {all_checked}{xhtml}> {lang_all}
+    <input type="radio" name="topic_option" value="homeonly" id="topic_option_homeonly" {homeonly_checked}{xhtml}> {lang_homeonly}
+    <span style="{topic_option_hide}"><input type="radio" name="topic_option" id="topic_option_selectedtopics" value="selectedtopics" {selectedtopics_checked}{xhtml}></span>
+</div>
+<div id="panel_topic_options" style="vertical-align:top;display:inline-block;{topic_hide}">
+    <select name="tid[]" multiple="multiple" class="multiple" size="4" id="tid">
         {topic_options}
     </select>
-</span>
-<span style="vertical-align:top;{inherit_hide}">
+</div>
+<div id="panel_inherit_options" style="vertical-align:top;display:inline-block;{inherit_hide}">
     <input type="hidden" name="topic_inherit_hide" value="{topic_inherit_hide}"{xhtml}>
     <span style="vertical-align:top;">{lang_inherit}:</span>
-    <select name="inherit_tid[]" multiple="multiple" size="4">
+    <select name="inherit_tid[]" multiple="multiple" class="multiple" size="4" id="inherit_tid">
         {inherit_options}
     </select>
-</span>
-<span style="vertical-align:top;{default_hide}">
+</div>
+<div id="panel_default_options" style="vertical-align:top;display:inline-block;{default_hide}">
     <input type="hidden" name="topic_default_hide" value="{topic_default_hide}"{xhtml}>
-    {lang_default}:
-    <select name="default_tid">
+    <span style="vertical-align:top;">{lang_default}:</span>
+    <select name="default_tid" id="default_tid">
         {default_options}
     </select>
-</span>
-<span style="{info_hide}">
+</div>
+<div style="{info_hide}">
     <p>{topic_info}</p>
-</span>
+</div>
+
+{# end {templatelocation} #}
diff -r b568b60e6f2c -r 97a355431797 public_html/layout/professional_css/admin/common/edit_topics.thtml
--- a/public_html/layout/professional_css/admin/common/edit_topics.thtml	Thu Jul 04 15:19:09 2013 -0400
+++ b/public_html/layout/professional_css/admin/common/edit_topics.thtml	Fri Jul 05 23:24:45 2013 -0400
@@ -1,28 +1,27 @@
+{# begin {templatelocation} #}
 
-<!-- admin/common/edit_topics.thtml { -->
-
-<div style="vertical-align:top;display:inline-block;{options_hide}">
+<div id="panel_radio_options" style="vertical-align:top;display:inline-block;{options_hide}">
     <input type="hidden" name="topic_options_hide" value="{topic_options_hide}"{xhtml}>
-    <input type="radio" name="topic_option" value="all" {all_checked}{xhtml}> {lang_all}
-    <input type="radio" name="topic_option" value="homeonly" {homeonly_checked}{xhtml}> {lang_homeonly}
-    <span style="{topic_option_hide}"><input type="radio" name="topic_option" value="selectedtopics" {selectedtopics_checked}{xhtml}></span>
+    <input type="radio" name="topic_option" value="all" id="topic_option_all" {all_checked}{xhtml}> {lang_all}
+    <input type="radio" name="topic_option" value="homeonly" id="topic_option_homeonly" {homeonly_checked}{xhtml}> {lang_homeonly}
+    <span style="{topic_option_hide}"><input type="radio" name="topic_option" id="topic_option_selectedtopics" value="selectedtopics" {selectedtopics_checked}{xhtml}></span>
 </div>
-<div style="vertical-align:top;display:inline-block;{topic_hide}">
-    <select name="tid[]" multiple="multiple" class="multiple" size="4">
+<div id="panel_topic_options" style="vertical-align:top;display:inline-block;{topic_hide}">
+    <select name="tid[]" multiple="multiple" class="multiple" size="4" id="tid">
         {topic_options}
     </select>
 </div>
-<div style="vertical-align:top;display:inline-block;{inherit_hide}">
+<div id="panel_inherit_options" style="vertical-align:top;display:inline-block;{inherit_hide}">
     <input type="hidden" name="topic_inherit_hide" value="{topic_inherit_hide}"{xhtml}>
     <span style="vertical-align:top;">{lang_inherit}:</span>
-    <select name="inherit_tid[]" multiple="multiple" class="multiple" size="4">
+    <select name="inherit_tid[]" multiple="multiple" class="multiple" size="4" id="inherit_tid">
         {inherit_options}
     </select>
 </div>
-<div style="vertical-align:top;display:inline-block;{default_hide}">
+<div id="panel_default_options" style="vertical-align:top;display:inline-block;{default_hide}">
     <input type="hidden" name="topic_default_hide" value="{topic_default_hide}"{xhtml}>
     <span style="vertical-align:top;">{lang_default}:</span>
-    <select name="default_tid">
+    <select name="default_tid" id="default_tid">
         {default_options}
     </select>
 </div>
@@ -30,4 +29,4 @@
     <p>{topic_info}</p>
 </div>
 
-<!-- } admin/common/edit_topics.thtml -->
+{# end {templatelocation} #}
diff -r b568b60e6f2c -r 97a355431797 system/lib-topic.php
--- a/system/lib-topic.php	Thu Jul 04 15:19:09 2013 -0400
+++ b/system/lib-topic.php	Fri Jul 05 23:24:45 2013 -0400
@@ -833,7 +833,7 @@
 */
 function TOPIC_getTopicSelectionControl($type, $id, $show_options = false, $show_inherit = false, $show_default = false)
 {
-    global $_CONF, $LANG27, $_TABLES, $topic;
+    global $_CONF, $LANG27, $_TABLES, $topic, $_SCRIPTS;
     
     $tids = array();
     $inherit_tids = array();
@@ -910,6 +910,9 @@
     $topic_templates = COM_newTemplate($_CONF['path_layout'] . 'admin/common');
     $topic_templates->set_file(array('editor' => 'edit_topics.thtml'));
     
+    $_SCRIPTS->setJavaScriptLibrary('jquery');
+    $_SCRIPTS->setJavascriptFile('topic_control', '/javascript/topic_control.js');
+    
     $topiclist = TOPIC_getTopicListSelect($tids, false);
     if ($topiclist == '') { // Topics do not exist
         $topic_templates->set_var('topic_option_hide', 'display: none;');



More information about the geeklog-cvs mailing list