Form.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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. if (this.fireEvent("queryLoad")) {
  206. MWF.xDesktop.requireApp("cms.Xform", "lp." + MWF.language, null, false);
  207. // this.container.setStyles(this.css.container);
  208. this._loadBusinessData();
  209. this.fireEvent("beforeLoad");
  210. if (this.app) if (this.app.fireEvent) this.app.fireEvent("beforeLoad");
  211. this.loadContent(callback)
  212. }
  213. },
  214. loadContent: function (callback) {
  215. this.subformCount = 0;
  216. this.subformLoadedCount = 0;
  217. this.subformLoaded = [this.json.id];
  218. this._loadHtml();
  219. this._loadForm();
  220. this.fireEvent("beforeModulesLoad");
  221. this._loadModules(this.node);
  222. if (!this.options.readonly) {
  223. if (this.options.autoSave) this.autoSave();
  224. this.app.addEvent("queryClose", function () {
  225. if (this.options.saveOnClose && this.businessData.document.docStatus == "draft") this.saveDocument(null, true);
  226. //if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  227. Object.each(this.forms, function (module, id) {
  228. if (module.json.type == "Htmleditor" && module.editor) {
  229. //if(CKEDITOR.currentImageDialog)CKEDITOR.currentImageDialog.destroy();
  230. //CKEDITOR.currentImageDialog = null;
  231. CKEDITOR.remove(module.editor);
  232. delete module.editor
  233. }
  234. });
  235. }.bind(this));
  236. }
  237. this.fireEvent("afterModulesLoad");
  238. this.fireEvent("postLoad");
  239. this.fireEvent("afterLoad");
  240. if (this.app && this.app.fireEvent) {
  241. this.app.fireEvent("afterModulesLoad");
  242. this.app.fireEvent("postLoad");
  243. this.app.fireEvent("afterLoad");
  244. }
  245. // 告诉移动端表单加载完成
  246. if (this.app && this.app.mobile) {
  247. if (callback) callback();
  248. }
  249. },
  250. autoSave: function () {
  251. //this.autoSaveTimerID = window.setInterval(function(){
  252. // this.saveDocument();
  253. //}.bind(this), 300000);
  254. },
  255. _loadBusinessData: function () {
  256. if (!this.businessData) {
  257. this.businessData = {
  258. "data": {}
  259. };
  260. }
  261. },
  262. _loadEvents: function () {
  263. Object.each(this.json.events, function (e, key) {
  264. if (e.code) {
  265. if (this.options.moduleEvents.indexOf(key) != -1) {
  266. this.addEvent(key, function (event) {
  267. return this.Macro.fire(e.code, this, event);
  268. }.bind(this));
  269. } else {
  270. if (key == "load") {
  271. this.addEvent("postLoad", function () {
  272. return this.Macro.fire(e.code, this);
  273. }.bind(this));
  274. } else if (key == "submit") {
  275. this.addEvent("beforePublish", function () {
  276. return this.Macro.fire(e.code, this);
  277. }.bind(this));
  278. } else {
  279. this.node.addEvent(key, function (event) {
  280. return this.Macro.fire(e.code, this, event);
  281. }.bind(this));
  282. }
  283. }
  284. }
  285. }.bind(this));
  286. },
  287. _loadModules: function (dom) {
  288. //var subDom = this.node.getFirst();
  289. //while (subDom){
  290. // if (subDom.get("MWFtype")){
  291. // var json = this._getDomjson(subDom);
  292. // var module = this._loadModule(json, subDom);
  293. // this.modules.push(module);
  294. // }
  295. // subDom = subDom.getNext();
  296. //}
  297. var moduleNodes = this._getModuleNodes(dom);
  298. moduleNodes.each(function (node) {
  299. var json = this._getDomjson(node);
  300. if (!this.options.showAttachment && json.type == "Attachment") {
  301. return;
  302. }
  303. //移动端去掉操作栏
  304. if (this.app.mobile && json.type === "Actionbar") {
  305. return;
  306. }
  307. var module = this._loadModule(json, node);
  308. this.modules.push(module);
  309. }.bind(this));
  310. },
  311. _loadModule: function (json, node, beforeLoad) {
  312. if (!json) return;
  313. if (!MWF["CMS" + json.type]) {
  314. MWF.xDesktop.requireApp("cms.Xform", json.type, null, false);
  315. }
  316. var module = new MWF["CMS" + json.type](node, json, this);
  317. if (beforeLoad) beforeLoad.apply(module);
  318. if (!this.all[json.id]) this.all[json.id] = module;
  319. if (module.field) {
  320. if (!this.forms[json.id]) this.forms[json.id] = module;
  321. }
  322. module.readonly = this.options.readonly;
  323. module.load();
  324. return module;
  325. },
  326. //getData: function(){
  327. // var data= Object.clone(this.businessData.data);
  328. // Object.each(this.forms, function(module, id){
  329. // debugger;
  330. // if (module.json.section=="yes"){
  331. // data[id] = this.getSectionData(module, data[id]);
  332. // }else{
  333. // data[id] = module.getData();
  334. // }
  335. // }.bind(this));
  336. //
  337. // this.businessData.data = data;
  338. // this.Macro.environment.setData(this.businessData.data);
  339. // return data;
  340. //},
  341. trim: function (array) {
  342. var arr = [];
  343. array.each(function (v) {
  344. if (v) arr.push(v);
  345. });
  346. return arr;
  347. },
  348. transportPermissionData: function (array, t) {
  349. var result = [];
  350. array.each(function (data) {
  351. var dn = typeOf(data) === "string" ? data : data.distinguishedName;
  352. if (dn) {
  353. var flag = dn.substr(dn.length - 1, 1);
  354. var type;
  355. switch (flag.toLowerCase()) {
  356. case "i":
  357. type = "人员"; //"身份";
  358. break;
  359. case "p":
  360. type = "人员";
  361. break;
  362. case "u":
  363. type = "组织";
  364. break;
  365. case "g":
  366. type = "群组";
  367. break;
  368. case "r":
  369. type = "角色";
  370. break;
  371. default:
  372. type = "";
  373. //result.push( data );
  374. }
  375. if (type) {
  376. var name;
  377. if( typeOf(data) === "object" && data.name ){
  378. name = data.name;
  379. }else if( MWF.name && MWF.name.cn ){
  380. name = MWF.name.cn( dn );
  381. }else{
  382. name = dn.split("@")[0];
  383. }
  384. result.push({
  385. permission: t == "author" ? "作者" : "阅读",
  386. permissionObjectType: type,
  387. permissionObjectName: name,
  388. permissionObjectCode: dn
  389. })
  390. }
  391. }
  392. });
  393. return result.length > 0 ? result : null;
  394. },
  395. getSpecialData: function () {
  396. var data = this.businessData.data;
  397. var readers = [];
  398. var authors = [];
  399. var pictures = [];
  400. var cloudPictures = [];
  401. var summary = "";
  402. Object.each(this.forms, function (module, id) {
  403. if (module.json.type == "Readerfield" || module.json.type == "Reader") {
  404. if (module.json.section == "yes") {
  405. readers = readers.concat(this.getSectionData(module, data[id]));
  406. } else {
  407. readers = readers.concat(module.getData());
  408. }
  409. }
  410. if (module.json.type == "Authorfield" || module.json.type == "Author") {
  411. if (module.json.section == "yes") {
  412. authors = authors.concat(this.getSectionData(module, data[id]));
  413. } else {
  414. authors = authors.concat(module.getData());
  415. }
  416. }
  417. if (module.json.type == "ImageClipper") {
  418. var d = module.getData();
  419. if (d) pictures.push(d);
  420. }
  421. if (module.json.type == "Htmleditor") {
  422. var text = module.getText();
  423. summary = text.substr(0, 80);
  424. cloudPictures = cloudPictures.concat(module.getImageIds());
  425. }
  426. });
  427. if (data.processOwnerList && typeOf(data.processOwnerList) == "array") { //如果是流程中发布的
  428. var owner = { personValue: [] };
  429. data.processOwnerList.each(function (p) {
  430. owner.personValue.push({
  431. name: p,
  432. type: "person"
  433. });
  434. });
  435. readers = readers.concat(owner);
  436. }
  437. return {
  438. readers: this.transportPermissionData(readers, "reader"),
  439. authors: this.transportPermissionData(authors, "author"),
  440. pictures: pictures,
  441. summary: summary,
  442. cloudPictures: cloudPictures
  443. };
  444. },
  445. getDocumentData: function (formData) {
  446. var data = Object.clone(this.businessData.document);
  447. if (formData.subject) {
  448. data.title = formData.subject;
  449. data.subject = formData.subject;
  450. this.businessData.document.title = formData.subject;
  451. this.businessData.document.subject = formData.subject;
  452. }
  453. data.isNewDocument = false;
  454. return data;
  455. },
  456. saveDocument: function (callback, sync) {
  457. this.fireEvent("beforeSave");
  458. if (this.businessData.document.docStatus == "published") {
  459. if (!this.formValidation("publish")) {
  460. this.app.content.unmask();
  461. //if (callback) callback();
  462. return false;
  463. }
  464. }
  465. if (!this.formSaveValidation()) {
  466. this.app.content.unmask();
  467. if (callback) callback();
  468. return false;
  469. }
  470. var data = this.getData();
  471. var specialData = this.getSpecialData();
  472. var documentData = this.getDocumentData(data);
  473. documentData.readerList = specialData.readers;
  474. documentData.authorList = specialData.authors;
  475. documentData.pictureList = specialData.pictures;
  476. documentData.summary = specialData.summary;
  477. documentData.cloudPictures = specialData.cloudPictures;
  478. documentData.docData = data;
  479. delete documentData.attachmentList;
  480. this.fireEvent("postSave", [documentData]);
  481. if (this.officeList) {
  482. this.officeList.each(function (module) {
  483. module.save();
  484. });
  485. }
  486. this.documentAction.saveDocument(documentData, function () {
  487. //this.documentAction.saveData(function(json){
  488. this.app.notice(MWF.xApplication.cms.Xform.LP.dataSaved, "success");
  489. this.businessData.data.isNew = false;
  490. this.fireEvent("afterSave");
  491. if (callback) callback();
  492. //}.bind(this), null, this.businessData.document.id, data, !sync );
  493. }.bind(this), null, !sync);
  494. },
  495. closeDocument: function () {
  496. this.fireEvent("beforeClose");
  497. if (this.app) {
  498. this.app.close();
  499. }
  500. },
  501. printDocument: function (form) {
  502. var form = form;
  503. if (!form) {
  504. form = this.json.id;
  505. if (this.json.printForm && this.json.printForm !== "none") form = this.json.printForm;
  506. }
  507. window.open(o2.filterUrl("../x_desktop/printcmsdoc.html?documentid=" + this.businessData.document.id + "&form=" + form));
  508. },
  509. formValidation: function (status) {
  510. if (this.options.readonly) return true;
  511. var flag = true;
  512. //flag = this.validation();
  513. Object.each(this.forms, function (field, key) {
  514. field.validationMode();
  515. if (!field.validation(status)) {
  516. flag = false;
  517. }
  518. }.bind(this));
  519. return flag;
  520. },
  521. formSaveValidation: function () {
  522. if (!this.json.validationSave) return true;
  523. if (!this.json.validationSave.code) return true;
  524. var flag = this.Macro.exec(this.json.validationSave.code, this);
  525. if (!flag) flag = MWF.xApplication.cms.Xform.LP.notValidation;
  526. if (typeOf(flag) === "string") {
  527. if (flag !== "true") {
  528. this.app.notice(flag, "error");
  529. return false;
  530. }
  531. } else if (flag.toString() != "true") {
  532. return false;
  533. }
  534. return true;
  535. },
  536. formPublishValidation: function () {
  537. if (!this.json.validationPublish) return true;
  538. if (!this.json.validationPublish.code) return true;
  539. var flag = this.Macro.exec(this.json.validationPublish.code, this);
  540. if (!flag) flag = MWF.xApplication.cms.Xform.LP.notValidation;
  541. if (typeOf(flag) === "string") {
  542. if (flag !== "true") {
  543. this.app.notice(flag, "error");
  544. return false;
  545. }
  546. } else if (flag.toString() != "true") {
  547. return false;
  548. }
  549. return true;
  550. },
  551. publishDocument: function (callback) {
  552. this.fireEvent("beforePublish");
  553. this.app.content.mask({
  554. "destroyOnHide": true,
  555. "style": this.app.css.maskNode
  556. });
  557. if (!this.formValidation("publish")) {
  558. this.app.content.unmask();
  559. //if (callback) callback();
  560. return false;
  561. }
  562. if (!this.formPublishValidation()) {
  563. this.app.content.unmask();
  564. if (callback) callback();
  565. return false;
  566. }
  567. var data = this.getData();
  568. var specialData = this.getSpecialData();
  569. //this.documentAction.saveData(function(json){
  570. var documentData = this.getDocumentData(data);
  571. documentData.readerList = specialData.readers;
  572. documentData.authorList = specialData.authors;
  573. documentData.pictureList = specialData.pictures;
  574. documentData.summary = specialData.summary;
  575. documentData.cloudPictures = specialData.cloudPictures;
  576. documentData.docData = data;
  577. delete documentData.attachmentList;
  578. //this.documentAction.saveDocument(documentData, function(){
  579. this.fireEvent("postPublish", [documentData]);
  580. if (this.app) if (this.app.fireEvent) this.app.fireEvent("postPublish",[documentData]);
  581. if (this.officeList) {
  582. this.officeList.each(function (module) {
  583. module.save();
  584. });
  585. }
  586. this.documentAction.publishDocumentComplex(documentData, function (json) {
  587. this.businessData.data.isNew = false;
  588. this.fireEvent("afterPublish", [this, json.data]);
  589. if (this.app) if (this.app.fireEvent) this.app.fireEvent("afterPublish",[this, json.data]);
  590. if (callback) callback();
  591. if (this.app.mobile) {
  592. this.app.content.unmask();
  593. console.log('这里是移动端');
  594. } else {
  595. if (this.businessData.document.title) {
  596. this.app.notice(MWF.xApplication.cms.Xform.LP.documentPublished + ": “" + this.businessData.document.title + "”", "success");
  597. } else {
  598. this.app.notice(MWF.xApplication.cms.Xform.LP.documentPublished, "success");
  599. }
  600. this.options.saveOnClose = false;
  601. }
  602. debugger;
  603. if( layout.inBrowser ){
  604. try{
  605. if( window.opener && window.opener.o2RefreshCMSView ){
  606. window.opener.o2RefreshCMSView();
  607. }
  608. }catch (e) {}
  609. window.setTimeout(function () {
  610. this.app.close();
  611. }.bind(this), 1500)
  612. }else{
  613. this.app.close();
  614. }
  615. }.bind(this));
  616. //}.bind(this))
  617. //}.bind(this), null, this.businessData.document.id, data);
  618. },
  619. //publishDocument_bak: function(callback){
  620. // this.fireEvent("beforePublish");
  621. // this.app.content.mask({
  622. // "destroyOnHide": true,
  623. // "style": this.app.css.maskNode
  624. // });
  625. // if (!this.formValidation("publish")){
  626. // this.app.content.unmask();
  627. // if (callback) callback();
  628. // return false;
  629. // }
  630. //
  631. // var data = this.getData();
  632. // var specialData = this.getSpecialData();
  633. // this.documentAction.saveData(function(json){
  634. // this.businessData.data.isNew = false;
  635. // var documentData = this.getDocumentData(data);
  636. // documentData.permissionList = specialData.readers;
  637. // documentData.pictureList = specialData.pictures;
  638. // documentData.summary = specialData.summary;
  639. // delete documentData.attachmentList;
  640. // this.documentAction.saveDocument(documentData, function(){
  641. // this.documentAction.publishDocument(documentData, function(json){
  642. // this.fireEvent("afterPublish");
  643. // this.fireEvent("postPublish");
  644. // if (callback) callback();
  645. // this.app.notice(MWF.xApplication.cms.Xform.LP.documentPublished+": “"+this.businessData.document.title+"”", "success");
  646. // this.options.saveOnClose = false;
  647. // this.app.close();
  648. // //this.close();
  649. // }.bind(this) );
  650. // }.bind(this))
  651. // }.bind(this), null, this.businessData.document.id, data);
  652. //},
  653. deleteDocumentForMobile: function () {
  654. if (this.app.mobile) {
  655. this.app.content.mask({
  656. "style": {
  657. "background-color": "#999",
  658. "opacity": 0.6
  659. }
  660. });
  661. this.fireEvent("beforeDelete");
  662. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeDelete");
  663. this.documentAction.removeDocument(this.businessData.document.id, function (json) {
  664. this.fireEvent("afterDelete");
  665. if (this.app && this.app.fireEvent) this.app.fireEvent("afterDelete");
  666. this.app.notice(MWF.xApplication.cms.Xform.LP.documentDelete + ": “" + this.businessData.document.title + "”", "success");
  667. this.options.autoSave = false;
  668. this.options.saveOnClose = false;
  669. this.fireEvent("postDelete");
  670. this.app.close();
  671. }.bind(this));
  672. }
  673. },
  674. /**
  675. * @summary 弹出删除文档确认框.
  676. * @method deleteDocument
  677. * @memberof CMSForm
  678. * @example
  679. * this.form.getApp().appForm.deleteDocument();
  680. */
  681. deleteDocument: function () {
  682. var _self = this;
  683. var p = MWF.getCenterPosition(this.app.content, 380, 150);
  684. var event = {
  685. "event": {
  686. "x": p.x,
  687. "y": p.y - 200,
  688. "clientX": p.x,
  689. "clientY": p.y - 200
  690. }
  691. };
  692. this.app.confirm("infor", event, MWF.xApplication.cms.Xform.LP.deleteDocumentTitle, MWF.xApplication.cms.Xform.LP.deleteDocumentText, 380, 120, function () {
  693. _self.app.content.mask({
  694. "style": {
  695. "background-color": "#999",
  696. "opacity": 0.6
  697. }
  698. });
  699. _self.fireEvent("beforeDelete");
  700. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("beforeDelete");
  701. _self.documentAction.removeDocument(_self.businessData.document.id, function (json) {
  702. _self.fireEvent("afterDelete");
  703. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("afterDelete");
  704. _self.app.notice(MWF.xApplication.cms.Xform.LP.documentDelete + ": “" + _self.businessData.document.title + "”", "success");
  705. _self.options.autoSave = false;
  706. _self.options.saveOnClose = false;
  707. _self.fireEvent("postDelete");
  708. _self.app.close();
  709. this.close();
  710. }.bind(this));
  711. //this.close();
  712. }, function () {
  713. this.close();
  714. });
  715. },
  716. /**
  717. * @summary 编辑文档.
  718. * @method editDocument
  719. * @memberof CMSForm
  720. * @example
  721. * this.form.getApp().appForm.editDocument();
  722. */
  723. editDocument: function () {
  724. if (this.app.inBrowser) {
  725. this.modules.each(function (module) {
  726. MWF.release(module);
  727. });
  728. //MWF.release(this);
  729. this.app.node.destroy();
  730. this.app.options.readonly = false;
  731. this.app.loadApplication();
  732. } else {
  733. var options = { "documentId": this.businessData.document.id, "readonly": false }; //this.explorer.app.options.application.allowControl};
  734. if (this.app.options.formEditId) options.formEditId = this.app.options.formEditId;
  735. this.app.desktop.openApplication(null, "cms.Document", options);
  736. this.app.close();
  737. }
  738. },
  739. //2019-11-29 移动端 开启编辑模式
  740. /**
  741. * @summary 移动端开启编辑模式.
  742. * @method editDocumentForMobile
  743. * @memberof CMSForm
  744. * @example
  745. * this.form.getApp().appForm.editDocumentForMobile();
  746. */
  747. editDocumentForMobile: function () {
  748. if (this.app.mobile) {
  749. this.app.options.readonly = false;
  750. this.app.loadDocument(this.app.options);
  751. }
  752. },
  753. /**
  754. * @summary 弹出设置热点的界面.
  755. * @method setPopularDocument
  756. * @memberof CMSForm
  757. * @example
  758. * this.form.getApp().appForm.setPopularDocument();
  759. */
  760. setPopularDocument: function () {
  761. this.app.setPopularDocument();
  762. },
  763. printWork: function (app, form) {
  764. var application = app || this.businessData.work.application;
  765. var form = form;
  766. if (!form) {
  767. form = this.json.id;
  768. if (this.json.printForm) form = this.json.printForm;
  769. }
  770. window.open(o2.filterUrl("../x_desktop/printWork.html?workid=" + this.businessData.work.id + "&app=" + this.businessData.work.application + "&form=" + form));
  771. },
  772. openWindow: function (form, app) {
  773. var form = form;
  774. if (!form) {
  775. form = this.json.id;
  776. }
  777. if (this.businessData.document) {
  778. //var application = app;
  779. //window.open("../x_desktop/printWork.html?workCompletedId="+this.businessData.workCompleted.id+"&app="+application+"&form="+form);
  780. }
  781. },
  782. /**
  783. * @summary 将新上传的附件在指定的附件组件中展现.
  784. * @method uploadedAttachment
  785. * @memberof CMSForm
  786. * @param {String} site - 附件组件的标识
  787. * @param {String} id - 新上传的附件id
  788. * @example
  789. * this.form.getApp().appForm.uploadedAttachment(site, id);
  790. */
  791. uploadedAttachment: function (site, id) {
  792. this.documentAction.getAttachment(id, this.businessData.document.id, function (json) {
  793. var att = this.all[site];
  794. if (att) {
  795. if (json.data) att.attachmentController.addAttachment(json.data);
  796. att.attachmentController.checkActions();
  797. att.fireEvent("upload", [json.data]);
  798. }
  799. }.bind(this));
  800. },
  801. replacedAttachment: function (site, id) {
  802. this.documentAction.getAttachment(id, this.businessData.document.id, function (json) {
  803. var att = this.all[site];
  804. if (att) {
  805. var attachmentController = att.attachmentController;
  806. var attachment = null;
  807. for (var i = 0; i < attachmentController.attachments.length; i++) {
  808. if (attachmentController.attachments[i].data.id === id) {
  809. attachment = attachmentController.attachments[i];
  810. break;
  811. }
  812. }
  813. attachment.data = json.data;
  814. attachment.reload();
  815. attachmentController.checkActions();
  816. }
  817. }.bind(this))
  818. }
  819. });