Documenteditor.js 128 KB

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