Documenteditor.js 141 KB

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