Documenteditor.js 100 KB

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