Documenteditor.js 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810
  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", "queryLoad", "beforeLoad", "postLoad", "afterLoad"],
  6. "docPageHeight": 850.4,
  7. "docPageFullWidth": 794,
  8. "pageShow": "single"
  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. this._loadModuleEvents();
  42. if (this.fireEvent("queryLoad")){
  43. this.fireEvent("beforeLoad");
  44. this.cssPath = this.form.path+this.form.options.style+"/doc.wcss";
  45. this._loadCss();
  46. this._queryLoaded();
  47. this._loadUserInterface(function(){
  48. this.fireEvent("postLoad");
  49. this.fireEvent("afterLoad");
  50. this.fireEvent("load");
  51. }.bind(this));
  52. this._loadStyles();
  53. this._afterLoaded();
  54. }
  55. },
  56. _createNewPage: function(){
  57. var pageNode = new Element("div.doc_layout_page", {"styles": this.css.doc_page}).inject(this.contentNode);
  58. var pageContentNode = new Element("div.doc_layout_page_content", {"styles": this.css.doc_layout_page_content}).inject(pageNode);
  59. pageNode.set("data-pagecount", this.pages.length+1);
  60. this.pages.push(pageNode);
  61. return pageNode;
  62. },
  63. _getShow: function(name, typeItem, scriptItem){
  64. switch (this.json[typeItem]) {
  65. case "y":
  66. return true;
  67. case "n":
  68. return false;
  69. case "a":
  70. if (["copies", "secret", "priority", "attachment", "annotation", "copyto"].indexOf(name!=-1)){
  71. return !!this.data[name] && (!!this.data[name].length);
  72. }
  73. return true;
  74. case "s":
  75. if (this.json[scriptItem] && this.json[scriptItem].code){
  76. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  77. }
  78. return true;
  79. }
  80. },
  81. _createPage: function(callback){
  82. debugger;
  83. var pageContentNode = this._createNewPage().getFirst();
  84. // var html = '<div class="doc_block doc_layout_copiesSecretPriority">';
  85. // if (this._getShow("copies", "copiesShow", "copiesShowScript")) html += ' <div class="doc_layout_copies"></div>';
  86. // if (this._getShow("secret", "secretShow", "secretShowScript")) html += ' <div class="doc_layout_secret"></div>';
  87. // if (this._getShow("priority", "priorityShow", "priorityShowScript")) html += ' <div class="doc_layout_priority"></div>';
  88. // html += '</div>'
  89. // if (this._getShow("redHeader", "redHeaderShow", "redHeaderShowScript")) html += '<div class="doc_block doc_layout_redHeader"></div>';
  90. //
  91. // if (this._getShow("signer", "signerShow", "signerShowScript")){
  92. // this.json.fileup = true;
  93. // html += '<table class="doc_block doc_layout_filenoup" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  94. // '<tr><td class="doc_layout_filenoup_fileno_td">';
  95. // if (this._getShow("fileno", "filenoShow", "filenoShowScript")) html += ' <span> </span><span class="doc_layout_filenoup_fileno"></span>';
  96. //
  97. // html += ' </td><td class="doc_layout_filenoup_signer_td">' +
  98. // ' <table class="doc_layout_filenoup_signer_table" cellpadding="0" cellspacing="0" border="0">' +
  99. // ' <tr><td class="doc_layout_filenoup_signerTitle_td">'+
  100. // ' <span class="doc_layout_filenoup_signer"></span>' +
  101. // ' </td><td class="doc_layout_filenoup_signerContent_td">' +
  102. // ' <span class="doc_layout_filenoup_signerContent"></span><span> </span>' +
  103. // ' </td></tr>' +
  104. // ' </table>' +
  105. // ' </td></tr>' +
  106. // '</table>';
  107. // }else{
  108. // if (this._getShow("fileno", "filenoShow", "filenoShowScript")) html += '<div class=\"doc_block doc_layout_fileno\"></div>';
  109. // }
  110. // html += "<div color=\"#ff0000\" class=\"doc_block doc_layout_redline\"></div>";
  111. // if (this._getShow("subject", "subjectShow", "subjectShowScript")) html += "<div class=\"doc_block doc_layout_subject\"></div>";
  112. // if (this._getShow("mainSend", "mainSendShow", "mainSendShowScript")) html += "<div class=\"doc_block doc_layout_mainSend\"></div>";
  113. // html += "<div class=\"doc_block doc_layout_filetext\"></div>";
  114. //
  115. // if (this._getShow("attachment", "attachmentShow", "attachmentShowScript")){
  116. // html += '<table class="doc_block doc_layout_attachment" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  117. // ' <tr><td class="doc_layout_attachment_title_td">' +
  118. // ' <span>  </span><span class="doc_layout_attachment_title"></span>' +
  119. // ' </td><td class="doc_layout_attachment_content_td">' +
  120. // ' <span class="doc_layout_attachment_content"></span>' +
  121. // ' </td></tr>' +
  122. // '</table>';
  123. // };
  124. //
  125. // // html += '<table class="doc_block doc_layout_issuance" cellpadding="0" cellspacing="0" border="0">' +
  126. // // ' <tr><td class="doc_layout_issuanceUnit"></td></tr>' +
  127. // // ' <tr><td class="doc_layout_issuanceDate"></td></tr>' +
  128. // // '</table>'doc_layout_edition_read
  129. //
  130. // var showIssuanceUnit = this._getShow("issuanceUnit", "issuanceUnitShow", "issuanceUnitShowScript");
  131. // var showIssuanceDate = this._getShow("issuanceDate", "issuanceDateShow", "issuanceDateShowScript");
  132. // if (showIssuanceUnit || showIssuanceDate){
  133. // html += '<div class="doc_block" style="overflow: hidden;"><table class="doc_layout_issuance" cellpadding="0" cellspacing="0" border="0">';
  134. // if (showIssuanceUnit) html += ' <tr><td class="doc_layout_issuanceUnit"></td></tr>';
  135. // if (showIssuanceDate) html += ' <tr><td class="doc_layout_issuanceDate"></td></tr>';
  136. // html += '</table></div>';
  137. // }
  138. // if (this._getShow("annotation", "annotationShow", "annotationShowScript")) html += '<div class="doc_block doc_layout_annotation"></div>';
  139. //
  140. // html += '<table class="doc_block doc_layout_edition" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  141. // ' <tr><td class="doc_layout_edition_copyto">';
  142. //
  143. // if (this._getShow("copyto", "copytoShow", "copytoShowScript")){
  144. // html += ' <table class="doc_layout_edition_copyto_table" align="center" cellpadding="0" cellspacing="0" border="0">' +
  145. // ' <tr>' +
  146. // ' <td class="doc_layout_edition_copyto_title"></td>' +
  147. // ' <td class="doc_layout_edition_copyto_content"></td>' +
  148. // ' </tr>' +
  149. // ' </table>';
  150. // }
  151. //
  152. //
  153. // html += ' </td></tr><tr><td class="doc_layout_edition_issuance">'+
  154. // ' <table class="doc_layout_edition_issuance_table" align="center" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  155. // ' <tr>';
  156. //
  157. // if (this._getShow("editionUnit", "editionUnitShow", "editionUnitShowScript")) html += '<td class="doc_layout_edition_issuance_unit"></td>';
  158. // if (this._getShow("editionDate", "editionDateShow", "editionDateShowScript")) html += '<td class="doc_layout_edition_issuance_date"></td>';
  159. //
  160. // html += ' </tr>' +
  161. // ' </table>' +
  162. // '</td></tr>' +
  163. // '</table>';
  164. //@todo
  165. // '<table class="doc_block doc_layout_filenoup" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  166. // ' <tr><td class="doc_layout_filenoup_fileno_td">' +
  167. // ' <span> </span><span class="doc_layout_filenoup_fileno">浙移发〔2019〕20号</span>' +
  168. // ' </td><td class="doc_layout_filenoup_signer_td">' +
  169. // ' <table class="doc_layout_filenoup_signer_table" cellpadding="0" cellspacing="0" border="0">' +
  170. // ' <tr><td class="doc_layout_filenoup_signerTitle_td">' +
  171. // ' <span class="doc_layout_filenoup_signer">签发人:</span>' +
  172. // ' </td><td class="doc_layout_filenoup_signerContent_td">' +
  173. // ' <span class="doc_layout_filenoup_signerContent"></span><span> </span>' +
  174. // ' </td></tr>' +
  175. // ' </table>' +
  176. // ' </td></tr>' +
  177. // '</table>'+
  178. //
  179. //
  180. // "<div class=\"doc_block doc_layout_fileno\"></div>" +
  181. // "<div color=\"#ff0000\" class=\"doc_block doc_layout_redline\"></div>" +
  182. // "<div class=\"doc_block doc_layout_subject\"></div>" +
  183. // "<div class=\"doc_block doc_layout_mainSend\">:</div>"+
  184. // "<div class=\"doc_block doc_layout_filetext\"></div>" +
  185. //
  186. // '<table class="doc_block doc_layout_attachment" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  187. // ' <tr><td class="doc_layout_attachment_title_td">' +
  188. // ' <span>  </span><span class="doc_layout_attachment_title"></span>' +
  189. // ' </td><td class="doc_layout_attachment_content_td">' +
  190. // ' <span class="doc_layout_attachment_content"></span>' +
  191. // ' </td></tr>' +
  192. // '</table>' +
  193. // '<table class="doc_block doc_layout_issuance" cellpadding="0" cellspacing="0" border="0">' +
  194. // ' <tr><td class="doc_layout_issuanceUnit"></td></tr>' +
  195. // ' <tr><td class="doc_layout_issuanceDate"></td></tr>' +
  196. // '</table>' +
  197. // '<div class="doc_block doc_layout_annotation"></div>'+
  198. // // pageContentNode.set("html", html);
  199. // //
  200. // // pageContentNode = this._createNewPage().getFirst();
  201. // // html = '' +
  202. // '<table class="doc_block doc_layout_edition" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  203. // ' <tr><td class="doc_layout_edition_copyto">' +
  204. // ' <table class="doc_layout_edition_copyto_table" align="center" cellpadding="0" cellspacing="0" border="0">' +
  205. // ' <tr>' +
  206. // ' <td class="doc_layout_edition_copyto_title"></td>' +
  207. // ' <td class="doc_layout_edition_copyto_content"></td>' +
  208. // ' </tr>' +
  209. // ' </table>' +
  210. // ' </td></tr>' +
  211. // ' <tr><td class="doc_layout_edition_issuance">' +
  212. // ' <table class="doc_layout_edition_issuance_table" align="center" width="100%" cellpadding="0" cellspacing="0" border="0">' +
  213. // ' <tr>' +
  214. // ' <td class="doc_layout_edition_issuance_unit"></td>' +
  215. // ' <td class="doc_layout_edition_issuance_date"></td>' +
  216. // ' </tr>' +
  217. // ' </table>' +
  218. // ' </td></tr>' +
  219. // '</table>';
  220. var control = this.getShowControl();
  221. this.json.fileup = !!(control.signer);
  222. //this.json.documentTempleteType!="cus"
  223. this.getTempleteJson(function(){
  224. var templete = this.json.documentTempleteName || "standard";
  225. pageContentNode.loadHtml("/x_component_process_FormDesigner/Module/Documenteditor/templete/"+this.templeteJson[templete].file, function(){
  226. if (this.attachmentTemplete){
  227. var attNode = pageContentNode.getElement(".doc_layout_attachment_content");
  228. if (attNode) attNode.empty();
  229. }
  230. if (callback) callback(control);
  231. }.bind(this));
  232. }.bind(this));
  233. },
  234. getTempleteJson: function(callback){
  235. if (this.templeteJson){
  236. if (callback) callback();
  237. }else{
  238. o2.getJSON("/x_component_process_FormDesigner/Module/Documenteditor/templete/templete.json", function(json){
  239. this.templeteJson = json;
  240. if (callback) callback();
  241. }.bind(this));
  242. }
  243. },
  244. getShowControl: function(){
  245. var control = {};
  246. control.copies = this._getShow("copies", "copiesShow", "copiesShowScript");
  247. control.secret = this._getShow("secret", "secretShow", "secretShowScript");
  248. control.priority = this._getShow("priority", "priorityShow", "priorityShowScript");
  249. control.redHeader = this._getShow("redHeader", "redHeaderShow", "redHeaderShowScript");
  250. control.signer = this._getShow("signer", "signerShow", "signerShowScript");
  251. control.fileno = this._getShow("fileno", "filenoShow", "filenoShowScript");
  252. control.subject = this._getShow("subject", "subjectShow", "subjectShowScript");
  253. control.mainSend = this._getShow("mainSend", "mainSendShow", "mainSendShowScript");
  254. control.attachment = this._getShow("attachment", "attachmentShow", "attachmentShowScript");
  255. control.issuanceUnit = this._getShow("issuanceUnit", "issuanceUnitShow", "issuanceUnitShowScript");
  256. control.issuanceDate = this._getShow("issuanceDate", "issuanceDateShow", "issuanceDateShowScript");
  257. control.annotation = this._getShow("annotation", "annotationShow", "annotationShowScript");
  258. control.copyto = this._getShow("copyto", "copytoShow", "copytoShowScript");
  259. control.editionUnit = this._getShow("editionUnit", "editionUnitShow", "editionUnitShowScript");
  260. control.editionDate = this._getShow("editionDate", "editionDateShow", "editionDateShowScript");
  261. control.meetingAttend = this._getShow("meetingAttend", "meetingAttendShow", "meetingAttendShowScript");
  262. control.meetingLeave = this._getShow("meetingLeave", "meetingLeaveShow", "meetingLeaveShowScript");
  263. control.meetingSit = this._getShow("meetingSit", "meetingSitShow", "meetingSitShowScript");
  264. return control;
  265. },
  266. // _getEdit: function(name, typeItem, scriptItem){
  267. // switch (this.json[typeItem]) {
  268. // case "y":
  269. // return true;
  270. // case "n":
  271. // return false;
  272. // // case "a":
  273. // // if (["copies", "secret", "priority", "attachment", "annotation", "copyto"].indexOf(name!=-1)){
  274. // // return !!this.data[name] && (!!this.data[name].length);
  275. // // }
  276. // // return true;
  277. // case "s":
  278. // if (this.json[scriptItem] && this.json[scriptItem].code){
  279. // return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  280. // }
  281. // return true;
  282. // }
  283. // },
  284. getEditControl: function(){
  285. var control = {};
  286. control.copies = this._getEdit("copies", "copiesEdit", "copiesEditScript");
  287. control.secret = this._getEdit("secret", "secretEdit", "secretEditScript");
  288. control.priority = this._getEdit("priority", "priorityEdit", "priorityEditScript");
  289. control.redHeader = this._getEdit("redHeader", "redHeaderEdit", "redHeaderEditScript");
  290. control.signer = this._getEdit("signer", "signerEdit", "signerEditScript");
  291. control.fileno = this._getEdit("fileno", "filenoEdit", "filenoEditScript");
  292. control.subject = this._getEdit("subject", "subjectEdit", "subjectEditScript");
  293. control.mainSend = this._getEdit("mainSend", "mainSendEdit", "mainSendEditScript");
  294. control.attachment = this._getEdit("attachment", "attachmentEdit", "attachmentEditScript");
  295. control.issuanceUnit = this._getEdit("issuanceUnit", "issuanceUnitEdit", "issuanceUnitEditScript");
  296. control.issuanceDate = this._getEdit("issuanceDate", "issuanceDateEdit", "issuanceDateEditScript");
  297. control.annotation = this._getEdit("annotation", "annotationEdit", "annotationEditScript");
  298. control.copyto = this._getEdit("copyto", "copytoEdit", "copytoEditScript");
  299. control.editionUnit = this._getEdit("editionUnit", "editionUnitEdit", "editionUnitEditScript");
  300. control.editionDate = this._getEdit("editionDate", "editionDateEdit", "editionDateEditScript");
  301. control.meetingAttend = this._getShow("meetingAttend", "meetingAttendEdit", "meetingAttendEditScript");
  302. control.meetingLeave = this._getShow("meetingLeave", "meetingLeaveEdit", "meetingLeaveEditScript");
  303. control.meetingSit = this._getShow("meetingSit", "meetingSitEdit", "meetingSitEditScript");
  304. return control;
  305. },
  306. //份数 密级 紧急程度
  307. _loadCopiesSecretPriority: function(){
  308. this.layout_copiesSecretPriority = this.contentNode.getElement(".doc_layout_copiesSecretPriority");
  309. if (this.layout_copiesSecretPriority) this.layout_copiesSecretPriority.setStyles(this.css.doc_layout_copiesSecretPriority);
  310. this.layout_copies = this.contentNode.getElement(".doc_layout_copies");
  311. if (this.layout_copies) this.layout_copies.setStyles(this.css.doc_layout_copies);
  312. this.layout_secret = this.contentNode.getElement(".doc_layout_secret");
  313. if (this.layout_secret) this.layout_secret.setStyles(this.css.doc_layout_secret);
  314. this.layout_priority = this.contentNode.getElement(".doc_layout_priority");
  315. if (this.layout_priority) this.layout_priority.setStyles(this.css.doc_layout_priority);
  316. },
  317. //红头
  318. _loadRedHeader: function(){
  319. this.layout_redHeader = this.contentNode.getElement(".doc_layout_redHeader");
  320. if (this.layout_redHeader) this.layout_redHeader.setStyles(this.css.doc_layout_redHeader);
  321. },
  322. //文号签发人(上行文)
  323. _loadFileNoUp: function(){
  324. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  325. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  326. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable.setStyles(this.css.doc_layout_filenoup);
  327. var td = this.contentNode.getElement(".doc_layout_filenoup_fileno_td");
  328. if (td) td.setStyles(this.css.doc_layout_filenoup_fileno_td);
  329. this.layout_fileno = this.contentNode.getElement(".doc_layout_filenoup_fileno");
  330. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_filenoup_fileno);
  331. td = this.contentNode.getElement(".doc_layout_filenoup_signer_td");
  332. if (td) td.setStyles(this.css.doc_layout_filenoup_signer_td);
  333. var node = this.contentNode.getElement(".doc_layout_filenoup_signer_table");
  334. if (node) node.setStyles(this.css.doc_layout_filenoup_signer_table);
  335. node = this.contentNode.getElement(".doc_layout_filenoup_signerTitle_td");
  336. if (node) node.setStyles(this.css.doc_layout_filenoup_signerTitle_td);
  337. this.layout_signerTitle = this.contentNode.getElement(".doc_layout_filenoup_signer");
  338. if (this.layout_signerTitle) this.layout_signerTitle.setStyles(this.css.doc_layout_filenoup_signer);
  339. node = this.contentNode.getElement(".doc_layout_filenoup_signerContent_td");
  340. if (node) node.setStyles(this.css.doc_layout_filenoup_signerContent_td);
  341. this.layout_signer = this.contentNode.getElement(".doc_layout_filenoup_signerContent");
  342. if (this.layout_signer) this.layout_signer.setStyles(this.css.doc_layout_filenoup_signerContent);
  343. },
  344. //文号
  345. _loadFileNo: function(){
  346. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  347. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  348. this.layout_fileno = this.contentNode.getElement(".doc_layout_fileno");
  349. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_fileno);
  350. },
  351. //红线
  352. _loadRedLine: function(){
  353. this.layout_redLine = this.contentNode.getElement(".doc_layout_redline");
  354. if (this.layout_redLine) this.layout_redLine.setStyles(this.css.doc_layout_redline);
  355. },
  356. //标题
  357. _loadSubject:function(){
  358. this.layout_subject = this.contentNode.getElement(".doc_layout_subject");
  359. if (this.layout_subject) this.layout_subject.setStyles(this.css.doc_layout_subject);
  360. },
  361. //主送
  362. _loadMainSend: function(){
  363. this.layout_mainSend = this.contentNode.getElement(".doc_layout_mainSend");
  364. if (this.layout_mainSend) this.layout_mainSend.setStyles(this.css.doc_layout_mainSend);
  365. },
  366. //正文
  367. // _createFiletext: function(filetextNode, node, where){
  368. // if (!filetextNode){
  369. // var filetextNode = new Element("div.doc_layout_filetext").inject(node, where);
  370. // filetextNode.addClass("doc_block");
  371. // filetextNode.setAttribute('contenteditable', true);
  372. // }
  373. // CKEDITOR.disableAutoInline = true;
  374. // var filetextEditor = CKEDITOR.inline(filetextNode, this._getEditorConfig());
  375. // filetextNode.store("editor", filetextEditor);
  376. // if (!this.filetextEditors) this.filetextEditors = [];
  377. // this.filetextEditors.push(filetextEditor);
  378. //
  379. // filetextEditor.on( 'blur', function(e) {
  380. // // var filetextNode = e.editor.container.$;
  381. // // var pageNode = filetextNode.getParent(".doc_layout_page");
  382. // // this._checkSplitPage(pageNode);
  383. // // this._repage();
  384. // }.bind(this));
  385. //
  386. // return filetextNode;
  387. // },
  388. _loadFiletext: function(){
  389. this.layout_filetext = this.contentNode.getElement(".doc_layout_filetext");
  390. this.layout_filetext.setStyles(this.css.doc_layout_filetext);
  391. //this.layout_filetext = this.contentNode.getElement(".doc_layout_filetext");
  392. // if (this.layout_filetexts.length){
  393. // this.layout_filetexts.each(function(layout_filetext){
  394. // layout_filetext.setStyles(this.css.doc_layout_filetext);
  395. // }.bind(this));
  396. // }
  397. },
  398. //附件
  399. _loadAttachment: function(){
  400. this.layout_attachmentTable = this.contentNode.getElement(".doc_layout_attachment");
  401. if (this.layout_attachmentTable) this.layout_attachmentTable.setStyles(this.css.doc_layout_attachment);
  402. var node = this.contentNode.getElement(".doc_layout_attachment_title_td");
  403. if (node) node.setStyles(this.css.doc_layout_attachment_title_td);
  404. this.layout_attachmentTitle = this.contentNode.getElement(".doc_layout_attachment_title");
  405. if (node) node.setStyles(this.css.doc_layout_attachment_title);
  406. node = this.contentNode.getElement(".doc_layout_attachment_content_td");
  407. if (node) node.setStyles(this.css.doc_layout_attachment_content_td);
  408. this.layout_attachment = this.contentNode.getElement(".doc_layout_attachment_content");
  409. if (this.layout_attachment) this.layout_attachment.setStyles(this.css.doc_layout_attachment_content);
  410. },
  411. //发布单位
  412. _loadIssuance: function(){
  413. this.layout_issuanceTable = this.contentNode.getElement(".doc_layout_issuance");
  414. this.layout_issuanceUnit = this.contentNode.getElement(".doc_layout_issuanceUnit");
  415. this.layout_issuanceDate = this.contentNode.getElement(".doc_layout_issuanceDate");
  416. if (this.layout_issuanceTable) this.layout_issuanceTable.setStyles(this.css.doc_layout_issuance);
  417. if (this.layout_issuanceUnit) this.layout_issuanceUnit.setStyles(this.css.doc_layout_issuanceUnit);
  418. if (this.layout_issuanceDate) this.layout_issuanceDate.setStyles(this.css.doc_layout_issuanceDate);
  419. },
  420. //附注
  421. _loadAnnotation: function(){
  422. this.layout_annotation = this.contentNode.getElement(".doc_layout_annotation");
  423. if (this.layout_annotation) this.layout_annotation.setStyles(this.css.doc_layout_annotation);
  424. },
  425. //版记
  426. _loadEdition: function(){
  427. this.layout_editionArea = this.contentNode.getElement(".doc_layout_editionArea");
  428. this.layout_edition = this.contentNode.getElement(".doc_layout_edition");
  429. if (this.layout_edition) this.layout_edition.setStyles(this.css.doc_layout_edition);
  430. var node = this.contentNode.getElement(".doc_layout_edition_copyto");
  431. if (node) node.setStyles(this.css.doc_layout_edition_copyto);
  432. node = this.contentNode.getElement(".doc_layout_edition_copyto_table");
  433. if (node) node.setStyles(this.css.doc_layout_edition_copyto_table);
  434. this.layout_copytoTitle = this.contentNode.getElement(".doc_layout_edition_copyto_title");
  435. if (this.layout_copytoTitle) this.layout_copytoTitle.setStyles(this.css.doc_layout_edition_copyto_title);
  436. this.layout_copytoContent = this.contentNode.getElement(".doc_layout_edition_copyto_content");
  437. if (this.layout_copytoContent) this.layout_copytoContent.setStyles(this.css.doc_layout_edition_copyto_content);
  438. var issuance = this.contentNode.getElement(".doc_layout_edition_issuance");
  439. if (issuance) issuance.setStyles(this.css.doc_layout_edition_issuance);
  440. var issuance_table = this.contentNode.getElement(".doc_layout_edition_issuance_table");
  441. if (issuance_table) issuance_table.setStyles(this.css.doc_layout_edition_issuance_table);
  442. this.layout_edition_issuance_unit = this.contentNode.getElement(".doc_layout_edition_issuance_unit");
  443. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.setStyles(this.css.doc_layout_edition_issuance_unit);
  444. this.layout_edition_issuance_date = this.contentNode.getElement(".doc_layout_edition_issuance_date");
  445. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.setStyles(this.css.doc_layout_edition_issuance_date);
  446. },
  447. _loadMeeting: function(){
  448. this.layout_meetingAttendArea = this.contentNode.getElement(".doc_layout_meeting_attend");
  449. this.layout_meetingAttendTitle = this.contentNode.getElement(".doc_layout_meeting_attend_title");
  450. this.layout_meetingAttendContent = this.contentNode.getElement(".doc_layout_meeting_attend_content");
  451. this.layout_meetingLeaveArea = this.contentNode.getElement(".doc_layout_meeting_leave");
  452. this.layout_meetingLeaveTitle = this.contentNode.getElement(".doc_layout_meeting_leave_title");
  453. this.layout_meetingLeaveContent = this.contentNode.getElement(".doc_layout_meeting_leave_content");
  454. this.layout_meetingSitArea = this.contentNode.getElement(".doc_layout_meeting_sit");
  455. this.layout_meetingSitTitle = this.contentNode.getElement(".doc_layout_meeting_sit_title");
  456. this.layout_meetingSitContent = this.contentNode.getElement(".doc_layout_meeting_sit_content");
  457. },
  458. _loadPageLayout: function(control){
  459. this._loadCopiesSecretPriority();
  460. this._loadRedHeader();
  461. if (this.json.fileup){
  462. this._loadFileNoUp();
  463. }else{
  464. this._loadFileNo();
  465. }
  466. this._loadRedLine();
  467. this._loadSubject();
  468. this._loadMainSend();
  469. this._loadFiletext();
  470. this._loadAttachment();
  471. this._loadIssuance();
  472. this._loadAnnotation();
  473. this._loadEdition();
  474. //会议纪要
  475. this._loadMeeting();
  476. this.reSetShow(control);
  477. this.reSetEdit();
  478. // 份数: this.layout_copies
  479. // 密级: this.layout_secret
  480. // 紧急程度: this.layout_priority
  481. // 红头: this.layout_redHeader
  482. // 上行文编号签发: this.layout_fileNoUpTable
  483. // 文号: this.layout_fileno
  484. // 签发: this.layout_signerTitle
  485. // 签发人: this.layout_signer
  486. // 文号: this.layout_fileno
  487. // 红线: this.layout_redLine
  488. // 标题: this.layout_subject
  489. // 主送单位: this.layout_mainSend
  490. // 正文: this.layout_filetexts
  491. // 附件: this.layout_attachmentTitle
  492. // 附件: this.layout_attachment
  493. // 单位: this.layout_issuanceUnit
  494. // 签发时间: this.layout_issuanceDate
  495. // 附注: this.layout_annotation
  496. // 抄送: this.layout_copytoTitle
  497. // 抄送: this.layout_copytoContent
  498. // 版记单位 this.layout_edition_issuance_unit
  499. // 版记日期 this.layout_edition_issuance_date
  500. },
  501. reSetShow: function(control){
  502. debugger;
  503. if (!control) control = this.getShowControl();
  504. var m = function(s){ return (control[s]) ? "show" : "hide"; }
  505. if (this.layout_copies) this.layout_copies[m("copies")]();
  506. if (this.layout_secret) this.layout_secret[m("secret")]();
  507. if (this.layout_priority) this.layout_priority[m("priority")]();
  508. if (this.layout_redHeader) this.layout_redHeader[m("redHeader")]();
  509. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable[m("signer")]();
  510. if (this.layout_filenoArea) this.layout_filenoArea[(!control.signer) ? "show" : "hide"]();
  511. if (this.layout_fileno) this.layout_fileno[m("fileno")]();
  512. if (this.layout_subject) this.layout_subject[m("subject")]();
  513. if (this.layout_mainSend) this.layout_mainSend[m("mainSend")]();
  514. if (this.layout_attachmentTable) this.layout_attachmentTable[m("attachment")]();
  515. if (this.layout_issuanceUnit) this.layout_issuanceUnit[m("issuanceUnit")]();
  516. if (this.layout_issuanceDate) this.layout_issuanceDate[m("issuanceDate")]();
  517. if (this.layout_annotation) this.layout_annotation[m("annotation")]();
  518. if (!control.copyto && !control.editionUnit && !control.editionDate){
  519. if (this.layout_editionArea) this.layout_editionArea.hide();
  520. }else{
  521. if (this.layout_editionArea) this.layout_editionArea.show();
  522. if (this.layout_copytoTitle) this.layout_copytoTitle[m("copyto")]();
  523. if (this.layout_copytoContent) this.layout_copytoContent[m("copyto")]();
  524. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit[m("editionUnit")]();
  525. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date[m("editionDate")]();
  526. }
  527. if (this.layout_meetingAttendArea) this.layout_meetingAttendArea[m("meetingAttend")]();
  528. if (this.layout_meetingLeaveArea) this.layout_meetingLeaveArea[m("meetingLeave")]();
  529. if (this.layout_meetingSitArea) this.layout_meetingSitArea[m("meetingSit")]();
  530. // this.layout_annotation[m("annotation")]();
  531. // this.layout_annotation[m("annotation")]();
  532. // this.layout_annotation[m("annotation")]();
  533. },
  534. reSetEdit: function(control){
  535. //未进行数据绑定时,可允许编辑
  536. if (!control) var control = this.getEditControl();
  537. if (!!this.json.subjectValueData && this.json.subjectValueType=="data") this.layout_subject.set("contenteditable", control.subject);
  538. // this.layout_subject.addEvent("keydown", function(e){
  539. // debugger;
  540. // if (this.json.subjectValueType=="data" && this.json.subjectValueData){
  541. // // var v = e.target.get("HTML");
  542. // // this.form.businessData.data[this.json.subjectValueData] = v
  543. // var module = this.form.all[this.json.subjectValueData];
  544. // if (module){
  545. // var bindFun = module.node.retrieve(this.json.id+"bindFun");
  546. // module.node
  547. // }
  548. // }
  549. // }.bind(this));
  550. },
  551. _loadUserInterface: function(callback){
  552. this.node.empty();
  553. this.node.setStyles(this.form.css.documentEditorNode);
  554. this.pages = [];
  555. this.allowEdit = this._isAllowEdit();
  556. this.toolNode = new Element("div", {"styles": this.css.doc_toolbar}).inject(this.node);
  557. this.contentNode = new Element("div", {"styles": this.css.doc_content}).inject(this.node);
  558. if (!this.form.isLoaded){
  559. this.form.addEvent("afterModulesLoad", function(){this.loadDocumentEditor(callback);}.bind(this));
  560. }else{
  561. this.loadDocumentEditor(callback);
  562. }
  563. },
  564. loadDocumentEditor: function(callback){
  565. //this.contentNode.addEvent("resize", this._checkScale.bind(this));
  566. this._loadToolbars();
  567. this._loadFiletextPage(function(){
  568. if (this.options.pageShow!=="double"){
  569. this._singlePage();
  570. }else{
  571. this._doublePage();
  572. }
  573. this.form.addEvent("afterSave", function(){
  574. this.resetData();
  575. }.bind(this));
  576. if (this.json.toWord=="y"){
  577. if (this.json.toWordTrigger=="open") this.toWord();
  578. if (this.json.toWordTrigger=="save") this.form.addEvent("beforeSave", this.toWord.bind(this));
  579. if (this.json.toWordTrigger=="submit") this.form.addEvent("beforeProcess", this.toWord.bind(this));
  580. }
  581. if (callback) callback();
  582. }.bind(this));
  583. },
  584. _returnScale: function(){
  585. this.isScale = false;
  586. this.scale = 0;
  587. this.contentNode.setStyles({
  588. "transform":"scale(1)",
  589. });
  590. if (this.pages.length){
  591. this.pages.each(function(page){
  592. page.setStyles({
  593. "transform":"scale(1)",
  594. });
  595. });
  596. }
  597. this.node.setStyles({
  598. "height": "auto"
  599. });
  600. },
  601. _checkScale: function(offset){
  602. debugger;
  603. offset = 0;
  604. if (this.pages.length){
  605. var pageSize = this.pages[0].getSize();
  606. var contentSize = this.node.getSize();
  607. var contentWidth = (offset) ? contentSize.x-20-offset : contentSize.x-20;
  608. if (contentWidth<pageSize.x){
  609. this.isScale = true;
  610. var scale = (contentWidth)/pageSize.x;
  611. this.scale = scale;
  612. var h = this.node.getSize().y;
  613. h = h - contentSize.y*(1-scale);
  614. this.node.setStyles({
  615. "height":""+h+"px"
  616. });
  617. this.contentNode.setStyles({
  618. "transform":"scale(1, "+scale+")",
  619. "transform-origin": "0px 0px",
  620. "overflow": "visible"
  621. });
  622. this._singlePage();
  623. this.pages.each(function(page){
  624. page.setStyles({
  625. "transform":"scale("+scale+", 1)",
  626. "transform-origin": "0px 0px",
  627. "overflow": "visible",
  628. "margin-left": "10px"
  629. });
  630. });
  631. if (this.doublePageAction) this.doublePageAction.hide();
  632. }
  633. }
  634. },
  635. _switchReadOrEdit: function(){
  636. if (this.eiitMode){
  637. this._readFiletext();
  638. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  639. this.eiitMode = false;
  640. }else{
  641. this._editFiletext();
  642. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted)
  643. this.eiitMode = true;
  644. }
  645. },
  646. _switchReadOrEditInline: function(){
  647. if (this.eiitMode){
  648. this._readFiletext();
  649. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  650. this.eiitMode = false;
  651. }else{
  652. this._editFiletext("inline");
  653. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted)
  654. this.eiitMode = true;
  655. }
  656. },
  657. _readFiletext: function(){
  658. this._returnScale();
  659. if (this.filetextEditor) this.filetextEditor.destroy();
  660. if (this.filetextScrollNode){
  661. if (this.reLocationFiletextToolbarFun){
  662. this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  663. //this.form.app.removeEvent("resize", this.reLocationFiletextToolbarFun);
  664. this.reLocationFiletextToolbarFun = null;
  665. }
  666. this.filetextScrollNode = null;
  667. }
  668. if (this.filetextToolbarNode) this.filetextToolbarNode = null;
  669. this.layout_filetext.setAttribute('contenteditable', false);
  670. this.data = this.getData();
  671. //this._checkSplitPage(this.pages[0]);
  672. this._repage();
  673. },
  674. _editFiletext: function(inline){
  675. this._returnScale();
  676. this._singlePage();
  677. this.pages = [];
  678. this.contentNode.empty();
  679. this._createPage(function(control){
  680. this._loadPageLayout(control);
  681. // var docData = this._getBusinessData();
  682. // if (!docData) docData = this._getDefaultData();
  683. this.setData(this.data);
  684. this._checkScale();
  685. this.node.setStyles({
  686. "height":"auto"
  687. });
  688. this._createEditor(inline);
  689. }.bind(this));
  690. },
  691. _createEditor: function(inline){
  692. if (this.allowEdit){
  693. this.loadCkeditorFiletext(function(e){
  694. debugger;
  695. e.editor.focus();
  696. e.editor.getSelection().scrollIntoView();
  697. //this.getFiletextToolber();
  698. //this.filetextToolbarNode.inject(this.layout_filetext.getOffsetParent());
  699. this.locationFiletextToolbar();
  700. }.bind(this), inline);
  701. }
  702. },
  703. getFiletextToolber: function(){
  704. if (this.filetextEditor) {
  705. if (!this.filetextToolbarNode) {
  706. var className = "cke_editor_" + this.filetextEditor.name;
  707. var filetextToolbarNode = $$("." + className)[0];
  708. this.filetextToolbarNode = filetextToolbarNode;
  709. //filetextToolbarNode.destroy();
  710. }
  711. }
  712. },
  713. reLocationFiletextToolbar: function(){
  714. this.getFiletextToolber();
  715. // if (this.filetextToolbarNode){
  716. // this.filetextToolbarNode.setStyle("display", "block");
  717. // var offsetNode = this.layout_filetext.getOffsetParent();
  718. //
  719. // this.filetextToolbarNode.setStyle("left", 0);
  720. // var h = this.filetextToolbarNode.getSize().y;
  721. // var p = this.layout_filetext.getPosition(offsetNode).y-h;
  722. //
  723. // var postion = this.layout_filetext.getPosition(this.form.app.content);
  724. // if (postion.y-h<0){
  725. // this.filetextToolbarNode.inject(this.form.app.content);
  726. // this.filetextToolbarNode.setStyle("top", 0);
  727. // this.filetextToolbarNode.setStyle("left", ""+postion.x+"px");
  728. // }else{
  729. // this.filetextToolbarNode.inject(offsetNode);
  730. // this.filetextToolbarNode.setStyle("top", "" + p + "px");
  731. // this.filetextToolbarNode.setStyle("left", 0);
  732. // this.filetextToolbarNode.setStyle("left", "auto");
  733. // }
  734. // }
  735. if (this.filetextToolbarNode){
  736. if (!this.filetextScrollNode){
  737. var scrollNode = this.contentNode;
  738. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  739. scrollNode = scrollNode.getParent();
  740. }
  741. this.filetextScrollNode = scrollNode;
  742. }
  743. var h = this.filetextToolbarNode.getSize().y;
  744. var position = this.layout_filetext.getPosition(this.form.app.content);
  745. var size = this.layout_filetext.getSize();
  746. var contentSize = this.filetextScrollNode.getSize();
  747. if (position.y<0 && size.y+position.y+h<contentSize.y){
  748. var top = size.y+position.y;
  749. this.filetextToolbarNode.setStyle("top", ""+top+"px");
  750. }else if (position.y-h<0){
  751. this.filetextToolbarNode.setStyle("top", 0);
  752. }else{
  753. var p = this.layout_filetext.getPosition().y-h;
  754. this.filetextToolbarNode.setStyle("top", "" + p + "px");
  755. }
  756. }
  757. //
  758. // this.filetextToolbarNode.inject(offsetNode);
  759. //
  760. //
  761. // this.filetextToolbarNode.setStyle("top", ""+p+"px");
  762. },
  763. locationFiletextToolbar: function(){
  764. this.reLocationFiletextToolbar();
  765. if (this.filetextToolbarNode) {
  766. var scrollNode = this.contentNode;
  767. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  768. scrollNode = scrollNode.getParent();
  769. }
  770. if (scrollNode){
  771. this.filetextScrollNode = scrollNode;
  772. this.reLocationFiletextToolbarFun = this.reLocationFiletextToolbar.bind(this);
  773. this.filetextScrollNode.addEvent("scroll", this.reLocationFiletextToolbarFun);
  774. }
  775. }
  776. },
  777. _isAllowEdit:function(){
  778. if (this.readonly) return false;
  779. if (this.json.allowEdit=="n") return false;
  780. if (this.json.allowEdit=="s"){
  781. if (this.json.allowEditScript && this.json.allowEditScript.code){
  782. return !!this.form.Macro.exec(this.json.allowEditScript.code, this);
  783. }
  784. }
  785. return true;
  786. },
  787. _getEdit: function(name, typeItem, scriptItem){
  788. switch (this.json[typeItem]) {
  789. case "y":
  790. return true;
  791. case "n":
  792. return false;
  793. case "s":
  794. if (this.json[scriptItem] && this.json[scriptItem].code){
  795. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  796. }
  797. return true;
  798. }
  799. },
  800. loadCkeditorStyle: function(node){
  801. if (node){
  802. o2.load("ckeditor", function(){
  803. //CKEDITOR.disableAutoInline = true;
  804. node.setAttribute('contenteditable', true);
  805. var editor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  806. this.filetextEditor.on("instanceReady", function(e){
  807. if (callback) callback(e);
  808. }.bind(this));
  809. }.bind(this));
  810. }
  811. },
  812. _loadToolbars: function(){
  813. var html ="";
  814. if (this.allowEdit){
  815. //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>";
  816. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"/x_component_process_Xform/$Form/default/icon/editdoc.png\" title=\""+MWF.xApplication.process.Xform.LP.editdoc+"\" MWFButtonAction=\"_switchReadOrEditInline\" MWFButtonText=\""+MWF.xApplication.process.Xform.LP.editdoc+"\"></span>";
  817. //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>";
  818. }
  819. this.toolNode.set("html", html);
  820. MWF.require("MWF.widget.Toolbar", function() {
  821. this.toolbar = new MWF.widget.Toolbar(this.toolNode, {"style": "documentEdit"}, this);
  822. this.toolbar.load();
  823. }.bind(this));
  824. this.doublePageAction = new Element("div", {"styles": this.css.doc_toolbar_doublePage, "text": MWF.xApplication.process.Xform.LP.doublePage}).inject(this.toolNode);
  825. this.doublePageAction.addEvent("click", function(){
  826. if (this.options.pageShow!=="double"){
  827. this._doublePage();
  828. }else{
  829. this._singlePage();
  830. }
  831. }.bind(this));
  832. },
  833. _repage: function(delay){
  834. debugger;
  835. if (this.options.pageShow!=="double"){
  836. this._singlePage();
  837. }else{
  838. this._doublePage();
  839. }
  840. if (delay){
  841. if (!this.form.isLoaded){
  842. this.form.addEvent("afterLoad", this._checkScale.bind(this));
  843. }else{
  844. this._checkScale();
  845. }
  846. }else{
  847. this._checkScale();
  848. }
  849. },
  850. _singlePage: function(){
  851. var w = this.contentNode.getSize().x;
  852. var count = 1;
  853. var pageWidth = count * this.options.docPageFullWidth;
  854. var margin = (w-pageWidth)/(count+1);
  855. if (this.isScale){
  856. margin = "10"
  857. }
  858. this.pages.each(function(page, i){
  859. page.setStyles({
  860. "float": "left",
  861. "margin-left": ""+margin+"px"
  862. });
  863. });
  864. // this.pages.each(function(page){
  865. // page.setStyle("float", "none");
  866. // });
  867. this.options.pageShow="single";
  868. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
  869. },
  870. createWaitSplitPage: function(){
  871. debugger;
  872. this.node.mask({
  873. "style": {
  874. "background-color": "#cccccc",
  875. "opacity": 0.3
  876. }
  877. });
  878. this.waitSplitPageNode = new Element("div", {"styles": this.form.css.waitSplitPageNode, "text": MWF.xApplication.process.Xform.LP.computePage}).inject(this.node);
  879. this.waitSplitPageNode.position({
  880. "relativeTo": this.contentNode,
  881. "position": "topRight",
  882. "edge": "topRight",
  883. "offset": {
  884. "x": -10,
  885. "y": 10
  886. }
  887. });
  888. //this.form.notice(MWF.xApplication.process.Xform.LP.computePage, "info", this.node);
  889. },
  890. clearWaitSplitPage: function(){
  891. this.node.unmask();
  892. if (this.waitSplitPageNode) this.waitSplitPageNode.destroy();
  893. this.waitSplitPageNode = null;
  894. },
  895. _doublePage: function(){
  896. this.createWaitSplitPage();
  897. window.setTimeout(function(){
  898. this._checkSplitPage(this.pages[0]);
  899. var w = this.contentNode.getSize().x;
  900. var count = (w/this.options.docPageFullWidth).toInt();
  901. var pages = this.contentNode.getElements(".doc_layout_page");
  902. count = Math.min(pages.length, count);
  903. var pageWidth = count * this.options.docPageFullWidth;
  904. var margin = (w-pageWidth)/(count+1);
  905. this.pages.each(function(page, i){
  906. page.setStyles({
  907. "float": "left",
  908. "margin-left": ""+margin+"px"
  909. });
  910. });
  911. // this.pages.each(function(page, i){
  912. // if ((i % 2)===0){
  913. // page.setStyle("float", "left");
  914. // }else{
  915. // page.setStyle("float", "right");
  916. // }
  917. // });
  918. this.options.pageShow="double";
  919. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
  920. this.clearWaitSplitPage();
  921. }.bind(this), 1000);
  922. },
  923. _getDefaultData: function(){
  924. return this.json.defaultValue;
  925. //return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
  926. },
  927. _loadFiletextPage: function(callback){
  928. this.data = this._getBusinessData();
  929. if (!this.data) this.data = this._getDefaultData();
  930. this._computeData(true);
  931. this._createPage(function(control){
  932. this._loadPageLayout(control);
  933. // this.data = this._getBusinessData();
  934. // if (!this.data) this.data = this._getDefaultData();
  935. this.setData(this.data);
  936. // this._checkSplitPage(this.pages[0]);
  937. //this._repage(true);
  938. //this.loadCkeditorFiletext();
  939. if (!this.readonly){
  940. //if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
  941. // if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
  942. // if (this.json.allowEditSubject) this.loadCkeditorSubject();
  943. // if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
  944. // if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
  945. // if (this.json.allowEditSigner) this.loadCkeditorSigner();
  946. // if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
  947. }
  948. if (callback) callback();
  949. }.bind(this));
  950. },
  951. _getEditorConfig: function(){
  952. // var mathElements = [
  953. // 'math',
  954. // 'maction',
  955. // 'maligngroup',
  956. // 'malignmark',
  957. // 'menclose',
  958. // 'merror',
  959. // 'mfenced',
  960. // 'mfrac',
  961. // 'mglyph',
  962. // 'mi',
  963. // 'mlabeledtr',
  964. // 'mlongdiv',
  965. // 'mmultiscripts',
  966. // 'mn',
  967. // 'mo',
  968. // 'mover',
  969. // 'mpadded',
  970. // 'mphantom',
  971. // 'mroot',
  972. // 'mrow',
  973. // 'ms',
  974. // 'mscarries',
  975. // 'mscarry',
  976. // 'msgroup',
  977. // 'msline',
  978. // 'mspace',
  979. // 'msqrt',
  980. // 'msrow',
  981. // 'mstack',
  982. // 'mstyle',
  983. // 'msub',
  984. // 'msup',
  985. // 'msubsup',
  986. // 'mtable',
  987. // 'mtd',
  988. // 'mtext',
  989. // 'mtr',
  990. // 'munder',
  991. // 'munderover',
  992. // 'semantics',
  993. // 'annotation',
  994. // 'annotation-xml'
  995. // ];
  996. //CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.13.0/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
  997. var editorConfig = {
  998. qtRows: 20, // Count of rows
  999. qtColumns: 20, // Count of columns
  1000. qtBorder: '1', // Border of inserted table
  1001. qtWidth: '95%', // Width of inserted table
  1002. qtStyle: { 'border-collapse' : 'collapse' },
  1003. qtClass: 'test', // Class of table
  1004. qtCellPadding: '0', // Cell padding table
  1005. qtCellSpacing: '0', // Cell spacing table
  1006. qtPreviewBorder: '4px double black', // preview table border
  1007. qtPreviewSize: '4px', // Preview table cell size
  1008. qtPreviewBackground: '#c8def4', // preview table background (hover)
  1009. // format_tags: '标题一;标题二;标题三;标题四;正文', // entries is displayed in "Paragraph format"
  1010. format_tags: '标题一;标题二;正文(标题三,四)', // entries is displayed in "Paragraph format"
  1011. 'format_标题一': {
  1012. name: '标题一',
  1013. element: 'div',
  1014. styles: {
  1015. 'font-family': '黑体',
  1016. 'font-size': '16pt'
  1017. }
  1018. },
  1019. 'format_标题二': {
  1020. name: '标题二',
  1021. element: 'div',
  1022. styles: {
  1023. 'font-family': '楷体',
  1024. 'font-size': '16pt'
  1025. }
  1026. },
  1027. // 'format_标题三': {
  1028. // name: '标题三',
  1029. // element: 'div',
  1030. // styles: {
  1031. // 'font-family': '仿宋',
  1032. // 'font-size': '16pt'
  1033. // }
  1034. // },
  1035. // 'format_标题四': {
  1036. // name: '标题四',
  1037. // element: 'div',
  1038. // styles: {
  1039. // 'font-family': '仿宋',
  1040. // 'font-size': '16pt'
  1041. // }
  1042. // },
  1043. 'format_正文(标题三,四)': {
  1044. name: '正文(标题三,四)',
  1045. element: 'div',
  1046. styles: {
  1047. 'font-family': '仿宋',
  1048. 'font-size': '16pt'
  1049. }
  1050. }
  1051. };
  1052. editorConfig.toolbarGroups = [
  1053. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  1054. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  1055. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  1056. { name: 'forms', groups: [ 'forms' ] },
  1057. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  1058. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  1059. { name: 'links', groups: [ 'links' ] },
  1060. { name: 'insert', groups: [ 'insert' ] },
  1061. { name: 'styles', groups: [ 'styles' ] },
  1062. { name: 'colors', groups: [ 'colors' ] },
  1063. { name: 'tools', groups: [ 'tools' ] },
  1064. { name: 'others', groups: [ 'others' ] },
  1065. { name: 'about', groups: [ 'about' ] }
  1066. ];
  1067. //editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,mathjax,ckeditor_wiris";
  1068. editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,eqneditor";
  1069. //editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
  1070. editorConfig.removeButtons = 'Source,Save,NewPage,Preview,Print,Templates,Paste,PasteFromWord,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Bold,Italic,Underline,Strike,Subscript,Superscript,CopyFormatting,RemoveFormat,BulletedList,Outdent,Indent,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Link,Unlink,Anchor,Image,Flash,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,TextColor,BGColor,Maximize,ShowBlocks,About,Styles,Font,FontSize';
  1071. //editorConfig.extraAllowedContent = mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)';
  1072. //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';
  1073. editorConfig.removePlugins = ['magicline'];
  1074. editorConfig.enterMode = 3;
  1075. // editorConfig.extraPlugins = ['ecnet','mathjax'];
  1076. // editorConfig.removePlugins = ['magicline'];
  1077. // editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
  1078. return editorConfig;
  1079. },
  1080. _checkSplitPage: function(pageNode){
  1081. if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
  1082. var contentNode = pageNode.getFirst();
  1083. if (contentNode.getSize().y>this.options.docPageHeight){
  1084. this._splitPage(pageNode);
  1085. }
  1086. var i = pageNode.get("data-pagecount").toInt();
  1087. if (i && this.pages.length-1>=i){
  1088. this._checkSplitPage(this.pages[i]);
  1089. }
  1090. if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
  1091. },
  1092. _splitFiletextNodeOneWord:function(lnode, nextPageNode){
  1093. var text = lnode.textContent;
  1094. var len = text.length;
  1095. var left = text.substring(0, len-1);
  1096. var right = text.substring(len-1, len);
  1097. lnode.textContent = left;
  1098. nextPageNode.textContent = right+nextPageNode.textContent;
  1099. //nextPageNode.appendText(right, "top");
  1100. },
  1101. _splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
  1102. var contentNode = pageNode.getFirst();
  1103. var lnode = node.lastChild;
  1104. if (!lnode){
  1105. if (node.parentNode) node.parentNode.removeChild(node);
  1106. //node.remove();
  1107. }else{
  1108. while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
  1109. var tmpnode = lnode.previousSibling;
  1110. var nodeType = lnode.nodeType;
  1111. if (!nextPageNode) nextPageNode = nextFiletextNode;
  1112. if (nodeType == Node.ELEMENT_NODE) {
  1113. if (lnode.tagName == "table") {
  1114. lnode.inject(nextPageNode);
  1115. } else if (lnode.tagName == "BR") {
  1116. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1117. } else {
  1118. var id = lnode.get("data-pagePart");
  1119. if (!id){
  1120. id = (new o2.widget.UUID()).toString();
  1121. lnode.set("data-pagePart", id);
  1122. }
  1123. var tmpNode = nextPageNode.getFirst();
  1124. if (tmpNode && tmpNode.get("data-pagePart")==id){
  1125. nextPageNode = tmpNode;
  1126. }else{
  1127. nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
  1128. }
  1129. //var subnode = lnode.getLast();
  1130. this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
  1131. if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1132. nextPageNode = nextPageNode.getParent();
  1133. }
  1134. } else if (nodeType == Node.TEXT_NODE) {
  1135. var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
  1136. while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
  1137. //console.log(contentNode.getSize().y);
  1138. this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
  1139. }
  1140. if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
  1141. } else {
  1142. //lnode.remove();
  1143. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1144. }
  1145. lnode = tmpnode;
  1146. }
  1147. if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
  1148. }
  1149. //this._checkSplitPage(pageNode);
  1150. },
  1151. _splitPage: function(pageNode){
  1152. var contentNode = pageNode.getFirst();
  1153. var blockNodes = pageNode.getElements(".doc_block");
  1154. if (blockNodes.length){
  1155. var blockNode = blockNodes[blockNodes.length-1];
  1156. var idx = this.pages.indexOf(pageNode);
  1157. if (this.pages.length<=idx+1) this._createNewPage();
  1158. var nextPage = this.pages[idx+1];
  1159. if (blockNode.hasClass("doc_layout_filetext")){
  1160. var filetextNode = nextPage.getElement(".doc_layout_filetext");
  1161. if (!filetextNode){
  1162. filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
  1163. //filetextNode.setAttribute('contenteditable', true);
  1164. }
  1165. if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
  1166. //var nextEditor = filetextNode.retrieve("editor");
  1167. var node = blockNode;
  1168. var nextPageNode = filetextNode;
  1169. this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
  1170. }else{
  1171. blockNode.inject(nextPage.getFirst(), "top");
  1172. //var contentNode = pageNode.getFirst();
  1173. if (contentNode.getSize().y>this.options.docPageHeight){
  1174. this._splitPage(pageNode);
  1175. }
  1176. }
  1177. }
  1178. },
  1179. loadCkeditorFiletext: function(callback, inline){
  1180. if (this.layout_filetext){
  1181. o2.load("ckeditor", function(){
  1182. CKEDITOR.disableAutoInline = true;
  1183. this.layout_filetext.setAttribute('contenteditable', true);
  1184. if (inline){
  1185. this.filetextEditor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1186. }else{
  1187. this.filetextEditor = CKEDITOR.replace(this.layout_filetext, this._getEditorConfig());
  1188. }
  1189. this.filetextEditor.on("instanceReady", function(e){
  1190. if (callback) callback(e);
  1191. }.bind(this));
  1192. this.filetextEditor.on( 'focus', function( e ) {
  1193. window.setTimeout(this.reLocationFiletextToolbar.bind(this), 10);
  1194. }.bind(this) );
  1195. // this.filetextEditor.on("key", function(e){
  1196. // debugger;
  1197. // }.bind(this));
  1198. }.bind(this));
  1199. }
  1200. },
  1201. _loadEvents: function(editorConfig){
  1202. Object.each(this.json.events, function(e, key){
  1203. if (e.code){
  1204. this.editor.on(key, function(event){
  1205. return this.form.Macro.fire(e.code, this, event);
  1206. }.bind(this), this);
  1207. }
  1208. }.bind(this));
  1209. },
  1210. _bindFieldChange: function(name,dataItem, dom){
  1211. var field = this.form.all[this.json[dataItem]];
  1212. if (field){
  1213. var bindFun = function(){
  1214. this._computeItemFieldData(name, dataItem);
  1215. //if (this.data[name]){
  1216. if (this[dom]){
  1217. if (dom=="layout_redHeader" || dom=="layout_subject"){
  1218. this[dom].set("html", this.data[name]|| "");
  1219. }else if (dom=="layout_attachment"){
  1220. this.setAttachmentData();
  1221. }else{
  1222. this[dom].set("text", this.data[name]|| "");
  1223. }
  1224. }
  1225. this.reSetShow();
  1226. //}
  1227. }.bind(this);
  1228. field.node.store(this.json.id+"bindFun", bindFun);
  1229. field.addModuleEvent("change", bindFun);
  1230. }
  1231. },
  1232. _computeItemFieldData: function(name, dataItem){
  1233. var v = "";
  1234. var module = this.form.all[this.json[dataItem]];
  1235. if (module && module.getData) v = module.getData();
  1236. if (!v) v = this.form.businessData.data[this.json[dataItem]];
  1237. if (v){
  1238. var t = o2.typeOf(v);
  1239. switch (t) {
  1240. case "string":
  1241. switch (name) {
  1242. case "issuanceDate":
  1243. case "editionDate":
  1244. var d = new Date(v);
  1245. if (d.isValid()){
  1246. var y = d.getFullYear();
  1247. var m = d.getMonth();
  1248. var day = d.getDate();
  1249. m = m +1;
  1250. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  1251. }else{
  1252. this.data[name] = v;
  1253. }
  1254. //this.data[name] = (new Date(v).isValid()) ? Date.parse(v).format("%Y年%m月%d%日") : v;
  1255. break;
  1256. case "mainSend":
  1257. this.data[name] = v + ":";
  1258. break;
  1259. default:
  1260. this.data[name] = v;
  1261. }
  1262. break;
  1263. case "array":
  1264. var strs = [];
  1265. v.each(function(value){
  1266. if (o2.typeOf(value)=="object" && value.distinguishedName){
  1267. strs.push(value.name);
  1268. }else{
  1269. strs.push(value.toString());
  1270. }
  1271. });
  1272. //if (strs.length){
  1273. switch (name) {
  1274. case "attachment":
  1275. // this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>");
  1276. var atts = strs.map(function(a){
  1277. return (a.indexOf(".")!=-1) ? a.substring(0, a.lastIndexOf(".")) : a;
  1278. });
  1279. this.data[name] = atts;
  1280. break;
  1281. case "issuanceDate":
  1282. case "editionDate":
  1283. var tmpStrs = strs.map(function(n, i){
  1284. var d = Date.parse(n);
  1285. return (d.isValid()) ? d.format("“%Y年%m月%d%日") : n;
  1286. });
  1287. this.data[name] = tmpStrs.join(",")
  1288. break;
  1289. case "mainSend":
  1290. debugger;
  1291. this.data[name] = strs.join(",") + ":";
  1292. break;
  1293. default:
  1294. this.data[name] = strs.join(",");
  1295. }
  1296. //}
  1297. break;
  1298. default:
  1299. this.data[name] = v.toString();
  1300. }
  1301. }else{
  1302. this.data[name] = this.json.defaultValue[name];
  1303. }
  1304. },
  1305. _computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
  1306. switch (this.json[typeItem]) {
  1307. case "data":
  1308. if (this.json[dataItem]){
  1309. if (ev) this._bindFieldChange(name, dataItem, dom);
  1310. this._computeItemFieldData(name, dataItem);
  1311. }
  1312. break;
  1313. case "script":
  1314. if (this.json[scriptItem] && this.json[scriptItem].code){
  1315. var v = this.form.Macro.exec(this.json[scriptItem].code, this);
  1316. this.data[name] = v;
  1317. if (name=="attachment"){
  1318. //this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>") : v;
  1319. this.data[name] = (typeOf(v)=="array") ? v : [v];
  1320. }
  1321. if (name=="issuanceDate" || name=="editionDate"){
  1322. var d = Date.parse(v);
  1323. this.data[name] = (d.isValid()) ? d.format("“%Y年%m月%d%日") : v;
  1324. }
  1325. }
  1326. break;
  1327. }
  1328. },
  1329. _computeData: function(ev){
  1330. this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
  1331. this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
  1332. this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
  1333. this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
  1334. this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
  1335. this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
  1336. this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
  1337. this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
  1338. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
  1339. this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
  1340. this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
  1341. this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
  1342. this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
  1343. this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
  1344. this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
  1345. this._computeItemData("meetingAttend", "meetingAttendValueType", "meetingAttendValueData", "meetingAttendValueScript", ev, "layout_meetingAttendContent");
  1346. this._computeItemData("meetingLeave", "meetingLeaveValueType", "meetingLeaveValueData", "meetingLeaveValueScript", ev, "layout_meetingLeaveContent");
  1347. this._computeItemData("meetingSit", "meetingSitValueType", "meetingSitValueData", "meetingSitValueScript", ev, "layout_meetingSitContent");
  1348. },
  1349. _loadValue: function(){
  1350. var data = this._getBusinessData();
  1351. },
  1352. reload: function(){
  1353. this.resetData();
  1354. },
  1355. resetData: function(){
  1356. this._computeData(false);
  1357. this.pages = [];
  1358. this.contentNode.empty();
  1359. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  1360. this.eiitMode = false;
  1361. this._createPage(function(control){
  1362. this._loadPageLayout(control);
  1363. this.setData(this.data);
  1364. this._checkSplitPage(this.pages[0]);
  1365. this._repage();
  1366. }.bind(this));
  1367. },
  1368. getData: function(){
  1369. //if (this.eiitMode){
  1370. if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
  1371. if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
  1372. if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
  1373. if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
  1374. if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
  1375. if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
  1376. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  1377. if (this.layout_subject) this.data.subject = this.layout_subject.get("html");
  1378. if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
  1379. if (this.eiitMode) if (this.layout_filetext) this.data.filetext = this.layout_filetext.get("html");
  1380. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  1381. if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
  1382. if (this.layout_attachment){
  1383. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", false, "layout_attachment");
  1384. // var atts = [];
  1385. // var nodes = this.layout_attachment.getElements(".doc_layout_attachment_content_name");
  1386. // if (nodes.length){
  1387. // nodes.each(function(node){
  1388. // atts.push(node.get("text"));
  1389. // });
  1390. // }
  1391. // this.data.attachment = atts;
  1392. }
  1393. if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("text");
  1394. if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
  1395. if (this.layout_annotation) this.data.annotation = this.layout_annotation.get("text");
  1396. if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
  1397. if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
  1398. if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
  1399. if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
  1400. if (this.layout_meetingAttendTitle) this.data.meetingAttendTitle = this.layout_meetingAttendTitle.get("text");
  1401. if (this.layout_meetingLeaveTitle) this.data.meetingLeaveTitle = this.layout_meetingLeaveTitle.get("text");
  1402. if (this.layout_meetingSitTitle) this.data.meetingSitTitle = this.layout_meetingSitTitle.get("text");
  1403. if (this.layout_meetingAttendContent) this.data.meetingAttend = this.layout_meetingAttendContent.get("text");
  1404. if (this.layout_meetingLeaveContent) this.data.meetingLeave = this.layout_meetingLeaveContent.get("text");
  1405. if (this.layout_meetingSitContent) this.data.meetingSit = this.layout_meetingSitContent.get("text");
  1406. //}
  1407. return this.data;
  1408. },
  1409. setAttachmentData: function(){
  1410. if (!this.attachmentTemplete){
  1411. this.attachmentTemplete = this.layout_attachment.get("html");
  1412. }
  1413. this.layout_attachment.empty();
  1414. if (this.data.attachment && this.data.attachment.length && this.data.attachment.each){
  1415. //var tmpdiv = new Element("div", {"styles": {"display":"none"}}).inject(document.body);
  1416. var tmpdiv = new Element("div");
  1417. this.data.attachment.each(function(name, idx){
  1418. tmpdiv.set("html", this.attachmentTemplete);
  1419. var serialNode = tmpdiv.getElement(".doc_layout_attachment_content_serial");
  1420. var nameNode = tmpdiv.getElement(".doc_layout_attachment_content_name");
  1421. if (serialNode) serialNode.set("text", idx+1);
  1422. if (nameNode) nameNode.set("text", name);
  1423. var html = tmpdiv.get("html");
  1424. tmpdiv.empty();
  1425. this.layout_attachment.appendHTML(html);
  1426. }.bind(this));
  1427. tmpdiv.destroy();
  1428. }
  1429. },
  1430. setData: function(data){
  1431. if (data){
  1432. debugger;
  1433. this.data = data;
  1434. this._setBusinessData(data);
  1435. if (this.layout_copies) this.layout_copies.set("text", data.copies || " ");
  1436. if (this.layout_secret) this.layout_secret.set("text", data.secret || " ");
  1437. if (this.layout_priority) this.layout_priority.set("text", data.priority || " ");
  1438. if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
  1439. if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
  1440. if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
  1441. if (this.layout_signer) this.layout_signer.set("text", data.signer || " ");
  1442. if (this.layout_subject) this.layout_subject.set("html", data.subject || " ");
  1443. if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
  1444. if (this.layout_filetext) this.layout_filetext.set("html", data.filetext || "");
  1445. if (this.layout_signer) this.layout_signer.set("text", data.signer || "");
  1446. if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
  1447. if (this.layout_attachment){
  1448. this.setAttachmentData();
  1449. }
  1450. if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("text", data.issuanceUnit || " ");
  1451. if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
  1452. if (this.layout_annotation) this.layout_annotation.set("text", data.annotation || " ");
  1453. if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
  1454. if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
  1455. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
  1456. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
  1457. if (this.layout_meetingAttendTitle) this.layout_meetingAttendTitle.set("text", data.meetingAttendTitle || this.json.defaultValue.meetingAttendTitle || " ");
  1458. if (this.layout_meetingLeaveTitle) this.layout_meetingLeaveTitle.set("text", data.meetingLeaveTitle || this.json.defaultValue.meetingLeaveTitle || " ");
  1459. if (this.layout_meetingSitTitle) this.layout_meetingSitTitle.set("text", data.meetingSitTitle || this.json.defaultValue.meetingSitTitle || " ");
  1460. if (this.layout_meetingAttendContent) this.layout_meetingAttendContent.set("text", data.meetingAttend || " ");
  1461. if (this.layout_meetingLeaveContent) this.layout_meetingLeaveContent.set("text", data.meetingLeave || " ");
  1462. if (this.layout_meetingSitContent) this.layout_meetingSitContent.set("text", data.meetingSit || " ");
  1463. }
  1464. },
  1465. createErrorNode: function(text){
  1466. var node = new Element("div");
  1467. var iconNode = new Element("div", {
  1468. "styles": {
  1469. "width": "20px",
  1470. "height": "20px",
  1471. "float": "left",
  1472. "background": "url("+"/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  1473. }
  1474. }).inject(node);
  1475. var textNode = new Element("div", {
  1476. "styles": {
  1477. "line-height": "20px",
  1478. "margin-left": "20px",
  1479. "color": "red",
  1480. "word-break": "keep-all"
  1481. },
  1482. "text": text
  1483. }).inject(node);
  1484. return node;
  1485. },
  1486. notValidationMode: function(text){
  1487. if (!this.isNotValidationMode){
  1488. this.isNotValidationMode = true;
  1489. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  1490. this.node.setStyle("border", "1px solid red");
  1491. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  1492. this.showNotValidationMode(this.node);
  1493. }
  1494. },
  1495. showNotValidationMode: function(node){
  1496. var p = node.getParent("div");
  1497. if (p){
  1498. if (p.get("MWFtype") == "tab$Content"){
  1499. if (p.getParent("div").getStyle("display")=="none"){
  1500. var contentAreaNode = p.getParent("div").getParent("div");
  1501. var tabAreaNode = contentAreaNode.getPrevious("div");
  1502. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  1503. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  1504. tabNode.click();
  1505. p = tabAreaNode.getParent("div");
  1506. }
  1507. }
  1508. this.showNotValidationMode(p);
  1509. }
  1510. },
  1511. validationMode: function(){
  1512. if (this.isNotValidationMode){
  1513. this.isNotValidationMode = false;
  1514. this.node.setStyles(this.node.retrieve("borderStyle"));
  1515. if (this.errNode){
  1516. this.errNode.destroy();
  1517. this.errNode = null;
  1518. }
  1519. }
  1520. },
  1521. validationConfigItem: function(routeName, data){
  1522. var flag = (data.status=="all") ? true: (routeName == data.decision);
  1523. if (flag){
  1524. var n = this.getData();
  1525. var v = (data.valueType=="value") ? n : n.length;
  1526. switch (data.operateor){
  1527. case "isnull":
  1528. if (!v){
  1529. this.notValidationMode(data.prompt);
  1530. return false;
  1531. }
  1532. break;
  1533. case "notnull":
  1534. if (v){
  1535. this.notValidationMode(data.prompt);
  1536. return false;
  1537. }
  1538. break;
  1539. case "gt":
  1540. if (v>data.value){
  1541. this.notValidationMode(data.prompt);
  1542. return false;
  1543. }
  1544. break;
  1545. case "lt":
  1546. if (v<data.value){
  1547. this.notValidationMode(data.prompt);
  1548. return false;
  1549. }
  1550. break;
  1551. case "equal":
  1552. if (v==data.value){
  1553. this.notValidationMode(data.prompt);
  1554. return false;
  1555. }
  1556. break;
  1557. case "neq":
  1558. if (v!=data.value){
  1559. this.notValidationMode(data.prompt);
  1560. return false;
  1561. }
  1562. break;
  1563. case "contain":
  1564. if (v.indexOf(data.value)!=-1){
  1565. this.notValidationMode(data.prompt);
  1566. return false;
  1567. }
  1568. break;
  1569. case "notcontain":
  1570. if (v.indexOf(data.value)==-1){
  1571. this.notValidationMode(data.prompt);
  1572. return false;
  1573. }
  1574. break;
  1575. }
  1576. }
  1577. return true;
  1578. },
  1579. validationConfig: function(routeName, opinion){
  1580. if (this.json.validationConfig){
  1581. if (this.json.validationConfig.length){
  1582. for (var i=0; i<this.json.validationConfig.length; i++) {
  1583. var data = this.json.validationConfig[i];
  1584. if (!this.validationConfigItem(routeName, data)) return false;
  1585. }
  1586. }
  1587. return true;
  1588. }
  1589. return true;
  1590. },
  1591. validation: function(routeName, opinion){
  1592. if (!this.validationConfig(routeName, opinion)) return false;
  1593. if (!this.json.validation) return true;
  1594. if (!this.json.validation.code) return true;
  1595. var flag = this.form.Macro.exec(this.json.validation.code, this);
  1596. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  1597. if (flag.toString()!="true"){
  1598. this.notValidationMode(flag);
  1599. return false;
  1600. }
  1601. return true;
  1602. },
  1603. toWord: function(){
  1604. var flag = true;
  1605. if (this.json.toWordConditionScript && this.json.toWordConditionScript.code){
  1606. flag = !!this.form.Macro.exec(this.json.toWordConditionScript.code, this);
  1607. }
  1608. if (flag){
  1609. var toEdit = false;
  1610. if (this.eiitMode){
  1611. toEdit = true;
  1612. this._readFiletext();
  1613. }
  1614. this._returnScale();
  1615. this.pages = [];
  1616. this.contentNode.empty();
  1617. this._createPage(function(control){
  1618. this._loadPageLayout(control);
  1619. this.setData(this.data);
  1620. this._checkScale();
  1621. this.node.setStyles({
  1622. "height":"auto"
  1623. });
  1624. var content = this.contentNode.getFirst().getFirst().get("html");
  1625. var body = {
  1626. "fileName": this.json.toWordFilename || "",
  1627. "site": this.json.toWordSite || "$doc",
  1628. "content": content
  1629. };
  1630. o2.Actions.get("x_processplatform_assemble_surface").docToWord(this.form.businessData.work.id, body, function(json){
  1631. if (this.form.businessData.workCompleted){
  1632. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id,function(attjson){
  1633. this.showToWord(attjson.data);
  1634. }.bind(this));
  1635. }else{
  1636. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id,function(attjson){
  1637. this.showToWord(attjson.data);
  1638. }.bind(this));
  1639. }
  1640. }.bind(this));
  1641. if (!toEdit){
  1642. this._readFiletext();
  1643. }else{
  1644. this._createEditor();
  1645. }
  1646. }.bind(this));
  1647. }
  1648. },
  1649. showToWord: function(att){
  1650. var site = this.json.toWordSite || "$doc";
  1651. var attModule = this.form.all[site];
  1652. if (attModule){
  1653. attModule.attachmentController.clear();
  1654. attModule.attachmentController.addAttachment(att);
  1655. }
  1656. }
  1657. });