FPhoto_wev8.js 22.6 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 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
if(typeof(MEC_NS) == 'undefined'){
	MEC_NS = {};
}

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

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

MEC_NS.FPhoto.prototype.afterDesignHtmlBuild = function () {
	$("#NMEC_" + this.id).find(".wev-upload span")
	.html(SystemEnv.getHtmlNoteName(4117));//添加图片
	$("#NMEC_" + this.id).find('.wev-upload-tip')
	.html(SystemEnv.getHtmlNoteName(5373));//附件上传目录未设置
};

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

	
var tip = "";
var watermarkTip = "";
	if(_userLanguage=="8"){
		tip = "Quality: the smaller the value, the lower the quality, the smaller the size of the compressed image, but the picture is not clear. The setting values ranged from 0.1 to 1 </div><div> scaling: compression will be to picture the original wide high will be multiplied by a scaling ratio, the smaller the value of, image compression wide Takahashi is small, and the volume will be smaller and smaller. The value is set between 0.1 and 1.";
		watermarkTip = "Watermark Content Description: </br> supports system variables, page parameters, data sets, current location {CURRPOSITION}, current longitude {CURRLNG}, current latitude {CURRLAT}";
	}else if(_userLanguage=="9"){
		tip = "質量:值越小,質量越低,圖片壓縮後體積越小,但圖片也會越不清晰。該值設置介于0.1 至 1之間</div><div>縮放:壓縮時會以圖片的原始寬高會乘以縮放比例,值越小,壓縮後圖片的寬高越小,體積也會越小。該值設置介于0.1 至 1之間";
		watermarkTip = "水印內容說明:</br>支持系統變量,頁面參數,數據集,當前位置{CURRPOSITION},當前經度{CURRLNG},當前緯度{CURRLAT}";
	}else{
		tip = "质量:值越小,质量越低,图片压缩后体积越小,但图片也会越不清晰。该值设置介于0.1 至 1之间</div><div>缩放:压缩时会以图片的原始宽高会乘以缩放比例,值越小,压缩后图片的宽高越小,体积也会越小。该值设置介于0.1 至 1之间";
		watermarkTip = "水印内容说明:</br>支持系统变量,页面参数,数据集,当前位置{CURRPOSITION},当前经度{CURRLNG},当前纬度{CURRLAT}";
	}
	var theId = this.id;
	
	var htm = "<div id=\"MADFPhoto_"+theId+"\" class=\"MADFPhoto_Container\">"
							+"<div class=\"title\">"+SystemEnv.getHtmlNoteName(4650)+"</div>"
							+"<div class=\"form-group\">"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4607)+"</span>"  //所属表单:
							    +"<div class=\"col-m-8\"><select class=\"form-control\" data-autobind id=\"formid_"+theId+"\" onchange=\"MADFPhoto_FormChange('"+theId+"')\">"+Mec_GetFormOptionHtml()+"</select></div>"
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4513)+"</span>"  //对应字段:
								+"<div class=\"col-m-8 required\"><select class=\"form-control requireded\" data-autobind onchange=\"Mec_SetFieldDefaultLabelName('" + theId + "')\" id=\"fieldname_" + theId + "\"></select></div>"
								+ "<span class=\"col-4 search-control\">"
									+ "<INPUT id=\"fieldSearch_"+theId+"\" class=\"form-control\" type=\"text\"/>"
									+ "<div id=\"fieldSearchResult_"+theId+"\" class=\"search-result MADFPhoto_FieldSearchResult"+styleL+"\"><ul></ul></div>"
									+ "<div id=\"fieldSearchTip_"+theId+"\" class=\"search-tip\">"+SystemEnv.getHtmlNoteName(4590)+"</div>"  //在来源中检索...
								+ "</span>"
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4514)+"</span>"  //显示名称:
								+"<div class=\"col-m-8\"><input class=\"form-control\" data-autobind='fieldlabel' onchange=\"$(this).attr('user-entered',true);\"    id=\"fieldlabel_"+theId+"\" type=\"text\" "+MLanguage.ATTR+"/></div>"
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label1"+styleL+"\">"+SystemEnv.getHtmlNoteName(4633)+"</span>"  //图片绘制:
								+"<div class=\"col-2 pd-4\"><input type=\"checkbox\" id=\"isDrawing_"+theId+"\"/></div>"
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label2"+styleL+"\">"+SystemEnv.getHtmlNoteName(4579)+"</span>"  //是否压缩:
								+"<div class=\"col-2 pd-4\"><input type=\"checkbox\" id=\"isCompress_"+theId+"\" onclick=\"MADFPhoto_ChangeComp(this, '"+theId+"');\"/></div>"
							+"</div>"
							+"<div id=\"compressWrap_"+theId+"\" style=\"display:none;\">"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4930)+"</span>"	//压缩质量:
									+"<div class=\"col-m-8\"><input class=\"form-control\" type=\"text\" id=\"quality_"+theId+"\" placeholder=\"0.1 ~ 1\"/></div>"
								+"</div>"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4931)+"</span>"	//缩放比例:
									+"<div class=\"col-m-8\"><input class=\"form-control\" type=\"text\" id=\"zoom_"+theId+"\" placeholder=\"0.1 ~ 1\"/></div>"
								+"</div>"
								+"<div class=\"tip-control row\" style=\"display:block;\"><div>"+tip+"</div></div>"  //质量:值越小,质量越低,图片压缩后体积越小,但图片也会越不清晰。该值设置介于0.1 至 1之间</div><div>缩放:压缩时会以图片的原始宽高会乘以缩放比例,值越小,压缩后图片的宽高越小,体积也会越小。该值设置介于0.1 至 1之间
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label2"+styleL+"\">"+SystemEnv.getHtmlNoteName(4926)+"</span>"  //添加水印:
								+"<div class=\"col-2 pd-4\"><input type=\"checkbox\" id=\"addWatermark_"+theId+"\" onclick=\"MADFPhoto_ChangeCompWatermark(this, '"+theId+"');\"/></div>"
							+"</div>"
							+"<div id=\"watermarkWrap_"+theId+"\" style=\"display:none;\">"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4927)+"</span>"  //水印位置:
									+"<div class=\"col-m-8\"><select class=\"form-control\" id=\"watermarkPosition_"+theId+"\">"
										+"<option value=\"1\">"+SystemEnv.getHtmlNoteName(5029)+"</option>"  //右下角
										+"<option value=\"2\">"+SystemEnv.getHtmlNoteName(5028)+"</option>"  //左下角
										+"<option value=\"3\">"+SystemEnv.getHtmlNoteName(5027)+"</option>"  //右上角
										+"<option value=\"4\">"+SystemEnv.getHtmlNoteName(5026)+"</option>"
										+"<option value=\"5\">"+SystemEnv.getHtmlNoteName(5061)+"</option>"	//顶部居中
										+"<option value=\"6\">"+SystemEnv.getHtmlNoteName(5062)+"</option>"	//底部居中
									+"</select></div>"
								+"</div>"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADC_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4928)+"</span>"  //水印字体:
									+"<div class=\"col-m-8\"><input class=\"form-control\" id=\"watermarkFont_"+theId+"\" type=\"text\" style=\"display: inline-block;width: 64px;\"/>"
									
									+"<span tyle=\"margin-left: 5px;\">"+SystemEnv.getHtmlNoteName(4197)+"</span>"  //颜色:
									+"<input class=\"form-control\" id=\"watermarkColor_"+theId+"\" type=\"text\" style=\"display: inline-block;width: 64px;\"/>"
									
									+"<span style=\"margin-left: 5px;\">"+SystemEnv.getHtmlNoteName(4198)+"</span>"  //大小:
									+"<input class=\"form-control\" id=\"watermarkFontsize_"+theId+"\" type=\"text\" style=\"display: inline-block;width: 32px;\"/>" 
									+"<span style=\"font-size: 12px;\">&nbsp;PX</span>"
									+"</div>"
								+"</div>"
								+"<div class=\"row mg-0\">"
									+"<span class=\"col-2 span-control MADC_BaseInfo_Label2"+styleL+"\">"+SystemEnv.getHtmlNoteName(4199)+"</span>"  //是否粗体:
									+"<div class=\"col-2 pd-4\"><input id=\"watermarkFontweight_"+theId+"\" type=\"checkbox\"/></div>"
								+"</div>"
								+"<div class=\"row\">"
									+"<span class=\"col-2 span-control MADC_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4929)+"</span>"	//水印内容:
									+"<div class=\"col-m-8\"><textarea class=\"area-control\" id=\"watermarkContent_"+theId+"\"></textarea></div>"
								+"</div>"
								+"<div class=\"tip-control row\" style=\"display:block;\"><div>"+watermarkTip+"</div></div>"  //
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(5063)+"</span>"	//上传限制:
								+"<div class=\"col-m-8\"><input class=\"form-control\" type=\"text\" id=\"limit_"+theId+"\" placeholder=\""+SystemEnv.getHtmlNoteName(5064)+"\"/></div>"	//最大上传照片数,如:5,默认不限制
							+"</div>"
							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4628)+"</span>"  //拍照类型:
								+"<div class=\"col-m-8\"><select class=\"form-control\" id=\"photoType_"+theId+"\">"
									+"<option value=\"1\">"+SystemEnv.getHtmlNoteName(4629)+"</option>"  //默认
									+"<option value=\"2\">"+SystemEnv.getHtmlNoteName(4630)+"</option>"  //只拍照
									+"<option value=\"3\">"+SystemEnv.getHtmlNoteName(4631)+" "+SystemEnv.getHtmlNoteName(4632)+"</option>"  //只选择照片(仅在emobile中生效)
								+"</select></div>"
							+"</div>"

							+"<div class=\"row\">"
								+ "<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(6150)+"</span>"  //命名规则:
								+ "<div class=\"col-m-8 requireded\" style=\"position:relative;\">"
								+ "<input type=\"text\" id=\"namerule_"+theId+"\" data-autobind class=\"form-control MADF_Text\" style=\"padding-right: 22px;\"/><b/>"
								+ "<div class=\"helper\"  style=\"top:8px;right:5px\" for=\"default\">?</div>"
								+ "</div>"
							+"</div>"

							+"<div class=\"row\">"
								+"<span class=\"col-2 span-control MADFPhoto_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4531)+"</span>"  //显示类型:
								+"<div class=\"col-m-8\"><select class=\"form-control\" 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>"
							+"<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.FPhoto.prototype.afterAttrDlgBuild = function(){
	var theId = this.id;
	var $attrContainer = $("#MADFPhoto_" + theId);

	var formid = this.mecJson["formid"];// Form mec_id
	var fieldname = this.mecJson["fieldname"];// 对应字段
	var fieldlabel = this.mecJson["fieldlabel"];// 显示名称
	var readonly = Mec_FiexdUndefinedVal(this.mecJson["readonly"], "0");
	var required = Mec_FiexdUndefinedVal(this.mecJson["required"], "0");// 是否必填
	
	var photoType = Mec_FiexdUndefinedVal(this.mecJson["photoType"], "1");// 拍照类型
	$("#photoType_"+theId).val(photoType);
	
	if(required == "1"){
		$("#showType_"+theId).val("3");
	}else if(readonly == "1"){
		$("#showType_"+theId).val("2");
	}else{
		$("#showType_"+theId).val("1");
	}
	
	$("#formid_"+theId).val(formid);
	MADFPhoto_FormChange(theId,fieldname);
	MLanguage.setValue($("#fieldlabel_"+theId), fieldlabel);
	
	var isDrawing = Mec_FiexdUndefinedVal(this.mecJson["isDrawing"]);
	if(isDrawing == "1"){
		$("#isDrawing_"+theId).checked();
	}
	
	var isCompress = Mec_FiexdUndefinedVal(this.mecJson["isCompress"], "1");
	if(isCompress == "1"){
		$("#isCompress_"+theId).checked();
		$("#compressWrap_"+theId).show();
	}
	
	$("#quality_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["quality"], "0.5"));
	$("#limit_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["limit"], ""));
	
	$("#zoom_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["zoom"], "0.5"));
	
	var addWatermark = Mec_FiexdUndefinedVal(this.mecJson["addWatermark"], "0");// 添加水印
	if(addWatermark == "1"){
		$("#addWatermark_"+theId).checked();
		$("#watermarkWrap_"+theId).show();
	}
	$("#watermarkPosition_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["watermarkPosition"], 1));// 水印位置
	$("#watermarkFont_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["watermarkFont"], "Verdana"));// 水印字体
	$("#watermarkColor_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["watermarkColor"], "#F8F8F8"));// 字体颜色
	$("#watermarkFontsize_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["watermarkFontsize"], "18"));
	$("#watermarkContent_"+theId).val(Mec_FiexdUndefinedVal(this.mecJson["watermarkContent"], "{CURRDATE} {CURRTIME}"));//水印内容
	
	if(this.mecJson["watermarkFontweight"] == "bold"){
		$("#watermarkFontweight_"+theId).checked();
	}
	
	MADFPhoto_InitFieldSearch(theId);
	$("#MADFPhoto_"+theId).checkbox();
	$('#formid_' + theId, $attrContainer).on("select2:opening.formbefore", function () {
		var $this = $(this);
		var value = $this.val();
		$(this).html(Mec_GetFormOptionHtml()).val(value);
	});

	MADFPhoto_GetNameRule(theId);
	require(["modal"], function(modal) {
		var tip = MADFPhoto_NameRuleSetTip();
		var indexArr = [];
		$attrContainer.on('click','.helper', function(e) {
			indexArr.push(modal.tips(tip, $(this), {
				area: ['340px', '']
			}));
			e.stopPropagation();
		});

		$("body").on("click", function(e) {
			var $target = $(e.target);
			var layero = $target.parents(".layui-layer-tips");
			if(layero.length) return;
			indexArr.map(function (v) {
				modal.close(v);
			});
		});
	});
};

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

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

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

/*获取JSON*/
MEC_NS.FPhoto.prototype.getMecJson = function(){
	var theId = this.id;
	
	this.mecJson["id"] = theId;
	this.mecJson["mectype"] = this.type;
	
	var $attrContainer = $("#MADFPhoto_"+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));
		this.mecJson["formid"] = formid;
		this.mecJson["fieldname"] = fieldname;
		this.mecJson["fieldlabel"] = fieldlabel;
		this.mecJson["isDrawing"] = $("#isDrawing_"+theId).is(':checked') ? "1" : "0";
		this.mecJson["isCompress"] = $("#isCompress_"+theId).is(':checked') ? "1" : "0";
		this.mecJson["quality"] = $("#quality_"+theId).val();
		this.mecJson["limit"] = $("#limit_"+theId).val();
		this.mecJson["zoom"] = $("#zoom_"+theId).val();
		this.mecJson["addWatermark"] = $("#addWatermark_"+theId).is(':checked') ? "1" : "0";
		this.mecJson["watermarkPosition"] = $("#watermarkPosition_"+theId).val();
		this.mecJson["watermarkColor"] = $("#watermarkColor_"+theId).val();
		this.mecJson["watermarkFont"] = $("#watermarkFont_"+theId).val();
		this.mecJson["watermarkFontsize"] = $("#watermarkFontsize_"+theId).val();
		this.mecJson["watermarkFontweight"] = $("#watermarkFontweight_"+theId).is(':checked') ? "bold" : "normal";
		this.mecJson["watermarkContent"] = $("#watermarkContent_"+theId).val();
		this.mecJson["photoType"] = $("#photoType_"+theId).val()||'';
		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";
		}
	}
	return this.mecJson;
};

MEC_NS.FPhoto.prototype.saveMecCommonConfig = function(){
	var theId = this.id;
	var $attrContainer = $("#MADFPhoto_"+theId);
	if($attrContainer.length > 0){
		var identification = Mec_GetCommonConfigIdentification(theId,"fphoto-namerule");
		return Mec_SaveMobileAppCommonConfig(identification,{ namerule :$("#namerule_"+theId ).val()});
	}
	return false;
};

MEC_NS.FPhoto.prototype.getDefaultMecJson = function(){
	var theId = this.id;
	
	var defMecJson = {};
	
	defMecJson["id"] = theId;
	defMecJson["mectype"] = this.type;

	defMecJson["fieldlabel"] = "";
	defMecJson["watermarkPosition"] = 1;
	defMecJson["watermarkFont"] = "Verdana";
	defMecJson["watermarkColor"] = "#F8F8F8";
	defMecJson["watermarkFontsize"] = "18";
	defMecJson["watermarkFontweight"] = "normal";
	defMecJson["watermarkContent"] = "{CURRDATE} {CURRTIME}";
	
	return defMecJson;
};

MEC_NS.FPhoto.prototype.validate = function () {
	var isValid = true;
	var mec_id = this.id;
	var $pluginAttr = $('#MAD_' + mec_id);

	var checkNotEmptyField = [];
	checkNotEmptyField.push({
		name:'fieldname',
		value:this.mecJson.fieldname,
		emptyMsg:'"' + SystemEnv.getHtmlNoteName(4513).replace(/[\:\:]/g, '') + '" ' + SystemEnv.getHtmlNoteName(6041) //对应字段
	});

	if($("#namerule_"+mec_id ).data('load')){
		checkNotEmptyField.push({
			name:'namerule',
			value:$("#namerule_"+ mec_id ).val(),
			emptyMsg:'"' + SystemEnv.getHtmlNoteName(6150).replace(/[\:\:]/g, '') + '" ' + SystemEnv.getHtmlNoteName(6041) //命名规则
		});
	}

	checkNotEmptyField.map(function (field) {
		if(!!field.value) return;
		isValid = false;
		$pluginAttr.find('#'+field.name+'_' + mec_id).parents('.col-m-8').validate({
			value: field.value,
			rules: [{ msg: field.emptyMsg }],
		});
	});
	return isValid;
};

function MADFPhoto_ChangeComp(cbObj, mec_id){
	setTimeout(function(){	//checkbox用了插件,不延时checkbox的checked状态获取不准确
		if(cbObj.checked){
			$("#compressWrap_"+mec_id).show();
		}else{
			$("#compressWrap_"+mec_id).hide();
		}
	},100);
}

function MADFPhoto_ChangeCompWatermark(cbObj, mec_id){
	setTimeout(function(){

		if(cbObj.checked){
			$("#watermarkWrap_"+mec_id).show();
		}else{
			$("#watermarkWrap_"+mec_id).hide();
		}
	},100);
}

function MADFPhoto_FormChange(mec_id,selectedField){
	var formidObj = $("#formid_"+mec_id);
	var formid = formidObj.val();
	Mec_GetFieldOptionHtml(formid, "fieldname_"+mec_id, selectedField);
}

function MADFPhoto_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:MADFPhoto_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();
			}
		}
	});
	
	$("#MADFPhoto_" + mec_id).bind("click", function(){
		hideSearchResult();
	});
}

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


function MADFPhoto_GetNameRule(mecid){
	var identification = Mec_GetCommonConfigIdentification(mecid,"fphoto-namerule");
	Mec_GetMobileAppCommonConfig(identification).then(function (config) {
		var namerule = (config && JSON.parse(config).namerule) ||  (SystemEnv.getHtmlNoteName(6151) + "-{timestamp}"); //移动建模图片附件
		$("#namerule_"+mecid ).val(namerule).data('load',true);
	});
}

function  MADFPhoto_NameRuleSetTip(){
	var tip = "变量支持说明:<br/> 1.时间戳 {timestamp};<br/>  2.主表字段值 {t1.fieldname};<br/> 3.系统变量,如:{currusername}、{currdate}、{currtime}等;<br/> 4.页面参数,如:{billid};";
	if(_userLanguage=="8"){
		tip = "Variable support description: <br/> 1. timestamp {timestamp} ;<br/> 2. Main table field value {t1.field name} ;<br/> 3. System variables such as {currusername}, {currdate}, {currtime} etc.;<br/> 4. Page parameters, such as {billid};";
	}else if(_userLanguage=="9"){
		tip = "變數支持說明:<br/> 1.時間戳記{timestamp};<br/> 2.主錶欄位值{t1.fieldname};<br/> 3.系統變數,如:{currusername}、{currdate}、{currtime}等;<br/> 4.頁面參數,如:{billid};";
	}
	return tip;
}