From 7f80c74b5910ae7e0054016330489cb3f0e3d6c3 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Fri, 12 Apr 2013 09:28:42 +0000 Subject: [PATCH] Add onselect attribute for nextmatch --- .../js/et2_dataview_controller_selection.js | 9 ++++++ etemplate/js/et2_extension_nextmatch.js | 29 ++++++++++++++++++- .../js/et2_extension_nextmatch_controller.js | 12 ++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/etemplate/js/et2_dataview_controller_selection.js b/etemplate/js/et2_dataview_controller_selection.js index 97f2908a5b..51f63e526e 100644 --- a/etemplate/js/et2_dataview_controller_selection.js +++ b/etemplate/js/et2_dataview_controller_selection.js @@ -52,6 +52,9 @@ var et2_dataview_selectionManager = Class.extend({ this._inUpdate = false; this._total = 0; this._children = []; + + // Callback for when the selection changes + this.select_callback = null; }, destroy: function () { @@ -74,6 +77,7 @@ var et2_dataview_selectionManager = Class.extend({ { this.unregisterRow(key, this._registeredRows[key].tr); } + this.select_callback = null; }, setIndexMap: function (_indexMap) { @@ -418,6 +422,11 @@ var et2_dataview_selectionManager = Class.extend({ { this._selectRange(this._focusedEntry.idx, _entry.idx); } + + if(this.select_callback && typeof this.select_callback == "function") + { + this.select_callback.apply(this._context, arguments); + } }, _selectRange: function (_start, _stop) { diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index 15c7495324..9d61504eec 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -93,6 +93,11 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], { "description": "Customise the nextmatch - right side. Provided template becomes a child of nextmatch, and any input widgets with onChange can trigger the nextmatch to refresh by returning true.", "default": "" }, + "onselect": { + "name": "onselect", + "type": "string", + "description": "JS code which gets executed when rows are selected. Can also be a app.appname.func(selected) style method" + }, "settings": { "name": "Settings", "type": "any", @@ -387,6 +392,29 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], { return {ids:[],inverted:false}; }, + onselect: function() { + // Execute the JS code connected to the event handler + if (this.options.onselect) + { + if (typeof this.options.onselect == "string" && + this.options.onselect.substr(0,4) == "app." && window.app) + { + var parts = this.options.onselect.split("."); + if(parts.length == 3 && typeof window.app[parts[1]] == "object" && + typeof window.app[parts[1]][parts[2]] == "function") + { + window.app[parts[1]][parts[2]].call(this, this.getSelection()); + } + } + + // Exectute the legacy JS code + else if (!(et2_compileLegacyJS(this.options.onselect, this, _node))()) + { + return false; + } + } + }, + /** * Generates the column caption for the given column widget */ @@ -1102,7 +1130,6 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], { return path; }, - // Input widget getValue: function() { return null;}, resetDirty: function() {}, diff --git a/etemplate/js/et2_extension_nextmatch_controller.js b/etemplate/js/et2_extension_nextmatch_controller.js index 366b83088c..3ba592bdb2 100644 --- a/etemplate/js/et2_extension_nextmatch_controller.js +++ b/etemplate/js/et2_extension_nextmatch_controller.js @@ -62,6 +62,9 @@ var et2_nextmatch_controller = et2_dataview_controller.extend( this._actionManager = null; this._objectManager = _objectManager; } + // Add our selection callback to selection manager + var self = this; + this._objectManager.setSelectedCallback = function() {self._selectCallback(this);}; // Call the parent et2_dataview_controller constructor this._super(_parentController, _grid, this, this._rowCallback, @@ -80,6 +83,7 @@ var et2_nextmatch_controller = et2_dataview_controller.extend( // Directly use the API-Implementation of dataRegisterUID and // dataUnregisterUID this.dataUnregisterUID = _egw.dataUnregisterUID; + }, destroy: function () { @@ -257,6 +261,14 @@ var et2_nextmatch_controller = et2_dataview_controller.extend( this._super.apply(this, arguments); }, + /** + * Execute the select callback when the row selection changes + */ + _selectCallback: function(action) + { + this._widget.onselect.call(this._widget, action); + }, + /** -- Implementation of et2_IDataProvider -- **/