Documenteditor.js 142 KB

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