| 1 |
- MWF.xApplication.cms=MWF.xApplication.cms||{};MWF.xApplication.cms.Xform=MWF.xApplication.cms.Xform||{};MWF.require("MWF.widget.Common",null,false);MWF.require("MWF.xAction.org.express.RestActions",null,false);MWF.xDesktop.requireApp("Selector","package",null,false);MWF.xDesktop.requireApp("process.Xform","Form",null,false);MWF.require("MWF.widget.O2Identity",null,false);MWF.xDesktop.requireApp("cms.Xform","Package",null,false);MWF.xApplication.cms.Xform.Form=MWF.CMSForm=new Class({Implements:[Options,Events],Extends:MWF.APPForm,options:{style:"default",readonly:false,cssPath:"",autoSave:false,saveOnClose:false,showAttachment:true,moduleEvents:["queryLoad","beforeLoad","postLoad","afterLoad","beforeSave","postSave","afterSave","beforeClose","beforePublish","postPublish","afterPublish","beforeModulesLoad","resize","afterModulesLoad"]},initialize:function(t,e,i){this.setOptions(i);this.container=$(t);this.container.setStyle("-webkit-user-select","text");this.data=e;this.json=e.json;this.html=e.html;this.path="/x_component_cms_Xform/$Form/";this.cssPath=this.options.cssPath||"/x_component_cms_Xform/$Form/"+this.options.style+"/css.wcss";this._loadCss();this.modules=[];this.all={};this.forms={}},load:function(){if(this.app){if(this.app.formNode)this.app.formNode.setStyles(this.json.styles);if(this.app.addEvent)this.app.addEvent("resize",function(){this.fireEvent("resize")}.bind(this))}this.Macro=new MWF.CMSMacro.CMSFormContext(this);this.container.set("html",this.html);this.node=this.container.getFirst();this._loadEvents();if(this.fireEvent("queryLoad")){MWF.xDesktop.requireApp("cms.Xform","lp."+MWF.language,null,false);this._loadBusinessData();this.fireEvent("beforeLoad");if(this.app)if(this.app.fireEvent)this.app.fireEvent("beforeLoad");this.loadContent()}},loadContent:function(){this._loadHtml();this._loadForm();this.fireEvent("beforeModulesLoad");this._loadModules(this.node);if(!this.options.readonly){if(this.options.autoSave)this.autoSave();this.app.addEvent("queryClose",function(){if(this.options.saveOnClose&&this.businessData.document.docStatus=="draft")this.saveDocument(null,true);Object.each(this.forms,function(t,e){if(t.json.type=="Htmleditor"&&t.editor){CKEDITOR.remove(t.editor);delete t.editor}})}.bind(this))}this.fireEvent("afterModulesLoad");this.fireEvent("postLoad");this.fireEvent("afterLoad");if(this.app&&this.app.fireEvent){this.app.fireEvent("afterModulesLoad");this.app.fireEvent("postLoad");this.app.fireEvent("afterLoad")}},autoSave:function(){},_loadBusinessData:function(){if(!this.businessData){this.businessData={data:{}}}},_loadEvents:function(){Object.each(this.json.events,function(e,t){if(e.code){if(this.options.moduleEvents.indexOf(t)!=-1){this.addEvent(t,function(t){return this.Macro.fire(e.code,this,t)}.bind(this))}else{if(t=="load"){this.addEvent("postLoad",function(){return this.Macro.fire(e.code,this)}.bind(this))}else if(t=="submit"){this.addEvent("beforePublish",function(){return this.Macro.fire(e.code,this)}.bind(this))}else{this.node.addEvent(t,function(t){return this.Macro.fire(e.code,this,t)}.bind(this))}}}}.bind(this))},_loadModules:function(t){var e=this._getModuleNodes(t);e.each(function(t){var e=this._getDomjson(t);if(!this.options.showAttachment&&e.type=="Attachment"){return}var i=this._loadModule(e,t);this.modules.push(i)}.bind(this))},_loadModule:function(t,e,i){if(!t)return;if(!MWF["CMS"+t.type]){MWF.xDesktop.requireApp("cms.Xform",t.type,null,false)}var s=new MWF["CMS"+t.type](e,t,this);if(i)i.apply(s);if(!this.all[t.id])this.all[t.id]=s;if(s.field){if(!this.forms[t.id])this.forms[t.id]=s}s.readonly=this.options.readonly;s.load();return s},trim:function(t){var e=[];t.each(function(t){if(t)e.push(t)});return e},transportPermissionData:function(t,s){var a=[];t.each(function(t){if(t.distinguishedName){var e=t.distinguishedName.substr(t.distinguishedName.length-1,1);var i;switch(e.toLowerCase()){case"i":i="人员";break;case"p":i="人员";break;case"u":i="组织";break;case"g":i="群组";break;case"r":i="角色";break;default:i=""}if(i){a.push({permission:s=="author"?"作者":"阅读",permissionObjectType:i,permissionObjectName:t.distinguishedName})}}});return a.length>0?a:null},getSpecialData:function(){var a=this.businessData.data;var o=[];var n=[];var r=[];var c=[];var u="";Object.each(this.forms,function(t,e){if(t.json.type=="Readerfield"){if(t.json.section=="yes"){o=o.concat(this.getSectionData(t,a[e]))}else{o=o.concat(t.getData())}}if(t.json.type=="Authorfield"){if(t.json.section=="yes"){n=n.concat(this.getSectionData(t,a[e]))}else{n=n.concat(t.getData())}}if(t.json.type=="ImageClipper"){var i=t.getData();if(i)r.push(i)}if(t.json.type=="Htmleditor"){var s=t.getText();u=s.substr(0,80);c=c.concat(t.getImageIds())}});if(a.processOwnerList&&typeOf(a.processOwnerList)=="array"){var e={personValue:[]};a.processOwnerList.each(function(t){e.personValue.push({name:t,type:"person"})});o=o.concat(e)}return{readers:this.transportPermissionData(o,"reader"),authors:this.transportPermissionData(n,"author"),pictures:r,summary:u,cloudPictures:c}},getDocumentData:function(t){var e=Object.clone(this.businessData.document);if(t.subject){e.title=t.subject;e.subject=t.subject;this.businessData.document.title=t.subject;this.businessData.document.subject=t.subject}e.isNewDocument=false;return e},saveDocument:function(t,e){this.fireEvent("beforeSave");if(!this.formSaveValidation()){this.app.content.unmask();return false}if(this.businessData.document.docStatus=="published"){if(!this.formValidation("publish")){if(t)t();return false}}var i=this.getData();var s=this.getSpecialData();var a=this.getDocumentData(i);a.readerList=s.readers;a.authorList=s.authors;a.pictureList=s.pictures;a.summary=s.summary;a.cloudPictures=s.cloudPictures;a.docData=i;delete a.attachmentList;this.fireEvent("postSave",[a]);if(this.officeList){this.officeList.each(function(t){t.save(history)})}this.documentAction.saveDocument(a,function(){this.notice(MWF.xApplication.cms.Xform.LP.dataSaved,"success");this.businessData.data.isNew=false;this.fireEvent("afterSave");if(t)t()}.bind(this),null,!e)},closeDocument:function(){this.fireEvent("beforeClose");if(this.app){this.app.close()}},formValidation:function(i){if(this.options.readonly)return true;var s=true;Object.each(this.forms,function(t,e){t.validationMode();if(!t.validation(i)){s=false}}.bind(this));return s},formSaveValidation:function(){if(!this.json.validationSave)return true;if(!this.json.validationSave.code)return true;var t=this.Macro.exec(this.json.validationSave.code,this);if(!t)t=MWF.xApplication.cms.Xform.LP.notValidation;if(t.toString()!="true"){return false}return true},formPublishValidation:function(){if(!this.json.validationPublish)return true;if(!this.json.validationPublish.code)return true;var t=this.Macro.exec(this.json.validationPublish.code,this);if(!t)t=MWF.xApplication.cms.Xform.LP.notValidation;if(t.toString()!="true"){return false}return true},publishDocument:function(e){this.fireEvent("beforePublish");this.app.content.mask({destroyOnHide:true,style:this.app.css.maskNode});if(!this.formPublishValidation()){this.app.content.unmask();return false}if(!this.formValidation("publish")){this.app.content.unmask();if(e)e();return false}var t=this.getData();var i=this.getSpecialData();var s=this.getDocumentData(t);s.readerList=i.readers;s.authorList=i.authors;s.pictureList=i.pictures;s.summary=i.summary;s.cloudPictures=i.cloudPictures;s.docData=t;delete s.attachmentList;this.fireEvent("postPublish",[s]);if(this.officeList){this.officeList.each(function(t){t.save(history)})}this.documentAction.publishDocumentComplex(s,function(t){this.businessData.data.isNew=false;this.fireEvent("afterPublish");if(e)e();if(this.businessData.document.title){this.app.notice(MWF.xApplication.cms.Xform.LP.documentPublished+": “"+this.businessData.document.title+"”","success")}else{this.app.notice(MWF.xApplication.cms.Xform.LP.documentPublished,"success")}this.options.saveOnClose=false;this.app.close()}.bind(this))},deleteDocument:function(){var e=this;var t=MWF.getCenterPosition(this.app.content,380,150);var i={event:{x:t.x,y:t.y-200,clientX:t.x,clientY:t.y-200}};this.app.confirm("infor",i,MWF.xApplication.cms.Xform.LP.deleteDocumentTitle,MWF.xApplication.cms.Xform.LP.deleteDocumentText,380,120,function(){e.app.content.mask({style:{"background-color":"#999",opacity:.6}});e.documentAction.removeDocument(e.businessData.document.id,function(t){e.app.notice(MWF.xApplication.cms.Xform.LP.documentDelete+": “"+e.businessData.document.title+"”","success");e.options.autoSave=false;e.options.saveOnClose=false;e.fireEvent("postDelete");e.app.close();this.close()}.bind(this))},function(){this.close()})},editDocument:function(){if(this.app.inBrowser){this.modules.each(function(t){MWF.release(t)});this.app.node.destroy();this.app.options.readonly=false;this.app.loadApplication()}else{var t={documentId:this.businessData.document.id,readonly:false};this.app.desktop.openApplication(null,"cms.Document",t);this.app.close()}},setPopularDocument:function(){this.app.setPopularDocument()},printWork:function(t,e){var i=t||this.businessData.work.application;var e=e;if(!e){e=this.json.id;if(this.json.printForm)e=this.json.printForm}window.open("/x_desktop/printWork.html?workid="+this.businessData.work.id+"&app="+this.businessData.work.application+"&form="+e)},openWindow:function(t,e){var t=t;if(!t){t=this.json.id}if(this.businessData.document){}},uploadedAttachment:function(i,t){this.documentAction.getAttachment(t,this.businessData.document.id,function(t){var e=this.all[i];if(e){if(t.data)e.attachmentController.addAttachment(t.data);e.attachmentController.checkActions();e.fireEvent("upload",[t.data])}}.bind(this))},replacedAttachment:function(o,n){this.documentAction.getAttachment(n,this.businessData.document.id,function(t){var e=this.all[o];if(e){var i=e.attachmentController;var s=null;for(var a=0;a<i.attachments.length;a++){if(i.attachments[a].data.id===n){s=i.attachments[a];break}}s.data=t.data;s.reload();i.checkActions()}}.bind(this))}});
|