Html_wev8.js 2.7 KB
if(typeof(MEC_NS) == 'undefined'){
	MEC_NS = {};
}

MEC_NS.Html = function(type, id, mecJson){
	this.type = type;
	if(!id){
		id = new UUID().toString();
	}
	this.id = id;
	if(!mecJson){
		mecJson = {};
	}
	this.editor = {};
	this.mecJson = mecJson;
	var that = this;
	require(['mec'], function(mec){
		that.remark = function(){
			return mec.remark(that.mecJson.htm);
        };
	});
}

/*获取id。 必需的方法*/
MEC_NS.Html.prototype.getID = function(){
	return this.id;
};

MEC_NS.Html.prototype.runWhenPageOnLoad = function () {
	//页面初始化会过滤掉html中的样式,因为需要重新渲染一次。
};

/*获取设计的html, 页面上怎么显示控件完全依赖于此方法。 必需的方法*/
MEC_NS.Html.prototype.getDesignHtml = function(){
	return getDesignHtml(this);
};

/*获取构建属性编辑窗体的html,添加和单击控件后会调用此方法,由此方法去构建属性编辑窗体。 必需的方法*/
MEC_NS.Html.prototype.getAttrDlgHtml = function(){
	var theId = this.id;
	
	var htm = "<div id=\"MADH_"+theId+"\" style=\"height: inherit;\">";
	htm += "<div class=\"html-control\" id=\"con_"+theId+"\" >";
		htm += "<div id=\"htm_"+theId+"\" class=\"content editor\"></div>";
	htm += "</div>";
	htm += "<div class=\"bottom\"><div class=\"save-btn\" onclick=\"refreshMecDesign('"+theId+"');\">"+SystemEnv.getHtmlNoteName(3451)+"</div></div>";  //确定
	htm += "</div>";
	
	htm += "<div class=\"MAD_Alert\">"+SystemEnv.getHtmlNoteName(4115)+"</div>";  //已生成到布局
	return htm;
};


/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.Html.prototype.afterAttrDlgBuild = function(){
	var that = this,
		theId = this.id;
	var mecHandler = MECHandlerPool.getHandler(theId);
	
	$('#' + 'MADH_' + theId).parent().height('100%'); // 将容器设置为100%高度 便于编辑器随容器高变化
	
	require(['htmlEditor'], function(htmlEditor) {
		that.editor = htmlEditor.editor('htm_'+theId, 'html', ['Mobile_NS']);
		that.editor.setValue(that.mecJson.htm || "", true);
		that.editor.getSession().on('change',function(){
			mecHandler.autobind.update();
		});
		$('#htm_' + theId).data('editor', that.editor);
	});
};

/*获取JSON*/
MEC_NS.Html.prototype.getMecJson = function(){
	var theId = this.id;
	
	this.mecJson["id"] = theId;
	this.mecJson["mectype"] = this.type;
	
	var $attrContainer = $("#MADH_"+theId);
	if($attrContainer.length > 0){
		this.editor.getValue && (this.mecJson["htm"] = this.editor.getValue());
	}
	return this.mecJson;
};

MEC_NS.Html.prototype.getHtm = function(){
	return Mec_FiexdUndefinedVal(this.mecJson["htm"]);
};