global.js
23.5 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/// <reference path="jquery-1.11.1.js" />
var global = global || {
contextPath: '',
basePath: ''
};
global.scrollbarSize = '';
global.main = global.main || { mainTabs: null };
(function () {
if (typeof global.main.openTab !== 'function') {
/**
* 在主页中打开tab页
*
* @param id
* @param title
* @param src
*/
global.main.openTab = function (id, title, src) {
var tempwindow = window;
var tabcontrol = tempwindow.global.main.mainTabs;
while (tabcontrol == null && tempwindow != null) {
if (tempwindow == top) {
break;
}
tempwindow = tempwindow.parent;
tabcontrol = tempwindow.global.main.mainTabs;
}
if (!tabcontrol) {
console.info('global.main.mainTabs is null');
return;
}
global.openTab(tabcontrol, id, title, src);
};
}
if (typeof global.main.closeTab !== 'function') {
/**
* 在主页中关闭tab页
*
* @param id
* @param title
*/
global.main.closeTab = function (id, title) {
var tempwindow = window;
var tabcontrol = tempwindow.global.main.mainTabs;
while (tabcontrol == null && tempwindow != null) {
if (tempwindow == top) {
break;
}
tempwindow = tempwindow.parent;
tabcontrol = tempwindow.global.main.mainTabs;
}
if (!tabcontrol) {
console.info('global.main.mainTabs is null');
return;
}
global.closeTab(tabcontrol, id, title);
};
}
if (typeof global.openTab !== 'function') {
/**
* 打开tab页
*
* @param tabcontrol
* @param id
* @param title
* @param src
*/
global.openTab = function (tabcontrol, id, title, src) {
var page = null;
if (id) {
page = tabcontrol.tabs('getPage', id);
} else if (title) {
page = tabcontrol.tabs('getTab', title);
}
if (page) {
var tabIndex = tabcontrol.tabs('getTabIndex', page);
tabcontrol.tabs('select', tabIndex);
} else {
var opts = {
id: id,
title: title,
closable: true,
content: global.strfmt('<iframe src="{0}" allowTransparency="true" style="border: medium none; width: 100%; height: 100%; margin-bottom: -10px;" frameBorder="0"></iframe>', src),
border: false,
fit: true
};
tabcontrol.tabs('add', opts);
}
};
}
if (typeof global.getTab != 'function') {
/**
* 获取tab页
*
* @param tabcontrol
* @param id
* @param title
*/
global.getTab = function (tabcontrol, id, title) {
var page = null;
if (id) {
page = tabcontrol.tabs('getPage', id);
} else if (title) {
page = tabcontrol.tabs('getTab', title);
}
return page;
};
}
if (typeof global.closeTab !== 'function') {
/**
* 关闭tab页
*
* @param tabcontrol
* @param id
* @param title
*/
global.closeTab = function (tabcontrol, id, title) {
var page = null;
if (id) {
page = tabcontrol.tabs('getPage', id);
} else if (title) {
page = tabcontrol.tabs('getTab', title);
}
if (page) {
var tabIndex = tabcontrol.tabs('getTabIndex', page);
tabcontrol.tabs('close', tabIndex);
}
};
}
if (typeof global.modalDialog !== 'function') {
/**
* 显示模态对话框
*
* @param options
*/
global.modalDialog = function (options) {
var opts = $.extend({
title: ' ',
width: 640,
height: 480,
modal: true,
onClose: function () {
$(this).dialog('destroy');
}
}, options);
opts.modal = true;
if (options.url) {
opts.content = global.strfmt('<iframe src="{0}" allowTransparency="true" style="border: medium none; width: 100%; height: 100%; margin-bottom: -10px;" frameBorder="0"></iframe>', options.url);
}
return $('<div/>').dialog(opts);
};
}
if (typeof global.validate !== 'function') {
global.validate = function (dom) {
var result = true;
$(dom).find('.validatebox-text').each(function (index) {
if (!$(this).validatebox('isValid')) {
result = false;
return false;
}
});
return result;
};
}
if (typeof global.setdata !== 'function') {
global.setdata = function (dom, data) {
$(dom).find('.data-common').each(function (index) {
var fieldname = $(this).attr('name');
if (fieldname && data[fieldname]) {
$(this).val(data[fieldname]);
}
});
$(dom).find('.data-easyui').each(function (index) {
var fieldname = $(this).attr('textboxname');
var fieldvalue = data[fieldname];
if(!fieldvalue){
fieldvalue = "";
}
if (fieldvalue || "" == fieldvalue) {
if ($(this).hasClass('datetimebox-f')) {
if ($.isNumeric(fieldvalue)) {
$(this).datetimebox('setValue', global.datefmt(new Date(data[fieldname]), 'M/d/yyyy HH:mm:ss'));
} else {
$(this).datetimebox('setValue', fieldvalue);
}
} else if ($(this).hasClass('numberspinner-f')) {
$(this).numberspinner('setValue', fieldvalue);
} else if ($(this).hasClass('datetimespinner-f')) {
if ($.isNumeric(fieldvalue)) {
$(this).datetimespinner('setValue', global.datefmt(new Date(data[fieldname]), 'M/d/yyyy HH:mm:ss'));
} else {
$(this).datetimespinner('setValue', fieldvalue);
}
} else if ($(this).hasClass('timespinner-f')) {
if ($.isNumeric(fieldvalue)) {
$(this).timespinner('setValue', global.datefmt(new Date(data[fieldname]), 'HH:mm:ss'));
} else {
$(this).timespinner('setValue', fieldvalue);
}
} else if ($(this).hasClass('combobox-f')) {
var opts = $(this).combobox('options');
if (opts.multiple) {
fieldvalue = $(this).combobox('setValues', fieldvalue);
} else {
fieldvalue = $(this).combobox('setValue', fieldvalue);
}
} else if ($(this).hasClass('combo-f')) {
var opts = $(this).combobox('options');
if (opts.multiple) {
fieldvalue = $(this).combo('setValues', fieldvalue);
} else {
fieldvalue = $(this).combo('setValue', fieldvalue);
}
} else if ($(this).hasClass('textbox-f')) {
$(this).textbox('setValue', fieldvalue);
}
}
});
};
}
if (typeof global.getdata !== 'function') {
global.getdata = function (dom) {
var data = {};
$(dom).find('.data-common').each(function (index) {
var fieldname = $(this).attr('name');
var fieldvalue = $(this).val();
if (fieldname) {
data[fieldname] = fieldvalue;
}
});
$(dom).find('.data-easyui').each(function (index) {
var fieldname = $(this).attr('textboxname');
var fieldvalue = '';
if (fieldname) {
if ($(this).hasClass('datetimebox-f')) {
fieldvalue = $(this).datetimebox('getValue');
} else if ($(this).hasClass('datebox-f')) {
fieldvalue = $(this).datebox('getValue');
} else if ($(this).hasClass('numberspinner-f')) {
fieldvalue = $(this).numberspinner('getValue');
} else if ($(this).hasClass('datetimespinner-f')) {
fieldvalue = $(this).datetimespinner('getValue');
} else if ($(this).hasClass('timespinner-f')) {
fieldvalue = $(this).timespinner('getValue');
} else if ($(this).hasClass('spinner')) {
fieldvalue = $(this).spinner('getValue');
} else if ($(this).hasClass('combobox-f')) {
var opts = $(this).combobox('options');
if (opts.multiple) {
fieldvalue = $(this).combobox('getValues');
} else {
fieldvalue = $(this).combobox('getValue');
}
} else if ($(this).hasClass('combo-f')) {
var opts = $(this).combo('options');
if (opts.multiple) {
fieldvalue = $(this).combo('getValues');
} else {
fieldvalue = $(this).combo('getValue');
}
} else if ($(this).hasClass('textbox-f')) {
fieldvalue = $(this).textbox('getValue');
}
data[fieldname] = fieldvalue;
}
});
return data;
};
}
if (typeof global.cleardata !== 'function') {
global.cleardata = function (dom) {
$(dom).find('.data-common').each(function (index) {
$(this).val();
});
$(dom).find('.data-easyui').each(function (index) {
if ($(this).hasClass('datetimebox-f')) {
$(this).datetimebox('setValue', '');
} else if ($(this).hasClass('numberspinner-f')) {
$(this).numberspinner('setValue', '');
} else if ($(this).hasClass('combobox-f')) {
var valueField = $(this).combobox('options')['valueField'];
var data = $(this).combobox('getData');
if (data && $.isArray(data) && data.length > 0) $(this).combobox('setValue', data[0][valueField]);
} else if ($(this).hasClass('datetimespinner-f')) {
$(this).datetimespinner('setValue', '');
} else if ($(this).hasClass('timespinner-f')) {
$(this).timespinner('setValue', '');
} else if ($(this).hasClass('combobox-f')) {
$(this).combobox('setValue', '');
} else if ($(this).hasClass('combo-f')) {
$(this).combo('setValue', '');
} else if ($(this).hasClass('textbox-f')) {
$(this).textbox('setValue', '');
}
});
};
}
if (typeof global.stopPropagation !== 'function') {
/**
* 阻止事件冒泡
*
* @param e
* 事件参数
*/
global.stopPropagation = function (e) {
e = e || window.event;
e.preventDefault();
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
};
}
if (typeof global.strfmt !== 'function') {
/**
* 字符串格式化处理
*
* @param str
* 字符串格式
* @returns
*/
global.strfmt = function (str) {
if (!str || !arguments || arguments.length < 1) {
return;
}
for (var i = 0; i < arguments.length - 1; i++) {
str = str.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i + 1]);
}
return str;
};
}
if (typeof global.datefmt !== 'function') {
/**
* 字符串格式化处理
*
* @param date
* js日期对象
* @param format
* 日期时间格式字符串
* @returns
*/
global.datefmt = function (date, format) {
if (!format) {
return date.getTime();
}
var o = {
"M+": date.getMonth() + 1,
"d+": date.getDate(),
"H+": date.getHours(),
"h+": date.getHours(),
"m+": date.getMinutes(),
"s+": date.getSeconds(),
"q+": Math.floor((date.getMonth() + 3) / 3),
"S": date.getMilliseconds()
};
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
};
}
if (typeof global.syncpost !== 'function') {
global.syncpost = function (url, data, callback, type) {
var opts = { url: url, type: 'post', async: false };
if (data) {
if (typeof data === 'function') {
opts.success = data;
} else {
opts.data = data;
}
}
if (callback) {
if (typeof callback === 'function') {
opts.success = callback;
} else {
opts.dataType = type;
}
}
$.ajax(opts);
};
}
if (typeof global.syncget !== 'function') {
global.syncget = function (url, data, callback, type) {
var opts = { url: url, type: 'get', async: false };
if (data) {
if (typeof data === 'function') {
opts.success = data;
} else {
opts.data = data;
}
}
if (callback) {
if (typeof callback === 'function') {
opts.success = callback;
} else {
opts.dataType = type;
}
}
$.ajax(opts);
};
}
if (typeof global.menudom != 'function') {
global.menudom = function (data) {
if (!data || !data.items || !$.isArray(data.items)) return '';
var menu = $('<div/>');
for (var name in data) {
if (name == 'items') continue;
menu.attr(name, data[name]);
}
for (var i = 0; i < data.items.length; i++) {
var item = data.items[i];
var dataoptions = '';
var menuitem = $('<div/>');
for (var name in item) {
if (name == 'id') {
menuitem.attr('id', item[name]);
} else if (name == 'text') {
menuitem.text(item[name]);
} else {
dataoptions += name + ":'" + item[name] + "',";
}
}
if (dataoptions.length > 0) dataoptions = dataoptions.substr(0, dataoptions.length - 1);
menuitem.attr('data-options', dataoptions);
menu.append(menuitem);
}
return menu;
};
}
if (typeof global.typev !== 'function') {
global.typev = function (obj) {
var stype = Object.prototype.toString.call(obj);
return stype.substring(stype.indexOf(' ') + 1, stype.indexOf(']')).toLowerCase();
};
}
if (typeof global.isEqual !== 'function') {
global.isEqual = function (val1, val2) {
if (val1 == val2) return true;
var typeVal1 = typeof val1;
var typeVal2 = typeof val2;
if (typeVal1 == 'object' && (val1 instanceof Date)) typeVal1 = 'date';
if (typeVal2 == 'object' && (val1 instanceof Date)) typeVal2 = 'date';
if (typeVal1 == typeVal2 == 'undefined') {
return true;
} else if (typeVal1 == typeVal2 == 'boolean') {
return val1 && val2;
} else if ((typeVal1 == 'boolean' && typeVal2 == 'string')
|| (typeVal1 == 'string' && typeVal2 == 'boolean')) {
return (val1 + '') == (val2 + '');
} else if ((typeVal1 == 'undefined' && typeVal2 == 'string' && val2 == '')
|| (typeVal1 == 'string' && typeVal2 == 'undefined' && val1 == '')) {
return true;
} else if ((typeVal1 == 'number' && typeVal2 == 'string')
|| (typeVal1 == 'string' && typeVal2 == 'number')) {
return val1 == val2;
} else if (typeVal1 == 'number' && typeVal2 == 'date') {
return val1 == val2.getTime();
} else if (typeVal1 == 'date' && typeVal2 == 'number') {
return val1.getTime() == val2;
} else {
return false;
}
return false;
};
}
if (typeof global.serverdata !== 'function') {
global.serverdata = function (data, prefix) {
prefix = prefix ? prefix + '.' : '';
var result = {};
for (var name in data) {
if (!data[name]) {
result[prefix + name] = data[name];
continue;
}
if ($.isArray(data[name])) {
result[prefix + name] = JSON.stringify(data[name]);
continue;
}
var dtype = typeof data[name];
if (dtype == 'string' || dtype == 'number' || dtype == 'boolean' || data[name] instanceof Date) {
result[prefix + name] = data[name];
} else if (dtype == 'object') {
var tmp = dist.global.serverdata(data[name], prefix + name);
$.extend(true, result, tmp);
}
}
return result;
};
}
if (typeof global.guidGenerator !== 'function') {
global.guidGenerator = function (format) {
var S4 = function () {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
format = format || 'N';
format = format.toUpperCase();
if (format == 'N') {
return (S4() + S4() + S4() + S4() + S4() + S4() + S4() + S4());
} else if (format == 'D') {
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
} else if (format == 'B') {
return ('{' + S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4() + '}');
} else if (format == 'P') {
return ('(' + S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4() + ')');
} else {
return '00000000-0000-0000-0000-00000000000';
}
};
}
if (typeof global.getScrollbarSize !== 'function') {
global.getScrollbarSize = function () {
if (!global.scrollbarSize) {
var noScroll, scroll, oDiv = document.createElement("DIV");
oDiv.style.cssText = "position:absolute; top:-1000px; width:100px; height:100px; overflow:hidden;";
noScroll = document.body.appendChild(oDiv).clientWidth;
oDiv.style.overflowY = "scroll";
scroll = oDiv.clientWidth;
document.body.removeChild(oDiv);
global.scrollbarSize = noScroll - scroll;
}
return global.scrollbarSize;
};
}
if (typeof global.getParameter !== 'function') {
global.getParameter = function (str, name) {
if (!str) return null;
if (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = str.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
} else {
var params = {};
var arr = str.substr(1).split('&');
for (var i = 0; i < arr.length; i++) {
var parr = arr[i].split('=');
params[parr[0]] = unescape(parr[1]);
}
return params;
}
};
}
if (typeof global.findItem !== 'function') {
global.findItem = function (source, key, keyField) {
source = source || [];
keyField = keyField || 'id';
for (var i = 0; i < source.length; i++) {
if (source[i][keyField] == key) {
return source[i];
}
}
return null;
};
}
})();
function DomEditMgr(dom) {
this.dom = dom;
global.cleardata(this.dom);
this.orginalData = global.getdata(this.dom);
this.setdata = function (data) {
global.setdata(this.dom, data);
this.orginalData = data;
return this;
};
this.getdata = function () {
return global.getdata(this.dom);
};
this.cleardata = function () {
global.cleardata(this.dom);
this.orginalData = global.getdata(this.dom);
return this;
};
this.setunmodify = function () {
this.orginalData = global.getdata(this.dom);
return this;
};
this.revert = function () {
global.setdata(this.dom, this.orginalData);
return this;
}
this.ischanged = function () {
var data = global.getdata(this.dom);
var result = false;
for (var name in data) {
if (!global.isEqual(data[name], this.orginalData[name])) {
return true;
}
}
return result;
};
this.getdom = function () {
return this.dom;
};
};
function DataMgr() {
var orginal = null;
var current = null;
this.dataLoaded = false;
this.init = function (data) {
this.dataLoaded = true;
if (!data) {
current = {};
orginal = {};
return;
}
orginal = data;
current = $.extend(true, {}, data);
};
this.getData = function (name) {
if (!current) return null;
if (name) return current[name];
return current;
};
this.setData = function (data, name) {
if (!current) current = {};
if (name) {
current[name] = data;
} else {
for (var n in data) {
current[n] = data[n];
}
}
};
}