Documenteditor.js 139 KB

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