Documenteditor.js 142 KB

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