Documenteditor.js 142 KB

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