Documenteditor.js 135 KB

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