FHandwriting_wev8.js
10.8 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
if(typeof(MEC_NS) == 'undefined'){
MEC_NS = {};
}
MEC_NS.FHandwriting = function(type, id, mecJson){
this.type = type;
if(!id){
id = new UUID().toString();
}
this.id = id;
if(!mecJson){
mecJson = this.getDefaultMecJson();
}
this.mecJson = mecJson;
var that = this;
require(['mec'], function(mec){
that.remark = function(){
return mec.remark(that.mecJson.fieldlabel);
};
});
};
/*获取id。 必需的方法*/
MEC_NS.FHandwriting.prototype.getID = function(){
return this.id;
};
/*获取设计的html, 页面上怎么显示控件完全依赖于此方法。 必需的方法*/
MEC_NS.FHandwriting.prototype.getDesignHtml = function(){
return getDesignHtml(this);
};
/*获取构建属性编辑窗体的html,添加和单击控件后会调用此方法,由此方法去构建属性编辑窗体。 必需的方法*/
MEC_NS.FHandwriting.prototype.getAttrDlgHtml = function(){
var styleL = "_style" + _userLanguage;
var theId = this.id;
var htm = "<div id=\"MADFHandwriting_"+theId+"\" class=\"MADFHandwriting_Container\">"
+"<div class=\"title\">"+SystemEnv.getHtmlNoteName(4650)+"</div>"
+"<div class=\"form-group\">"
+"<div class=\"row\">"
+"<span class=\"col-2 span-control MADFHandwriting_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4607)+"</span>" //所属表单:
+"<div class=\"col-m-8\"><select class=\"form-control\" data-autobind id=\"formid_"+theId+"\" onchange=\"MADFHandwriting_FormChange('"+theId+"')\">"+Mec_GetFormOptionHtml()+"</select></div>"
+"</div>"
+"<div class=\"row\">"
+"<span class=\"col-2 span-control MADFHandwriting_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4513)+"</span>" //对应字段:
+"<div class=\"col-m-8 required\"><select class=\"form-control requireded\" data-autobind onchange=\"Mec_SetFieldDefaultLabelName('" + theId + "')\" id=\"fieldname_" + theId + "\"></select></div>"
+ "<span class=\"col-4 search-control\">"
+ "<INPUT id=\"fieldSearch_"+theId+"\" class=\"form-control\" type=\"text\"/>"
+" <div id=\"fieldSearchResult_"+theId+"\" class=\"search-result MADFHandwriting_FieldSearchResult"+styleL+"\"><ul></ul></div>"
+ "<div id=\"fieldSearchTip_"+theId+"\" class=\"search-tip\">"+SystemEnv.getHtmlNoteName(4590)+"</div>" //在来源中检索...
+ "</span>"
+"</div>"
+"<div class=\"row\">"
+"<span class=\"col span-control pd-0\"> </span>"
+"<div>" + SystemEnv.getHtmlNoteName(6266) + "</div>" //提示:请选择附件类型字段
+"</div>"
+"<div class=\"row\">"
+"<span class=\"col-2 span-control MADFHandwriting_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4514)+"</span>" //显示名称:
+"<div class=\"col-m-8\"><input class=\"form-control\" onchange=\"$(this).attr('user-entered',true);\" data-autobind='fieldlabel' id=\"fieldlabel_"+theId+"\" type=\"text\" "+MLanguage.ATTR+"/></div>"
+"</div>"
+"<div class=\"row\">"
+"<span class=\"col-2 span-control MADFHandwriting_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4128)+"</span>" //高度:
+"<div class=\"col-m-8\"><input class=\"form-control\" data-autobind='height' id=\"height_"+theId+"\" type=\"text\" placeholder=\""+SystemEnv.getHtmlNoteName(4586)+"\"/></div>" //如:175,此处缺省为插件高度
+"</div>"
+"<div class=\"row\">"
+"<span class=\"col-2 span-control MADFHandwriting_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4515)+"</span>" //提示信息:
+"<div class=\"col-m-8\"><input class=\"form-control\" data-autobind='prompt' id=\"prompt_"+theId+"\" type=\"text\" placeholder=\""+SystemEnv.getHtmlNoteName(4624)+"\" "+MLanguage.ATTR+"/></div>" //输入手写前提示信息
+"</div>"
+"<div class=\"row\">"
+"<span class=\"col-2 span-control MADFHandwriting_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4531)+"</span>" //显示类型:
+"<div class=\"col-m-8\"><select class=\"form-control\" data-autobind id=\"showType_"+theId+"\">"
+"<option value=\"1\">"+SystemEnv.getHtmlNoteName(4532)+"</option>" //可编辑
+"<option value=\"2\">"+SystemEnv.getHtmlNoteName(4533)+"</option>" //只读
+"<option value=\"3\">"+SystemEnv.getHtmlNoteName(4534)+"</option>" //必填
+"</select></div>"
+"</div>"
+"</div>"
+"<div class=\"bottom\"><div class=\"save-btn\" onclick=\"refreshMecDesign('"+theId+"');\">"+SystemEnv.getHtmlNoteName(3451)+"</div></div>" //确定
+"</div>";
htm += "<div class=\"MAD_Alert\">"+SystemEnv.getHtmlNoteName(4115)+"</div>"; //已生成到布局
return htm;
};
/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.FHandwriting.prototype.afterAttrDlgBuild = function(){
var theId = this.id;
var $attrContainer = $("#MADFHandwriting_" + theId);
var formid = this.mecJson["formid"];// Form mec_id
var fieldname = this.mecJson["fieldname"];// 对应字段
var fieldlabel = this.mecJson["fieldlabel"];// 显示名称
var height = this.mecJson["height"];
var prompt = this.mecJson["prompt"]; //点击输入
var readonly = Mec_FiexdUndefinedVal(this.mecJson["readonly"], "0");
var required = Mec_FiexdUndefinedVal(this.mecJson["required"], "0");// 是否必填
if(required == "1"){
$("#showType_"+theId).val("3");
}else if(readonly == "1"){
$("#showType_"+theId).val("2");
}else{
$("#showType_"+theId).val("1");
}
$("#formid_"+theId).val(formid);
MADFHandwriting_FormChange(theId,fieldname);
MLanguage.setValue($("#fieldlabel_"+theId), fieldlabel);
$("#height_"+theId).val(height);
MLanguage.setValue($("#prompt_"+theId), prompt);
MADFHandwriting_InitFieldSearch(theId);
$("#MADFHandwriting_"+theId).checkbox();
$('#formid_' + theId, $attrContainer).on("select2:opening.formbefore", function () {
var $this = $(this);
var value = $this.val();
$(this).html(Mec_GetFormOptionHtml()).val(value);
});
};
//表单类控件更新所属表单相关信息的函数,当表单delete或change时触发
MEC_NS.FHandwriting.prototype.updateFormWithInfo = function (eventType) {
var theId = this.id;
if (eventType === 'delete') {
$('#formid_' + theId).empty();
$('#fieldname_' + theId).empty();
} else {
MADFHandwriting_FormChange(theId);
}
}
MEC_NS.FHandwriting.prototype.updateMecJsonByForm = function () {
this.mecJson['fieldname'] = '';
}
/*获取JSON*/
MEC_NS.FHandwriting.prototype.getMecJson = function(){
var theId = this.id;
this.mecJson["id"] = theId;
this.mecJson["mectype"] = this.type;
var $attrContainer = $("#MADFHandwriting_"+theId);
if($attrContainer.length > 0){
var formid=Mec_FiexdUndefinedVal($("#formid_"+theId).val());
var fieldname=Mec_FiexdUndefinedVal($("#fieldname_"+theId).val());
var fieldlabel = MLanguage.getValue($("#fieldlabel_"+theId));
var height = $("#height_"+theId).val();
var prompt = MLanguage.getValue($("#prompt_"+theId)); //点击输入
this.mecJson["formid"] = formid;
this.mecJson["fieldname"] = fieldname;
this.mecJson["fieldlabel"] = fieldlabel;
this.mecJson["height"] = height;
this.mecJson["prompt"] = prompt;
var showType = $("#showType_"+theId).val();
if(showType == "1"){
this.mecJson["required"] = "0";
this.mecJson["readonly"] = "0";
}else if(showType == "2"){
this.mecJson["required"] = "0";
this.mecJson["readonly"] = "1";
}else{
this.mecJson["required"] = "1";
this.mecJson["readonly"] = "0";
}
}
return this.mecJson;
};
MEC_NS.FHandwriting.prototype.getDefaultMecJson = function(){
var theId = this.id;
var defMecJson = {};
defMecJson["id"] = theId;
defMecJson["mectype"] = this.type;
defMecJson["fieldlabel"] = "";
defMecJson["height"] = "150";
defMecJson["prompt"] = "点击输入"; //SystemEnv.getHtmlNoteName(4625);
return defMecJson;
};
MEC_NS.FHandwriting.prototype.validate = function () {
var fieldname = this.mecJson.fieldname;
var isValid = !!fieldname;
if (!isValid) {
var mec_id = this.id;
var $pluginAttr = $('#MAD_' + mec_id);
$pluginAttr.find('#fieldname_' + mec_id).parents('.col-m-8').validate({
value: fieldname,
rules: [{
msg: '"' + SystemEnv.getHtmlNoteName(4513).replace(/[\:\:]/g, '') + '" ' + SystemEnv.getHtmlNoteName(6041) //对应字段
}],
});
}
return isValid;
};
function MADFHandwriting_ChangeComp(cbObj, mec_id){
setTimeout(function(){ //checkbox用了插件,不延时checkbox的checked状态获取不准确
if(cbObj.checked){
$("#compressWrap_"+mec_id).show();
}else{
$("#compressWrap_"+mec_id).hide();
}
},100);
}
function MADFHandwriting_FormChange(mec_id,selectedField){
var formidObj = $("#formid_"+mec_id);
var formid = formidObj.val();
Mec_GetFieldOptionHtml(formid, "fieldname_"+mec_id, selectedField);
}
function MADFHandwriting_InitFieldSearch(mec_id){
var $searchText = $("#fieldSearch_" + mec_id);
var $searchTextTip = $("#fieldSearchTip_" + mec_id);
$searchTextTip.click(function(e){
$searchText[0].focus();
e.stopPropagation();
});
$searchText.focus(function(){
$searchTextTip.hide();
});
$searchText.blur(function(){
if(this.value == ""){
$searchTextTip.show();
}
});
$searchText.click(function(e){
e.stopPropagation();
});
var $srarchResult = $("#fieldSearchResult_" + mec_id);
function hideSearchResult(){
$srarchResult.hide();
}
function showSearchResult(){
$srarchResult.show();
}
function clearSearchResult(){
$srarchResult.children("ul").find("*").remove();
}
var preSearchText = "";
$searchText.keyup(function(event){
if(this.value == ""){
preSearchText = "";
hideSearchResult();
clearSearchResult();
}else{
if(this.value != preSearchText){
preSearchText = this.value;
var searchValue = this.value;
//clearSearchResult();
var resultHtml = "";
var $vfieldName = $("#fieldname_" + mec_id);
$vfieldName.find("option").each(function(){
var vt = $(this).text();
var vv = $(this).attr("value");
if(vt.toLowerCase().indexOf(searchValue.toLowerCase()) != -1){
resultHtml += "<li><a href=\"javascript:MADFHandwriting_SetFieldSelected('"+mec_id+"','"+vv+"');\">"+vt+"</a></li>";
}
});
if(resultHtml == ""){
resultHtml = "<li><font class='tip'>"+SystemEnv.getHtmlNoteName(4270)+"</font></li>"; //无匹配的结果
}
$srarchResult.children("ul").html(resultHtml);
showSearchResult();
}
}
});
$("#MADFHandwriting_" + mec_id).bind("click", function(){
hideSearchResult();
});
}
function MADFHandwriting_SetFieldSelected(mec_id, v){
var $field = $("#fieldname_" + mec_id);
$field.val(v);
preSearchText = "";
var $searchText = $("#fieldSearch_" + mec_id);
$searchText.val("");
$searchText.trigger("blur");
MADFHandwriting_InitFieldSearch(mec_id);
}