MWF.xDesktop.requireApp("process.Xform","Attachment",null,false);MWF.xDesktop.requireApp("cms.FormDesigner","widget.AttachmentController",null,false);MWF.xApplication.cms.Xform.AttachmentController=new Class({Extends:MWF.xApplication.cms.FormDesigner.widget.AttachmentController,options:{officeFiles:["doc","docx","dotx","dot","xls","xlsx","xlsm","xlt","xltx","pptx","ppt","pot","potx","potm","pdf"]},checkDeleteAction:function(){if(this.options.readonly){this.setActionDisabled(this.deleteAction);this.setActionDisabled(this.min_deleteAction);return false}if(this.options.isDeleteOption!=="y"&&this.options.isDeleteOption!=="n"){if(this.selectedAttachments.length&&this.selectedAttachments.length==1){var t=true;if(this.options.isDeleteOption==="o"){for(var e=0;e0){var n=i[i.length-1].data;this.form.documentAction.getAttachmentUrl(n.id,this.form.businessData.document.id,function(i){if(this.attachmentController.options.toBase64){this.form.documentAction.getSubjectAttachmentBase64(n.id,this.attachmentController.options.base64MaxSize,function(t){var e=t.data?"data:image/png;base64,"+t.data.value:null;if(this.postSelect)this.postSelect(i,n,e)}.bind(this))}else{if(this.postSelect)this.postSelect(i,n)}}.bind(this))}},createUploadFileNode:function(){this.attachmentController.doUploadAttachment({site:this.json.id},this.form.documentAction.action,"uploadAttachment",{id:this.form.businessData.document.id},null,function(t){if(t.id){this.form.documentAction.getAttachment(t.id,this.form.businessData.document.id,function(t){if(t.data){this.attachmentController.addAttachment(t.data);this.form.businessData.attachmentList.push(t.data)}this.attachmentController.checkActions();this.fireEvent("upload",[t.data])}.bind(this))}this.attachmentController.checkActions()}.bind(this),function(t){if(t.length){if(t.length+this.attachmentController.attachments.length>this.attachmentController.options.attachmentCount&&this.attachmentController.options.attachmentCount>0){var e=MWF.xApplication.cms.Xform.LP.uploadMore;e=e.replace("{n}",this.attachmentController.options.attachmentCount);this.form.notice(e,"error");return false}}return true}.bind(this))},uploadAttachment:function(t,e){if(window.o2&&window.o2.uploadAttachment){window.o2.uploadAttachment(this.json.id)}else if(window.webkit&&window.webkit.messageHandlers){window.webkit.messageHandlers.uploadAttachment.postMessage({site:this.json.id})}else{this.createUploadFileNode()}},getData:function(){return this.attachmentController.getAttachmentNames()},deleteAttachments:function(t,e,i){var n=[];i.each(function(t){n.push(t.data.name)}.bind(this));var s=this;this.form.confirm("warn",t,MWF.xApplication.cms.Xform.LP.deleteAttachmentTitle,MWF.xApplication.cms.Xform.LP.deleteAttachment+"( "+n.join(", ")+" )",300,120,function(){while(i.length){var t=i.shift();s.deleteAttachment(t)}this.close()},function(){this.close()},null)},deleteAttachment:function(e){this.fireEvent("delete",[e.data]);this.form.documentAction.deleteAttachment(e.data.id,function(t){this.attachmentController.removeAttachment(e);this.attachmentController.checkActions();this.fireEvent("afterDelete",[e.data])}.bind(this))},replaceAttachment:function(t,e,i){if(window.o2&&window.o2.replaceAttachment){window.o2.replaceAttachment(i.data.id,this.json.id)}else if(window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.replaceAttachment){window.webkit.messageHandlers.replaceAttachment.postMessage({id:i.data.id,site:this.json.id})}else{var n=this;this.form.confirm("warn",t,MWF.xApplication.process.Xform.LP.replaceAttachmentTitle,MWF.xApplication.process.Xform.LP.replaceAttachment+"( "+i.data.name+" )",350,120,function(){n.replaceAttachmentFile(i);this.close()},function(){this.close()},null)}},createReplaceFileNode:function(e){this.attachmentController.doUploadAttachment({site:this.json.id},this.form.documentAction.action,"replaceAttachment",{id:e.data.id,documentid:this.form.businessData.document.id},null,function(t){this.form.documentAction.getAttachment(e.data.id,this.form.businessData.document.id,function(t){e.data=t.data;e.reload();this.attachmentController.checkActions()}.bind(this))}.bind(this),null)},replaceAttachmentFile:function(t){this.createReplaceFileNode(t)},downloadAttachment:function(t,e,i){if(this.form.businessData.document){i.each(function(t){if(window.o2&&window.o2.downloadAttachment){window.o2.downloadAttachment(t.data.id)}else if(window.webkit&&window.webkit.messageHandlers){window.webkit.messageHandlers.downloadAttachment.postMessage({id:t.data.id,site:this.json.id})}else{this.form.documentAction.getAttachmentStream(t.data.id,this.form.businessData.document.id)}}.bind(this))}},openAttachment:function(t,e,i){if(this.form.businessData.document){i.each(function(t){if(window.o2&&window.o2.downloadAttachment){window.o2.downloadAttachment(t.data.id)}else if(window.webkit&&window.webkit.messageHandlers){window.webkit.messageHandlers.downloadAttachment.postMessage({id:t.data.id,site:this.json.id})}else{this.form.documentAction.getAttachmentData(t.data.id,this.form.businessData.document.id)}}.bind(this))}},getAttachmentUrl:function(t,e){if(this.form.businessData.document){this.form.documentAction.getAttachmentUrl(t.data.id,this.form.businessData.document.id,e)}},createErrorNode:function(t){var e=new Element("div");var i=new Element("div",{styles:{width:"20px",height:"20px",float:"left",background:"url("+"/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"}}).inject(e);var n=new Element("div",{styles:{"line-height":"20px","margin-left":"20px",color:"red","word-break":"keep-all"},text:t}).inject(e);return e},notValidationMode:function(t){if(!this.isNotValidationMode){this.isNotValidationMode=true;this.node.store("borderStyle",this.node.getStyles("border-left","border-right","border-top","border-bottom"));this.node.setStyle("border","1px solid red");this.errNode=this.createErrorNode(t).inject(this.node,"after");this.showNotValidationMode(this.node)}},showNotValidationMode:function(t){var e=t.getParent("div");if(e){if(e.get("MWFtype")=="tab$Content"){if(e.getParent("div").getStyle("display")=="none"){var i=e.getParent("div").getParent("div");var n=i.getPrevious("div");var s=i.getChildren().indexOf(e.getParent("div"));var o=n.getChildren()[s];o.click();e=n.getParent("div")}}this.showNotValidationMode(e)}},validationMode:function(){if(this.isNotValidationMode){this.isNotValidationMode=false;this.node.setStyles(this.node.retrieve("borderStyle"));if(this.errNode){this.errNode.destroy();this.errNode=null}}},validationConfigItem:function(t,e){var i=e.status=="all"?true:t=="publish";if(i){var n=this.getData();var s=e.valueType=="value"?n:n.length;switch(e.operateor){case"isnull":if(!s){this.notValidationMode(e.prompt);return false}break;case"notnull":if(s){this.notValidationMode(e.prompt);return false}break;case"gt":if(s>e.value){this.notValidationMode(e.prompt);return false}break;case"lt":if(s