From f50a1f434d2384c041e11070aba54b1e552fa85d Mon Sep 17 00:00:00 2001 From: secretr Date: Sat, 29 Nov 2008 17:35:38 +0000 Subject: [PATCH] JS changes to fit the needs of userclass groups (added new response action ElementInvokeById) --- e107_admin/userclass2.php | 30 +++++++++++++++++++++-------- e107_files/jslib/e107.js.php | 32 +++++++++++++++++++++++++------ e107_handlers/userclass_class.php | 10 +++++----- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/e107_admin/userclass2.php b/e107_admin/userclass2.php index 8e62bd26a..b0826937b 100644 --- a/e107_admin/userclass2.php +++ b/e107_admin/userclass2.php @@ -11,9 +11,9 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/userclass2.php,v $ -| $Revision: 1.14 $ -| $Date: 2008-11-27 22:07:30 $ -| $Author: e107steved $ +| $Revision: 1.15 $ +| $Date: 2008-11-29 17:35:38 $ +| $Author: secretr $ +----------------------------------------------------------------------------+ */ @@ -92,9 +92,24 @@ if(e_AJAX_REQUEST) } $sql->db_Select('userclass_classes', '*', "userclass_id='".$class_num."' "); $row = $sql->db_Fetch(MYSQL_ASSOC); - if ($row['userclass_type'] != UC_TYPE_GROUP) - { -// $row['group_classes_select'] = array_flip(explode(',',$row['userclass_accum'])); // Need to do something to fill in the classes array + + //Response action - reset all group checkboxes + $jshelper->addResponseAction('reset-checked', array('group_classes_select' => '0')); + + //it's grouped userclass + if ($row['userclass_type'] == UC_TYPE_GROUP) + { + //Response action - show group, hide standard + $jshelper->addResponseAction('element-invoke-by-id', array('show' => 'userclass_type_groups', 'hide' => 'userclass_type_standard')); + + //fill in the classes array + $tmp = explode(',',$row['userclass_accum']); + foreach ($tmp as $uid) { + $row['group_classes_select_'.$uid] = $uid; + } + } else { + //hide group, show standard rows + $jshelper->addResponseAction('element-invoke-by-id', array('hide' => 'userclass_type_groups', 'show' => 'userclass_type_standard')); } unset($row['userclass_accum']); $row['createclass'] = UCSLAN_14; //update the submit button value @@ -102,7 +117,7 @@ if(e_AJAX_REQUEST) //icon $row['iconview'] = $row['userclass_icon'] ? e_IMAGE_ABS.'userclasses/'.$row['userclass_icon'] : e_IMAGE_ABS."generic/blank.gif"; $row["uc_icon_select"] = $row['userclass_icon']; //icons select box - + //Send the prefered response type //echo $jshelper->sendJSONResponse('fill-form', $row); echo $jshelper->sendXMLResponse('fill-form', $row); @@ -1022,7 +1037,6 @@ function headerjs() \$('updatecancel').show(); //If link is clicked use it's href as a target - $('classForm').fillForm($(document.body), { handler: target.readAttribute('href') }); } })); diff --git a/e107_files/jslib/e107.js.php b/e107_files/jslib/e107.js.php index 1102df962..bc238a809 100644 --- a/e107_files/jslib/e107.js.php +++ b/e107_files/jslib/e107.js.php @@ -8,8 +8,8 @@ * e107 Javascript API * * $Source: /cvs_backup/e107_0.8/e107_files/jslib/e107.js.php,v $ - * $Revision: 1.9 $ - * $Date: 2008-11-23 12:21:49 $ + * $Revision: 1.10 $ + * $Date: 2008-11-29 17:35:38 $ * $Author: secretr $ * */ @@ -2264,12 +2264,34 @@ var e107AjaxAbstract = Class.create ({ var checked = parseInt(response[key]) ? true : false; $$('input[name^=' + key + ']').each( function(felement) { var itype = String(felement.type); - if('checkbox radio'.include(itype.toLowerCase())) + if(itype && 'checkbox radio'.include(itype.toLowerCase())) felement.checked = checked; }); }.bind(this)); }, + /** + * Invoke methods on element or element collections by id + * + * Examples: + * {'show': 'id1,id2,id3'} -> show elements with id id1,id2 and id3 + * {'writeAttribute,rel,external': 'id1,id2,id3'} -> invoke writeAttribute('rel', 'external') on elements with id id1,id2 and id3 + */ + _processResponseElementInvokeById: function(response) { + //response.key is comma separated list representing method -> args to be invoked on every element + Object.keys(response).each(function(key) { + var tmp = $A(key.split(',')), + method = tmp[0], + args = tmp.slice(1); + //response.value is comma separated element id list + $A(response[key].split(',')).each( function(el) { + el = $(el.strip()); + if(el) + el[method].apply(el, args) + }); + }); + }, + /** * Update element by type */ @@ -2277,12 +2299,10 @@ var e107AjaxAbstract = Class.create ({ el = $(el); if(!el) return; var type = el.nodeName.toLowerCase(), itype = el.type; if(type == 'input' || type == 'textarea') { - //FIXME checkbox, radio if(itype) itype = itype.toLowerCase(); - switch (itype) { case 'checkbox': - case 'radio': + case 'radio': el.checked = (el.value == data); break; default: diff --git a/e107_handlers/userclass_class.php b/e107_handlers/userclass_class.php index 87a9b1405..a94fc0874 100644 --- a/e107_handlers/userclass_class.php +++ b/e107_handlers/userclass_class.php @@ -11,9 +11,9 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_handlers/userclass_class.php,v $ -| $Revision: 1.19 $ -| $Date: 2008-11-27 22:07:30 $ -| $Author: e107steved $ +| $Revision: 1.20 $ +| $Date: 2008-11-29 17:35:38 $ +| $Author: secretr $ +----------------------------------------------------------------------------+ */ @@ -482,7 +482,7 @@ class user_class // $style = " style='text-indent:".(12*$nest_level)."px'"; $style = " style='text-indent:".(1.2*$nest_level)."em'"; } - return "
".$this->class_tree[$classnum]['userclass_name']."
\n"; + return "
".$this->class_tree[$classnum]['userclass_name']."
\n"; } @@ -500,7 +500,7 @@ class user_class { $style = " style='text-indent:".(1.2*$nest_level)."em'"; } - return "
".$this->class_tree[$classnum]['userclass_name'].' ('.$this->class_tree[$classnum]['userclass_description'].")
\n"; + return "
".$this->class_tree[$classnum]['userclass_name'].' ('.$this->class_tree[$classnum]['userclass_description'].")
\n"; }