Documenteditor.js 140 KB

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