From b2e9b07af86c824896a163949c341cee0faa7f39 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 10 Apr 2012 20:27:37 +0000 Subject: [PATCH] Get most submit actions working --- .../class.etemplate_widget_nextmatch.inc.php | 4 +- .../js/et2_dataview_controller_selection.js | 3 ++ etemplate/js/et2_extension_nextmatch.js | 11 +++-- .../js/et2_extension_nextmatch_actions.js | 48 ++++++++++++++----- .../js/et2_extension_nextmatch_controller.js | 4 ++ 5 files changed, 52 insertions(+), 18 deletions(-) diff --git a/etemplate/inc/class.etemplate_widget_nextmatch.inc.php b/etemplate/inc/class.etemplate_widget_nextmatch.inc.php index f3710d3fac..32f2aef059 100644 --- a/etemplate/inc/class.etemplate_widget_nextmatch.inc.php +++ b/etemplate/inc/class.etemplate_widget_nextmatch.inc.php @@ -685,7 +685,7 @@ class etemplate_widget_nextmatch extends etemplate_widget $value = self::get_array($content, $form_name); // On client, rows does not get its own namespace, but all apps are expecting it - $value[$form_name]['rows'] = $value; + $value['rows'] = $value; // Save current column settings as default (admins only) if($value['as_default']) @@ -703,7 +703,7 @@ class etemplate_widget_nextmatch extends etemplate_widget $GLOBALS['egw']->preferences->save_repository(false,'default'); } } - $validated = $value; + $validated[$form_name] = $value; } /** diff --git a/etemplate/js/et2_dataview_controller_selection.js b/etemplate/js/et2_dataview_controller_selection.js index bbb2cdb8c1..410c8c3414 100644 --- a/etemplate/js/et2_dataview_controller_selection.js +++ b/etemplate/js/et2_dataview_controller_selection.js @@ -278,6 +278,9 @@ var et2_dataview_selectionManager = Class.extend({ // Create an action object for the tr and connect it to a dummy AOI _entry.ao = this._actionObjectManager.addObject(_uid, dummyAOI); + + // Force context (actual widget) in here, it's the last place it's available + _entry.ao._context = this._context; _entry.ao.updateActionLinks(_links); _entry.ao._index = _idx; diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index 17ce217135..eb698f9610 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -65,7 +65,7 @@ var et2_INextmatchSortable = new Interface({ /** * Class which implements the "nextmatch" XET-Tag */ -var et2_nextmatch = et2_DOMWidget.extend(et2_IResizeable, { +var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], { attributes: { "template": { @@ -845,10 +845,15 @@ var et2_nextmatch = et2_DOMWidget.extend(et2_IResizeable, { getPath: function() { var path = this._super.apply(this,arguments); - if(this.id) path.push(this.id); + if(this.id && path[path.length -1] == this.id) path.pop(); return path; - } + }, + + // Input widget + getValue: function() { return null;}, + resetDirty: function() {}, + isDirty: function() { return false;} }); et2_register_widget(et2_nextmatch, ["nextmatch"]); diff --git a/etemplate/js/et2_extension_nextmatch_actions.js b/etemplate/js/et2_extension_nextmatch_actions.js index 7c4fcbb44b..afe724f429 100644 --- a/etemplate/js/et2_extension_nextmatch_actions.js +++ b/etemplate/js/et2_extension_nextmatch_actions.js @@ -130,19 +130,32 @@ function nm_action(_action, _senders, _target, _ids) for (var i in checkboxes) checkboxes_elem.value += checkboxes[i].id + ":" + (checkboxes[i].checked ? "1" : "0") + ";"; - document.getElementById(mgr.etemplate_var_prefix+'[nm][nm_action]').value = _action.id; - document.getElementById(mgr.etemplate_var_prefix+'[nm][selected]').value = ids; - if (typeof _action.data.button != 'undefined') + var nextmatch = _action.data.nextmatch; + if(!nextmatch && _senders.length) { - submitit(mgr.etemplate_form.context, mgr.etemplate_var_prefix+'[nm][rows]['+_action.data.button+']['+ids+']'); + // Pull it from deep within, where it was stuffed in et2_dataview_controller_selection._attachActionObject() + nextmatch = _senders[0]._context._widget; + } + if(nextmatch) + { + // Fake a getValue() function + nextmatch.getValue = function() { + var value = { + "selected": idsArr, + "checkboxes": checkboxes_elem ? checkboxes_elem.value : null + }; + value[nextmatch.options.settings.action_var]= _action.id; + return value; + } + nextmatch.getInstanceManager().submit(); + + // Clear action in case there's another one + delete nextmatch.getValue; } else { - mgr.etemplate_form.submit(); + egw().debug("error", "Missing nextmatch widget, could not submit", _action); } - // Clear action in case there's another one - document.getElementById(mgr.etemplate_var_prefix+'[nm][nm_action]').value = null; - break; } } @@ -227,8 +240,7 @@ var nm_popup_action, nm_popup_ids = null; */ function nm_open_popup(_action, _ids) { - var popup = document.getElementById(_action.getManager().etemplate_var_prefix + '[' + _action.id + '_popup]'); - + var popup = jQuery("#"+_action.id+"_popup").get(0) || jQuery("[id*='" + _action.id + "_popup']").get(0); if (popup) { nm_popup_action = _action; nm_popup_ids = _ids; @@ -241,10 +253,20 @@ function nm_open_popup(_action, _ids) */ function nm_submit_popup(button) { - button.form.submit_button.value = button.name; // set name of button (sub-action) + if(button.form) + { + button.form.submit_button.value = button.name; // set name of button (sub-action) + } + // Mangle senders to get IDs where nm_action() wants them + // No idea why this is needed + var ids = {ids:[]}; + for(var i in nm_popup_ids) + { + ids.ids.push(nm_popup_ids[i].id); + } // call regular nm_action to transmit action and senders correct - nm_action(nm_popup_action, null, null, nm_popup_ids); + nm_action(nm_popup_action,nm_popup_ids, null, ids); } /** @@ -253,7 +275,7 @@ function nm_submit_popup(button) function nm_hide_popup(element, div_id) { var prefix = element.id.substring(0,element.id.indexOf('[')); - var popup = document.getElementById(prefix+'['+div_id+']'); + var popup = jQuery("#"+_action.id+"_popup").get(0) || jQuery("[id*='" + _action.id + "_popup']").get(0); // Hide popup if(popup) { diff --git a/etemplate/js/et2_extension_nextmatch_controller.js b/etemplate/js/et2_extension_nextmatch_controller.js index c4a788f99f..4b60afaf20 100644 --- a/etemplate/js/et2_extension_nextmatch_controller.js +++ b/etemplate/js/et2_extension_nextmatch_controller.js @@ -128,6 +128,10 @@ var et2_nextmatch_controller = et2_dataview_controller.extend( // Get the selected ids descriptor object var ids = self._selectionMgr.getSelected(); + // Pass a reference to the actual widget + if (typeof _action.data == 'undefined' || !_action.data) _action.data = {}; + _action.data.nextmatch = self._widget; + // Call the nm_action function with the ids nm_action(_action, _senders, _target, ids); });