Documenteditor.js 118 KB

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