/** * (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');