FLbs_wev8.js 17.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
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(){
	var theId = this.id;
	
	var fieldlabel = this.mecJson["fieldlabel"];// 显示名称
	fieldlabel = Mec_FiexdUndefinedVal(fieldlabel);
	var html = "";
	html += "<div class=\"Design_FLbs_Container\">";
	html += "<div class=\"Design_FLbs_Fieldlabel\">" + fieldlabel + "</div>";
	html += "<div class=\"Design_FLbs_Fielddom\">"+SystemEnv.getHtmlNoteName(4562)+"</div>";  //LBS字段
	html += "</div>";
	
	return html;
};

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

	var theId = this.id;
	
	var htm = "<div id=\"MADFLbs_"+theId+"\" class=\"MADFLbs_Container\">"
							+"<div class=\"MADFLbs_Title\">LBS</div>"
							+"<div class=\"MADFLbs_BaseInfo\">"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4607)+"</span>"  //所属表单:
							    +"<select class=\"MADFLbs_Select\" id=\"formid_"+theId+"\" onchange=\"MADFLbs_FormChange('"+theId+"')\">"+Mec_GetFormOptionHtml()+"</select>"
							+"</div>"
							+"<div class=\"MADFLbs_BaseInfo\">"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4513)+"</span>"  //对应字段:
								+"<select class=\"MADFLbs_Select\" id=\"fieldname_"+theId+"\"></select>"
								+ "<span style=\"margin-left: 10px; position: relative;display: inline-block;\">"
									+ "<INPUT id=\"fieldSearch_"+theId+"\" class=\"MADFLbs_fieldSearch\" type=\"text\"/>"
									+ "<div id=\"fieldSearchTip_"+theId+"\" class=\"MADFLbs_fieldSearchTip\">"+SystemEnv.getHtmlNoteName(4590)+"</div>"  //在来源中检索...
								+ "</span>"
							+"</div>"
							+"<div id=\"fieldSearchResult_"+theId+"\" class=\"MADFLbs_FieldSearchResult MADFLbs_FieldSearchResult"+styleL+"\"><ul></ul></div>"
							+"<div class=\"MADFLbs_BaseInfo\" style=\"display:none;\">"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4514)+"</span>"  //显示名称:
								+"<input class=\"MADFLbs_Text\" id=\"fieldlabel_"+theId+"\" type=\"text\" />"
							+"</div>"
							
							+"<div class=\"MADFLbs_BaseInfo\">"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4563)+"</span>"  //数据保存:
								+"<select class=\"MADFLbs_Select\" id=\"savetype_"+theId+"\" onchange=\"MADFLbs_SavetypeChange('"+theId+"')\" style=\"width: 262px;\">"
									+"<option value=\"1\">"+SystemEnv.getHtmlNoteName(4564)+"</option>"  //只保存经纬度
									+"<option value=\"2\">"+SystemEnv.getHtmlNoteName(4565)+"</option>"  //只保存地址中文名称
									+"<option value=\"3\">"+SystemEnv.getHtmlNoteName(4566)+"</option>"  //既保存经纬度,同时保存地址中文名称
								+"</select>"
							+"</div>"
							+"<div class=\"MADFLbs_BaseInfo\" id=\"MADFLbs_Address_"+theId+"\">"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4567)+"</span>"  //中文名字段:
								+"<select class=\"MADFLbs_Select\" id=\"addressFieldname_"+theId+"\"></select>"
								+ "<span style=\"margin-left: 10px; position: relative;display: inline-block;\">"
									+ "<INPUT id=\"addressFieldSearch_"+theId+"\" class=\"MADFLbs_fieldSearch\" type=\"text\"/>"
									+ "<div id=\"addressFieldSearchTip_"+theId+"\" class=\"MADFLbs_fieldSearchTip\">"+SystemEnv.getHtmlNoteName(4590)+"</div>"  //在来源中检索...
								+ "</span>"
							+"</div>"
							+"<div id=\"addressFieldSearchResult_"+theId+"\" class=\"MADFLbs_AddressFieldSearchResult MADFLbs_AddressFieldSearchResult"+styleL+"\"><ul></ul></div>"
							
							+"<div class=\"MADFLbs_BaseInfo\">"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4568)+"</span>"  //定位类型:
								+"<select class=\"MADFLbs_Select\" id=\"postype_"+theId+"\" style=\"width: 262px;\">"
									+"<option value=\"1\">"+SystemEnv.getHtmlNoteName(4569)+"</option>"  //只显示当前位置,不显示周围热点
									+"<option value=\"2\">"+SystemEnv.getHtmlNoteName(4570)+"</option>"  //显示当前位置和周围热点
									+"<option value=\"3\">"+SystemEnv.getHtmlNoteName(4571)+"</option>"  //显示当前位置和周围热点,并允许改变位置
								+"</select>"
							+"</div>"
							+"<div class=\"MADFLbs_BaseInfo\">"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4318)+"</span>"  //按钮名称:
								+"<input class=\"MADFLbs_Text\" id=\"btntext_"+theId+"\" type=\"text\"  data-multi=false/>"
							+"</div>"
							+"<div class=\"MADFLbs_BaseInfo\">"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4572)+"</span>"  //搜索半径:
								+"<input class=\"MADFLbs_Text\" id=\"poiradius_"+theId+"\" type=\"text\" style=\"width: 85px;\"/>"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4573)+"</span>"  //热点个数:
								+"<input class=\"MADFLbs_Text\" id=\"numpois_"+theId+"\" type=\"text\" style=\"width: 85px;\"/>"
							+"</div>"
							+"<div class=\"MADFLbs_BaseInfo\">"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label1"+styleL+"\">"+SystemEnv.getHtmlNoteName(4319)+"</span>"  //回调脚本:
								/*+"<textarea class=\"MADFLbs_Text\" id=\"backscript_"+theId+"\" style=\"height: 80px;padding: 2px 4px;\"></textarea>"*/
								+"<div class=\"MADFLbs_BaseInfo_Script\" id=\"scriptdiv_"+theId+"\">"
									+"<input id=\"backscript_"+theId+"\" type=\"hidden\" value=\"\"/>"+SystemEnv.getHtmlNoteName(4574)  //单击
								+"</div>"
							+"</div>"
							+"<div class=\"MADFLbs_BaseInfo\">"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4531)+"</span>"  //显示类型:
								+"<select class=\"MADFLbs_Select\" 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 class=\"MADFLbs_BaseInfo\">"
								+"<span class=\"MADFLbs_BaseInfo_Label MADFLbs_BaseInfo_Label1"+styleL+"\">"+SystemEnv.getHtmlNoteName(4575)+"</span>"  //当前位置:
								+"<input type=\"checkbox\" id=\"isShowCurrLocation_"+theId+"\" onclick=\"MADFLbs_ShowContent(this, '"+theId+"');\"/>"
							+"</div>"
							+"<div class=\"MADFLbs_BaseInfo\" id=\"contentWrap_"+theId+"\" style=\"display:none;\">"
								+"<div style=\"padding: 5px;line-height: 18px;border: 1px dotted #ccc;margin: 10px 15px 10px 10px;border-radius:3px;\"><div>"+SystemEnv.getHtmlNoteName(4576)+"</div></div>"  //如勾选该选项,则默认显示当前位置
							+"</div>"
							+"<div class=\"MADFLbs_Bottom\"><div class=\"MADFLbs_SaveBtn\" 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 formid = this.mecJson["formid"];// Form mec_id
	var fieldname = this.mecJson["fieldname"];// 对应字段
	var fieldlabel = 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 = this.mecJson["numpois"];// 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);
	$("#fieldlabel_"+theId).val(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).attr("checked","checked");
		$("#contentWrap_"+theId).show();
	}
	
	MADFLbs_SavetypeChange(theId);
	
	$("#scriptdiv_"+theId).click(function(){
		SL_AddScriptToField($("#backscript_"+theId));
	});
	
	MADFLbs_InitFieldSearch(theId);
	MADFLbs_InitAddressFieldSearch(theId);
	$("#MADFLbs_"+theId).jNice();
	MLanguage({
		container: $("#MADFLbs_"+theId + " .MADFLbs_BaseInfo")
    });
};

/*获取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=Mec_FiexdUndefinedVal($("#fieldlabel_"+theId).val());
		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"] =  MLanguage.getValue($("#btntext_"+theId))|| 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";
		}
	}
	return this.mecJson;
};

MEC_NS.FLbs.prototype.getDefaultMecJson = function(){
	var theId = this.id;
	
	var defMecJson = {};
	defMecJson["id"] = theId;
	defMecJson["savetype"] = "1";
	defMecJson["postype"] = "1";
	defMecJson["btntext"] = SystemEnv.getHtmlNoteName(3451);  //确定
	defMecJson["poiradius"] = "500";
	defMecJson["numpois"] = "12";
	
	return defMecJson;
};

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_InitFieldSearch(mec_id){
	var $searchText = $("#fieldSearch_" + mec_id);
	var $searchTextTip = $("#fieldSearchTip_" + mec_id);
	
	$searchTextTip.click(function(e){
		$searchText[0].focus();
		e.stopPropagation(); 
	});
	
	$searchText.focus(function(){
		$searchTextTip.hide();
	});
	
	$searchText.blur(function(){
		if(this.value == ""){
			$searchTextTip.show();
		}
	});
	
	$searchText.click(function(e){
		e.stopPropagation(); 
	});
	
	var $srarchResult = $("#fieldSearchResult_" + mec_id);
	function hideSearchResult(){
		$srarchResult.hide();	
	}
	
	function showSearchResult(){
		$srarchResult.show();	
	}
	
	function clearSearchResult(){
		$srarchResult.children("ul").find("*").remove();	
	}
	
	var preSearchText = "";
	
	$searchText.keyup(function(event){
		if(this.value == ""){
			preSearchText = "";
			hideSearchResult();
			clearSearchResult();
		}else{
			if(this.value != preSearchText){
				preSearchText = this.value;
				var searchValue = this.value;
				//clearSearchResult();
				
				var resultHtml = "";
				
				var $vfieldName = $("#fieldname_"  + mec_id);
				$vfieldName.find("option").each(function(){
					var vt = $(this).text();
					var vv = $(this).attr("value");
					if(vt.toLowerCase().indexOf(searchValue.toLowerCase()) != -1){
						resultHtml += "<li><a href=\"javascript:MADFLbs_SetFieldSelected('"+mec_id+"','"+vv+"');\">"+vt+"</a></li>";
					}
				});
				
				if(resultHtml == ""){
					resultHtml = "<li><font class='tip'>"+SystemEnv.getHtmlNoteName(4270)+"</font></li>";  //无匹配的结果
				}
				
				$srarchResult.children("ul").html(resultHtml);
				showSearchResult();
			}
		}
	});
	
	$("#MADFLbs_" + mec_id).bind("click", function(){
		hideSearchResult();
	});
}

function MADFLbs_SetFieldSelected(mec_id, v){
	var $field = $("#fieldname_" + mec_id);
	$field.val(v);
	
	preSearchText = "";
	var $searchText = $("#fieldSearch_" + mec_id);
	$searchText.val("");
	$searchText.trigger("blur");
	MADFLbs_InitFieldSearch(mec_id)
}

function MADFLbs_InitAddressFieldSearch(mec_id){
	var $addressSearchText = $("#addressFieldSearch_" + mec_id);
	var $addressSearchTextTip = $("#addressFieldSearchTip_" + mec_id);
	
	$addressSearchTextTip.click(function(e){
		$addressSearchText[0].focus();
		e.stopPropagation(); 
	});
	
	$addressSearchText.focus(function(){
		$addressSearchTextTip.hide();
	});
	
	$addressSearchText.blur(function(){
		if(this.value == ""){
			$addressSearchTextTip.show();
		}
	});
	
	$addressSearchText.click(function(e){
		e.stopPropagation(); 
	});
	
	var $addressSrarchResult = $("#addressFieldSearchResult_" + mec_id);
	function hideAddressSearchResult(){
		$addressSrarchResult.hide();	
	}
	
	function showAddressSearchResult(){
		$addressSrarchResult.show();	
	}
	
	function clearAddressSearchResult(){
		$addressSrarchResult.children("ul").find("*").remove();	
	}
	
	var preAddressSearchText = "";
	
	$addressSearchText.keyup(function(event){
		if(this.value == ""){
			preAddressSearchText = "";
			hideAddressSearchResult();
			clearAddressSearchResult();
		}else{
			if(this.value != preAddressSearchText){
				preAddressSearchText = this.value;
				var addressSearchValue = this.value;
				//clearSearchResult();
				
				var resultHtml = "";
				
				var $vfieldName = $("#addressFieldname_"  + mec_id);
				$vfieldName.find("option").each(function(){
					var vt = $(this).text();
					var vv = $(this).attr("value");
					if(vt.toLowerCase().indexOf(addressSearchValue.toLowerCase()) != -1){
						resultHtml += "<li><a href=\"javascript:MADFLbs_SetAddressFieldSelected('"+mec_id+"','"+vv+"');\">"+vt+"</a></li>";
					}
				});
				
				if(resultHtml == ""){
					resultHtml = "<li><font class='tip'>"+SystemEnv.getHtmlNoteName(4270)+"</font></li>";  //无匹配的结果
				}
				
				$addressSrarchResult.children("ul").html(resultHtml);
				showAddressSearchResult();
			}
		}
	});
	
	$("#MADFLbs_" + mec_id).bind("click", function(){
		hideAddressSearchResult();
	});
}

function MADFLbs_SetAddressFieldSelected(mec_id, v){
	var $addressField = $("#addressFieldname_" + mec_id);
	$addressField.val(v);
	
	preAddressSearchText = "";
	var $addressSearchText = $("#addressFieldSearch_" + mec_id);
	$addressSearchText.val("");
	$addressSearchText.trigger("blur");
	MADFLbs_InitAddressFieldSearch(mec_id)
}

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_ShowContent(cbObj, mec_id){
	setTimeout(function(){	//checkbox用了插件,不延时checkbox的checked状态获取不准确
		if(cbObj.checked){
			$("#contentWrap_"+mec_id).show();
		}else{
			$("#contentWrap_"+mec_id).hide();
		}
	},100);
}