Add onselect attribute for nextmatch

This commit is contained in:
Nathan Gray 2013-04-12 09:28:42 +00:00
parent b8609009dc
commit 7f80c74b59
3 changed files with 49 additions and 1 deletions

View File

@ -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) {

View File

@ -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() {},

View File

@ -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 -- **/