Documenteditor.js 126 KB

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