2 * (c) 2005-2009 Richard Cowin (http://openrico.org)
3 * (c) 2005-2009 Matt Brown (http://dowdybrown.com)
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the
11 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12 * either express or implied. See the License for the specific language governing permissions
13 * and limitations under the License.
16 // -----------------------------------------------------
\r
18 // Custom formatting for LiveGrid columns
\r
20 // columnSpecs Usage: { type:'control', control:new Rico.TableColumn.CONTROLNAME() }
\r
22 // -----------------------------------------------------
\r
24 Rico.TableColumn = {};
26 Rico.TableColumn.checkboxKey = function(showKey) {
27 this.initialize(showKey);
30 Rico.TableColumn.checkboxKey.prototype = {
32 * @class Custom formatting for a LiveGrid column.
33 * Display unique key column as: <checkbox> <key value>
34 * and keep track of which keys the user selects
35 * Key values should not contain <, >, or &
38 initialize: function(showKey) {
42 this._showKey=showKey;
\r
45 _create: function(gridCell,windowRow) {
46 this._checkboxes[windowRow]=Rico.createFormField(gridCell,'input','checkbox',this.liveGrid.tableId+'_chkbox_'+this.index+'_'+windowRow);
47 this._spans[windowRow]=Rico.createFormField(gridCell,'span',null,this.liveGrid.tableId+'_desc_'+this.index+'_'+windowRow);
48 this._clear(gridCell,windowRow);
49 Rico.eventBind(this._checkboxes[windowRow], 'click', Rico.eventHandle(this,'_onclick'));
52 _onclick: function(e) {
53 var elem=Event.element(e);
54 var windowRow=parseInt(elem.id.substr((elem.id.lastIndexOf('_',elem.id.length)+1))); //faster than split
55 var v=this.getValue(windowRow);
62 _clear: function(gridCell,windowRow) {
63 var box=this._checkboxes[windowRow];
65 box.style.display='none';
66 this._spans[windowRow].innerHTML='';
69 _display: function(v,gridCell,windowRow) {
70 var box=this._checkboxes[windowRow];
72 box.checked=this._KeyHash[v];
73 if (this._showKey) this._spans[windowRow].innerHTML=v;
76 _SelectedKeys: function() {
77 return Rico.keys(this._KeyHash);
80 _addChecked: function(k){
\r
84 _remChecked: function(k){
\r
85 delete this._KeyHash[k];
\r
90 Rico.TableColumn.checkbox = function(checkedValue, uncheckedValue, defaultValue, readOnly)
92 this.initialize(checkedValue, uncheckedValue, defaultValue, readOnly);
95 Rico.TableColumn.checkbox.prototype = {
97 * @class display checkboxes for two-valued column (e.g. yes/no)
100 initialize: function(checkedValue, uncheckedValue, defaultValue, readOnly) {
101 this._checkedValue=checkedValue;
102 this._uncheckedValue=uncheckedValue;
103 this._defaultValue=defaultValue || false;
104 this._readOnly=readOnly || false;
108 _create: function(gridCell,windowRow) {
109 this._checkboxes[windowRow]=Rico.createFormField(gridCell,'input','checkbox',this.liveGrid.tableId+'_chkbox_'+this.index+'_'+windowRow);
110 this._clear(gridCell,windowRow);
112 this._checkboxes[windowRow].disabled=true;
114 Rico.eventBind(this._checkboxes[windowRow], 'click', Rico.eventHandle(this,'_onclick'));
117 _onclick: function(e) {
118 var elem=Event.element(e);
119 var windowRow=parseInt(elem.id.substr((elem.id.lastIndexOf('_',elem.id.length)+1))); //faster than split
120 var newval=elem.checked ? this._checkedValue : this._uncheckedValue;
121 this.setValue(windowRow,newval);
124 _clear: function(gridCell,windowRow) {
125 var box=this._checkboxes[windowRow];
126 box.checked=this._defaultValue;
127 box.style.display='none';
130 _display: function(v,gridCell,windowRow) {
131 var box=this._checkboxes[windowRow];
132 box.style.display='';
133 box.checked=(v==this._checkedValue);
139 Rico.TableColumn.textbox = function(boxSize, boxMaxLen, readOnly) {
140 this.initialize(boxSize, boxMaxLen, readOnly);
143 Rico.TableColumn.textbox.prototype = {
145 * @class display value in a text box
148 initialize: function(boxSize, boxMaxLen, readOnly) {
149 this._boxSize=boxSize;
150 this._boxMaxLen=boxMaxLen;
151 this._readOnly=readOnly || false;
155 _create: function(gridCell,windowRow) {
156 var box=Rico.createFormField(gridCell,'input','text',this.liveGrid.tableId+'_txtbox_'+this.index+'_'+windowRow);
157 box.size=this._boxSize;
158 box.maxLength=this._boxMaxLen;
159 this._textboxes[windowRow]=box;
160 this._clear(gridCell,windowRow);
164 Rico.eventBind(box, 'change', Rico.eventHandle(this,'_onchange'));
167 _onchange: function(e) {
168 var elem=Event.element(e);
169 var windowRow=parseInt(elem.id.substr((elem.id.lastIndexOf('_',elem.id.length)+1))); //faster than split
170 this.setValue(windowRow,elem.value);
173 _clear: function(gridCell,windowRow) {
174 var box=this._textboxes[windowRow];
176 box.style.display='none';
179 _display: function(v,gridCell,windowRow) {
180 var box=this._textboxes[windowRow];
181 box.style.display='';
188 Rico.TableColumn.HighlightCell = function(chkcol,chkval,highlightColor,highlightBackground,chkop) {
189 this.initialize(chkcol,chkval,highlightColor,highlightBackground,chkop);
192 Rico.TableColumn.HighlightCell.prototype = {
194 * @class highlight a grid cell when a particular value is present in the specified column
197 initialize: function(chkcol,chkval,highlightColor,highlightBackground,chkop) {
\r
198 this._chkcol=chkcol;
\r
201 this._highlightColor=highlightColor;
\r
202 this._highlightBackground=highlightBackground;
\r
205 _clear: function(gridCell,windowRow) {
\r
206 gridCell.style.color='';
\r
207 gridCell.style.backgroundColor='';
\r
208 gridCell.innerHTML=' ';
\r
211 _display: function(v,gridCell,windowRow) {
\r
212 var gridval=this.liveGrid.buffer.getWindowValue(windowRow,this._chkcol);
\r
216 match=(gridval!=this._chkval);
219 match=(gridval>this._chkval);
222 match=(gridval<this._chkval);
225 match=(gridval>=this._chkval);
228 match=(gridval<=this._chkval);
231 match=(Math.abs(gridval)>this._chkval);
234 match=(Math.abs(gridval)<this._chkval);
237 match=(Math.abs(gridval)>=this._chkval);
240 match=(Math.abs(gridval)<=this._chkval);
243 match=(gridval==this._chkval);
246 gridCell.style.color=match ? this._highlightColor : '';
\r
247 gridCell.style.backgroundColor=match ? this._highlightBackground : '';
\r
248 gridCell.innerHTML=this._format(v);
\r
253 Rico.TableColumn.bgColor = function() {
256 Rico.TableColumn.bgColor.prototype = {
258 * @class database value contains a css color name/value
261 _clear: function(gridCell,windowRow) {
262 gridCell.style.backgroundColor='';
265 _display: function(v,gridCell,windowRow) {
266 gridCell.style.backgroundColor=v;
272 Rico.TableColumn.link = function(href,target,linktext) {
273 this.initialize(href,target,linktext);
276 Rico.TableColumn.link.prototype = {
278 * @class database value contains a url to another page
281 initialize: function(href,target,linktext) {
284 this._linktext=linktext;
288 _create: function(gridCell,windowRow) {
289 this._anchors[windowRow]=Rico.createFormField(gridCell,'a',null,this.liveGrid.tableId+'_a_'+this.index+'_'+windowRow);
290 if (this._target) this._anchors[windowRow].target=this._target;
291 this._clear(gridCell,windowRow);
294 _clear: function(gridCell,windowRow) {
295 this._anchors[windowRow].href='';
296 this._anchors[windowRow].innerHTML='';
299 _display: function(v,gridCell,windowRow) {
300 var buf=this.liveGrid.buffer;
301 var href=this._href=='self' ? v : this._href.replace(/\{\d+\}/g,
303 var colIdx=parseInt($1.substr(1),10);
304 return encodeURIComponent(buf.getWindowValue(windowRow,colIdx));
307 var desc=this._linktext || v;
309 this._anchors[windowRow].href=href;
310 this._anchors[windowRow].innerHTML=desc;
312 this._clear(gridCell,windowRow);
319 Rico.TableColumn.image = function(prefix,suffix) {
320 this.initialize(prefix,suffix);
323 Rico.TableColumn.image.prototype = {
325 * @class database value contains a url to an image
328 initialize: function(prefix,suffix) {
330 this._prefix=prefix || '';
331 this._suffix=suffix || '';
334 _create: function(gridCell,windowRow) {
335 this._img[windowRow]=Rico.createFormField(gridCell,'img',null,this.liveGrid.tableId+'_img_'+this.index+'_'+windowRow);
336 this._clear(gridCell,windowRow);
339 _clear: function(gridCell,windowRow) {
340 var img=this._img[windowRow];
341 img.style.display='none';
345 _display: function(v,gridCell,windowRow) {
346 var img=this._img[windowRow];
347 this._img[windowRow].src=this._prefix+v+this._suffix;
348 img.style.display='';
354 Rico.TableColumn.lookup = function(map, defaultCode, defaultDesc) {
355 this.initialize(map, defaultCode, defaultDesc);
358 Rico.TableColumn.lookup.prototype = {
360 * @class map a database value to a display value
363 initialize: function(map, defaultCode, defaultDesc) {
365 this._defaultCode=defaultCode || '';
366 this._defaultDesc=defaultDesc || ' ';
368 this._sortfunc=function(v) { return self._sortvalue(v); };
370 this._descriptions=[];
373 _create: function(gridCell,windowRow) {
374 this._descriptions[windowRow]=Rico.createFormField(gridCell,'span',null,this.liveGrid.tableId+'_desc_'+this.index+'_'+windowRow);
375 this._codes[windowRow]=Rico.createFormField(gridCell,'input','hidden',this.liveGrid.tableId+'_code_'+this.index+'_'+windowRow);
376 this._clear(gridCell,windowRow);
379 _clear: function(gridCell,windowRow) {
380 this._codes[windowRow].value=this._defaultCode;
381 this._descriptions[windowRow].innerHTML=this._defaultDesc;
384 _sortvalue: function(v) {
385 return this._getdesc(v).replace(/&/g, '&').replace(/</g,'<').replace(/>/g,'>').replace(/ /g,' ');
388 _getdesc: function(v) {
389 var desc=this._map[v];
390 return (typeof desc=='string') ? desc : this._defaultDesc;
393 _export: function(v) {
394 return this._getdesc(v);
397 _display: function(v,gridCell,windowRow) {
398 this._codes[windowRow].value=v;
399 this._descriptions[windowRow].innerHTML=this._getdesc(v);
406 Rico.TableColumn.MultiLine = function() {
409 Rico.TableColumn.MultiLine.prototype = {
411 * @class Fix issues with multiline content in IE
413 _display: function(v,gridCell,windowRow) {
\r
414 var newdiv = document.createElement("div");
\r
415 newdiv.innerHTML = this._format(v);
\r
416 newdiv.style.height='100%';
\r
417 if (gridCell.firstChild)
\r
418 gridCell.replaceChild(newdiv, gridCell.firstChild);
\r
420 gridCell.appendChild(newdiv);
\r