-
Notifications
You must be signed in to change notification settings - Fork 0
/
slick.ext.editors.js
148 lines (119 loc) · 3.2 KB
/
slick.ext.editors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"Ext": {
"Editors": {
"TextEditorLimit": TextEditorLimit,
"SelectCellEditor": SelectCellEditor
}
}
}
});
function TextEditorLimit(args) {
var $input;
var defaultValue;
var scope = this;
this.init = function () {
$input = $("<INPUT type=text class='editor-text' onblur='return ( this.value.length < " + args.column.editorLimit + " )' onKeyPress='return ( this.value.length < " + args.column.editorLimit + " )' />")
.appendTo(args.container)
.bind("keydown.nav", function (e) {
if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT) {
e.stopImmediatePropagation();
}
})
.focus()
.select();
};
this.destroy = function () {
$input.remove();
};
this.focus = function () {
$input.focus();
};
this.getValue = function () {
return $input.val();
};
this.setValue = function (val) {
$input.val(val);
};
this.loadValue = function (item) {
defaultValue = item[args.column.field] || "";
$input.val(defaultValue);
$input[0].defaultValue = defaultValue;
$input.select();
};
this.serializeValue = function () {
return $input.val();
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
};
this.validate = function () {
if (args.column.validator) {
var validationResults = args.column.validator($input.val());
if (!validationResults.valid) {
return validationResults;
}
}
return {
valid: true,
msg: null
};
};
this.init();
}
function SelectCellEditor(args) {
var $select;
var defaultValue;
var scope = this;
this.init = function () {
var option_str = '<option value=""></option>';
var options = args.item[args.column.optionList]
var opt_values = options.split(',');
for (i = 0; i < opt_values.length; i++) {
v = opt_values[i];
// For data list option_str += "<OPTION value='" + v + "'>";
option_str += "<option value='" + v + "'>" + v + "</option>";
}
// FOr Data List $select = $("<input list='molds' name='mold'><datalist id='molds' tabIndex='0' class='editor-select'>" + option_str + "</datalist>");
$select = $("<select id='molds' tabIndex='0' class='editor-text'>" + option_str + "</select>");
$select.appendTo(args.container);
$select.focus();
};
this.destroy = function () {
$select.remove();
};
this.focus = function () {
$select.focus();
};
this.loadValue = function (item) {
defaultValue = item[args.column.field] || "";
$select.val(defaultValue);
$select[0].defaultValue = defaultValue;
$select.select();
};
this.serializeValue = function () {
return $select.val();
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return ($select.val() != defaultValue);
};
this.validate = function () {
return {
valid: true,
msg: null
};
};
this.getInputEl = function () {
return $select;
};
this.init();
}
})(jQuery);