Form.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. MWF.xApplication.cms = MWF.xApplication.cms || {};
  2. MWF.xApplication.cms.Xform = MWF.xApplication.cms.Xform || {};
  3. MWF.require("MWF.widget.Common", null, false);
  4. // MWF.require("MWF.xAction.org.express.RestActions", null, false);
  5. MWF.xDesktop.requireApp("Selector", "package", null, false);
  6. MWF.xDesktop.requireApp("process.Xform", "Form", null, false);
  7. MWF.require("MWF.widget.O2Identity", null, false);
  8. MWF.xDesktop.requireApp("cms.Xform", "Package", null, false);
  9. /** @class CMSForm 内容管理表单。
  10. * @o2category FormComponents
  11. * @o2range {CMS}
  12. * @alias CMSForm
  13. * @example
  14. * //可以在脚本中获取表单
  15. * //方法1:
  16. * var form = this.form.getApp().appForm; //获取表单
  17. * //方法2
  18. * var form = this.target; //在表单本身的事件脚本中获取
  19. * @hideconstructor
  20. */
  21. MWF.xApplication.cms.Xform.Form = MWF.CMSForm = new Class(
  22. /** @lends CMSForm# */
  23. {
  24. Implements: [Options, Events],
  25. Extends: MWF.APPForm,
  26. options: {
  27. "style": "default",
  28. "readonly": false,
  29. "cssPath": "",
  30. "autoSave": false,
  31. "saveOnClose": false,
  32. "showAttachment": true,
  33. "moduleEvents": [
  34. /**
  35. * 表单加载前触发。表单html已经就位。
  36. * @event CMSForm#queryLoad
  37. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  38. */
  39. "queryLoad",
  40. /**
  41. * 表单加载前触发。数据(businessData)已经就绪。
  42. * @event CMSForm#beforeLoad
  43. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  44. */
  45. "beforeLoad",
  46. /**
  47. * 表单的所有组件加载前触发,此时表单的样式和js head已经加载。
  48. * @event CMSForm#beforeModulesLoad
  49. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  50. */
  51. "beforeModulesLoad",
  52. /**
  53. * 表单加载后触发。
  54. * @event CMSForm#postLoad
  55. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  56. */
  57. "postLoad",
  58. /**
  59. * 表单的所有组件加载后触发。
  60. * @event CMSForm#afterModulesLoad
  61. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  62. */
  63. "afterModulesLoad",
  64. /**
  65. * 表单加载后触发。
  66. * @event CMSForm#afterLoad
  67. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  68. */
  69. "afterLoad",
  70. /**
  71. * 保存前触发。
  72. * @event CMSForm#beforeSave
  73. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  74. */
  75. "beforeSave",
  76. /**
  77. * 数据已经整理完成,但还未保存到后台时触发。this.event指向整理完成的数据
  78. * @event CMSForm#afterSave
  79. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  80. */
  81. "postSave",
  82. /**
  83. * 数据保存到后台后触发。
  84. * @event CMSForm#afterSave
  85. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  86. */
  87. "afterSave",
  88. /**
  89. * 关闭前触发。
  90. * @event CMSForm#beforeClose
  91. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  92. */
  93. "beforeClose",
  94. /**
  95. * 发布前触发。
  96. * @event CMSForm#beforePublish
  97. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  98. */
  99. "beforePublish",
  100. /**
  101. * 数据已经整理完成,但还未调用服务发布触发。this.event指向整理完成的数据
  102. * @event CMSForm#postPublish
  103. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  104. */
  105. "postPublish",
  106. /**
  107. * 执行后台服务发布后触发。
  108. * @event CMSForm#afterPublish
  109. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  110. */
  111. "afterPublish",
  112. /**
  113. * 删除前触发。
  114. * @event CMSForm#beforeDelete
  115. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  116. */
  117. "beforeDelete",
  118. /**
  119. * 删除后触发。
  120. * @event CMSForm#afterDelete
  121. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  122. */
  123. "afterDelete",
  124. "resize"
  125. ]
  126. },
  127. /**
  128. * @summary 获取表单的所有数据.
  129. * @method getData
  130. * @memberof CMSForm
  131. * @example
  132. * var data = this.form.getApp().appForm.getData();
  133. * @return {Object}
  134. */
  135. initialize: function (node, data, options) {
  136. this.setOptions(options);
  137. /**
  138. * @summary 表单容器
  139. * @see https://mootools.net/core/docs/1.6.0/Element/Element
  140. * @member {Element}
  141. * @example
  142. * //可以在脚本中获取表单容器
  143. * var formContainer = this.form.getApp().appForm.container;
  144. */
  145. this.container = $(node);
  146. this.container.setStyle("-webkit-user-select", "text");
  147. this.data = data;
  148. /**
  149. * @summary 表单的配置信息,比如表单名称等等.
  150. * @member {Object}
  151. * @example
  152. * //可以在脚本中获取表单配置信息
  153. * var json = this.form.getApp().appForm.json; //表单配置信息
  154. * var name = json.name; //表单名称
  155. */
  156. this.json = data.json;
  157. this.html = data.html;
  158. this.path = "../x_component_cms_Xform/$Form/";
  159. this.cssPath = this.options.cssPath || "../x_component_cms_Xform/$Form/" + this.options.style + "/css.wcss";
  160. this._loadCss();
  161. /**
  162. * @summary 表单中的所有组件数组.
  163. * @member {Array}
  164. * @example
  165. * //下面的样例对表单组件进行循环,并且判断是输入类型的组件
  166. * var modules = this.form.getApp().appForm.modules; //获取所有表单组件
  167. * for( var i=0; i<modules.length; i++ ){ //循环处理组件
  168. * //获取组件的类型
  169. var moduleName = module.json.moduleName;
  170. if( !moduleName ){
  171. moduleName = typeOf(module.json.type) === "string" ? module.json.type.toLowerCase() : "";
  172. }
  173. if( ["calendar","combox","number","textfield"].contains( moduleName )){ //输入类型框
  174. //do something
  175. }
  176. * }
  177. */
  178. this.modules = [];
  179. /**
  180. * 该对象的key是组件标识,value是组件对象,可以使用该对象根据组件标识获取组件。<br/>
  181. * 需要注意的是,在子表单中嵌入不绑定数据的组件(比如div,common,button等等),系统允许重名。<br/>
  182. * 在打开表单的时候,系统会根据重名情况,自动在组件的标识后跟上 "_1", "_2"。
  183. * @summary 表单中的所有组件对象.
  184. * @member {Object}
  185. * @example
  186. * var moduleAll = this.form.getApp().appForm.all; //获取组件对象
  187. * var subjectField = moduleAll["subject"] //获取名称为subject的组件
  188. */
  189. this.all = {};
  190. this.forms = {};
  191. //if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  192. },
  193. load: function (callback) {
  194. if (this.app) {
  195. if (this.app.formNode) this.app.formNode.setStyles(this.json.styles);
  196. if (this.app.addEvent) this.app.addEvent("resize", function () {
  197. this.fireEvent("resize");
  198. }.bind(this))
  199. }
  200. //if (!this.businessData.control.allowSave) this.setOptions({"readonly": true});
  201. this.Macro = new MWF.CMSMacro.CMSFormContext(this);
  202. this.container.set("html", this.html);
  203. this.node = this.container.getFirst();
  204. this._loadEvents();
  205. this.loadRelatedScript();
  206. if (this.fireEvent("queryLoad")) {
  207. MWF.xDesktop.requireApp("cms.Xform", "lp." + MWF.language, null, false);
  208. // this.container.setStyles(this.css.container);
  209. this._loadBusinessData();
  210. this.fireEvent("beforeLoad");
  211. if (this.app) if (this.app.fireEvent) this.app.fireEvent("beforeLoad");
  212. this.loadContent(callback)
  213. }
  214. },
  215. loadRelatedScript: function () {
  216. if (this.json.includeScripts && this.json.includeScripts.length) {
  217. var includeScriptText = "";
  218. var includedIds = [];
  219. this.json.includeScripts.each(function (s) {
  220. if (this.app.relatedScriptMap && this.app.relatedScriptMap[s.id]) {
  221. includeScriptText += "\n" + this.app.relatedScriptMap[s.id].text;
  222. includedIds.push(s.id);
  223. }
  224. }.bind(this));
  225. if (includeScriptText) this.Macro.exec(includeScriptText, this);
  226. }
  227. },
  228. loadContent: function (callback) {
  229. this.subformCount = 0;
  230. this.subformLoadedCount = 0;
  231. this.subformLoaded = [this.json.id];
  232. this._loadHtml();
  233. this._loadForm();
  234. this.fireEvent("beforeModulesLoad");
  235. this._loadModules(this.node);
  236. if (!this.options.readonly) {
  237. if (this.options.autoSave) this.autoSave();
  238. this.app.addEvent("queryClose", function () {
  239. if (this.options.saveOnClose && this.businessData.document.docStatus == "draft") this.saveDocument(null, true);
  240. //if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  241. Object.each(this.forms, function (module, id) {
  242. if (module.json.type == "Htmleditor" && module.editor) {
  243. //if(CKEDITOR.currentImageDialog)CKEDITOR.currentImageDialog.destroy();
  244. //CKEDITOR.currentImageDialog = null;
  245. CKEDITOR.remove(module.editor);
  246. delete module.editor
  247. }
  248. });
  249. }.bind(this));
  250. }
  251. this.fireEvent("afterModulesLoad");
  252. this.fireEvent("postLoad");
  253. this.fireEvent("afterLoad");
  254. if (this.app && this.app.fireEvent) {
  255. this.app.fireEvent("afterModulesLoad");
  256. this.app.fireEvent("postLoad");
  257. this.app.fireEvent("afterLoad");
  258. }
  259. // 告诉移动端表单加载完成
  260. if (this.app && this.app.mobile) {
  261. if (callback) callback();
  262. }
  263. },
  264. autoSave: function () {
  265. //this.autoSaveTimerID = window.setInterval(function(){
  266. // this.saveDocument();
  267. //}.bind(this), 300000);
  268. },
  269. _loadBusinessData: function () {
  270. if (!this.businessData) {
  271. this.businessData = {
  272. "data": {}
  273. };
  274. }
  275. },
  276. _loadEvents: function () {
  277. Object.each(this.json.events, function (e, key) {
  278. if (e.code) {
  279. if (this.options.moduleEvents.indexOf(key) != -1) {
  280. this.addEvent(key, function (event) {
  281. return this.Macro.fire(e.code, this, event);
  282. }.bind(this));
  283. } else {
  284. if (key == "load") {
  285. this.addEvent("postLoad", function () {
  286. return this.Macro.fire(e.code, this);
  287. }.bind(this));
  288. } else if (key == "submit") {
  289. this.addEvent("beforePublish", function () {
  290. return this.Macro.fire(e.code, this);
  291. }.bind(this));
  292. } else {
  293. this.node.addEvent(key, function (event) {
  294. return this.Macro.fire(e.code, this, event);
  295. }.bind(this));
  296. }
  297. }
  298. }
  299. }.bind(this));
  300. },
  301. _loadModules: function (dom) {
  302. //var subDom = this.node.getFirst();
  303. //while (subDom){
  304. // if (subDom.get("MWFtype")){
  305. // var json = this._getDomjson(subDom);
  306. // var module = this._loadModule(json, subDom);
  307. // this.modules.push(module);
  308. // }
  309. // subDom = subDom.getNext();
  310. //}
  311. var moduleNodes = this._getModuleNodes(dom);
  312. moduleNodes.each(function (node) {
  313. var json = this._getDomjson(node);
  314. if (!this.options.showAttachment && json.type == "Attachment") {
  315. return;
  316. }
  317. //移动端去掉操作栏
  318. if (this.app.mobile && json.type === "Actionbar") {
  319. return;
  320. }
  321. var module = this._loadModule(json, node);
  322. this.modules.push(module);
  323. }.bind(this));
  324. },
  325. _loadModule: function (json, node, beforeLoad) {
  326. if (!json) return;
  327. if (!MWF["CMS" + json.type]) {
  328. MWF.xDesktop.requireApp("cms.Xform", json.type, null, false);
  329. }
  330. var module = new MWF["CMS" + json.type](node, json, this);
  331. if (beforeLoad) beforeLoad.apply(module);
  332. if (!this.all[json.id]) this.all[json.id] = module;
  333. if (module.field) {
  334. if (!this.forms[json.id]) this.forms[json.id] = module;
  335. }
  336. module.readonly = this.options.readonly;
  337. module.load();
  338. return module;
  339. },
  340. //getData: function(){
  341. // var data= Object.clone(this.businessData.data);
  342. // Object.each(this.forms, function(module, id){
  343. // debugger;
  344. // if (module.json.section=="yes"){
  345. // data[id] = this.getSectionData(module, data[id]);
  346. // }else{
  347. // data[id] = module.getData();
  348. // }
  349. // }.bind(this));
  350. //
  351. // this.businessData.data = data;
  352. // this.Macro.environment.setData(this.businessData.data);
  353. // return data;
  354. //},
  355. trim: function (array) {
  356. var arr = [];
  357. array.each(function (v) {
  358. if (v) arr.push(v);
  359. });
  360. return arr;
  361. },
  362. transportPermissionData: function (array, t) {
  363. var result = [];
  364. array.each(function (data) {
  365. var dn = typeOf(data) === "string" ? data : data.distinguishedName;
  366. if (dn) {
  367. var flag = dn.substr(dn.length - 1, 1);
  368. var type;
  369. switch (flag.toLowerCase()) {
  370. case "i":
  371. type = "人员"; //"身份";
  372. break;
  373. case "p":
  374. type = "人员";
  375. break;
  376. case "u":
  377. type = "组织";
  378. break;
  379. case "g":
  380. type = "群组";
  381. break;
  382. case "r":
  383. type = "角色";
  384. break;
  385. default:
  386. type = "";
  387. //result.push( data );
  388. }
  389. if (type) {
  390. var name;
  391. if( typeOf(data) === "object" && data.name ){
  392. name = data.name;
  393. }else if( MWF.name && MWF.name.cn ){
  394. name = MWF.name.cn( dn );
  395. }else{
  396. name = dn.split("@")[0];
  397. }
  398. result.push({
  399. permission: t == "author" ? "作者" : "阅读",
  400. permissionObjectType: type,
  401. permissionObjectName: name,
  402. permissionObjectCode: dn
  403. })
  404. }
  405. }
  406. });
  407. return result.length > 0 ? result : null;
  408. },
  409. getSpecialData: function () {
  410. var data = this.businessData.data;
  411. var readers = [];
  412. var authors = [];
  413. var pictures = [];
  414. var cloudPictures = [];
  415. var summary = "";
  416. Object.each(this.forms, function (module, id) {
  417. if (module.json.type == "Readerfield" || module.json.type == "Reader") {
  418. if (module.json.section == "yes") {
  419. readers = readers.concat(this.getSectionData(module, data[id]));
  420. } else {
  421. readers = readers.concat(module.getData());
  422. }
  423. }
  424. if (module.json.type == "Authorfield" || module.json.type == "Author") {
  425. if (module.json.section == "yes") {
  426. authors = authors.concat(this.getSectionData(module, data[id]));
  427. } else {
  428. authors = authors.concat(module.getData());
  429. }
  430. }
  431. if (module.json.type == "ImageClipper") {
  432. var d = module.getData();
  433. if (d) pictures.push(d);
  434. }
  435. if (module.json.type == "Htmleditor") {
  436. var text = module.getText();
  437. summary = text.substr(0, 80);
  438. cloudPictures = cloudPictures.concat(module.getImageIds());
  439. }
  440. });
  441. if (data.processOwnerList && typeOf(data.processOwnerList) == "array") { //如果是流程中发布的
  442. var owner = { personValue: [] };
  443. data.processOwnerList.each(function (p) {
  444. owner.personValue.push({
  445. name: p,
  446. type: "person"
  447. });
  448. });
  449. readers = readers.concat(owner);
  450. }
  451. return {
  452. readers: this.transportPermissionData(readers, "reader"),
  453. authors: this.transportPermissionData(authors, "author"),
  454. pictures: pictures,
  455. summary: summary,
  456. cloudPictures: cloudPictures
  457. };
  458. },
  459. getDocumentData: function (formData) {
  460. var data = Object.clone(this.businessData.document);
  461. if (formData.subject) {
  462. data.title = formData.subject;
  463. data.subject = formData.subject;
  464. this.businessData.document.title = formData.subject;
  465. this.businessData.document.subject = formData.subject;
  466. }
  467. data.isNewDocument = false;
  468. return data;
  469. },
  470. saveDocument: function (callback, sync) {
  471. this.fireEvent("beforeSave");
  472. if (this.businessData.document.docStatus == "published") {
  473. if (!this.formValidation("publish")) {
  474. this.app.content.unmask();
  475. //if (callback) callback();
  476. return false;
  477. }
  478. }
  479. if (!this.formSaveValidation()) {
  480. this.app.content.unmask();
  481. if (callback) callback();
  482. return false;
  483. }
  484. var data = this.getData();
  485. var specialData = this.getSpecialData();
  486. var documentData = this.getDocumentData(data);
  487. documentData.readerList = specialData.readers;
  488. documentData.authorList = specialData.authors;
  489. documentData.pictureList = specialData.pictures;
  490. documentData.summary = specialData.summary;
  491. documentData.cloudPictures = specialData.cloudPictures;
  492. documentData.docData = data;
  493. delete documentData.attachmentList;
  494. this.fireEvent("postSave", [documentData]);
  495. if (this.officeList) {
  496. this.officeList.each(function (module) {
  497. module.save();
  498. });
  499. }
  500. this.documentAction.saveDocument(documentData, function () {
  501. //this.documentAction.saveData(function(json){
  502. this.app.notice(MWF.xApplication.cms.Xform.LP.dataSaved, "success");
  503. this.businessData.data.isNew = false;
  504. this.fireEvent("afterSave");
  505. if (callback) callback();
  506. //}.bind(this), null, this.businessData.document.id, data, !sync );
  507. }.bind(this), null, !sync);
  508. },
  509. closeDocument: function () {
  510. this.fireEvent("beforeClose");
  511. if (this.app) {
  512. this.app.close();
  513. }
  514. },
  515. printDocument: function (form) {
  516. var form = form;
  517. if (!form) {
  518. form = this.json.id;
  519. if (this.json.printForm && this.json.printForm !== "none") form = this.json.printForm;
  520. }
  521. window.open(o2.filterUrl("../x_desktop/printcmsdoc.html?documentid=" + this.businessData.document.id + "&form=" + form));
  522. },
  523. formValidation: function (status) {
  524. if (this.options.readonly) return true;
  525. var flag = true;
  526. //flag = this.validation();
  527. Object.each(this.forms, function (field, key) {
  528. field.validationMode();
  529. if (!field.validation(status)) {
  530. flag = false;
  531. }
  532. }.bind(this));
  533. return flag;
  534. },
  535. formSaveValidation: function () {
  536. if (!this.json.validationSave) return true;
  537. if (!this.json.validationSave.code) return true;
  538. var flag = this.Macro.exec(this.json.validationSave.code, this);
  539. if (!flag) flag = MWF.xApplication.cms.Xform.LP.notValidation;
  540. if (typeOf(flag) === "string") {
  541. if (flag !== "true") {
  542. this.app.notice(flag, "error");
  543. return false;
  544. }
  545. } else if (flag.toString() != "true") {
  546. return false;
  547. }
  548. return true;
  549. },
  550. formPublishValidation: function () {
  551. if (!this.json.validationPublish) return true;
  552. if (!this.json.validationPublish.code) return true;
  553. var flag = this.Macro.exec(this.json.validationPublish.code, this);
  554. if (!flag) flag = MWF.xApplication.cms.Xform.LP.notValidation;
  555. if (typeOf(flag) === "string") {
  556. if (flag !== "true") {
  557. this.app.notice(flag, "error");
  558. return false;
  559. }
  560. } else if (flag.toString() != "true") {
  561. return false;
  562. }
  563. return true;
  564. },
  565. publishDocument: function (callback) {
  566. this.fireEvent("beforePublish");
  567. this.app.content.mask({
  568. "destroyOnHide": true,
  569. "style": this.app.css.maskNode
  570. });
  571. if (!this.formValidation("publish")) {
  572. this.app.content.unmask();
  573. //if (callback) callback();
  574. return false;
  575. }
  576. if (!this.formPublishValidation()) {
  577. this.app.content.unmask();
  578. if (callback) callback();
  579. return false;
  580. }
  581. var data = this.getData();
  582. var specialData = this.getSpecialData();
  583. //this.documentAction.saveData(function(json){
  584. var documentData = this.getDocumentData(data);
  585. documentData.readerList = specialData.readers;
  586. documentData.authorList = specialData.authors;
  587. documentData.pictureList = specialData.pictures;
  588. documentData.summary = specialData.summary;
  589. documentData.cloudPictures = specialData.cloudPictures;
  590. documentData.docData = data;
  591. delete documentData.attachmentList;
  592. //this.documentAction.saveDocument(documentData, function(){
  593. this.fireEvent("postPublish", [documentData]);
  594. if (this.app) if (this.app.fireEvent) this.app.fireEvent("postPublish",[documentData]);
  595. if (this.officeList) {
  596. this.officeList.each(function (module) {
  597. module.save();
  598. });
  599. }
  600. this.documentAction.publishDocumentComplex(documentData, function (json) {
  601. this.businessData.data.isNew = false;
  602. this.fireEvent("afterPublish", [this, json.data]);
  603. if (this.app) if (this.app.fireEvent) this.app.fireEvent("afterPublish",[this, json.data]);
  604. if (callback) callback();
  605. if (this.app.mobile) {
  606. this.app.content.unmask();
  607. console.log('这里是移动端');
  608. } else {
  609. if (this.businessData.document.title) {
  610. this.app.notice(MWF.xApplication.cms.Xform.LP.documentPublished + ": “" + this.businessData.document.title + "”", "success");
  611. } else {
  612. this.app.notice(MWF.xApplication.cms.Xform.LP.documentPublished, "success");
  613. }
  614. this.options.saveOnClose = false;
  615. }
  616. debugger;
  617. if( layout.inBrowser ){
  618. try{
  619. if( window.opener && window.opener.o2RefreshCMSView ){
  620. window.opener.o2RefreshCMSView();
  621. }
  622. }catch (e) {}
  623. window.setTimeout(function () {
  624. this.app.close();
  625. }.bind(this), 1500)
  626. }else{
  627. this.app.close();
  628. }
  629. }.bind(this));
  630. //}.bind(this))
  631. //}.bind(this), null, this.businessData.document.id, data);
  632. },
  633. //publishDocument_bak: function(callback){
  634. // this.fireEvent("beforePublish");
  635. // this.app.content.mask({
  636. // "destroyOnHide": true,
  637. // "style": this.app.css.maskNode
  638. // });
  639. // if (!this.formValidation("publish")){
  640. // this.app.content.unmask();
  641. // if (callback) callback();
  642. // return false;
  643. // }
  644. //
  645. // var data = this.getData();
  646. // var specialData = this.getSpecialData();
  647. // this.documentAction.saveData(function(json){
  648. // this.businessData.data.isNew = false;
  649. // var documentData = this.getDocumentData(data);
  650. // documentData.permissionList = specialData.readers;
  651. // documentData.pictureList = specialData.pictures;
  652. // documentData.summary = specialData.summary;
  653. // delete documentData.attachmentList;
  654. // this.documentAction.saveDocument(documentData, function(){
  655. // this.documentAction.publishDocument(documentData, function(json){
  656. // this.fireEvent("afterPublish");
  657. // this.fireEvent("postPublish");
  658. // if (callback) callback();
  659. // this.app.notice(MWF.xApplication.cms.Xform.LP.documentPublished+": “"+this.businessData.document.title+"”", "success");
  660. // this.options.saveOnClose = false;
  661. // this.app.close();
  662. // //this.close();
  663. // }.bind(this) );
  664. // }.bind(this))
  665. // }.bind(this), null, this.businessData.document.id, data);
  666. //},
  667. deleteDocumentForMobile: function () {
  668. if (this.app.mobile) {
  669. this.app.content.mask({
  670. "style": {
  671. "background-color": "#999",
  672. "opacity": 0.6
  673. }
  674. });
  675. this.fireEvent("beforeDelete");
  676. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeDelete");
  677. this.documentAction.removeDocument(this.businessData.document.id, function (json) {
  678. this.fireEvent("afterDelete");
  679. if (this.app && this.app.fireEvent) this.app.fireEvent("afterDelete");
  680. this.app.notice(MWF.xApplication.cms.Xform.LP.documentDelete + ": “" + this.businessData.document.title + "”", "success");
  681. this.options.autoSave = false;
  682. this.options.saveOnClose = false;
  683. this.fireEvent("postDelete");
  684. this.app.close();
  685. }.bind(this));
  686. }
  687. },
  688. /**
  689. * @summary 弹出删除文档确认框.
  690. * @method deleteDocument
  691. * @memberof CMSForm
  692. * @example
  693. * this.form.getApp().appForm.deleteDocument();
  694. */
  695. deleteDocument: function () {
  696. var _self = this;
  697. var p = MWF.getCenterPosition(this.app.content, 380, 150);
  698. var event = {
  699. "event": {
  700. "x": p.x,
  701. "y": p.y - 200,
  702. "clientX": p.x,
  703. "clientY": p.y - 200
  704. }
  705. };
  706. this.app.confirm("infor", event, MWF.xApplication.cms.Xform.LP.deleteDocumentTitle, MWF.xApplication.cms.Xform.LP.deleteDocumentText, 380, 120, function () {
  707. _self.app.content.mask({
  708. "style": {
  709. "background-color": "#999",
  710. "opacity": 0.6
  711. }
  712. });
  713. _self.fireEvent("beforeDelete");
  714. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("beforeDelete");
  715. _self.documentAction.removeDocument(_self.businessData.document.id, function (json) {
  716. _self.fireEvent("afterDelete");
  717. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("afterDelete");
  718. _self.app.notice(MWF.xApplication.cms.Xform.LP.documentDelete + ": “" + _self.businessData.document.title + "”", "success");
  719. _self.options.autoSave = false;
  720. _self.options.saveOnClose = false;
  721. _self.fireEvent("postDelete");
  722. _self.app.close();
  723. this.close();
  724. }.bind(this));
  725. //this.close();
  726. }, function () {
  727. this.close();
  728. });
  729. },
  730. /**
  731. * @summary 编辑文档.
  732. * @method editDocument
  733. * @memberof CMSForm
  734. * @example
  735. * this.form.getApp().appForm.editDocument();
  736. */
  737. editDocument: function () {
  738. if (this.app.inBrowser) {
  739. this.modules.each(function (module) {
  740. MWF.release(module);
  741. });
  742. //MWF.release(this);
  743. this.app.node.destroy();
  744. this.app.options.readonly = false;
  745. this.app.loadApplication();
  746. } else {
  747. var options = { "documentId": this.businessData.document.id, "readonly": false }; //this.explorer.app.options.application.allowControl};
  748. if (this.app.options.formEditId) options.formEditId = this.app.options.formEditId;
  749. this.app.desktop.openApplication(null, "cms.Document", options);
  750. this.app.close();
  751. }
  752. },
  753. //2019-11-29 移动端 开启编辑模式
  754. /**
  755. * @summary 移动端开启编辑模式.
  756. * @method editDocumentForMobile
  757. * @memberof CMSForm
  758. * @example
  759. * this.form.getApp().appForm.editDocumentForMobile();
  760. */
  761. editDocumentForMobile: function () {
  762. if (this.app.mobile) {
  763. this.app.options.readonly = false;
  764. this.app.loadDocument(this.app.options);
  765. }
  766. },
  767. /**
  768. * @summary 弹出设置热点的界面.
  769. * @method setPopularDocument
  770. * @memberof CMSForm
  771. * @example
  772. * this.form.getApp().appForm.setPopularDocument();
  773. */
  774. setPopularDocument: function () {
  775. this.app.setPopularDocument();
  776. },
  777. printWork: function (app, form) {
  778. var application = app || this.businessData.work.application;
  779. var form = form;
  780. if (!form) {
  781. form = this.json.id;
  782. if (this.json.printForm) form = this.json.printForm;
  783. }
  784. window.open(o2.filterUrl("../x_desktop/printWork.html?workid=" + this.businessData.work.id + "&app=" + this.businessData.work.application + "&form=" + form));
  785. },
  786. openWindow: function (form, app) {
  787. var form = form;
  788. if (!form) {
  789. form = this.json.id;
  790. }
  791. if (this.businessData.document) {
  792. //var application = app;
  793. //window.open("../x_desktop/printWork.html?workCompletedId="+this.businessData.workCompleted.id+"&app="+application+"&form="+form);
  794. }
  795. },
  796. /**
  797. * @summary 将新上传的附件在指定的附件组件中展现.
  798. * @method uploadedAttachment
  799. * @memberof CMSForm
  800. * @param {String} site - 附件组件的标识
  801. * @param {String} id - 新上传的附件id
  802. * @example
  803. * this.form.getApp().appForm.uploadedAttachment(site, id);
  804. */
  805. uploadedAttachment: function (site, id) {
  806. this.documentAction.getAttachment(id, this.businessData.document.id, function (json) {
  807. var att = this.all[site];
  808. if (att) {
  809. if (json.data) att.attachmentController.addAttachment(json.data);
  810. att.attachmentController.checkActions();
  811. att.fireEvent("upload", [json.data]);
  812. }
  813. }.bind(this));
  814. },
  815. replacedAttachment: function (site, id) {
  816. this.documentAction.getAttachment(id, this.businessData.document.id, function (json) {
  817. var att = this.all[site];
  818. if (att) {
  819. var attachmentController = att.attachmentController;
  820. var attachment = null;
  821. for (var i = 0; i < attachmentController.attachments.length; i++) {
  822. if (attachmentController.attachments[i].data.id === id) {
  823. attachment = attachmentController.attachments[i];
  824. break;
  825. }
  826. }
  827. attachment.data = json.data;
  828. attachment.reload();
  829. attachmentController.checkActions();
  830. }
  831. }.bind(this))
  832. }
  833. });