Documenteditor.js 135 KB

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