FLbs_wev8.js 18.3 KB
if(typeof(MEC_NS) == 'undefined'){
	MEC_NS = {};
}

MEC_NS.FLbs = function(type, id, mecJson){
	this.type = type;
	if(!id){
		id = new UUID().toString();
	}
	this.id = id;
	if(!mecJson){
		mecJson = this.getDefaultMecJson();
	}
	this.mecJson = mecJson;
};

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

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

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

	var theId = this.id;
	
	var limitPointTip = "";
	if(_userLanguage=="8"){
		limitPointTip = "The content here is a coordinate information format: longitude, latitude can be: 1. fixed coordinates, such as 121.522443,31.082311 2., get page parameters, such as {coordinate} 3. data set references, such as {data.coordinate}";
	}else if(_userLanguage=="9"){
		limitPointTip = "此處內容為一個座標資訊,格式為:經度,緯度
可以是:
1.固定的座標,如:121.522443,31.082311
2.獲取頁面參數,如:{coordinate}
3.數据集引用,如:{data.coordinate}" ;
	}else{
		limitPointTip = "此处内容为一个坐标信息,格式为:经度,纬度
可以是:
1. 固定的坐标,如:121.522443,31.082311
2. 获取页面参数,如:{coordinate}
3. 数据集引用, 如:{data.coordinate}";
	}
	
	var htm = "<div id=\"MADFLbs_"+theId+"\" class=\"MADFLbs_Container\">"
							+"<div class=\"title\">"+SystemEnv.getHtmlNoteName(4650)+"</div>"
							+"<div class=\"form-group\">"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4607)+"</span>"  //所属表单:
							    +"<div class=\"col-m-8\"><select class=\"form-control\" data-autobind id=\"formid_"+theId+"\" onchange=\"MADFLbs_FormChange('"+theId+"')\">"+Mec_GetFormOptionHtml()+"</select></div>"
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4513)+"</span>"  //对应字段:
								+"<div class=\"col-m-8 required\"><select class=\"form-control requireded\"  data-autobind id=\"fieldname_" + theId + "\"></select></div>"
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4514)+"</span>"  //显示名称:
								+"<div class=\"col-m-8\"><input class=\"form-control\" id=\"fieldlabel_"+theId+"\" type=\"text\" "+MLanguage.ATTR+"/></div>"
							+"</div>"
							
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4563)+"</span>"  //数据保存:
								+"<div class=\"col-m-8\"><select class=\"form-control\" id=\"savetype_"+theId+"\" onchange=\"MADFLbs_SavetypeChange('"+theId+"')\">"
									+"<option value=\"1\">"+SystemEnv.getHtmlNoteName(4564)+"</option>"  //只保存经纬度
									+"<option value=\"2\">"+SystemEnv.getHtmlNoteName(4565)+"</option>"  //只保存地址中文名称
									+"<option value=\"3\">"+SystemEnv.getHtmlNoteName(4566)+"</option>"  //既保存经纬度,同时保存地址中文名称
								+"</select></div>"
							+"</div>"
							+"<div class=\"row\" id=\"MADFLbs_Address_"+theId+"\">"
								+"<span class=\"col-2 span-control MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(5053)+"</span>"  //中文字段:
								+"<div class=\"col-m-8\"><select class=\"MADFLbs_Select\" data-autobind id=\"addressFieldname_"+theId+"\"></select></div>"
							+"</div>"
							
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4568)+"</span>"  //定位类型:
								+"<div class=\"col-m-8\"><select class=\"form-control\" id=\"postype_"+theId+"\" onchange=\"MADFLbs_changePosType('"+theId+"');\">"
									+"<option value=\"1\">"+SystemEnv.getHtmlNoteName(4569)+"</option>"  //只显示当前位置,不显示周围热点
									+"<option value=\"2\">"+SystemEnv.getHtmlNoteName(4570)+"</option>"  //显示当前位置和周围热点
									+"<option value=\"3\">"+SystemEnv.getHtmlNoteName(4571)+"</option>"  //显示当前位置和周围热点,并允许改变位置
								+"</select></div>"
							+"</div>"
							+"<div class=\"row\" style=\"display:none;\">"
								+"<span class=\"col-2 span-control MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4318)+"</span>"  //按钮名称:
								+"<div class=\"col-m-8\"><input class=\"form-control\" id=\"btntext_"+theId+"\" type=\"text\" /></div>"
							+"</div>"
							+"<div class=\"row poi-content\" style=\"position: relative;display:none;\">"
								+"<span class=\"col-2 span-control MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4572)+"</span>"  //搜索半径:
								+"<div class=\"col-m-8\"><input class=\"form-control\" id=\"poiradius_"+theId+"\" type=\"text\" /></div>"
								+"<div style=\"position: absolute;right: 8px;top: 7px;color: #999;font-size: 13px;\">"+SystemEnv.getHtmlNoteName(5059)+"</div>"//米
							+"</div>"
							+"<div class=\"row poi-content\" style=\"display:none;\">"
								+"<span class=\"col-2 span-control ml-5 MADFLbs_BaseInfo_Label"+styleL+"\" >"+SystemEnv.getHtmlNoteName(4573)+"</span>"  //热点个数:
								+"<div class=\"col-m-8\"><input class=\"form-control\" id=\"numpois_"+theId+"\" type=\"text\"/></div>"
							+"</div>"
							+"<div class=\"row\" style=\"display:none;\">"
								+"<span class=\"col-2 span-control MADFLbs_BaseInfo_Label1"+styleL+"\">"+SystemEnv.getHtmlNoteName(4319)+"</span>"  //回调脚本:
								/*+"<textarea class=\"MADFLbs_Text\" id=\"backscript_"+theId+"\" style=\"height: 80px;padding: 2px 4px;\"></textarea>"*/
								+"<div class=\"col-4 click-control\" id=\"scriptdiv_"+theId+"\">"
									+"<input id=\"backscript_"+theId+"\" type=\"hidden\" value=\"\"/>"+SystemEnv.getHtmlNoteName(4574)  //单击
								+"</div>"
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4531)+"</span>"  //显示类型:
								+"<div class=\"col-m-8\"><select class=\"form-control\" 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 MADFLbs_BaseInfo_Label1"+styleL+"\">"+SystemEnv.getHtmlNoteName(4575)+"</span>"  //当前位置:
								+"<div class=\"col pd-4\"><input type=\"checkbox\" id=\"isShowCurrLocation_"+theId+"\" /><span class=\"font-12 ml-5\">"+SystemEnv.getHtmlNoteName(4576)+"</span></div>"
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5054)+"</span>"	//定位限制:
								+"<div class=\"col pd-4\"><input type=\"checkbox\" id=\"limitEnabled_"+theId+"\" onclick=\"MADFLbs_ShowLimitContent(this, '"+theId+"');\"/><span class=\"font-12 ml-5\">"+SystemEnv.getHtmlNoteName(5055)+"</span></div>"	//限制在指定点多少米范围内可以定位
							+"</div>"
							+"<div id=\"limitContent_"+theId+"\" style=\"display: none;\">"
							
							+ "<div class=\"row\">"
								+ "<span class=\"col-2 span-control\" style=\"vertical-align: top;\">"+SystemEnv.getHtmlNoteName(5056)+"</span>"	//指定点坐标:
								+ "<div class=\"col-m-8\"><textarea class=\"area-control\" style=\"height:120px;\" id=\"limitPoint_"+theId+"\" placeholder=\""+limitPointTip+"\"></textarea></div>"
							+ "</div>"
							+ "<div class=\"row\">"
								+ "<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4842)+"</span>"  //坐标类型:
								+ "<span class=\"col-m-8 multi-checkbox\">"
									+ "<span>"
										+ "<input type=\"checkbox\" name=\"limitCoordinateType_"+theId+"\" value=\"1\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4843)+"</span>"  //高德/腾讯
									+ "</span>"
									+ "<span>"
										+ "<input type=\"checkbox\" name=\"limitCoordinateType_"+theId+"\" value=\"2\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4844)+"</span>" //百度
									+ "</span>"
									+ "<span>"
										+ "<input type=\"checkbox\" name=\"limitCoordinateType_"+theId+"\" value=\"3\"/><span class=\"cbboxLabel\">GPS</span>" 
									+ "</span>"
								+ "</span>"
							+ "</div>"
							+"<div class=\"row\" style=\"position: relative;\">"
								+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5058)+"</span>"	//限制范围:
								+"<div class=\"col-m-8\"><input class=\"form-control\" id=\"limitRadius_"+theId+"\" type=\"text\" /></div>"
								+"<div style=\"position: absolute;right: 8px;top: 7px;color: #999;font-size: 13px;\">"+SystemEnv.getHtmlNoteName(5059)+"</div>"	//米
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5060)+"</span>"	//提示文本:
								+"<div class=\"col-m-8\"><input class=\"form-control\" id=\"limitTip_"+theId+"\" type=\"text\" "+MLanguage.ATTR+"/></div>"
							+"</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;
};

/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.FLbs.prototype.afterAttrDlgBuild = function(){
	var theId = this.id;
	var $attrContainer = $("#MADFLbs_" + theId);
	
	var formid = this.mecJson["formid"];// Form mec_id
	var fieldname = this.mecJson["fieldname"];// 对应字段
	var fieldlabel = Mec_FiexdUndefinedVal(this.mecJson["fieldlabel"], "所在位置");// 显示名称
	var savetype = Mec_FiexdUndefinedVal(this.mecJson["savetype"], "1");// 数据保存
	var addressFieldname = this.mecJson["addressFieldname"];// 地址中文名称字段
	var postype = this.mecJson["postype"];// 定位类型
	var btntext = this.mecJson["btntext"];// 按钮名称
	var poiradius = this.mecJson["poiradius"];// poi半径
	var numpois = Mec_FiexdUndefinedVal(this.mecJson["numpois"], "12");// poi数量
	var backscript = this.mecJson["backscript"];// 回调脚本
	if(backscript && backscript != ""){
		backscript = decodeURIComponent(backscript);
	}
	var required = Mec_FiexdUndefinedVal(this.mecJson["required"], "0");// 是否必填
	var readonly = Mec_FiexdUndefinedVal(this.mecJson["readonly"], "0");// 是否只读
	if(required == "1"){
		$("#showType_"+theId).val("3");
	}else if(readonly == "1"){
		$("#showType_"+theId).val("2");
	}else{
		$("#showType_"+theId).val("1");
	}
	
	$("#formid_"+theId).val(formid);
	MADFLbs_FormChange(theId,fieldname,addressFieldname);
	MLanguage.setValue($("#fieldlabel_"+theId), fieldlabel);
	$("#savetype_"+theId).val(savetype);
	$("#postype_"+theId).val(postype);
	$("#btntext_"+theId).val(btntext);
	$("#poiradius_"+theId).val(poiradius);
	$("#numpois_"+theId).val(numpois);
	$("#backscript_"+theId).val(backscript);
	
	var isShowCurrLocation = Mec_FiexdUndefinedVal(this.mecJson["isShowCurrLocation"]);
	if(isShowCurrLocation == "1"){
		$("#isShowCurrLocation_"+theId).checked();
	}
	
	MADFLbs_SavetypeChange(theId);
	MADFLbs_changePosType(theId);
	
	$("#scriptdiv_"+theId).click(function(){
		SL_AddScriptToField($("#backscript_"+theId));
	});
	
	var limitEnabled = Mec_FiexdUndefinedVal(this.mecJson["limitEnabled"], "0");
	if(limitEnabled == "1"){
		$("#limitEnabled_"+theId).checked();
		$("#limitContent_"+theId).show();
	}
	$("#limitPoint_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["limitPoint"]));
	
	var limitCoordinateType = Mec_FiexdUndefinedVal(this.mecJson["limitCoordinateType"], "2");
	var $limitCoordinateType = $("input[type='checkbox'][name='limitCoordinateType_"+theId+"'][value='"+limitCoordinateType+"']");
	if($limitCoordinateType.length > 0){
		$limitCoordinateType.checked();
	}
	
	$("#limitRadius_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["limitRadius"], "1000"));
	
	MLanguage.setValue($("#limitTip_"+theId), Mec_FiexdUndefinedVal(this.mecJson["limitTip"]));
	
	$("#MADFLbs_"+theId).checkbox();
	$('#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.FLbs.prototype.updateFormWithInfo = function (eventType) {
	var theId = this.id;

	if (eventType === 'delete') {
		$('#formid_' + theId).empty();
		$('#fieldname_' + theId).empty();
	} else {
		MADFLbs_FormChange(theId);
	}
	this.mecJson['fieldname'] = '';
}

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

/*获取JSON*/
MEC_NS.FLbs.prototype.getMecJson = function(){
	var theId = this.id;
	
	this.mecJson["id"] = theId;
	this.mecJson["mectype"] = this.type;
	
	var $attrContainer = $("#MADFLbs_"+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 savetype=Mec_FiexdUndefinedVal($("#savetype_"+theId).val());
		var addressFieldname=Mec_FiexdUndefinedVal($("#addressFieldname_"+theId).val());
		var postype=Mec_FiexdUndefinedVal($("#postype_"+theId).val());
		var btntext=Mec_FiexdUndefinedVal($("#btntext_"+theId).val());
		var poiradius=Mec_FiexdUndefinedVal($("#poiradius_"+theId).val());
		var numpois=Mec_FiexdUndefinedVal($("#numpois_"+theId).val());
		var backscript=Mec_FiexdUndefinedVal($("#backscript_"+theId).val());
		backscript = encodeURIComponent(backscript);
		var showType = $("#showType_"+theId).val();
		this.mecJson["formid"] = formid;
		this.mecJson["fieldname"] = fieldname;
		this.mecJson["fieldlabel"] = fieldlabel;
		this.mecJson["savetype"] = savetype;
		this.mecJson["addressFieldname"] = addressFieldname;
		this.mecJson["postype"] = postype;
		this.mecJson["btntext"] = btntext;
		this.mecJson["poiradius"] = poiradius;
		this.mecJson["numpois"] = numpois;
		this.mecJson["backscript"] = backscript;
		this.mecJson["isShowCurrLocation"] = $("#isShowCurrLocation_"+theId).is(':checked') ? "1" : "0";
		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["limitEnabled"] = $("#limitEnabled_"+theId).is(':checked') ? "1" : "0";
		this.mecJson["limitPoint"] = $("#limitPoint_"+theId).val();
		this.mecJson["limitCoordinateType"] = $("input[type='checkbox'][name='limitCoordinateType_"+theId+"']:checked").val();
		this.mecJson["limitRadius"] = $("#limitRadius_"+theId).val();
		this.mecJson["limitTip"] = MLanguage.getValue($("#limitTip_"+theId));
	}
	return this.mecJson;
};

MEC_NS.FLbs.prototype.getDefaultMecJson = function(){
	var theId = this.id;
	
	var defMecJson = {};
	defMecJson["id"] = theId;
	defMecJson["fieldlabel"] = SystemEnv.getHtmlNoteName( 4941 );//所在位置
	defMecJson["savetype"] = "1";
	defMecJson["postype"] = "1";
	defMecJson["btntext"] = SystemEnv.getHtmlNoteName(3451);  //确定
	defMecJson["poiradius"] = "500";
	defMecJson["numpois"] = "12";
	defMecJson["limitEnabled"] = "0";
	defMecJson["limitPoint"] = "";
	defMecJson["limitCoordinateType"] = "2";
	defMecJson["limitRadius"] = "1000";
	defMecJson["limitTip"] = SystemEnv.getHtmlNoteName(5261);  //当前位置超出限制范围
	return defMecJson;
};

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

function MADFLbs_SavetypeChange(mec_id){
	var $Entry = $("#MADFLbs_" + mec_id);
	
	var savetype = $("#savetype_" + mec_id, $Entry).val();
	if(savetype == "1" || savetype == "2"){
		$("#MADFLbs_Address_"+mec_id, $Entry).hide();
	}else if(savetype == "3"){
		$("#MADFLbs_Address_"+mec_id, $Entry).show();
	}
}

function MADFLbs_ShowLimitContent(cbObj, mec_id){
	setTimeout(function(){	//checkbox用了插件,不延时checkbox的checked状态获取不准确
		if(cbObj.checked){
			var locationType = $("#postype_" + mec_id).val();
			if(locationType === '3'){
				$(cbObj).removeAttr("checked");
				alert(SystemEnv.getHtmlNoteName(5243));//当定位类型为允许改变位置时,无法设定定位限制!
			}else{
				$("#limitContent_"+mec_id).show();
			}
		}else{
			$("#limitContent_"+mec_id).hide();
		}
	},100);
}

function MADFLbs_changePosType(mec_id){
	var v = $("#postype_" + mec_id).val();
	var $attrContainer = $("#MADFLbs_"+mec_id);
	if(v == "1"){
		$(".poi-content", $attrContainer).hide();
	}else{
		$(".poi-content", $attrContainer).show();
		if(v == '3'){
			var $limit = $('#limitEnabled_'+mec_id);
			setTimeout(function(){	//checkbox用了插件,不延时checkbox的checked状态获取不准确
				if($limit[0].checked){
					$limit.removeAttr("checked");
					MADFLbs_ShowLimitContent($limit[0],mec_id);
					alert(SystemEnv.getHtmlNoteName(5243));//当定位类型为允许改变位置时,无法设定定位限制!
				}
			},100);
		}
	}
}