Documenteditor.js 139 KB

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