Documenteditor.js 137 KB

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