Always disable Rico debugging
[misc/kostenrechnung] / lib / ricoTableColumnDB.js
1 /**
2   *  (c) 2008,9 Joey Schulze <joey@infodrom.org>
3   *
4   *  Rico is licensed under the Apache License, Version 2.0 (the "License"); you may not use this
5   *  file except in compliance with the License. You may obtain a copy of the License at
6   *   http://www.apache.org/licenses/LICENSE-2.0
7   **/
8
9 if(typeof Rico=='undefined') throw("RicoExtension requires the Rico JavaScript framework");
10 if(typeof Rico.TableColumn=='undefined') throw("RicoExtension requires ricoGridCommon.js");
11 if(typeof Rico.TableColumn.checkbox=='undefined') throw("RicoExtension requires ricoGridControls.js");
12
13 // Checkbox with database connection
14 Rico.TableColumn.checkboxDB = Class.create(Rico.TableColumn.checkbox, {
15
16         initialize: function($super, refcol, update) {
17             $super(1, 0, 0, 0);
18             this._referenceColumn = refcol;
19             this._updateUrl = update;
20         },
21
22         _onclick: function($super,e) {
23             $super(e);
24             var elem=Event.element(e);
25             var windowRow=parseInt(elem.id.split(/_/).pop());
26
27             this._update(windowRow);
28         },
29
30         _formbase: function() {
31             return 'table='+this.liveGrid.tableId+'&column='+this.index;
32         },
33
34         _update: function(row) {
35             if (this._referenceColumn == undefined || this._updateUrl == undefined)
36                 return false;
37
38             var value = this.getValue(row);
39
40             if (value == undefined)
41                 return false;
42
43             var id = this.liveGrid.columns[this._referenceColumn].getValue(row);
44             var formdata = this._formbase() + '&reference='+id+'&value='+value;
45
46             new Ajax.Request(this._updateUrl, {method: 'post', parameters: formdata});
47         },
48
49         _updateall: function(value) {
50             var formdata = this._formbase() + '&value='+value;
51
52             if (this.liveGrid.filterCount() > 0) {
53                 var cols = this.liveGrid.columns.length;
54                 for (var c = 0; c < cols; c++) {
55                     var column = this.liveGrid.columns[c]
56                     if (column.filterType == Rico.TableColumn.USERFILTER) {
57                         var filter = column.filterOp + '|' + column.filterValues;
58                         formdata += '&filter_'+c+'='+filter;
59                     }
60                 }
61             }
62
63             new Ajax.Request(this._updateUrl, {method: 'post', parameters: formdata});
64
65             var basename = this.liveGrid.tableId + '_chkbox_' + this.index + '_';
66             var childCnt = this.numRows();
67             var val = value?true:false;
68             for (var r = 0; r < childCnt; r++)
69                 if (this.getValue(r) != null) {
70                     var name = basename + r;
71                     $(name).checked = val;
72                 }
73
74             var rows = this.liveGrid.buffer.totalRows;
75             for (var i = 0; i < rows; i++)
76                 this.liveGrid.buffer.setValue(i, this.index, value);
77         },
78
79         _checkall: function() {
80             this._updateall(1);
81         },
82         _uncheckall: function() {
83             this._updateall(0);
84         },
85
86         _createFilters: function(parent,name) {
87             field_p=RicoUtil.createFormField(parent,'img',null,name+'_p');
88             field_p.src = Rico.imgDir+'p.gif';
89             field_p.tableColumn = this;
90             field_p.onclick = function() { this.tableColumn._checkall(); };
91             field_m=RicoUtil.createFormField(parent,'img',null,name+'_m');
92             field_m.src = Rico.imgDir+'m.gif';
93             field_m.tableColumn = this;
94             field_m.onclick = function() { this.tableColumn._uncheckall(); };
95         }
96 });
97
98 Rico.includeLoaded('ricoTableColumnDB.js');