diff --git a/etemplate/inc/class.etemplate_widget_nextmatch.inc.php b/etemplate/inc/class.etemplate_widget_nextmatch.inc.php index 32f2aef059..5da4d339cc 100644 --- a/etemplate/inc/class.etemplate_widget_nextmatch.inc.php +++ b/etemplate/inc/class.etemplate_widget_nextmatch.inc.php @@ -172,6 +172,7 @@ class etemplate_widget_nextmatch extends etemplate_widget $value['start'] = (int)$queriedRange['start']; $value['num_rows'] = (int)$queriedRange['num_rows']; + if($value['num_rows'] == 0) $value['num_rows'] = 20; // if app supports parent_id / hierarchy ($value['parent_id'] not empty), set parent_id as filter if (($parent_id = $value['parent_id'])) { @@ -687,6 +688,13 @@ class etemplate_widget_nextmatch extends etemplate_widget // On client, rows does not get its own namespace, but all apps are expecting it $value['rows'] = $value; + // Legacy support - action popups were not properly namespaced + $preserve = self::get_array(self::$request->preserv, $form_name); + if($value[$preserve['action_var']] && $content[$value[$preserve['action_var']].'_popup']) + { + $validated += $content[$value[$preserve['action_var']].'_popup']; + } + // Save current column settings as default (admins only) if($value['as_default']) { diff --git a/etemplate/js/et2_extension_nextmatch_actions.js b/etemplate/js/et2_extension_nextmatch_actions.js index afe724f429..e742f6478c 100644 --- a/etemplate/js/et2_extension_nextmatch_actions.js +++ b/etemplate/js/et2_extension_nextmatch_actions.js @@ -114,7 +114,7 @@ function nm_action(_action, _senders, _target, _ids) // open div styled as popup contained in current form and named action.id+'_popup' if (nm_popup_action == null) { - nm_open_popup(_action, _ids); + nm_open_popup(_action, _ids.ids); break; } // fall through, if popup is open --> submit form @@ -145,12 +145,24 @@ function nm_action(_action, _senders, _target, _ids) "checkboxes": checkboxes_elem ? checkboxes_elem.value : null }; value[nextmatch.options.settings.action_var]= _action.id; + if(_target && _target.id) value[_target.id] = true; return value; } - nextmatch.getInstanceManager().submit(); - // Clear action in case there's another one - delete nextmatch.getValue; + if(_action.data.nm_action == 'popup') + { + nextmatch.getInstanceManager().submit(); + + // Clear action in case there's another one + delete nextmatch.getValue; + + // TODO: force nextmatch to re-load affected rows + } + else + { + // Full POST + nextmatch.getInstanceManager().postSubmit(); + } } else { @@ -245,6 +257,27 @@ function nm_open_popup(_action, _ids) nm_popup_action = _action; nm_popup_ids = _ids; popup.style.display = 'block'; +/* +Not working yet - DOM manipulation causes et2 problems + var dialog = jQuery('.action_popup-content',popup); + var d_buttons = []; + jQuery('button',popup).each(function(index) { + var but = jQuery(this); + d_buttons.push({ + text: but.text(), + click: this.onclick ? this.onclick : function(e) { + dialog.dialog("close"); + // Need to destroy the dialog, etemplate widget needs divs back where they were + dialog.dialog("destroy"); + nm_popup_action.data.nextmatch.getRoot().getWidgetById(but.attr("id")).onclick.apply(nm_popup_action.data.nextmatch.getRoot().getWidgetById(but.attr("id")), e.currentTarget);} + }); + }); + dialog.dialog({ + title: jQuery('.promptheader',popup).text(), + modal: true, + buttons: d_buttons + }); +*/ } } @@ -257,16 +290,20 @@ function nm_submit_popup(button) { button.form.submit_button.value = button.name; // set name of button (sub-action) } + else if (nm_popup_action.data.nextmatch) + { + nm_popup_action.data.nextmatch.getRoot().getWidgetById(button.id).clicked = true; + } // 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); + ids.ids.push(nm_popup_ids[i]); } // call regular nm_action to transmit action and senders correct - nm_action(nm_popup_action,nm_popup_ids, null, ids); + nm_action(nm_popup_action,nm_popup_ids, button, ids); } /** diff --git a/etemplate/js/et2_widget_button.js b/etemplate/js/et2_widget_button.js index 615ccabfb3..af5343ccbc 100644 --- a/etemplate/js/et2_widget_button.js +++ b/etemplate/js/et2_widget_button.js @@ -122,12 +122,15 @@ var et2_button = et2_baseWidget.extend([et2_IInput, et2_IDetachedDOM], { }, onclick: function(_node) { + this.clicked = true; + // Execute the JS code connected to the event handler if (this.options.onclick) { // Exectute the legacy JS code if (!(et2_compileLegacyJS(this.options.onclick, this, _node))()) { + this.clicked = false; return false; } } @@ -135,10 +138,9 @@ var et2_button = et2_baseWidget.extend([et2_IInput, et2_IDetachedDOM], { // Submit the form if (this._type != "buttononly") { - this.clicked = true; this.getInstanceManager().submit(this); //TODO: this only needs to be passed if it's in a datagrid - this.clicked = false; } + this.clicked = false; }, set_label: function(_value) { diff --git a/etemplate/js/etemplate2.js b/etemplate/js/etemplate2.js index 0471c0cf1a..81dab7dabc 100644 --- a/etemplate/js/etemplate2.js +++ b/etemplate/js/etemplate2.js @@ -293,6 +293,44 @@ etemplate2.prototype.submit = function(button) } } +/** + * Does a full form post submit. + * Only use this one if you need it, use the ajax submit() instead + */ +etemplate2.prototype.postSubmit = function() +{ + // Get the form values + var values = this.getValues(this.widgetContainer); + + // Trigger the submit event + var canSubmit = true; + this.widgetContainer.iterateOver(function(_widget) { + if (_widget.submit(values) === false) + { + canSubmit = false; + } + }, this, et2_ISubmitListener); + + if (canSubmit) + { + var form = document.createElement("form"); + form.method = "POST"; + form.action = egw().webserverUrl +"/json.php?menuaction=etemplate::ajax_process_post"; + + var etemplate_id = document.createElement("input"); + etemplate_id.name = 'etemplate_exec_id'; + etemplate_id.value = this.etemplate_exec_id; + form.appendChild(etemplate_id); + + var input = document.createElement("input"); + input.name = 'value'; + input.value = egw().jsonEncode(values); + form.appendChild(input); + + form.submit(); + } +} + /** * Fetches all input element values and returns them in an associative * array. Widgets which introduce namespacing can use the internal _target