1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 09:29:45 +01:00

JS changes to fit the needs of userclass groups (added new response action ElementInvokeById)

This commit is contained in:
secretr 2008-11-29 17:35:38 +00:00
parent 364f49090c
commit f50a1f434d
3 changed files with 53 additions and 19 deletions

View File

@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_admin/userclass2.php,v $ | $Source: /cvs_backup/e107_0.8/e107_admin/userclass2.php,v $
| $Revision: 1.14 $ | $Revision: 1.15 $
| $Date: 2008-11-27 22:07:30 $ | $Date: 2008-11-29 17:35:38 $
| $Author: e107steved $ | $Author: secretr $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@ -92,9 +92,24 @@ if(e_AJAX_REQUEST)
} }
$sql->db_Select('userclass_classes', '*', "userclass_id='".$class_num."' "); $sql->db_Select('userclass_classes', '*', "userclass_id='".$class_num."' ");
$row = $sql->db_Fetch(MYSQL_ASSOC); $row = $sql->db_Fetch(MYSQL_ASSOC);
if ($row['userclass_type'] != UC_TYPE_GROUP)
{ //Response action - reset all group checkboxes
// $row['group_classes_select'] = array_flip(explode(',',$row['userclass_accum'])); // Need to do something to fill in the classes array $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']); unset($row['userclass_accum']);
$row['createclass'] = UCSLAN_14; //update the submit button value $row['createclass'] = UCSLAN_14; //update the submit button value
@ -102,7 +117,7 @@ if(e_AJAX_REQUEST)
//icon //icon
$row['iconview'] = $row['userclass_icon'] ? e_IMAGE_ABS.'userclasses/'.$row['userclass_icon'] : e_IMAGE_ABS."generic/blank.gif"; $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 $row["uc_icon_select"] = $row['userclass_icon']; //icons select box
//Send the prefered response type //Send the prefered response type
//echo $jshelper->sendJSONResponse('fill-form', $row); //echo $jshelper->sendJSONResponse('fill-form', $row);
echo $jshelper->sendXMLResponse('fill-form', $row); echo $jshelper->sendXMLResponse('fill-form', $row);
@ -1022,7 +1037,6 @@ function headerjs()
\$('updatecancel').show(); \$('updatecancel').show();
//If link is clicked use it's href as a target //If link is clicked use it's href as a target
$('classForm').fillForm($(document.body), { handler: target.readAttribute('href') }); $('classForm').fillForm($(document.body), { handler: target.readAttribute('href') });
} }
})); }));

View File

@ -8,8 +8,8 @@
* e107 Javascript API * e107 Javascript API
* *
* $Source: /cvs_backup/e107_0.8/e107_files/jslib/e107.js.php,v $ * $Source: /cvs_backup/e107_0.8/e107_files/jslib/e107.js.php,v $
* $Revision: 1.9 $ * $Revision: 1.10 $
* $Date: 2008-11-23 12:21:49 $ * $Date: 2008-11-29 17:35:38 $
* $Author: secretr $ * $Author: secretr $
* *
*/ */
@ -2264,12 +2264,34 @@ var e107AjaxAbstract = Class.create ({
var checked = parseInt(response[key]) ? true : false; var checked = parseInt(response[key]) ? true : false;
$$('input[name^=' + key + ']').each( function(felement) { $$('input[name^=' + key + ']').each( function(felement) {
var itype = String(felement.type); var itype = String(felement.type);
if('checkbox radio'.include(itype.toLowerCase())) if(itype && 'checkbox radio'.include(itype.toLowerCase()))
felement.checked = checked; felement.checked = checked;
}); });
}.bind(this)); }.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 * Update element by type
*/ */
@ -2277,12 +2299,10 @@ var e107AjaxAbstract = Class.create ({
el = $(el); if(!el) return; el = $(el); if(!el) return;
var type = el.nodeName.toLowerCase(), itype = el.type; var type = el.nodeName.toLowerCase(), itype = el.type;
if(type == 'input' || type == 'textarea') { if(type == 'input' || type == 'textarea') {
//FIXME checkbox, radio
if(itype) itype = itype.toLowerCase(); if(itype) itype = itype.toLowerCase();
switch (itype) { switch (itype) {
case 'checkbox': case 'checkbox':
case 'radio': case 'radio':
el.checked = (el.value == data); el.checked = (el.value == data);
break; break;
default: default:

View File

@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_handlers/userclass_class.php,v $ | $Source: /cvs_backup/e107_0.8/e107_handlers/userclass_class.php,v $
| $Revision: 1.19 $ | $Revision: 1.20 $
| $Date: 2008-11-27 22:07:30 $ | $Date: 2008-11-29 17:35:38 $
| $Author: e107steved $ | $Author: secretr $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@ -482,7 +482,7 @@ class user_class
// $style = " style='text-indent:".(12*$nest_level)."px'"; // $style = " style='text-indent:".(12*$nest_level)."px'";
$style = " style='text-indent:".(1.2*$nest_level)."em'"; $style = " style='text-indent:".(1.2*$nest_level)."em'";
} }
return "<div {$style}><input type='checkbox' name='{$treename}[]' value='{$classnum}'{$chk} />".$this->class_tree[$classnum]['userclass_name']."</div>\n"; return "<div {$style}><input type='checkbox' name='{$treename}[]' id='{$treename}_{$classnum}' value='{$classnum}'{$chk} />".$this->class_tree[$classnum]['userclass_name']."</div>\n";
} }
@ -500,7 +500,7 @@ class user_class
{ {
$style = " style='text-indent:".(1.2*$nest_level)."em'"; $style = " style='text-indent:".(1.2*$nest_level)."em'";
} }
return "<div {$style}><input type='checkbox' name='{$treename}[]' value='{$classnum}'{$chk} />".$this->class_tree[$classnum]['userclass_name'].' ('.$this->class_tree[$classnum]['userclass_description'].")</div>\n"; return "<div {$style}><input type='checkbox' name='{$treename}[]' id='{$treename}_{$classnum}' value='{$classnum}'{$chk} />".$this->class_tree[$classnum]['userclass_name'].' ('.$this->class_tree[$classnum]['userclass_description'].")</div>\n";
} }