summaryrefslogtreecommitdiff
path: root/frontend/beta/js/YUI-extensions/grid/editor
Unidiff
Diffstat (limited to 'frontend/beta/js/YUI-extensions/grid/editor') (more/less context) (show whitespace changes)
-rw-r--r--frontend/beta/js/YUI-extensions/grid/editor/CellEditor.js91
-rw-r--r--frontend/beta/js/YUI-extensions/grid/editor/CheckboxEditor.js60
-rw-r--r--frontend/beta/js/YUI-extensions/grid/editor/DateEditor.js268
-rw-r--r--frontend/beta/js/YUI-extensions/grid/editor/NumberEditor.js166
-rw-r--r--frontend/beta/js/YUI-extensions/grid/editor/SelectEditor.js37
-rw-r--r--frontend/beta/js/YUI-extensions/grid/editor/TextEditor.js110
6 files changed, 732 insertions, 0 deletions
diff --git a/frontend/beta/js/YUI-extensions/grid/editor/CellEditor.js b/frontend/beta/js/YUI-extensions/grid/editor/CellEditor.js
new file mode 100644
index 0000000..7c51a48
--- a/dev/null
+++ b/frontend/beta/js/YUI-extensions/grid/editor/CellEditor.js
@@ -0,0 +1,91 @@
1/**
2 * @class YAHOO.ext.grid.CellEditor
3 * Base class for all EditorGrid editors
4 */
5YAHOO.ext.grid.CellEditor = function(element){
6 this.colIndex = null;
7 this.rowIndex = null;
8 this.grid = null;
9 this.editing = false;
10 this.originalValue = null;
11 this.element = getEl(element, true);
12 this.element.addClass('ygrid-editor');
13 this.element.dom.tabIndex = 1;
14 this.initialized = false;
15 this.callback = null;
16};
17
18YAHOO.ext.grid.CellEditor.prototype = {
19 init : function(grid, bodyElement, callback){
20 // there's no way for the grid to know if multiple columns
21 // share the same editor so it will try to initialize the
22 // same one over and over
23 if(this.initialized) return;
24 this.initialized = true;
25 this.callback = callback;
26 this.grid = grid;
27 bodyElement.appendChild(this.element.dom);
28 this.initEvents();
29 },
30
31 initEvents : function(){
32 var stopOnEnter = function(e){
33 if(e.browserEvent.keyCode == e.RETURN){
34 this.stopEditing(true);
35 }else if(e.browserEvent.keyCode == e.ESC){
36 this.setValue(this.originalValue);
37 this.stopEditing(true);
38 }
39 }
40 this.element.mon('keydown', stopOnEnter, this, true);
41 this.element.on('blur', this.stopEditing, this, true);
42 },
43
44 startEditing : function(value, row, cell){
45 this.originalValue = value;
46 this.rowIndex = row.rowIndex;
47 this.colIndex = cell.columnIndex;
48 this.cell = cell;
49 this.setValue(value);
50 var cellbox = getEl(cell, true).getBox();
51 this.fitToCell(cellbox);
52 this.editing = true;
53 this.show();
54 },
55
56 stopEditing : function(focusCell){
57 if(this.editing){
58 this.editing = false;
59 var newValue = this.getValue();
60 this.hide();
61 //if(focusCell){try{this.cell.focus();}catch(e){}}; // try to give the cell focus so keyboard nav still works
62 if(this.originalValue != newValue){
63 this.callback(newValue, this.rowIndex, this.colIndex);
64 }
65 }
66 },
67
68 setValue : function(value){
69 this.element.dom.value = value;
70 },
71
72 getValue : function(){
73 return this.element.dom.value;
74 },
75
76 fitToCell : function(box){
77 this.element.setBox(box, true);
78 },
79
80 show : function(){
81 this.element.show();
82 this.element.focus();
83 },
84
85 hide : function(){
86 try{
87 this.element.dom.blur();
88 }catch(e){}
89 this.element.hide();
90 }
91};
diff --git a/frontend/beta/js/YUI-extensions/grid/editor/CheckboxEditor.js b/frontend/beta/js/YUI-extensions/grid/editor/CheckboxEditor.js
new file mode 100644
index 0000000..681b847
--- a/dev/null
+++ b/frontend/beta/js/YUI-extensions/grid/editor/CheckboxEditor.js
@@ -0,0 +1,60 @@
1/**
2 * @class YAHOO.ext.grid.CheckboxEditor
3 * @extends YAHOO.ext.grid.CellEditor
4Provides a checkbox for editing boolean values. It currently has no configuration options.<br><br>
5For more information on using this editor, see <a href="http://www.jackslocum.com/yui/2006/09/10/adding-built-in-editing-support-to-the-yahoo-ui-extensions-grid/">this blog post</a>.
6* @constructor
7* Create a new CheckboxEditor
8 */
9YAHOO.ext.grid.CheckboxEditor = function(){
10 var div = document.createElement('span');
11 div.className = 'ygrid-editor ygrid-checkbox-editor';
12 var cb = document.createElement('input');
13 cb.type = 'checkbox';
14 cb.setAttribute('autocomplete', 'off');
15 div.appendChild(cb);
16 document.body.appendChild(div);
17 YAHOO.ext.grid.CheckboxEditor.superclass.constructor.call(this, div);
18 div.tabIndex = '';
19 cb.tabIndex = 1;
20 this.cb = getEl(cb, true);
21};
22
23YAHOO.extendX(YAHOO.ext.grid.CheckboxEditor, YAHOO.ext.grid.CellEditor);
24
25YAHOO.ext.grid.CheckboxEditor.prototype.fitToCell = function(box){
26 this.element.setBox(box, true);
27};
28
29YAHOO.ext.grid.CheckboxEditor.prototype.setValue = function(value){
30 this.cb.dom.checked = (value === true || value === 'true' || value === 1 || value === '1');
31};
32
33YAHOO.ext.grid.CheckboxEditor.prototype.getValue = function(){
34 return this.cb.dom.checked;
35};
36
37YAHOO.ext.grid.CheckboxEditor.prototype.show = function(){
38 this.element.show();
39 this.cb.focus();
40};
41
42YAHOO.ext.grid.CheckboxEditor.prototype.initEvents = function(){
43 var stopOnEnter = function(e){
44 if(e.browserEvent.keyCode == e.RETURN){
45 this.stopEditing(true);
46 }else if(e.browserEvent.keyCode == e.ESC){
47 this.setValue(this.originalValue);
48 this.stopEditing(true);
49 }
50 }
51 this.cb.mon('keydown', stopOnEnter, this, true);
52 this.cb.on('blur', this.stopEditing, this, true);
53};
54
55YAHOO.ext.grid.CheckboxEditor.prototype.hide = function(){
56 try{
57 this.cb.dom.blur();
58 }catch(e){}
59 this.element.hide();
60};
diff --git a/frontend/beta/js/YUI-extensions/grid/editor/DateEditor.js b/frontend/beta/js/YUI-extensions/grid/editor/DateEditor.js
new file mode 100644
index 0000000..303ad2b
--- a/dev/null
+++ b/frontend/beta/js/YUI-extensions/grid/editor/DateEditor.js
@@ -0,0 +1,268 @@
1/**
2 * @class YAHOO.ext.grid.DateEditor
3 * @extends YAHOO.ext.grid.CellEditor
4Provides a date editor field, and optionally a DatePicker. The DateEditor provides a method to override (showCalendar) if you don't want to use the built in DatePicker control. The reason I chose to use my own DatePicker control rather than the nice YUI Calendar component is my control was very easy to override events to make it work well with the grid. It's also only 5k compressed, while the YUI Calendar is 40k compressed. The DatePicker supports left/right keys to move months, up/down keys to move years and the mouse wheel to quickly go through the months. The DateEditor supports the following configuration options:
5<ul class="list">
6<li><i>format</i> - The date format for the editor. The format is identical to <a href="http://www.php.net/date">PHP date()</a> and text is allowed. Credit for that goes to <a style="font-weight:normal;" href="http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/">this fantastic date library</a>. This format is for the editor only and doesn't affect the rendering of the cell when not in edit mode. Your rendering function can use any date format it wants.</li>
7<li><i>minValue</i> - The minimum allowed date. Can be either a Javascript date object or a string date in the specified format.</li>
8<li><i>maxValue</i> - The maximum allowed date. Can be either a Javascript date object or a string date in the specified format.</li>
9<li><i>minText</i> - The tooltip to display when the date in the cell is before minValue.</li>
10<li><i>maxText</i> - The tooltip to display when the date in the cell is after maxValue.</li>
11<li><i>invalidText</i> - The text to display when the date in the field is invalid (for example: 02/31/06)</li>
12<li><i>disabledDays</i> - An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday.</li>
13<li><i>disabledDaysText</i> - The tooltip to display when the date in the cell (or DatePicker) falls on a disabled day.</li>
14<li><i>disabledDates</i> - An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular expression so they are very powerful. For example, ["03/08/2003", "09/16/2003"] would disable those dates, but ["03/08", "09/16"] would disable them for every year. If you are using short years, you will want to use ^ to tell the regular expression to only match the beginning like ["^03/08"]. To disable March of 2006: ["03/../2006"] or every March ["^03"]. In order to support regular expressions, if you are using a date format that has "." in it, you will have to escape the dot when restricting dates. For example: ["03\\.08\\.03"].</li>
15<li><i>disabledDatesText</i> - The tooltip to display when the date in the cell (or DatePicker) falls on a disabled date.</li>
16<li><i>allowBlank</i> - True if the cell is allowed to be empty.</li>
17<li><i>blankText</i> - The tooltip (error message) to display when the cell is empty and is not allowed to be.</li>
18<li><i>validator</i> - Any custom validation function you want called. The function must return true if the data is valid or an error message otherwise.</li>
19<li><i>validationDelay</i> - The delay in milliseconds for validation. Each time the user types something the field is validated after a specified delay, setting this value allows you to customize that delay (for example, if your custom validation routine is slow).</li>
20</ul>
21For more information on using this editor, see <a href="http://www.jackslocum.com/yui/2006/09/10/adding-built-in-editing-support-to-the-yahoo-ui-extensions-grid/">this blog post</a>.
22* @constructor
23* Create a new DateEditor
24* @param {Object} config
25 */
26YAHOO.ext.grid.DateEditor = function(config){
27 var div = document.createElement('span');
28 div.className = 'ygrid-editor ygrid-editor-container';
29
30 var element = document.createElement('input');
31 element.type = 'text';
32 element.tabIndex = 1;
33 element.setAttribute('autocomplete', 'off');
34 div.appendChild(element);
35
36 var pick = document.createElement('span');
37 pick.className = 'pick-button';
38 div.appendChild(pick);
39
40 document.body.appendChild(div);
41
42 this.div = getEl(div, true);
43 this.element = getEl(element, true);
44 this.pick = getEl(pick, true);
45
46 this.colIndex = null;
47 this.rowIndex = null;
48 this.grid = null;
49 this.editing = false;
50 this.originalValue = null;
51 this.initialized = false;
52 this.callback = null;
53
54 this.cal = null;
55 this.mouseDownHandler = YAHOO.ext.EventManager.wrap(this.handleMouseDown, this, true);
56
57 YAHOO.ext.util.Config.apply(this, config);
58 if(typeof this.minValue == 'string') this.minValue = this.parseDate(this.minValue);
59 if(typeof this.maxValue == 'string') this.maxValue = this.parseDate(this.maxValue);
60 this.ddMatch = /ddnone/;
61 if(this.disabledDates){
62 var dd = this.disabledDates;
63 var re = "(?:";
64 for(var i = 0; i < dd.length; i++){
65 re += dd[i];
66 if(i != dd.length-1) re += "|";
67 }
68 this.ddMatch = new RegExp(re + ")");
69 }
70};
71
72YAHOO.ext.grid.DateEditor.prototype = {
73 init : function(grid, bodyElement, callback){
74 if(this.initialized) return;
75
76 this.initialized = true;
77 this.callback = callback;
78 this.grid = grid;
79 bodyElement.appendChild(this.div.dom);
80 this.initEvents();
81 },
82
83 initEvents : function(){
84 var stopOnEnter = function(e){
85 if(e.browserEvent.keyCode == e.RETURN){
86 this.stopEditing(true);
87 }else if(e.browserEvent.keyCode == e.ESC){
88 this.setValue(this.originalValue);
89 this.stopEditing(true);
90 }
91 }
92 this.element.mon('keydown', stopOnEnter, this, true);
93 var vtask = new YAHOO.ext.util.DelayedTask(this.validate, this);
94 this.element.mon('keyup', vtask.delay.createDelegate(vtask, [this.validationDelay]));
95 this.pick.on('click', this.showCalendar, this, true);
96 },
97
98 startEditing : function(value, row, cell){
99 this.originalValue = value;
100 this.rowIndex = row.rowIndex;
101 this.colIndex = cell.columnIndex;
102 this.cell = cell;
103 this.setValue(value);
104 this.validate();
105 var cellbox = getEl(cell, true).getBox();
106 this.div.setBox(cellbox, true);
107 this.element.setWidth(cellbox.width-this.pick.getWidth());
108 this.editing = true;
109 YAHOO.util.Event.on(document, "mousedown", this.mouseDownHandler);
110 this.show();
111 },
112
113 stopEditing : function(focusCell){
114 if(this.editing){
115 YAHOO.util.Event.removeListener(document, "mousedown", this.mouseDownHandler);
116 this.editing = false;
117 var newValue = this.getValue();
118 this.hide();
119 //if(focusCell){try{this.cell.focus();}catch(e){}}// try to give the cell focus so keyboard nav still works
120 if(this.originalValue != newValue){
121 this.callback(newValue, this.rowIndex, this.colIndex);
122 }
123 }
124 },
125
126 setValue : function(value){
127 this.element.dom.value = this.formatDate(value);
128 this.validate();
129 },
130
131 getValue : function(){
132 if(!this.validate()){
133 return this.originalValue;
134 }else{
135 var value = this.element.dom.value;
136 if(value.length < 1){
137 return value;
138 } else{
139 return this.parseDate(value);
140 }
141 }
142 },
143
144 show : function() {
145 this.div.show();
146 this.element.focus();
147 this.validate();
148 },
149
150 hide : function(){
151 try{
152 this.element.dom.blur();
153 }catch(e){}
154 this.div.hide();
155 },
156
157 validate : function(){
158 var dom = this.element.dom;
159 var value = dom.value;
160 if(value.length < 1){ // if it's blank
161 if(this.allowBlank){
162 dom.title = '';
163 this.element.removeClass('ygrid-editor-invalid');
164 return true;
165 }else{
166 dom.title = this.blankText;
167 this.element.addClass('ygrid-editor-invalid');
168 return false;
169 }
170 }
171 value = this.parseDate(value);
172 if(!value){
173 dom.title = this.invalidText.replace('%0', dom.value).replace('%1', this.format);
174 this.element.addClass('ygrid-editor-invalid');
175 return false;
176 }
177 var time = value.getTime();
178 if(this.minValue && time < this.minValue.getTime()){
179 dom.title = this.minText.replace('%0', this.formatDate(this.minValue));
180 this.element.addClass('ygrid-editor-invalid');
181 return false;
182 }
183 if(this.maxValue && time > this.maxValue.getTime()){
184 dom.title = this.maxText.replace('%0', this.formatDate(this.maxValue));
185 this.element.addClass('ygrid-editor-invalid');
186 return false;
187 }
188 if(this.disabledDays){
189 var day = value.getDay();
190 for(var i = 0; i < this.disabledDays.length; i++) {
191 if(day === this.disabledDays[i]){
192 dom.title = this.disabledDaysText;
193 this.element.addClass('ygrid-editor-invalid');
194 return false;
195 }
196 }
197 }
198 var fvalue = this.formatDate(value);
199 if(this.ddMatch.test(fvalue)){
200 dom.title = this.disabledDatesText.replace('%0', fvalue);
201 this.element.addClass('ygrid-editor-invalid');
202 return false;
203 }
204 var msg = this.validator(value);
205 if(msg !== true){
206 dom.title = msg;
207 this.element.addClass('ygrid-editor-invalid');
208 return false;
209 }
210 dom.title = '';
211 this.element.removeClass('ygrid-editor-invalid');
212 return true;
213 },
214
215 handleMouseDown : function(e){
216 var t = e.getTarget();
217 var dom = this.div.dom;
218 if(t != dom && !YAHOO.util.Dom.isAncestor(dom, t)){
219 this.stopEditing();
220 }
221 },
222
223 showCalendar : function(value){
224 if(this.cal == null){
225 this.cal = new YAHOO.ext.DatePicker(this.div.dom.parentNode.parentNode);
226 }
227 this.cal.minDate = this.minValue;
228 this.cal.maxDate = this.maxValue;
229 this.cal.disabledDatesRE = this.ddMatch;
230 this.cal.disabledDatesText = this.disabledDatesText;
231 this.cal.disabledDays = this.disabledDays;
232 this.cal.disabledDaysText = this.disabledDaysText;
233 this.cal.format = this.format;
234 if(this.minValue){
235 this.cal.minText = this.minText.replace('%0', this.formatDate(this.minValue));
236 }
237 if(this.maxValue){
238 this.cal.maxText = this.maxText.replace('%0', this.formatDate(this.maxValue));
239 }
240 var r = this.div.getRegion();
241 this.cal.show(r.left, r.bottom, this.getValue(), this.setValue.createDelegate(this));
242 },
243
244 parseDate : function(value){
245 if(!value || value instanceof Date) return value;
246 return Date.parseDate(value, this.format);
247 },
248
249 formatDate : function(date){
250 if(!date || !(date instanceof Date)) return date;
251 return date.format(this.format);
252 }
253};
254
255YAHOO.ext.grid.DateEditor.prototype.format = 'm/d/y';
256YAHOO.ext.grid.DateEditor.prototype.disabledDays = null;
257YAHOO.ext.grid.DateEditor.prototype.disabledDaysText = '';
258YAHOO.ext.grid.DateEditor.prototype.disabledDates = null;
259YAHOO.ext.grid.DateEditor.prototype.disabledDatesText = '';
260YAHOO.ext.grid.DateEditor.prototype.allowBlank = true;
261YAHOO.ext.grid.DateEditor.prototype.minValue = null;
262YAHOO.ext.grid.DateEditor.prototype.maxValue = null;
263YAHOO.ext.grid.DateEditor.prototype.minText = 'The date in this field must be after %0';
264YAHOO.ext.grid.DateEditor.prototype.maxText = 'The date in this field must be before %0';
265YAHOO.ext.grid.DateEditor.prototype.blankText = 'This field cannot be blank';
266YAHOO.ext.grid.DateEditor.prototype.invalidText = '%0 is not a valid date - it must be in the format %1';
267YAHOO.ext.grid.DateEditor.prototype.validationDelay = 200;
268YAHOO.ext.grid.DateEditor.prototype.validator = function(){return true;};
diff --git a/frontend/beta/js/YUI-extensions/grid/editor/NumberEditor.js b/frontend/beta/js/YUI-extensions/grid/editor/NumberEditor.js
new file mode 100644
index 0000000..f74d3d9
--- a/dev/null
+++ b/frontend/beta/js/YUI-extensions/grid/editor/NumberEditor.js
@@ -0,0 +1,166 @@
1/**
2 * @class YAHOO.ext.grid.NumberEditor
3 * @extends YAHOO.ext.grid.CellEditor
4Provides a masked editor for numeric values. Invalid keys are ignored. It supports the following configuration options:
5<ul class="list">
6<li><i>allowDecimals</i> - True if the cell can have decimal values.</li>
7<li><i>decimalSeparator</i> - Character(s) to allow as the decimal separator.</li>
8<li><i>decimalPrecision</i> - Set the maximum decimal precision.</li>
9<li><i>decimalPrecisionFcn</i> - Define the function to call to remove extra precision (ie. Math.floor, Math.round, Math.ceil or your own function).</li>
10<li><i>allowNegative</i> - True if the cell allows negative values.</li>
11<li><i>selectOnFocus</i> - True to select the text when the editor is activated.</li>
12<li><i>minValue</i> - The minimum value the cell will allow.</li>
13<li><i>maxValue</i> - The maximum value the cell will allow.</li>
14<li><i>minText</i> - The tooltip to display when the value in the cell is below the minimum.</li>
15<li><i>maxText</i> - The tooltip to display when the value in the cell is above the maximum.</li>
16<li><i>nanText</i> - The tooltip to display when the value in the cell is not a valid number (for example, negatives are allowed and the value in the cell is just "-" with no numbers).</li>
17<li><i>allowBlank</i> - True if the cell is allowed to be empty.</li>
18<li><i>blankText</i> - The tooltip (error message) to display when the cell is empty and is not allowed to be.</li>
19<li><i>validator</i> - Any custom validation function you want called. The function must return true if the data is valid or an error message otherwise.</li>
20<li><i>validationDelay</i> - The delay in milliseconds for validation. Each time the user types something the field is validated after a specified delay, setting this value allows you to customize that delay (for example, if your custom validation routine is slow).</li>
21</ul>
22For more information on using this editor, see <a href="http://www.jackslocum.com/yui/2006/09/10/adding-built-in-editing-support-to-the-yahoo-ui-extensions-grid/">this blog post</a>.
23* @constructor
24* Create a new NumberEditor
25* @param {Object} config
26 */
27YAHOO.ext.grid.NumberEditor = function(config){
28 var element = document.createElement('input');
29 element.type = 'text';
30 element.className = 'ygrid-editor ygrid-num-editor';
31 element.setAttribute('autocomplete', 'off');
32 document.body.appendChild(element);
33 YAHOO.ext.grid.NumberEditor.superclass.constructor.call(this, element);
34 YAHOO.ext.util.Config.apply(this, config);
35};
36YAHOO.extendX(YAHOO.ext.grid.NumberEditor, YAHOO.ext.grid.CellEditor);
37
38YAHOO.ext.grid.NumberEditor.prototype.initEvents = function(){
39 var stopOnEnter = function(e){
40 if(e.browserEvent.keyCode == e.RETURN){
41 this.stopEditing(true);
42 }else if(e.browserEvent.keyCode == e.ESC){
43 this.setValue(this.originalValue);
44 this.stopEditing(true);
45 }
46 };
47
48 var allowed = "0123456789";
49 if(this.allowDecimals){
50 allowed += this.decimalSeparator;
51 }
52 if(this.allowNegative){
53 allowed += '-';
54 }
55 var keyPress = function(e){
56 var c = e.getCharCode();
57 if(c != e.BACKSPACE && allowed.indexOf(String.fromCharCode(c)) === -1){
58 e.stopEvent();
59 }
60 };
61 this.element.mon('keydown', stopOnEnter, this, true);
62 var vtask = new YAHOO.ext.util.DelayedTask(this.validate, this);
63 this.element.mon('keyup', vtask.delay.createDelegate(vtask, [this.validationDelay]));
64 this.element.mon('keypress', keyPress, this, true);
65 this.element.on('blur', this.stopEditing, this, true);
66};
67
68YAHOO.ext.grid.NumberEditor.prototype.validate = function(){
69 var dom = this.element.dom;
70 var value = dom.value;
71 if(value.length < 1){ // if it's blank
72 if(this.allowBlank){
73 dom.title = '';
74 this.element.removeClass('ygrid-editor-invalid');
75 return true;
76 }else{
77 dom.title = this.blankText;
78 this.element.addClass('ygrid-editor-invalid');
79 return false;
80 }
81 }
82 if(value.search(/\d+/) === -1){
83 dom.title = this.nanText.replace('%0', value);
84 this.element.addClass('ygrid-editor-invalid');
85 return false;
86 }
87 var num = this.parseValue(value);
88 if(num < this.minValue){
89 dom.title = this.minText.replace('%0', this.minValue);
90 this.element.addClass('ygrid-editor-invalid');
91 return false;
92 }
93 if(num > this.maxValue){
94 dom.title = this.maxText.replace('%0', this.maxValue);
95 this.element.addClass('ygrid-editor-invalid');
96 return false;
97 }
98 var msg = this.validator(value);
99 if(msg !== true){
100 dom.title = msg;
101 this.element.addClass('ygrid-editor-invalid');
102 return false;
103 }
104 dom.title = '';
105 this.element.removeClass('ygrid-editor-invalid');
106 return true;
107};
108
109YAHOO.ext.grid.NumberEditor.prototype.show = function(){
110 this.element.dom.title = '';
111 YAHOO.ext.grid.NumberEditor.superclass.show.call(this);
112 if(this.selectOnFocus){
113 try{
114 this.element.dom.select();
115 }catch(e){}
116 }
117 this.validate(this.element.dom.value);
118};
119
120YAHOO.ext.grid.NumberEditor.prototype.getValue = function(){
121 if(!this.validate()){
122 return this.originalValue;
123 }else{
124 var value = this.element.dom.value;
125 if(value.length < 1){
126 return value;
127 } else{
128 return this.fixPrecision(this.parseValue(value));
129 }
130 }
131};
132YAHOO.ext.grid.NumberEditor.prototype.parseValue = function(value){
133 return parseFloat(new String(value).replace(this.decimalSeparator, '.'));
134};
135
136YAHOO.ext.grid.NumberEditor.prototype.fixPrecision = function(value){
137 if(!this.allowDecimals || this.decimalPrecision == -1 || isNaN(value) || value == 0 || !value){
138 return value;
139 }
140 // this should work but doesn't due to precision error in JS
141 // var scale = Math.pow(10, this.decimalPrecision);
142 // var fixed = this.decimalPrecisionFcn(value * scale);
143 // return fixed / scale;
144 //
145 // so here's our workaround:
146 var scale = Math.pow(10, this.decimalPrecision+1);
147 var fixed = this.decimalPrecisionFcn(value * scale);
148 fixed = this.decimalPrecisionFcn(fixed/10);
149 return fixed / (scale/10);
150};
151
152YAHOO.ext.grid.NumberEditor.prototype.allowBlank = true;
153YAHOO.ext.grid.NumberEditor.prototype.allowDecimals = true;
154YAHOO.ext.grid.NumberEditor.prototype.decimalSeparator = '.';
155YAHOO.ext.grid.NumberEditor.prototype.decimalPrecision = 2;
156YAHOO.ext.grid.NumberEditor.prototype.decimalPrecisionFcn = Math.floor;
157YAHOO.ext.grid.NumberEditor.prototype.allowNegative = true;
158YAHOO.ext.grid.NumberEditor.prototype.selectOnFocus = true;
159YAHOO.ext.grid.NumberEditor.prototype.minValue = Number.NEGATIVE_INFINITY;
160YAHOO.ext.grid.NumberEditor.prototype.maxValue = Number.MAX_VALUE;
161YAHOO.ext.grid.NumberEditor.prototype.minText = 'The minimum value for this field is %0';
162YAHOO.ext.grid.NumberEditor.prototype.maxText = 'The maximum value for this field is %0';
163YAHOO.ext.grid.NumberEditor.prototype.blankText = 'This field cannot be blank';
164YAHOO.ext.grid.NumberEditor.prototype.nanText = '%0 is not a valid number';
165YAHOO.ext.grid.NumberEditor.prototype.validationDelay = 100;
166YAHOO.ext.grid.NumberEditor.prototype.validator = function(){return true;};
diff --git a/frontend/beta/js/YUI-extensions/grid/editor/SelectEditor.js b/frontend/beta/js/YUI-extensions/grid/editor/SelectEditor.js
new file mode 100644
index 0000000..200b8e3
--- a/dev/null
+++ b/frontend/beta/js/YUI-extensions/grid/editor/SelectEditor.js
@@ -0,0 +1,37 @@
1/**
2 * @class YAHOO.ext.grid.SelectEditor
3 * @extends YAHOO.ext.grid.CellEditor
4Creates an editor out of an existing select field. You can create the select element through DOM in Javascript and pass it to the SelectEditor's constructor <b>or</b> an easier way is like this:
5<br><br>
6Define the select field in your document, giving it the ygrid-editor class.
7<pre><code>
8&lt;select id="light" class="ygrid-editor"&gt;
9 &lt;option value="Shade"&gt;Shade&lt;/option&gt;
10 &lt;option value="Mostly Shady"&gt;Mostly Shady&lt;/option&gt;
11 &lt;option value="Sun or Shade"&gt;Sun or Shade&lt;/option&gt;
12 &lt;option value="Mostly Sunny"&gt;Mostly Sunny&lt;/option&gt;
13 &lt;option value="Sunny"&gt;Sunny&lt;/option&gt;
14&lt;/select&gt;
15</code></pre>
16Create the SelectEditor object, passing in the id of your select field.
17<pre><code>
18var editor = new YAHOO.ext.grid.SelectEditor('light');
19</code></pre>
20For more information on using this editor, see <a href="http://www.jackslocum.com/yui/2006/09/10/adding-built-in-editing-support-to-the-yahoo-ui-extensions-grid/">this blog post</a>.
21* @constructor
22* Create a new SelectEditor
23* @param {HTMLElement/String} element
24 */
25YAHOO.ext.grid.SelectEditor = function(element){
26 element.hideFocus = true;
27 YAHOO.ext.grid.SelectEditor.superclass.constructor.call(this, element);
28 this.element.swallowEvent('click');
29};
30YAHOO.extendX(YAHOO.ext.grid.SelectEditor, YAHOO.ext.grid.CellEditor);
31
32YAHOO.ext.grid.SelectEditor.prototype.fitToCell = function(box){
33 if(YAHOO.ext.util.Browser.isGecko){
34 box.height -= 3;
35 }
36 this.element.setBox(box, true);
37};
diff --git a/frontend/beta/js/YUI-extensions/grid/editor/TextEditor.js b/frontend/beta/js/YUI-extensions/grid/editor/TextEditor.js
new file mode 100644
index 0000000..3c97acd
--- a/dev/null
+++ b/frontend/beta/js/YUI-extensions/grid/editor/TextEditor.js
@@ -0,0 +1,110 @@
1/**
2 * @class YAHOO.ext.grid.TextEditor
3 * @extends YAHOO.ext.grid.CellEditor
4Provides basic text editing for a cells and supports the following configuration options:
5<ul class="list">
6<li><i>allowBlank</i> - True if the cell is allowed to be empty.</li>
7<li><i>minLength</i> - The minimum length the cell will accept.</li>
8<li><i>maxLength</i> - The maximum length the cell will allow.</li>
9<li><i>minText</i> - The tooltip to display when the length of the value in the cell is below the minimum.</li>
10<li><i>maxText</i> - The tooltip to display when the length of the value in the cell is above the maximum.</li>
11<li><i>selectOnFocus</i> - True to select the text when the editor is activated.</li>
12<li><i>blankText</i> - The tooltip (error message) to display when the cell is empty and is not allowed to be.</li>
13<li><i>regex</i> - A regular expression to match if the value is valid. If the regex.test(value) returns false, the value is considered invalid.</li>
14<li><i>regexText</i> - The tooltip (error message) to display when regex does not match.</li>
15<li><i>validator</i> - Any custom validation function you want called. The function must return true if the data is valid or an error message otherwise.</li>
16<li><i>validationDelay</i> - The delay in milliseconds for validation. Each time the user types something the field is validated after a specified delay, setting this value allows you to customize that delay (for example, if your custom validation routine is slow).</li>
17</ul>
18For more information on using this editor, see <a href="http://www.jackslocum.com/yui/2006/09/10/adding-built-in-editing-support-to-the-yahoo-ui-extensions-grid/">this blog post</a>.
19* @constructor
20* Create a new TextEditor
21* @param {Object} config
22 */
23YAHOO.ext.grid.TextEditor = function(config){
24 var element = document.createElement('input');
25 element.type = 'text';
26 element.className = 'ygrid-editor ygrid-text-editor';
27 element.setAttribute('autocomplete', 'off');
28 document.body.appendChild(element);
29 YAHOO.ext.grid.TextEditor.superclass.constructor.call(this, element);
30 YAHOO.ext.util.Config.apply(this, config);
31};
32YAHOO.extendX(YAHOO.ext.grid.TextEditor, YAHOO.ext.grid.CellEditor);
33
34YAHOO.ext.grid.TextEditor.prototype.validate = function(){
35 var dom = this.element.dom;
36 var value = dom.value;
37 if(value.length < 1){ // if it's blank
38 if(this.allowBlank){
39 dom.title = '';
40 this.element.removeClass('ygrid-editor-invalid');
41 return true;
42 }else{
43 dom.title = this.blankText;
44 this.element.addClass('ygrid-editor-invalid');
45 return false;
46 }
47 }
48 if(value.length < this.minLength){
49 dom.title = this.minText.replace('%0', this.minLength);
50 this.element.addClass('ygrid-editor-invalid');
51 return false;
52 }
53 if(value.length > this.maxLength){
54 dom.title = this.maxText.replace('%0', this.maxLength);
55 this.element.addClass('ygrid-editor-invalid');
56 return false;
57 }
58 var msg = this.validator(value);
59 if(msg !== true){
60 dom.title = msg;
61 this.element.addClass('ygrid-editor-invalid');
62 return false;
63 }
64 if(this.regex && !this.regex.test(value)){
65 dom.title = this.regexText;
66 this.element.addClass('ygrid-editor-invalid');
67 return false;
68 }
69 dom.title = '';
70 this.element.removeClass('ygrid-editor-invalid');
71 return true;
72};
73
74YAHOO.ext.grid.TextEditor.prototype.initEvents = function(){
75 YAHOO.ext.grid.TextEditor.superclass.initEvents.call(this);
76 var vtask = new YAHOO.ext.util.DelayedTask(this.validate, this);
77 this.element.mon('keyup', vtask.delay.createDelegate(vtask, [this.validationDelay]));
78};
79
80YAHOO.ext.grid.TextEditor.prototype.show = function(){
81 this.element.dom.title = '';
82 YAHOO.ext.grid.TextEditor.superclass.show.call(this);
83 this.element.focus();
84 if(this.selectOnFocus){
85 try{
86 this.element.dom.select();
87 }catch(e){}
88 }
89 this.validate(this.element.dom.value);
90};
91
92YAHOO.ext.grid.TextEditor.prototype.getValue = function(){
93 if(!this.validate()){
94 return this.originalValue;
95 }else{
96 return this.element.dom.value;
97 }
98};
99
100YAHOO.ext.grid.TextEditor.prototype.allowBlank = true;
101YAHOO.ext.grid.TextEditor.prototype.minLength = 0;
102YAHOO.ext.grid.TextEditor.prototype.maxLength = Number.MAX_VALUE;
103YAHOO.ext.grid.TextEditor.prototype.minText = 'The minimum length for this field is %0';
104YAHOO.ext.grid.TextEditor.prototype.maxText = 'The maximum length for this field is %0';
105YAHOO.ext.grid.TextEditor.prototype.selectOnFocus = true;
106YAHOO.ext.grid.TextEditor.prototype.blankText = 'This field cannot be blank';
107YAHOO.ext.grid.TextEditor.prototype.validator = function(){return true;};
108YAHOO.ext.grid.TextEditor.prototype.validationDelay = 200;
109YAHOO.ext.grid.TextEditor.prototype.regex = null;
110YAHOO.ext.grid.TextEditor.prototype.regexText = '';