DynamicForm_wev8.js
34.7 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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
if(typeof(MEC_NS) == 'undefined'){
MEC_NS = {};
}
MEC_NS.DynamicForm = function(type, id, mecJson){
this.type = type;
if(!id){
id = new UUID().toString();
}
this.id = id;
this.utils = require("utils");
if(!mecJson){
mecJson = this.getDefaultMecJson();
}
this.mecJson = mecJson;
};
/*获取id。 必需的方法*/
MEC_NS.DynamicForm.prototype.getID = function(){
return this.id;
};
/*获取设计的html, 页面上怎么显示控件完全依赖于此方法。 必需的方法*/
MEC_NS.DynamicForm.prototype.getDesignHtml = function(){
return getDesignHtml(this);
};
/*获取构建属性编辑窗体的html,添加和单击控件后会调用此方法,由此方法去构建属性编辑窗体。 必需的方法*/
MEC_NS.DynamicForm.prototype.getAttrDlgHtml = function(){
var theId = this.id;
var getDataFormatHtm = function () {
var htm = '\
<div class="mb-10 block-area">\
<div class="title" style="font-weight:normal;color:#666;">'+SystemEnv.getHtmlNoteName(4295)/*输出格式*/+'</div>\
<div class="form-group">\
<ul class="normal-list outformat-list" style="margin-bottom:0px;">\
<li>\
<div class="inline">\
<input name="key" type="hidden" value="DATAS">\
<input name="name" data-key="DATAS" type="text" class="form-control" value="">\
</div><div class="inline">\
<div class="ml-10">'+SystemEnv.getHtmlNoteName(4302)/*数据JSON对应KEY*/+'\
<div class="more-info pl-3" style="color:#108ee9;position:static;display:inline;"></div>\
</div>\
</div>\
</li>\
</ul>\
<ul class="normal-list outformat-list block-control hide">\
<li>\
<div class="inline">\
<div class="inline" style="width:60%;">\
<input name="key" type="hidden" value="STATUS_CODE">\
<input name="name" data-key="STATUS_CODE" type="text" class="form-control" value="">\
</div><div class="inline" style="width:10%;text-align:center;">\
-\
</div><div class="inline" style="width:30%;">\
<input name="value" type="text" class="form-control" value="">\
</div>\
</div><div class="inline">\
<div class="ml-10">'+SystemEnv.getHtmlNoteName(5257)/*结果状态码对应KEY - 正常响应对应的值*/+'</div>\
</div>\
</li><li>\
<div class="inline">\
<input name="key" type="hidden" value="ERROR_MSG">\
<input name="name" data-key="ERROR_MSG" type="text" class="form-control" value="">\
</div><div class="inline">\
<div class="ml-10">'+SystemEnv.getHtmlNoteName(5256)/*错误提示对应KEY*/+'</div>\
</div>\
</li>\
</ul>\
</div>\
</div>';
return htm;
};
var htm = '<div id="MAD'+theId+'" style="height: inherit;">\
<div class="title">'+SystemEnv.getHtmlNoteName(6276)+/*字段来源*/'</div>\
<div class="form-group">\
<div class="row">\
<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(4142)/*名称*/+'</span>\
<div class="col-m-8 required">\
<input id="formName_'+theId+'" class="form-control" type="text" data-autobind />\
</div>\
</div>\
\
<div class="row">\
<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(4255)/*来源*/+'</span>\
<span class="col-m-8 multi-checkbox">\
<span>\
<input name="sourceType_'+theId+'" type="checkbox" value="0"/>\
<span>'+SystemEnv.getHtmlNoteName(4376)/*表单*/+'</span>\
</span>\
<span>\
<input name="sourceType_'+theId+'" type="checkbox" value="2"/>\
<span>Url</span>\
</span>\
<span>\
<input name="sourceType_'+theId+'" type="checkbox" value="3"/>\
<span>'+SystemEnv.getHtmlNoteName(5268)/*接口*/+'</span>\
</span>\
</span>\
</div>\
\
<div data-source-content data-sourcetype0-content style="display: none;">\
<div class="row">\
<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(4377)/*表单*/+'</span>\
<div class="col-m-8 required" style="position: relative;">\
<input id="sourceTableName_'+theId+'" class="form-control" type="text" readonly/>\
<div class="search-before" style="position: absolute;top:2px;right:2px;"></div>\
<input id="sourceTableId_'+theId+'" type="hidden"/>\
</div>\
</div>\
<div class="row" style="position: relative;">\
<span class="col span-control pd-0"> </span> \
<div class="col-m-8">\
<div style="text-align:right;">\
<a class="table-design help-link inline">'+SystemEnv.getHtmlNoteName(6277)/*如何设计表单?*/+'</a>\
</div>\
</div>\
</div>\
<div class="row">\
<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(4378)/*条件*/+'</span>\
<div class="col-m-8" style="position:relative;">\
<textarea id="sourceTableCondition_'+theId+'" class="area-control" placeholder="'+SystemEnv.getHtmlNoteName(4594)/*查询条件,支持变量,如:id={id} and name={name}*/+'"></textarea>\
<div class="helper" for="sourceTableCondition">?</div>\
</div>\
</div>\
</div>\
\
<div data-source-content data-sourcetype2-content style="display: none;">\
<div class="row" style="position: relative;margin-bottom:0;">\
<span class="col-2 span-control">Url:</span>\
<div class="col-m-8 inline-icons required">\
<input type="text" id="sourceUrl_'+theId+'" class="form-control"/>\
<div class="helper" for="url" style="top:9px;">?</div>\
</div>\
</div>\
\
<div class="row" style="position: relative;">\
<span class="col span-control pd-0"> </span> \
<div class="col-m-8">\
<div style="text-align:right;">\
<a class="download-source-template help-link inline">'+SystemEnv.getHtmlNoteName(4288)/*下载模板*/+'</a>\
<a class="init-source-template help-link inline">'+SystemEnv.getHtmlNoteName(4289)/*使用模板*/+'</a>\
</div>\
</div>\
</div>\
</div>\
\
<div data-source-content data-sourcetype3-content style="display: none;">\
<div class="row">\
<div class="col-2 span-control">' + SystemEnv.getHtmlNoteName(6102) /*接口:*/+ '</div>\
<div class="col-m-8 required">\
<div class="col edit-before pd-72" style="width: 20px;text-align:left;"></div>\
<div id="apiName_'+theId+'" class="col ml-5 pd-7 link selectApi_tip"></div>\
</div>\
</div>\
'+getDataFormatHtm()+'\
</div>\
</div>'+''/*数据来源配置---end*/+'\
\
<div class="title">'+SystemEnv.getHtmlNoteName(5252)+/*数据展示*/'</div>\
<div class="form-group">\
<div class="row">\
<div class="col-2 span-control">\
'+SystemEnv.getHtmlNoteName(5253)+/*数据只读:*/'\
</div>\
<div class="col-m-8"><input type="checkbox" id="dataReadonly_'+theId+'"/></div>\
</div>\
</div>\
\
<div class="title">'+SystemEnv.getHtmlNoteName(6278)+/*数据存储*/'\
<div class="p-loading save-loading" style="top:6px;font-weight:normal;"><span>'+SystemEnv.getHtmlNoteName(4317)+'</span></div>\
</div>\
<div class="form-group">\
<div class="row">\
<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(6279)/*存储方式:*/+'</span>\
<span class="col-m-8 multi-checkbox">\
<span>\
<input name="saveType_'+theId+'" type="checkbox" value="0"/>\
<span>'+SystemEnv.getHtmlNoteName(4376)/*表单*/+'</span>\
</span>\
<span data-source-content data-sourcetype2-content data-sourcetype3-content style="display: none;">\
<input name="saveType_'+theId+'" type="checkbox" value="2"/>\
<span>Url</span>\
</span>\
</span>\
</div>\
\
<div data-savetype-content data-savetype0-content style="display: none;">\
<div class="row">\
<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(4201)+/*数据源:*/'</span>\
<div class="col-m-8">\
<div class="col-8">\
<select class="form-control" id="saveDataSource_'+theId+'">\
<option value="">(local)</option>\
</select>\
</div>\
<div class="col-4 pr-10"><input type="button" class="btn-control save-datasource-btn-clear" value="'+SystemEnv.getHtmlNoteName(4335)+/*清除缓存*/'"/></div>\
</div>\
</div>\
\
<div class="row">\
<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(4327)+/*表名:*/'</span>\
<div class="col-m-8">\
<select class="form-control save-tablename" id="saveTableName_'+theId+'">\
</select>\
</div>\
</div>\
\
<div class="title" style="font-weight:normal;color:#666;">\
'+SystemEnv.getHtmlNoteName(6280)+/*存储字段设置*/'\
</div>\
\
<div class="row">\
<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(6281)+/*存储字段名:*/'</span>\
<div class="col-m-8">\
<select class="form-control save-fieldname" id="saveFieldName_'+theId+'">\
</select>\
</div>\
</div>\
\
<div class="row">\
<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(6282)+/*存储字段值:*/'</span>\
<div class="col-m-8">\
<select class="form-control save-fieldvalue" id="saveFieldValue_'+theId+'">\
</select>\
</div>\
</div>\
\
<div class="row">\
<span class="col-2 span-control">'+SystemEnv.getHtmlNoteName(6283)+/*主数据关联字段:*/'</span>\
<div class="col-m-8">\
<select class="form-control save-mainfield" id="saveMainField_'+theId+'">\
</select>\
</div>\
</div>\
</div>\
\
<div data-savetype-content data-savetype2-content style="display: none;">\
<div data-source-content data-sourcetype2-content data-sourcetype3-content style="display: none;">\
<div class="row" style="position: relative;margin-bottom:0;">\
<span class="col-2 span-control">Url:</span>\
<div class="col-m-8 inline-icons">\
<input type="text" id="saveUrl_'+theId+'" class="form-control"/>\
<div class="helper" for="url" style="top:9px;">?</div>\
</div>\
</div>\
\
<div class="row" style="position: relative;">\
<span class="col span-control pd-0"> </span> \
<div class="col-m-8">\
<div style="text-align:right;">\
<a class="download-save-template help-link inline">'+SystemEnv.getHtmlNoteName(4288)/*下载模板*/+'</a>\
<a class="init-save-template help-link inline">'+SystemEnv.getHtmlNoteName(4289)/*使用模板*/+'</a>\
</div>\
</div>\
</div>\
</div>\
</div>\
</div>'+''/*数据存储---end*/+'\
</div>';
return htm;
};
/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.DynamicForm.prototype.afterAttrDlgBuild = function() {
var theId = this.id;
var $attrContainer = this.$attrContainer = $("#MAD_" + theId);
this.bindAttrDlgHtmlEvent();
$attrContainer.checkbox();
$("#formName_" + theId).val(this.mecJson["formname"]);
var sourceType = this.mecJson["sourceType"];
var $sourceType = $("input[type='checkbox'][name='sourceType_"+theId+"'][value='" + sourceType + "']");
if($sourceType.length > 0){
$sourceType.checked();
}
$("#sourceTableName_" + theId).val(this.mecJson["sourceTableName"]);
$("#sourceTableId_" + theId).val(this.mecJson["sourceTableId"]);
$("#sourceTableCondition_" + theId).val(this.mecJson["sourceTableCondition"]);
$("#sourceUrl_" + theId).val(this.mecJson["sourceUrl"]);
var sourceApiConfig = this.mecJson.sourceApiConfig;
var apiId = sourceApiConfig && sourceApiConfig.api.id || "";
var apiName = sourceApiConfig && sourceApiConfig.api.name || "";
$("#apiName_"+theId).data("last", apiId).text(apiName);
var sourceApiDataFormat = this.mecJson.sourceApiDataFormat;
var $apiAttr = $attrContainer.find("div[data-sourcetype3-content]");
sourceApiDataFormat && $apiAttr.find("ul.outformat-list > li").each(function(){
var $li = $(this);
var key = $("input[name='key']", $li).val();
if (sourceApiDataFormat[key]) {
var $name = $("input[name='name']", $li), $value = $("input[name='value']", $li);
if ($value.length) {
$name.val(sourceApiDataFormat[key].key);
$value.val(sourceApiDataFormat[key].value);
} else {
$name.val(sourceApiDataFormat[key]);
}
}
});
var dataReadonly = this.mecJson["dataReadonly"];
if (dataReadonly == "1") {
$("#dataReadonly_" + theId).attr("checked", "checked");
}
var saveType = this.mecJson["saveType"];
var $saveType = $("input[type='checkbox'][name='saveType_"+theId+"'][value='" + saveType + "']");
if($saveType.length > 0){
$saveType.attr("checked", "checked")
$saveType.triggerHandler("click");
}
//数据源相关设置
this.setSaveTypeDatasource(this.mecJson["saveDataSource"] || "$ECOLOGY_SYS_LOCAL_POOLNAME", this.mecJson["saveTableName"]);
$("#saveUrl_" + theId).val(this.mecJson["saveUrl"]);
};
/*获取JSON*/
MEC_NS.DynamicForm.prototype.getMecJson = function(){
var theId = this.id;
this.mecJson["id"] = theId;
this.mecJson["mectype"] = this.type;
var $attrContainer = $("#MAD_"+theId);
if($attrContainer.length > 0){
this.mecJson["formname"] = $("#formName_" + theId).val();
var $sourceType = $("input[type='checkbox'][name='sourceType_"+theId+"']:checked");
if($sourceType.length > 0){
this.mecJson["sourceType"] = $sourceType.val();
}
this.mecJson["sourceTableName"] = $("#sourceTableName_" + theId).val();
this.mecJson["sourceTableId"] = $("#sourceTableId_" + theId).val();
this.mecJson["sourceTableCondition"] = $("#sourceTableCondition_" + theId).val();
this.mecJson["sourceUrl"] = $("#sourceUrl_" + theId).val();
var $apiAttr = $attrContainer.find("div[data-sourcetype3-content]");
var formats = {};
$apiAttr.find("ul.outformat-list > li").each(function(){
var $li = $(this);
var key = $("input[name='key']", $li).val();
var keyName = $("input[name='name']", $li).val();
var keyValue = $("input[name='value']", $li).val();
if ($("input[name='value']", $li).length) {
formats[key] = { key: keyName, value: keyValue };
} else {
formats[key] = keyName;
}
});
this.mecJson["sourceApiDataFormat"] = formats;
this.mecJson["dataReadonly"] = $("#dataReadonly_" + theId).is(':checked') ? "1" : "0";
var $saveType = $("input[type='checkbox'][name='saveType_"+theId+"']:checked");
if($saveType.length > 0){
this.mecJson["saveType"] = $saveType.val();
}
this.mecJson["saveDataSource"] = $("#saveDataSource_" + theId).val();
this.mecJson["saveTableName"] = $("#saveTableName_" + theId).val();
this.mecJson["saveFieldName"] = $("#saveFieldName_" + theId).val();
this.mecJson["saveFieldValue"] = $("#saveFieldValue_" + theId).val();
this.mecJson["saveMainField"] = $("#saveMainField_" + theId).val();
this.mecJson["saveUrl"] = $("#saveUrl_" + theId).val();
}
return this.mecJson;
};
MEC_NS.DynamicForm.prototype.getDefaultMecJson = function(){
var count = $("abbr[m_type='DynamicForm']", "#homepageContainer").length;
return {
formname: SystemEnv.getHtmlNoteName(6287) + (count + 1),
sourceType: "0",
saveType: "0",
sourceApiConfig: this.getDefaultApiConfig()
};
};
MEC_NS.DynamicForm.prototype.getDefaultApiConfig = function(){
return {
api: {},
params: {
query: [],
body: {}
}
};
};
MEC_NS.DynamicForm.prototype.validate = function(){
var theId = this.id,
$pluginAttr = $('#MAD_' + theId);
if (!$pluginAttr.length) {
return true;
}
var mecJson = this.getMecJson(),
formName = mecJson.formname,
sourceType = mecJson.sourceType,
tableId = mecJson.sourceTableId,
sourceUrl = mecJson.sourceUrl,
sourceApiConfig = mecJson.sourceApiConfig || this.getDefaultApiConfig(),
selectApi = sourceApiConfig.api.id;
var isValid = ((sourceType == 0 && tableId) ||
(sourceType == 2 && sourceUrl) || (sourceType == 3 && selectApi)) && !!formName;
if(isValid){
return true;
}else{
var msg = "";
if(!formName){
msg = SystemEnv.getHtmlNoteName(6088); //表单名称未设置
$pluginAttr.find('#formName_' + theId).parents('.col-m-8').validate({
value: formName,
rules: [{
msg: '"' + SystemEnv.getHtmlNoteName(4497).replace(/[\:\:]/g, '') + '" ' + SystemEnv.getHtmlNoteName(6041) //表单名称
}]
});
}else{
msg = SystemEnv.getHtmlNoteName(6069); //请设置内容来源对应数据!
var validate = function (sourceValue, $field, msg, style) {
!sourceValue && $field.validate({
value: sourceValue,
rules: [{
msg: '"' + msg + '" ' + SystemEnv.getHtmlNoteName(6041)//未填写
}],
style: style
});
};
switch (sourceType) {
case "0":
validate(tableId, $("#sourceTableId_" + theId).closest(".col-m-8"), SystemEnv.getHtmlNoteName(4376));//表单
break;
case "2":
validate(sourceUrl, $("#sourceUrl_" + theId).closest(".col-m-8"), "Url");
break;
case "3":
validate(selectApi, $("#apiName_" + theId).closest(".col-m-8"), SystemEnv.getHtmlNoteName(5268));//接口
break;
}
}
return {
isValid: isValid,
msg: msg
};
}
};
$.extend(MEC_NS.DynamicForm.prototype, {
autoUpdate: function(){
var mecHandler = MECHandlerPool.getHandler(this.id);
//避免导入插件到低版本时报错
mecHandler && mecHandler.autobind && mecHandler.autobind.update();
},
bindAttrDlgHtmlEvent: function () {
var that = this, theId = this.id, $attrContainer = this.$attrContainer;
$attrContainer.on("click", ".more-info", function (e) {
var $this = $(this), $blockArea = $this.closest(".block-area");
$blockArea.find(".block-control").slideToggle(100, function () {
$this[$(this).is(":visible") ? "addClass" : "removeClass"]("hidden");
});
});
var $sourceType = $("input[type='checkbox'][name='sourceType_" + theId + "']");
$sourceType.on("click", function () {
var sourceType = $(this).val();
$("[data-source-content]").hide();
$("[data-sourcetype"+sourceType+"-content]").show();
});
//选择表单
var $tableSourceContent = $attrContainer.find("[data-sourcetype0-content]");
$tableSourceContent.find(".search-before").on("click", function () {
that.utils.openRcDialog("browser", {
title: SystemEnv.getHtmlNoteName(3418), //请选择
width: 700,
height: 500,
params:{
type: '1'
},
btn:[SystemEnv.getHtmlNoteName(3704),SystemEnv.getHtmlNoteName(3516)]
}, function(result) {
$("#sourceTableId_" + theId).val(result.id);
$("#sourceTableName_" + theId).val(result.name);
});
});
$tableSourceContent.on("click", ".table-design", function(e){
var dlg = top.createTopDialog();//获取Dialog对象
dlg.Model = true;
dlg.Width = $(document).width() * 0.8;//定义长度
dlg.Height = $(document).height() * 0.8;
dlg.URL = "/mobilemode/admin/dialog/sqlhelp/dynamicFormHelp.jsp";
dlg.Title = SystemEnv.getHtmlNoteName(6277); //如何设计表单?
dlg.btn = false;
dlg.show();
e.stopPropagation();
});
//字段来源url下载模板
var $urlSourceContent = $attrContainer.find("[data-sourcetype2-content]");
$urlSourceContent.on("click", ".download-source-template", function(e){
location.href = '/api/mobilemode/admin/designer/plugin/downloadTemplate?template=dynamicFormConfigTempletAction.jsp';
e.stopPropagation();
}).on("click", ".init-source-template", function(e){
$("#sourceUrl_" + theId).val("/mobilemode/actiontemplet/dynamicFormConfigTempletAction.jsp")
e.stopPropagation();
});
//存储url下载模板
var $urlSaveContent = $attrContainer.find("[data-savetype2-content]");
$urlSaveContent.on("click", ".download-save-template", function(e){
location.href = '/api/mobilemode/admin/designer/plugin/downloadTemplate?template=dynamicFormSubmitTempletAction.jsp';
e.stopPropagation();
}).on("click", ".init-save-template", function(e){
$("#saveUrl_" + theId).val("/mobilemode/actiontemplet/dynamicFormSubmitTempletAction.jsp")
e.stopPropagation();
});
require(["modal"], function(modal) {
var indexArr = [];
var urlTip = SystemEnv.getHtmlNoteName(6126).replace("#directory#", "/mobilemode/apps") + "<br/>"//1、存放位置:如果url为一个系统内部jsp必须放在/mobilemode/apps目录下
+ SystemEnv.getHtmlNoteName(6284) + " templet.jsp?name={name}" + "<br/>"//2、关于参数传递:如想传递一个当前页面参数name到后台,可通过在url上拼接参数实现,如:
+ SystemEnv.getHtmlNoteName(6285);//3、参数支持解析系统变量、页面参数以及数据集变量
var conditionTip = SystemEnv.getHtmlNoteName(6190);//支持系统变量、页面参数替换,格式:{name}
var showTip = function(msg, target){
indexArr.push(modal.tips(msg, target, {
area: ['300px', ''],
placement: "left"
}));
};
$tableSourceContent.find(".helper").on("click", function(e) {
showTip(conditionTip, $(this));
e.stopPropagation();
});
$urlSourceContent.find(".helper").on("click", function(e) {
showTip(urlTip, $(this));
e.stopPropagation();
});
$urlSaveContent.find(".helper").on("click", function(e) {
showTip(urlTip, $(this));
e.stopPropagation();
});
$("body").on("click", function(e) {
var $target = $(e.target);
var layero = $target.parents(".layui-layer-tips");
if(layero.length) return;
indexArr.map(function (v) {
modal.close(v);
});
});
});
//api选择
var $apiSourceContent = $attrContainer.find("[data-sourcetype3-content]");
$apiSourceContent.on("click", ".edit-before, .selectApi_tip", function(e){
var sourceApiConfig = that.mecJson.sourceApiConfig || that.getDefaultApiConfig();
that.utils.openRcDialog("api-config", {
title: SystemEnv.getHtmlNoteName(5239).replace(/[::]/g, ""),//接口配置
params: {
id: sourceApiConfig.api.id||"",
config: sourceApiConfig,
height: 506
}
}, function(result) {
that.mecJson.sourceApiConfig = result;
var selectApi = result.api || {};
var selectApiId = selectApi.id,
selectApiName = selectApi.name;
var $apiText = $apiSourceContent.find(".selectApi_tip");
var lastSourceValue = $apiText.data("last");
if(!selectApiId || selectApiId === lastSourceValue) return;
$apiText.data("last", selectApiId).text(selectApiName);
that.utils.api('api', {
action: "info",
type: "get",
data: {
"id": selectApiId
}
}).then(function (apiResult) {
apiResult = apiResult.data;
var resultDefine = apiResult.resultDefine || [];
//结果定义(输出参数)
var keyMap = {};
resultDefine.forEach(function(ele) {
var resultKey = ele.name || "";
if(resultKey.indexOf(".") === -1){
if(ele.type === "ARRAY"){
!keyMap.DATAS && (keyMap.DATAS = resultKey);
}
}
});
var $outFormatLi = $("ul.outformat-list > li", $attrContainer);
$outFormatLi.each(function(){
var $li = $(this);
var _key = $("input[name='key']", $li).val();
keyMap[_key] && $("input[name='name']", $li).val(keyMap[_key]);
});
});
});
});
var $tableSaveContent = $("div[data-savetype0-content]");
var $saveType = $("input[type='checkbox'][name='saveType_" + theId + "']");
$saveType.on("click", function () {
var type = $(this).val();
$("div[data-savetype-content]").hide();
$("div[data-savetype"+type+"-content]").show();
});
$("#saveDataSource_" + theId).on("change", function () {
that.saveTypeDatasourceChange($(this).val());
});
$tableSaveContent.on("change", ".save-tablename", function () {
that.saveTableNameChange();
});
$attrContainer.find(".save-datasource-btn-clear").on("click", function () {
var datasource = $("#saveDataSource_" + theId).val(),
tablename = $("#saveTableName_" + theId).val();
that.utils.api("designer/plugin", {
action: "removeTablesFromComInfo",
data: {
datasource: datasource
}
}, function (result) {
that.saveTypeDatasourceChange(datasource, tablename);
});
});
},
setSaveTypeDatasource: function (defDatasource, defTablename) {
var that = this,
theId = this.id;
this.utils.api("designer/plugin", {
action: "getDatasource",
notification: false,
data: {}
}, function (result) {
var html = result.data.reduce(function (prev, next) {
var selected = '';
if (next == defDatasource) {
selected = 'selected';
}
return prev += '<option value="' + next + '" ' + selected + '>' + next + '</option>';
}, '<option value="$ECOLOGY_SYS_LOCAL_POOLNAME">(local)</option>');
$("#saveDataSource_" + theId).html(html);
that.saveTypeDatasourceChange(defDatasource, defTablename);
});
},
saveTypeDatasourceChangeBefore: function () {
var theId = this.id,
$table = $("#saveTableName_" + theId),
$tableContainer = $table.parent();
if ($table.children().length > 0) {
$tableContainer.empty().append('<select class="form-control save-tablename" id="saveTableName_' + theId + '"></select>');
$("#saveTableName_" + theId).niceSelect();
}
},
saveTypeDatasourceChange: function (defDatasource, defTablename) {
var that = this,
theId = this.id;
this.saveTypeDatasourceChangeBefore();
var $saveType = $("input[type='checkbox'][name='saveType_" + theId + "']:checked");
var saveType = $saveType.length > 0 ? $saveType.val() : "0";
var loading = function(isLoading) {
if (saveType != "0") return;
var $datasource = $("#saveDataSource_" + theId),
$tablename = $("#saveTableName_" + theId),
$loading = that.$attrContainer.find(".p-loading.save-loading");
if (isLoading) {
$datasource.attr("disabled", true);
$tablename.attr("disabled", true);
$loading.show();
} else {
$datasource.removeAttr("disabled");
$tablename.removeAttr("disabled");
$loading.hide();
}
};
loading(true);
this.utils.api("designer/plugin", {
action: "getTablesByDataSource",
notification: false,
data: {
datasource: defDatasource
}
}, function (result) {
loading(false);
that.setTablenameOption(result.data, defTablename, $("#saveTableName_" + theId)[0]);
that.saveTableNameChange();
}, function (result) {
loading(false);
});
},
setTablenameOption: function (datas, defTablename, table) {
var theId = this.id,
$table = $(table);
var items = datas.reduce(function(prev, item){
if(item.table_type != 'VIEW' && item.table_name){
//选择框不允许空值
if(!defTablename){
defTablename = item.table_name;
}
if(item.table_name.toUpperCase() == defTablename.toUpperCase()){
var showText = item.table_name + (item.table_type == 'TABLE' ? ' ['+SystemEnv.getHtmlNoteName(4509)+']' : ''); //表
$table.empty().append('<option value="'+item.table_name+'" selected>'+showText+'</option>')
}
prev.push({
id: item.table_name,
text: item.table_name + (item.table_type == 'TABLE' ? ' ['+SystemEnv.getHtmlNoteName(4509)+']' : '') //表
});
}
return prev;
}, []);
$table.niceSelect({
pagination: true,
datas: items,
pageSize: 200
});
},
saveTableNameChange: function () {
var that = this, theId = this.id;
var datasource = $("#saveDataSource_" + theId).val(),
tablename = $("#saveTableName_" + theId).val();
this.utils.api("designer/plugin", {
action: "getFieldsByTable",
data: {
datasource: datasource,
tablename: tablename,
formType: 1
}
}, function (result) {
var datas = result.data;
$("#saveFieldName_" + theId).html(that.getFieldOptionHtml(datas, that.mecJson["saveFieldName"]));
$("#saveFieldValue_" + theId).html(that.getFieldOptionHtml(datas, that.mecJson["saveFieldValue"]));
$("#saveMainField_" + theId).html(that.getFieldOptionHtml(datas, that.mecJson["saveMainField"]));
});
},
getFieldOptionHtml: function (datas, defVal) {
return datas.reduce(function (html, item) {
var column_name = item.column_name;
var column_label = item.column_label;
html += '<option value="' + column_name + '"';
if (defVal && column_name && column_name.toLowerCase() == defVal.toLowerCase()) {
html += ' selected ';
}
if (column_label) {
column_name = column_name + ' [' + MLanguage.parse(column_label) + ']';
}
html += '>' + column_name + '</option>';
return html;
}, '<option value=""></option>');
}
});