FRange_wev8.js 9.72 KB
if(typeof(MEC_NS) == 'undefined'){
	MEC_NS = {};
}

MEC_NS.FRange = 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.FRange.prototype.getID = function(){
	return this.id;
};

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

/*获取构建属性编辑窗体的html,添加和单击控件后会调用此方法,由此方法去构建属性编辑窗体。 必需的方法*/
MEC_NS.FRange.prototype.getAttrDlgHtml = function(){

	var theId = this.id;
	
	var htm = "<div id=\"MADFRange_"+theId+"\" style=\"padding-bottom: 10px;\">";
	htm+="<div class=\"title\">"+SystemEnv.getHtmlNoteName(4650)+"</div>";  
    htm+="<div class=\"form-group\">";
    htm+="<div class=\"row\">";
    htm+="<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4607)+"</span>";  //所属表单:
    htm+="<div class=\"col-m-8\"><select class=\"form-control\" data-autobind id=\"formid_"+theId+"\" onchange=\"MADFRange_FormChange('"+theId+"')\">"+Mec_GetFormOptionHtml()+"</select></div>";
    htm+="</div>";
    htm+="<div class=\"row\">";
    htm+="<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4513)+"</span>";  //对应字段:
    htm+="<div class=\"col-m-8 required\"><select class=\"form-control requireded\" data-autobind onchange=\"Mec_SetFieldDefaultLabelName('"+theId+"')\" id=\"fieldname_"+theId+"\"></select></div>";
    htm+="</div>";
    htm+="<div class=\"row\">";
    htm+="<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4514)+"</span>";  //显示名称:
    htm+="<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>";
    htm+="</div>";
    htm+="<div class=\"row\">";
    htm+="<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4610)+":</span>";  //最小值:
    htm+="<div class=\"col-m-8\"><input class=\"form-control\" id=\"min_"+theId+"\" type=\"text\" /></div>";
    htm+="</div>";
    htm+="<div class=\"row\">";
    htm+="<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4611)+":</span>";  //最大值:
    htm+="<div class=\"col-m-8\"><input class=\"form-control\" id=\"max_"+theId+"\" type=\"text\" /></div>";
    htm+="</div>";
    htm+="<div class=\"row\">";
    htm+="<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5065)+"</span>";  //步长:
    htm+="<div class=\"col-m-8\"><input class=\"form-control\" id=\"step_"+theId+"\" type=\"text\" /></div>";
    htm+="</div>";
	htm+="<div class=\"row\">";
	htm+="<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4531)+"</span>";  //显示类型:
	htm+="<div class=\"col-m-8\"><select class=\"form-control\" data-autobind id=\"showType_"+theId+"\">";
	htm+="<option value=\"1\">"+SystemEnv.getHtmlNoteName(4532)+"</option>";  //可编辑
	htm+="<option value=\"2\">"+SystemEnv.getHtmlNoteName(4533)+"</option>";  //只读
	htm+="<option value=\"3\">"+SystemEnv.getHtmlNoteName(4534)+"</option>";  //必填
	htm+="</select></div>";
	htm+="</div>";
    htm+="<div class=\"row\">";
    htm+="<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4535)+"</span>";  //默认值:
    htm+="<div class=\"col-m-8 pd-7\"><span class=\"edit-before\" onclick=\"MADFRange_editOneInParamOnPage('"+theId+"')\"></span>";
    htm+="<span id=\"paramValue_"+theId+"\"></span></div>";
    htm+"</div>";
    htm+="</div>";
    htm+="<div class=\"row\">";
    htm+="<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5476)+"</span>";  //内容换行:
    htm+="<div class=\"col-2 pd-4\"><input type=\"checkbox\" id=\"needWrap_"+theId+"\"/></div>";
    htm+="</div>";
    htm+="<div class=\"bottom\">";
    htm+="<div class=\"save-btn\" onclick=\"refreshMecDesign('"+theId+"');\">"+SystemEnv.getHtmlNoteName(3451)+"</div>";  //确定
    htm+="</div>";
    htm+="</div>";
	htm += "<div class=\"MAD_Alert\">"+SystemEnv.getHtmlNoteName(4115)+"</div>";  //已生成到布局
	return htm;
};

/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.FRange.prototype.afterAttrDlgBuild = function(){
	var theId = this.id;
	var $attrContainer = $("#MADFRange_" + theId);

	var formid = this.mecJson["formid"];
	var fieldname = this.mecJson["fieldname"];
	var fieldlabel = this.mecJson["fieldlabel"];
	var readonly = Mec_FiexdUndefinedVal(this.mecJson["readonly"], "0");
	var required = Mec_FiexdUndefinedVal(this.mecJson["required"], "0");// 是否必填
	var defaultvalue = this.mecJson["defaultvalue"];
	$("#formid_"+theId).val(formid);
	MADFRange_FormChange(theId,fieldname);
	MLanguage.setValue($("#fieldlabel_"+theId), fieldlabel);
	if(required == "1"){
		$("#showType_"+theId).val("3");
	}else if(readonly == "1"){
		$("#showType_"+theId).val("2");
	}else{
		$("#showType_"+theId).val("1");
	}
	var needWrap = Mec_FiexdUndefinedVal(this.mecJson["needWrap"], 0);
	if(needWrap == "1"){
		$("#needWrap_"+theId).checked();
	}
	
	$("#defaultvalue_"+theId).val(defaultvalue);
	
	var inParams = this.mecJson["inParams"];
	for(var i = 0; inParams && i < inParams.length; i++){
		$("#paramValue_"+theId).text(inParams[i]["paramValue"]);
		break;
	}
	$("#min_"+theId).val(this.mecJson["min"]);
	$("#max_"+theId).val(this.mecJson["max"]);
	$("#step_"+theId).val(this.mecJson["step"]);

	var mecHandler = MECHandlerPool.getHandler(theId);
	$("#MADFRange_"+theId).checkbox({
		onClick: function () {
			mecHandler.autobind.update();
		}
	});
	$('#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.FRange.prototype.updateFormWithInfo = function (eventType) {
	var theId = this.id;

	if (eventType === 'delete') {
		$('#formid_' + theId).empty();
		$('#fieldname_' + theId).empty();
	} else {
		MADFRange_FormChange(theId);
	}
}

MEC_NS.FRange.prototype.updateMecJsonByForm = function () {
	this.mecJson['fieldname'] = '';
}

/*获取JSON*/
MEC_NS.FRange.prototype.getMecJson = function(){
	var theId = this.id;
	
	this.mecJson["id"] = theId;
	this.mecJson["mectype"] = this.type;
	
	var $attrContainer=$("#MADFRange_"+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 defaultvalue=Mec_FiexdUndefinedVal($("#defaultvalue_"+theId).val());
		this.mecJson["formid"] = formid;
		this.mecJson["fieldname"] = fieldname;
		this.mecJson["fieldlabel"] = fieldlabel;
		this.mecJson["defaultvalue"] = defaultvalue;
		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";
		}
		this.mecJson["needWrap"] = $("#needWrap_"+theId).is(':checked') ? "1" : "0";

		var inParams = this.mecJson["inParams"];
		var paramValue = $("#paramValue_"+theId).text();
		for(var i = 0; i < inParams.length; i++){
			inParams[i]["paramValue"] = paramValue;
			break;
		}
		this.mecJson["min"] = Mec_FiexdUndefinedVal($("#min_"+theId).val());
		this.mecJson["max"] = Mec_FiexdUndefinedVal($("#max_"+theId).val());
		this.mecJson["step"] = Mec_FiexdUndefinedVal($("#step_"+theId).val());
	}
	return this.mecJson;
};

MEC_NS.FRange.prototype.getDefaultMecJson = function(){
	return {
		id: this.id,
		mectype: this.type,
		inParams: [{ paramValue: "" }],
		fieldlabel: SystemEnv.getHtmlNoteName(4141), // 名称
		min: "0",
		max: "100",
		step: "1"
	};
};

MEC_NS.FRange.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 MADFRange_FormChange(mec_id,selectedField){
	var formidObj = $("#formid_"+mec_id);
	var formid = formidObj.val();
	Mec_GetFieldOptionHtml(formid, "fieldname_"+mec_id, selectedField);
}

function MADFRange_editOneInParamOnPage(mec_id){
	var mecHandler = MECHandlerPool.getHandler(mec_id);
	var inParams = mecHandler.mecJson["inParams"];
	var paramobj = null;
	for(var i = 0; i < inParams.length; i++){
		paramobj = inParams[i];
		break;
	}

	var paramValue = paramobj["paramValue"];
	paramValue = compressByLZ(paramValue);// 系统安全编码
	
	var url = "/mobilemode/admin/dialog/defaultparaminfo.jsp?paramValue="+paramValue;
	var dlg = top.createTopDialog();//获取Dialog对象
	
	dlg.Width = 755;//定义长度
	dlg.Height = 515;
	dlg.Model = true;
	dlg.normalDialog = false;
	dlg.URL = url;
	dlg.Title = SystemEnv.getHtmlNoteName(4002);  //编辑
	dlg.show();
	dlg.hookFn = function(result){
		paramobj["paramValue"] = result["paramValue"];
		
		$("#paramValue_"+mec_id).text(result["paramValue"]);
	};

}