Weather_wev8.js 4.64 KB
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;
};