Documenteditor.js 121 KB

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