]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/dojo/openils/widget/_GridHelperColumns.js
LP#1482400: when activating a PO, provide better progress updates
[working/Evergreen.git] / Open-ILS / web / js / dojo / openils / widget / _GridHelperColumns.js
1 /* to be inherited by autogrid and similar */
2 if (!dojo._hasResource["openils.widget._GridHelperColumns"]) {
3     dojo._hasResource["openils.widget._GridHelperColumns"] = true;
4
5     dojo.provide("openils.widget._GridHelperColumns");
6     dojo.declare(
7         "openils.widget._GridHelperColumns", null, {
8
9             "hideSelector": false,
10             "selectorWidth": 1.5,
11             "hideLineNumber": false,
12             "lineNumberWidth": "1.5",
13
14             "getSelectedRows": function() {
15                 var rows = [];
16                 dojo.forEach(
17                     dojo.query('[name=autogrid.selector]', this.domNode),
18                     function(input) {
19                         if(input.checked)
20                             rows.push(input.getAttribute('row'));
21                     }
22                 );
23                 return rows;
24             },
25
26             "getFirstSelectedRow": function() {
27                 return this.getSelectedRows()[0];
28             },
29
30             "getSelectedItems": function() {
31                 var items = [];
32                 var self = this;
33                 dojo.forEach(this.getSelectedRows(), function(idx) { items.push(self.getItem(idx)); });
34                 return items;
35             },
36
37             "selectRow": function(rowIdx) {
38                 var inputs = dojo.query('[name=autogrid.selector]', this.domNode);
39                 for(var i = 0; i < inputs.length; i++) {
40                     if(inputs[i].getAttribute('row') == rowIdx) {
41                         if(!inputs[i].disabled)
42                             inputs[i].checked = true;
43                         break;
44                     }
45                 }
46             },
47
48             "deSelectRow": function(rowIdx) {
49                 var inputs = dojo.query('[name=autogrid.selector]', this.domNode);
50                 for(var i = 0; i < inputs.length; i++) {
51                     if(inputs[i].getAttribute('row') == rowIdx) {
52                         inputs[i].checked = false;
53                         break;
54                     }
55                 }
56             },
57
58             "toggleSelectAll": function() {
59                 var selected = this.getSelectedRows();
60                 for(var i = 0; i < this.rowCount; i++) {
61                     if(selected[0])
62                         this.deSelectRow(i);
63                     else
64                         this.selectRow(i);
65                 }
66             },
67
68             "_formatRowSelectInput": function(rowIdx) {
69                 if (rowIdx === null || rowIdx === undefined)
70                     return "";
71                 var s = "<input type='checkbox' name='autogrid.selector' row='"
72                     + rowIdx + "'";
73                 if (this.disableSelectorForRow &&
74                         this.disableSelectorForRow(rowIdx))
75                     s += " disabled='disabled'";
76                 return s + "/>";
77             },
78
79             // style the cells in the line number column
80             "onStyleRow": function(row) {
81                 if (!this.hideLineNumber) {
82                     var cellIdx = this.hideSelector ? 0 : 1;
83                     dojo.addClass(
84                         this.views.views[0].getCellNode(row.index, cellIdx),
85                         "autoGridLineNumber"
86                     );
87                 }
88             },
89
90             /* Don't allow sorting on the selector column */
91             "canSort": function(rowIdx) {
92                 if (rowIdx == 1 && !this.hideSelector)
93                     return false;
94                 if (this.hideSelector && rowIdx == 1 && !this.hideLineNumber)
95                     return false;
96                 if (!this.hideSelector && rowIdx == 2 && !this.hideLineNumber)
97                     return false;
98                 return true;
99             },
100
101             "_startupGridHelperColumns": function() {
102                 if (!this.hideLineNumber) {
103                     this.structure[0].cells[0].unshift({
104                         "field": "+lineno",
105                         "get": function(rowIdx, item) {
106                             if (item) return 1 + rowIdx;
107                         },
108                         "width": this.lineNumberWidth,
109                         "name": "#",
110                         "nonSelectable": false
111                     });
112                 }
113                 if (!this.hideSelector) {
114                     this.structure[0].cells[0].unshift({
115                         "field": "+selector",
116                         "formatter": dojo.hitch(
117                             this, function(rowIdx) {
118                                 return this._formatRowSelectInput(rowIdx);
119                             }
120                         ),
121                         "get": function(rowIdx, item) {
122                             if (item) return rowIdx;
123                         },
124                         "width": this.selectorWidth,
125                         "name": "&#x2713",
126                         "nonSelectable": true
127                     });
128                     dojo.connect(
129                         this, "onHeaderCellClick", function(e) {
130                             if (e.cell.index == 0)
131                                 this.toggleSelectAll();
132                         }
133                     );
134                 }
135             }
136         }
137     );
138 }