Weather_wev8.js
4.64 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
if(typeof(MEC_NS) == 'undefined'){
MEC_NS = {};
}
MEC_NS.Weather = 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(){
if(that.mecJson.cityType == '1'){
return mec.remark(SystemEnv.getHtmlNoteName(6178));
}
return mec.remark(that.mecJson.city);
};
});
};
/*获取id。 必需的方法*/
MEC_NS.Weather.prototype.getID = function(){
return this.id;
};
MEC_NS.Weather.prototype.runWhenPageOnLoad = function(){
this.afterDesignHtmlBuild();
};
/*获取设计的html, 页面上怎么显示控件完全依赖于此方法。 必需的方法*/
MEC_NS.Weather.prototype.getDesignHtml = function(){
return getDesignHtml(this);
};
/*页面上显示控件完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.Weather.prototype.afterDesignHtmlBuild = function(){
this.buildWeather();
};
MEC_NS.Weather.prototype.buildWeather = function(){
var theId = this.id;
if(this.mecJson.cityType == '1' || !this.mecJson.city || /{\w+}/.test(this.mecJson.city)){
Mobile_NS.showCurrentCityWeather(theId);
} else {
Mobile_NS.initWeather(theId, this.mecJson.city);
}
};
/*获取构建属性编辑窗体的html,添加和单击控件后会调用此方法,由此方法去构建属性编辑窗体。 必需的方法*/
MEC_NS.Weather.prototype.getAttrDlgHtml = function(){
var styleL = "_style" + _userLanguage;
var theId = this.id;
var htm = "<div id=\"MADWEA_"+theId+"\" style=\"padding-bottom: 10px;\">"
+ "<div class=\"title\">"+SystemEnv.getHtmlNoteName(4650)+"</div>" //天气信息
+ "<div class=\"form-group\">"
+ "<div class=\"row\">"
+ "<span class=\"col-2 span-control MADWEA_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(6179)+"</span>" //位置:
+ "<div class=\"col-m-8\">"
+ "<select class=\"form-control\" data-autobind id=\"cityType_"+theId+"\" onchange=\"cityTypeChange(this, '"+theId+"');\">"
+ "<option value=\"1\">"+SystemEnv.getHtmlNoteName(6178)+"</option>"//当前城市
+ "<option value=\"2\">"+SystemEnv.getHtmlNoteName(6177)+"</option>"//指定城市
+ "</select>"
+ "</div>"
+ "</div>"
+ "<div class=\"row specified-city\" style=\"display: none;\">"
+ "<span class=\"col-2 span-control MADWEA_BaseInfo_Label\">"+SystemEnv.getHtmlNoteName(6180)+"</span>" //指定城市:
+ "<div class=\"col-m-8\"><input class=\"form-control\" data-autobind id=\"city_"+theId+"\" type=\"text\"/></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;
};
var cityTypeChange = function(city, mec_id){
var $container = $('#MADWEA_' + mec_id);
var $city = $container.find('.specified-city');
var cityType = $(city).val();
if(cityType == '1'){
$city.hide();
}else {
$city.show();
}
}
/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.Weather.prototype.afterAttrDlgBuild = function(){
var theId = this.id;
var cityType = this.mecJson["cityType"] || '2';
var city = this.mecJson["city"];
if(this.mecJson["paramName"]){
city = '{' + this.mecJson["paramName"] + '}';
delete this.mecJson.paramName;
}
$("#cityType_" + theId).val(cityType).trigger('change');
$("#city_" + theId).val(city);
$("#MADWEA_"+theId).checkbox();
};
/*获取JSON*/
MEC_NS.Weather.prototype.getMecJson = function(){
var theId = this.id;
this.mecJson["id"] = theId;
this.mecJson["mectype"] = this.type;
var $attrContainer = $("#MADWEA_"+theId);
if($attrContainer.length > 0){
var $city = $("#city_" + theId);
var city = $city.val();
this.mecJson["city"] = city;
this.mecJson["cityType"] = $('#cityType_' + theId).val() || '1';
}
return this.mecJson;
};
MEC_NS.Weather.prototype.getDefaultMecJson = function(){
var theId = this.id;
var defMecJson = {};
defMecJson["id"] = theId;
defMecJson["mectype"] = this.type;
defMecJson["cityType"] = '1';
defMecJson["city"] = "上海";
return defMecJson;
};