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 flag = true; if (this.options.isDeleteOption==="o"){ for (var i=0; i 0 ){ // this.form.documentAction.getAttachmentUrl(attachments[attachments.length-1].data.id, this.form.businessData.document.id, function(url){ // if(this.postSelect)this.postSelect( url ) // }.bind(this)) //} if( attachments.length > 0 ){ var data = attachments[attachments.length-1].data; this.form.documentAction.getAttachmentUrl( data.id, this.form.businessData.document.id, function(url){ if( this.attachmentController.options.toBase64 ){ this.form.documentAction.getSubjectAttachmentBase64( data.id, this.attachmentController.options.base64MaxSize, function( json ){ var base64Code = json.data ? "data:image/png;base64,"+json.data.value : null; if(this.postSelect)this.postSelect( url , data, base64Code ) }.bind(this) ) }else{ if(this.postSelect)this.postSelect( url , data ) } }.bind(this)) } }, createUploadFileNode: function(){ this.attachmentController.doUploadAttachment({"site": this.json.id}, this.form.documentAction.action, "uploadAttachment", {"id": this.form.businessData.document.id}, null, function(o){ if (o.id){ this.form.documentAction.getAttachment(o.id, this.form.businessData.document.id, function(json){ if (json.data){ this.attachmentController.addAttachment(json.data); this.form.businessData.attachmentList.push(json.data); } this.attachmentController.checkActions(); this.fireEvent("upload", [json.data]); }.bind(this)) } this.attachmentController.checkActions(); }.bind(this), function(files){ if (files.length){ if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){ var content = MWF.xApplication.cms.Xform.LP.uploadMore; content = content.replace("{n}", this.attachmentController.options.attachmentCount); this.form.notice(content, "error"); return false; } } return true; }.bind(this)); // this.uploadFileAreaNode = new Element("div"); // var html = ""; // this.uploadFileAreaNode.set("html", html); // // this.fileUploadNode = this.uploadFileAreaNode.getFirst(); // this.fileUploadNode.addEvent("change", function(){ // this.validationMode(); // var files = this.fileUploadNode.files; // if (files.length){ // if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){ // var content = MWF.xApplication.cms.Xform.LP.uploadMore; // content = content.replace("{n}", this.attachmentController.options.attachmentCount); // this.form.notice(content, "error"); // }else{ // for (var i = 0; i < files.length; i++) { // var file = files.item(i); // // var formData = new FormData(); // formData.append('file', file); // formData.append('site', this.json.id); // //formData.append('folder', folderId); // // this.form.documentAction.uploadAttachment(this.form.businessData.document.id ,function(o, text){ // if (o.id){ // this.form.documentAction.getAttachment(o.id, this.form.businessData.document.id, function(json){ // if (json.data){ // this.attachmentController.addAttachment(json.data); // this.form.businessData.attachmentList.push(json.data); // } // this.attachmentController.checkActions(); // // this.fireEvent("upload", [json.data]); // }.bind(this)) // } // this.attachmentController.checkActions(); // }.bind(this), null, formData, file); // } // } // } // }.bind(this)); }, uploadAttachment: function(e, node){ if (window.o2android && window.o2android.uploadAttachment){ window.o2android.uploadAttachment(this.json.id); }else if(window.webkit && window.webkit.messageHandlers) { window.webkit.messageHandlers.uploadAttachment.postMessage({"site": this.json.id}); }else{ // if (!this.uploadFileAreaNode){ this.createUploadFileNode(); // } // this.fileUploadNode.click(); } }, getData: function(){ return this.attachmentController.getAttachmentNames(); }, //getInputData : function(){ // return this.getData(); //}, deleteAttachments: function(e, node, attachments){ var names = []; attachments.each(function(attachment){ names.push(attachment.data.name); }.bind(this)); var _self = this; this.form.confirm("warn", e, MWF.xApplication.cms.Xform.LP.deleteAttachmentTitle, MWF.xApplication.cms.Xform.LP.deleteAttachment+"( "+names.join(", ")+" )", 300, 120, function(){ while (attachments.length){ var attachment = attachments.shift(); _self.deleteAttachment(attachment); } this.close(); }, function(){ this.close(); }, null); }, deleteAttachment: function(attachment){ this.fireEvent("delete", [attachment.data]); this.form.documentAction.deleteAttachment(attachment.data.id, function(json ){ this.attachmentController.removeAttachment(attachment); //this.form.businessData.attachmentList.erase( attachment.data ) this.attachmentController.checkActions(); this.fireEvent("afterDelete", [attachment.data]); }.bind(this)); }, replaceAttachment: function(e, node, attachment){ if (window.o2android && window.o2android.replaceAttachment){ window.o2android.replaceAttachment(attachment.data.id, this.json.id); }else if(window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.replaceAttachment) { window.webkit.messageHandlers.replaceAttachment.postMessage({"id": attachment.data.id, "site": this.json.id}); }else { var _self = this; this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.replaceAttachmentTitle, MWF.xApplication.process.Xform.LP.replaceAttachment+"( "+attachment.data.name+" )", 350, 120, function(){ _self.replaceAttachmentFile(attachment); this.close(); }, function(){ this.close(); }, null); } }, createReplaceFileNode: function(attachment){ this.attachmentController.doUploadAttachment({"site": this.json.id}, this.form.documentAction.action, "replaceAttachment", {"id": attachment.data.id, "documentid": this.form.businessData.document.id}, null, function(o){ this.form.documentAction.getAttachment(attachment.data.id, this.form.businessData.document.id, function(json){ attachment.data = json.data; attachment.reload(); this.attachmentController.checkActions(); }.bind(this)) }.bind(this), null); // this.replaceFileAreaNode = new Element("div"); // var html = ""; // this.replaceFileAreaNode.set("html", html); // // this.fileReplaceNode = this.replaceFileAreaNode.getFirst(); // this.fileReplaceNode.addEvent("change", function(){ // var files = this.fileReplaceNode.files; // if (files.length){ // for (var i = 0; i < files.length; i++) { // var file = files.item(i); // // var formData = new FormData(); // formData.append('file', file); // // formData.append('site', this.json.id); // // this.form.documentAction.replaceAttachment(attachment.data.id, this.form.businessData.document.id ,function(o, text){ // this.form.documentAction.getAttachment(attachment.data.id, this.form.businessData.document.id, function(json){ // attachment.data = json.data; // attachment.reload(); // this.attachmentController.checkActions(); // }.bind(this)) // }.bind(this), null, formData, file); // } // } // }.bind(this)); }, replaceAttachmentFile: function(attachment){ //if (!this.replaceFileAreaNode){ this.createReplaceFileNode(attachment); // } // this.fileReplaceNode.click(); }, downloadAttachment: function(e, node, attachments){ if (this.form.businessData.document){ attachments.each(function(att){ if (window.o2android && window.o2android.downloadAttachment){ window.o2android.downloadAttachment(att.data.id); }else if(window.webkit && window.webkit.messageHandlers) { window.webkit.messageHandlers.downloadAttachment.postMessage({"id": att.data.id, "site": this.json.id}); }else{ this.form.documentAction.getAttachmentStream(att.data.id, this.form.businessData.document.id); } }.bind(this)); } }, openAttachment: function(e, node, attachments){ if (this.form.businessData.document){ attachments.each(function(att){ if (window.o2android && window.o2android.downloadAttachment){ window.o2android.downloadAttachment(att.data.id); }else if(window.webkit && window.webkit.messageHandlers) { window.webkit.messageHandlers.downloadAttachment.postMessage({"id": att.data.id, "site": this.json.id}); }else { this.form.documentAction.getAttachmentData(att.data.id, this.form.businessData.document.id); } }.bind(this)); } //this.downloadAttachment(e, node, attachment); }, getAttachmentUrl: function(attachment, callback){ if (this.form.businessData.document){ this.form.documentAction.getAttachmentUrl(attachment.data.id, this.form.businessData.document.id, callback); } }, createErrorNode: function(text){ var node = new Element("div"); var iconNode = 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(node); var textNode = new Element("div", { "styles": { "line-height": "20px", "margin-left": "20px", "color": "red", "word-break": "keep-all" }, "text": text }).inject(node); return node; }, notValidationMode: function(text){ 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(text).inject(this.node, "after"); this.showNotValidationMode(this.node); } }, showNotValidationMode: function(node){ var p = node.getParent("div"); if (p){ if (p.get("MWFtype") == "tab$Content"){ if (p.getParent("div").getStyle("display")=="none"){ var contentAreaNode = p.getParent("div").getParent("div"); var tabAreaNode = contentAreaNode.getPrevious("div"); var idx = contentAreaNode.getChildren().indexOf(p.getParent("div")); var tabNode = tabAreaNode.getChildren()[idx]; tabNode.click(); p = tabAreaNode.getParent("div"); } } this.showNotValidationMode(p); } }, 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(routeName, data){ var flag = (data.status=="all") ? true: (routeName == "publish"); if (flag){ var n = this.getData(); var v = (data.valueType=="value") ? n : n.length; switch (data.operateor){ case "isnull": if (!v){ this.notValidationMode(data.prompt); return false; } break; case "notnull": if (v){ this.notValidationMode(data.prompt); return false; } break; case "gt": if (v>data.value){ this.notValidationMode(data.prompt); return false; } break; case "lt": if (v