Documenteditor.js 135 KB

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