From 337559c3c5ad3b5a56987bcb383289fd477f7f5d Mon Sep 17 00:00:00 2001 From: Joey Schulze Date: Sat, 27 Feb 2010 23:13:23 +0100 Subject: [PATCH] Support for database oriented checkboxes as control in LiveGrid tables --- ajax/ricoUpdateConnection.php | 74 ++++++++++++++++++++++++++ lib/ricoTableColumnDB.js | 98 +++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 ajax/ricoUpdateConnection.php create mode 100644 lib/ricoTableColumnDB.js diff --git a/ajax/ricoUpdateConnection.php b/ajax/ricoUpdateConnection.php new file mode 100644 index 0000000..3c5e2cf --- /dev/null +++ b/ajax/ricoUpdateConnection.php @@ -0,0 +1,74 @@ + diff --git a/lib/ricoTableColumnDB.js b/lib/ricoTableColumnDB.js new file mode 100644 index 0000000..f0a31be --- /dev/null +++ b/lib/ricoTableColumnDB.js @@ -0,0 +1,98 @@ +/** + * (c) 2008,9 Joey Schulze + * + * Rico is licensed under the Apache License, Version 2.0 (the "License"); you may not use this + * file except in compliance with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + **/ + +if(typeof Rico=='undefined') throw("RicoExtension requires the Rico JavaScript framework"); +if(typeof Rico.TableColumn=='undefined') throw("RicoExtension requires ricoGridCommon.js"); +if(typeof Rico.TableColumn.checkbox=='undefined') throw("RicoExtension requires ricoGridControls.js"); + +// Checkbox with database connection +Rico.TableColumn.checkboxDB = Class.create(Rico.TableColumn.checkbox, { + + initialize: function($super, refcol, update) { + $super(1, 0, 0, 0); + this._referenceColumn = refcol; + this._updateUrl = update; + }, + + _onclick: function($super,e) { + $super(e); + var elem=Event.element(e); + var windowRow=parseInt(elem.id.split(/_/).pop()); + + this._update(windowRow); + }, + + _formbase: function() { + return 'table='+this.liveGrid.tableId+'&column='+this.index; + }, + + _update: function(row) { + if (this._referenceColumn == undefined || this._updateUrl == undefined) + return false; + + var value = this.getValue(row); + + if (value == undefined) + return false; + + var id = this.liveGrid.columns[this._referenceColumn].getValue(row); + var formdata = this._formbase() + '&reference='+id+'&value='+value; + + new Ajax.Request(this._updateUrl, {method: 'post', parameters: formdata}); + }, + + _updateall: function(value) { + var formdata = this._formbase() + '&value='+value; + + if (this.liveGrid.filterCount() > 0) { + var cols = this.liveGrid.columns.length; + for (var c = 0; c < cols; c++) { + var column = this.liveGrid.columns[c] + if (column.filterType == Rico.TableColumn.USERFILTER) { + var filter = column.filterOp + '%' + column.filterValues; + formdata += '&filter_'+c+'='+filter; + } + } + } + + new Ajax.Request(this._updateUrl, {method: 'post', parameters: formdata}); + + var basename = this.liveGrid.tableId + '_chkbox_' + this.index + '_'; + var childCnt = this.numRows(); + var val = value?true:false; + for (var r = 0; r < childCnt; r++) + if (this.getValue(r) != null) { + var name = basename + r; + $(name).checked = val; + } + + var rows = this.liveGrid.buffer.totalRows; + for (var i = 0; i < rows; i++) + this.liveGrid.buffer.setValue(i, this.index, value); + }, + + _checkall: function() { + this._updateall(1); + }, + _uncheckall: function() { + this._updateall(0); + }, + + _createFilters: function(parent,name) { + field_p=RicoUtil.createFormField(parent,'img',null,name+'_p'); + field_p.src = Rico.imgDir+'p.gif'; + field_p.tableColumn = this; + field_p.onclick = function() { this.tableColumn._checkall(); }; + field_m=RicoUtil.createFormField(parent,'img',null,name+'_m'); + field_m.src = Rico.imgDir+'m.gif'; + field_m.tableColumn = this; + field_m.onclick = function() { this.tableColumn._uncheckall(); }; + } +}); + +Rico.includeLoaded('ricoTableColumnDB.js'); -- 2.20.1