Documenteditor.js 135 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928
  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. this.toWord(function(data){
  1097. if (this.form.businessData.work && !this.form.businessData.work.completedTime){
  1098. this.form.workAction.getAttachmentStream(data.id, this.form.businessData.work.id);
  1099. }else{
  1100. this.form.workAction.getWorkcompletedAttachmentStream(data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  1101. }
  1102. }.bind(this));
  1103. },
  1104. _historyDoc: function(){
  1105. this.getHistory(function(){
  1106. //this.history.play();
  1107. }.bind(this));
  1108. },
  1109. getHistory: function(callback){
  1110. if (this.history){
  1111. this.history.active(function(){
  1112. if (callback) callback();
  1113. });
  1114. }else{
  1115. MWF.xDesktop.requireApp("process.Xform", "widget.DocumentHistory", function(){
  1116. this.history = new MWF.xApplication.process.Xform.widget.DocumentHistory(this);
  1117. this.history.load(function(){
  1118. if (callback) callback();
  1119. });
  1120. }.bind(this));
  1121. }
  1122. },
  1123. htmlToText: function(html){
  1124. var tmpdiv = new Element("div", {"html": html});
  1125. var text = tmpdiv.get("text");
  1126. tmpdiv.destroy();
  1127. return text;
  1128. },
  1129. _readFiletext: function(){
  1130. //this._returnScale();
  1131. this.zoom(1);
  1132. if (this.filetextEditor) this.filetextEditor.destroy();
  1133. if (this.filetextScrollNode){
  1134. if (this.reLocationFiletextToolbarFun){
  1135. this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  1136. //this.form.app.removeEvent("resize", this.reLocationFiletextToolbarFun);
  1137. this.reLocationFiletextToolbarFun = null;
  1138. }
  1139. this.filetextScrollNode = null;
  1140. }
  1141. if (this.filetextToolbarNode) this.filetextToolbarNode = null;
  1142. this.layout_filetext.setAttribute('contenteditable', false);
  1143. this.data = this.getData();
  1144. // debugger;
  1145. if (!this.data.filetext){
  1146. //this.data.filetext = this.json.defaultValue.filetext;
  1147. this.layout_filetext.set("html", this.json.defaultValue.filetext);
  1148. }
  1149. //this._checkSplitPage(this.pages[0]);
  1150. this._repage();
  1151. },
  1152. _editFiletext: function(inline){
  1153. this._returnScale();
  1154. this.zoom(1);
  1155. this._singlePage();
  1156. this.pages = [];
  1157. this.contentNode.empty();
  1158. this._createPage(function(control){
  1159. this._loadPageLayout(control);
  1160. // var docData = this._getBusinessData();
  1161. // if (!docData) docData = this._getDefaultData();
  1162. if (this.data.filetext == this.json.defaultValue.filetext) this.data.filetext = "  ";
  1163. this.setData(this.data);
  1164. this._checkScale();
  1165. this.node.setStyles({
  1166. "height":"auto"
  1167. });
  1168. this._createEditor(inline);
  1169. }.bind(this));
  1170. },
  1171. _createEditor: function(inline){
  1172. if (this.allowEdit){
  1173. this.loadCkeditorFiletext(function(e){
  1174. e.editor.focus();
  1175. e.editor.getSelection().scrollIntoView();
  1176. //this.getFiletextToolber();
  1177. //this.filetextToolbarNode.inject(this.layout_filetext.getOffsetParent());
  1178. this.locationFiletextToolbar();
  1179. }.bind(this), inline);
  1180. }
  1181. },
  1182. getFiletextToolber: function(){
  1183. if (this.filetextEditor) {
  1184. if (!this.filetextToolbarNode) {
  1185. var className = "cke_editor_" + this.filetextEditor.name;
  1186. var filetextToolbarNode = $$("." + className)[0];
  1187. this.filetextToolbarNode = filetextToolbarNode;
  1188. //filetextToolbarNode.destroy();
  1189. }
  1190. }
  1191. },
  1192. reLocationFiletextToolbar: function(){
  1193. this.getFiletextToolber();
  1194. // if (this.filetextToolbarNode){
  1195. // this.filetextToolbarNode.setStyle("display", "block");
  1196. // var offsetNode = this.layout_filetext.getOffsetParent();
  1197. //
  1198. // this.filetextToolbarNode.setStyle("left", 0);
  1199. // var h = this.filetextToolbarNode.getSize().y;
  1200. // var p = this.layout_filetext.getPosition(offsetNode).y-h;
  1201. //
  1202. // var postion = this.layout_filetext.getPosition(this.form.app.content);
  1203. // if (postion.y-h<0){
  1204. // this.filetextToolbarNode.inject(this.form.app.content);
  1205. // this.filetextToolbarNode.setStyle("top", 0);
  1206. // this.filetextToolbarNode.setStyle("left", ""+postion.x+"px");
  1207. // }else{
  1208. // this.filetextToolbarNode.inject(offsetNode);
  1209. // this.filetextToolbarNode.setStyle("top", "" + p + "px");
  1210. // this.filetextToolbarNode.setStyle("left", 0);
  1211. // this.filetextToolbarNode.setStyle("left", "auto");
  1212. // }
  1213. // }
  1214. if (this.filetextToolbarNode){
  1215. if (!this.filetextScrollNode){
  1216. var scrollNode = this.contentNode;
  1217. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("4-y")!=="auto"))){
  1218. scrollNode = scrollNode.getParent();
  1219. }
  1220. this.filetextScrollNode = scrollNode;
  1221. }
  1222. var h = this.filetextToolbarNode.getSize().y;
  1223. var position = this.layout_filetext.getPosition();
  1224. var size = this.layout_filetext.getSize();
  1225. var contentSize = this.filetextScrollNode.getSize();
  1226. if (position.y<0 && size.y+position.y+h<contentSize.y){
  1227. // var top = size.y+position.y;
  1228. // this.filetextToolbarNode.setStyle("top", ""+top+"px");
  1229. var tp = this.toolbar.node.getPosition();
  1230. var tsy = this.toolbar.node.getSize().y;
  1231. var h = tp.y+tsy;
  1232. this.filetextToolbarNode.setStyle("top", ""+h+"px");
  1233. }else if (position.y-h<0){
  1234. var tp = this.toolbar.node.getPosition();
  1235. var tsy = this.toolbar.node.getSize().y;
  1236. var h = tp.y+tsy;
  1237. this.filetextToolbarNode.setStyle("top", ""+h+"px");
  1238. }else{
  1239. var p = this.layout_filetext.getPosition().y-h;
  1240. this.filetextToolbarNode.setStyle("top", "" + p + "px");
  1241. }
  1242. }
  1243. //
  1244. // this.filetextToolbarNode.inject(offsetNode);
  1245. //
  1246. //
  1247. // this.filetextToolbarNode.setStyle("top", ""+p+"px");
  1248. },
  1249. locationFiletextToolbar: function(){
  1250. this.reLocationFiletextToolbar();
  1251. if (this.filetextToolbarNode) {
  1252. var scrollNode = this.contentNode;
  1253. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  1254. scrollNode = scrollNode.getParent();
  1255. }
  1256. if (scrollNode){
  1257. this.filetextScrollNode = scrollNode;
  1258. this.reLocationFiletextToolbarFun = this.reLocationFiletextToolbar.bind(this);
  1259. this.filetextScrollNode.addEvent("scroll", this.reLocationFiletextToolbarFun);
  1260. }
  1261. }
  1262. },
  1263. _isAllowEdit:function(){
  1264. if (this.readonly) return false;
  1265. if (this.json.allowEdit=="n") return false;
  1266. if (this.json.allowEdit=="s"){
  1267. if (this.json.allowEditScript && this.json.allowEditScript.code){
  1268. return !!this.form.Macro.exec(this.json.allowEditScript.code, this);
  1269. }
  1270. }
  1271. return true;
  1272. },
  1273. _isAllowPrint: function(){
  1274. if (this.json.allowPrint=="n") return false;
  1275. if (this.json.allowPrint=="s"){
  1276. if (this.json.allowPrintScript && this.json.allowPrintScript.code){
  1277. return !!this.form.Macro.exec(this.json.allowPrintScript.code, this);
  1278. }
  1279. }
  1280. return true;
  1281. },
  1282. _isAllowHistory: function(){
  1283. if (this.json.allowHistory=="n") return false;
  1284. if (this.json.allowHistory=="s"){
  1285. if (this.json.allowHistoryScript && this.json.allowHistoryScript.code){
  1286. return !!this.form.Macro.exec(this.json.allowHistoryScript.code, this);
  1287. }
  1288. }
  1289. return true;
  1290. },
  1291. _getEdit: function(name, typeItem, scriptItem){
  1292. switch (this.json[typeItem]) {
  1293. case "y":
  1294. return true;
  1295. case "n":
  1296. return false;
  1297. case "s":
  1298. if (this.json[scriptItem] && this.json[scriptItem].code){
  1299. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  1300. }
  1301. return true;
  1302. }
  1303. },
  1304. loadCkeditorStyle: function(node){
  1305. if (node){
  1306. o2.load("ckeditor", function(){
  1307. //CKEDITOR.disableAutoInline = true;
  1308. node.setAttribute('contenteditable', true);
  1309. var editor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1310. this.filetextEditor.on("instanceReady", function(e){
  1311. if (callback) callback(e);
  1312. }.bind(this));
  1313. }.bind(this));
  1314. }
  1315. },
  1316. _loadToolbars: function(){
  1317. var html ="";
  1318. var editdoc, printdoc, history;
  1319. if (layout.mobile){
  1320. editdoc = MWF.xApplication.process.Xform.LP.editdoc_mobile;
  1321. printdoc = MWF.xApplication.process.Xform.LP.printdoc_mobile;
  1322. history = MWF.xApplication.process.Xform.LP.history_mobile;
  1323. }else{
  1324. editdoc = MWF.xApplication.process.Xform.LP.editdoc;
  1325. printdoc = MWF.xApplication.process.Xform.LP.printdoc;
  1326. history = MWF.xApplication.process.Xform.LP.history;
  1327. }
  1328. if (this.allowEdit){
  1329. //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>";
  1330. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/editdoc.png\" title=\""+editdoc+"\" MWFButtonAction=\"_switchReadOrEditInline\" MWFButtonText=\""+editdoc+"\"></span>";
  1331. //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>";
  1332. }
  1333. if (this.allowPrint){
  1334. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/print.png\" title=\""+printdoc+"\" MWFButtonAction=\"_printDoc\" MWFButtonText=\""+printdoc+"\"></span>";
  1335. }
  1336. if (this.allowHistory){
  1337. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/versions.png\" title=\""+history+"\" MWFButtonAction=\"_historyDoc\" MWFButtonText=\""+history+"\"></span>";
  1338. }
  1339. // if (this.json.fullWidth=="y"){
  1340. // html += "<span style='line-height: 26px; color: #999999; font-size: 12px'>已启用半角空格自动转换为全角空格,如需输入半角空格,请使用:SHIFT+空格</span>"
  1341. // }
  1342. this.toolbarNode = new Element("div", {"styles": this.css.doc_toolbar_node}).inject(this.toolNode);
  1343. this.toolbarNode.set("html", html);
  1344. MWF.require("MWF.widget.Toolbar", function() {
  1345. this.toolbar = new MWF.widget.Toolbar(this.toolbarNode, {"style": "documentEdit"}, this);
  1346. this.toolbar.load();
  1347. }.bind(this));
  1348. if (!layout.mobile){
  1349. this.scrollNode = this.toolbarNode.getParentSrcollNode();
  1350. if (this.scrollNode){
  1351. this.scrollNode.addEvent("scroll", function(){
  1352. this.resizeToolbar();
  1353. }.bind(this));
  1354. }
  1355. }
  1356. this.doublePageAction = new Element("div", {"styles": this.css.doc_toolbar_doublePage, "text": MWF.xApplication.process.Xform.LP.doublePage}).inject(this.toolbarNode);
  1357. this.doublePageAction.addEvent("click", function(){
  1358. if (this.options.pageShow!=="double"){
  1359. this._doublePage();
  1360. }else{
  1361. this._singlePage();
  1362. }
  1363. }.bind(this));
  1364. if (layout.mobile) this.doublePageAction.hide();
  1365. this.zoomActionArea = new Element("div", {"styles": {"float": "right", "margin-right": "10px"}}).inject(this.toolbarNode);
  1366. if (this.json.isScale !== "y") this.zoomActionArea.hide();
  1367. this.zoomAddAction = new Element("div", {
  1368. "styles": {
  1369. "float": "right",
  1370. "margin-top": "3px",
  1371. "height": "20px",
  1372. "width": "20px",
  1373. "text-align": "center",
  1374. "line-height": "20px",
  1375. "border": "1px solid #cccccc",
  1376. "background-color": "#ffffff",
  1377. "margin-left": "5px"
  1378. },
  1379. "text": "+"
  1380. }).inject(this.zoomActionArea);
  1381. this.zoomSelectAction = new Element("select", {
  1382. "styles": {
  1383. "float": "right",
  1384. "margin-top": "3px",
  1385. "height": "20px",
  1386. "width": "60px",
  1387. "text-align": "center",
  1388. "line-height": "20px",
  1389. "border": "1px solid #cccccc",
  1390. "background-color": "#ffffff",
  1391. "margin-left": "5px"
  1392. },
  1393. "text": "100%"
  1394. }).inject(this.zoomActionArea);
  1395. this.zoomSubAction = new Element("div", {
  1396. "styles": {
  1397. "float": "right",
  1398. "margin-top": "3px",
  1399. "height": "20px",
  1400. "width": "20px",
  1401. "text-align": "center",
  1402. "line-height": "20px",
  1403. "border": "1px solid #cccccc",
  1404. "background-color": "#ffffff",
  1405. "margin-left": "5px"
  1406. },
  1407. "text": "-"
  1408. }).inject(this.zoomActionArea);
  1409. // this.zoomSelectAction = new Element("select", {"styles": {"float": "right"}}).inject(this.toolbarNode);
  1410. var options = "<option value='2'>200%</option> " +
  1411. "<option value='1.95'>195%</option>" +
  1412. "<option value='1.9'>190%</option>" +
  1413. "<option value='1.85'>185%</option>" +
  1414. "<option value='1.8'>180%</option>" +
  1415. "<option value='1.75'>175%</option>" +
  1416. "<option value='1.7'>170%</option>" +
  1417. "<option value='1.65'>165%</option>" +
  1418. "<option value='1.6'>160%</option>" +
  1419. "<option value='1.55'>155%</option>" +
  1420. "<option value='1.5'>150%</option> " +
  1421. "<option value='1.45'>145%</option>" +
  1422. "<option value='1.4'>140%</option>" +
  1423. "<option value='1.35'>135%</option>" +
  1424. "<option value='1.3'>130%</option>" +
  1425. "<option value='1.25'>125%</option>" +
  1426. "<option value='1.2'>120%</option>" +
  1427. "<option value='1.15'>115%</option>" +
  1428. "<option value='1.1'>110%</option>" +
  1429. "<option value='1.05'>105%</option>" +
  1430. "<option value='1' selected>100%</option>" +
  1431. "<option value='0.95'>95%</option>" +
  1432. "<option value='0.90'>90%</option>" +
  1433. "<option value='0.85'>85%</option>" +
  1434. "<option value='0.80'>80%</option>" +
  1435. "<option value='0.75'>75%</option>" +
  1436. "<option value='0.70'>70%</option>" +
  1437. "<option value='0.65'>65%</option>" +
  1438. "<option value='0.6'>60%</option>" +
  1439. "<option value='0.55'>55%</option>" +
  1440. "<option value='0.5'>50%</option>";
  1441. this.zoomSelectAction.set("html", options);
  1442. this.zoomSelectAction.addEvent("change", function(e){
  1443. this.scaleTo(e.target.options[e.target.selectedIndex].value);
  1444. }.bind(this));
  1445. this.zoomAddAction.addEvent("click", function(){
  1446. debugger;
  1447. var i = (this.scale/0.05).toInt();
  1448. if (i*0.05<this.scale) i++;
  1449. var v = i*0.05;
  1450. //var v = this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value.toFloat();
  1451. v = v+0.05;
  1452. if (v<0.5) v = 0.5;
  1453. if (v>2) v = 2;
  1454. this.scaleTo(v);
  1455. }.bind(this));
  1456. this.zoomSubAction.addEvent("click", function(){
  1457. var i = (this.scale/0.05).toInt();
  1458. if (i*0.05<this.scale) i++;
  1459. var v = i*0.05;
  1460. //var v = this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value.toFloat();
  1461. v = v-0.05;
  1462. if (v<0.5) v = 0.5;
  1463. if (v>2) v = 2;
  1464. this.scaleTo(v);
  1465. }.bind(this));
  1466. },
  1467. scaleTo: function(scale){
  1468. this._returnScale();
  1469. this.scale = scale;
  1470. this.zoom();
  1471. var w = this.contentNode.getSize().x;
  1472. var count = 1;
  1473. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1474. var pageWidth = count * docPageFullWidth;
  1475. var margin = (w-pageWidth)/(count+1);
  1476. if (this.isScale){
  1477. margin = "10";
  1478. }
  1479. if (this.scale) margin = margin/this.scale;
  1480. if (margin < 10){
  1481. var offset = 10-margin;
  1482. margin = 10;
  1483. this.contentNode.scrollTo(offset, 0);
  1484. }
  1485. this.pages.each(function(page, i){
  1486. page.setStyles({
  1487. "float": "left",
  1488. "margin-left": ""+margin+"px"
  1489. });
  1490. });
  1491. this.resetNodeSize();
  1492. },
  1493. _repage: function(delay){
  1494. if (this.options.pageShow!=="double"){
  1495. this._singlePage();
  1496. }else{
  1497. this._doublePage();
  1498. }
  1499. if (delay){
  1500. if (!this.form.isLoaded){
  1501. this.form.addEvent("afterLoad", this._checkScale.bind(this));
  1502. }else{
  1503. this._checkScale();
  1504. }
  1505. }else{
  1506. this._checkScale();
  1507. }
  1508. },
  1509. _singlePage: function(){
  1510. //if (this.editMode) this._readFiletext();
  1511. this.zoom(1);
  1512. this._checkScale();
  1513. var w = this.contentNode.getSize().x;
  1514. var count = 1;
  1515. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1516. //var docPageFullWidth = this.options.docPageFullWidt;
  1517. var pageWidth = count * docPageFullWidth;
  1518. var margin = (w-pageWidth)/(count+1);
  1519. if (this.isScale){
  1520. margin = "10";
  1521. }
  1522. if (this.scale) margin = margin/this.scale;
  1523. this.pages.each(function(page, i){
  1524. page.setStyles({
  1525. "float": "left",
  1526. "margin-left": ""+margin+"px"
  1527. });
  1528. });
  1529. this.resetNodeSize();
  1530. // this.pages.each(function(page){
  1531. // page.setStyle("float", "none");
  1532. // });
  1533. this.resizeSidebar();
  1534. this.options.pageShow="single";
  1535. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
  1536. },
  1537. resetNodeSize: function(){
  1538. var contentSize = this.contentNode.getSize();
  1539. var toolbarSize = this.toolNode.getSize();
  1540. contentHeight = contentSize.y;
  1541. var h = contentHeight+toolbarSize.y+20;
  1542. //h = h - contentSize.y*(1-this.scale);
  1543. this.node.setStyles({
  1544. "height":""+h+"px"
  1545. });
  1546. this.resizeSidebar();
  1547. },
  1548. createWaitSplitPage: function(){
  1549. this.node.mask({
  1550. "style": {
  1551. "background-color": "#cccccc",
  1552. "opacity": 0.3
  1553. }
  1554. });
  1555. this.waitSplitPageNode = new Element("div", {"styles": this.form.css.waitSplitPageNode, "text": MWF.xApplication.process.Xform.LP.computePage}).inject(this.node);
  1556. this.waitSplitPageNode.position({
  1557. "relativeTo": this.node,
  1558. "position": "topRight",
  1559. "edge": "topRight",
  1560. "offset": {
  1561. "x": -10,
  1562. "y": 45
  1563. }
  1564. });
  1565. //this.form.notice(MWF.xApplication.process.Xform.LP.computePage, "info", this.node);
  1566. },
  1567. clearWaitSplitPage: function(){
  1568. this.node.unmask();
  1569. if (this.waitSplitPageNode) this.waitSplitPageNode.destroy();
  1570. this.waitSplitPageNode = null;
  1571. },
  1572. _doublePage: function(){
  1573. if (this.editMode) this._switchReadOrEditInline();
  1574. this.zoom(1);
  1575. this.createWaitSplitPage();
  1576. window.setTimeout(function(){
  1577. this._checkSplitPage(this.pages[0]);
  1578. this.zoom(1);
  1579. var w = this.contentNode.getSize().x;
  1580. var toPageWidth = (w-100)/2;
  1581. scale = toPageWidth/this.options.docPageFullWidth;
  1582. if (scale<1) this.zoom(scale);
  1583. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1584. //var docPageFullWidth = this.options.docPageFullWidth;
  1585. var w = this.contentNode.getSize().x;
  1586. var count = (w/docPageFullWidth).toInt();
  1587. var pages = this.contentNode.getElements(".doc_layout_page");
  1588. count = Math.min(pages.length, count);
  1589. var pageWidth = count * docPageFullWidth;
  1590. var margin = (w-pageWidth)/(count+1);
  1591. if (this.scale) margin = margin/(this.scale);
  1592. this.pages.each(function(page, i){
  1593. page.setStyles({
  1594. "float": "left",
  1595. "margin-left": ""+margin+"px"
  1596. });
  1597. });
  1598. // this.pages.each(function(page, i){
  1599. // if ((i % 2)===0){
  1600. // page.setStyle("float", "left");
  1601. // }else{
  1602. // page.setStyle("float", "right");
  1603. // }
  1604. // });
  1605. this.resetNodeSize();
  1606. this.options.pageShow="double";
  1607. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
  1608. this.resizeSidebar();
  1609. this.clearWaitSplitPage();
  1610. }.bind(this), 1000);
  1611. },
  1612. _getDefaultData: function(){
  1613. return Object.clone(this.json.defaultValue);
  1614. //return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
  1615. },
  1616. _loadFiletextPage: function(callback){
  1617. this.data = this._getBusinessData();
  1618. if (!this.data) this.data = this._getDefaultData();
  1619. this._computeData(true);
  1620. this._createPage(function(control){
  1621. this._loadPageLayout(control);
  1622. // this.data = this._getBusinessData();
  1623. // if (!this.data) this.data = this._getDefaultData();
  1624. this.setData(this.data);
  1625. // this._checkSplitPage(this.pages[0]);
  1626. //this._repage(true);
  1627. //this.loadCkeditorFiletext();
  1628. if (!this.readonly){
  1629. //if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
  1630. // if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
  1631. // if (this.json.allowEditSubject) this.loadCkeditorSubject();
  1632. // if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
  1633. // if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
  1634. // if (this.json.allowEditSigner) this.loadCkeditorSigner();
  1635. // if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
  1636. }
  1637. if (callback) callback();
  1638. }.bind(this));
  1639. },
  1640. _getEditorConfig: function(){
  1641. // var mathElements = [
  1642. // 'math',
  1643. // 'maction',
  1644. // 'maligngroup',
  1645. // 'malignmark',
  1646. // 'menclose',
  1647. // 'merror',
  1648. // 'mfenced',
  1649. // 'mfrac',
  1650. // 'mglyph',
  1651. // 'mi',
  1652. // 'mlabeledtr',
  1653. // 'mlongdiv',
  1654. // 'mmultiscripts',
  1655. // 'mn',
  1656. // 'mo',
  1657. // 'mover',
  1658. // 'mpadded',
  1659. // 'mphantom',
  1660. // 'mroot',
  1661. // 'mrow',
  1662. // 'ms',
  1663. // 'mscarries',
  1664. // 'mscarry',
  1665. // 'msgroup',
  1666. // 'msline',
  1667. // 'mspace',
  1668. // 'msqrt',
  1669. // 'msrow',
  1670. // 'mstack',
  1671. // 'mstyle',
  1672. // 'msub',
  1673. // 'msup',
  1674. // 'msubsup',
  1675. // 'mtable',
  1676. // 'mtd',
  1677. // 'mtext',
  1678. // 'mtr',
  1679. // 'munder',
  1680. // 'munderover',
  1681. // 'semantics',
  1682. // 'annotation',
  1683. // 'annotation-xml'
  1684. // ];
  1685. //CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.13.0/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
  1686. debugger;
  1687. var editorConfig = {
  1688. qtRows: 20, // Count of rows
  1689. qtColumns: 20, // Count of columns
  1690. qtBorder: '1', // Border of inserted table
  1691. qtWidth: '95%', // Width of inserted table
  1692. qtStyle: { 'border-collapse' : 'collapse' },
  1693. qtClass: 'documenteditor_table'+this.form.json.id+this.json.id, // Class of table
  1694. qtCellPadding: '0', // Cell padding table
  1695. qtCellSpacing: '0', // Cell spacing table
  1696. qtPreviewBorder: '4px double black', // preview table border
  1697. qtPreviewSize: '4px', // Preview table cell size
  1698. qtPreviewBackground: '#c8def4', // preview table background (hover)
  1699. // format_tags: '标题一;标题二;标题三;标题四;正文', // entries is displayed in "Paragraph format"
  1700. format_tags: '标题一;标题二;正文(标题三,四)', // entries is displayed in "Paragraph format"
  1701. 'format_标题一': {
  1702. name: '标题一(三号黑体)',
  1703. element: 'div',
  1704. styles: {
  1705. 'font-family': '黑体',
  1706. 'font-size': '16pt'
  1707. }
  1708. },
  1709. 'format_标题二': {
  1710. name: '标题二(三号楷体)',
  1711. element: 'div',
  1712. styles: {
  1713. 'font-family': '楷体',
  1714. 'font-size': '16pt'
  1715. }
  1716. },
  1717. // 'format_标题三': {
  1718. // name: '标题三',
  1719. // element: 'div',
  1720. // styles: {
  1721. // 'font-family': '仿宋',
  1722. // 'font-size': '16pt'
  1723. // }
  1724. // },
  1725. // 'format_标题四': {
  1726. // name: '标题四',
  1727. // element: 'div',
  1728. // styles: {
  1729. // 'font-family': '仿宋',
  1730. // 'font-size': '16pt'
  1731. // }
  1732. // },
  1733. 'format_正文(标题三,四)': {
  1734. name: '正文(标题三,四)',
  1735. element: 'div',
  1736. styles: {
  1737. 'font-family': '仿宋',
  1738. 'font-size': '16pt'
  1739. }
  1740. }
  1741. };
  1742. editorConfig.toolbarGroups = [
  1743. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  1744. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  1745. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  1746. { name: 'forms', groups: [ 'forms' ] },
  1747. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  1748. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  1749. { name: 'links', groups: [ 'links' ] },
  1750. { name: 'insert', groups: [ 'insert' ] },
  1751. { name: 'styles', groups: [ 'styles' ] },
  1752. { name: 'colors', groups: [ 'colors' ] },
  1753. { name: 'tools', groups: [ 'tools' ] },
  1754. { name: 'others', groups: [ 'others' ] },
  1755. { name: 'about', groups: [ 'about' ] }
  1756. ];
  1757. //editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,mathjax,ckeditor_wiris";
  1758. //editorConfig.extraPlugins = "ecnet,colordialog,quicktable,tableresize,eqneditor";
  1759. //editorConfig.extraPlugins = "tableresize,quicktable";
  1760. editorConfig.extraPlugins = "quicktable,tableresize";
  1761. //editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
  1762. 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';
  1763. //editorConfig.extraAllowedContent = mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)';
  1764. editorConfig.pasteFromWordRemoveFontStyles = false;
  1765. editorConfig.pasteFromWordRemoveStyles = false;
  1766. //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';
  1767. editorConfig.removePlugins = ['magicline'];
  1768. editorConfig.enterMode = 3;
  1769. // editorConfig.extraPlugins = ['ecnet','mathjax'];
  1770. // editorConfig.removePlugins = ['magicline'];
  1771. // editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
  1772. return editorConfig;
  1773. },
  1774. _checkSplitPage: function(pageNode){
  1775. if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
  1776. var contentNode = pageNode.getFirst();
  1777. if (contentNode.getSize().y>this.options.docPageHeight){
  1778. this._splitPage(pageNode);
  1779. }
  1780. var i = pageNode.get("data-pagecount").toInt();
  1781. if (i && this.pages.length-1>=i){
  1782. this._checkSplitPage(this.pages[i]);
  1783. }
  1784. if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
  1785. },
  1786. _splitFiletextNodeOneWord:function(lnode, nextPageNode){
  1787. var text = lnode.textContent;
  1788. var len = text.length;
  1789. var left = text.substring(0, len-1);
  1790. var right = text.substring(len-1, len);
  1791. lnode.textContent = left;
  1792. nextPageNode.textContent = right+nextPageNode.textContent;
  1793. //nextPageNode.appendText(right, "top");
  1794. },
  1795. _splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
  1796. var contentNode = pageNode.getFirst();
  1797. var lnode = node.lastChild;
  1798. if (!lnode){
  1799. if (node.parentNode) node.parentNode.removeChild(node);
  1800. //node.remove();
  1801. }else{
  1802. while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
  1803. var tmpnode = lnode.previousSibling;
  1804. var nodeType = lnode.nodeType;
  1805. if (!nextPageNode) nextPageNode = nextFiletextNode;
  1806. if (nodeType == Node.ELEMENT_NODE) {
  1807. if (lnode.tagName == "table") {
  1808. lnode.inject(nextPageNode);
  1809. } else if (lnode.tagName == "BR") {
  1810. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1811. } else {
  1812. var id = lnode.get("data-pagePart");
  1813. if (!id){
  1814. id = (new o2.widget.UUID()).toString();
  1815. lnode.set("data-pagePart", id);
  1816. }
  1817. var tmpNode = nextPageNode.getFirst();
  1818. if (tmpNode && tmpNode.get("data-pagePart")==id){
  1819. nextPageNode = tmpNode;
  1820. }else{
  1821. nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
  1822. }
  1823. //var subnode = lnode.getLast();
  1824. this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
  1825. if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1826. nextPageNode = nextPageNode.getParent();
  1827. }
  1828. } else if (nodeType == Node.TEXT_NODE) {
  1829. var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
  1830. while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
  1831. //console.log(contentNode.getSize().y);
  1832. this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
  1833. }
  1834. if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
  1835. } else {
  1836. //lnode.remove();
  1837. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1838. }
  1839. lnode = tmpnode;
  1840. }
  1841. if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
  1842. }
  1843. //this._checkSplitPage(pageNode);
  1844. },
  1845. _splitPage: function(pageNode){
  1846. var contentNode = pageNode.getFirst();
  1847. var blockNodes = pageNode.getElements(".doc_block");
  1848. if (blockNodes.length){
  1849. var blockNode = blockNodes[blockNodes.length-1];
  1850. var idx = this.pages.indexOf(pageNode);
  1851. if (this.pages.length<=idx+1) this._createNewPage();
  1852. var nextPage = this.pages[idx+1];
  1853. if (blockNode.hasClass("doc_layout_filetext")){
  1854. var filetextNode = nextPage.getElement(".doc_layout_filetext");
  1855. if (!filetextNode){
  1856. filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
  1857. //filetextNode.setAttribute('contenteditable', true);
  1858. }
  1859. if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
  1860. //var nextEditor = filetextNode.retrieve("editor");
  1861. var node = blockNode;
  1862. var nextPageNode = filetextNode;
  1863. this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
  1864. }else{
  1865. blockNode.inject(nextPage.getFirst(), "top");
  1866. //var contentNode = pageNode.getFirst();
  1867. if (contentNode.getSize().y>this.options.docPageHeight){
  1868. this._splitPage(pageNode);
  1869. }
  1870. }
  1871. }
  1872. },
  1873. transWidth: function(node){
  1874. if (!node) return '';
  1875. while (node){
  1876. if (node.nodeType==3){
  1877. node.nodeValue = node.nodeValue.replace(/\x20/g, " ");
  1878. }else if (node.nodeType==8){
  1879. //nothing
  1880. }else{
  1881. this.transWidth(node.firstChild);
  1882. }
  1883. node = node.nextSibling;
  1884. }
  1885. },
  1886. insertFullWidth: function(node, txt){
  1887. if (!node) return '';
  1888. while (node){
  1889. if (node.nodeType==3){
  1890. node.nodeValue = txt+node.nodeValue;
  1891. return true;
  1892. }else if (node.nodeType==8){
  1893. //nothing
  1894. }else{
  1895. var flag = this.insertFullWidth(node.firstChild, txt);
  1896. if (flag) return true;
  1897. }
  1898. node = node.nextSibling;
  1899. }
  1900. },
  1901. loadCkeditorFiletext: function(callback, inline){
  1902. if (this.layout_filetext){
  1903. o2.load("../o2_lib/htmleditor/ckeditor4130/ckeditor.js", function(){
  1904. CKEDITOR.disableAutoInline = true;
  1905. this.layout_filetext.setAttribute('contenteditable', true);
  1906. if (inline){
  1907. this.filetextEditor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1908. }else{
  1909. this.filetextEditor = CKEDITOR.replace(this.layout_filetext, this._getEditorConfig());
  1910. }
  1911. this.filetextEditor.on("instanceReady", function(e){
  1912. if (callback) callback(e);
  1913. }.bind(this));
  1914. this.filetextEditor.on( 'focus', function( e ) {
  1915. window.setTimeout(this.reLocationFiletextToolbar.bind(this), 10);
  1916. }.bind(this) );
  1917. this.filetextEditor.on( 'paste', function( e ) {
  1918. var html = e.data.dataValue;
  1919. //if (this.json.fullWidth=="y") html = html.replace(/\x20/g, " ");
  1920. var tmp = new Element("div")
  1921. tmp.set("html", html);
  1922. var pList = tmp.getElements("p");
  1923. pList.each(function(p, i){
  1924. //if (Browser.name=="ie"){
  1925. if (this.json.fullWidth!=="n") this.transWidth(p);
  1926. if (!p.getParent("table")){
  1927. var text = p.get("text");
  1928. var rex = /^\u3000*/;
  1929. var m = text.match(rex);
  1930. var l = (m[0]) ? Math.max((2-m[0].length), 0): 2;
  1931. var txt = "";
  1932. // for (var i=0; i<l; i++) txt+=" ";
  1933. // this.insertFullWidth(p.getFirst(), txt);
  1934. for (var i=0; i<l; i++) p.appendText(" ","top");
  1935. }
  1936. //}else{
  1937. // var textIndent = p.getStyle("text-indent");
  1938. // if (textIndent.toInt()) p.appendText("  ","top");
  1939. //}
  1940. }.bind(this));
  1941. e.data.dataValue = tmp.get("html");
  1942. tmp.destroy();
  1943. }.bind(this) );
  1944. if (this.json.textIndent!=="n"){
  1945. // this.filetextEditor.addCommand( 'textIndent_P', {
  1946. // exec: function( editor ) {
  1947. // debugger;
  1948. // editor.insertHtml("<br><div>  </div>");
  1949. // }
  1950. // } );
  1951. // this.filetextEditor.setKeystroke( CKEDITOR.CTRL + 13, 'textIndent_P' );
  1952. this.layout_filetext.addEvent("keyup", function(ev){
  1953. if (ev.code==13) this.filetextEditor.insertText("  ");
  1954. }.bind(this));
  1955. //
  1956. // this.filetextEditor.on("key", function(e){
  1957. // if (e.data.keyCode==13){
  1958. // e.editor.insertText("  ");
  1959. // //e.cancel();
  1960. // }
  1961. // }.bind(this));
  1962. }
  1963. if (this.json.fullWidth!=="n"){
  1964. this.filetextEditor.addCommand( 'insertHalfSpace', {
  1965. exec: function( editor ) {
  1966. editor.insertText(" ");
  1967. }
  1968. } );
  1969. this.filetextEditor.setKeystroke( CKEDITOR.SHIFT + 32, 'insertHalfSpace' );
  1970. this.filetextEditor.on("key", function(e){
  1971. if (this.json.fullWidth!=="n") if (e.data.keyCode==32){
  1972. e.editor.insertText(" ");
  1973. e.cancel();
  1974. }
  1975. }.bind(this));
  1976. }
  1977. }.bind(this));
  1978. }
  1979. },
  1980. _loadEvents: function(editorConfig){
  1981. Object.each(this.json.events, function(e, key){
  1982. if (e.code){
  1983. this.editor.on(key, function(event){
  1984. return this.form.Macro.fire(e.code, this, event);
  1985. }.bind(this), this);
  1986. }
  1987. }.bind(this));
  1988. },
  1989. _bindFieldChange: function(name,dataItem, dom){
  1990. var field = this.form.all[this.json[dataItem]];
  1991. if (field){
  1992. var bindFun = function(){
  1993. this._computeItemFieldData(name, dataItem);
  1994. //if (this.data[name]){
  1995. if (this[dom]){
  1996. if (dom=="layout_redHeader" || dom=="layout_subject" || dom=="layout_issuanceUnit" || dom=="layout_meetingAttendContent" || dom=="layout_meetingLeaveContent" || dom=="layout_meetingSitContent" || dom=="layout_meetingRecordContent"){
  1997. this[dom].set("html", this.data[name]|| "");
  1998. }else if (dom=="layout_attachment"){
  1999. this.setAttachmentData();
  2000. }else{
  2001. this[dom].set("text", this.data[name]|| "");
  2002. }
  2003. }
  2004. this.reSetShow();
  2005. //}
  2006. }.bind(this);
  2007. field.node.store(this.json.id+"bindFun", bindFun);
  2008. field.addModuleEvent("change", bindFun);
  2009. }
  2010. },
  2011. _computeItemFieldData: function(name, dataItem, dataItemNode){
  2012. var v = "";
  2013. var module = (dataItemNode) ? this.form.all[dataItemNode] : this.form.all[this.json[dataItem]];
  2014. if (module && module.getData) v = module.getData();
  2015. if (!v) v = (dataItemNode) ? this.form.businessData.data[dataItemNode] : this.form.businessData.data[this.json[dataItem]];
  2016. if (v){
  2017. var t = o2.typeOf(v);
  2018. switch (t) {
  2019. case "string":
  2020. switch (name) {
  2021. case "issuanceDate":
  2022. case "editionDate":
  2023. var d = new Date(v);
  2024. debugger;
  2025. if (d.isValid() && d.getFullYear()!=1970){
  2026. var y = d.getFullYear();
  2027. var m = d.getMonth();
  2028. var day = d.getDate();
  2029. m = m +1;
  2030. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  2031. }else{
  2032. this.data[name] = v;
  2033. }
  2034. //this.data[name] = (new Date(v).isValid()) ? Date.parse(v).format("%Y年%m月%d%日") : v;
  2035. break;
  2036. case "mainSend":
  2037. this.data[name] = v + ":";
  2038. break;
  2039. default:
  2040. this.data[name] = v;
  2041. }
  2042. break;
  2043. case "array":
  2044. var strs = [];
  2045. v.each(function(value){
  2046. if (o2.typeOf(value)=="object" && value.distinguishedName){
  2047. strs.push(value.name);
  2048. }else{
  2049. strs.push(value.toString());
  2050. }
  2051. });
  2052. //if (strs.length){
  2053. switch (name) {
  2054. case "attachment":
  2055. // this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>");
  2056. var atts = strs.map(function(a){
  2057. return (a.indexOf(".")!=-1) ? a.substring(0, a.lastIndexOf(".")) : a;
  2058. });
  2059. this.data[name] = atts;
  2060. break;
  2061. case "issuanceDate":
  2062. case "editionDate":
  2063. var tmpStrs = strs.map(function(n, i){
  2064. var d = Date.parse(n);
  2065. if (d.isValid() && d.getFullYear()!=1970){
  2066. var y = d.getFullYear();
  2067. var m = d.getMonth();
  2068. var day = d.getDate();
  2069. m = m +1;
  2070. return ""+y+"年"+m+"月"+day+"日";
  2071. }else{
  2072. return n;
  2073. }
  2074. //return () ? d.format("%Y年%m月%d日") : n;
  2075. });
  2076. this.data[name] = tmpStrs.join(",");
  2077. break;
  2078. case "mainSend":
  2079. this.data[name] = strs.join(",") + ":";
  2080. break;
  2081. default:
  2082. this.data[name] = strs.join(",");
  2083. }
  2084. //}
  2085. break;
  2086. default:
  2087. this.data[name] = v.toString();
  2088. }
  2089. }else{
  2090. this.data[name] = this.json.defaultValue[name];
  2091. }
  2092. },
  2093. computeData: function(){
  2094. this._computeData(false);
  2095. this.setData(this.data);
  2096. },
  2097. _computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
  2098. switch (this.json[typeItem]) {
  2099. case "data":
  2100. if (this.json[dataItem]){
  2101. if (ev) this._bindFieldChange(name, dataItem, dom);
  2102. this._computeItemFieldData(name, dataItem);
  2103. }
  2104. break;
  2105. case "script":
  2106. if (this.json[scriptItem] && this.json[scriptItem].code){
  2107. var v = this.form.Macro.exec(this.json[scriptItem].code, this);
  2108. this.data[name] = v;
  2109. if (name=="attachment"){
  2110. //this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>") : v;
  2111. this.data[name] = (typeOf(v)=="array") ? v : [v];
  2112. }
  2113. if (name=="issuanceDate" || name=="editionDate"){
  2114. var d = Date.parse(v);
  2115. if (d.isValid() && d.getFullYear()!=1970){
  2116. var y = d.getFullYear();
  2117. var m = d.getMonth();
  2118. var day = d.getDate();
  2119. m = m +1;
  2120. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  2121. }else{
  2122. this.data[name] = v;
  2123. }
  2124. //this.data[name] = (d.isValid() && d.getFullYear()!=1970) ? d.format("%Y年%m月%d日") : v;
  2125. }
  2126. }
  2127. break;
  2128. }
  2129. },
  2130. _computeCustomItemData: function(name, field, ev){
  2131. //if (this.json.customFields[l.name]){
  2132. if (ev) this._bindCustomFieldChange(name, field, name);
  2133. this._computeItemFieldData(name, null, field);
  2134. //}
  2135. },
  2136. _bindCustomFieldChange: function(name, dataItem, dom){
  2137. var field = this.form.all[dataItem];
  2138. if (field){
  2139. var bindFun = function(){
  2140. this._computeItemFieldData(name, null, dataItem);
  2141. //if (this.data[name]){
  2142. if (this[dom]){
  2143. debugger;
  2144. if (dom=="layout_redHeader" || dom=="layout_subject" || dom=="layout_issuanceUnit"){
  2145. this[dom].set("html", this.data[name]|| "");
  2146. }else if (dom=="layout_attachment"){
  2147. this.setAttachmentData();
  2148. }else{
  2149. this[dom].set("text", this.data[name]|| "");
  2150. }
  2151. }
  2152. this.reSetShow();
  2153. //}
  2154. }.bind(this);
  2155. field.node.store(this.json.id+"bindFun", bindFun);
  2156. field.addModuleEvent("change", bindFun);
  2157. }
  2158. },
  2159. _computeData: function(ev){
  2160. this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
  2161. this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
  2162. this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
  2163. this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
  2164. this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
  2165. this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
  2166. this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
  2167. this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
  2168. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
  2169. this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
  2170. this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
  2171. this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
  2172. this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
  2173. this._computeItemData("copyto2", "copyto2ValueType", "copyto2ValueData", "copyto2ValueScript", ev, "layout_copyto2Content");
  2174. this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
  2175. this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
  2176. this._computeItemData("meetingAttend", "meetingAttendValueType", "meetingAttendValueData", "meetingAttendValueScript", ev, "layout_meetingAttendContent");
  2177. this._computeItemData("meetingLeave", "meetingLeaveValueType", "meetingLeaveValueData", "meetingLeaveValueScript", ev, "layout_meetingLeaveContent");
  2178. this._computeItemData("meetingSit", "meetingSitValueType", "meetingSitValueData", "meetingSitValueScript", ev, "layout_meetingSitContent");
  2179. this._computeItemData("meetingRecord", "meetingRecordValueType", "meetingRecordValueData", "meetingRecordValueScript", ev, "layout_meetingRecordContent");
  2180. Object.each(this.json.customFields, function(field, k){
  2181. this._computeCustomItemData(k, field, ev);
  2182. }.bind(this));
  2183. // if (this.customLayouts){
  2184. // this.customLayouts.each(function(l){
  2185. // this._computeCustomItemData(l, ev);
  2186. // }.bind(this))
  2187. // }
  2188. },
  2189. _loadValue: function(){
  2190. var data = this._getBusinessData();
  2191. },
  2192. reload: function(){
  2193. this.resetData();
  2194. },
  2195. resetData: function(diffFiletext){
  2196. if (this.editMode){ this._switchReadOrEditInline(); }
  2197. this._computeData(false);
  2198. this.pages = [];
  2199. this.contentNode.empty();
  2200. if (this.allowEdit) this.toolbar.childrenButton[0].setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdoc_mobile : MWF.xApplication.process.Xform.LP.editdoc);
  2201. this.editMode = false;
  2202. this._createPage(function(control){
  2203. this._loadPageLayout(control);
  2204. this.setData(this.data, diffFiletext);
  2205. //this._checkSplitPage(this.pages[0]);
  2206. debugger;
  2207. this._repage();
  2208. }.bind(this));
  2209. },
  2210. isEmpty: function(){
  2211. var data = this.getData();
  2212. if( typeOf(data) !== "object" )return true;
  2213. return !data.filetext || data.filetext===this.json.defaultValue.filetext;
  2214. },
  2215. getData: function(){
  2216. //if (this.editMode){
  2217. debugger;
  2218. if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
  2219. if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
  2220. if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
  2221. if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
  2222. if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
  2223. if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
  2224. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  2225. if (this.layout_subject) this.data.subject = this.layout_subject.get("html");
  2226. if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
  2227. if (this.editMode) if (this.layout_filetext){
  2228. var text = this.layout_filetext.get("text");
  2229. text = text.replace(/\u3000*/g, "");
  2230. if (text && text !==this.json.defaultValue.filetext){
  2231. this.data.filetext = this.layout_filetext.get("html");
  2232. }else{
  2233. this.data.filetext = "";
  2234. }
  2235. }
  2236. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  2237. if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
  2238. if (this.layout_attachment){
  2239. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", false, "layout_attachment");
  2240. // var atts = [];
  2241. // var nodes = this.layout_attachment.getElements(".doc_layout_attachment_content_name");
  2242. // if (nodes.length){
  2243. // nodes.each(function(node){
  2244. // atts.push(node.get("text"));
  2245. // });
  2246. // }
  2247. // this.data.attachment = atts;
  2248. }
  2249. if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("html");
  2250. if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
  2251. if (this.layout_annotation) this.data.annotation = this.layout_annotation.get("text");
  2252. if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
  2253. if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
  2254. if (this.layout_copyto2Title) this.data.copyto2Title = this.layout_copyto2Title.get("text");
  2255. if (this.layout_copyto2Content) this.data.copyto2 = this.layout_copyto2Content.get("text");
  2256. if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
  2257. if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
  2258. if (this.layout_meetingAttendTitle) this.data.meetingAttendTitle = this.layout_meetingAttendTitle.get("text");
  2259. if (this.layout_meetingLeaveTitle) this.data.meetingLeaveTitle = this.layout_meetingLeaveTitle.get("text");
  2260. if (this.layout_meetingSitTitle) this.data.meetingSitTitle = this.layout_meetingSitTitle.get("text");
  2261. if (this.layout_meetingAttendContent) this.data.meetingAttend = this.layout_meetingAttendContent.get("html");
  2262. if (this.layout_meetingLeaveContent) this.data.meetingLeave = this.layout_meetingLeaveContent.get("html");
  2263. if (this.layout_meetingSitContent) this.data.meetingSit = this.layout_meetingSitContent.get("html");
  2264. if (this.layout_meetingRecordContent) this.data.meetingRecord = this.layout_meetingRecordContent.get("html");
  2265. if (this.customLayouts){
  2266. this.customLayouts.each(function(l){
  2267. this.data[l.name] = l.node.get("html");
  2268. }.bind(this))
  2269. }
  2270. //}
  2271. return this.data;
  2272. },
  2273. setAttachmentData: function(){
  2274. if (!this.attachmentTemplete){
  2275. this.attachmentTemplete = this.layout_attachment.get("html");
  2276. }
  2277. this.layout_attachment.empty();
  2278. if (this.data.attachment && this.data.attachment.length && this.data.attachment.each){
  2279. //var tmpdiv = new Element("div", {"styles": {"display":"none"}}).inject(document.body);
  2280. var tmpdiv = new Element("div");
  2281. this.data.attachment.each(function(name, idx){
  2282. tmpdiv.set("html", this.attachmentTemplete);
  2283. var serialNode = tmpdiv.getElement(".doc_layout_attachment_content_serial");
  2284. var nameNode = tmpdiv.getElement(".doc_layout_attachment_content_name");
  2285. if (serialNode) serialNode.set("text", idx+1);
  2286. if (nameNode) nameNode.set("text", name);
  2287. var html = tmpdiv.get("html");
  2288. tmpdiv.empty();
  2289. this.layout_attachment.appendHTML(html);
  2290. }.bind(this));
  2291. tmpdiv.destroy();
  2292. }
  2293. },
  2294. setData: function(data, diffFiletext){
  2295. if (data){
  2296. this.data = data;
  2297. // this.data["$json"] = this.json;
  2298. this._setBusinessData(data);
  2299. if (this.layout_copies){
  2300. if (data.copies){
  2301. this.layout_copies.set("text", data.copies || " ");
  2302. }else{
  2303. this.layout_copies.set("html", "<span>&nbsp</span>");
  2304. }
  2305. }
  2306. if (this.layout_secret){
  2307. if (data.secret){
  2308. this.layout_secret.set("text", data.secret || " ");
  2309. }else{
  2310. this.layout_secret.set("html", "<span>&nbsp</span>");
  2311. }
  2312. }
  2313. if (this.layout_priority){
  2314. if (data.priority){
  2315. this.layout_priority.set("text", data.priority || " ");
  2316. }else{
  2317. this.layout_priority.set("html", "<span>&nbsp</span>");
  2318. }
  2319. }
  2320. if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
  2321. if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
  2322. if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
  2323. if (this.layout_signer) this.layout_signer.set("text", data.signer || " ");
  2324. if (this.layout_subject) this.layout_subject.set("html", data.subject || " ");
  2325. if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
  2326. if (diffFiletext) {
  2327. this.layout_filetext.set("html", diffFiletext);
  2328. }else if (this.layout_filetext){
  2329. //this.layout_filetext.set("placeholder", this.json.defaultValue.filetext);
  2330. this.layout_filetext.set("html", data.filetext || "  ");
  2331. }
  2332. if (this.layout_signer) this.layout_signer.set("text", data.signer || "");
  2333. if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
  2334. if (this.layout_attachment){
  2335. this.setAttachmentData();
  2336. }
  2337. if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("html", data.issuanceUnit || " ");
  2338. if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
  2339. if (this.layout_annotation) this.layout_annotation.set("text", data.annotation || " ");
  2340. if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
  2341. if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
  2342. if (this.layout_copyto2Title) this.layout_copyto2Title.set("text", data.copyto2Title || " ");
  2343. if (this.layout_copyto2Content) this.layout_copyto2Content.set("text", data.copyto2 || " ");
  2344. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
  2345. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
  2346. if (this.layout_meetingAttendTitle) this.layout_meetingAttendTitle.set("text", data.meetingAttendTitle || this.json.defaultValue.meetingAttendTitle || " ");
  2347. if (this.layout_meetingLeaveTitle) this.layout_meetingLeaveTitle.set("text", data.meetingLeaveTitle || this.json.defaultValue.meetingLeaveTitle || " ");
  2348. if (this.layout_meetingSitTitle) this.layout_meetingSitTitle.set("text", data.meetingSitTitle || this.json.defaultValue.meetingSitTitle || " ");
  2349. if (this.layout_meetingAttendContent) this.layout_meetingAttendContent.set("html", data.meetingAttend || " ");
  2350. if (this.layout_meetingLeaveContent) this.layout_meetingLeaveContent.set("html", data.meetingLeave || " ");
  2351. if (this.layout_meetingSitContent) this.layout_meetingSitContent.set("html", data.meetingSit || " ");
  2352. if (this.layout_meetingRecordContent) this.layout_meetingRecordContent.set("html", data.meetingRecord || " ");
  2353. if (this.customLayouts){
  2354. this.customLayouts.each(function(l){
  2355. l.node.set("html", this.data[l.name] || " ");
  2356. }.bind(this))
  2357. }
  2358. debugger;
  2359. if (this.layout_issuanceUnit && this.layout_issuanceDate ){
  2360. var table = this.layout_issuanceUnit.getParent("table")
  2361. if (table && !table.hasClass("doc_layout_headIssuance")){
  2362. var unitWidth = o2.getTextSize(this.layout_issuanceUnit.get("text"), {
  2363. "font-size":"16pt",
  2364. "font-family":"'Times New Roman',仿宋",
  2365. "letter-spacing": "-0.4pt"
  2366. }).x;
  2367. var dateWidth = o2.getTextSize(this.layout_issuanceDate.get("text"), {
  2368. "font-size":"16pt",
  2369. "font-family":"'Times New Roman',仿宋",
  2370. "letter-spacing": "-0.4pt"
  2371. }).x;
  2372. // var unitWidth = this.layout_issuanceUnit.getSize().x;
  2373. // var dateWidth = this.layout_issuanceDate.getSize().x;
  2374. if (unitWidth<dateWidth){
  2375. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  2376. if (flagTd){
  2377. var pt = ((dateWidth-unitWidth)/96)*72 +32+32;
  2378. flagTd.setStyle("width", ""+pt+"pt");
  2379. }
  2380. table = this.layout_issuanceDate.getParent("table");
  2381. table.setStyle("width", "auto");
  2382. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  2383. if (flagTd) flagTd.setStyle("width", "32pt");
  2384. var p = this.layout_issuanceDate.getParent("p");
  2385. if (p) p.setStyle("text-align", "right");
  2386. }else{
  2387. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  2388. if (flagTd) flagTd.setStyle("width", "32pt");
  2389. var table = this.layout_issuanceUnit.getParent("table");
  2390. var x = table.getSize().x;
  2391. table = this.layout_issuanceDate.getParent("table");
  2392. table.setStyle("width", ""+x+"px");
  2393. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  2394. if (flagTd) flagTd.setStyle("width", "32pt");
  2395. var p = this.layout_issuanceDate.getParent("p");
  2396. if (p) p.setStyle("text-align", "center");
  2397. }
  2398. }
  2399. }
  2400. var coptyToTitleNode = (this.layout_copytoTitle || this.layout_copyto2Title);
  2401. if (coptyToTitleNode){
  2402. var editionTable = coptyToTitleNode.getParent("table");
  2403. if (editionTable) if (editionTable.get("data-compute-style")=="y"){
  2404. var rows = editionTable.rows;
  2405. for (var i=0; i<rows.length; i++){
  2406. var cell = rows[i].cells[0];
  2407. var tmp = cell.getElement(".doc_layout_edition_issuance_unit");
  2408. if (!tmp) tmp = cell.getElement(".doc_layout_edition_issuance_date");
  2409. if (!tmp){
  2410. var text = cell.get("text").trim();
  2411. var l = 14*text.length;
  2412. var wl = 19*text.length;
  2413. cell.setStyles({
  2414. "max-width": ""+l+"pt !important",
  2415. "min-width": ""+l+"pt !important",
  2416. "width": ""+wl+"pt"
  2417. });
  2418. }
  2419. }
  2420. }
  2421. }
  2422. }
  2423. },
  2424. createErrorNode: function(text){
  2425. var node = new Element("div");
  2426. var iconNode = new Element("div", {
  2427. "styles": {
  2428. "width": "20px",
  2429. "height": "20px",
  2430. "float": "left",
  2431. "background": "url("+"../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  2432. }
  2433. }).inject(node);
  2434. var textNode = new Element("div", {
  2435. "styles": {
  2436. "line-height": "20px",
  2437. "margin-left": "20px",
  2438. "color": "red",
  2439. "word-break": "keep-all"
  2440. },
  2441. "text": text
  2442. }).inject(node);
  2443. return node;
  2444. },
  2445. notValidationMode: function(text){
  2446. if (!this.isNotValidationMode){
  2447. this.isNotValidationMode = true;
  2448. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  2449. this.node.setStyle("border", "1px solid red");
  2450. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  2451. this.showNotValidationMode(this.node);
  2452. }
  2453. },
  2454. showNotValidationMode: function(node){
  2455. var p = node.getParent("div");
  2456. if (p){
  2457. if (p.get("MWFtype") == "tab$Content"){
  2458. if (p.getParent("div").getStyle("display")=="none"){
  2459. var contentAreaNode = p.getParent("div").getParent("div");
  2460. var tabAreaNode = contentAreaNode.getPrevious("div");
  2461. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  2462. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  2463. tabNode.click();
  2464. p = tabAreaNode.getParent("div");
  2465. }
  2466. }
  2467. this.showNotValidationMode(p);
  2468. }
  2469. },
  2470. validationMode: function(){
  2471. if (this.isNotValidationMode){
  2472. this.isNotValidationMode = false;
  2473. this.node.setStyles(this.node.retrieve("borderStyle"));
  2474. if (this.errNode){
  2475. this.errNode.destroy();
  2476. this.errNode = null;
  2477. }
  2478. }
  2479. },
  2480. validationConfigItem: function(routeName, data){
  2481. var flag = (data.status=="all") ? true: (routeName == data.decision);
  2482. if (flag){
  2483. var n = this.getData();
  2484. var v = (data.valueType=="value") ? n : n.length;
  2485. switch (data.operateor){
  2486. case "isnull":
  2487. if (!v){
  2488. this.notValidationMode(data.prompt);
  2489. return false;
  2490. }
  2491. break;
  2492. case "notnull":
  2493. if (v){
  2494. this.notValidationMode(data.prompt);
  2495. return false;
  2496. }
  2497. break;
  2498. case "gt":
  2499. if (v>data.value){
  2500. this.notValidationMode(data.prompt);
  2501. return false;
  2502. }
  2503. break;
  2504. case "lt":
  2505. if (v<data.value){
  2506. this.notValidationMode(data.prompt);
  2507. return false;
  2508. }
  2509. break;
  2510. case "equal":
  2511. if (v==data.value){
  2512. this.notValidationMode(data.prompt);
  2513. return false;
  2514. }
  2515. break;
  2516. case "neq":
  2517. if (v!=data.value){
  2518. this.notValidationMode(data.prompt);
  2519. return false;
  2520. }
  2521. break;
  2522. case "contain":
  2523. if (v.indexOf(data.value)!=-1){
  2524. this.notValidationMode(data.prompt);
  2525. return false;
  2526. }
  2527. break;
  2528. case "notcontain":
  2529. if (v.indexOf(data.value)==-1){
  2530. this.notValidationMode(data.prompt);
  2531. return false;
  2532. }
  2533. break;
  2534. }
  2535. }
  2536. return true;
  2537. },
  2538. validationConfig: function(routeName, opinion){
  2539. if (this.json.validationConfig){
  2540. if (this.json.validationConfig.length){
  2541. for (var i=0; i<this.json.validationConfig.length; i++) {
  2542. var data = this.json.validationConfig[i];
  2543. if (!this.validationConfigItem(routeName, data)) return false;
  2544. }
  2545. }
  2546. return true;
  2547. }
  2548. return true;
  2549. },
  2550. validation: function(routeName, opinion){
  2551. if (!this.validationConfig(routeName, opinion)) return false;
  2552. if (!this.json.validation) return true;
  2553. if (!this.json.validation.code) return true;
  2554. var flag = this.form.Macro.exec(this.json.validation.code, this);
  2555. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  2556. if (flag.toString()!="true"){
  2557. this.notValidationMode(flag);
  2558. return false;
  2559. }
  2560. return true;
  2561. },
  2562. removeDisplayNone: function(node){
  2563. var n = node.getFirst();
  2564. while (n){
  2565. if (n.getStyle("display")=="none"){
  2566. var tmp = n.getNext();
  2567. n.destroy();
  2568. n = tmp;
  2569. }else{
  2570. n = this.removeDisplayNone(n);
  2571. n = n.getNext();
  2572. }
  2573. }
  2574. return node;
  2575. },
  2576. toWord: function(callback, name){
  2577. debugger;
  2578. var docNmae = name || "";
  2579. if (!docNmae){
  2580. try{
  2581. docNmae = this.json.toWordFilename || this.form.businessData.data.subject || this.form.businessData.data["$work"].title
  2582. }catch (e) {}
  2583. }
  2584. var toEdit = false;
  2585. if (this.editMode){
  2586. toEdit = true;
  2587. this._readFiletext();
  2588. }
  2589. //this._returnScale();
  2590. this.zoom(1);
  2591. this.pages = [];
  2592. this.contentNode.empty();
  2593. this._createPage(function(control){
  2594. this._loadPageLayout(control);
  2595. this.setData(this.data);
  2596. this._checkScale();
  2597. this.node.setStyles({
  2598. "height":"auto"
  2599. });
  2600. //var content = this.contentNode.getFirst().getFirst().get("html");
  2601. var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
  2602. var htmlNode = tmpNode.getLast();
  2603. htmlNode = this.removeDisplayNone(htmlNode);
  2604. var content = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"><head><meta charset=\"UTF-8\" /></head><body>"+tmpNode.get("html")+"</body></html>";
  2605. var fileName = docNmae || this.json.toWordFilename || "$doc";
  2606. var n = fileName.lastIndexOf(".");
  2607. var ex = fileName.substring(n, fileName.length).toLowerCase();
  2608. if (ex!==".doc" && ex!==".docx") fileName = fileName+".doc";
  2609. var body = {
  2610. "fileName": fileName,
  2611. "site": this.json.toWordSite || "$doc",
  2612. "content": content
  2613. };
  2614. o2.Actions.get("x_processplatform_assemble_surface").docToWord(this.form.businessData.work.id, body, function(json){
  2615. if (this.form.businessData.workCompleted){
  2616. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id,function(attjson){
  2617. if (callback) callback(attjson.data);
  2618. this.showToWord(attjson.data);
  2619. }.bind(this));
  2620. }else{
  2621. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id,function(attjson){
  2622. if (callback) callback(attjson.data);
  2623. this.showToWord(attjson.data);
  2624. }.bind(this));
  2625. }
  2626. }.bind(this));
  2627. tmpNode.destroy();
  2628. if (!toEdit){
  2629. this._readFiletext();
  2630. }else{
  2631. this._createEditor();
  2632. }
  2633. }.bind(this));
  2634. },
  2635. docToWord: function(){
  2636. var flag = true;
  2637. if (this.json.toWordConditionScript && this.json.toWordConditionScript.code){
  2638. flag = !!this.form.Macro.exec(this.json.toWordConditionScript.code, this);
  2639. }
  2640. if (flag){
  2641. this.toWord();
  2642. }
  2643. },
  2644. showToWord: function(att_word){
  2645. var site = this.json.toWordSite || "$doc";
  2646. var attModule = this.form.all[site];
  2647. if (attModule){
  2648. var atts = [];
  2649. attModule.attachmentController.attachments.each(function(att){
  2650. if (att.data.name!==att_word.name){
  2651. atts.push(att.data)
  2652. }
  2653. }.bind(this));
  2654. attModule.attachmentController.clear();
  2655. atts.each(function (att) {
  2656. //if (att.site===this.json.id || (this.json.isOpenInOffice && this.json.officeControlName===att.site)) this.attachmentController.addAttachment(att);
  2657. if ((att.site === attModule.json.id) && att.name!==att_word.name) attModule.attachmentController.addAttachment(att);
  2658. }.bind(this));
  2659. // attModule.attachmentController.reloadAttachments();
  2660. attModule.attachmentController.addAttachment(att_word);
  2661. }
  2662. }
  2663. });