]> git.argeo.org Git - gpl/argeo-slc.git/blob - CellEditorFactory.js
1be48083699f5b34fef07475ade92057e5ae4597
[gpl/argeo-slc.git] / CellEditorFactory.js
1 /*******************************************************************************
2 *
3 * Argeo
4 *
5 ******************************************************************************/
6
7 /**
8 * A cell editor factory creating text fields or disabled text fields.
9 *
10 */
11 qx.Class.define("org.argeo.slc.ria.execution.CellEditorFactory",
12 {
13 extend : qx.ui.table.cellrenderer.Default,
14 implement : qx.ui.table.ICellEditorFactory,
15
16 /*
17 * ****************************************************************************
18 * CONSTRUCTOR
19 * ****************************************************************************
20 */
21
22 construct : function() {
23 this.base(arguments);
24 },
25
26 /*
27 * ****************************************************************************
28 * PROPERTIES
29 * ****************************************************************************
30 */
31
32 properties : {
33
34 /**
35 * function that validates the result the function will be called with
36 * the new value and the old value and is supposed to return the value
37 * that is set as the table value.
38 */
39 validationFunction : {
40 check : "Function",
41 nullable : true,
42 init : null
43 }
44
45 },
46
47 /*
48 * ****************************************************************************
49 * MEMBERS
50 * ****************************************************************************
51 */
52 members : {
53
54 // overridden
55 _getContentHtml : function(cellInfo) {
56 var table = cellInfo.table;
57 var tableModel = table.getTableModel();
58 var rowData = tableModel.getRowData(cellInfo.row);
59 var metaData = rowData[2];
60 if (metaData.disabled) {
61 return '<span style="color:#999;">' + qx.bom.String.escape(this._formatValue(cellInfo)) + '</span>';
62 }else{
63 return qx.bom.String.escape(this._formatValue(cellInfo));
64 }
65 },
66
67
68 // interface implementation
69 createCellEditor : function(cellInfo) {
70 var table = cellInfo.table;
71 var tableModel = table.getTableModel();
72 var rowData = tableModel.getRowData(cellInfo.row);
73 var metaData = rowData[2];
74 if (metaData.disabled) {
75 return null; // var cellEditor = new
76 // qx.ui.table.celleditor.TextField();
77 }
78
79 var cellEditor = new qx.ui.form.TextField;
80 cellEditor.setAppearance("table-editor-textfield");
81 cellEditor.originalValue = cellInfo.value;
82 if (cellInfo.value === null) {
83 cellInfo.value = "";
84 }
85 cellEditor.setValue("" + cellInfo.value);
86
87 cellEditor.addListener("appear", function() {
88 cellEditor.selectAll();
89 });
90
91 var validationFunc;
92 if (metaData.subType == "integer") {
93 validationFunc = function(newValue, oldValue){
94 var isNum = !isNaN(newValue * 1);
95 if (!isNum) {
96 alert("Warning, this field only accepts Integers!");
97 return oldValue;
98 }
99 return newValue;
100 };
101 }
102
103 cellEditor.setUserData("validationFunc", validationFunc);
104
105 return cellEditor;
106 },
107
108 // interface implementation
109 getCellEditorValue : function(cellEditor) {
110 var value = cellEditor.getValue();
111 var validationFunc = cellEditor.getUserData("validationFunc");
112
113 // validation function will be called with new and old value
114 // var validationFunc = this.getValidationFunction();
115 if (validationFunc) {
116 value = validationFunc(value, cellEditor.originalValue);
117 }
118
119 if (typeof cellEditor.originalValue == "number") {
120 value = parseFloat(value);
121 }
122
123 return value;
124 }
125 }
126 });