-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlegacy.js
More file actions
291 lines (256 loc) · 6.31 KB
/
legacy.js
File metadata and controls
291 lines (256 loc) · 6.31 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
Legacy = {
/**
* Namespace reserved for delegate instances
*/
references : { },
/**
* Namespace reserved for classes
*/
classes: { },
/**
* Namespace reserved for UI-scoped function definitions
*/
functions: {
noNAN : function(n) {
var out = 0;
if (isNaN(n) || n < 0) n = 0;
return n;
}
},
/**
* Namespace reserved for everything else
*/
xchng: { },
/**
* Generic init code for UI
*/
init: function() { },
/**
* Tools, collection of simple tools for UI development
*/
tools: {
/**
* Tool UI Init, preselect for selectboxes
*/
initUI:function(){
$("[preselect]").each(function(){ $(this).val($(this).attr("preselect")); });
},
/**
* Find the base component of a node
*
* @param $startNode
* @param compID
*/
findComponent: function($startNode, compID) {
var $comp = $startNode.parents("#"+compID);
if ($comp.size()>0) return $comp;
$relation = $startNode.parents("[data-belongsto]");
if ($relation.size()<1) return null;
var belongs = $relation.attr("data-belongsto");
var $comp = $("#"+belongs);
if ($comp.size()>0) return $comp;
return null;
},
/**
* Simple Translation function
* @param word
* @param language
*/
translate: function(word, language) {
var key = word.toLowerCase();
if (!UI.dictionary[language]) return word;
if (!UI.dictionary[language][key]) return word;
return UI.dictionary[language][key];
},
instances: {
}
},
/**
* Namespace reserved for dictionaries
*/
dictionary: {
"nl_nl": {
},
"us_en": {
}
},
/**
* Class Todo
* Represents a todo list
* A todo list is a very useful class that can be used to postpone actions.
*/
Todo: {
/**
* Static property tasks, contains tasks in the todo list.
*/
tasks: {},
/**
* Adds a task to the todo list
* @param n name of the list
* @param t function to add to the list
*/
add: function(n,t){ UI.Todo.tasks[n].push(t); },
/**
* Runs item n in the todo list
* @param n
*/
run: function(n){ for(var i in UI.Todo.tasks[n]){ UI.Todo.tasks[n][i]() } UI.Todo.create(n); },
/**
* Creates a new list
* @param n
*/
create: function(n){ UI.Todo.tasks[n]=[]; }
},
/**
* Date picker
*/
DatePicker : {
/**
* Applies the datapicker (standard jQuery Date picker plugin)
*/
applyDatePickers: function() { if (!$.datepicker) return;
$("input.date").each(function() {
var minDate = new Date($(this).attr('data-minDate'));
$(this).datepicker({
"dateFormat":"yy-mm-dd",
"minDate": minDate,
"buttonImage":"/static/source/shared/img/calendar.gif",
showOn: "button",
buttonImageOnly: true
});
});
}
},
/**
* Logger, can be used to log information about
* script execution and errors. Also makes sure console.log - will
* not cause problems in browsers that do not support the console feature.
*/
Logger: {
initLogger: function(){
if (window.console && window.console.log) return;
console = {
logs:[],
log: function(msg){
console.logs.push(msg);
}
}
}
},
UIObject: {
createNew: function( bundle ) {
var obj = {};
var protected = bundle;
protected.delegate = null;
protected.delegateID = protected.$targetNode.attr("data-delegate");
if (UI.references[protected.delegateID]) {
protected.delegate = UI.references[protected.delegateID];
}
protected.callDelegate = function( method, args ) {
if (protected.delegate && protected.delegate[method]) {
return protected.delegate[method].apply(protected.delegate,args);
}
else {
return null;
}
}
return obj;
}
},
Component: {
createNew: function( bundle ) {
var obj = UI.UIObject.createNew( bundle );
var protected = bundle;
if (protected.$targetNode.attr("data-config")) {
protected.config = protected.$targetNode.attr("data-config").toString().split(",");
}
else {
protected.config = [];
}
obj.hasConfig = function( item ) {
for(var i in protected.config) {
if (protected.config[i]==item) return true;
}
return false;
}
return obj;
}
},
/**
* Represents the server
*/
Server: {
/**
* Namespace for instances of Server
*/
instances: {},
/**
* Creates a new server. Just like anything else a server is connected
* to a node.
* @param $node
*/
createNew: function($node){
var obj = {};
var $targetNode = $node;
if ($targetNode.attr("id")) UI.Server.instances[ $targetNode.attr("id") ] = obj;
return obj;
},
/**
* Applies servers
*/
applyServers: function() {
$(".server").each(function(){
UI.Server.createNew( $(this) );
});
$(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError){
if (UI.Server.flags.userAbort) { UI.Server.flags.userAbort=0; return; }
notification("error","Request has failed. Try again or call support.");
$("#spinner").remove();
UI.Server.flags.busy = 0;
});
$(document).ajaxSend(function(e, jqxhr, settings){
//if (UI.Server.flags.busy) {
// jqxhr.abort();alert(1);
// return false;
//}
UI.Server.flags.busy = 1;
UI.Server.flags.timer = setTimeout(function(){
if ($("#spinner").size()==0 && UI.Server.flags.busy) $("body").append("<img id='spinner' style='position:fixed;left:50%;top:45%' src='/static/source/shared/img/spinner.gif?123'>");
},500);
});
$(document).ajaxComplete(function(e,xhr){
UI.Server.flags.busy = 0;
$("#spinner").remove();
});
$(document).ajaxSuccess(function(e,xhr){
UI.Server.flags.busy = 0;
$("#spinner").remove();
if (xhr.responseText.indexOf('<!DOCTYPE')===0) {
//loading HTML tag? that cannot be good.
document.location.href='/';
}
});
},
flags: { userAbort:0,busy:0,timer:0 }
},
applyFixedFormats: function(){
$(".fixformat2dec").each(function(){
if ($(this).attr("data-processed")=="yes") return;
$(this).attr("data-processed","yes");
$(this).change(function(){
var cellValue = $(this).val();
cellValue = cellValue.toString().replace(",",".");
var v = parseFloat( cellValue,10 );
if (v==NaN) {
v=0;
}
var newVal = v.toFixed(2);
if (isNaN(newVal)) newVal = 0;
$(this).val(newVal);
});
});
}
};
for(var i in Legacy) {
UI[i] = Legacy[i];
}