1 /* ---------------------------------------------------------------------------
2 * Copyright (C) 2008 Georgia Public Library Service
3 * Bill Erickson <erickson@esilibrary.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * ---------------------------------------------------------------------------
17 if(!dojo._hasResource["openils.GridColumnPicker"]) {
18 dojo._hasResource["openils.GridColumnPicker"] = true;
19 dojo.provide('openils.GridColumnPicker');
20 dojo.declare('openils.GridColumnPicker', null, {
22 constructor : function (dialog, grid) {
25 this.structure = grid.structure;
26 this.dialogTable = dialog.domNode.getElementsByTagName('tbody')[0];
27 this.baseCellList = this.structure[0].cells[0].slice();
29 this.grid.model.fields.get(0).sort = false;
32 // builds the column-picker dialog table
34 var cells = this._selectableCellList();
36 var rows = dojo.query('tr', this.dialogTable);
38 for(var i = 0; i < rows.length; i++) {
39 if(rows[i].getAttribute('picker'))
40 this.dialogTable.removeChild(rows[i]);
43 rows = dojo.query('tr', this.dialogTable);
46 lastChild = rows[rows.length-1];
48 for(var i = 0; i < cells.length; i++) {
49 // setting table.innerHTML breaks stuff, so do it the hard way
50 tr = document.createElement('tr');
51 tr.setAttribute('picker', 'picker');
52 td1 = document.createElement('td');
53 td2 = document.createElement('td');
54 td3 = document.createElement('td');
56 ipt = document.createElement('input');
57 ipt.setAttribute('type', 'checkbox');
58 ipt.setAttribute('checked', 'checked');
59 ipt.setAttribute('ident', cells[i].field+''+cells[i].name);
60 ipt.setAttribute('name', 'selector');
62 ipt2 = document.createElement('input');
63 ipt2.setAttribute('type', 'checkbox');
64 ipt2.setAttribute('ident', cells[i].field+''+cells[i].name);
65 ipt2.setAttribute('name', 'width');
67 td1.appendChild(document.createTextNode(cells[i].name));
69 td3.appendChild(ipt2);
74 this.dialogTable.insertBefore(tr, lastChild);
76 this.dialogTable.appendChild(tr);
80 // update the grid based on the items selected in the picker dialog
83 var rows = dojo.query('[picker=picker]', this.dialogTable);
85 for(var j = 0; j < this.baseCellList.length; j++) {
86 var cell = this.baseCellList[j];
87 if(cell.selectableColumn) {
88 for(var i = 0; i < rows.length; i++) {
90 var selector = dojo.query('[name=selector]', row)[0];
91 var width = dojo.query('[name=width]', row)[0];
92 if(selector.checked && selector.getAttribute('ident') == cell.field+''+cell.name) {
95 else delete cell.width;
96 newCellList.push(cell);
99 } else { // if it's not selectable, always show it
100 newCellList.push(cell);
104 this.structure[0].cells[0] = newCellList;
105 this.grid.setStructure(this.structure);
109 _selectableCellList : function() {
110 var cellList = this.structure[0].cells[0];
112 for(var i = 0; i < cellList.length; i++) {
113 var cell = cellList[i];
114 if(cell.selectableColumn)
115 cells.push({name:cell.name, field:cell.field});
120 // save me as a user setting
121 persist : function() {