Slide_wev8.js
17.4 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
if(typeof(MEC_NS) == 'undefined'){
MEC_NS = {};
}
MEC_NS.Slide = function(type, id, mecJson){
this.type = type;
if(!id){
id = new UUID().toString();
}
this.id = id;
if(!mecJson){
mecJson = this.getDefaultMecJson();
}
this.mecJson = mecJson;
};
/*加载数据*/
MEC_NS.Slide.loadData = function(callback) {
var _u = require('utils');
navPanel = _u.use('navPanel');
navPanel('loadNavItems', callback);
};
/*获取id。 必需的方法*/
MEC_NS.Slide.prototype.getID = function(){
return this.id;
};
/*获取设计的html, 页面上怎么显示控件完全依赖于此方法。 必需的方法*/
MEC_NS.Slide.prototype.getDesignHtml = function(){
return getDesignHtml(this);
};
/*获取构建属性编辑窗体的html,添加和单击控件后会调用此方法,由此方法去构建属性编辑窗体。 必需的方法*/
MEC_NS.Slide.prototype.getAttrDlgHtml = function(){
var theId = this.id;
var htm = "<div id=\"MADS_Silde_"+theId+"\" class=\"MADSSilde_Container\">"
+"<div class=\"title\">"
+SystemEnv.getHtmlNoteName(4650) //基本信息
+"</div>"
+ "<div class=\"form-group\">"
+ "<div class=\"row\">"
+ "<div class=\"col-2 span-control\">" + SystemEnv.getHtmlNoteName(4128) + "</div>" //高度:
+ "<div class=\"col-m-8\"><input type=\"text\" data-autobind='height' id=\"height_"+theId+"\" class=\"form-control\"/></div>"
+ "</div>"
+ "<div class=\"row\">"
+ "<div class=\"col-2 span-control\">" + SystemEnv.getHtmlNoteName(4133) + ":</div>" //轮播设置:
+ "<div class=\"col-m-8\"><select id=\"auto_"+theId+"\" class=\"form-control\">"
+ "<option value=\"0\">"+SystemEnv.getHtmlNoteName(4134)+"</option>" //不轮播
+ "<option value=\"3\">3"+SystemEnv.getHtmlNoteName(4135)+"</option>" //秒
+ "<option value=\"5\">5"+SystemEnv.getHtmlNoteName(4135)+"</option>" //秒
+ "<option value=\"7\">7"+SystemEnv.getHtmlNoteName(4135)+"</option>" //秒
+ "<option value=\"9\">9"+SystemEnv.getHtmlNoteName(4135)+"</option>" //秒
+ "</select></div>"
+ "</div>"
+ "<div class=\"row\">"
+ "<div class=\"col-2 span-control\">" + SystemEnv.getHtmlNoteName(4129) + "</div>" //延迟加载:
+ "<div class=\"col pd-7\"><input type=\"checkbox\" id=\"lazyLoad_"+theId+"\"/></div>"
+ "</div>"
+ "<div class=\"row\">"
+ "<div class=\"col-2 span-control\">" + SystemEnv.getHtmlNoteName(6119) + "</div>" //默认加载:
+ "<span class=\"col-m-8 multi-checkbox\">"
+ "<span>"
+ "<input type=\"checkbox\" name=\"defaultLoad_"+theId+"\" value=\"0\"/>"
+ "<span class=\"cbboxLabel\">"+ SystemEnv.getHtmlNoteName(6120) +"</span>" //第一张图片
+ "</span>"
+ "<span>"
+ "<input type=\"checkbox\" name=\"defaultLoad_"+theId+"\" value=\"1\"/>"
+ "<span class=\"cbboxLabel\">"+ SystemEnv.getHtmlNoteName(6121) +"</span>" //所有图片
+ "</span>"
+ "</span>"
+ "</div> "
+ "<div class=\"row\">"
+ "<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5078)+"</span>" //图片来源:
+ "<span class=\"col-8 pd-7\">"
+ "<div class=\"multi-switch\">"
+ "<span>"
+ "<input type=\"checkbox\" data-checkbox='false' name=\"slideBtnType_"+theId+"\" value=\"L\" onclick=\"MADS_ChangeSlideType(this, '"+theId+"');\"/><span>"+SystemEnv.getHtmlNoteName(4543)+"</span>"
+ "</span>"
+ "<span>"
+ "<input type=\"checkbox\" data-checkbox='false' name=\"slideBtnType_"+theId+"\" value=\"R\" onclick=\"MADS_ChangeSlideType(this, '"+theId+"');\"/><span>"+SystemEnv.getHtmlNoteName(4120)+"</span>"
+ "</span>"
+"</div>"
+ "</span>"
+ "</div>"
+ "</div>"
+ "<div class=\"title\">"
+ SystemEnv.getHtmlNoteName(5079)
+ "<div id=\"MADS_Silde_Add_"+theId+"\" data-autobind class=\"add-before MADS_Silde_Add\" data-scroll=\"bottom\" onclick=\"MADS_AddRow('"+theId+"');\">"+SystemEnv.getHtmlNoteName(3518)+"</div>"
+ "</div>"
+ "<div class=\"form-group\">"
+ "<div class=\"MADS_Silde_Container img-list form-group\" id=\"leftContainer_"+theId+"\">";
var pic_items = this.mecJson["pic_items"];
for(var i = 0; i < pic_items.length; i++){
htm += MADS_CreateRow(i, theId);
}
htm +=
" </div>"
+ "<div class=\"MADS_Silde_URLContainer\" id=\"rightContainer_"+theId+"\" style=\"display: none;\">"
+"<div class=\"MADS_Silde_URLBorder\">"
+ "<div class=\"row\">"
+ "<div class=\"col-m-3 span-control\">" + SystemEnv.getHtmlNoteName(4123) + "</div>" //来源URL:
+ "<div class=\"col-m-8\"><input type=\"text\" id=\"slideUrl_"+theId+"\" class=\"form-control\"/></div>"
+ "</div>"
+ "<div class=\"tip-control\" style=\"display:block;\">"
+ "<div>"+SystemEnv.getHtmlNoteName(4121)+SystemEnv.getHtmlNoteName(4122)+"</div>" //注: 返回数据类型为json数组
+ "<div>"+SystemEnv.getHtmlNoteName(4124)+" -- action</div>" //图片链接对应的key
+ "<div>"+SystemEnv.getHtmlNoteName(4124)+" -- pic_path</div>" //图片链接对应的key
+ "<div>"+SystemEnv.getHtmlNoteName(4124)+" -- pic_desc</div>"+ //图片链接对应的key
"<div>"+SystemEnv.getHtmlNoteName(4125)+"</div>" + //示例:
"<div>[{\"action\":\"/mobilemode/demo.jsp\",</div>" +
"<div>\"pic_path\":\"/mobilemode/demo.png\",</div>" +
"<div>\"pic_desc\":\""+SystemEnv.getHtmlNoteName(4126)+"1\"}]</div>" //图例
+"</div>"
+ "</div>"
+"</div>"
+"</div>"
+ "<div class=\"bottom\"><div class=\"save-btn\" onclick=\"refreshMecDesign('"+theId+"');\">"+SystemEnv.getHtmlNoteName(3451)+"</div></div>" //确定
+ "</div>"
+ "<div class=\"NoLessSide MAD_Warn\">"+SystemEnv.getHtmlNoteName(4137)+"</div>"; //幻灯片图片数不得少于1张
htm += "<div class=\"MAD_Alert\">"+SystemEnv.getHtmlNoteName(4115)+"</div>"; //已生成到布局
return htm;
};
MEC_NS.Slide.prototype.afterDesignHtmlBuild = function () {
var $con = $("#NMEC_" + this.id);
var $loading = $con.find(".wev-swipe-overlay");
$loading.hide();
$con.find("img").each(function () {
var $img = $(this);
var src = $img.attr("lazy-src");
$img.attr("src", src);
})
}
/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.Slide.prototype.afterAttrDlgBuild = function(){
var theId = this.id;
var mecHandler = MECHandlerPool.getHandler(theId);
var height = this.mecJson["height"]; //高度
var auto = this.mecJson["auto"]; //轮播秒数
var slideUrl = this.mecJson["slideUrl"]; // 来源url
$("#height_"+theId).val(height);
$("#auto_"+theId).val(auto);
$("#slideUrl_"+theId).val(slideUrl);
var lazyLoad = Mec_FiexdUndefinedVal(this.mecJson["lazyLoad"] , "0");
if(lazyLoad == "1"){
$("#lazyLoad_"+theId).attr("checked","checked");
}
var defaultLoad = Mec_FiexdUndefinedVal(this.mecJson["defaultLoad"] , "0");
var $defaultLoad = $('input[name="defaultLoad_'+theId+'"][value="'+defaultLoad+'"]');
if($defaultLoad.length > 0){
$defaultLoad.checked();
}
var slideBtnType = this.mecJson["slideBtnType"];
var $slideBtnType = $("input[type='checkbox'][name='slideBtnType_"+theId+"'][value='"+slideBtnType+"']");
if($slideBtnType.length > 0){
$slideBtnType.switched();
}
/*
if(slideBtnType == "R"){
$("#rightBtn_"+theId).addClass("checked");
$("#rightContainer_"+theId).show();
$("#MADS_Silde_Add").hide();
}else{
$("#leftBtn_"+theId).addClass("checked");
$("#leftContainer_"+theId).show();
}
$("#leftBtn_"+theId).click(function(){
$(this).addClass("checked");
$("#rightBtn_"+theId).removeClass("checked");
$("#leftContainer_"+theId).show();
$("#MADS_Silde_Add").show();
$("#rightContainer_"+theId).hide();
});
$("#rightBtn_"+theId).click(function(){
$(this).addClass("checked");
$("#leftBtn_"+theId).removeClass("checked");
$("#rightContainer_"+theId).show();
$("#leftContainer_"+theId).hide();
$("#MADS_Silde_Add").hide();
});
*/
var pic_items = this.mecJson["pic_items"];
for(var i = 0; i < pic_items.length; i++){
var p_item = pic_items[i];
var pic_type = p_item["pic_type"]; //0本地图片 1网址获取
var pic_path = p_item["pic_path"];
var pic_desc = p_item["pic_desc"];
var source = p_item["source"]; //1系统组件 2自定义
var uiid = p_item["uiid"];
var custom = p_item["custom"];
var jscode = p_item["jscode"];
var navContainer = $('#source_' +i+ '_' +theId).parent();
navPanel('setNav', navContainer, {
uiid: uiid,
custom: custom,
jscode: jscode,
sourcetype: source
});
$("#pic_type_"+i+"_"+theId).val(pic_type);
$("#pic_path_"+i+"_"+theId).val(pic_path);
MLanguage.setValue($("#pic_desc_"+i+"_"+theId), pic_desc);
$("#source_"+i+"_"+theId).val(source);
$("#ui_"+i+"_"+theId).val(uiid);
if(source==1){
//获取dataurl
var dataurl = UrlSelectUtil.MOBILE_PAGE_PREFIX + String(uiid).replace('homepage_',"");
//调用生成
UrlSelectUtil.link.setUrlLink($("#uiview_"+ i +"_"+theId).parent(),dataurl);
}else if(source==2){
UrlSelectUtil.link.setUrlLink($("#uiview_"+ i +"_"+theId).parent(),custom);
}else if(source==3){
$("#uiview_"+i+"_"+theId).val("脚本");
}
$("#custom_"+i+"_"+theId).val(custom);
$("#jscode_"+i+"_"+theId).val(jscode);
$("#source_"+i+"_"+theId).val(source);
$("#ui_"+i+"_"+theId).val(uiid);
MADS_SetPicPath(i, theId, pic_path);
}
MADS_TriggerTable(theId);
$("#MADS_Silde_"+theId + " .MADS_Silde_Container").sortable({
revert: false,
axis: "y",
items: ".MADS_Silde_Item",
cursor: "move",
update: function(){
mecHandler.autobind.update();
}
});
$("#MADS_Silde_"+theId).switcher({
onClick: function () {
mecHandler.autobind && mecHandler.autobind.update();
}
}).checkbox();
};
/*获取JSON*/
MEC_NS.Slide.prototype.getMecJson = function(){
var theId = this.id;
this.mecJson["id"] = theId;
this.mecJson["mectype"] = this.type;
var $attrContainer = $("#MADS_Silde_"+theId);
if($attrContainer.length > 0){
this.mecJson["height"] = $("#height_"+theId).val(); //高度
this.mecJson["auto"] = $("#auto_"+theId).val(); //轮播秒数
this.mecJson["slideUrl"] = $("#slideUrl_"+theId).val(); // 来源URL
this.mecJson["lazyLoad"] = $("#lazyLoad_"+theId).is(':checked') ? "1" : "0";// 延迟加载
this.mecJson["defaultLoad"] = $("input[name='defaultLoad_"+theId+"']:checked").val();
this.mecJson["slideBtnType"] = $("input[type='checkbox'][name='slideBtnType_"+theId+"']:checked").val();
var pic_items = [];
$("#MADS_Silde_"+theId + " .MADS_Silde_Container .MADS_Silde_Item").each(function(i){
var rowIndex = $(this).attr("rowIndex");
var p_item = {};
p_item["pic_type"] = $("#pic_type_"+rowIndex+"_"+theId).val(); //0本地图片 1网址获取
p_item["pic_path"] = $("#pic_path_"+rowIndex+"_"+theId).val();
p_item["pic_desc"] = MLanguage.getValue($("#pic_desc_"+rowIndex+"_"+theId));
p_item["source"] = $("#source_"+rowIndex+"_"+theId).val(); //1系统组件 2自定义
p_item["uiid"] = $("#ui_"+rowIndex+"_"+theId).val();
p_item["custom"] = $("#custom_"+rowIndex+"_"+theId).val();
p_item["jscode"] = $("#jscode_"+rowIndex+"_"+theId).val();
pic_items.push(p_item);
});
this.mecJson["pic_items"] = pic_items;
}
return this.mecJson;
};
MEC_NS.Slide.prototype.getDefaultMecJson = function(){
return {
id: this.id,
mectype: this.type,
height: 200,
auto: 0, //轮播秒数
slideBtnType: "L",
pic_items: [{
pic_type: "0", //0本地图片 1网址获取
pic_desc: SystemEnv.getHtmlNoteName(4325), // 描述
pic_path: "/mobilemode/piclibrary/03-E9_flat/slider01.jpg"
}, {
pic_type: "0", //0本地图片 1网址获取
pic_desc: SystemEnv.getHtmlNoteName(4325) + "2", // 描述
pic_path: "/mobilemode/piclibrary/03-E9_flat/slider02.jpg"
}]
};
};
MEC_NS.Slide.prototype.getEmptyPicPath = function(){
return "/mobilemode/images/mec/pic-icon_wev8.png";
};
function MADS_ChangeSlideType(cbObj, mec_id){
var objV = cbObj.value;
if(objV == "R"){
$("#MADS_Silde_Add_"+mec_id).hide();
$("#leftContainer_"+mec_id).hide();
$("#rightContainer_"+mec_id).show();
}else{
$("#rightContainer_"+mec_id).hide();
$("#leftContainer_"+mec_id).show();
$("#MADS_Silde_Add_"+mec_id).show();
}
}
function MADS_PicSet(rowIndex, mec_id){
var pic_typeV = $("#pic_type_"+rowIndex+"_"+mec_id).val();
var pic_pathV = $("#pic_path_"+rowIndex+"_"+mec_id).val();
var params = "pic_type=" + pic_typeV + "&pic_path=" + encodeURIComponent(pic_pathV);
showPicsetModal(params, function(result){
var picPath = result["pic_path"];
$("#pic_type_"+rowIndex+"_"+mec_id).val(result["pic_type"]);
$("#pic_path_"+rowIndex+"_"+mec_id).val(picPath);
MADS_SetPicPath(rowIndex, mec_id, picPath);
});
};
function MADS_SetPicPath(rowIndex, mec_id, picPath){
var $picAddbtn = $("#pic_addbtn_"+rowIndex+"_"+mec_id);
var $picImg = $("#pic_img_"+rowIndex+"_"+mec_id);
var mecHandler = MECHandlerPool.getHandler(mec_id);
if(picPath && picPath != ""){
$picAddbtn.hide();
$picImg.show();
$picImg[0].src = picPath;
}else{
$picImg.hide();
$picAddbtn.show();
}
mecHandler.autobind && mecHandler.autobind.update();
}
function MADS_TriggerTable(mec_id){
$("#MADS_Silde_"+mec_id + " .MADS_Silde_Container .MADS_Silde_Item").each(function(i){
var rowIndex = $(this).attr("rowIndex");
MADS_TriggerTableRow(rowIndex, mec_id);
});
}
function MADS_TriggerTableRow(rowIndex, mec_id){
MADS_SourceChange(rowIndex, mec_id);
}
function MADS_SourceChange(rowIndex, mec_id){
var sourceV = $("#source_"+rowIndex+"_"+mec_id).val();
var $ui = $("#ui_"+rowIndex+"_"+mec_id);
var $custom = $("#custom_"+rowIndex+"_"+mec_id);
var $jscode = $("#jscode_"+rowIndex+"_"+mec_id);
if(sourceV == "1"){
$custom.hide();
$jscode.hide();
$ui.show();
}else if(sourceV == "2"){
$ui.hide();
$jscode.hide();
$custom.show();
}else if(sourceV == "3"){
$custom.hide();
$ui.hide();
$jscode.show();
}
}
function MADS_DelRow(rowIndex, mec_id){
var mecHandler = MECHandlerPool.getHandler(mec_id);
var $MADS_Silde_Container = $("#MADS_Silde_"+mec_id + " .MADS_Silde_Container");
if($(".MADS_Silde_Item", $MADS_Silde_Container).length <= 1){
$("#MAD_"+mec_id+" .NoLessSide").fadeIn(1000, function(){
$(this).fadeOut(2000);
});
return;
}
$(".MADS_Silde_Item[rowIndex='"+rowIndex+"']",$MADS_Silde_Container).remove();
mecHandler.autobind.update();
}
function MADS_AddRow(mec_id){
var maxRowIndex = 0;
$("#MADS_Silde_"+mec_id + " .MADS_Silde_Container .MADS_Silde_Item").each(function(i){
var rowIndex = parseInt($(this).attr("rowIndex"));
if(rowIndex > maxRowIndex){
maxRowIndex = rowIndex;
}
});
var currRowIndex = maxRowIndex + 1;
var htm = MADS_CreateRow(currRowIndex, mec_id);
var $newRow = $(htm);
$("#MADS_Silde_"+mec_id + " .MADS_Silde_Container").append($newRow);
MADS_TriggerTableRow(currRowIndex, mec_id);
$newRow.MLanguage();
}
function MADS_CreateRow(currRowIndex, mec_id){
var htm =
"<div class=\"item row MADS_Silde_Item\" rowIndex=\""+currRowIndex+"\">"
+ "<div class=\"img-item col-4 MADS_Silde_Item_Img\" onclick=\"MADS_PicSet("+currRowIndex+",'"+mec_id+"');\">"
+ "<img id=\"pic_img_"+currRowIndex+"_"+mec_id+"\" style=\"display: none;\"/>"
+ "<input type=\"hidden\" id=\"pic_type_"+currRowIndex+"_"+mec_id+"\"/>"
+ "<input type=\"hidden\" id=\"pic_path_"+currRowIndex+"_"+mec_id+"\"/>"
+ "<div id=\"pic_addbtn_"+currRowIndex+"_"+mec_id+"\" class=\"light-add\"></div>"
+ "</div>"
+ "<div class=\"item-detail col-6 MADS_Silde_Item_Detail\">"
+ "<div class=\"row\">"
+ "<input type=\"text\" data-autobind id=\"pic_desc_"+currRowIndex+"_"+mec_id+"\" class=\"form-control\" placeholder=\""+SystemEnv.getHtmlNoteName(4582)+"\" "+MLanguage.ATTR+">" //请输入图片标题 / 描述
+ "</div>"
+ "<div class=\"MADS_Silde_Item_Detail2\">"
+ "<div class=\"sbHolder\" style=\"width: 100%;\"><a href=\"javascript:void(0);\" onclick=\"javascript:showNavPanel('#uiview_"+currRowIndex+"_"+mec_id+"');\" class=\"sbToggle sbToggle-btc\" style=\"right: 3px;top: 3px;\"></a>"
+ "<input class=\"panel-input\" readonly='readonly' unselectable='on' id=\"uiview_"+currRowIndex+"_"+mec_id+"\" autocomplete=\"off\" onclick=\"javascript:showNavPanel(this);\">"
+ "<input id=\"ui_"+currRowIndex+"_"+mec_id+"\" type=\"hidden\" />"
+ "<input id=\"source_"+currRowIndex+"_"+mec_id+"\" type=\"hidden\" />"
+ "<input id=\"custom_"+currRowIndex+"_"+mec_id+"\" type=\"hidden\"/>"
+ "<input id=\"jscode_"+currRowIndex+"_"+mec_id+"\" type=\"hidden\"/>"
+ "</div>"
+ "</div>"
+ "</div>"
+ "<div class=\"del-before\" onclick=\"MADS_DelRow("+currRowIndex+",'"+mec_id+"');\"></div>"
+ "</div>";
return htm;
}
function MADS_getUISelectOptionHtml(){
var htm = "<option value=\"\"></option>",
common_mec_nav_items = require('navPanel').getNavItems();
for(var i = 0; i < common_mec_nav_items.length; i++){
var uiid = common_mec_nav_items[i]["uiid"];
var uiname = common_mec_nav_items[i]["uiname"];
htm += "<option value=\""+uiid+"\">"+uiname+"</option>";
}
return htm;
}