Documenteditor.js 122 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656
  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) 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.layout_subject){
  663. if (!this.json.subjectValueData && this.json.subjectValueType=="data"){
  664. this.layout_subject.set("contenteditable", control.subject);
  665. this.layout_subject.addEvent("blur", function(){
  666. this.getData();
  667. }.bind(this))
  668. }
  669. }
  670. if (this.layout_issuanceUnit){
  671. if (!this.json.issuanceUnitValueData && this.json.issuanceUnitValueType=="data"){
  672. this.layout_issuanceUnit.set("contenteditable", control.issuanceUnit);
  673. this.layout_issuanceUnit.addEvent("blur", function(){
  674. this.getData();
  675. }.bind(this))
  676. }
  677. }
  678. // this.layout_subject.addEvent("keydown", function(e){
  679. // debugger;
  680. // if (this.json.subjectValueType=="data" && this.json.subjectValueData){
  681. // // var v = e.target.get("HTML");
  682. // // this.form.businessData.data[this.json.subjectValueData] = v
  683. // var module = this.form.all[this.json.subjectValueData];
  684. // if (module){
  685. // var bindFun = module.node.retrieve(this.json.id+"bindFun");
  686. // module.node
  687. // }
  688. // }
  689. // }.bind(this));
  690. },
  691. _loadUserInterface: function(callback){
  692. this.node.empty();
  693. this.node.setStyles(this.form.css.documentEditorNode);
  694. this.pages = [];
  695. this.allowEdit = this._isAllowEdit();
  696. this.allowPrint = this._isAllowPrint();
  697. this.allowHistory = this._isAllowHistory();
  698. this.toolNode = new Element("div", {"styles": this.css.doc_toolbar}).inject(this.node);
  699. this.contentNode = new Element("div", {"styles": this.css.doc_content}).inject(this.node);
  700. if (!this.form.isLoaded){
  701. this.form.addEvent("afterModulesLoad", function(){this.loadDocumentEditor(callback);}.bind(this));
  702. }else{
  703. this.loadDocumentEditor(callback);
  704. }
  705. },
  706. loadDocumentEditor: function(callback){
  707. this._loadToolbars();
  708. this._loadFiletextPage(function(){
  709. if (this.options.pageShow!=="double"){
  710. this._singlePage();
  711. }else{
  712. this._doublePage();
  713. }
  714. // this.form.addEvent("beforeProcess", function(){
  715. // this.resetData();
  716. // if (this.checkSaveNewEdition()) this.saveNewDataEdition();
  717. // this.notSaveResetData = true;
  718. // }.bind(this));
  719. this.form.addEvent("beforeSave", function(){
  720. this.resetData();
  721. this.checkSaveNewEdition();
  722. //if (!this.notSaveResetData) this.resetData();
  723. }.bind(this));
  724. if (this.json.toWord=="y"){
  725. if (this.json.toWordTrigger=="open") this.docToWord();
  726. if (this.json.toWordTrigger=="save") this.form.addEvent("beforeSave", this.docToWord.bind(this));
  727. if (this.json.toWordTrigger=="submit") this.form.addEvent("beforeProcess", this.docToWord.bind(this));
  728. }
  729. if (!layout.mobile) this.loadSideToolbar();
  730. o2.load("../o2_lib/diff-match-patch/diff_match_patch.js");
  731. if (this.form.businessData.data["$work"]){
  732. var id = this.form.businessData.data["$work"].job;
  733. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.listWithJobCategory(id, this.json.id, function(json){
  734. this.historyDocumentList = json.data;
  735. if (this.historyDocumentList.length){
  736. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.get(this.historyDocumentList[this.historyDocumentList.length-1].id, function(json){
  737. var data = JSON.parse(json.data.data);
  738. this.originaHistoryData = data.data;
  739. }.bind(this));
  740. }
  741. }.bind(this));
  742. }
  743. if (callback) callback();
  744. }.bind(this));
  745. if (!this.form.documenteditorList) this.form.documenteditorList=[];
  746. this.form.documenteditorList.push(this);
  747. },
  748. checkSaveNewEdition: function(callback){
  749. debugger;
  750. if (!this.allowEdit || !this.data.filetext || this.data.filetext == this.json.defaultValue.filetext) return false;
  751. if (this.form.businessData.work){
  752. var originaData = this.form.businessData.originalData[this.json.id];
  753. var editionData = {"category": this.json.id};
  754. if (!originaData || !originaData.filetext || !this.originaHistoryData){
  755. //保存原始版本
  756. this.originaHistoryData = {"data": this.data.filetext};
  757. editionData.data = JSON.stringify({"data": this.data.filetext});
  758. }else if (originaData.filetext!=this.data.filetext){
  759. //保存历史版本
  760. var data = this.data.filetext;
  761. var earlyData = originaData.filetext;
  762. var dmp = new diff_match_patch();
  763. var diff_d = dmp.diff_main(earlyData, data);
  764. dmp.diff_cleanupSemantic(diff_d);
  765. var patch_list = dmp.patch_make(earlyData, data, diff_d);
  766. editionData.data = JSON.stringify({"patchs": dmp.patch_toText(patch_list)});
  767. }else{
  768. return false;
  769. }
  770. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  771. //originaData.filetext = this.data.filetext;
  772. if (callback) callback();
  773. }.bind(this));
  774. }
  775. },
  776. // saveNewDataEdition: function(callback){
  777. // if (this.form.businessData.work){
  778. // var editionData = {"category": this.json.id};
  779. // if (this.form.businessData.originalData[this.json.id] && this.form.businessData.originalData[this.json.id].filetext){
  780. // var data = this.data.filetext;
  781. // var earlyData = this.form.businessData.originalData[this.json.id].filetext;
  782. // var dmp = new diff_match_patch();
  783. // var diff_d = dmp.diff_main(earlyData, data);
  784. // dmp.diff_cleanupSemantic(diff_d);
  785. // var patch_list = dmp.patch_make(earlyData, data, diff_d);
  786. // editionData.data = {"patchs": dmp.patch_toText(patch_list)};
  787. //
  788. // }else{
  789. // editionData.data = {"data": this.data.filetext};
  790. // }
  791. // o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  792. // this.form.businessData.originalData[this.json.id] = this.data.filetext;
  793. // if (callback) callback();
  794. // }.bind(this));
  795. // }
  796. // },
  797. resizeToolbar: function(){
  798. if (this.toolbarNode){
  799. var p = this.toolNode.getPosition(this.scrollNode);
  800. var size = this.toolNode.getSize();
  801. var pl = this.toolbarNode.getStyle("padding-left").toInt();
  802. var pr = this.toolbarNode.getStyle("padding-right").toInt();
  803. var x = size.x-pl-pr;
  804. //var pNode = this.toolNode.getOffsetParent();
  805. var paddingTop = this.form.node.getStyle("padding-top");
  806. try {
  807. paddingTop = paddingTop.toInt();
  808. }catch (e) {
  809. paddingTop = 0;
  810. }
  811. if (p.y<paddingTop){
  812. this.toolbarNode.inject(this.scrollNode);
  813. this.toolbarNode.setStyles({
  814. "position": "absolute",
  815. "width": ""+x+"px",
  816. "z-index": 200,
  817. "top": paddingTop+"px",
  818. "left": ""+p.x+"px"
  819. });
  820. }else{
  821. this.toolbarNode.inject(this.toolNode);
  822. this.toolbarNode.setStyles({"position": "static"});
  823. }
  824. }
  825. },
  826. resizeSidebar: function(){
  827. if (this.sidebarNode){
  828. var fileTextNode = this.contentNode.getElement("div.doc_layout_filetext");
  829. if (fileTextNode){
  830. this.sidebarNode.position({
  831. relativeTo: fileTextNode,
  832. position: 'topLeft',
  833. edge: 'topRight',
  834. offset: {"x": -20, "y": 60}
  835. });
  836. var p = fileTextNode.getPosition(this.form.app.content);
  837. var ptop = fileTextNode.getPosition(this.node);
  838. //if ((p.y+s.y)<0) this.sidebarNode.setStyle("top", p.y+s.y);
  839. if (p.y<0){
  840. var top = ptop.y-p.y+200;
  841. this.sidebarNode.setStyle("top", top);
  842. }
  843. // var p = fileTextNode.getPosition();
  844. // this.sidebarNode.setStyle("top", p.y);
  845. }
  846. }
  847. },
  848. loadSideToolbar: function(){
  849. if (this.allowEdit){
  850. if (this.pages.length){
  851. var fileTextNode = this.pages[0].getElement("div.doc_layout_filetext");
  852. if (fileTextNode){
  853. this.sidebarNode = new Element("div", {"styles": this.css.doc_sidebar}).inject(this.node);
  854. this.resizeSidebar();
  855. this.scrollNode = this.sidebarNode.getParentSrcollNode();
  856. if (this.scrollNode){
  857. this.scrollNode.addEvent("scroll", function(){
  858. this.resizeSidebar();
  859. }.bind(this));
  860. }
  861. 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>";
  862. this.sidebarNode.set("html", html);
  863. MWF.require("MWF.widget.Toolbar", function() {
  864. this.sideToolbar = new MWF.widget.Toolbar(this.sidebarNode, {"style": "documentEdit_side"}, this);
  865. this.sideToolbar.load();
  866. }.bind(this));
  867. }
  868. }
  869. }
  870. },
  871. _returnScale: function(){
  872. this.isScale = false;
  873. this.scale = 0;
  874. this.contentNode.setStyles({
  875. "transform":"scale(1)",
  876. });
  877. if (this.pages.length){
  878. this.pages.each(function(page){
  879. page.setStyles({
  880. "transform":"scale(1)",
  881. });
  882. });
  883. }
  884. this.node.setStyles({
  885. "height": "auto"
  886. });
  887. },
  888. _checkScale: function(offset){
  889. offset = 0;
  890. if (this.pages.length){
  891. //var pageSize = this.pages[0].getSize();
  892. var pageSize_x = this.options.docPageFullWidth
  893. var contentSize = this.contentNode.getSize();
  894. var contentWidth = (offset) ? contentSize.x-20-offset : contentSize.x-20;
  895. if (contentWidth<pageSize_x){
  896. this.isScale = true;
  897. var scale = (contentWidth)/pageSize_x;
  898. this.scale = scale;
  899. this.zoom();
  900. this.resetNodeSize();
  901. }
  902. }
  903. },
  904. zoom: function(scale){
  905. if (scale) this.scale = scale;
  906. var w = this.node.getSize().x;
  907. if (this.history && this.history.historyListAreaNode) w = w-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  908. w = w/this.scale;
  909. this.contentNode.setStyles({
  910. "transform":"scale("+this.scale+")",
  911. "transform-origin": "0px 0px",
  912. "overflow": "hidden",
  913. "width": ""+w+"px"
  914. });
  915. },
  916. _switchReadOrEdit: function(){
  917. if (this.editMode){
  918. this._readFiletext();
  919. if (this.allowEdit) {
  920. var button = this.toolbar.childrenButton[0];
  921. button.setText(MWF.xApplication.process.Xform.LP.editdoc);
  922. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png");
  923. //this.getFullWidthFlagNode().dispose();
  924. }
  925. this.editMode = false;
  926. }else{
  927. this._editFiletext();
  928. if (this.allowEdit) {
  929. var button = this.toolbar.childrenButton[0];
  930. button.setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  931. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png");
  932. //this.toolbar.node.inject(this.getFullWidthFlagNode());
  933. }
  934. this.editMode = true;
  935. }
  936. },
  937. _switchReadOrEditInline: function(){
  938. if (this.editMode){
  939. this._readFiletext();
  940. if (this.allowEdit){
  941. if (!layout.mobile) {
  942. var button = this.sideToolbar.childrenButton[0];
  943. button.setText(MWF.xApplication.process.Xform.LP.editdoc);
  944. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png");
  945. //this.getFullWidthFlagNode().dispose();
  946. }
  947. button = this.toolbar.childrenButton[0];
  948. button.setText(MWF.xApplication.process.Xform.LP.editdoc);
  949. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png");
  950. //this.getFullWidthFlagNode().dispose();
  951. // if (!layout.mobile)this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  952. // this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  953. }
  954. this.editMode = false;
  955. }else{
  956. this._editFiletext("inline");
  957. if (this.allowEdit){
  958. if (!layout.mobile) {
  959. var button = this.sideToolbar.childrenButton[0];
  960. button.setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  961. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png");
  962. //this.toolbar.node.inject(this.getFullWidthFlagNode());
  963. }
  964. button = this.toolbar.childrenButton[0];
  965. button.setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  966. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png");
  967. //this.toolbar.node.inject(this.getFullWidthFlagNode());
  968. // if (!layout.mobile) this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  969. // this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  970. }
  971. this.editMode = true;
  972. }
  973. },
  974. // getFullWidthFlagNode: function(){
  975. // if (!this.fullWidthFlagNode){
  976. // this.fullWidthFlagNode = new Element("span", {
  977. // "styles": {
  978. // "line-height": "26px",
  979. // "color": "#999999",
  980. // "font-size": "12px"
  981. // },
  982. // "text": MWF.xApplication.process.Xform.LP.fullWidth
  983. // });
  984. // }
  985. // return this.fullWidthFlagNode;
  986. // },
  987. _printDoc: function(){
  988. this.toWord(function(data){
  989. if (this.form.businessData.work && !this.form.businessData.work.completedTime){
  990. this.form.workAction.getAttachmentStream(data.id, this.form.businessData.work.id);
  991. }else{
  992. this.form.workAction.getWorkcompletedAttachmentStream(data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  993. }
  994. }.bind(this));
  995. },
  996. _historyDoc: function(){
  997. this.getHistory(function(){
  998. //this.history.play();
  999. }.bind(this));
  1000. },
  1001. getHistory: function(callback){
  1002. if (this.history){
  1003. this.history.active(function(){
  1004. if (callback) callback();
  1005. });
  1006. }else{
  1007. MWF.xDesktop.requireApp("process.Xform", "widget.DocumentHistory", function(){
  1008. this.history = new MWF.xApplication.process.Xform.widget.DocumentHistory(this);
  1009. this.history.load(function(){
  1010. if (callback) callback();
  1011. });
  1012. }.bind(this));
  1013. }
  1014. },
  1015. htmlToText: function(html){
  1016. var tmpdiv = new Element("div", {"html": html});
  1017. var text = tmpdiv.get("text");
  1018. tmpdiv.destroy();
  1019. return text;
  1020. },
  1021. _readFiletext: function(){
  1022. //this._returnScale();
  1023. this.zoom(1);
  1024. if (this.filetextEditor) this.filetextEditor.destroy();
  1025. if (this.filetextScrollNode){
  1026. if (this.reLocationFiletextToolbarFun){
  1027. this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  1028. //this.form.app.removeEvent("resize", this.reLocationFiletextToolbarFun);
  1029. this.reLocationFiletextToolbarFun = null;
  1030. }
  1031. this.filetextScrollNode = null;
  1032. }
  1033. if (this.filetextToolbarNode) this.filetextToolbarNode = null;
  1034. this.layout_filetext.setAttribute('contenteditable', false);
  1035. this.data = this.getData();
  1036. // debugger;
  1037. if (!this.data.filetext){
  1038. //this.data.filetext = this.json.defaultValue.filetext;
  1039. this.layout_filetext.set("html", this.json.defaultValue.filetext);
  1040. }
  1041. //this._checkSplitPage(this.pages[0]);
  1042. this._repage();
  1043. },
  1044. _editFiletext: function(inline){
  1045. this._returnScale();
  1046. this.zoom(1);
  1047. this._singlePage();
  1048. this.pages = [];
  1049. this.contentNode.empty();
  1050. this._createPage(function(control){
  1051. this._loadPageLayout(control);
  1052. // var docData = this._getBusinessData();
  1053. // if (!docData) docData = this._getDefaultData();
  1054. if (this.data.filetext == this.json.defaultValue.filetext) this.data.filetext = "  ";
  1055. this.setData(this.data);
  1056. this._checkScale();
  1057. this.node.setStyles({
  1058. "height":"auto"
  1059. });
  1060. this._createEditor(inline);
  1061. }.bind(this));
  1062. },
  1063. _createEditor: function(inline){
  1064. if (this.allowEdit){
  1065. this.loadCkeditorFiletext(function(e){
  1066. e.editor.focus();
  1067. e.editor.getSelection().scrollIntoView();
  1068. //this.getFiletextToolber();
  1069. //this.filetextToolbarNode.inject(this.layout_filetext.getOffsetParent());
  1070. this.locationFiletextToolbar();
  1071. }.bind(this), inline);
  1072. }
  1073. },
  1074. getFiletextToolber: function(){
  1075. if (this.filetextEditor) {
  1076. if (!this.filetextToolbarNode) {
  1077. var className = "cke_editor_" + this.filetextEditor.name;
  1078. var filetextToolbarNode = $$("." + className)[0];
  1079. this.filetextToolbarNode = filetextToolbarNode;
  1080. //filetextToolbarNode.destroy();
  1081. }
  1082. }
  1083. },
  1084. reLocationFiletextToolbar: function(){
  1085. this.getFiletextToolber();
  1086. // if (this.filetextToolbarNode){
  1087. // this.filetextToolbarNode.setStyle("display", "block");
  1088. // var offsetNode = this.layout_filetext.getOffsetParent();
  1089. //
  1090. // this.filetextToolbarNode.setStyle("left", 0);
  1091. // var h = this.filetextToolbarNode.getSize().y;
  1092. // var p = this.layout_filetext.getPosition(offsetNode).y-h;
  1093. //
  1094. // var postion = this.layout_filetext.getPosition(this.form.app.content);
  1095. // if (postion.y-h<0){
  1096. // this.filetextToolbarNode.inject(this.form.app.content);
  1097. // this.filetextToolbarNode.setStyle("top", 0);
  1098. // this.filetextToolbarNode.setStyle("left", ""+postion.x+"px");
  1099. // }else{
  1100. // this.filetextToolbarNode.inject(offsetNode);
  1101. // this.filetextToolbarNode.setStyle("top", "" + p + "px");
  1102. // this.filetextToolbarNode.setStyle("left", 0);
  1103. // this.filetextToolbarNode.setStyle("left", "auto");
  1104. // }
  1105. // }
  1106. if (this.filetextToolbarNode){
  1107. if (!this.filetextScrollNode){
  1108. var scrollNode = this.contentNode;
  1109. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  1110. scrollNode = scrollNode.getParent();
  1111. }
  1112. this.filetextScrollNode = scrollNode;
  1113. }
  1114. var h = this.filetextToolbarNode.getSize().y;
  1115. var position = this.layout_filetext.getPosition();
  1116. var size = this.layout_filetext.getSize();
  1117. var contentSize = this.filetextScrollNode.getSize();
  1118. if (position.y<0 && size.y+position.y+h<contentSize.y){
  1119. // var top = size.y+position.y;
  1120. // this.filetextToolbarNode.setStyle("top", ""+top+"px");
  1121. var tp = this.toolbar.node.getPosition();
  1122. var tsy = this.toolbar.node.getSize().y;
  1123. var h = tp.y+tsy;
  1124. this.filetextToolbarNode.setStyle("top", ""+h+"px");
  1125. }else if (position.y-h<0){
  1126. var tp = this.toolbar.node.getPosition();
  1127. var tsy = this.toolbar.node.getSize().y;
  1128. var h = tp.y+tsy;
  1129. this.filetextToolbarNode.setStyle("top", ""+h+"px");
  1130. }else{
  1131. var p = this.layout_filetext.getPosition().y-h;
  1132. this.filetextToolbarNode.setStyle("top", "" + p + "px");
  1133. }
  1134. }
  1135. //
  1136. // this.filetextToolbarNode.inject(offsetNode);
  1137. //
  1138. //
  1139. // this.filetextToolbarNode.setStyle("top", ""+p+"px");
  1140. },
  1141. locationFiletextToolbar: function(){
  1142. this.reLocationFiletextToolbar();
  1143. if (this.filetextToolbarNode) {
  1144. var scrollNode = this.contentNode;
  1145. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  1146. scrollNode = scrollNode.getParent();
  1147. }
  1148. if (scrollNode){
  1149. this.filetextScrollNode = scrollNode;
  1150. this.reLocationFiletextToolbarFun = this.reLocationFiletextToolbar.bind(this);
  1151. this.filetextScrollNode.addEvent("scroll", this.reLocationFiletextToolbarFun);
  1152. }
  1153. }
  1154. },
  1155. _isAllowEdit:function(){
  1156. if (this.readonly) return false;
  1157. if (this.json.allowEdit=="n") return false;
  1158. if (this.json.allowEdit=="s"){
  1159. if (this.json.allowEditScript && this.json.allowEditScript.code){
  1160. return !!this.form.Macro.exec(this.json.allowEditScript.code, this);
  1161. }
  1162. }
  1163. return true;
  1164. },
  1165. _isAllowPrint: function(){
  1166. if (this.json.allowPrint=="n") return false;
  1167. if (this.json.allowPrint=="s"){
  1168. if (this.json.allowPrintScript && this.json.allowPrintScript.code){
  1169. return !!this.form.Macro.exec(this.json.allowPrintScript.code, this);
  1170. }
  1171. }
  1172. return true;
  1173. },
  1174. _isAllowHistory: function(){
  1175. if (this.json.allowHistory=="n") return false;
  1176. if (this.json.allowHistory=="s"){
  1177. if (this.json.allowHistoryScript && this.json.allowHistoryScript.code){
  1178. return !!this.form.Macro.exec(this.json.allowHistoryScript.code, this);
  1179. }
  1180. }
  1181. return true;
  1182. },
  1183. _getEdit: function(name, typeItem, scriptItem){
  1184. switch (this.json[typeItem]) {
  1185. case "y":
  1186. return true;
  1187. case "n":
  1188. return false;
  1189. case "s":
  1190. if (this.json[scriptItem] && this.json[scriptItem].code){
  1191. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  1192. }
  1193. return true;
  1194. }
  1195. },
  1196. loadCkeditorStyle: function(node){
  1197. if (node){
  1198. o2.load("ckeditor", function(){
  1199. //CKEDITOR.disableAutoInline = true;
  1200. node.setAttribute('contenteditable', true);
  1201. var editor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1202. this.filetextEditor.on("instanceReady", function(e){
  1203. if (callback) callback(e);
  1204. }.bind(this));
  1205. }.bind(this));
  1206. }
  1207. },
  1208. _loadToolbars: function(){
  1209. var html ="";
  1210. if (this.allowEdit){
  1211. //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>";
  1212. 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>";
  1213. //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>";
  1214. }
  1215. if (this.allowPrint){
  1216. 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>";
  1217. }
  1218. if (this.allowHistory){
  1219. 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>";
  1220. }
  1221. // if (this.json.fullWidth=="y"){
  1222. // html += "<span style='line-height: 26px; color: #999999; font-size: 12px'>已启用半角空格自动转换为全角空格,如需输入半角空格,请使用:SHIFT+空格</span>"
  1223. // }
  1224. this.toolbarNode = new Element("div", {"styles": this.css.doc_toolbar_node}).inject(this.toolNode);
  1225. this.toolbarNode.set("html", html);
  1226. MWF.require("MWF.widget.Toolbar", function() {
  1227. this.toolbar = new MWF.widget.Toolbar(this.toolbarNode, {"style": "documentEdit"}, this);
  1228. this.toolbar.load();
  1229. }.bind(this));
  1230. if (!layout.mobile){
  1231. this.scrollNode = this.toolbarNode.getParentSrcollNode();
  1232. if (this.scrollNode){
  1233. this.scrollNode.addEvent("scroll", function(){
  1234. this.resizeToolbar();
  1235. }.bind(this));
  1236. }
  1237. }
  1238. this.doublePageAction = new Element("div", {"styles": this.css.doc_toolbar_doublePage, "text": MWF.xApplication.process.Xform.LP.doublePage}).inject(this.toolbarNode);
  1239. this.doublePageAction.addEvent("click", function(){
  1240. if (this.options.pageShow!=="double"){
  1241. this._doublePage();
  1242. }else{
  1243. this._singlePage();
  1244. }
  1245. }.bind(this));
  1246. // this.zoomSelectAction = new Element("select", {"styles": {"float": "right"}}).inject(this.toolbarNode);
  1247. // var options = "<option value='2'>200%</option> " +
  1248. // "<option value='1.75'>175%</option>" +
  1249. // "<option value='1.5'>150%</option>" +
  1250. // "<option value='1' selected>100%</option>" +
  1251. // "<option value='0.75'>75%</option>" +
  1252. // "<option value='0.5'>50%</option>" +
  1253. // "<option value='0.25'>25%</option>"
  1254. // this.zoomSelectAction.set("html", options);
  1255. // this.zoomSelectAction.addEvent("change", function(e){
  1256. // this._returnScale();
  1257. // this.scale = e.target.options[e.target.selectedIndex].value;
  1258. // this.zoom();
  1259. // }.bind(this));
  1260. },
  1261. _repage: function(delay){
  1262. if (this.options.pageShow!=="double"){
  1263. this._singlePage();
  1264. }else{
  1265. this._doublePage();
  1266. }
  1267. if (delay){
  1268. if (!this.form.isLoaded){
  1269. this.form.addEvent("afterLoad", this._checkScale.bind(this));
  1270. }else{
  1271. this._checkScale();
  1272. }
  1273. }else{
  1274. this._checkScale();
  1275. }
  1276. },
  1277. _singlePage: function(){
  1278. //if (this.editMode) this._readFiletext();
  1279. this.zoom(1);
  1280. this._checkScale();
  1281. var w = this.contentNode.getSize().x;
  1282. var count = 1;
  1283. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1284. //var docPageFullWidth = this.options.docPageFullWidt;
  1285. var pageWidth = count * docPageFullWidth;
  1286. var margin = (w-pageWidth)/(count+1);
  1287. if (this.isScale){
  1288. margin = "10";
  1289. }
  1290. if (this.scale) margin = margin/this.scale;
  1291. this.pages.each(function(page, i){
  1292. page.setStyles({
  1293. "float": "left",
  1294. "margin-left": ""+margin+"px"
  1295. });
  1296. });
  1297. this.resetNodeSize();
  1298. // this.pages.each(function(page){
  1299. // page.setStyle("float", "none");
  1300. // });
  1301. this.resizeSidebar();
  1302. this.options.pageShow="single";
  1303. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
  1304. },
  1305. resetNodeSize: function(){
  1306. var contentSize = this.contentNode.getSize();
  1307. var toolbarSize = this.toolNode.getSize();
  1308. contentHeight = contentSize.y;
  1309. var h = contentHeight+toolbarSize.y+20;
  1310. //h = h - contentSize.y*(1-this.scale);
  1311. this.node.setStyles({
  1312. "height":""+h+"px"
  1313. });
  1314. },
  1315. createWaitSplitPage: function(){
  1316. this.node.mask({
  1317. "style": {
  1318. "background-color": "#cccccc",
  1319. "opacity": 0.3
  1320. }
  1321. });
  1322. this.waitSplitPageNode = new Element("div", {"styles": this.form.css.waitSplitPageNode, "text": MWF.xApplication.process.Xform.LP.computePage}).inject(this.node);
  1323. this.waitSplitPageNode.position({
  1324. "relativeTo": this.node,
  1325. "position": "topRight",
  1326. "edge": "topRight",
  1327. "offset": {
  1328. "x": -10,
  1329. "y": 45
  1330. }
  1331. });
  1332. //this.form.notice(MWF.xApplication.process.Xform.LP.computePage, "info", this.node);
  1333. },
  1334. clearWaitSplitPage: function(){
  1335. this.node.unmask();
  1336. if (this.waitSplitPageNode) this.waitSplitPageNode.destroy();
  1337. this.waitSplitPageNode = null;
  1338. },
  1339. _doublePage: function(){
  1340. if (this.editMode) this._switchReadOrEditInline();
  1341. this.zoom(1);
  1342. this.createWaitSplitPage();
  1343. window.setTimeout(function(){
  1344. this._checkSplitPage(this.pages[0]);
  1345. this.zoom(1);
  1346. var w = this.contentNode.getSize().x;
  1347. var toPageWidth = (w-100)/2;
  1348. scale = toPageWidth/this.options.docPageFullWidth;
  1349. if (scale<1) this.zoom(scale);
  1350. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1351. //var docPageFullWidth = this.options.docPageFullWidth;
  1352. var w = this.contentNode.getSize().x;
  1353. var count = (w/docPageFullWidth).toInt();
  1354. var pages = this.contentNode.getElements(".doc_layout_page");
  1355. count = Math.min(pages.length, count);
  1356. var pageWidth = count * docPageFullWidth;
  1357. var margin = (w-pageWidth)/(count+1);
  1358. if (this.scale) margin = margin/(this.scale);
  1359. this.pages.each(function(page, i){
  1360. page.setStyles({
  1361. "float": "left",
  1362. "margin-left": ""+margin+"px"
  1363. });
  1364. });
  1365. // this.pages.each(function(page, i){
  1366. // if ((i % 2)===0){
  1367. // page.setStyle("float", "left");
  1368. // }else{
  1369. // page.setStyle("float", "right");
  1370. // }
  1371. // });
  1372. this.resetNodeSize();
  1373. this.options.pageShow="double";
  1374. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
  1375. this.resizeSidebar();
  1376. this.clearWaitSplitPage();
  1377. }.bind(this), 1000);
  1378. },
  1379. _getDefaultData: function(){
  1380. return Object.clone(this.json.defaultValue);
  1381. //return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
  1382. },
  1383. _loadFiletextPage: function(callback){
  1384. this.data = this._getBusinessData();
  1385. if (!this.data) this.data = this._getDefaultData();
  1386. this._computeData(true);
  1387. this._createPage(function(control){
  1388. this._loadPageLayout(control);
  1389. // this.data = this._getBusinessData();
  1390. // if (!this.data) this.data = this._getDefaultData();
  1391. this.setData(this.data);
  1392. // this._checkSplitPage(this.pages[0]);
  1393. //this._repage(true);
  1394. //this.loadCkeditorFiletext();
  1395. if (!this.readonly){
  1396. //if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
  1397. // if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
  1398. // if (this.json.allowEditSubject) this.loadCkeditorSubject();
  1399. // if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
  1400. // if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
  1401. // if (this.json.allowEditSigner) this.loadCkeditorSigner();
  1402. // if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
  1403. }
  1404. if (callback) callback();
  1405. }.bind(this));
  1406. },
  1407. _getEditorConfig: function(){
  1408. // var mathElements = [
  1409. // 'math',
  1410. // 'maction',
  1411. // 'maligngroup',
  1412. // 'malignmark',
  1413. // 'menclose',
  1414. // 'merror',
  1415. // 'mfenced',
  1416. // 'mfrac',
  1417. // 'mglyph',
  1418. // 'mi',
  1419. // 'mlabeledtr',
  1420. // 'mlongdiv',
  1421. // 'mmultiscripts',
  1422. // 'mn',
  1423. // 'mo',
  1424. // 'mover',
  1425. // 'mpadded',
  1426. // 'mphantom',
  1427. // 'mroot',
  1428. // 'mrow',
  1429. // 'ms',
  1430. // 'mscarries',
  1431. // 'mscarry',
  1432. // 'msgroup',
  1433. // 'msline',
  1434. // 'mspace',
  1435. // 'msqrt',
  1436. // 'msrow',
  1437. // 'mstack',
  1438. // 'mstyle',
  1439. // 'msub',
  1440. // 'msup',
  1441. // 'msubsup',
  1442. // 'mtable',
  1443. // 'mtd',
  1444. // 'mtext',
  1445. // 'mtr',
  1446. // 'munder',
  1447. // 'munderover',
  1448. // 'semantics',
  1449. // 'annotation',
  1450. // 'annotation-xml'
  1451. // ];
  1452. //CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.13.0/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
  1453. debugger;
  1454. var editorConfig = {
  1455. qtRows: 20, // Count of rows
  1456. qtColumns: 20, // Count of columns
  1457. qtBorder: '1', // Border of inserted table
  1458. qtWidth: '95%', // Width of inserted table
  1459. qtStyle: { 'border-collapse' : 'collapse' },
  1460. qtClass: 'documenteditor_table'+this.form.json.id+this.json.id, // Class of table
  1461. qtCellPadding: '0', // Cell padding table
  1462. qtCellSpacing: '0', // Cell spacing table
  1463. qtPreviewBorder: '4px double black', // preview table border
  1464. qtPreviewSize: '4px', // Preview table cell size
  1465. qtPreviewBackground: '#c8def4', // preview table background (hover)
  1466. // format_tags: '标题一;标题二;标题三;标题四;正文', // entries is displayed in "Paragraph format"
  1467. format_tags: '标题一;标题二;正文(标题三,四)', // entries is displayed in "Paragraph format"
  1468. 'format_标题一': {
  1469. name: '标题一(三号黑体)',
  1470. element: 'div',
  1471. styles: {
  1472. 'font-family': '黑体',
  1473. 'font-size': '16pt'
  1474. }
  1475. },
  1476. 'format_标题二': {
  1477. name: '标题二(三号楷体)',
  1478. element: 'div',
  1479. styles: {
  1480. 'font-family': '楷体',
  1481. 'font-size': '16pt'
  1482. }
  1483. },
  1484. // 'format_标题三': {
  1485. // name: '标题三',
  1486. // element: 'div',
  1487. // styles: {
  1488. // 'font-family': '仿宋',
  1489. // 'font-size': '16pt'
  1490. // }
  1491. // },
  1492. // 'format_标题四': {
  1493. // name: '标题四',
  1494. // element: 'div',
  1495. // styles: {
  1496. // 'font-family': '仿宋',
  1497. // 'font-size': '16pt'
  1498. // }
  1499. // },
  1500. 'format_正文(标题三,四)': {
  1501. name: '正文(标题三,四)',
  1502. element: 'div',
  1503. styles: {
  1504. 'font-family': '仿宋',
  1505. 'font-size': '16pt'
  1506. }
  1507. }
  1508. };
  1509. editorConfig.toolbarGroups = [
  1510. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  1511. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  1512. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  1513. { name: 'forms', groups: [ 'forms' ] },
  1514. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  1515. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  1516. { name: 'links', groups: [ 'links' ] },
  1517. { name: 'insert', groups: [ 'insert' ] },
  1518. { name: 'styles', groups: [ 'styles' ] },
  1519. { name: 'colors', groups: [ 'colors' ] },
  1520. { name: 'tools', groups: [ 'tools' ] },
  1521. { name: 'others', groups: [ 'others' ] },
  1522. { name: 'about', groups: [ 'about' ] }
  1523. ];
  1524. //editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,mathjax,ckeditor_wiris";
  1525. //editorConfig.extraPlugins = "ecnet,colordialog,quicktable,tableresize,eqneditor";
  1526. //editorConfig.extraPlugins = "tableresize,quicktable";
  1527. editorConfig.extraPlugins = "quicktable,tableresize";
  1528. //editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
  1529. 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';
  1530. //editorConfig.extraAllowedContent = mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)';
  1531. editorConfig.pasteFromWordRemoveFontStyles = false;
  1532. editorConfig.pasteFromWordRemoveStyles = false;
  1533. //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';
  1534. editorConfig.removePlugins = ['magicline'];
  1535. editorConfig.enterMode = 3;
  1536. // editorConfig.extraPlugins = ['ecnet','mathjax'];
  1537. // editorConfig.removePlugins = ['magicline'];
  1538. // editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
  1539. return editorConfig;
  1540. },
  1541. _checkSplitPage: function(pageNode){
  1542. if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
  1543. var contentNode = pageNode.getFirst();
  1544. if (contentNode.getSize().y>this.options.docPageHeight){
  1545. this._splitPage(pageNode);
  1546. }
  1547. var i = pageNode.get("data-pagecount").toInt();
  1548. if (i && this.pages.length-1>=i){
  1549. this._checkSplitPage(this.pages[i]);
  1550. }
  1551. if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
  1552. },
  1553. _splitFiletextNodeOneWord:function(lnode, nextPageNode){
  1554. var text = lnode.textContent;
  1555. var len = text.length;
  1556. var left = text.substring(0, len-1);
  1557. var right = text.substring(len-1, len);
  1558. lnode.textContent = left;
  1559. nextPageNode.textContent = right+nextPageNode.textContent;
  1560. //nextPageNode.appendText(right, "top");
  1561. },
  1562. _splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
  1563. var contentNode = pageNode.getFirst();
  1564. var lnode = node.lastChild;
  1565. if (!lnode){
  1566. if (node.parentNode) node.parentNode.removeChild(node);
  1567. //node.remove();
  1568. }else{
  1569. while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
  1570. var tmpnode = lnode.previousSibling;
  1571. var nodeType = lnode.nodeType;
  1572. if (!nextPageNode) nextPageNode = nextFiletextNode;
  1573. if (nodeType == Node.ELEMENT_NODE) {
  1574. if (lnode.tagName == "table") {
  1575. lnode.inject(nextPageNode);
  1576. } else if (lnode.tagName == "BR") {
  1577. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1578. } else {
  1579. var id = lnode.get("data-pagePart");
  1580. if (!id){
  1581. id = (new o2.widget.UUID()).toString();
  1582. lnode.set("data-pagePart", id);
  1583. }
  1584. var tmpNode = nextPageNode.getFirst();
  1585. if (tmpNode && tmpNode.get("data-pagePart")==id){
  1586. nextPageNode = tmpNode;
  1587. }else{
  1588. nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
  1589. }
  1590. //var subnode = lnode.getLast();
  1591. this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
  1592. if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1593. nextPageNode = nextPageNode.getParent();
  1594. }
  1595. } else if (nodeType == Node.TEXT_NODE) {
  1596. var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
  1597. while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
  1598. //console.log(contentNode.getSize().y);
  1599. this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
  1600. }
  1601. if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
  1602. } else {
  1603. //lnode.remove();
  1604. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1605. }
  1606. lnode = tmpnode;
  1607. }
  1608. if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
  1609. }
  1610. //this._checkSplitPage(pageNode);
  1611. },
  1612. _splitPage: function(pageNode){
  1613. var contentNode = pageNode.getFirst();
  1614. var blockNodes = pageNode.getElements(".doc_block");
  1615. if (blockNodes.length){
  1616. var blockNode = blockNodes[blockNodes.length-1];
  1617. var idx = this.pages.indexOf(pageNode);
  1618. if (this.pages.length<=idx+1) this._createNewPage();
  1619. var nextPage = this.pages[idx+1];
  1620. if (blockNode.hasClass("doc_layout_filetext")){
  1621. var filetextNode = nextPage.getElement(".doc_layout_filetext");
  1622. if (!filetextNode){
  1623. filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
  1624. //filetextNode.setAttribute('contenteditable', true);
  1625. }
  1626. if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
  1627. //var nextEditor = filetextNode.retrieve("editor");
  1628. var node = blockNode;
  1629. var nextPageNode = filetextNode;
  1630. this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
  1631. }else{
  1632. blockNode.inject(nextPage.getFirst(), "top");
  1633. //var contentNode = pageNode.getFirst();
  1634. if (contentNode.getSize().y>this.options.docPageHeight){
  1635. this._splitPage(pageNode);
  1636. }
  1637. }
  1638. }
  1639. },
  1640. transWidth: function(node){
  1641. if (!node) return '';
  1642. while (node){
  1643. if (node.nodeType==3){
  1644. node.nodeValue = node.nodeValue.replace(/\x20/g, " ");
  1645. }else if (node.nodeType==8){
  1646. //nothing
  1647. }else{
  1648. this.transWidth(node.firstChild);
  1649. }
  1650. node = node.nextSibling;
  1651. }
  1652. },
  1653. insertFullWidth: function(node, txt){
  1654. if (!node) return '';
  1655. while (node){
  1656. if (node.nodeType==3){
  1657. node.nodeValue = txt+node.nodeValue;
  1658. return true;
  1659. }else if (node.nodeType==8){
  1660. //nothing
  1661. }else{
  1662. var flag = this.insertFullWidth(node.firstChild, txt);
  1663. if (flag) return true;
  1664. }
  1665. node = node.nextSibling;
  1666. }
  1667. },
  1668. loadCkeditorFiletext: function(callback, inline){
  1669. if (this.layout_filetext){
  1670. o2.load("../o2_lib/htmleditor/ckeditor4130/ckeditor.js", function(){
  1671. CKEDITOR.disableAutoInline = true;
  1672. this.layout_filetext.setAttribute('contenteditable', true);
  1673. if (inline){
  1674. this.filetextEditor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1675. }else{
  1676. this.filetextEditor = CKEDITOR.replace(this.layout_filetext, this._getEditorConfig());
  1677. }
  1678. this.filetextEditor.on("instanceReady", function(e){
  1679. if (callback) callback(e);
  1680. }.bind(this));
  1681. this.filetextEditor.on( 'focus', function( e ) {
  1682. window.setTimeout(this.reLocationFiletextToolbar.bind(this), 10);
  1683. }.bind(this) );
  1684. this.filetextEditor.on( 'paste', function( e ) {
  1685. var html = e.data.dataValue;
  1686. //if (this.json.fullWidth=="y") html = html.replace(/\x20/g, " ");
  1687. var tmp = new Element("div")
  1688. tmp.set("html", html);
  1689. var pList = tmp.getElements("p");
  1690. pList.each(function(p, i){
  1691. //if (Browser.name=="ie"){
  1692. if (this.json.fullWidth!=="n") this.transWidth(p);
  1693. if (!p.getParent("table")){
  1694. var text = p.get("text");
  1695. var rex = /^\u3000*/;
  1696. var m = text.match(rex);
  1697. var l = (m[0]) ? Math.max((2-m[0].length), 0): 2;
  1698. var txt = "";
  1699. // for (var i=0; i<l; i++) txt+=" ";
  1700. // this.insertFullWidth(p.getFirst(), txt);
  1701. for (var i=0; i<l; i++) p.appendText(" ","top");
  1702. }
  1703. //}else{
  1704. // var textIndent = p.getStyle("text-indent");
  1705. // if (textIndent.toInt()) p.appendText("  ","top");
  1706. //}
  1707. }.bind(this));
  1708. e.data.dataValue = tmp.get("html");
  1709. tmp.destroy();
  1710. }.bind(this) );
  1711. if (this.json.textIndent!=="n"){
  1712. // this.filetextEditor.addCommand( 'textIndent_P', {
  1713. // exec: function( editor ) {
  1714. // debugger;
  1715. // editor.insertHtml("<br><div>  </div>");
  1716. // }
  1717. // } );
  1718. // this.filetextEditor.setKeystroke( CKEDITOR.CTRL + 13, 'textIndent_P' );
  1719. this.layout_filetext.addEvent("keyup", function(ev){
  1720. if (ev.code==13) this.filetextEditor.insertText("  ");
  1721. }.bind(this));
  1722. //
  1723. // this.filetextEditor.on("key", function(e){
  1724. // if (e.data.keyCode==13){
  1725. // e.editor.insertText("  ");
  1726. // //e.cancel();
  1727. // }
  1728. // }.bind(this));
  1729. }
  1730. if (this.json.fullWidth!=="n"){
  1731. this.filetextEditor.addCommand( 'insertHalfSpace', {
  1732. exec: function( editor ) {
  1733. editor.insertText(" ");
  1734. }
  1735. } );
  1736. this.filetextEditor.setKeystroke( CKEDITOR.SHIFT + 32, 'insertHalfSpace' );
  1737. this.filetextEditor.on("key", function(e){
  1738. if (this.json.fullWidth!=="n") if (e.data.keyCode==32){
  1739. e.editor.insertText(" ");
  1740. e.cancel();
  1741. }
  1742. }.bind(this));
  1743. }
  1744. }.bind(this));
  1745. }
  1746. },
  1747. _loadEvents: function(editorConfig){
  1748. Object.each(this.json.events, function(e, key){
  1749. if (e.code){
  1750. this.editor.on(key, function(event){
  1751. return this.form.Macro.fire(e.code, this, event);
  1752. }.bind(this), this);
  1753. }
  1754. }.bind(this));
  1755. },
  1756. _bindFieldChange: function(name,dataItem, dom){
  1757. var field = this.form.all[this.json[dataItem]];
  1758. if (field){
  1759. var bindFun = function(){
  1760. this._computeItemFieldData(name, dataItem);
  1761. //if (this.data[name]){
  1762. if (this[dom]){
  1763. if (dom=="layout_redHeader" || dom=="layout_subject"){
  1764. this[dom].set("html", this.data[name]|| "");
  1765. }else if (dom=="layout_attachment"){
  1766. this.setAttachmentData();
  1767. }else{
  1768. this[dom].set("text", this.data[name]|| "");
  1769. }
  1770. }
  1771. this.reSetShow();
  1772. //}
  1773. }.bind(this);
  1774. field.node.store(this.json.id+"bindFun", bindFun);
  1775. field.addModuleEvent("change", bindFun);
  1776. }
  1777. },
  1778. _computeItemFieldData: function(name, dataItem, dataItemNode){
  1779. var v = "";
  1780. var module = (dataItemNode) ? this.form.all[dataItemNode] : this.form.all[this.json[dataItem]];
  1781. if (module && module.getData) v = module.getData();
  1782. if (!v) v = (dataItemNode) ? this.form.businessData.data[dataItemNode] : this.form.businessData.data[this.json[dataItem]];
  1783. if (v){
  1784. var t = o2.typeOf(v);
  1785. switch (t) {
  1786. case "string":
  1787. switch (name) {
  1788. case "issuanceDate":
  1789. case "editionDate":
  1790. var d = new Date(v);
  1791. debugger;
  1792. if (d.isValid() && d.getFullYear()!=1970){
  1793. var y = d.getFullYear();
  1794. var m = d.getMonth();
  1795. var day = d.getDate();
  1796. m = m +1;
  1797. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  1798. }else{
  1799. this.data[name] = v;
  1800. }
  1801. //this.data[name] = (new Date(v).isValid()) ? Date.parse(v).format("%Y年%m月%d%日") : v;
  1802. break;
  1803. case "mainSend":
  1804. this.data[name] = v + ":";
  1805. break;
  1806. default:
  1807. this.data[name] = v;
  1808. }
  1809. break;
  1810. case "array":
  1811. var strs = [];
  1812. v.each(function(value){
  1813. if (o2.typeOf(value)=="object" && value.distinguishedName){
  1814. strs.push(value.name);
  1815. }else{
  1816. strs.push(value.toString());
  1817. }
  1818. });
  1819. //if (strs.length){
  1820. switch (name) {
  1821. case "attachment":
  1822. // this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>");
  1823. var atts = strs.map(function(a){
  1824. return (a.indexOf(".")!=-1) ? a.substring(0, a.lastIndexOf(".")) : a;
  1825. });
  1826. this.data[name] = atts;
  1827. break;
  1828. case "issuanceDate":
  1829. case "editionDate":
  1830. var tmpStrs = strs.map(function(n, i){
  1831. var d = Date.parse(n);
  1832. if (d.isValid() && d.getFullYear()!=1970){
  1833. var y = d.getFullYear();
  1834. var m = d.getMonth();
  1835. var day = d.getDate();
  1836. m = m +1;
  1837. return ""+y+"年"+m+"月"+day+"日";
  1838. }else{
  1839. return n;
  1840. }
  1841. //return () ? d.format("%Y年%m月%d日") : n;
  1842. });
  1843. this.data[name] = tmpStrs.join(",");
  1844. break;
  1845. case "mainSend":
  1846. this.data[name] = strs.join(",") + ":";
  1847. break;
  1848. default:
  1849. this.data[name] = strs.join(",");
  1850. }
  1851. //}
  1852. break;
  1853. default:
  1854. this.data[name] = v.toString();
  1855. }
  1856. }else{
  1857. this.data[name] = this.json.defaultValue[name];
  1858. }
  1859. },
  1860. computeData: function(){
  1861. this._computeData(false);
  1862. this.setData(this.data);
  1863. },
  1864. _computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
  1865. switch (this.json[typeItem]) {
  1866. case "data":
  1867. if (this.json[dataItem]){
  1868. if (ev) this._bindFieldChange(name, dataItem, dom);
  1869. this._computeItemFieldData(name, dataItem);
  1870. }
  1871. break;
  1872. case "script":
  1873. if (this.json[scriptItem] && this.json[scriptItem].code){
  1874. var v = this.form.Macro.exec(this.json[scriptItem].code, this);
  1875. this.data[name] = v;
  1876. if (name=="attachment"){
  1877. //this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>") : v;
  1878. this.data[name] = (typeOf(v)=="array") ? v : [v];
  1879. }
  1880. if (name=="issuanceDate" || name=="editionDate"){
  1881. var d = Date.parse(v);
  1882. if (d.isValid() && d.getFullYear()!=1970){
  1883. var y = d.getFullYear();
  1884. var m = d.getMonth();
  1885. var day = d.getDate();
  1886. m = m +1;
  1887. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  1888. }else{
  1889. this.data[name] = v;
  1890. }
  1891. //this.data[name] = (d.isValid() && d.getFullYear()!=1970) ? d.format("%Y年%m月%d日") : v;
  1892. }
  1893. }
  1894. break;
  1895. }
  1896. },
  1897. _computeCustomItemData: function(name, field, ev){
  1898. //if (this.json.customFields[l.name]){
  1899. if (ev) this._bindCustomFieldChange(name, field, name);
  1900. this._computeItemFieldData(name, null, field);
  1901. //}
  1902. },
  1903. _bindCustomFieldChange: function(name, dataItem, dom){
  1904. var field = this.form.all[dataItem];
  1905. if (field){
  1906. var bindFun = function(){
  1907. this._computeItemFieldData(name, null, dataItem);
  1908. //if (this.data[name]){
  1909. if (this[dom]){
  1910. if (dom=="layout_redHeader" || dom=="layout_subject"){
  1911. this[dom].set("html", this.data[name]|| "");
  1912. }else if (dom=="layout_attachment"){
  1913. this.setAttachmentData();
  1914. }else{
  1915. this[dom].set("text", this.data[name]|| "");
  1916. }
  1917. }
  1918. this.reSetShow();
  1919. //}
  1920. }.bind(this);
  1921. field.node.store(this.json.id+"bindFun", bindFun);
  1922. field.addModuleEvent("change", bindFun);
  1923. }
  1924. },
  1925. _computeData: function(ev){
  1926. this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
  1927. this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
  1928. this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
  1929. this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
  1930. this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
  1931. this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
  1932. this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
  1933. this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
  1934. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
  1935. this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
  1936. this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
  1937. this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
  1938. this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
  1939. this._computeItemData("copyto2", "copyto2ValueType", "copyto2ValueData", "copyto2ValueScript", ev, "layout_copyto2Content");
  1940. this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
  1941. this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
  1942. this._computeItemData("meetingAttend", "meetingAttendValueType", "meetingAttendValueData", "meetingAttendValueScript", ev, "layout_meetingAttendContent");
  1943. this._computeItemData("meetingLeave", "meetingLeaveValueType", "meetingLeaveValueData", "meetingLeaveValueScript", ev, "layout_meetingLeaveContent");
  1944. this._computeItemData("meetingSit", "meetingSitValueType", "meetingSitValueData", "meetingSitValueScript", ev, "layout_meetingSitContent");
  1945. this._computeItemData("meetingRecord", "meetingRecordValueType", "meetingRecordValueData", "meetingRecordValueScript", ev, "layout_meetingRecordContent");
  1946. Object.each(this.json.customFields, function(field, k){
  1947. this._computeCustomItemData(k, field, ev);
  1948. }.bind(this));
  1949. // if (this.customLayouts){
  1950. // this.customLayouts.each(function(l){
  1951. // this._computeCustomItemData(l, ev);
  1952. // }.bind(this))
  1953. // }
  1954. },
  1955. _loadValue: function(){
  1956. var data = this._getBusinessData();
  1957. },
  1958. reload: function(){
  1959. this.resetData();
  1960. },
  1961. resetData: function(diffFiletext){
  1962. if (this.editMode){ this._switchReadOrEditInline(); }
  1963. this._computeData(false);
  1964. this.pages = [];
  1965. this.contentNode.empty();
  1966. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  1967. this.editMode = false;
  1968. this._createPage(function(control){
  1969. this._loadPageLayout(control);
  1970. this.setData(this.data, diffFiletext);
  1971. //this._checkSplitPage(this.pages[0]);
  1972. debugger;
  1973. this._repage();
  1974. }.bind(this));
  1975. },
  1976. isEmpty: function(){
  1977. var data = this.getData();
  1978. if( typeOf(data) !== "object" )return true;
  1979. return !data.filetext || data.filetext===this.json.defaultValue.filetext;
  1980. },
  1981. getData: function(){
  1982. //if (this.editMode){
  1983. debugger;
  1984. if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
  1985. if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
  1986. if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
  1987. if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
  1988. if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
  1989. if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
  1990. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  1991. if (this.layout_subject) this.data.subject = this.layout_subject.get("html");
  1992. if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
  1993. if (this.editMode) if (this.layout_filetext){
  1994. var text = this.layout_filetext.get("text");
  1995. text = text.replace(/\u3000*/g, "");
  1996. if (text && text !==this.json.defaultValue.filetext){
  1997. this.data.filetext = this.layout_filetext.get("html");
  1998. }else{
  1999. this.data.filetext = "";
  2000. }
  2001. }
  2002. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  2003. if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
  2004. if (this.layout_attachment){
  2005. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", false, "layout_attachment");
  2006. // var atts = [];
  2007. // var nodes = this.layout_attachment.getElements(".doc_layout_attachment_content_name");
  2008. // if (nodes.length){
  2009. // nodes.each(function(node){
  2010. // atts.push(node.get("text"));
  2011. // });
  2012. // }
  2013. // this.data.attachment = atts;
  2014. }
  2015. if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("html");
  2016. if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
  2017. if (this.layout_annotation) this.data.annotation = this.layout_annotation.get("text");
  2018. if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
  2019. if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
  2020. if (this.layout_copyto2Title) this.data.copyto2Title = this.layout_copyto2Title.get("text");
  2021. if (this.layout_copyto2Content) this.data.copyto2 = this.layout_copyto2Content.get("text");
  2022. if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
  2023. if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
  2024. if (this.layout_meetingAttendTitle) this.data.meetingAttendTitle = this.layout_meetingAttendTitle.get("text");
  2025. if (this.layout_meetingLeaveTitle) this.data.meetingLeaveTitle = this.layout_meetingLeaveTitle.get("text");
  2026. if (this.layout_meetingSitTitle) this.data.meetingSitTitle = this.layout_meetingSitTitle.get("text");
  2027. if (this.layout_meetingAttendContent) this.data.meetingAttend = this.layout_meetingAttendContent.get("html");
  2028. if (this.layout_meetingLeaveContent) this.data.meetingLeave = this.layout_meetingLeaveContent.get("html");
  2029. if (this.layout_meetingSitContent) this.data.meetingSit = this.layout_meetingSitContent.get("html");
  2030. if (this.layout_meetingRecordContent) this.data.meetingRecord = this.layout_meetingRecordContent.get("html");
  2031. if (this.customLayouts){
  2032. this.customLayouts.each(function(l){
  2033. this.data[l.name] = l.node.get("html");
  2034. }.bind(this))
  2035. }
  2036. //}
  2037. return this.data;
  2038. },
  2039. setAttachmentData: function(){
  2040. if (!this.attachmentTemplete){
  2041. this.attachmentTemplete = this.layout_attachment.get("html");
  2042. }
  2043. this.layout_attachment.empty();
  2044. if (this.data.attachment && this.data.attachment.length && this.data.attachment.each){
  2045. //var tmpdiv = new Element("div", {"styles": {"display":"none"}}).inject(document.body);
  2046. var tmpdiv = new Element("div");
  2047. this.data.attachment.each(function(name, idx){
  2048. tmpdiv.set("html", this.attachmentTemplete);
  2049. var serialNode = tmpdiv.getElement(".doc_layout_attachment_content_serial");
  2050. var nameNode = tmpdiv.getElement(".doc_layout_attachment_content_name");
  2051. if (serialNode) serialNode.set("text", idx+1);
  2052. if (nameNode) nameNode.set("text", name);
  2053. var html = tmpdiv.get("html");
  2054. tmpdiv.empty();
  2055. this.layout_attachment.appendHTML(html);
  2056. }.bind(this));
  2057. tmpdiv.destroy();
  2058. }
  2059. },
  2060. setData: function(data, diffFiletext){
  2061. if (data){
  2062. this.data = data;
  2063. // this.data["$json"] = this.json;
  2064. this._setBusinessData(data);
  2065. if (this.layout_copies){
  2066. if (data.copies){
  2067. this.layout_copies.set("text", data.copies || " ");
  2068. }else{
  2069. this.layout_copies.set("html", "<span>&nbsp</span>");
  2070. }
  2071. }
  2072. if (this.layout_secret){
  2073. if (data.secret){
  2074. this.layout_secret.set("text", data.secret || " ");
  2075. }else{
  2076. this.layout_secret.set("html", "<span>&nbsp</span>");
  2077. }
  2078. }
  2079. if (this.layout_priority){
  2080. if (data.priority){
  2081. this.layout_priority.set("text", data.priority || " ");
  2082. }else{
  2083. this.layout_priority.set("html", "<span>&nbsp</span>");
  2084. }
  2085. }
  2086. if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
  2087. if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
  2088. if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
  2089. if (this.layout_signer) this.layout_signer.set("text", data.signer || " ");
  2090. if (this.layout_subject) this.layout_subject.set("html", data.subject || " ");
  2091. if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
  2092. if (diffFiletext) {
  2093. this.layout_filetext.set("html", diffFiletext);
  2094. }else if (this.layout_filetext){
  2095. //this.layout_filetext.set("placeholder", this.json.defaultValue.filetext);
  2096. this.layout_filetext.set("html", data.filetext || "  ");
  2097. }
  2098. if (this.layout_signer) this.layout_signer.set("text", data.signer || "");
  2099. if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
  2100. if (this.layout_attachment){
  2101. this.setAttachmentData();
  2102. }
  2103. if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("html", data.issuanceUnit || " ");
  2104. if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
  2105. if (this.layout_annotation) this.layout_annotation.set("text", data.annotation || " ");
  2106. if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
  2107. if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
  2108. if (this.layout_copyto2Title) this.layout_copyto2Title.set("text", data.copyto2Title || " ");
  2109. if (this.layout_copyto2Content) this.layout_copyto2Content.set("text", data.copyto2 || " ");
  2110. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
  2111. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
  2112. if (this.layout_meetingAttendTitle) this.layout_meetingAttendTitle.set("text", data.meetingAttendTitle || this.json.defaultValue.meetingAttendTitle || " ");
  2113. if (this.layout_meetingLeaveTitle) this.layout_meetingLeaveTitle.set("text", data.meetingLeaveTitle || this.json.defaultValue.meetingLeaveTitle || " ");
  2114. if (this.layout_meetingSitTitle) this.layout_meetingSitTitle.set("text", data.meetingSitTitle || this.json.defaultValue.meetingSitTitle || " ");
  2115. if (this.layout_meetingAttendContent) this.layout_meetingAttendContent.set("html", data.meetingAttend || " ");
  2116. if (this.layout_meetingLeaveContent) this.layout_meetingLeaveContent.set("html", data.meetingLeave || " ");
  2117. if (this.layout_meetingSitContent) this.layout_meetingSitContent.set("html", data.meetingSit || " ");
  2118. if (this.layout_meetingRecordContent) this.layout_meetingRecordContent.set("html", data.meetingRecord || " ");
  2119. if (this.customLayouts){
  2120. this.customLayouts.each(function(l){
  2121. l.node.set("html", this.data[l.name] || " ");
  2122. }.bind(this))
  2123. }
  2124. debugger;
  2125. if (this.layout_issuanceUnit && this.layout_issuanceDate ){
  2126. var table = this.layout_issuanceUnit.getParent("table")
  2127. if (table && !table.hasClass("doc_layout_headIssuance")){
  2128. var unitWidth = o2.getTextSize(this.layout_issuanceUnit.get("text"), {
  2129. "font-size":"16pt",
  2130. "font-family":"'Times New Roman',仿宋",
  2131. "letter-spacing": "-0.4pt"
  2132. }).x;
  2133. var dateWidth = o2.getTextSize(this.layout_issuanceDate.get("text"), {
  2134. "font-size":"16pt",
  2135. "font-family":"'Times New Roman',仿宋",
  2136. "letter-spacing": "-0.4pt"
  2137. }).x;
  2138. // var unitWidth = this.layout_issuanceUnit.getSize().x;
  2139. // var dateWidth = this.layout_issuanceDate.getSize().x;
  2140. if (unitWidth<dateWidth){
  2141. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  2142. if (flagTd){
  2143. var pt = ((dateWidth-unitWidth)/96)*72 +32+32;
  2144. flagTd.setStyle("width", ""+pt+"pt");
  2145. }
  2146. table = this.layout_issuanceDate.getParent("table");
  2147. table.setStyle("width", "auto");
  2148. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  2149. if (flagTd) flagTd.setStyle("width", "32pt");
  2150. var p = this.layout_issuanceDate.getParent("p");
  2151. if (p) p.setStyle("text-align", "right");
  2152. }else{
  2153. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  2154. if (flagTd) flagTd.setStyle("width", "32pt");
  2155. var table = this.layout_issuanceUnit.getParent("table");
  2156. var x = table.getSize().x;
  2157. table = this.layout_issuanceDate.getParent("table");
  2158. table.setStyle("width", ""+x+"px");
  2159. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  2160. if (flagTd) flagTd.setStyle("width", "32pt");
  2161. var p = this.layout_issuanceDate.getParent("p");
  2162. if (p) p.setStyle("text-align", "center");
  2163. }
  2164. }
  2165. }
  2166. var coptyToTitleNode = (this.layout_copytoTitle || this.layout_copyto2Title);
  2167. if (coptyToTitleNode){
  2168. var editionTable = coptyToTitleNode.getParent("table");
  2169. if (editionTable) if (editionTable.get("data-compute-style")=="y"){
  2170. var rows = editionTable.rows;
  2171. for (var i=0; i<rows.length; i++){
  2172. var cell = rows[i].cells[0];
  2173. var tmp = cell.getElement(".doc_layout_edition_issuance_unit");
  2174. if (!tmp) tmp = cell.getElement(".doc_layout_edition_issuance_date");
  2175. if (!tmp){
  2176. var text = cell.get("text").trim();
  2177. var l = 14*text.length;
  2178. cell.setStyles({
  2179. "max-width": ""+l+"pt",
  2180. "min-width": ""+l+"pt"
  2181. });
  2182. }
  2183. }
  2184. }
  2185. }
  2186. }
  2187. },
  2188. createErrorNode: function(text){
  2189. var node = new Element("div");
  2190. var iconNode = new Element("div", {
  2191. "styles": {
  2192. "width": "20px",
  2193. "height": "20px",
  2194. "float": "left",
  2195. "background": "url("+"../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  2196. }
  2197. }).inject(node);
  2198. var textNode = new Element("div", {
  2199. "styles": {
  2200. "line-height": "20px",
  2201. "margin-left": "20px",
  2202. "color": "red",
  2203. "word-break": "keep-all"
  2204. },
  2205. "text": text
  2206. }).inject(node);
  2207. return node;
  2208. },
  2209. notValidationMode: function(text){
  2210. if (!this.isNotValidationMode){
  2211. this.isNotValidationMode = true;
  2212. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  2213. this.node.setStyle("border", "1px solid red");
  2214. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  2215. this.showNotValidationMode(this.node);
  2216. }
  2217. },
  2218. showNotValidationMode: function(node){
  2219. var p = node.getParent("div");
  2220. if (p){
  2221. if (p.get("MWFtype") == "tab$Content"){
  2222. if (p.getParent("div").getStyle("display")=="none"){
  2223. var contentAreaNode = p.getParent("div").getParent("div");
  2224. var tabAreaNode = contentAreaNode.getPrevious("div");
  2225. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  2226. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  2227. tabNode.click();
  2228. p = tabAreaNode.getParent("div");
  2229. }
  2230. }
  2231. this.showNotValidationMode(p);
  2232. }
  2233. },
  2234. validationMode: function(){
  2235. if (this.isNotValidationMode){
  2236. this.isNotValidationMode = false;
  2237. this.node.setStyles(this.node.retrieve("borderStyle"));
  2238. if (this.errNode){
  2239. this.errNode.destroy();
  2240. this.errNode = null;
  2241. }
  2242. }
  2243. },
  2244. validationConfigItem: function(routeName, data){
  2245. var flag = (data.status=="all") ? true: (routeName == data.decision);
  2246. if (flag){
  2247. var n = this.getData();
  2248. var v = (data.valueType=="value") ? n : n.length;
  2249. switch (data.operateor){
  2250. case "isnull":
  2251. if (!v){
  2252. this.notValidationMode(data.prompt);
  2253. return false;
  2254. }
  2255. break;
  2256. case "notnull":
  2257. if (v){
  2258. this.notValidationMode(data.prompt);
  2259. return false;
  2260. }
  2261. break;
  2262. case "gt":
  2263. if (v>data.value){
  2264. this.notValidationMode(data.prompt);
  2265. return false;
  2266. }
  2267. break;
  2268. case "lt":
  2269. if (v<data.value){
  2270. this.notValidationMode(data.prompt);
  2271. return false;
  2272. }
  2273. break;
  2274. case "equal":
  2275. if (v==data.value){
  2276. this.notValidationMode(data.prompt);
  2277. return false;
  2278. }
  2279. break;
  2280. case "neq":
  2281. if (v!=data.value){
  2282. this.notValidationMode(data.prompt);
  2283. return false;
  2284. }
  2285. break;
  2286. case "contain":
  2287. if (v.indexOf(data.value)!=-1){
  2288. this.notValidationMode(data.prompt);
  2289. return false;
  2290. }
  2291. break;
  2292. case "notcontain":
  2293. if (v.indexOf(data.value)==-1){
  2294. this.notValidationMode(data.prompt);
  2295. return false;
  2296. }
  2297. break;
  2298. }
  2299. }
  2300. return true;
  2301. },
  2302. validationConfig: function(routeName, opinion){
  2303. if (this.json.validationConfig){
  2304. if (this.json.validationConfig.length){
  2305. for (var i=0; i<this.json.validationConfig.length; i++) {
  2306. var data = this.json.validationConfig[i];
  2307. if (!this.validationConfigItem(routeName, data)) return false;
  2308. }
  2309. }
  2310. return true;
  2311. }
  2312. return true;
  2313. },
  2314. validation: function(routeName, opinion){
  2315. if (!this.validationConfig(routeName, opinion)) return false;
  2316. if (!this.json.validation) return true;
  2317. if (!this.json.validation.code) return true;
  2318. var flag = this.form.Macro.exec(this.json.validation.code, this);
  2319. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  2320. if (flag.toString()!="true"){
  2321. this.notValidationMode(flag);
  2322. return false;
  2323. }
  2324. return true;
  2325. },
  2326. removeDisplayNone: function(node){
  2327. var n = node.getFirst();
  2328. while (n){
  2329. if (n.getStyle("display")=="none"){
  2330. var tmp = n.getNext();
  2331. n.destroy();
  2332. n = tmp;
  2333. }else{
  2334. n = this.removeDisplayNone(n);
  2335. n = n.getNext();
  2336. }
  2337. }
  2338. return node;
  2339. },
  2340. toWord: function(callback, name){
  2341. debugger;
  2342. var docNmae = name || "";
  2343. if (!docNmae){
  2344. try{
  2345. docNmae = this.json.toWordFilename || this.form.businessData.data.subject || this.form.businessData.data["$work"].title
  2346. }catch (e) {}
  2347. }
  2348. var toEdit = false;
  2349. if (this.editMode){
  2350. toEdit = true;
  2351. this._readFiletext();
  2352. }
  2353. //this._returnScale();
  2354. this.zoom(1);
  2355. this.pages = [];
  2356. this.contentNode.empty();
  2357. this._createPage(function(control){
  2358. this._loadPageLayout(control);
  2359. this.setData(this.data);
  2360. this._checkScale();
  2361. this.node.setStyles({
  2362. "height":"auto"
  2363. });
  2364. //var content = this.contentNode.getFirst().getFirst().get("html");
  2365. var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
  2366. var htmlNode = tmpNode.getLast();
  2367. htmlNode = this.removeDisplayNone(htmlNode);
  2368. var content = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"><head><meta charset=\"UTF-8\" /></head><body>"+tmpNode.get("html")+"</body></html>";
  2369. var fileName = docNmae || this.json.toWordFilename || "$doc";
  2370. fileName = fileName+".doc";
  2371. var body = {
  2372. "fileName": fileName,
  2373. "site": this.json.toWordSite || "$doc",
  2374. "content": content
  2375. };
  2376. o2.Actions.get("x_processplatform_assemble_surface").docToWord(this.form.businessData.work.id, body, function(json){
  2377. if (this.form.businessData.workCompleted){
  2378. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id,function(attjson){
  2379. if (callback) callback(attjson.data);
  2380. this.showToWord(attjson.data);
  2381. }.bind(this));
  2382. }else{
  2383. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id,function(attjson){
  2384. if (callback) callback(attjson.data);
  2385. this.showToWord(attjson.data);
  2386. }.bind(this));
  2387. }
  2388. }.bind(this));
  2389. tmpNode.destroy();
  2390. if (!toEdit){
  2391. this._readFiletext();
  2392. }else{
  2393. this._createEditor();
  2394. }
  2395. }.bind(this));
  2396. },
  2397. docToWord: function(){
  2398. debugger;
  2399. var flag = true;
  2400. if (this.json.toWordConditionScript && this.json.toWordConditionScript.code){
  2401. flag = !!this.form.Macro.exec(this.json.toWordConditionScript.code, this);
  2402. }
  2403. if (flag){
  2404. this.toWord();
  2405. }
  2406. },
  2407. showToWord: function(att){
  2408. var site = this.json.toWordSite || "$doc";
  2409. var attModule = this.form.all[site];
  2410. if (attModule){
  2411. attModule.attachmentController.clear();
  2412. attModule.attachmentController.addAttachment(att);
  2413. }
  2414. }
  2415. });