Form.js 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737
  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. * @o2cn 内容管理表单
  11. * @o2category FormComponents
  12. * @o2range {CMS}
  13. * @alias CMSForm
  14. * @example
  15. * //可以在脚本中获取表单
  16. * //方法1:
  17. * var form = this.form.getApp().appForm; //获取表单
  18. * //方法2
  19. * var form = this.target; //在表单本身的事件脚本中获取
  20. * @hideconstructor
  21. */
  22. MWF.xApplication.cms.Xform.Form = MWF.CMSForm = new Class(
  23. /** @lends CMSForm# */
  24. {
  25. Implements: [Options, Events],
  26. Extends: MWF.APPForm,
  27. options: {
  28. "style": "default",
  29. "readonly": false,
  30. "cssPath": "",
  31. "autoSave": false,
  32. "saveOnClose": false,
  33. "showAttachment": true,
  34. "moduleEvents": [
  35. /**
  36. * 表单加载前触发。表单html已经就位。
  37. * @event CMSForm#queryLoad
  38. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  39. */
  40. "queryLoad",
  41. /**
  42. * 表单加载前触发。数据(businessData)已经就绪。
  43. * @event CMSForm#beforeLoad
  44. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  45. */
  46. "beforeLoad",
  47. /**
  48. * 表单的所有组件加载前触发,此时表单的样式和js head已经加载。
  49. * @event CMSForm#beforeModulesLoad
  50. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  51. */
  52. "beforeModulesLoad",
  53. /**
  54. * 表单加载后触发。
  55. * @event CMSForm#postLoad
  56. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  57. */
  58. "postLoad",
  59. /**
  60. * 表单的所有组件加载后触发。
  61. * @event CMSForm#afterModulesLoad
  62. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  63. */
  64. "afterModulesLoad",
  65. /**
  66. * 表单加载后触发。
  67. * @event CMSForm#afterLoad
  68. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  69. */
  70. "afterLoad",
  71. /**
  72. * 保存前触发。
  73. * @event CMSForm#beforeSave
  74. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  75. */
  76. "beforeSave",
  77. /**
  78. * 数据已经整理完成,但还未保存到后台时触发。this.event指向整理完成的数据
  79. * @event CMSForm#postSave
  80. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  81. */
  82. "postSave",
  83. /**
  84. * 数据保存到后台后触发。
  85. * @event CMSForm#afterSave
  86. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  87. */
  88. "afterSave",
  89. /**
  90. * 关闭前触发。
  91. * @event CMSForm#beforeClose
  92. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  93. */
  94. "beforeClose",
  95. /**
  96. * 发布前触发。
  97. * @event CMSForm#beforePublish
  98. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  99. */
  100. "beforePublish",
  101. /**
  102. * 数据已经整理完成,但还未调用服务发布触发。this.event指向整理完成的数据
  103. * @event CMSForm#postPublish
  104. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  105. */
  106. "postPublish",
  107. /**
  108. * 执行后台服务发布后触发。
  109. * @event CMSForm#afterPublish
  110. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  111. */
  112. "afterPublish",
  113. /**
  114. * 定时发布前触发。
  115. * @event CMSForm#beforeWaitPublish
  116. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  117. */
  118. "beforeWaitPublish",
  119. /**
  120. * 数据已经整理完成,但还未调用定时发布服务前触发。this.event指向整理完成的数据
  121. * @event CMSForm#postWaitPublish
  122. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  123. */
  124. "postWaitPublish",
  125. /**
  126. * 执行后台定时发布服务后触发。
  127. * @event CMSForm#afterPublish
  128. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  129. */
  130. "afterWaitPublish",
  131. /**
  132. * 删除前触发。
  133. * @event CMSForm#beforeDelete
  134. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  135. */
  136. "beforeDelete",
  137. /**
  138. * 删除后触发。
  139. * @event CMSForm#afterDelete
  140. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  141. */
  142. "afterDelete",
  143. "resize"
  144. ]
  145. },
  146. /**
  147. * @summary 获取表单的所有数据.
  148. * @method getData
  149. * @memberof CMSForm
  150. * @example
  151. * var data = this.form.getApp().appForm.getData();
  152. * @return {Object}
  153. */
  154. initialize: function (node, data, options) {
  155. this.setOptions(options);
  156. /**
  157. * @summary 表单容器
  158. * @see https://mootools.net/core/docs/1.6.0/Element/Element
  159. * @member {Element}
  160. * @example
  161. * //可以在脚本中获取表单容器
  162. * var formContainer = this.form.getApp().appForm.container;
  163. */
  164. this.container = $(node);
  165. this.container.setStyle("-webkit-user-select", "text");
  166. this.data = data;
  167. /**
  168. * @summary 表单的配置信息,比如表单名称等等.
  169. * @member {Object}
  170. * @example
  171. * //可以在脚本中获取表单配置信息
  172. * var json = this.form.getApp().appForm.json; //表单配置信息
  173. * var name = json.name; //表单名称
  174. */
  175. this.json = data.json;
  176. this.html = data.html;
  177. this.path = "../x_component_cms_Xform/$Form/";
  178. this.cssPath = this.options.cssPath || "../x_component_cms_Xform/$Form/" + this.options.style + "/css.wcss";
  179. this._loadCss();
  180. /**
  181. * @summary 表单中的所有组件数组.
  182. * @member {Array}
  183. * @example
  184. * //下面的样例对表单组件进行循环,并且判断是输入类型的组件
  185. * var modules = this.form.getApp().appForm.modules; //获取所有表单组件
  186. * for( var i=0; i<modules.length; i++ ){ //循环处理组件
  187. * //获取组件的类型
  188. var moduleName = module.json.moduleName;
  189. if( !moduleName ){
  190. moduleName = typeOf(module.json.type) === "string" ? module.json.type.toLowerCase() : "";
  191. }
  192. if( ["calendar","combox","number","textfield"].contains( moduleName )){ //输入类型框
  193. //do something
  194. }
  195. * }
  196. */
  197. this.modules = [];
  198. /**
  199. * 该对象的key是组件标识,value是组件对象,可以使用该对象根据组件标识获取组件。<br/>
  200. * 需要注意的是,在子表单中嵌入不绑定数据的组件(比如div,common,button等等),系统允许重名。<br/>
  201. * 在打开表单的时候,系统会根据重名情况,自动在组件的标识后跟上 "_1", "_2"。
  202. * @summary 表单中的所有组件对象.
  203. * @member {Object}
  204. * @example
  205. * var moduleAll = this.form.getApp().appForm.all; //获取组件对象
  206. * var subjectField = moduleAll["subject"] //获取名称为subject的组件
  207. */
  208. this.all = {};
  209. this.forms = {};
  210. //if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  211. },
  212. load: function (callback) {
  213. if (this.app) {
  214. if (this.app.formNode) this.app.formNode.setStyles(this.json.styles);
  215. if (this.app.addEvent) this.app.addEvent("resize", function () {
  216. this.fireEvent("resize");
  217. }.bind(this))
  218. }
  219. //if (!this.businessData.control.allowSave) this.setOptions({"readonly": true});
  220. this.Macro = new MWF.CMSMacro.CMSFormContext(this);
  221. this.loadLanguage(function(flag) {
  222. this.isParseLanguage = flag;
  223. if (flag && this.formDataText) {
  224. var data = o2.bindJson(this.formDataText, {"lp": MWF.xApplication.cms.Xform.LP.form});
  225. this.data = JSON.parse(data);
  226. this.json = this.data.json;
  227. this.html = this.data.html;
  228. }
  229. var cssClass = "";
  230. if (this.json.css && this.json.css.code) cssClass = this.loadCss();
  231. this.container.set("html", this.html);
  232. this.node = this.container.getFirst();
  233. if (cssClass) this.node.addClass(cssClass);
  234. this._loadEvents();
  235. this.loadRelatedScript();
  236. if (this.fireEvent("queryLoad")) {
  237. // MWF.xDesktop.requireApp("cms.Xform", "lp." + MWF.language, null, false);
  238. // this.container.setStyles(this.css.container);
  239. this._loadBusinessData();
  240. this.fireEvent("beforeLoad");
  241. if (this.app) if (this.app.fireEvent) this.app.fireEvent("beforeLoad");
  242. this.loadContent(callback)
  243. }
  244. }.bind(this));
  245. },
  246. loadLanguage: function(callback){
  247. MWF.xDesktop.requireApp("cms.Xform", "lp." + MWF.language, null, false);
  248. //formDataText
  249. if (this.json.languageType!=="script" && this.json.languageType!=="default"){
  250. if (callback) callback();
  251. return true;
  252. }
  253. var language = MWF.xApplication.cms.Xform.LP.form;
  254. var languageJson = null;
  255. if (this.json.languageType=="script"){
  256. if (this.json.languageScript && this.json.languageScript.code){
  257. languageJson = this.Macro.exec(this.json.languageScript.code, this);
  258. }
  259. }else if (this.json.languageType=="default") {
  260. var name = "lp-"+o2.language;
  261. var application = this.businessData.document.appId;
  262. var p1 = this.documentAction.getDictRoot(name, application, function(d){
  263. return d.data;
  264. }, function(){});
  265. var p2 = this.documentAction.getScriptByNameV2(name, application, function(d){
  266. return this.Macro.exec(d.data.text, this);
  267. }.bind(this), function(){});
  268. languageJson = Promise.any([p1, p2]);
  269. }
  270. if (languageJson){
  271. if (languageJson.then && o2.typeOf(languageJson.then)=="function"){
  272. languageJson.then(function(json) {
  273. MWF.xApplication.cms.Xform.LP.form = Object.merge(MWF.xApplication.cms.Xform.LP.form, json);
  274. if (callback) callback(true);
  275. }, function(){
  276. if (callback) callback(true);
  277. })
  278. }else{
  279. MWF.xApplication.cms.Xform.LP.form = Object.merge(MWF.xApplication.cms.Xform.LP.form, languageJson);
  280. if (callback) callback(true);
  281. }
  282. }else{
  283. if (callback) callback(true);
  284. }
  285. },
  286. loadRelatedScript: function () {
  287. if (this.json.includeScripts && this.json.includeScripts.length) {
  288. var includeScriptText = "";
  289. var includedIds = [];
  290. this.json.includeScripts.each(function (s) {
  291. if (this.app.relatedScriptMap && this.app.relatedScriptMap[s.id]) {
  292. includeScriptText += "\n" + this.app.relatedScriptMap[s.id].text;
  293. includedIds.push(s.id);
  294. }
  295. }.bind(this));
  296. if (includeScriptText) this.Macro.exec(includeScriptText, this);
  297. }
  298. },
  299. loadContent: function (callback) {
  300. this.subformCount = 0;
  301. this.subformLoadedCount = 0;
  302. this.subformLoaded = [this.json.id];
  303. this._loadHtml();
  304. this._loadForm();
  305. this.fireEvent("beforeModulesLoad");
  306. this._loadModules(this.node);
  307. if (!this.options.readonly) {
  308. if (this.options.autoSave) this.autoSave();
  309. this.app.addEvent("queryClose", function () {
  310. if (this.options.saveOnClose && this.businessData.document.docStatus == "draft") this.saveDocument(null, true);
  311. //if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  312. Object.each(this.forms, function (module, id) {
  313. if (module.json && module.json.type == "Htmleditor" && module.editor) {
  314. //if(CKEDITOR.currentImageDialog)CKEDITOR.currentImageDialog.destroy();
  315. //CKEDITOR.currentImageDialog = null;
  316. CKEDITOR.remove(module.editor);
  317. delete module.editor
  318. }
  319. });
  320. }.bind(this));
  321. }
  322. this.fireEvent("afterModulesLoad");
  323. this.fireEvent("postLoad");
  324. this.fireEvent("afterLoad");
  325. if (this.app && this.app.fireEvent) {
  326. this.app.fireEvent("afterModulesLoad");
  327. this.app.fireEvent("postLoad");
  328. this.app.fireEvent("afterLoad");
  329. }
  330. // 移动端表单 展现底部工具栏
  331. debugger;
  332. if (this.json.mode === "Mobile") {
  333. var node = document.body.getElement(".o2_form_mobile_actions");
  334. if (node) {
  335. node.empty();
  336. this._loadMobileActions(node, callback);
  337. } else {
  338. if (callback) callback();
  339. }
  340. }
  341. // 告诉移动端表单加载完成
  342. // if (this.app && this.app.mobile) {
  343. // if (callback) callback();
  344. // }
  345. },
  346. autoSave: function () {
  347. //this.autoSaveTimerID = window.setInterval(function(){
  348. // this.saveDocument();
  349. //}.bind(this), 300000);
  350. },
  351. // 默认的移动端底部工具栏
  352. _loadMobileDefaultTools: function (callback) {
  353. if (this.json.defaultTools) {
  354. if (callback) callback();
  355. } else {
  356. this.json.defaultTools = o2.JSON.get("../x_component_process_FormDesigner/Module/Actionbar/toolbars.json", function (json) {
  357. this.json.defaultTools = json;
  358. if (callback) callback();
  359. }.bind(this));
  360. }
  361. },
  362. // 移动端生成底部工具栏
  363. _loadMobileActions: function (node, callback) {
  364. var tools = [];
  365. this._loadMobileDefaultTools(function () {
  366. if (this.json.defaultTools) {
  367. var jsonStr = JSON.stringify(this.json.defaultTools);
  368. jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.cms.Xform.LP.form});
  369. this.json.defaultTools = JSON.parse(jsonStr);
  370. this.json.defaultTools.each(function (tool) {
  371. var flag = this._checkDefaultMobileActionItem(tool, this.options.readonly);
  372. if (flag) tools.push(tool);
  373. }.bind(this));
  374. }
  375. if (this.json.tools) {
  376. var jsonStr = JSON.stringify(this.json.tools);
  377. jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.cms.Xform.LP.form});
  378. this.json.tools = JSON.parse(jsonStr);
  379. this.json.tools.each(function (tool) {
  380. var flag = this._checkCustomMobileActionItem(tool, this.options.readonly);
  381. if (flag) tools.push(tool);
  382. }.bind(this));
  383. }
  384. this.mobileTools = tools;
  385. //app上用原来的按钮样式
  386. if (window.o2android) {
  387. if (tools.length) if (node) this._createMobileActions(node, tools);
  388. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.o2mLog) {
  389. if (tools.length) if (node) this._createMobileActions(node, tools);
  390. } else {
  391. //钉钉 企业微信用新的样式
  392. if (tools.length) if (node) this._createMobileActionsDingdingStyle(node, tools);
  393. }
  394. if (callback) callback();
  395. }.bind(this));
  396. },
  397. // 检查默认按钮是否显示
  398. _checkDefaultMobileActionItem: function (tool, readonly, noCondition) {
  399. var flag = true;
  400. if (tool.control) {
  401. flag = this.businessData.control[tool.control]
  402. }
  403. if (!noCondition) if (tool.condition) {
  404. var hideFlag = this.Macro.exec(tool.condition, this);
  405. flag = flag && (!hideFlag);
  406. }
  407. // if (readonly) if (!tool.read) flag = false;
  408. if (readonly){
  409. if (!tool.read) flag = false;
  410. }else{
  411. if (!tool.edit) flag = false;
  412. }
  413. // 移动端禁用 关闭和打印
  414. if (tool.id === "action_close" || tool.id === "action_print" || tool.id === "action_popular") {
  415. flag = false;
  416. }
  417. return flag;
  418. },
  419. // 检查自定义按钮是否显示
  420. _checkCustomMobileActionItem: function (tool, readonly) {
  421. var flag = true;
  422. if (readonly) {
  423. flag = tool.readShow;
  424. } else {
  425. flag = tool.editShow;
  426. }
  427. if (flag) {
  428. flag = true;
  429. if (tool.control) {
  430. flag = this.businessData.control[tool.control]
  431. }
  432. if (tool.condition) {
  433. var hideFlag = this.Macro.exec(tool.condition, this);
  434. flag = !hideFlag;
  435. }
  436. }
  437. return flag;
  438. },
  439. // 创建默认样式的底部工具栏
  440. _createMobileActions: function (node, tools) {
  441. node.show();
  442. var count = tools.length;
  443. if (count <= 2) {
  444. this.css.html5ActionButton.width = "100%";
  445. if (count == 2) this.css.html5ActionButton.width = "49%";
  446. tools.each(function (tool) {
  447. var action = new Element("div", { "styles": this.css.html5ActionButton, "text": tool.text }).inject(node);
  448. action.store("tool", tool);
  449. action.addEvent("click", function (e) {
  450. var t = e.target.retrieve("tool");
  451. e.setDisable = function () { }
  452. if (t.actionScript) {
  453. this._runCustomAction(t.actionScript);
  454. } else {
  455. if (this[t.action]) this[t.action](e);
  456. }
  457. }.bind(this));
  458. this._setMobileBottonStyle(action);
  459. }.bind(this));
  460. if (count == 2) new Element("div", { "styles": this.css.html5ActionButtonSplit }).inject(node.getLast(), "before");
  461. } else {
  462. this.css.html5ActionButton.width = "38%"
  463. for (var i = 0; i < 2; i++) {
  464. tool = tools[i];
  465. var action = new Element("div", { "styles": this.css.html5ActionButton, "text": tool.text }).inject(node);
  466. action.store("tool", tool);
  467. action.addEvent("click", function (e) {
  468. var t = e.target.retrieve("tool");
  469. e.setDisable = function () { }
  470. if (t.actionScript) {
  471. this._runCustomAction(t.actionScript);
  472. } else {
  473. if (this[t.action]) this[t.action](e);
  474. }
  475. }.bind(this));
  476. this._setMobileBottonStyle(action);
  477. }
  478. new Element("div", { "styles": this.css.html5ActionButtonSplit }).inject(node.getLast(), "before");
  479. new Element("div", { "styles": this.css.html5ActionButtonSplit }).inject(node);
  480. this.css.html5ActionButton.width = "23%"
  481. var action = new Element("div", { "styles": this.css.html5ActionButton, "text": "…" }).inject(node);
  482. action.addEvent("click", function (e) {
  483. this._loadMoreMobileActions(tools, 2, node);
  484. }.bind(this));
  485. this._setMobileBottonStyle(action);
  486. }
  487. },
  488. // 更多按钮
  489. _loadMoreMobileActions: function (tools, n, node) {
  490. document.body.mask({
  491. "id": "cms_toolbar_mask_id",
  492. "style": {
  493. "background-color": "#cccccc",
  494. "opacity": 0.6
  495. },
  496. "hideOnClick": true,
  497. "onHide": function () {
  498. if (this.actionMoreArea){
  499. this.actionMoreArea.setStyle("display", "none");
  500. }
  501. }.bind(this)
  502. });
  503. if (this.actionMoreArea) {
  504. this.actionMoreArea.setStyle("display", "block");
  505. } else {
  506. var size = document.body.getSize();
  507. this.actionMoreArea = new Element("div", { "styles": this.css.html5ActionOtherArea }).inject(document.body);
  508. var pl = this.actionMoreArea.getStyle("padding-left").toInt();
  509. var pr = this.actionMoreArea.getStyle("padding-right").toInt();
  510. var w = size.x - pl - pr;
  511. this.actionMoreArea.setStyle("width", "" + w + "px");
  512. for (var i = n; i < tools.length; i++) {
  513. tool = tools[i];
  514. var action = new Element("div", { "styles": this.css.html5ActionOtherButton, "text": tool.text }).inject(this.actionMoreArea);
  515. action.store("tool", tool);
  516. action.addEvent("click", function (e) {
  517. //隐藏更多菜单
  518. var mask = document.id("cms_toolbar_mask_id");
  519. mask.destroy();
  520. this.actionMoreArea.setStyle("display", "none");
  521. var t = e.target.retrieve("tool");
  522. e.setDisable = function () { }
  523. if (t.actionScript) {
  524. this._runCustomAction(t.actionScript);
  525. } else {
  526. if (this[t.action]) this[t.action](e);
  527. }
  528. }.bind(this));
  529. this._setMobileBottonStyle(action);
  530. }
  531. }
  532. // actionArea.position({
  533. // relativeTo: node,
  534. // position: 'topCenter',
  535. // edge: 'bottomCenter'
  536. // });
  537. },
  538. _setMobileBottonStyle: function (action) {
  539. var _self = this;
  540. action.addEvents({
  541. "mouseover": function (e) { this.setStyles(_self.css.html5ActionButton_over) },
  542. "mouseout": function (e) { this.setStyles(_self.css.html5ActionButton_up) },
  543. "mousedown": function (e) { this.setStyles(_self.css.html5ActionButton_over) },
  544. "mouseup": function (e) { this.setStyles(_self.css.html5ActionButton_up) },
  545. "touchstart": function (e) { this.setStyles(_self.css.html5ActionButton_over) },
  546. "touchcancel": function (e) { this.setStyles(_self.css.html5ActionButton_up) },
  547. "touchend": function (e) { this.setStyles(_self.css.html5ActionButton_up) },
  548. "touchmove": function (e) { this.setStyles(_self.css.html5ActionButton_over) }
  549. });
  550. },
  551. // 钉钉企业微信样式的按钮
  552. _createMobileActionsDingdingStyle: function (node, tools) {
  553. node.show();
  554. var count = tools.length;
  555. if (count <= 2) {
  556. //左边 间隔
  557. var dingdingSplitLeft = new Element("div", { "styles": this.css.html5ActionButtonDingdingSplit, "text": " " }).inject(node);
  558. var splitSize = dingdingSplitLeft.getSize();
  559. var size = document.body.getSize();
  560. var buttonWidth = (size.x - splitSize.x * (count + 1) - (count * 2)) / count;
  561. tools.each(function (tool) {
  562. var actionStyle = this.css.html5ActionButtonDingdingNormal;
  563. if (tool.id === "action_edit" || tool.id === "action_saveData" || tool.id === "action_saveDraftDocument" || tool.id === "action_publishDocument" || tool.id === "action_publishDocumentDelayed") {
  564. actionStyle = this.css.html5ActionButtonDingdingPrimary;
  565. } else if (tool.id === "action_delete") {
  566. actionStyle = this.css.html5ActionButtonDingdingDanger;
  567. }
  568. actionStyle.width = buttonWidth + "px";
  569. var action = new Element("div", { "styles": actionStyle, "text": tool.text }).inject(node);
  570. action.store("tool", tool);
  571. action.addEvent("click", function (e) {
  572. var clickFun = function () {
  573. var t = e.target.retrieve("tool");
  574. e.setDisable = function () { };
  575. if (t.actionScript) {
  576. this._runCustomAction(t.actionScript);
  577. } else {
  578. if (this[t.action]) this[t.action](e);
  579. }
  580. }.bind(this);
  581. if (tool.text === "继续流转" || tool.id === "action_processWork") {
  582. //输入法激活的时候,需要一段时间等待输入法关闭
  583. window.setTimeout(clickFun, 100)
  584. } else {
  585. clickFun();
  586. }
  587. }.bind(this));
  588. new Element("div", { "styles": this.css.html5ActionButtonDingdingSplit, "text": " " }).inject(node);
  589. }.bind(this));
  590. } else {
  591. //左边 间隔
  592. var dingdingSplitLeft = new Element("div", { "styles": this.css.html5ActionButtonDingdingSplit, "text": " " }).inject(node);
  593. var splitSize = dingdingSplitLeft.getSize();
  594. var size = document.body.getSize();
  595. var buttonWidth = (size.x - splitSize.x * 4 - 6) / 5;
  596. for (var i = 0; i < 3; i++) {
  597. tool = tools[i];
  598. var actionStyle = this.css.html5ActionButtonDingdingNormal;
  599. if (tool.id === "action_edit" || tool.id === "action_saveData" || tool.id === "action_saveDraftDocument" || tool.id === "action_publishDocument" || tool.id === "action_publishDocumentDelayed") {
  600. actionStyle = this.css.html5ActionButtonDingdingPrimary;
  601. } else if (tool.id === "action_delete") {
  602. actionStyle = this.css.html5ActionButtonDingdingDanger;
  603. }
  604. if (i == 2) {
  605. this.css.html5ActionButtonDingdingMore.width = buttonWidth + "px";
  606. var action = new Element("div", { "styles": this.css.html5ActionButtonDingdingMore, "text": "…" }).inject(node);
  607. action.addEvent("click", function (e) {
  608. this._loadMoreMobileActionsDingdingStyle(tools, 2, node);
  609. }.bind(this));
  610. } else {
  611. actionStyle.width = (buttonWidth * 2) + "px";
  612. var action = new Element("div", { "styles": actionStyle, "text": tool.text }).inject(node);
  613. action.store("tool", tool);
  614. action.addEvent("click", function (e) {
  615. var t = e.target.retrieve("tool");
  616. e.setDisable = function () { }
  617. if (t.actionScript) {
  618. this._runCustomAction(t.actionScript);
  619. } else {
  620. if (this[t.action]) this[t.action](e);
  621. }
  622. }.bind(this));
  623. }
  624. new Element("div", { "styles": this.css.html5ActionButtonDingdingSplit, "text": " " }).inject(node);
  625. }
  626. }
  627. },
  628. //
  629. _loadMoreMobileActionsDingdingStyle: function (tools, n, node) {
  630. document.body.mask({
  631. "id": "cms_toolbar_mask_id",
  632. "style": {
  633. "background-color": "#cccccc",
  634. "opacity": 0.6
  635. },
  636. "hideOnClick": true,
  637. "onHide": function () {
  638. if (this.actionMoreArea){
  639. this.actionMoreArea.setStyle("display", "none");
  640. }
  641. }.bind(this)
  642. });
  643. if (this.actionMoreArea) {
  644. this.actionMoreArea.setStyle("display", "block");
  645. } else {
  646. var size = document.body.getSize();
  647. this.actionMoreArea = new Element("div", { "styles": this.css.html5ActionOtherArea }).inject(document.body);
  648. var pl = this.actionMoreArea.getStyle("padding-left").toInt();
  649. var pr = this.actionMoreArea.getStyle("padding-right").toInt();
  650. var w = size.x - pl - pr;
  651. this.actionMoreArea.setStyle("width", "" + w + "px");
  652. for (var i = n; i < tools.length; i++) {
  653. tool = tools[i];
  654. var actionStyle = this.css.html5ActionButtonDingdingNormal;
  655. if (tool.id === "action_edit" || tool.id === "action_saveData" || tool.id === "action_saveDraftDocument" || tool.id === "action_publishDocument" || tool.id === "action_publishDocumentDelayed") {
  656. actionStyle = this.css.html5ActionButtonDingdingPrimary;
  657. } else if (tool.id === "action_delete") {
  658. actionStyle = this.css.html5ActionButtonDingdingDanger;
  659. }
  660. actionStyle.width = "100%";
  661. var action = new Element("div", { "styles": actionStyle, "text": tool.text }).inject(this.actionMoreArea);
  662. action.store("tool", tool);
  663. action.addEvent("click", function (e) {
  664. //隐藏更多菜单
  665. var mask = document.id("cms_toolbar_mask_id");
  666. mask.destroy();
  667. this.actionMoreArea.setStyle("display", "none");
  668. var t = e.target.retrieve("tool");
  669. e.setDisable = function () { }
  670. if (t.actionScript) {
  671. this._runCustomAction(t.actionScript);
  672. } else {
  673. if (this[t.action]) this[t.action](e);
  674. }
  675. }.bind(this));
  676. }
  677. }
  678. },
  679. _loadBusinessData: function () {
  680. if (!this.businessData) {
  681. this.businessData = {
  682. "data": {}
  683. };
  684. }
  685. },
  686. _loadEvents: function () {
  687. Object.each(this.json.events, function (e, key) {
  688. if (e.code) {
  689. if (this.options.moduleEvents.indexOf(key) != -1) {
  690. this.addEvent(key, function (event) {
  691. return this.Macro.fire(e.code, this, event);
  692. }.bind(this));
  693. } else {
  694. if (key == "load") {
  695. this.addEvent("postLoad", function () {
  696. return this.Macro.fire(e.code, this);
  697. }.bind(this));
  698. } else if (key == "submit") {
  699. this.addEvent("beforePublish", function () {
  700. return this.Macro.fire(e.code, this);
  701. }.bind(this));
  702. } else {
  703. this.node.addEvent(key, function (event) {
  704. return this.Macro.fire(e.code, this, event);
  705. }.bind(this));
  706. }
  707. }
  708. }
  709. }.bind(this));
  710. },
  711. _loadModules: function (dom, beforeLoadModule, replace, callback) {
  712. var moduleNodes = this._getModuleNodes(dom);
  713. var modules = [], jsons = [];
  714. moduleNodes.each(function (node) {
  715. var json = this._getDomjson(node);
  716. jsons.push( json );
  717. if (!this.options.showAttachment && json && json.type == "Attachment") {
  718. return;
  719. }
  720. //移动端去掉操作栏
  721. if (layout.mobile && json && json.type === "Actionbar") {
  722. return;
  723. }
  724. var module = this._loadModule(json, node, beforeLoadModule, replace);
  725. this.modules.push(module);
  726. modules.push( module );
  727. }.bind(this));
  728. if( callback )callback( moduleNodes, jsons, modules )
  729. },
  730. _loadModule: function (json, node, beforeLoad) {
  731. if (!json) return;
  732. //流程组件返回
  733. if( ( json.type === "Log" && json.logType ) || ["Monitor","ReadLog"].contains(json.type) ){
  734. node.empty();
  735. return;
  736. }else if( this.options.useProcessForm && json.type === "Actionbar" ){ //使用流程表单,组件是操作条
  737. json.type = "ProcessActionbar"
  738. }
  739. if (!MWF["CMS" + json.type]) {
  740. var moduleType = json.type;
  741. if(moduleType === "AttachmentDg")moduleType = "Attachment";
  742. MWF.xDesktop.requireApp("cms.Xform", moduleType, null, false);
  743. }
  744. var module = new MWF["CMS" + json.type](node, json, this);
  745. if (beforeLoad) beforeLoad.apply(module);
  746. if (!this.all[json.id]) this.all[json.id] = module;
  747. if (module.field) {
  748. if (!this.forms[json.id]) this.forms[json.id] = module;
  749. }
  750. module.readonly = this.options.readonly;
  751. module.load();
  752. return module;
  753. },
  754. //getData: function(){
  755. // var data= Object.clone(this.businessData.data);
  756. // Object.each(this.forms, function(module, id){
  757. // debugger;
  758. // if (module.json.section=="yes"){
  759. // data[id] = this.getSectionData(module, data[id]);
  760. // }else{
  761. // data[id] = module.getData();
  762. // }
  763. // }.bind(this));
  764. //
  765. // this.businessData.data = data;
  766. // this.Macro.environment.setData(this.businessData.data);
  767. // return data;
  768. //},
  769. trim: function (array) {
  770. var arr = [];
  771. array.each(function (v) {
  772. if (v) arr.push(v);
  773. });
  774. return arr;
  775. },
  776. transportPermissionData: function (array, t) {
  777. var result = [];
  778. array.each(function (data) {
  779. var dn = typeOf(data) === "string" ? data : data.distinguishedName;
  780. if (dn) {
  781. var flag = dn.substr(dn.length - 1, 1);
  782. var type;
  783. switch (flag.toLowerCase()) {
  784. case "i":
  785. type = "人员"; //"身份";
  786. break;
  787. case "p":
  788. type = "人员";
  789. break;
  790. case "u":
  791. type = "组织";
  792. break;
  793. case "g":
  794. type = "群组";
  795. break;
  796. case "r":
  797. type = "角色";
  798. break;
  799. default:
  800. type = "";
  801. //result.push( data );
  802. }
  803. if (type) {
  804. var name;
  805. if( typeOf(data) === "object" && data.name ){
  806. name = data.name;
  807. }else if( MWF.name && MWF.name.cn ){
  808. name = MWF.name.cn( dn );
  809. }else{
  810. name = dn.split("@")[0];
  811. }
  812. result.push({
  813. permission: t == "author" ? "作者" : "阅读",
  814. permissionObjectType: type,
  815. permissionObjectName: name,
  816. permissionObjectCode: dn
  817. })
  818. }
  819. }
  820. });
  821. return result;
  822. },
  823. getSpecialData: function () {
  824. var data = this.businessData.data;
  825. var readers = [];
  826. var authors = [];
  827. var pictures = [];
  828. var cloudPictures = [];
  829. var summary = "";
  830. Object.each(this.forms, function (module, id) {
  831. if (module.json.type == "Readerfield" || module.json.type == "Reader") {
  832. if (module.json.section == "yes") {
  833. readers = readers.concat(this.getSectionData(module, data[id]));
  834. } else {
  835. readers = readers.concat(module.getData());
  836. }
  837. }
  838. if (module.json.type == "Authorfield" || module.json.type == "Author") {
  839. if (module.json.section == "yes") {
  840. authors = authors.concat(this.getSectionData(module, data[id]));
  841. } else {
  842. authors = authors.concat(module.getData());
  843. }
  844. }
  845. if (module.json.type == "ImageClipper") {
  846. var d = module.getData();
  847. if (d) pictures.push(d);
  848. }
  849. if (module.json.type == "Htmleditor") {
  850. var text = module.getText();
  851. summary = text.substr(0, 80);
  852. cloudPictures = cloudPictures.concat(module.getImageIds());
  853. }
  854. if (module.json.type == "TinyMCEEditor") {
  855. var text = module.getText();
  856. summary = text.substr(0, 80);
  857. cloudPictures = cloudPictures.concat(module.getImageIds());
  858. }
  859. });
  860. if (data.processOwnerList && typeOf(data.processOwnerList) == "array") { //如果是流程中发布的
  861. var owner = { personValue: [] };
  862. data.processOwnerList.each(function (p) {
  863. owner.personValue.push({
  864. name: p,
  865. type: "person"
  866. });
  867. });
  868. readers = readers.concat(owner);
  869. }
  870. return {
  871. readers: this.transportPermissionData(readers, "reader"),
  872. authors: this.transportPermissionData(authors, "author"),
  873. pictures: pictures,
  874. summary: summary,
  875. cloudPictures: cloudPictures
  876. };
  877. },
  878. getDocumentData: function (formData) {
  879. var data = Object.clone(this.businessData.document);
  880. if (formData.subject) {
  881. data.title = formData.subject;
  882. data.subject = formData.subject;
  883. this.businessData.document.title = formData.subject;
  884. this.businessData.document.subject = formData.subject;
  885. }
  886. data.isNewDocument = false;
  887. return data;
  888. },
  889. saveDocument: function (callback, sync) {
  890. this.fireEvent("beforeSave");
  891. if (this.businessData.document.docStatus == "published") {
  892. if (!this.formValidation("publish")) {
  893. this.app.content.unmask();
  894. //if (callback) callback();
  895. return false;
  896. }
  897. }
  898. if (!this.formSaveValidation()) {
  899. this.app.content.unmask();
  900. if (callback && typeof callback === "function") callback();
  901. return false;
  902. }
  903. var data = this.getData();
  904. var specialData = this.getSpecialData();
  905. var documentData = this.getDocumentData(data);
  906. if( documentData.docStatus === "waitPublish" ){
  907. documentData.documentNotify = this.getNoticeOptions();
  908. }
  909. documentData.readerList = specialData.readers;
  910. documentData.authorList = specialData.authors;
  911. documentData.pictureList = specialData.pictures;
  912. documentData.summary = specialData.summary;
  913. documentData.cloudPictures = specialData.cloudPictures;
  914. documentData.docData = data;
  915. delete documentData.attachmentList;
  916. this.fireEvent("postSave", [documentData]);
  917. if (this.officeList) {
  918. this.officeList.each(function (module) {
  919. module.save();
  920. });
  921. }
  922. this.documentAction.saveDocument(documentData, function () {
  923. //this.documentAction.saveData(function(json){
  924. this.app.notice(MWF.xApplication.cms.Xform.LP.dataSaved, "success");
  925. this.businessData.data.isNew = false;
  926. this.fireEvent("afterSave");
  927. if (callback && typeof callback === "function") callback();
  928. if( !this.json.notReloadWhenSave ){
  929. this._reloadReadForm();
  930. }
  931. //}.bind(this), null, this.businessData.document.id, data, !sync );
  932. }.bind(this), null, !sync);
  933. },
  934. // 重新加载阅读表单
  935. _reloadReadForm: function() {
  936. this.fireEvent("reloadReadForm");
  937. if (this.app.inBrowser) {
  938. this.modules.each(function (module) {
  939. MWF.release(module);
  940. });
  941. //MWF.release(this);
  942. this.app.node.destroy();
  943. this.app.options.readonly = true;
  944. this.app.loadApplication();
  945. }
  946. },
  947. closeDocument: function () {
  948. this.fireEvent("beforeClose");
  949. if (this.app) {
  950. this.app.close();
  951. }
  952. },
  953. printDocument: function (form) {
  954. var form = form;
  955. if (!form) {
  956. form = this.json.id;
  957. if (this.json.printForm && this.json.printForm !== "none") form = this.json.printForm;
  958. }
  959. window.open(o2.filterUrl("../x_desktop/printcmsdoc.html?documentid=" + this.businessData.document.id + "&form=" + form));
  960. },
  961. formValidation: function (status) {
  962. if (this.options.readonly) return true;
  963. var flag = true;
  964. //flag = this.validation();
  965. Object.each(this.forms, function (field, key) {
  966. if (field.validationMode)field.validationMode();
  967. if (field.validation && !field.validation(status)) {
  968. flag = false;
  969. }
  970. }.bind(this));
  971. return flag;
  972. },
  973. formSaveValidation: function () {
  974. if (!this.json.validationSave) return true;
  975. if (!this.json.validationSave.code) return true;
  976. var flag = this.Macro.exec(this.json.validationSave.code, this);
  977. if (!flag) flag = MWF.xApplication.cms.Xform.LP.notValidation;
  978. if (typeOf(flag) === "string") {
  979. if (flag !== "true") {
  980. this.app.notice(flag, "error");
  981. return false;
  982. }
  983. } else if (flag.toString() != "true") {
  984. return false;
  985. }
  986. return true;
  987. },
  988. formPublishValidation: function () {
  989. if (!this.json.validationPublish) return true;
  990. if (!this.json.validationPublish.code) return true;
  991. var flag = this.Macro.exec(this.json.validationPublish.code, this);
  992. if (!flag) flag = MWF.xApplication.cms.Xform.LP.notValidation;
  993. if (typeOf(flag) === "string") {
  994. if (flag !== "true") {
  995. this.app.notice(flag, "error");
  996. return false;
  997. }
  998. } else if (flag.toString() != "true") {
  999. return false;
  1000. }
  1001. return true;
  1002. },
  1003. publishDocumentDelayed: function( callback ){
  1004. this.fireEvent("beforeWaitPublish");
  1005. // this.app.content.mask({
  1006. // "destroyOnHide": true,
  1007. // "style": this.app.css.maskNode
  1008. // });
  1009. if (!this.formValidation("publish")) {
  1010. // this.app.content.unmask();
  1011. //if (callback) callback();
  1012. return false;
  1013. }
  1014. if (!this.formPublishValidation()) {
  1015. // this.app.content.unmask();
  1016. if (callback) callback();
  1017. return false;
  1018. }
  1019. MWF.xDesktop.requireApp("cms.Document", "DelayPublishForm", null, false);
  1020. debugger;
  1021. var form = new MWF.xApplication.cms.Document.DelayPublishForm(this, {}, {
  1022. publishTime : this.businessData.document.publishTime || "",
  1023. onPostOk : function( publishTime ){
  1024. this._publishDocumentDelayed( publishTime );
  1025. }.bind(this)
  1026. },{
  1027. app : this.app, lp : this.app.lp, css : this.app.css, actions : this.app.action
  1028. });
  1029. form.create();
  1030. },
  1031. _publishDocumentDelayed: function( publishTime ){
  1032. var data = this.getData();
  1033. var specialData = this.getSpecialData();
  1034. //this.documentAction.saveData(function(json){
  1035. var documentData = this.getDocumentData(data);
  1036. documentData.publishTime = publishTime;
  1037. documentData.docStatus = "waitPublish";
  1038. documentData.documentNotify = this.getNoticeOptions();
  1039. documentData.readerList = specialData.readers;
  1040. documentData.authorList = specialData.authors;
  1041. documentData.pictureList = specialData.pictures;
  1042. documentData.summary = specialData.summary;
  1043. documentData.cloudPictures = specialData.cloudPictures;
  1044. documentData.docData = data;
  1045. delete documentData.attachmentList;
  1046. //this.documentAction.saveDocument(documentData, function(){
  1047. this.fireEvent("postWaitPublish", [documentData]);
  1048. if (this.app) if (this.app.fireEvent) this.app.fireEvent("postWaitPublish",[documentData]);
  1049. if (this.officeList) {
  1050. this.officeList.each(function (module) {
  1051. module.save();
  1052. });
  1053. }
  1054. this.documentAction.publishDocumentComplex(documentData, function (json) {
  1055. this.businessData.data.isNew = false;
  1056. this.fireEvent("afterWaitPublish", [this, json.data]);
  1057. if (this.app) if (this.app.fireEvent) this.app.fireEvent("afterWaitPublish",[this, json.data]);
  1058. // if (callback) callback(); // 传进来不是function
  1059. if (layout.mobile) {
  1060. // this.app.content.unmask();
  1061. this.closeWindowOnMobile();
  1062. } else {
  1063. if (this.businessData.document.title) {
  1064. this.app.notice(MWF.xApplication.cms.Xform.LP.documentDelayedPublished + ": “" + this.businessData.document.title + "”", "success");
  1065. } else {
  1066. this.app.notice(MWF.xApplication.cms.Xform.LP.documentDelayedPublished, "success");
  1067. }
  1068. this.options.saveOnClose = false;
  1069. debugger;
  1070. if( layout.inBrowser ){
  1071. try{
  1072. if( window.opener && window.opener.o2RefreshCMSView ){
  1073. window.opener.o2RefreshCMSView();
  1074. }
  1075. }catch (e) {}
  1076. window.setTimeout(function () {
  1077. this.app.close();
  1078. }.bind(this), 1500)
  1079. }else{
  1080. this.app.close();
  1081. }
  1082. }
  1083. }.bind(this));
  1084. },
  1085. publishDocument: function (callback, slience) {
  1086. this.fireEvent("beforePublish");
  1087. this.app.content.mask({
  1088. "destroyOnHide": true,
  1089. "style": this.app.css.maskNode
  1090. });
  1091. if (!this.formValidation("publish")) {
  1092. this.app.content.unmask();
  1093. if (o2.typeOf(callback) === "function") callback();
  1094. return false;
  1095. }
  1096. if (!this.formPublishValidation()) {
  1097. this.app.content.unmask();
  1098. if (o2.typeOf(callback) === "function") callback();
  1099. return false;
  1100. }
  1101. var data = this.getData();
  1102. var specialData = this.getSpecialData();
  1103. //this.documentAction.saveData(function(json){
  1104. var documentData = this.getDocumentData(data);
  1105. documentData.readerList = specialData.readers;
  1106. documentData.authorList = specialData.authors;
  1107. documentData.pictureList = specialData.pictures;
  1108. documentData.summary = specialData.summary;
  1109. documentData.cloudPictures = specialData.cloudPictures;
  1110. documentData.docData = data;
  1111. delete documentData.attachmentList;
  1112. //this.documentAction.saveDocument(documentData, function(){
  1113. this.fireEvent("postPublish", [documentData]);
  1114. if (this.app) if (this.app.fireEvent) this.app.fireEvent("postPublish",[documentData]);
  1115. if (this.officeList) {
  1116. this.officeList.each(function (module) {
  1117. module.save();
  1118. });
  1119. }
  1120. this.documentAction.publishDocumentComplex(documentData, function (json) {
  1121. this.sendNotice(function () {
  1122. this.businessData.data.isNew = false;
  1123. this.fireEvent("afterPublish", [this, json.data]);
  1124. if (this.app) if (this.app.fireEvent) this.app.fireEvent("afterPublish",[this, json.data]);
  1125. if (o2.typeOf(callback) === "function") callback(json); // 传进来不是function
  1126. if (layout.mobile) {
  1127. this.app.content.unmask();
  1128. this.closeWindowOnMobile();
  1129. } else {
  1130. if( slience !== true ){
  1131. if (this.businessData.document.title) {
  1132. this.app.notice(MWF.xApplication.cms.Xform.LP.documentPublished + ": “" + this.businessData.document.title + "”", "success");
  1133. } else {
  1134. this.app.notice(MWF.xApplication.cms.Xform.LP.documentPublished, "success");
  1135. }
  1136. }
  1137. this.options.saveOnClose = false;
  1138. debugger;
  1139. if( layout.inBrowser ){
  1140. try{
  1141. if( window.opener && window.opener.o2RefreshCMSView ){
  1142. window.opener.o2RefreshCMSView();
  1143. }
  1144. }catch (e) {}
  1145. window.setTimeout(function () {
  1146. this.app.close();
  1147. }.bind(this), 1500)
  1148. }else{
  1149. this.app.close();
  1150. }
  1151. }
  1152. }.bind(this));
  1153. }.bind(this));
  1154. //}.bind(this))
  1155. //}.bind(this), null, this.businessData.document.id, data);
  1156. },
  1157. getNoticeOptions: function(){
  1158. var rangeList = [];
  1159. var sendOptions;
  1160. if( this.json.noticeType === "custom" ){ //reader
  1161. switch ( o2.typeOf( this.json.noticeSpecificList ) ) {
  1162. case "array":
  1163. rangeList = this.json.noticeSpecificList;
  1164. break;
  1165. case "string":
  1166. case "object":
  1167. rangeList.push( this.json.noticeSpecificList );
  1168. break;
  1169. }
  1170. (this.json.noticeFormFieldList || []).each(function (name) {
  1171. var range = this.all[name.id] ? this.all[name.id].getData() : null;
  1172. if( range )rangeList = rangeList.concat( range );
  1173. }.bind(this));
  1174. if( this.json.noticeScript && this.json.noticeScript.code ){
  1175. range = this.Macro.exec(this.json.noticeScript.code, this);
  1176. switch ( o2.typeOf( range ) ) {
  1177. case "array":
  1178. rangeList = rangeList.concat( range );
  1179. break;
  1180. case "string":
  1181. case "object":
  1182. rangeList.push( range );
  1183. break;
  1184. }
  1185. }
  1186. rangeList = rangeList.clean().map(function ( range ) {
  1187. return o2.typeOf(range) === "string" ? range : range.distinguishedName
  1188. }).unique();
  1189. sendOptions = {
  1190. documentId: this.businessData.document.id,
  1191. notifyPersonList: rangeList,
  1192. notifyCreatePerson: this.json.notifyCreatePerson !== "no"
  1193. };
  1194. }else{
  1195. var readers = [];
  1196. Object.each(this.forms, function (module, id) {
  1197. if (module.json.type === "Readerfield" || module.json.type === "Reader") {
  1198. readers = readers.concat(module.getData());
  1199. }
  1200. });
  1201. rangeList = readers.clean().map(function ( range ) {
  1202. return o2.typeOf(range) === "string" ? range : range.distinguishedName
  1203. }).unique();
  1204. if( rangeList.length === 0 ){
  1205. if( this.json.blankToAllNotify !== "no" ){ //通知所有人
  1206. sendOptions = {
  1207. documentId: this.businessData.document.id,
  1208. notifyByDocumentReadPerson: true,
  1209. notifyCreatePerson: this.json.notifyCreatePerson !== "no"
  1210. };
  1211. }
  1212. }else{
  1213. sendOptions = {
  1214. documentId: this.businessData.document.id,
  1215. notifyPersonList: rangeList,
  1216. notifyByDocumentReadPerson: true,
  1217. notifyCreatePerson: this.json.notifyCreatePerson !== "no"
  1218. };
  1219. }
  1220. }
  1221. if( !sendOptions && this.json.notifyCreatePerson !== "no" ){
  1222. sendOptions = {
  1223. documentId: this.businessData.document.id,
  1224. notifyByDocumentReadPerson: false,
  1225. notifyCreatePerson: true
  1226. };
  1227. }
  1228. return sendOptions;
  1229. },
  1230. sendNotice: function( callback ){
  1231. var sendOptions = this.getNoticeOptions();
  1232. if( sendOptions && o2.Actions.load("x_cms_assemble_control").DocumentAction.publishNotify ) {
  1233. o2.Actions.load("x_cms_assemble_control").DocumentAction.publishNotify(this.businessData.document.id, sendOptions, function () {
  1234. if (callback) callback( sendOptions );
  1235. }, function () {
  1236. if (callback) callback( sendOptions );
  1237. })
  1238. }else{
  1239. if(callback)callback( sendOptions );
  1240. }
  1241. },
  1242. deleteDocumentForMobile: function () {
  1243. if (layout.mobile) {
  1244. this.app.content.mask({
  1245. "style": {
  1246. "background-color": "#999",
  1247. "opacity": 0.6
  1248. }
  1249. });
  1250. this.fireEvent("beforeDelete");
  1251. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeDelete");
  1252. this.documentAction.removeDocument(this.businessData.document.id, function (json) {
  1253. this.fireEvent("afterDelete");
  1254. if (this.app && this.app.fireEvent) this.app.fireEvent("afterDelete");
  1255. this.app.notice(MWF.xApplication.cms.Xform.LP.documentDelete + ": “" + this.businessData.document.title + "”", "success");
  1256. this.options.autoSave = false;
  1257. this.options.saveOnClose = false;
  1258. this.fireEvent("postDelete");
  1259. this.closeWindowOnMobile();
  1260. }.bind(this));
  1261. }
  1262. },
  1263. /**
  1264. * @summary 弹出删除文档确认框.
  1265. * @method deleteDocument
  1266. * @memberof CMSForm
  1267. * @example
  1268. * this.form.getApp().appForm.deleteDocument();
  1269. */
  1270. deleteDocument: function () {
  1271. var _self = this;
  1272. var p = MWF.getCenterPosition(this.app.content, 380, 150);
  1273. var event = {
  1274. "event": {
  1275. "x": p.x,
  1276. "y": p.y - 200,
  1277. "clientX": p.x,
  1278. "clientY": p.y - 200
  1279. }
  1280. };
  1281. debugger;
  1282. this.app.confirm("infor", event, MWF.xApplication.cms.Xform.LP.deleteDocumentTitle, MWF.xApplication.cms.Xform.LP.deleteDocumentText, 380, 120, function () {
  1283. if (layout.mobile) {
  1284. _self.deleteDocumentForMobile();
  1285. } else {
  1286. _self.app.content.mask({
  1287. "style": {
  1288. "background-color": "#999",
  1289. "opacity": 0.6
  1290. }
  1291. });
  1292. _self.fireEvent("beforeDelete");
  1293. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("beforeDelete");
  1294. _self.documentAction.removeDocument(_self.businessData.document.id, function (json) {
  1295. debugger;
  1296. _self.fireEvent("afterDelete");
  1297. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("afterDelete");
  1298. _self.app.notice(MWF.xApplication.cms.Xform.LP.documentDelete + ": “" + _self.businessData.document.title + "”", "success");
  1299. _self.options.autoSave = false;
  1300. _self.options.saveOnClose = false;
  1301. _self.fireEvent("postDelete");
  1302. _self.app.close();
  1303. this.close();
  1304. }.bind(this));
  1305. }
  1306. //this.close();
  1307. }, function () {
  1308. this.close();
  1309. });
  1310. },
  1311. /**
  1312. * @summary 编辑文档.
  1313. * @method editDocument
  1314. * @memberof CMSForm
  1315. * @example
  1316. * this.form.getApp().appForm.editDocument();
  1317. */
  1318. editDocument: function () {
  1319. this.fireEvent("editDocument");
  1320. if (this.app.inBrowser) {
  1321. this.modules.each(function (module) {
  1322. MWF.release(module);
  1323. });
  1324. //MWF.release(this);
  1325. this.app.node.destroy();
  1326. this.app.options.readonly = false;
  1327. this.app.loadApplication();
  1328. } else {
  1329. var options = { "documentId": this.businessData.document.id, "readonly": false }; //this.explorer.app.options.application.allowControl};
  1330. if (this.app.options.postPublish)options.postPublish = this.app.options.postPublish;
  1331. if (this.app.options.afterPublish)options.afterPublish = this.app.options.afterPublish;
  1332. if (this.app.options.postDelete)options.postDelete = this.app.options.postDelete;
  1333. if (this.app.options.formEditId) options.formEditId = this.app.options.formEditId;
  1334. this.app.desktop.openApplication(null, "cms.Document", options);
  1335. this.app.close();
  1336. }
  1337. },
  1338. //2019-11-29 移动端 开启编辑模式
  1339. /**
  1340. * @summary 移动端开启编辑模式.
  1341. * @method editDocumentForMobile
  1342. * @memberof CMSForm
  1343. * @example
  1344. * this.form.getApp().appForm.editDocumentForMobile();
  1345. */
  1346. editDocumentForMobile: function () {
  1347. if (layout.mobile) {
  1348. this.app.options.readonly = false;
  1349. this.app.loadDocument(this.app.options);
  1350. }
  1351. },
  1352. /**
  1353. * @summary 弹出设置热点的界面.
  1354. * @method setPopularDocument
  1355. * @memberof CMSForm
  1356. * @example
  1357. * this.form.getApp().appForm.setPopularDocument();
  1358. */
  1359. setPopularDocument: function () {
  1360. this.app.setPopularDocument();
  1361. },
  1362. // printWork: function (app, form) {
  1363. // var application = app || this.businessData.work.application;
  1364. // var form = form;
  1365. // if (!form) {
  1366. // form = this.json.id;
  1367. // if (this.json.printForm) form = this.json.printForm;
  1368. // }
  1369. // window.open(o2.filterUrl("../x_desktop/printWork.html?workid=" + this.businessData.work.id + "&app=" + this.businessData.work.application + "&form=" + form));
  1370. // },
  1371. openWindow: function (form, app) {
  1372. var form = form;
  1373. if (!form) {
  1374. form = this.json.id;
  1375. }
  1376. if (this.businessData.document) {
  1377. //var application = app;
  1378. //window.open("../x_desktop/printWork.html?workCompletedId="+this.businessData.workCompleted.id+"&app="+application+"&form="+form);
  1379. }
  1380. },
  1381. /**
  1382. * @summary 将新上传的附件在指定的附件组件中展现.
  1383. * @method uploadedAttachment
  1384. * @memberof CMSForm
  1385. * @param {String} site - 附件组件的标识
  1386. * @param {String} id - 新上传的附件id
  1387. * @example
  1388. * this.form.getApp().appForm.uploadedAttachment(site, id);
  1389. */
  1390. uploadedAttachment: function (site, id) {
  1391. this.documentAction.getAttachment(id, this.businessData.document.id, function (json) {
  1392. var flag = this.businessData.attachmentList.some(function (attData) {
  1393. return json.data.id === attData.id;
  1394. }.bind(this));
  1395. if( !flag ){
  1396. this.businessData.attachmentList.push(json.data);
  1397. }
  1398. var att = this.all[site];
  1399. if (att) {
  1400. if (json.data) att.attachmentController.addAttachment(json.data);
  1401. att.attachmentController.checkActions();
  1402. att.fireEvent("upload", [json.data]);
  1403. }
  1404. }.bind(this));
  1405. },
  1406. replacedAttachment: function (site, id) {
  1407. this.documentAction.getAttachment(id, this.businessData.document.id, function (json) {
  1408. var att = this.all[site];
  1409. if (att) {
  1410. var attachmentController = att.attachmentController;
  1411. var attachment = null;
  1412. for (var i = 0; i < attachmentController.attachments.length; i++) {
  1413. if (attachmentController.attachments[i].data.id === id) {
  1414. attachment = attachmentController.attachments[i];
  1415. break;
  1416. }
  1417. }
  1418. attachment.data = json.data;
  1419. attachment.reload();
  1420. attachmentController.checkActions();
  1421. }
  1422. }.bind(this))
  1423. },
  1424. uploadedAttachmentDatagrid: function (site, id, moduleId) {
  1425. this.documentAction.getAttachment(id, this.businessData.document.id, function (json) {
  1426. var flag = this.businessData.attachmentList.some(function (attData) {
  1427. return json.data.id === attData.id;
  1428. }.bind(this));
  1429. if( !flag ){
  1430. this.businessData.attachmentList.push(json.data);
  1431. }
  1432. var att = this.all[moduleId];
  1433. if (att) {
  1434. if (json.data) att.attachmentController.addAttachment(json.data);
  1435. att.setAttachmentBusinessData();
  1436. att.attachmentController.checkActions();
  1437. att.fireEvent("upload", [json.data]);
  1438. att.fireEvent("change", [json.data]);
  1439. }
  1440. }.bind(this));
  1441. },
  1442. replacedAttachmentDatagrid: function (site, id, moduleId) {
  1443. this.documentAction.getAttachment(id, this.businessData.document.id, function (json) {
  1444. var att = this.all[moduleId];
  1445. if (att) {
  1446. var attachmentController = att.attachmentController;
  1447. var attachment = null;
  1448. for (var i = 0; i < attachmentController.attachments.length; i++) {
  1449. if (attachmentController.attachments[i].data.id === id) {
  1450. attachment = attachmentController.attachments[i];
  1451. break;
  1452. }
  1453. }
  1454. attachment.data = json.data;
  1455. att.setAttachmentBusinessData();
  1456. attachment.reload();
  1457. attachmentController.checkActions();
  1458. att.fireEvent("change", [json.data]);
  1459. }
  1460. }.bind(this))
  1461. },
  1462. /**
  1463. * @summary 弹出文档置顶对话框,操作后使当前文档在列式服务中排在前面.
  1464. * @method setTop
  1465. * @memberof CMSForm
  1466. * @example
  1467. * this.form.getApp().appForm.setTop();
  1468. */
  1469. setTop: function () {
  1470. var _self = this;
  1471. var p = MWF.getCenterPosition(this.app.content, 380, 150);
  1472. var event = {
  1473. "event": {
  1474. "x": p.x,
  1475. "y": p.y - 200,
  1476. "clientX": p.x,
  1477. "clientY": p.y - 200
  1478. }
  1479. };
  1480. this.app.confirm("infor", event, MWF.xApplication.cms.Xform.LP.setTopTitle, MWF.xApplication.cms.Xform.LP.setTopText, 380, 120, function () {
  1481. o2.Actions.load("x_cms_assemble_control").DocumentAction.persist_top(_self.businessData.document.id, function () {
  1482. _self.app.notice(MWF.xApplication.cms.Xform.LP.setTopSuccess, "success");
  1483. _self.app.reload();
  1484. this.close();
  1485. }.bind(this))
  1486. //this.close();
  1487. }, function () {
  1488. this.close();
  1489. });
  1490. },
  1491. /**
  1492. * @summary 弹出文档取消置顶对话框.
  1493. * @method cancelTop
  1494. * @memberof CMSForm
  1495. * @example
  1496. * this.form.getApp().appForm.cancelTop();
  1497. */
  1498. cancelTop: function () {
  1499. var _self = this;
  1500. var p = MWF.getCenterPosition(this.app.content, 380, 150);
  1501. var event = {
  1502. "event": {
  1503. "x": p.x,
  1504. "y": p.y - 200,
  1505. "clientX": p.x,
  1506. "clientY": p.y - 200
  1507. }
  1508. };
  1509. this.app.confirm("infor", event, MWF.xApplication.cms.Xform.LP.cancelTopTitle, MWF.xApplication.cms.Xform.LP.cancelTopText, 380, 120, function () {
  1510. o2.Actions.load("x_cms_assemble_control").DocumentAction.persist_unTop(_self.businessData.document.id, function () {
  1511. _self.app.notice(MWF.xApplication.cms.Xform.LP.cancelTopSuccess, "success");
  1512. _self.app.reload();
  1513. this.close();
  1514. }.bind(this))
  1515. //this.close();
  1516. }, function () {
  1517. this.close();
  1518. });
  1519. },
  1520. /**
  1521. * @summary 一键下载表单和附件.
  1522. * @method downloadAll
  1523. * @memberof CMSForm
  1524. * @example
  1525. * this.form.getApp().appForm.downloadAll();
  1526. */
  1527. downloadAll: function () {
  1528. o2.Actions.load("x_cms_assemble_control").FileInfoAction.uploadWorkInfo(this.businessData.document.id, "pdf", {
  1529. "workHtml": encodeURIComponent(this.app.content.get("html")),
  1530. "pageWidth": 1000
  1531. }, function (json) {
  1532. var htmlFormId = json.data.id;
  1533. htmlFormId = htmlFormId.replace("#", "%23");
  1534. var url = "/x_cms_assemble_control/jaxrs/fileinfo/batch/download/doc/" + this.businessData.document.id + "/site/(0)";
  1535. url = o2.filterUrl(o2.Actions.getHost("x_processplatform_assemble_surface") + url);
  1536. var downloadUrl = o2.filterUrl(url + "?fileName=&flag=" + htmlFormId);
  1537. if ((o2.thirdparty.isDingdingPC() || o2.thirdparty.isQywxPC())) {
  1538. var xtoken = Cookie.read(o2.tokenName);
  1539. downloadUrl += "&" + o2.tokenName + "=" + xtoken;
  1540. }
  1541. window.open(downloadUrl);
  1542. }.bind(this));
  1543. },
  1544. /**
  1545. * 移动端处理关闭
  1546. */
  1547. closeWindowOnMobile: function () {
  1548. if (window.o2android && window.o2android.postMessage) {
  1549. var body = {
  1550. type: "closeDocumentWindow",
  1551. data: {}
  1552. };
  1553. window.o2android.postMessage(JSON.stringify(body));
  1554. } else if (window.o2android && window.o2android.closeDocumentWindow) {
  1555. window.o2android.closeDocumentWindow("");
  1556. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.closeDocumentWindow) {
  1557. window.webkit.messageHandlers.closeDocumentWindow.postMessage("");
  1558. } else if (window.wx && window.__wxjs_environment === 'miniprogram') { //微信小程序 关闭页面
  1559. wx.miniProgram.navigateBack({ delta: 1 });
  1560. } else if (window.uni && window.uni.navigateBack) { // uniapp 关闭页面
  1561. window.uni.navigateBack();
  1562. } else if (this.json.afterProcessAction === "redirect" && this.json.afterProcessRedirectScript && this.json.afterProcessRedirectScript.code) {
  1563. var url = this.Macro.exec(this.json.afterProcessRedirectScript.code, this);
  1564. (new URI(url)).go();
  1565. } else {
  1566. var uri = new URI(window.location.href);
  1567. var redirectlink = uri.getData("redirectlink");
  1568. if (redirectlink) {
  1569. history.replaceState(null, "work", redirectlink);
  1570. redirectlink.toURI().go();
  1571. } else {
  1572. this.app.close();
  1573. }
  1574. // var len = window.history.length;
  1575. // if (len > 1) {
  1576. // history.back();
  1577. // } else {
  1578. // // window.location = o2.filterUrl("../x_desktop/appMobile.html?app=process.TaskCenter");
  1579. // history.replaceState(null, "work", o2.filterUrl("../x_desktop/appMobile.html?app=process.TaskCenter"));
  1580. // o2.filterUrl("../x_desktop/appMobile.html?app=process.TaskCenter").toURI().go();
  1581. // }
  1582. }
  1583. },
  1584. // //列式流程log
  1585. // listWorkLog: function ( callback ) {
  1586. // if( !this.businessData.data.$work || !this.businessData.data.$work.job ){
  1587. // callback([]);
  1588. // return
  1589. // }
  1590. //
  1591. // if( this.workLogList ){
  1592. // callback(this.workLogList);
  1593. // return;
  1594. // }
  1595. //
  1596. // //只获取一次。把callback存起来,等异步调用完成后一次性执行callback
  1597. // if( !this.worklogCallbackList )this.worklogCallbackList = [];
  1598. // Promise.resolve( o2.Actions.load("x_processplatform_assemble_surface").WorkLogAction.listWithJob( this.businessData.data.$work.job )).then(function(json){
  1599. // this.workLogList = json.data;
  1600. // debugger;
  1601. // while( this.worklogCallbackList.length ){
  1602. // this.worklogCallbackList.shift()( this.workLogList );
  1603. // }
  1604. // }.bind(this));
  1605. // this.worklogCallbackList.push( callback );
  1606. // },
  1607. // //列式流程record
  1608. // listWorkRecord: function ( callback ) {
  1609. // if( !this.businessData.data.$work || !this.businessData.data.$work.job ){
  1610. // callback([]);
  1611. // return
  1612. // }
  1613. //
  1614. // if( this.workRecordList ){
  1615. // callback(this.workRecordList);
  1616. // return;
  1617. // }
  1618. //
  1619. // //只获取一次。把callback存起来,等异步调用完成后一次性执行callback
  1620. // if( !this.workRecordCallbackList )this.workRecordCallbackList = [];
  1621. // Promise.resolve( o2.Actions.load("x_processplatform_assemble_surface").RecordAction.listWithJob( this.businessData.data.$work.job )).then(function(json){
  1622. // this.workRecordList = json.data;
  1623. // while( this.workRecordCallbackList.length ){
  1624. // this.workRecordCallbackList.shift()( this.workRecordList );
  1625. // }
  1626. // }.bind(this));
  1627. // this.workRecordCallbackList.push( callback );
  1628. // }
  1629. });