Documenteditor.js 139 KB

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