Documenteditor.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.Documenteditor = MWF.APPDocumenteditor = new Class({
  3. Extends: MWF.APP$Module,
  4. options: {
  5. "moduleEvents": ["load", "postLoad", "afterLoad"],
  6. "docPageHeight": 850.4,
  7. "docPageFullWidth": 794,
  8. "pageShow": "double"
  9. },
  10. initialize: function(node, json, form, options){
  11. this.node = $(node);
  12. this.node.store("module", this);
  13. this.json = json;
  14. this.form = form;
  15. this.field = true;
  16. },
  17. _loadCss: function(reload){
  18. var key = encodeURIComponent(this.cssPath);
  19. if (!reload && o2.widget.css[key]){
  20. this.css = o2.widget.css[key];
  21. }else{
  22. this.cssPath = (this.cssPath.indexOf("?")!=-1) ? this.cssPath+"&v="+o2.version.v : this.cssPath+"?v="+o2.version.v;
  23. var r = new Request.JSON({
  24. url: this.cssPath,
  25. secure: false,
  26. async: false,
  27. method: "get",
  28. noCache: false,
  29. onSuccess: function(responseJSON, responseText){
  30. this.css = responseJSON;
  31. o2.widget.css[key] = responseJSON;
  32. }.bind(this),
  33. onError: function(text, error){
  34. console.log(error + text);
  35. }
  36. });
  37. r.send();
  38. }
  39. },
  40. load: function(){
  41. if (this.fireEvent("queryLoad")){
  42. this.cssPath = this.form.path+this.form.options.style+"/doc.wcss";
  43. this._loadCss();
  44. this._queryLoaded();
  45. this._loadUserInterface();
  46. this._loadStyles();
  47. this._afterLoaded();
  48. this.fireEvent("postLoad");
  49. this.fireEvent("load");
  50. }
  51. },
  52. _createNewPage: function(){
  53. var pageNode = new Element("div.doc_layout_page", {"styles": this.css.doc_page}).inject(this.contentNode);
  54. var pageContentNode = new Element("div.doc_layout_page_content", {"styles": this.css.doc_layout_page_content}).inject(pageNode);
  55. pageNode.set("data-pagecount", this.pages.length+1);
  56. this.pages.push(pageNode);
  57. return pageNode;
  58. },
  59. _getShow: function(name, typeItem, scriptItem){
  60. switch (this.json[typeItem]) {
  61. case "y":
  62. return true;
  63. case "n":
  64. return false;
  65. case "a":
  66. if (["copies", "secret", "priority", "attachment", "annotation", "copyto"].indexOf(name!=-1)){
  67. return !!this.data[name];
  68. }
  69. return true;
  70. case "s":
  71. if (this.json[scriptItem] && this.json[scriptItem].code){
  72. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  73. }
  74. return true;
  75. }
  76. },
  77. _createPage: function(){
  78. debugger;
  79. var pageContentNode = this._createNewPage().getFirst();
  80. var html = '<div class="doc_block doc_layout_copiesSecretPriority">';
  81. if (this._getShow("copies", "copiesShow", "copiesShowScript")) html += ' <div class="doc_layout_copies"></div>';
  82. if (this._getShow("secret", "secretShow", "secretShowScript")) html += ' <div class="doc_layout_secret"></div>';
  83. if (this._getShow("priority", "priorityShow", "priorityShowScript")) html += ' <div class="doc_layout_priority"></div>';
  84. html += '</div>'
  85. if (this._getShow("redHeader", "redHeaderShow", "redHeaderShowScript")) html += '<div class="doc_block doc_layout_redHeader"></div>';
  86. if (this._getShow("signer", "signerShow", "signerShowScript")){
  87. this.json.fileup = true;
  88. html += '<table class="doc_block doc_layout_filenoup" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  89. '<tr><td class="doc_layout_filenoup_fileno_td">';
  90. if (this._getShow("fileno", "filenoShow", "filenoShowScript")) html += ' <span> </span><span class="doc_layout_filenoup_fileno"></span>';
  91. html += ' </td><td class="doc_layout_filenoup_signer_td">' +
  92. ' <table class="doc_layout_filenoup_signer_table" cellpadding="0" cellspacing="0" border="0">' +
  93. ' <tr><td class="doc_layout_filenoup_signerTitle_td">'+
  94. ' <span class="doc_layout_filenoup_signer"></span>' +
  95. ' </td><td class="doc_layout_filenoup_signerContent_td">' +
  96. ' <span class="doc_layout_filenoup_signerContent"></span><span> </span>' +
  97. ' </td></tr>' +
  98. ' </table>' +
  99. ' </td></tr>' +
  100. '</table>';
  101. }else{
  102. if (this._getShow("fileno", "filenoShow", "filenoShowScript")) html += '<div class=\"doc_block doc_layout_fileno\"></div>';
  103. }
  104. html += "<div color=\"#ff0000\" class=\"doc_block doc_layout_redline\"></div>";
  105. if (this._getShow("subject", "subjectShow", "subjectShowScript")) html += "<div class=\"doc_block doc_layout_subject\"></div>";
  106. if (this._getShow("mainSend", "mainSendShow", "mainSendShowScript")) html += "<div class=\"doc_block doc_layout_mainSend\"></div>";
  107. html += "<div class=\"doc_block doc_layout_filetext\"></div>";
  108. if (this._getShow("attachment", "attachmentShow", "attachmentShowScript")){
  109. html += '<table class="doc_block doc_layout_attachment" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  110. ' <tr><td class="doc_layout_attachment_title_td">' +
  111. ' <span>  </span><span class="doc_layout_attachment_title"></span>' +
  112. ' </td><td class="doc_layout_attachment_content_td">' +
  113. ' <span class="doc_layout_attachment_content"></span>' +
  114. ' </td></tr>' +
  115. '</table>';
  116. };
  117. // html += '<table class="doc_block doc_layout_issuance" cellpadding="0" cellspacing="0" border="0">' +
  118. // ' <tr><td class="doc_layout_issuanceUnit"></td></tr>' +
  119. // ' <tr><td class="doc_layout_issuanceDate"></td></tr>' +
  120. // '</table>'
  121. var showIssuanceUnit = this._getShow("issuanceUnit", "issuanceUnitShow", "issuanceUnitShowScript");
  122. var showIssuanceDate = this._getShow("issuanceDate", "issuanceDateShow", "issuanceDateShowScript");
  123. if (showIssuanceUnit || showIssuanceDate){
  124. html += '<div class="doc_block" style="overflow: hidden;"><table class="doc_layout_issuance" cellpadding="0" cellspacing="0" border="0">';
  125. if (showIssuanceUnit) html += ' <tr><td class="doc_layout_issuanceUnit"></td></tr>';
  126. if (showIssuanceDate) html += ' <tr><td class="doc_layout_issuanceDate"></td></tr>';
  127. html += '</table></div>';
  128. }
  129. if (this._getShow("annotation", "annotationShow", "annotationShowScript")) html += '<div class="doc_block doc_layout_annotation"></div>';
  130. html += '<table class="doc_block doc_layout_edition" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  131. ' <tr><td class="doc_layout_edition_copyto">';
  132. if (this._getShow("copyto", "copytoShow", "copytoShowScript")){
  133. html += ' <table class="doc_layout_edition_copyto_table" align="center" cellpadding="0" cellspacing="0" border="0">' +
  134. ' <tr>' +
  135. ' <td class="doc_layout_edition_copyto_title"></td>' +
  136. ' <td class="doc_layout_edition_copyto_content"></td>' +
  137. ' </tr>' +
  138. ' </table>';
  139. }
  140. html += ' </td></tr><tr><td class="doc_layout_edition_issuance">'+
  141. ' <table class="doc_layout_edition_issuance_table" align="center" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  142. ' <tr>';
  143. if (this._getShow("editionUnit", "editionUnitShow", "editionUnitShowScript")) html += '<td class="doc_layout_edition_issuance_unit"></td>';
  144. if (this._getShow("editionDate", "editionDateShow", "editionDateShowScript")) html += '<td class="doc_layout_edition_issuance_date"></td>';
  145. html += ' </tr>' +
  146. ' </table>' +
  147. '</td></tr>' +
  148. '</table>';
  149. //@todo
  150. // '<table class="doc_block doc_layout_filenoup" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  151. // ' <tr><td class="doc_layout_filenoup_fileno_td">' +
  152. // ' <span> </span><span class="doc_layout_filenoup_fileno">浙移发〔2019〕20号</span>' +
  153. // ' </td><td class="doc_layout_filenoup_signer_td">' +
  154. // ' <table class="doc_layout_filenoup_signer_table" cellpadding="0" cellspacing="0" border="0">' +
  155. // ' <tr><td class="doc_layout_filenoup_signerTitle_td">' +
  156. // ' <span class="doc_layout_filenoup_signer">签发人:</span>' +
  157. // ' </td><td class="doc_layout_filenoup_signerContent_td">' +
  158. // ' <span class="doc_layout_filenoup_signerContent"></span><span> </span>' +
  159. // ' </td></tr>' +
  160. // ' </table>' +
  161. // ' </td></tr>' +
  162. // '</table>'+
  163. //
  164. //
  165. // "<div class=\"doc_block doc_layout_fileno\"></div>" +
  166. // "<div color=\"#ff0000\" class=\"doc_block doc_layout_redline\"></div>" +
  167. // "<div class=\"doc_block doc_layout_subject\"></div>" +
  168. // "<div class=\"doc_block doc_layout_mainSend\">:</div>"+
  169. // "<div class=\"doc_block doc_layout_filetext\"></div>" +
  170. //
  171. // '<table class="doc_block doc_layout_attachment" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  172. // ' <tr><td class="doc_layout_attachment_title_td">' +
  173. // ' <span>  </span><span class="doc_layout_attachment_title"></span>' +
  174. // ' </td><td class="doc_layout_attachment_content_td">' +
  175. // ' <span class="doc_layout_attachment_content"></span>' +
  176. // ' </td></tr>' +
  177. // '</table>' +
  178. // '<table class="doc_block doc_layout_issuance" cellpadding="0" cellspacing="0" border="0">' +
  179. // ' <tr><td class="doc_layout_issuanceUnit"></td></tr>' +
  180. // ' <tr><td class="doc_layout_issuanceDate"></td></tr>' +
  181. // '</table>' +
  182. // '<div class="doc_block doc_layout_annotation"></div>'+
  183. // // pageContentNode.set("html", html);
  184. // //
  185. // // pageContentNode = this._createNewPage().getFirst();
  186. // // html = '' +
  187. // '<table class="doc_block doc_layout_edition" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  188. // ' <tr><td class="doc_layout_edition_copyto">' +
  189. // ' <table class="doc_layout_edition_copyto_table" align="center" cellpadding="0" cellspacing="0" border="0">' +
  190. // ' <tr>' +
  191. // ' <td class="doc_layout_edition_copyto_title"></td>' +
  192. // ' <td class="doc_layout_edition_copyto_content"></td>' +
  193. // ' </tr>' +
  194. // ' </table>' +
  195. // ' </td></tr>' +
  196. // ' <tr><td class="doc_layout_edition_issuance">' +
  197. // ' <table class="doc_layout_edition_issuance_table" align="center" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  198. // ' <tr>' +
  199. // ' <td class="doc_layout_edition_issuance_unit"></td>' +
  200. // ' <td class="doc_layout_edition_issuance_date"></td>' +
  201. // ' </tr>' +
  202. // ' </table>' +
  203. // ' </td></tr>' +
  204. // '</table>';
  205. pageContentNode.set("html", html);
  206. },
  207. //份数 密级 紧急程度
  208. _loadCopiesSecretPriority: function(){
  209. this.layout_copiesSecretPriority = this.contentNode.getElement(".doc_layout_copiesSecretPriority");
  210. if (this.layout_copiesSecretPriority) this.layout_copiesSecretPriority.setStyles(this.css.doc_layout_copiesSecretPriority);
  211. this.layout_copies = this.contentNode.getElement(".doc_layout_copies");
  212. if (this.layout_copies) this.layout_copies.setStyles(this.css.doc_layout_copies);
  213. this.layout_secret = this.contentNode.getElement(".doc_layout_secret");
  214. if (this.layout_secret) this.layout_secret.setStyles(this.css.doc_layout_secret);
  215. this.layout_priority = this.contentNode.getElement(".doc_layout_priority");
  216. if (this.layout_priority) this.layout_priority.setStyles(this.css.doc_layout_priority);
  217. },
  218. //红头
  219. _loadRedHeader: function(){
  220. this.layout_redHeader = this.contentNode.getElement(".doc_layout_redHeader");
  221. if (this.layout_redHeader) this.layout_redHeader.setStyles(this.css.doc_layout_redHeader);
  222. },
  223. //文号签发人(上行文)
  224. _loadFileNoUp: function(){
  225. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  226. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable.setStyles(this.css.doc_layout_filenoup);
  227. var td = this.contentNode.getElement(".doc_layout_filenoup_fileno_td");
  228. if (td) td.setStyles(this.css.doc_layout_filenoup_fileno_td);
  229. this.layout_fileno = this.contentNode.getElement(".doc_layout_filenoup_fileno");
  230. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_filenoup_fileno);
  231. td = this.contentNode.getElement(".doc_layout_filenoup_signer_td");
  232. if (td) td.setStyles(this.css.doc_layout_filenoup_signer_td);
  233. var node = this.contentNode.getElement(".doc_layout_filenoup_signer_table");
  234. if (node) node.setStyles(this.css.doc_layout_filenoup_signer_table);
  235. node = this.contentNode.getElement(".doc_layout_filenoup_signerTitle_td").setStyles(this.css.doc_layout_filenoup_signerTitle_td);
  236. if (node) node.setStyles(this.css.doc_layout_filenoup_signerTitle_td);
  237. this.layout_signerTitle = this.contentNode.getElement(".doc_layout_filenoup_signer").setStyles(this.css.doc_layout_filenoup_signer);
  238. if (this.layout_signerTitle) this.layout_signerTitle.setStyles(this.css.doc_layout_filenoup_signer);
  239. node = this.contentNode.getElement(".doc_layout_filenoup_signerContent_td").setStyles(this.css.doc_layout_filenoup_signerContent_td);
  240. if (node) node.setStyles(this.css.doc_layout_filenoup_signerContent_td);
  241. this.layout_signer = this.contentNode.getElement(".doc_layout_filenoup_signerContent");
  242. if (this.layout_signer) this.layout_signer.setStyles(this.css.doc_layout_filenoup_signerContent);
  243. },
  244. //文号
  245. _loadFileNo: function(){
  246. this.layout_fileno = this.contentNode.getElement(".doc_layout_fileno");
  247. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_fileno);
  248. },
  249. //红线
  250. _loadRedLine: function(){
  251. this.layout_redLine = this.contentNode.getElement(".doc_layout_redline");
  252. if (this.layout_redLine) this.layout_redLine.setStyles(this.css.doc_layout_redline);
  253. },
  254. //标题
  255. _loadSubject:function(){
  256. this.layout_subject = this.contentNode.getElement(".doc_layout_subject");
  257. if (this.layout_subject) this.layout_subject.setStyles(this.css.doc_layout_subject);
  258. },
  259. //主送
  260. _loadMainSend: function(){
  261. this.layout_mainSend = this.contentNode.getElement(".doc_layout_mainSend");
  262. if (this.layout_mainSend) this.layout_mainSend.setStyles(this.css.doc_layout_mainSend);
  263. },
  264. //正文
  265. // _createFiletext: function(filetextNode, node, where){
  266. // if (!filetextNode){
  267. // var filetextNode = new Element("div.doc_layout_filetext").inject(node, where);
  268. // filetextNode.addClass("doc_block");
  269. // filetextNode.setAttribute('contenteditable', true);
  270. // }
  271. // CKEDITOR.disableAutoInline = true;
  272. // var filetextEditor = CKEDITOR.inline(filetextNode, this._getEditorConfig());
  273. // filetextNode.store("editor", filetextEditor);
  274. // if (!this.filetextEditors) this.filetextEditors = [];
  275. // this.filetextEditors.push(filetextEditor);
  276. //
  277. // filetextEditor.on( 'blur', function(e) {
  278. // // var filetextNode = e.editor.container.$;
  279. // // var pageNode = filetextNode.getParent(".doc_layout_page");
  280. // // this._checkSplitPage(pageNode);
  281. // // this._repage();
  282. // }.bind(this));
  283. //
  284. // return filetextNode;
  285. // },
  286. _loadFiletext: function(){
  287. this.layout_filetext = this.contentNode.getElement(".doc_layout_filetext");
  288. this.layout_filetext.setStyles(this.css.doc_layout_filetext);
  289. //this.layout_filetext = this.contentNode.getElement(".doc_layout_filetext");
  290. // if (this.layout_filetexts.length){
  291. // this.layout_filetexts.each(function(layout_filetext){
  292. // layout_filetext.setStyles(this.css.doc_layout_filetext);
  293. // }.bind(this));
  294. // }
  295. },
  296. //附件
  297. _loadAttachment: function(){
  298. this.layout_attachmentTable = this.contentNode.getElement(".doc_layout_attachment");
  299. if (this.layout_attachmentTable) this.layout_attachmentTable.setStyles(this.css.doc_layout_attachment);
  300. var node = this.contentNode.getElement(".doc_layout_attachment_title_td");
  301. if (node) node.setStyles(this.css.doc_layout_attachment_title_td);
  302. this.layout_attachmentTitle = this.contentNode.getElement(".doc_layout_attachment_title");
  303. if (node) node.setStyles(this.css.doc_layout_attachment_title);
  304. node = this.contentNode.getElement(".doc_layout_attachment_content_td");
  305. if (node) node.setStyles(this.css.doc_layout_attachment_content_td);
  306. this.layout_attachment = this.contentNode.getElement(".doc_layout_attachment_content");
  307. if (this.layout_attachment) this.layout_attachment.setStyles(this.css.doc_layout_attachment_content);
  308. },
  309. //发布单位
  310. _loadIssuance: function(){
  311. this.layout_issuanceTable = this.contentNode.getElement(".doc_layout_issuance");
  312. this.layout_issuanceUnit = this.contentNode.getElement(".doc_layout_issuanceUnit");
  313. this.layout_issuanceDate = this.contentNode.getElement(".doc_layout_issuanceDate");
  314. if (this.layout_issuanceTable) this.layout_issuanceTable.setStyles(this.css.doc_layout_issuance);
  315. if (this.layout_issuanceUnit) this.layout_issuanceUnit.setStyles(this.css.doc_layout_issuanceUnit);
  316. if (this.layout_issuanceDate) this.layout_issuanceDate.setStyles(this.css.doc_layout_issuanceDate);
  317. },
  318. //附注
  319. _loadAnnotation: function(){
  320. this.layout_annotation = this.contentNode.getElement(".doc_layout_annotation");
  321. if (this.layout_annotation) this.layout_annotation.setStyles(this.css.doc_layout_annotation);
  322. },
  323. //版记
  324. _loadEdition: function(){
  325. this.layout_edition = this.contentNode.getElement(".doc_layout_edition");
  326. if (this.layout_edition) this.layout_edition.setStyles(this.css.doc_layout_edition);
  327. var node = this.contentNode.getElement(".doc_layout_edition_copyto");
  328. if (node) node.setStyles(this.css.doc_layout_edition_copyto);
  329. node = this.contentNode.getElement(".doc_layout_edition_copyto_table");
  330. if (node) node.setStyles(this.css.doc_layout_edition_copyto_table);
  331. this.layout_copytoTitle = this.contentNode.getElement(".doc_layout_edition_copyto_title");
  332. if (this.layout_copytoTitle) this.layout_copytoTitle.setStyles(this.css.doc_layout_edition_copyto_title);
  333. this.layout_copytoContent = this.contentNode.getElement(".doc_layout_edition_copyto_content");
  334. if (this.layout_copytoContent) this.layout_copytoContent.setStyles(this.css.doc_layout_edition_copyto_content);
  335. var issuance = this.contentNode.getElement(".doc_layout_edition_issuance");
  336. if (issuance) issuance.setStyles(this.css.doc_layout_edition_issuance);
  337. var issuance_table = this.contentNode.getElement(".doc_layout_edition_issuance_table");
  338. if (issuance_table) issuance_table.setStyles(this.css.doc_layout_edition_issuance_table);
  339. this.layout_edition_issuance_unit = this.contentNode.getElement(".doc_layout_edition_issuance_unit");
  340. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.setStyles(this.css.doc_layout_edition_issuance_unit);
  341. this.layout_edition_issuance_date = this.contentNode.getElement(".doc_layout_edition_issuance_date");
  342. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.setStyles(this.css.doc_layout_edition_issuance_date);
  343. },
  344. _loadPageLayout: function(){
  345. this._loadCopiesSecretPriority();
  346. this._loadRedHeader();
  347. if (this.json.fileup){
  348. this._loadFileNoUp();
  349. }else{
  350. this._loadFileNo();
  351. }
  352. this._loadRedLine();
  353. this._loadSubject();
  354. this._loadMainSend();
  355. this._loadFiletext();
  356. this._loadAttachment();
  357. this._loadIssuance();
  358. this._loadAnnotation();
  359. this._loadEdition();
  360. // 份数: this.layout_copies
  361. // 密级: this.layout_secret
  362. // 紧急程度: this.layout_priority
  363. // 红头: this.layout_redHeader
  364. // 上行文编号签发: this.layout_fileNoUpTable
  365. // 文号: this.layout_fileno
  366. // 签发: this.layout_signerTitle
  367. // 签发人: this.layout_signer
  368. // 文号: this.layout_fileno
  369. // 红线: this.layout_redLine
  370. // 标题: this.layout_subject
  371. // 主送单位: this.layout_mainSend
  372. // 正文: this.layout_filetexts
  373. // 附件: this.layout_attachmentTitle
  374. // 附件: this.layout_attachment
  375. // 单位: this.layout_issuanceUnit
  376. // 签发时间: this.layout_issuanceDate
  377. // 附注: this.layout_annotation
  378. // 抄送: this.layout_copytoTitle
  379. // 抄送: this.layout_copytoContent
  380. // 版记单位 this.layout_edition_issuance_unit
  381. // 版记日期 this.layout_edition_issuance_date
  382. },
  383. _loadUserInterface: function(){
  384. this.node.empty();
  385. this.node.setStyles(this.form.css.documentEditorNode);
  386. this.pages = [];
  387. this.allowEdit = this._isAllowEdit();
  388. this.toolNode = new Element("div", {"styles": this.css.doc_toolbar}).inject(this.node);
  389. this.contentNode = new Element("div", {"styles": this.css.doc_content}).inject(this.node);
  390. //this.contentNode.addEvent("resize", this._checkScale.bind(this));
  391. this._loadToolbars();
  392. this._loadFiletextPage();
  393. if (this.options.pageShow==="single"){
  394. this._singlePage();
  395. }else{
  396. this._doublePage();
  397. }
  398. //this._checkScale();
  399. //var pages = this.contentNode.getElements(".doc_layout_page");
  400. this.form.addEvent("afterSave", function(){
  401. this.resetData();
  402. }.bind(this));
  403. },
  404. _returnScale: function(){
  405. this.isScale = false;
  406. this.scale = 0;
  407. this.contentNode.setStyles({
  408. "transform":"scale(1)",
  409. });
  410. if (this.pages.length){
  411. this.pages.each(function(page){
  412. page.setStyles({
  413. "transform":"scale(1)",
  414. });
  415. });
  416. }
  417. this.node.setStyles({
  418. "height": "auto"
  419. });
  420. },
  421. _checkScale: function(offset){
  422. debugger;
  423. offset = 0;
  424. if (this.pages.length){
  425. var pageSize = this.pages[0].getSize();
  426. var contentSize = this.node.getSize();
  427. var contentWidth = (offset) ? contentSize.x-20-offset : contentSize.x-20;
  428. if (contentWidth<pageSize.x){
  429. this.isScale = true;
  430. var scale = (contentWidth)/pageSize.x;
  431. this.scale = scale;
  432. var h = this.node.getSize().y;
  433. h = h - contentSize.y*(1-scale);
  434. this.node.setStyles({
  435. "height":""+h+"px"
  436. });
  437. this.contentNode.setStyles({
  438. "transform":"scale(1, "+scale+")",
  439. "transform-origin": "0px 0px",
  440. "overflow": "visible"
  441. });
  442. this._singlePage();
  443. this.pages.each(function(page){
  444. page.setStyles({
  445. "transform":"scale("+scale+", 1)",
  446. "transform-origin": "0px 0px",
  447. "overflow": "visible",
  448. "margin-left": "10px"
  449. });
  450. });
  451. if (this.doublePageAction) this.doublePageAction.hide();
  452. }
  453. }
  454. },
  455. _switchReadOrEdit: function(){
  456. if (this.eiitMode){
  457. this._readFiletext();
  458. this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  459. this.eiitMode = false;
  460. }else{
  461. this._editFiletext();
  462. this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted)
  463. this.eiitMode = true;
  464. }
  465. },
  466. _readFiletext: function(){
  467. this._returnScale();
  468. if (this.filetextEditor) this.filetextEditor.destroy();
  469. this.layout_filetext.setAttribute('contenteditable', false);
  470. this.data = this.getData();
  471. this._checkSplitPage(this.pages[0]);
  472. this._repage();
  473. },
  474. _editFiletext: function(){
  475. this._returnScale();
  476. this.pages = [];
  477. this.contentNode.empty();
  478. this._createPage();
  479. this._loadPageLayout();
  480. // var docData = this._getBusinessData();
  481. // if (!docData) docData = this._getDefaultData();
  482. this.setData(this.data);
  483. this._checkScale();
  484. this.node.setStyles({
  485. "height":"auto"
  486. });
  487. this._createEditor();
  488. },
  489. _createEditor: function(){
  490. if (this.allowEdit){
  491. this.loadCkeditorFiletext(function(e){
  492. e.editor.focus();
  493. e.editor.getSelection().scrollIntoView();
  494. }.bind(this));
  495. }
  496. },
  497. _isAllowEdit:function(){
  498. if (this.readonly) return false;
  499. if (this.json.allowEdit=="n") return false;
  500. if (this.json.allowEdit=="s"){
  501. if (this.josn.allowEditScript && this.josn.allowEditScript.code){
  502. return !!this.form.Macro.exec(this.josn.allowEditScript.code, this);
  503. }
  504. }
  505. return true;
  506. },
  507. _getEdit: function(name, typeItem, scriptItem){
  508. switch (this.json[typeItem]) {
  509. case "y":
  510. return true;
  511. case "n":
  512. return false;
  513. case "s":
  514. if (this.json[scriptItem] && this.json[scriptItem].code){
  515. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  516. }
  517. return true;
  518. }
  519. },
  520. loadCkeditorStyle: function(node){
  521. if (node){
  522. o2.load("ckeditor", function(){
  523. //CKEDITOR.disableAutoInline = true;
  524. node.setAttribute('contenteditable', true);
  525. var editor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  526. this.filetextEditor.on("instanceReady", function(e){
  527. if (callback) callback(e);
  528. }.bind(this));
  529. }.bind(this));
  530. }
  531. },
  532. _loadToolbars: function(){
  533. var html ="";
  534. if (this.allowEdit){
  535. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"/x_component_process_Xform/$Form/default/icon/editdoc.png\" title=\""+MWF.xApplication.process.Xform.LP.editdoc+"\" MWFButtonAction=\"_switchReadOrEdit\" MWFButtonText=\""+MWF.xApplication.process.Xform.LP.editdoc+"\"></span>";
  536. //html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"/x_component_process_Xform/$Form/default/icon/headerdoc.png\" title=\""+MWF.xApplication.process.Xform.LP.headerdoc+"\" MWFButtonAction=\"_redheaderDoc\" MWFButtonText=\""+MWF.xApplication.process.Xform.LP.headerdoc+"\"></span>";
  537. }
  538. this.toolNode.set("html", html);
  539. MWF.require("MWF.widget.Toolbar", function() {
  540. this.toolbar = new MWF.widget.Toolbar(this.toolNode, {"style": "documentEdit"}, this);
  541. this.toolbar.load();
  542. }.bind(this));
  543. this.doublePageAction = new Element("div", {"styles": this.css.doc_toolbar_doublePage, "text": MWF.xApplication.process.Xform.LP.doublePage}).inject(this.toolNode);
  544. this.doublePageAction.addEvent("click", function(){
  545. if (this.options.pageShow==="single"){
  546. this._doublePage();
  547. }else{
  548. this._singlePage();
  549. }
  550. }.bind(this));
  551. },
  552. _repage: function(delay){
  553. if (this.options.pageShow==="single"){
  554. this._singlePage();
  555. }else{
  556. this._doublePage();
  557. }
  558. if (delay){
  559. if (!this.form.isLoaded){
  560. this.form.addEvent("afterLoad", this._checkScale.bind(this));
  561. }else{
  562. this._checkScale();
  563. }
  564. }else{
  565. this._checkScale();
  566. }
  567. },
  568. _singlePage: function(){
  569. var w = this.contentNode.getSize().x;
  570. var count = 1;
  571. var pageWidth = count * this.options.docPageFullWidth;
  572. var margin = (w-pageWidth)/(count+1);
  573. if (this.isScale){
  574. margin = "10"
  575. }
  576. this.pages.each(function(page, i){
  577. page.setStyles({
  578. "float": "left",
  579. "margin-left": ""+margin+"px"
  580. });
  581. });
  582. // this.pages.each(function(page){
  583. // page.setStyle("float", "none");
  584. // });
  585. this.options.pageShow="single";
  586. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
  587. },
  588. _doublePage: function(){
  589. var w = this.contentNode.getSize().x;
  590. var count = (w/this.options.docPageFullWidth).toInt();
  591. var pages = this.contentNode.getElements(".doc_layout_page");
  592. count = Math.min(pages.length, count);
  593. var pageWidth = count * this.options.docPageFullWidth;
  594. var margin = (w-pageWidth)/(count+1);
  595. this.pages.each(function(page, i){
  596. page.setStyles({
  597. "float": "left",
  598. "margin-left": ""+margin+"px"
  599. });
  600. });
  601. // this.pages.each(function(page, i){
  602. // if ((i % 2)===0){
  603. // page.setStyle("float", "left");
  604. // }else{
  605. // page.setStyle("float", "right");
  606. // }
  607. // });
  608. this.options.pageShow="double";
  609. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
  610. },
  611. _getDefaultData: function(){
  612. return this.json.defaultValue;
  613. //return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
  614. },
  615. _loadFiletextPage: function(){
  616. this.data = this._getBusinessData();
  617. if (!this.data) this.data = this._getDefaultData();
  618. this._computeData(true);
  619. this._createPage();
  620. this._loadPageLayout();
  621. // this.data = this._getBusinessData();
  622. // if (!this.data) this.data = this._getDefaultData();
  623. this.setData(this.data);
  624. this._checkSplitPage(this.pages[0]);
  625. this._repage(true);
  626. //this.loadCkeditorFiletext();
  627. if (!this.readonly){
  628. //if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
  629. // if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
  630. // if (this.json.allowEditSubject) this.loadCkeditorSubject();
  631. // if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
  632. // if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
  633. // if (this.json.allowEditSigner) this.loadCkeditorSigner();
  634. // if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
  635. }
  636. },
  637. _getEditorConfig: function(){
  638. var editorConfig = {};
  639. editorConfig.toolbarGroups = [
  640. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  641. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  642. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  643. { name: 'forms', groups: [ 'forms' ] },
  644. //{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  645. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  646. { name: 'links', groups: [ 'links' ] },
  647. "/",
  648. { name: 'insert', groups: [ 'insert' ] },
  649. { name: 'styles', groups: [ 'styles' ] },
  650. { name: 'colors', groups: [ 'colors' ] },
  651. { name: 'tools', groups: [ 'tools' ] },
  652. { name: 'others', groups: [ 'others' ] },
  653. { name: 'about', groups: [ 'about' ] }
  654. ];
  655. editorConfig.removeButtons = 'NewPage,Templates,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Bold,Italic,Underline,Strike,Subscript,Superscript,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Link,Unlink,Anchor,Image,Flash,HorizontalRule,Smiley,SpecialChar,Iframe,Styles,Font,FontSize,TextColor,BGColor,ShowBlocks,About';
  656. editorConfig.enterMode = 3;
  657. editorConfig.extraPlugins = ['ecnet','mathjax'];
  658. editorConfig.removePlugins = ['magicline'];
  659. editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
  660. return editorConfig;
  661. },
  662. _checkSplitPage: function(pageNode){
  663. if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
  664. var contentNode = pageNode.getFirst();
  665. if (contentNode.getSize().y>this.options.docPageHeight){
  666. this._splitPage(pageNode);
  667. }
  668. var i = pageNode.get("data-pagecount").toInt();
  669. if (i && this.pages.length-1>=i){
  670. this._checkSplitPage(this.pages[i]);
  671. }
  672. if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
  673. },
  674. _splitFiletextNodeOneWord:function(lnode, nextPageNode){
  675. var text = lnode.textContent;
  676. var len = text.length;
  677. var left = text.substring(0, len-1);
  678. var right = text.substring(len-1, len);
  679. lnode.textContent = left;
  680. nextPageNode.textContent = right+nextPageNode.textContent;
  681. //nextPageNode.appendText(right, "top");
  682. },
  683. _splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
  684. var contentNode = pageNode.getFirst();
  685. var lnode = node.lastChild;
  686. if (!lnode){
  687. if (node.parentNode) node.parentNode.removeChild(node);
  688. //node.remove();
  689. }else{
  690. while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
  691. var tmpnode = lnode.previousSibling;
  692. var nodeType = lnode.nodeType;
  693. if (!nextPageNode) nextPageNode = nextFiletextNode;
  694. if (nodeType == Node.ELEMENT_NODE) {
  695. if (lnode.tagName == "table") {
  696. lnode.inject(nextPageNode);
  697. } else if (lnode.tagName == "BR") {
  698. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  699. } else {
  700. var id = lnode.get("data-pagePart");
  701. if (!id){
  702. id = (new o2.widget.UUID()).toString();
  703. lnode.set("data-pagePart", id);
  704. }
  705. var tmpNode = nextPageNode.getFirst();
  706. if (tmpNode && tmpNode.get("data-pagePart")==id){
  707. nextPageNode = tmpNode;
  708. }else{
  709. nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
  710. }
  711. //var subnode = lnode.getLast();
  712. this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
  713. if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  714. nextPageNode = nextPageNode.getParent();
  715. }
  716. } else if (nodeType == Node.TEXT_NODE) {
  717. var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
  718. while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
  719. //console.log(contentNode.getSize().y);
  720. this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
  721. }
  722. if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
  723. } else {
  724. //lnode.remove();
  725. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  726. }
  727. lnode = tmpnode;
  728. }
  729. if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
  730. }
  731. //this._checkSplitPage(pageNode);
  732. },
  733. _splitPage: function(pageNode){
  734. var contentNode = pageNode.getFirst();
  735. var blockNodes = pageNode.getElements(".doc_block");
  736. if (blockNodes.length){
  737. var blockNode = blockNodes[blockNodes.length-1];
  738. var idx = this.pages.indexOf(pageNode);
  739. if (this.pages.length<=idx+1) this._createNewPage();
  740. var nextPage = this.pages[idx+1];
  741. if (blockNode.hasClass("doc_layout_filetext")){
  742. var filetextNode = nextPage.getElement(".doc_layout_filetext");
  743. if (!filetextNode){
  744. filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
  745. //filetextNode.setAttribute('contenteditable', true);
  746. }
  747. if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
  748. //var nextEditor = filetextNode.retrieve("editor");
  749. var node = blockNode;
  750. var nextPageNode = filetextNode;
  751. this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
  752. }else{
  753. blockNode.inject(nextPage.getFirst(), "top");
  754. //var contentNode = pageNode.getFirst();
  755. if (contentNode.getSize().y>this.options.docPageHeight){
  756. this._splitPage(pageNode);
  757. }
  758. }
  759. }
  760. },
  761. loadCkeditorFiletext: function(callback){
  762. if (this.layout_filetext){
  763. o2.load("ckeditor", function(){
  764. CKEDITOR.disableAutoInline = true;
  765. this.layout_filetext.setAttribute('contenteditable', true);
  766. this.filetextEditor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  767. this.filetextEditor.on("instanceReady", function(e){
  768. if (callback) callback(e);
  769. }.bind(this));
  770. }.bind(this));
  771. }
  772. },
  773. _loadEvents: function(editorConfig){
  774. Object.each(this.json.events, function(e, key){
  775. if (e.code){
  776. this.editor.on(key, function(event){
  777. return this.form.Macro.fire(e.code, this, event);
  778. }.bind(this), this);
  779. }
  780. }.bind(this));
  781. },
  782. _bindFieldChange: function(name,dataItem, dom){
  783. debugger;
  784. var field = this.form.all[this.json[dataItem]];
  785. if (field){
  786. field.addModuleEvent("change", function(){
  787. debugger;
  788. this._computeItemFieldData(name, dataItem);
  789. if (this.data[name]){
  790. if (this[dom]){
  791. if (dom=="layout_redHeader"){
  792. this[dom].set("html", this.data[name]|| "");
  793. }else{
  794. this[dom].set("text", this.data[name]|| "");
  795. }
  796. }
  797. }
  798. }.bind(this));
  799. }
  800. },
  801. _computeItemFieldData: function(name, dataItem){
  802. var v = this.form.businessData.data[this.json[dataItem]];
  803. if (v){
  804. var t = o2.typeOf(v);
  805. switch (t) {
  806. case "string":
  807. switch (name) {
  808. case "issuanceDate":
  809. case "editionDate":
  810. var d = Date.parse(v);
  811. this.data[name] = (d.isValid()) ? d.format("“%Y年%m月%d%日") : v;
  812. break;
  813. case "mainSend":
  814. this.data[name] = v + ":";
  815. break;
  816. default:
  817. this.data[name] = v;
  818. }
  819. break;
  820. case "array":
  821. var strs = [];
  822. v.each(function(value){
  823. if (o2.typeOf(value)=="object" && value.distinguishedName){
  824. strs.push(value.name);
  825. }else{
  826. strs.push(value.toString());
  827. }
  828. });
  829. if (strs.length){
  830. switch (name) {
  831. case "attachment":
  832. this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>");
  833. break;
  834. case "issuanceDate":
  835. case "editionDate":
  836. var tmpStrs = strs.map(function(n, i){
  837. var d = Date.parse(n);
  838. return (d.isValid()) ? d.format("“%Y年%m月%d%日") : n;
  839. });
  840. this.data[name] = tmpStrs.join(",")
  841. break;
  842. case "mainSend":
  843. debugger;
  844. this.data[name] = strs.join(",") + ":";
  845. break;
  846. default:
  847. this.data[name] = strs.join(",");
  848. }
  849. }
  850. break;
  851. default:
  852. this.data[name] = v.toString();
  853. }
  854. }
  855. },
  856. _computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
  857. switch (this.json[typeItem]) {
  858. case "data":
  859. if (this.json[dataItem]){
  860. if (ev) this._bindFieldChange(name, dataItem, dom);
  861. this._computeItemFieldData(name, dataItem);
  862. }
  863. break;
  864. case "script":
  865. if (this.json[scriptItem] && this.json[scriptItem].code){
  866. var v = this.form.Macro.exec(this.json[scriptItem].code, this);
  867. this.data[name] = v;
  868. if (name=="attachment") this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>") : v;
  869. if (name=="issuanceDate" || name=="editionDate"){
  870. var d = Date.parse(v);
  871. this.data[name] = (d.isValid()) ? d.format("“%Y年%m月%d%日") : v;
  872. }
  873. }
  874. break;
  875. }
  876. },
  877. _computeData: function(ev){
  878. this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
  879. this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
  880. this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
  881. this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
  882. this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
  883. this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
  884. this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
  885. this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
  886. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
  887. this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
  888. this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
  889. this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
  890. this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
  891. this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
  892. this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
  893. debugger;
  894. },
  895. _loadValue: function(){
  896. var data = this._getBusinessData();
  897. },
  898. resetData: function(){
  899. this._computeData();
  900. this.pages = [];
  901. this.contentNode.empty();
  902. this._createPage();
  903. this._loadPageLayout();
  904. this.setData(this.data);
  905. this._checkSplitPage(this.pages[0]);
  906. this._repage();
  907. },
  908. getData: function(){
  909. if (this.eiitMode){
  910. if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
  911. if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
  912. if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
  913. if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
  914. if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
  915. if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
  916. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  917. if (this.layout_subject) this.data.subject = this.layout_subject.get("text");
  918. if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
  919. if (this.layout_filetext) this.data.filetext = this.layout_filetext.get("html");
  920. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  921. if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
  922. if (this.layout_attachment) this.data.attachment = this.layout_attachment.get("html");
  923. if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("text");
  924. if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
  925. if (this.layout_annotation) this.data.annotation = this.layout_annotation.get("text");
  926. if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
  927. if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
  928. if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
  929. if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
  930. }
  931. return this.data;
  932. },
  933. setData: function(data){
  934. if (data){
  935. this.data = data;
  936. this._setBusinessData(data);
  937. if (this.layout_copies) this.layout_copies.set("text", data.copies || " ");
  938. if (this.layout_secret) this.layout_secret.set("text", data.secret || " ");
  939. if (this.layout_priority) this.layout_priority.set("text", data.priority || " ");
  940. if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
  941. if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
  942. if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
  943. if (this.layout_signer) this.layout_signer.set("text", data.signer || " ");
  944. if (this.layout_subject) this.layout_subject.set("text", data.subject || " ");
  945. if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
  946. if (this.layout_filetext) this.layout_filetext.set("html", data.filetext || "");
  947. if (this.layout_signer) this.layout_signer.set("text", data.signer || "");
  948. if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
  949. if (this.layout_attachment) this.layout_attachment.set("html", data.attachment || " ");
  950. if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("text", data.issuanceUnit || " ");
  951. if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
  952. if (this.layout_annotation) this.layout_annotation.set("text", data.annotation || " ");
  953. if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
  954. if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
  955. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
  956. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
  957. }
  958. },
  959. createErrorNode: function(text){
  960. var node = new Element("div");
  961. var iconNode = new Element("div", {
  962. "styles": {
  963. "width": "20px",
  964. "height": "20px",
  965. "float": "left",
  966. "background": "url("+"/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  967. }
  968. }).inject(node);
  969. var textNode = new Element("div", {
  970. "styles": {
  971. "line-height": "20px",
  972. "margin-left": "20px",
  973. "color": "red",
  974. "word-break": "keep-all"
  975. },
  976. "text": text
  977. }).inject(node);
  978. return node;
  979. },
  980. notValidationMode: function(text){
  981. if (!this.isNotValidationMode){
  982. this.isNotValidationMode = true;
  983. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  984. this.node.setStyle("border", "1px solid red");
  985. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  986. this.showNotValidationMode(this.node);
  987. }
  988. },
  989. showNotValidationMode: function(node){
  990. var p = node.getParent("div");
  991. if (p){
  992. if (p.get("MWFtype") == "tab$Content"){
  993. if (p.getParent("div").getStyle("display")=="none"){
  994. var contentAreaNode = p.getParent("div").getParent("div");
  995. var tabAreaNode = contentAreaNode.getPrevious("div");
  996. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  997. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  998. tabNode.click();
  999. p = tabAreaNode.getParent("div");
  1000. }
  1001. }
  1002. this.showNotValidationMode(p);
  1003. }
  1004. },
  1005. validationMode: function(){
  1006. if (this.isNotValidationMode){
  1007. this.isNotValidationMode = false;
  1008. this.node.setStyles(this.node.retrieve("borderStyle"));
  1009. if (this.errNode){
  1010. this.errNode.destroy();
  1011. this.errNode = null;
  1012. }
  1013. }
  1014. },
  1015. validationConfigItem: function(routeName, data){
  1016. var flag = (data.status=="all") ? true: (routeName == data.decision);
  1017. if (flag){
  1018. var n = this.getData();
  1019. var v = (data.valueType=="value") ? n : n.length;
  1020. switch (data.operateor){
  1021. case "isnull":
  1022. if (!v){
  1023. this.notValidationMode(data.prompt);
  1024. return false;
  1025. }
  1026. break;
  1027. case "notnull":
  1028. if (v){
  1029. this.notValidationMode(data.prompt);
  1030. return false;
  1031. }
  1032. break;
  1033. case "gt":
  1034. if (v>data.value){
  1035. this.notValidationMode(data.prompt);
  1036. return false;
  1037. }
  1038. break;
  1039. case "lt":
  1040. if (v<data.value){
  1041. this.notValidationMode(data.prompt);
  1042. return false;
  1043. }
  1044. break;
  1045. case "equal":
  1046. if (v==data.value){
  1047. this.notValidationMode(data.prompt);
  1048. return false;
  1049. }
  1050. break;
  1051. case "neq":
  1052. if (v!=data.value){
  1053. this.notValidationMode(data.prompt);
  1054. return false;
  1055. }
  1056. break;
  1057. case "contain":
  1058. if (v.indexOf(data.value)!=-1){
  1059. this.notValidationMode(data.prompt);
  1060. return false;
  1061. }
  1062. break;
  1063. case "notcontain":
  1064. if (v.indexOf(data.value)==-1){
  1065. this.notValidationMode(data.prompt);
  1066. return false;
  1067. }
  1068. break;
  1069. }
  1070. }
  1071. return true;
  1072. },
  1073. validationConfig: function(routeName, opinion){
  1074. if (this.json.validationConfig){
  1075. if (this.json.validationConfig.length){
  1076. for (var i=0; i<this.json.validationConfig.length; i++) {
  1077. var data = this.json.validationConfig[i];
  1078. if (!this.validationConfigItem(routeName, data)) return false;
  1079. }
  1080. }
  1081. return true;
  1082. }
  1083. return true;
  1084. },
  1085. validation: function(routeName, opinion){
  1086. if (!this.validationConfig(routeName, opinion)) return false;
  1087. if (!this.json.validation) return true;
  1088. if (!this.json.validation.code) return true;
  1089. var flag = this.form.Macro.exec(this.json.validation.code, this);
  1090. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  1091. if (flag.toString()!="true"){
  1092. this.notValidationMode(flag);
  1093. return false;
  1094. }
  1095. return true;
  1096. }
  1097. });