FloatButton_wev8.js 14.7 KB
if(typeof(MEC_NS) == 'undefined'){
	MEC_NS = {};
}

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

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

MEC_NS.FloatButton.prototype.runWhenPageOnLoad = function(){
	this.afterDesignHtmlBuild();
};

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

MEC_NS.FloatButton.prototype.afterDesignHtmlBuild = function(isPageOnload){
	var theId = this.id;
	var $abbr = $("abbr[id='"+theId+"']");
	/*
	var offset = $("#content_editor").offset();
	var t = offset.top;
	var l = offset.left;*/
	
	var top = this.mecJson["top"];
	var right = this.mecJson["right"];
	var bottom = this.mecJson["bottom"];
	var left = this.mecJson["left"];
	
	$("#content_editor").after($abbr);
	var style = "";
	var positionType = this.mecJson["positionType"];
	if(positionType == "left_top"){
		style = "left:"+left+";top:"+top+";";
	}else if(positionType == "right_top"){
		style = "right:"+right+";top:"+top+";";
	}else if(positionType == "left_bottom"){
		style = "left:"+left+";bottom:"+bottom+";";
	}else if(positionType == "right_bottom"){
		style = "right:"+right+";bottom:"+bottom+";";
	}
	$abbr.attr("style", style);
	
};

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

	var theId = this.id;
	var htm = "<div id=\"MADFloatButton_"+theId+"\">"
				+"<div class=\"title\">"
				+SystemEnv.getHtmlNoteName(4650) //基本信息
				+"</div>"
				+"<div class=\"form-group\">"
					+"<div class=\"row\">"
						+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5024)+"</span>" //内容:
						+"<div class=\"col-m-8\" style=\"width:80px;\"><select class=\"form-control\" data-autobind id=\"contentType_"+theId+"\" onchange=\"MADFloatButton_ContentTypeChange('"+theId+"')\">"
						+"  <option value=\"1\">"+SystemEnv.getHtmlNoteName(4167)+"</option>" //图片
						+"  <option value=\"2\">"+SystemEnv.getHtmlNoteName(4373)+"</option>"	//文字
						+"</select></div>"
						+ "<div class=\"col-m-8\" style=\"width: calc(100% - 65px - 80px);padding-left:8px;\">"
							+ "<div class=\"icon-set-wrap content-v  content-v1\" style=\"display:none;\" id=\"img_"+theId+"\" onclick=\"MADFloatButton_PicSet('','"+theId+"');\">"
						    	+ "<div class=\"icon-set-delete\" onclick=\"MADFloatButton_SetPicPath('','"+theId+"','');\"></div>"
						    	+ "<img class=\"icon-set-img\"/>"
						    	+ "<input type=\"hidden\" />"
						    + "</div>"
						    + "<input data-autobind class=\"form-control content-v content-v2\" style=\"display:none;\" id=\"text_"+theId+"\" type=\"text\" placeholder=\""+SystemEnv.getHtmlNoteName(4177)+"\" "+MLanguage.ATTR+"/>"
						+ "</div>"
					+"</div>"
					+"<div class=\"row\">"
						+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5025)+"</span>"	//显示位置:
						+"<div class=\"col-m-8\"><div class=\"posBox\"> <div data-autobind data-value=\"left_top\">"+SystemEnv.getHtmlNoteName(5026)+"</div> <div data-autobind data-value=\"right_top\">"+SystemEnv.getHtmlNoteName(5027)+"</div> <div data-autobind data-value=\"left_bottom\">"+SystemEnv.getHtmlNoteName(5028)+"</div> <div data-autobind data-value=\"right_bottom\">"+SystemEnv.getHtmlNoteName(5029)+"</div> </div></div>"
					+"</div>"
					+"<div class=\"row posDetail posDetail-top\">"
						+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5030)+"</span>"  //距上偏移:
						+"<div class=\"col-m-8\"><input data-autobind='top' class=\"form-control\" id=\"top_"+theId+"\" type=\"text\" placeholder=\"如10px或者50%\"/></div>"
					+"</div>"
					+"<div class=\"row posDetail posDetail-right\">"
						+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5031)+"</span>"  //距右偏移:
						+"<div class=\"col-m-8\"><input data-autobind='right' class=\"form-control\" id=\"right_"+theId+"\" type=\"text\" placeholder=\"如10px或者50%\"/></div>"  //如10px或者50%
					+"</div>"
					+"<div class=\"row posDetail posDetail-bottom\">"
						+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5032)+"</span>"  //距下偏移:
						+"<div class=\"col-m-8\"><input data-autobind='bottom' class=\"form-control\" id=\"bottom_"+theId+"\" type=\"text\" placeholder=\"如10px或者50%\"/></div>"  //如10px或者50%
					+"</div>"
					+"<div class=\"row posDetail posDetail-left\">"
						+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5033)+"</span>"  //距左偏移:
						+"<div class=\"col-m-8\"><input data-autobind='left' class=\"form-control\" id=\"left_"+theId+"\" type=\"text\" placeholder=\"如10px或者50%\"/></div>"  //如10px或者50%
					+"</div>"
					+"<div class=\"row\">"
						+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5034)+"</span>"  //数字提示:
						+"<div class=\"col-m-8\" style=\"position: relative;\">"
							+ "<span>"
								+ "<input type=\"checkbox\" id=\"remind_"+theId+"\" value=\"1\" onclick=\"MADFloatButton_IsremindChange('"+theId+"');\"/>"
							+ "</span>"
							+ "<input type=\"hidden\" id=\"remindtype_"+theId+"\"/>"
							+ "<input type=\"hidden\" id=\"remindsql_"+theId+"\"/>"
							+ "<input type=\"hidden\" id=\"reminddatasource_"+theId+"\"/>"
							+ "<input type=\"hidden\" id=\"remindjavafilename_"+theId+"\"/>"
							+ "<input type=\"hidden\" id=\"remindapiconfig_"+theId+"\"/>"
							+ "<div id=\"numremindEditFlag_"+theId+"\" class=\"numremindEditFlag\" style=\"position: absolute;top: -6px;\" onclick=\"MADFloatButton_NumremindEdit('"+theId+"');\"></div>"
						+"</div>"  
					+"</div>"
					+"<div class=\"row\">"
						+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4349)+"</span>"  //单击事件:
						+"<div class=\"col-m-8\">"
							+ "<div class='multi-switch'>"
								+ "<span onclick=\"MADFloatButton_ChangeClickType(this, '"+theId+"');\">"
									+ "<input data-checkbox='false' type=\"checkbox\" name=\"clickType_"+theId+"\" value=\"1\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(5036)+"</span>"  //回到顶部
								+ "</span>"
								+ "<span style=\"position: relative;\" onclick=\"MADFloatButton_ChangeClickType(this, '"+theId+"');\">"
									+ "<input data-checkbox='false' type=\"checkbox\" name=\"clickType_"+theId+"\" value=\"2\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4634)+"</span>"  //脚本
								+ "</span>"
								+ "<a id=\"clickScriptWrap_"+theId+"\" class=\"click-control hide nhbtn_click_desc\" onclick=\"MADFloatButton_addClickScript('"+theId+"')\">"
									+ "<input  id=\"clickScript_"+theId+"\" type=\"hidden\" value=\"\">"
								+ "</a>"
							+ "</div>"
						+"</div>"
					+"</div>"
					
					+"<div class=\"row\">"
						+"<div class=\"tip-control\" style=\"display:block;\">"
						+ SystemEnv.getHtmlNoteName(5035) //如果单击事件为 回到顶部,按钮一开始是不会显示的,如果页面向下滚动的距离超过一屏,按钮此时才会显示。
						+"</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.FloatButton.prototype.afterAttrDlgBuild = function(){
	var theId = this.id;
	var mecHandler = MECHandlerPool.getHandler(theId);
	
	var $attrContainer = $("#MADFloatButton_"+theId);
	
	$("#contentType_"+theId).val(this.mecJson["contentType"]);
	MADFloatButton_ContentTypeChange(theId);
	
	MADFloatButton_SetPicPath("", theId, this.mecJson["img"]);
	MLanguage.setValue($("#text_" + theId), this.mecJson["text"]);
	
	$(".posBox > div", $attrContainer).click(function(){
		if(!$(this).hasClass("active")){
			$(this).siblings("div.active").removeClass("active");
			$(this).addClass("active");
			
			$(".posDetail", $attrContainer).hide();
			
			var v = $(this).attr("data-value");
			var vArr = v.split("_");
			for(var i = 0; i < vArr.length; i++){
				$(".posDetail-"+vArr[i], $attrContainer).show();
			}
		}
	});
	var positionType = this.mecJson["positionType"];
	$(".posBox > div[data-value='"+positionType+"']", $attrContainer).click();
	
	$("#top_" + theId).val(this.mecJson["top"]);
	$("#right_" + theId).val(this.mecJson["right"]);
	$("#bottom_" + theId).val(this.mecJson["bottom"]);
	$("#left_" + theId).val(this.mecJson["left"]);
	
	var remind = this.mecJson["remind"];
	if(remind == "1"){
		$("#remind_"+theId).checked();
	}
	$("#remindtype_" + theId).val(this.mecJson["remindtype"]);
	$("#remindsql_" + theId).val(this.mecJson["remindsql"]);
	$("#reminddatasource_" + theId).val(this.mecJson["reminddatasource"]);
	$("#remindjavafilename_" + theId).val(this.mecJson["remindjavafilename"]);
	$("#remindapiconfig_" + theId).val(Mec_FiexdUndefinedVal(this.mecJson["remindapiconfig"]));
	
	var clickTypeV = this.mecJson["clickType"];
	var $clickType = $("input[type='checkbox'][name='clickType_"+theId+"'][value='"+clickTypeV+"']");
	if($clickType.length > 0){
		$clickType.switched();
	}
	var scriptCode = Mec_FiexdUndefinedVal(this.mecJson["clickScript"]);
	var $clickScript = $("#clickScript_"+theId).val(scriptCode);

	SL_ChangeStyle($clickScript.parent(), scriptCode);
	
	$("#MADFloatButton_"+theId).switcher().checkbox({
		onClick: function () {
			mecHandler.autobind.update();
		}
	});
};

/*获取JSON*/
MEC_NS.FloatButton.prototype.getMecJson = function(){
	var theId = this.id;
	
	this.mecJson["id"] = theId;
	this.mecJson["mectype"] = this.type;
	
	var $attrContainer = $("#MADFloatButton_"+theId);
	if($attrContainer.length > 0){
		
		this.mecJson["contentType"] = $("#contentType_" + theId).val();
		this.mecJson["img"] = $("#img_"+theId + " input").val();
		this.mecJson["text"] = MLanguage.getValue($("#text_"+theId));
		
		this.mecJson["positionType"] = $(".posBox > div.active", $attrContainer).attr("data-value");
		this.mecJson["top"] = $("#top_" + theId).val();
		this.mecJson["right"] = $("#right_" + theId).val();
		this.mecJson["bottom"] = $("#bottom_" + theId).val();
		this.mecJson["left"] = $("#left_" + theId).val();
		
		this.mecJson["remind"] = $("#remind_"+theId).is(':checked') ? "1" : "0";
		this.mecJson["remindtype"] = $("#remindtype_" + theId).val();
		this.mecJson["remindsql"] = $("#remindsql_" + theId).val();
		this.mecJson["reminddatasource"] = $("#reminddatasource_" + theId).val();
		this.mecJson["remindjavafilename"] = $("#remindjavafilename_" + theId).val();
		this.mecJson["remindapiconfig"] = $("#remindapiconfig_" + theId).val();
		
		this.mecJson["clickType"] = $("input[type='checkbox'][name='clickType_"+theId+"']:checked").val();
		this.mecJson["clickScript"] = $("#clickScript_"+theId).val();
		
	}
	return this.mecJson;
};

MEC_NS.FloatButton.prototype.getDefaultMecJson = function(){
	var theId = this.id;
	
	var defMecJson = {};
	
	defMecJson["id"] = theId;
	defMecJson["mectype"] = this.type;
	
	defMecJson["contentType"] = "1";
	defMecJson["img"] = "/mobilemode/piclibrary/03-E9_flat/gotop.png";
	defMecJson["text"] = "";
	
	defMecJson["positionType"] = "right_bottom";
	
	defMecJson["top"] = "10px";
	defMecJson["right"] = "10px";
	defMecJson["bottom"] = "20px";
	defMecJson["left"] = "10px";
	
	defMecJson["remind"] = "0";
	
	defMecJson["clickType"] = "1";
	defMecJson["clickScript"] = "";
	
	return defMecJson;
};

function MADFloatButton_ChangeClickType(switchInner, mec_id){
	var value = $(switchInner).find('input').val();

	if(value == "2"){
		$("#clickScriptWrap_" + mec_id).show();
	} else{
		$("#clickScriptWrap_" + mec_id).hide();
	}
}

function MADFloatButton_addClickScript(mec_id){
	var $btnScript = $("#clickScript_"+mec_id);
	SL_AddScriptToField($btnScript);
}

function MADFloatButton_PicSet(prefix, mec_id){
	var pic_path = $("#img"+prefix+"_"+mec_id + " input").val();
	var params = "pic_path=" + pic_path;
	
	showPicsetModal(params, function(result){
		var picPath = result["pic_path"];
		MADFloatButton_SetPicPath(prefix, mec_id, picPath);
	});
}

function MADFloatButton_SetPicPath(prefix, mec_id, picPath){
	var mecHandler = MECHandlerPool.getHandler(mec_id);
	var $img = $("#img"+prefix+"_"+mec_id);
	$("input", $img).val(picPath);
	$(".icon-set-img", $img).attr("src", picPath);
	if(picPath == ""){
		$img.removeClass("hasValue");
	}else{
		$img.addClass("hasValue");
	}
	
	var e = event || window.event;
	if (e){
		if(e.stopPropagation){
			e.stopPropagation();  
		}else{
			e.cancelBubble=true;
		}
	}
	mecHandler.autobind && mecHandler.autobind.update();
}

function MADFloatButton_ContentTypeChange(mec_id){
	var v = $("#contentType_" + mec_id).val();
	
	var $attrContainer = $("#MADFloatButton_"+mec_id);
	$(".content-v", $attrContainer).hide();
	$(".content-v"+v, $attrContainer).show();
}

function MADFloatButton_IsremindChange(mec_id){
	setTimeout(function(){	//checkbox用了插件,不延时checkbox的checked状态获取不准确
		var $numremindEditFlag = $("#numremindEditFlag_"+mec_id);
		$("#remind_"+mec_id).is(':checked') ? $numremindEditFlag.show() : $numremindEditFlag.hide();
	},100);
}

function MADFloatButton_NumremindEdit(mec_id){
	var remindtypeV = $("#remindtype_"+mec_id).val();
	
	var remindsqlV = $("#remindsql_"+mec_id).val();
	remindsqlV = $m_encrypt(remindsqlV);// 系统安全编码
	
	var reminddatasourceV = $("#reminddatasource_"+mec_id).val();
	var remindjavafilenameV = $("#remindjavafilename_"+mec_id).val();
	
	var remindapiconfigV = compressByLZ($("#remindapiconfig_"+mec_id).val());
	
	var url = "/mobilemode/admin/dialog/numremind.jsp?remindtype="+remindtypeV+"&remindsql="+remindsqlV+"&reminddatasource="+reminddatasourceV+"&remindjavafilename="+remindjavafilenameV+"&remindapiconfig="+remindapiconfigV;
	var dlg = top.createTopDialog();//获取Dialog对象
	dlg.Model = true;
	dlg.Width = 500;//定义长度
	dlg.normalDialog = false;
	dlg.Height = 290;
	dlg.URL = url;
	dlg.Title = SystemEnv.getHtmlNoteName(3621);  //提示
	dlg.show();
	dlg.hookFn = function(result){
		$("#remindtype_"+mec_id).val(result["remindtype"]);
		$("#remindsql_"+mec_id).val(result["remindsql"]);
		$("#reminddatasource_"+mec_id).val(result["reminddatasource"]);
		$("#remindjavafilename_"+mec_id).val(result["remindjavafilename"]);
		$("#remindapiconfig_"+mec_id).val(result["remindapiconfig"]);
	};
};