Documenteditor.js 126 KB

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