Form.js 83 KB

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