MWF.xDesktop.requireApp("process.Xform", "$Module", null, false); /** @class AssociatedDocument 视图选择组件。 * @o2cn 视图选择 * @example * //可以在脚本中获取该组件 * //方法1: * var sourceText = this.form.get("fieldId"); //获取组件 * //方法2 * var sourceText = this.target; //在组件本身的脚本中获取 * @extends MWF.xApplication.process.Xform.Button * @o2category FormComponents * @o2range {Process|CMS} * @hideconstructor */ MWF.xApplication.process.Xform.AssociatedDocument = MWF.APPAssociatedDocument = new Class({ Implements: [Events], Extends: MWF.APP$Module, options: { /** * 视图参数(options)已经准备好,还未加载视图时执行。可以通过this.event得到视图参数,并可修改this.event修改视图的加载。 * @event MWF.xApplication.process.Xform.AssociatedDocument#beforeLoadView * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 异步加载视图后执行。 * @event MWF.xApplication.process.Xform.AssociatedDocument#loadView * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 选中视图中的一条记录后执行。可以通过this.event获取该次选择的记录。 * @event MWF.xApplication.process.Xform.AssociatedDocument#select * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 取消选中视图中的一条记录后执行。可以通过this.event获取该次取消选择的记录。 * @event MWF.xApplication.process.Xform.AssociatedDocument#unselect * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 点击确定后执行的事件。可以通过this.event获取选择的记录列表。 * @event MWF.xApplication.process.Xform.AssociatedDocument#selectResult * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 选择完成后,并且整理了关联文档数据后事件。可以通过this.event获取记录列表。 * @event MWF.xApplication.process.Xform.AssociatedDocument#afterSelectResult * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 删除关联文档前执行的事件。可以通过this.event获取删除的记录。 * @event MWF.xApplication.process.Xform.AssociatedDocument#deleteDocument * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 删除关联文档后执行的事件。可以通过this.event获取删除的记录。 * @event MWF.xApplication.process.Xform.AssociatedDocument#afterDeleteDocument * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ // /** // * 打开关联文档前执行的事件。 // * @event MWF.xApplication.process.Xform.AssociatedDocument#openDocument // * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} // */ "moduleEvents": ["load", "queryLoad", "postLoad", "beforeLoadView", "loadView", "select", "unselect", "selectResult", "afterSelectResult", "deleteDocument","afterDeleteDocument","openDocument"] }, _loadUserInterface: function(){ this.node.set({ "id": this.json.id, "MWFType": this.json.type }); this.documentList = []; var button = this.node.getElement("button"); if( this.isReadonly() ){ if( button )button.hide(); }else{ if (!button) button = new Element("button"); this.button = button; this.button.set({ "text": this.json.buttonText, "styles": this.json.buttonStyles }); this.button.addEvent("click", function(){ this.selectedData = null; this.selectView(function(data){ // if(data.length === 0){ // this.form.notice(MWF.xApplication.process.Xform.LP.selectDocNote, "info"); // return; // } var d = data.map(function (d) { return { "type": d.type === "process" ? "processPlatform" : "cms", "site": this.json.site || this.json.id, "view": d.view, "bundle": d.bundle } }.bind(this)); this.selectDocument(d); }.bind(this)); }.bind(this)); } if(this.json.recoveryStyles){ this.node.setStyles(this.json.recoveryStyles); } this.documentListNode = this.node.getElement(".MWFADContent"); this.documentListNode.setStyles( this.json.documentListNodeStyles || {} ); this.loadAssociatedDocument(); }, selectDocument: function(data){ this.cancelAllAssociated( function () { if( data && data.length ){ o2.Actions.load("x_processplatform_assemble_surface").CorrelationAction.createWithJob(this.form.businessData.work.job, { targetList: data }, function (json) { this.status = "showResult"; if(this.dlg.titleText)this.dlg.titleText.set("text", MWF.xApplication.process.Xform.LP.associatedResult); if( layout.mobile ){ var okAction = this.dlg.node.getElement(".MWF_dialod_Action_ok"); if (okAction) okAction.hide(); }else{ var okNode = this.dlg.button.getFirst(); if(okNode){ okNode.hide(); var cancelButton = okNode.getNext(); if(cancelButton)cancelButton.set("value", o2.LP.widget.close); } } if( (json.data.failureList && json.data.failureList.length) || (json.data.successList && json.data.successList.length) ){ this.showCreateResult(json.data.failureList, json.data.successList); } this.loadAssociatedDocument(function () { this.fireEvent("afterSelectResult", [this.documentList]); }.bind(this)); }.bind(this)); }else{ this.status = "showResult"; this.loadAssociatedDocument(function () { this.fireEvent("afterSelectResult", [this.documentList]); }.bind(this)); if( this.dlg )this.dlg.close(); } }.bind(this)); }, cancelAllAssociated: function( callback ){ var _self = this; if( this.documentList.length ){ var ids = []; if( this.json.reserve === false ){ ids = this.documentList.map(function (doc) { return doc.id; }); }else{ var viewIds = (this.json.queryView || []).map(function (view) { return view.id; }); var docs = this.documentList.filter(function (doc) { return viewIds.contains( doc.view ); }); ids = docs.map(function (doc) { return doc.id; }); } o2.Actions.load("x_processplatform_assemble_surface").CorrelationAction.deleteWithJob(this.getBundle(), { idList: ids },function (json) { //this.documentList = []; if(callback)callback(); }.bind(this)); }else{ if(callback)callback(); } }, loadAssociatedDocument: function( callback ){ this.documentListNode.empty(); o2.Actions.load("x_processplatform_assemble_surface").CorrelationAction.listWithJobWithSite(this.form.businessData.work.job, (this.json.site || this.json.id), function (json) { this.documentList = json.data; this.showDocumentList(); if(callback)callback(); }.bind(this)); }, showCreateResult: function(failureList, successList){ this.viewList.each(function (view) { view.showAssociatedDocumentResult(failureList, successList); }) }, showDocumentList: function(){ this.documentList.each(function(d){ if(d.targetCreatorPerson)d.targetCreatorPersonCn = d.targetCreatorPerson.split("@")[0]; }) this.documentListNode.empty(); switch (this.json.mode) { case "text": this.loadDocumentListText(); break; case "script": this.loadDocumentListScript(); break; case "default": default: this.loadDocumentListDefault(); break; } }, loadDocumentListDefault: function(){ this.documentList.each(function (d) { var itemNode = new Element("div", { styles: this.form.css.associatedDocumentItem }).inject( this.documentListNode ); var iconNode = new Element("div", { styles: this.form.css[ d.targetType === "processPlatform" ? "associatedDocumentWorkIcon" : "associatedDocumentCmsIcon" ] }).inject( itemNode ); var deleteNode; if( !this.isReadonly() ){ deleteNode = new Element("div", { styles: this.form.css.associatedDocumentDelete }).inject( itemNode ); if(!layout.mobile)deleteNode.hide(); } var textNode = new Element("div", { styles: this.form.css.associatedDocumentText, text: d.targetTitle }).inject( itemNode ); this._loadDocument(d, itemNode, deleteNode) }.bind(this)) }, loadDocumentListText: function(){ var lp = MWF.xApplication.process.Xform.LP; this.documentList.each(function (d) { var html = this.json.textStyle; if (this.json.textStyleScript && this.json.textStyleScript.code) { this.form.Macro.environment.line = d; html = this.form.Macro.exec(this.json.textStyleScript.code, this); } html = html.replace(/\{targetTitle\}/g, o2.txt(d.targetTitle)); html = html.replace(/\{targetStartTime\}/g, (d.targetType === "processPlatform") ? d.targetStartTime : d.targetStartTime); html = html.replace(/\{targetCreatorPersonCn\}/g, o2.txt((d.targetType === "processPlatform") ? d.targetCreatorPersonCn : d.targetCreatorPersonCn)); html = html.replace(/\{targetType\}/g, o2.txt((d.targetType === "processPlatform") ? lp.work : lp.document)); html = html.replace(/\{targetCategory\}/g, o2.txt((d.targetType === "processPlatform") ? d.targetCategory : d.targetCategory)); var itemNode = new Element("div", { styles: this.form.css.associatedDocumentItem, html: html }).inject(this.documentListNode); var deleteNode = itemNode.getElement("[data-o2-action='delete']"); if(!layout.mobile)deleteNode.hide(); this._loadDocument(d, itemNode, deleteNode); }.bind(this)) }, loadDocumentListScript: function(){ if (this.json.displayScript && this.json.displayScript.code){ var code = this.json.displayScript.code; this.documentList.each(function(d){ var itemNode = new Element("div", { styles: this.form.css.associatedDocumentItem, }).inject(this.documentListNode); this.form.Macro.environment.line = d; var r = this.form.Macro.exec(code, this); var t = o2.typeOf(r); if (t==="string"){ itemNode.set("html", r); }else if (t==="element"){ r.inject(itemNode); } var deleteNode = itemNode.getElement("[data-o2-action='delete']"); deleteNode.hide(); this._loadDocument(d, itemNode, deleteNode); }.bind(this)); } }, _loadDocument: function(d, itemNode, deleteNode){ if( layout.mobile ){ itemNode.addEvents({ "click": function (e) { this.openDoc(e, d); }.bind(this), }); }else{ itemNode.addEvents({ "mouseover": function () { if(deleteNode)deleteNode.show(); itemNode.setStyles( this.form.css.associatedDocumentItem_over ) }.bind(this), "mouseout": function () { if(deleteNode)deleteNode.hide(); itemNode.setStyles( this.form.css.associatedDocumentItem ) }.bind(this), "click": function (e) { this.openDoc(e, d); }.bind(this), }); } if( deleteNode ){ if( !this.isReadonly() ){ deleteNode.addEvents({ "click": function (ev) { this.cancelAssociated(ev, d, itemNode); ev.stopPropagation(); }.bind(this) }); }else{ deleteNode.hide(); } } if( this.json.showCard !== false ){ this.createInforNode( itemNode, d ); } }, cancelAssociated: function(e, d, itemNode){ var lp = MWF.xApplication.process.Xform.LP; var _self = this; this.form.confirm("warn", e, lp.cancelAssociatedTitle, lp.cancelAssociated.replace("{title}", o2.txt(d.targetTitle)), 370, 120, function () { _self.fireEvent("deleteDocument", [d]); o2.Actions.load("x_processplatform_assemble_surface").CorrelationAction.deleteWithJob(_self.form.businessData.work.job, { idList: [d.id] },function (json) { itemNode.destroy(); _self.documentList.erase(d); _self.fireEvent("afterDeleteDocument", [d]); this.close(); //this.showDocumentList(); }.bind(this)); }, function () { this.close(); }, null, null, this.form.json.confirmStyle); }, createInforNode: function(itemNode, d){ var lp = MWF.xApplication.process.Xform.LP; var inforNode = new Element("div"); var html = ""; var lineStyle = "clear: both; overflow:hidden"; var titleStyle = "width:60px; float:left; font-weight: bold"; var contentStyle = "width:120px; float:left; margin-left:10px"; if( d.targetType === "processPlatform" ){ html += "