FDateTime_wev8.js 14.1 KB
if(typeof(MEC_NS) == 'undefined'){
	MEC_NS = {};
}

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

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

/*获取构建属性编辑窗体的html,添加和单击控件后会调用此方法,由此方法去构建属性编辑窗体。 必需的方法*/
MEC_NS.FDateTime.prototype.getAttrDlgHtml = function(){
	
	var styleL = "_style" + _userLanguage;
	var theId = this.id;
	
	var htm = "<div id=\"MADFD_"+theId+"\" class=\"MADFD_Container\">"
							+"<div class=\"title\">"+SystemEnv.getHtmlNoteName(4650)+"</div>"
							+"<div class=\"form-group MADFD_BaseInfo\">"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADFD_BaseInfo_Label MADFD_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4607)+"</span>"  //所属表单:
								    +"<div class=\"col-m-8\"><select class=\"form-control MADFD_Select\" data-autobind id=\"formid_"+theId+"\" onchange=\"MADFD_FormChange('"+theId+"')\">"+Mec_GetFormOptionHtml()+"</select></div>"
								+"</div>"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADFD_BaseInfo_Label MADFD_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4513)+"</span>"  //对应字段:
								    +"<div class=\"col-m-8 required\"><select class=\"form-control requireded MADFD_Select\" data-autobind onchange=\"Mec_SetFieldDefaultLabelName('" + theId + "')\" id=\"fieldname_" + theId + "\"></select></div>"
								+"</div>"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADFD_BaseInfo_Label MADFD_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4514)+"</span>"  //显示名称:
								    +"<div class=\"col-m-8\"><input class=\"form-control MADFD_Text\" onchange=\"$(this).attr('user-entered',true);\"  data-autobind='fieldlabel' id=\"fieldlabel_"+theId+"\" type=\"text\" "+MLanguage.ATTR+"/></div>"
								+"</div>"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADFD_BaseInfo_Label MADFD_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4515)+"</span>"  //提示信息:
								    +"<div class=\"col-m-8\"><input class=\"form-control MADFD_Text\" data-autobind='fieldremind' id=\"fieldremind_"+theId+"\" type=\"text\" "+MLanguage.ATTR+"/></div>"
								+"</div>"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADFD_BaseInfo_Label MADFD_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4516)+"</span>"  //字段类型:
									+"<div class=\"col-m-8\"><select class=\"form-control MADFD_Select\" id=\"htmlType_"+theId+"\" onchange=\"MADFD_HtmlTypeChange('"+theId+"');\">"
										+"<option value=\"1\">"+SystemEnv.getHtmlNoteName(3715)+"</option>"  //日期
										+"<option value=\"2\">"+SystemEnv.getHtmlNoteName(3706)+"</option>"  //时间
										+"<option value=\"3\">"+SystemEnv.getHtmlNoteName(4518)+"</option>"  //日期时间
									+"</select></div>"
								+"</div>"
								+ "<div class=\"row MADFD_DateContent\">"
									+ "<span class=\"col-2 span-control MADFD_BaseInfo_Label MADFD_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4527)+"</span>"  //年份偏移:
									+ "<div class=\"col-m-8\">"
									 +	"<input class=\"form-control\" type=\"text\" id=\"yearPrevOffset_"+theId+"\" placeholder=\""+SystemEnv.getHtmlNoteName(4608)+"\" style=\"width: 47%;display: inline-block;\"/>"  //向前偏移,100
									 +  "&nbsp;~&nbsp;"
									 +  "<input class=\"form-control\" type=\"text\" id=\"yearNextOffset_"+theId+"\" placeholder=\""+SystemEnv.getHtmlNoteName(4609)+"\" style=\"width: 47%;display: inline-block;\"/>"  //向后偏移,1
									 +  "<a style=\"display:block;padding: 2px 0px 5px 0px;text-decoration: underline;\" href=\"javascript:MADFD_ShowTip('yearOffset');\">"+SystemEnv.getHtmlNoteName(4530)+"</a>"  //设置说明
									+ "</div>"
								+ "</div>"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADFD_BaseInfo_Label MADFD_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4531)+"</span>"  //显示类型:
									+"<div class=\"col-m-8\"><select class=\"form-control MADFD_Select\" data-autobind id=\"showType_"+theId+"\">"
										+"<option value=\"1\">"+SystemEnv.getHtmlNoteName(4532)+"</option>"  //可编辑
										+"<option value=\"2\">"+SystemEnv.getHtmlNoteName(4533)+"</option>"  //只读
										+"<option value=\"3\">"+SystemEnv.getHtmlNoteName(4534)+"</option>"  //必填
									+"</select></div>"
								+"</div>"
								+"<div class=\"row\">"
									+ "<span class=\"col-2 span-control MADFD_BaseInfo_Label MADFD_BaseInfo_Label1"+styleL+"\">"+SystemEnv.getHtmlNoteName(4535)+"</span>"  //默认值:
									+ "<div class=\"col-m-8 pd-7\"><span class=\"edit-before finput_btn_edit\" onclick=\"MADFD_editOneInParamOnPage('"+theId+"')\"></span>"
									+ "<span class=\"finput_param_paramValue\" id=\"paramValue_"+theId+"\"></span></div>"
								+"</div>"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADFD_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(5476)+"</span>"  //内容换行:
									+"<div class=\"col-2 pd-4\"><input type=\"checkbox\" id=\"needWrap_"+theId+"\"/></div>"
								+"</div>"
							+"</div>"
							+"<div class=\"bottom MADFD_Bottom\"><div class=\"save-btn MADFD_SaveBtn\" onclick=\"refreshMecDesign('"+theId+"');\">"+SystemEnv.getHtmlNoteName(3451)+"</div></div>"  //确定
					 +"</div>";
	htm += "<div class=\"MAD_Alert\">"+SystemEnv.getHtmlNoteName(4115)+"</div>";  //已生成到布局
	
	return htm;
};

MEC_NS.FDateTime.prototype.afterDesignHtmlBuild = function () {
	$("#NMEC_" + this.id).find(".wev-field-view-span")
		.addClass("wev-field-view-tip");
};

/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.FDateTime.prototype.afterAttrDlgBuild = function(){
	var theId = this.id;
	
	var formid = this.mecJson["formid"];// Form mec_id
	var fieldname = this.mecJson["fieldname"];// 对应字段
	var fieldlabel = this.mecJson["fieldlabel"];// 显示名称
	var fieldremind = this.mecJson["fieldremind"];// 提示信息
	var required = Mec_FiexdUndefinedVal(this.mecJson["required"], "0");// 是否必填
	var defaultvalue = this.mecJson["defaultvalue"];// 默认值
	var htmlType = this.mecJson["htmlType"];// 默认值
	var readonly = Mec_FiexdUndefinedVal(this.mecJson["readonly"], "0");
	
	var yearPrevOffset = Mec_FiexdUndefinedVal(this.mecJson["yearPrevOffset"]);
	var yearNextOffset = Mec_FiexdUndefinedVal(this.mecJson["yearNextOffset"]);
	
	$("#formid_"+theId).val(formid);
	MADFD_FormChange(theId,fieldname);
	MLanguage.setValue($("#fieldlabel_"+theId), fieldlabel);
	MLanguage.setValue($("#fieldremind_"+theId), fieldremind);
	$("#defaultvalue_"+theId).val(defaultvalue);
	$("#htmlType_"+theId).val(htmlType);
	
	$("#yearPrevOffset_" + theId).val(yearPrevOffset);
	$("#yearNextOffset_" + theId).val(yearNextOffset);
	
	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();
	}
	var inParams = this.mecJson["inParams"];
	var $container = $("#MADFD_" + theId);
	for(var i = 0; inParams && i < inParams.length; i++){
		$(".finput_param_paramValue", $container).text(inParams[i]["paramValue"]);
		break;
	}
	
	MADFD_HtmlTypeChange(theId);

	var mecHandler = MECHandlerPool.getHandler(theId);
	$("#MADFD_"+theId).checkbox({
		onClick: function () {
			mecHandler.autobind.update();
		}
	});
	$('#formid_' + theId, $container).on("select2:opening.formbefore", function () {
		var $this = $(this);
		var value = $this.val();
		$(this).html(Mec_GetFormOptionHtml()).val(value);
	});
};

//表单类控件更新所属表单相关信息的函数,当表单delete或change时触发
MEC_NS.FDateTime.prototype.updateFormWithInfo = function (eventType) {
	var theId = this.id;

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

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

/*获取JSON*/
MEC_NS.FDateTime.prototype.getMecJson = function(){
	var theId = this.id;
	
	this.mecJson["id"] = theId;
	this.mecJson["mectype"] = this.type;
	
	var $attrContainer = $("#MADFD_"+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 fieldremind = MLanguage.getValue($("#fieldremind_"+theId));
		var defaultvalue=Mec_FiexdUndefinedVal($("#defaultvalue_"+theId).val());
		var htmlType=Mec_FiexdUndefinedVal($("#htmlType_"+theId).val());
		this.mecJson["formid"] = formid;
		this.mecJson["fieldname"] = fieldname;
		this.mecJson["fieldlabel"] = fieldlabel;
		this.mecJson["fieldremind"] = fieldremind;
		this.mecJson["defaultvalue"] = defaultvalue;
		this.mecJson["htmlType"] = htmlType;
		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 = $(".finput_param_paramValue", $attrContainer).text();
		for(var i = 0; i < inParams.length; i++){
			inParams[i]["paramValue"] = paramValue;
			break;
		}
		this.mecJson["yearPrevOffset"] = $("#yearPrevOffset_" + theId).val();
		this.mecJson["yearNextOffset"] = $("#yearNextOffset_" + theId).val();
		
	}
	return this.mecJson;
};

MEC_NS.FDateTime.prototype.getDefaultMecJson = function(){
	return {
		id: this.id,
		mectype: this.type,
		inParams: [{ paramValue: "" }],
		fieldlabel: SystemEnv.getHtmlNoteName(4141), // 名称
		fieldremind: SystemEnv.getHtmlNoteName(3418),  //请选择
		htmlType: "3"
	};
};

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

function MADFD_HtmlTypeChange(mec_id){
	$htmlType = $("#htmlType_" + mec_id);
	var $attrContainer = $("#MADFD_"+mec_id);
	var htmlTypeVal = $htmlType.val();
	if($htmlType.val() == "1" || $htmlType.val() == "3"){
		$(".MADFD_DateContent", $attrContainer).show();
	}else{
		$(".MADFD_DateContent", $attrContainer).hide();
	}
}

function MADFD_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"];
		
		var $container = $("#MADFD_" + mec_id);
		$(".finput_param_paramValue", $container).text(result["paramValue"]);
	};
}

function MADFD_ShowTip(type){
	var tip = "";
	if(_userLanguage=="8"){
		tip = "Since the date of choice is a range of the year, the default is the current year to move forward for 100 years as the minimum year, backward shift 1 years as the biggest year, assuming that the current is 2016, the optional year for 1916-2017 years. \n so you can set the offset to complete the control of the year interval, if you want to display the current year, you can set a forward offset to 0, backward offset 0.";
	}else if(_userLanguage=="9"){
		tip = "因爲日期選擇時年份是有一個區間的,默認爲當前年向前偏移100年作爲最小年份,向後偏移1年作爲最大年份,假設當前是2016年,可選年份爲1916-2017年。\n所以可以對偏移進行設置來完成對年份區間的控制,假如隻想顯示當前年,可以設置向前偏移爲0,向後偏移爲0。";
	}else{
		tip = "因为日期选择时年份是有一个区间的,默认为当前年向前偏移100年作为最小年份,向后偏移1年作为最大年份,假设当前是2016年,可选年份为1916-2017年。\n所以可以对偏移进行设置来完成对年份区间的控制,假如只想显示当前年,可以设置向前偏移为0,向后偏移为0。";
	}
	if(type == "yearOffset"){
		alert(tip);  //因为日期选择时年份是有一个区间的,默认为当前年向前偏移100年作为最小年份,向后偏移1年作为最大年份,假设当前是2016年,可选年份为1916-2017年。\n所以可以对偏移进行设置来完成对年份区间的控制,假如只想显示当前年,可以设置向前偏移为0,向后偏移为0。
	}
}