Video_wev8.js 5.32 KB
if(typeof(MEC_NS) == 'undefined'){
	MEC_NS = {};
}

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

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

/*页面上显示控件完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.Video.prototype.afterDesignHtmlBuild = function(){
	var theId = this.id;
	
	var autoplay = this.mecJson["autoplay"];
	if(autoplay == "1"){
		$("#video"+theId).attr("autoplay", "autoplay");
	}
	
	var loop = this.mecJson["loop"];
	if(loop == "1"){
		$("#video"+theId).attr("loop", "loop");
	}
};

/*获取构建属性编辑窗体的html,添加和单击控件后会调用此方法,由此方法去构建属性编辑窗体。 必需的方法*/
MEC_NS.Video.prototype.getAttrDlgHtml = function(){
	var theId = this.id;
	
	var htm = "<div id=\"MADVideo_"+theId+"\">";
	htm += "<div class=\"title\">"+SystemEnv.getHtmlNoteName(4650)+"</div>";  //视频信息
	htm += "<div class=\"form-group\">"
			+ "<div class=\"row\">"	
				+ "<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4255)+"</span>"  //来源:
				+ "<div class=\"col-m-8 fupload-control\">"
					+ "<input id=\"video_path_"+theId+"\" data-autobind type=\"text\" class=\"form-control\" placeholder=\""+SystemEnv.getHtmlNoteName(5099)+"\" style=\"padding-right:54px;box-sizing: border-box;\"/>"
					//填写视频路径或上传一个视频
					+ "<div class=\"form-control-inline-btn\" onclick=\"fileUploadSet('"+theId+"');\">" + SystemEnv.getHtmlNoteName(5081) //上传
					+ "</div>"
				+ "</div>"
			+ "</div>"
			
			+ "<div class=\"row\">"	
				+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4191)+"</span>"  //宽度:
				+"<div class=\"col-m-8\"><input class=\"form-control\" data-autobind='width' id=\"width_"+theId+"\" type=\"text\" placeholder=\""+SystemEnv.getHtmlNoteName(4606)+"\"/></div>"  //如:344,此处缺省则为页面宽度
			+ "</div>"
			
			+"<div class=\"row\">"
				+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4492)+"</span>"  //自动播放:
				+"<div class=\"col pd-4\"><input type=\"checkbox\" id=\"autoplay_"+theId+"\"/></div>"
			+"</div>"
			
			+"<div class=\"row\">"
				+"<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4493)+"</span>"  //循环播放:
				+"<div class=\"col pd-4\"><input type=\"checkbox\" id=\"loop_"+theId+"\"/></div>"
			+"</div>";
	htm += "</div>";		
	htm += "<div class=\"bottom\"><div class=\"save-btn\" onclick=\"refreshMecDesign('"+theId+"');\">"+SystemEnv.getHtmlNoteName(3451)+"</div></div>";  //确定
	htm += "</div>";
	
	htm += "<div class=\"MAD_Alert\">"+SystemEnv.getHtmlNoteName(4115)+"</div>";  //已生成到布局
	
	return htm;
};

/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.Video.prototype.afterAttrDlgBuild = function(){
	var theId = this.id;
	var mecHandler = MECHandlerPool.getHandler(theId);
	
	var video_path = this.mecJson["video_path"];
	$("#video_path_"+theId).val(video_path);
	
	$("#width_"+theId).val(this.mecJson["width"]);
	
	var autoplay = this.mecJson["autoplay"];
	if(autoplay == "1"){
		$("#autoplay_"+theId).checked();
	}
	
	var loop = this.mecJson["loop"];
	if(loop == "1"){
		$("#loop_"+theId).checked();
	}
	
	$("#MADVideo_"+theId).checkbox({
		onClick: function () { 
			mecHandler.autobind && mecHandler.autobind.update();
		}
	});
};

/*获取JSON*/
MEC_NS.Video.prototype.getMecJson = function(){
	var theId = this.id;
	
	this.mecJson["id"] = theId;
	this.mecJson["mectype"] = this.type;
	
	var $attrContainer = $("#MADVideo_"+theId);
	if($attrContainer.length > 0){
		this.mecJson["video_path"] = $("#video_path_"+theId).val();
		this.mecJson["width"] = $("#width_"+theId).val();
		this.mecJson["autoplay"] = $("#autoplay_"+theId).is(':checked') ? "1" : "0";
		this.mecJson["loop"] = $("#loop_"+theId).is(':checked') ? "1" : "0";
	}
	
	return this.mecJson;
};

MEC_NS.Video.prototype.getDefaultMecJson = function(){
	var theId = this.id;
	
	var defMecJson = {};
	defMecJson["id"] = theId;
	defMecJson["mectype"] = this.type;
	
	defMecJson["video_path"] = "";
	defMecJson["width"] = "";
	defMecJson["autoplay"] = "0";
	defMecJson["loop"] = "0";
	
	return defMecJson;
};

function fileUploadSet(theId){
	var url = "/mobilemode/admin/dialog/fileUpload.jsp";
	var mecHandler = MECHandlerPool.getHandler(theId);
	
	var dlg = top.createTopDialog();//获取Dialog对象
	dlg.Model = true;
	dlg.Width = 350;//定义长度
	dlg.Height = 145;
	dlg.normalDialog = false;
	dlg.URL = url;
	dlg.Title = SystemEnv.getHtmlNoteName(4494);  //文件上传
	var index = dlg.show();
	dlg.hookFn = function(result){
		var filePath = result["file_path"];
		$("#video_path_"+theId).val(filePath);
		mecHandler.autobind.update();
	};
	$('#layui-layer' + index).find('.layui-layer-btn0').addClass('disabled');
}