Documenteditor.js 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302
  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. _loadPageLayout: function(control){
  405. this._loadCopiesSecretPriority();
  406. this._loadRedHeader();
  407. if (this.json.fileup){
  408. this._loadFileNoUp();
  409. }else{
  410. this._loadFileNo();
  411. }
  412. if (!this.layout_fileno) this._loadFileNo();
  413. this._loadRedLine();
  414. this._loadSubject();
  415. this._loadMainSend();
  416. this._loadFiletext();
  417. this._loadAttachment();
  418. this._loadIssuance();
  419. this._loadAnnotation();
  420. this._loadEdition();
  421. //会议纪要
  422. this._loadMeeting();
  423. this.reSetShow(control);
  424. this.reSetEdit();
  425. // 份数: this.layout_copies
  426. // 密级: this.layout_secret
  427. // 紧急程度: this.layout_priority
  428. // 红头: this.layout_redHeader
  429. // 上行文编号签发: this.layout_fileNoUpTable
  430. // 文号: this.layout_fileno
  431. // 签发: this.layout_signerTitle
  432. // 签发人: this.layout_signer
  433. // 文号: this.layout_fileno
  434. // 红线: this.layout_redLine
  435. // 标题: this.layout_subject
  436. // 主送单位: this.layout_mainSend
  437. // 正文: this.layout_filetexts
  438. // 附件: this.layout_attachmentTitle
  439. // 附件: this.layout_attachment
  440. // 单位: this.layout_issuanceUnit
  441. // 签发时间: this.layout_issuanceDate
  442. // 附注: this.layout_annotation
  443. // 抄送: this.layout_copytoTitle
  444. // 抄送: this.layout_copytoContent
  445. // 版记单位 this.layout_edition_issuance_unit
  446. // 版记日期 this.layout_edition_issuance_date
  447. },
  448. reSetShow: function(control){
  449. if (!control) control = this.getShowControl();
  450. var m = function(s){ return (control[s]) ? "show" : "hide"; }
  451. if (this.layout_copiesSecretPriority) this.layout_copiesSecretPriority[m("copiesSecretPriority")]();
  452. // control.copies = this._getShow("copies", "copiesShow", "copiesShowScript");
  453. // control.secret = this._getShow("secret", "secretShow", "secretShowScript");
  454. // control.priority = this._getShow("priority", "priorityShow", "priorityShowScript");
  455. var n = 0;
  456. if (!control.copies) n++;
  457. if (!control.secret) n++;
  458. if (!control.priority) n++;
  459. if (this.layout_copiesSecretPriority_blank){
  460. while (n>0){
  461. this.layout_copiesSecretPriority_blank.empty();
  462. this.layout_copiesSecretPriority_blank.appendHTML("<span style='font-size:16.0pt'>&nbsp;</span>");
  463. n--;
  464. }
  465. }
  466. if (this.layout_copies) this.layout_copies[m("copies")]();
  467. if (this.layout_secret) this.layout_secret[m("secret")]();
  468. if (this.layout_priority) this.layout_priority[m("priority")]();
  469. if (this.layout_redHeader) this.layout_redHeader[m("redHeader")]();
  470. if (this.layout_redLine) this.layout_redLine[m("redLine")]();
  471. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable[m("signer")]();
  472. if (this.layout_filenoArea) this.layout_filenoArea[(!control.signer) ? "show" : "hide"]();
  473. if (this.layout_fileno) this.layout_fileno[m("fileno")]();
  474. if (this.layout_subject) this.layout_subject[m("subject")]();
  475. if (this.layout_mainSend) this.layout_mainSend[m("mainSend")]();
  476. if (this.layout_attachmentTable) this.layout_attachmentTable[m("attachment")]();
  477. if (this.layout_issuanceUnit) this.layout_issuanceUnit[m("issuanceUnit")]();
  478. if (this.layout_issuanceDate) this.layout_issuanceDate[m("issuanceDate")]();
  479. if (this.layout_annotation) this.layout_annotation[m("annotation")]();
  480. 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)){
  481. if (this.layout_editionArea) this.layout_editionArea.hide();
  482. }else{
  483. if ((!control.copyto || !this.layout_copytoContent) && (!control.copyto2 || !this.layout_copyto2Content) ){
  484. if (this.layout_edition){
  485. if (this.layout_copytoContent) this.layout_copytoContent.getParent("tr").destroy();
  486. if (this.layout_copyto2Content) this.layout_copyto2Content.getParent("tr").destroy();
  487. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td")[0].setStyles({
  488. // "border-top": "solid windowtext 1.5pt",
  489. // "mso-border-top-alt": "solid windowtext 1pt"
  490. // });
  491. }
  492. }else if (!control.copyto || !this.layout_copytoContent){
  493. if (this.layout_copytoContent) this.layout_copytoContent.getParent("tr").destroy();
  494. //if (this.layout_copyto2Content) this.layout_edition.getElement("tr").destroy();
  495. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td").setStyles({
  496. // "border-top": "solid windowtext 1.5pt",
  497. // "mso-border-top-alt": "solid windowtext 1pt"
  498. // });
  499. }else if (!control.copyto2 || !this.layout_copyto2Content) {
  500. if (this.layout_copyto2Content) this.layout_copyto2Content.getParent("tr").destroy();
  501. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td").setStyles({
  502. // "border-bottom": "solid windowtext 0.75pt",
  503. // "mso-border-bottom-alt": "solid windowtext 0.75pt"
  504. // });
  505. }
  506. if ((!control.editionUnit || !this.layout_edition_issuance_unit) && (!control.editionDate || !this.layout_edition_issuance_date)){
  507. if (this.layout_editionArea && (this.layout_edition_issuance_date || this.layout_edition_issuance_unit)){
  508. var trs = this.layout_editionArea.getElement("table").rows;
  509. trs.item(trs.length-1).destroy();
  510. // trs = this.layout_editionArea.getElement("table").rows;
  511. // var tr = trs.item(trs.length-1);
  512. // if (tr){
  513. // tr.getElements("td").setStyles({
  514. // "border-bottom": "solid windowtext 1.5pt",
  515. // "mso-border-bottom-alt": "solid windowtext 1pt"
  516. // });
  517. // }
  518. }
  519. }
  520. if (this.layout_editionArea && (this.layout_edition_issuance_date || this.layout_edition_issuance_unit)){
  521. trs = this.layout_editionArea.getElement("table").rows;
  522. for (var i=0; i<trs.length; i++){
  523. var tds = trs.item(i).cells;
  524. for (var n=0; n<tds.length; n++){
  525. var td = tds.item(n);
  526. var tdClass = td.get("class");
  527. var tdClassList = (tdClass) ? tdClass.split(/\s+/g) : [];
  528. if (tdClassList.indexOf("line_top_thin_bottom_thick") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thick");
  529. if (tdClassList.indexOf("line_top_thick_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thick_bottom_thin");
  530. if (tdClassList.indexOf("line_top_thick_bottom_thick") != -1) tdClassList = tdClassList.erase("line_top_thick_bottom_thick");
  531. if (tdClassList.indexOf("line_top_thin_bottom_thin") == -1) tdClassList.unshift("line_top_thin_bottom_thin");
  532. // td.setStyles({
  533. // "border-top": "solid windowtext 0.75pt",
  534. // "mso-border-top-alt": "solid windowtext 0.75pt",
  535. // "border-bottom": "solid windowtext 0.75pt",
  536. // "mso-border-bottom-alt": "solid windowtext 0.75pt",
  537. // });
  538. if (i==0 && i!=(trs.length-1)){
  539. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  540. tdClassList.unshift("line_top_thick_bottom_thin");
  541. // td.setStyles({
  542. // "border-top": "solid windowtext 1.5pt",
  543. // "mso-border-top-alt": "solid windowtext 1pt"
  544. // });
  545. }else if (i==0 && i==(trs.length-1)){
  546. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  547. tdClassList.unshift("line_top_thick_bottom_thick");
  548. }else if (i!=0 && i==(trs.length-1)){
  549. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  550. tdClassList.unshift("line_top_thin_bottom_thick");
  551. }
  552. // if (i==(trs.length-1)){
  553. // if (tdClassList.indexOf("line_bottom_thin") != -1) tdClassList = tdClassList.erase("line_bottom_thin");
  554. // if (tdClassList.indexOf("line_bottom_thick") == -1) tdClassList.push("line_bottom_thick");
  555. // // td.setStyles({
  556. // // "border-bottom": "solid windowtext 1.5pt",
  557. // // "mso-border-bottom-alt": "solid windowtext 1pt"
  558. // // });
  559. // }
  560. tdClass = tdClassList.join(" ");
  561. td.set("class", tdClass);
  562. }
  563. }
  564. }
  565. if (this.layout_editionArea) this.layout_editionArea.show();
  566. if (this.layout_copytoTitle) this.layout_copytoTitle[m("copyto")]();
  567. if (this.layout_copytoContent) this.layout_copytoContent[m("copyto")]();
  568. if (this.layout_copyto2Title) this.layout_copyto2Title[m("copyto2")]();
  569. if (this.layout_copyto2Content) this.layout_copyto2Content[m("copyto2")]();
  570. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit[m("editionUnit")]();
  571. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date[m("editionDate")]();
  572. }
  573. if (this.layout_meetingAttendArea) this.layout_meetingAttendArea[m("meetingAttend")]();
  574. if (this.layout_meetingLeaveArea) this.layout_meetingLeaveArea[m("meetingLeave")]();
  575. if (this.layout_meetingSitArea) this.layout_meetingSitArea[m("meetingSit")]();
  576. if (this.layout_meetingRecordArea) this.layout_meetingRecordArea[m("meetingRecord")]();
  577. // this.layout_annotation[m("annotation")]();
  578. // this.layout_annotation[m("annotation")]();
  579. // this.layout_annotation[m("annotation")]();
  580. },
  581. reSetEdit: function(control){
  582. //未进行数据绑定时,可允许编辑
  583. if (!control) var control = this.getEditControl();
  584. if (!!this.json.subjectValueData && this.json.subjectValueType=="data") this.layout_subject.set("contenteditable", control.subject);
  585. // this.layout_subject.addEvent("keydown", function(e){
  586. // debugger;
  587. // if (this.json.subjectValueType=="data" && this.json.subjectValueData){
  588. // // var v = e.target.get("HTML");
  589. // // this.form.businessData.data[this.json.subjectValueData] = v
  590. // var module = this.form.all[this.json.subjectValueData];
  591. // if (module){
  592. // var bindFun = module.node.retrieve(this.json.id+"bindFun");
  593. // module.node
  594. // }
  595. // }
  596. // }.bind(this));
  597. },
  598. _loadUserInterface: function(callback){
  599. this.node.empty();
  600. this.node.setStyles(this.form.css.documentEditorNode);
  601. this.pages = [];
  602. this.allowEdit = this._isAllowEdit();
  603. this.allowPrint = this._isAllowPrint();
  604. this.allowHistory = this._isAllowHistory();
  605. this.toolNode = new Element("div", {"styles": this.css.doc_toolbar}).inject(this.node);
  606. this.contentNode = new Element("div", {"styles": this.css.doc_content}).inject(this.node);
  607. if (!this.form.isLoaded){
  608. this.form.addEvent("afterModulesLoad", function(){this.loadDocumentEditor(callback);}.bind(this));
  609. }else{
  610. this.loadDocumentEditor(callback);
  611. }
  612. },
  613. loadDocumentEditor: function(callback){
  614. this._loadToolbars();
  615. this._loadFiletextPage(function(){
  616. if (this.options.pageShow!=="double"){
  617. this._singlePage();
  618. }else{
  619. this._doublePage();
  620. }
  621. // this.form.addEvent("beforeProcess", function(){
  622. // this.resetData();
  623. // if (this.checkSaveNewEdition()) this.saveNewDataEdition();
  624. // this.notSaveResetData = true;
  625. // }.bind(this));
  626. this.form.addEvent("beforeSave", function(){
  627. this.resetData();
  628. this.checkSaveNewEdition();
  629. //if (!this.notSaveResetData) this.resetData();
  630. }.bind(this));
  631. if (this.json.toWord=="y"){
  632. if (this.json.toWordTrigger=="open") this.docToWord();
  633. if (this.json.toWordTrigger=="save") this.form.addEvent("beforeSave", this.docToWord.bind(this));
  634. if (this.json.toWordTrigger=="submit") this.form.addEvent("beforeProcess", this.docToWord.bind(this));
  635. }
  636. if (!layout.mobile) this.loadSideToolbar();
  637. o2.load("../o2_lib/diff-match-patch/diff_match_patch.js");
  638. if (this.form.businessData.data["$work"]){
  639. var id = this.form.businessData.data["$work"].job;
  640. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.listWithJobCategory(id, this.json.id, function(json){
  641. this.historyDocumentList = json.data;
  642. if (this.historyDocumentList.length){
  643. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.get(this.historyDocumentList[this.historyDocumentList.length-1].id, function(json){
  644. var data = JSON.parse(json.data.data);
  645. this.originaHistoryData = data.data;
  646. }.bind(this));
  647. }
  648. }.bind(this));
  649. }
  650. if (callback) callback();
  651. }.bind(this));
  652. if (!this.form.documenteditorList) this.form.documenteditorList=[];
  653. this.form.documenteditorList.push(this);
  654. },
  655. checkSaveNewEdition: function(callback){
  656. debugger;
  657. if (!this.allowEdit || !this.data.filetext || this.data.filetext == this.json.defaultValue.filetext) return false;
  658. if (this.form.businessData.work){
  659. var originaData = this.form.businessData.originalData[this.json.id];
  660. var editionData = {"category": this.json.id};
  661. if (!originaData || !originaData.filetext || !this.originaHistoryData){
  662. //保存原始版本
  663. this.originaHistoryData = {"data": this.data.filetext};
  664. editionData.data = JSON.stringify({"data": this.data.filetext});
  665. }else if (originaData.filetext!=this.data.filetext){
  666. //保存历史版本
  667. var data = this.data.filetext;
  668. var earlyData = originaData.filetext;
  669. var dmp = new diff_match_patch();
  670. var diff_d = dmp.diff_main(earlyData, data);
  671. dmp.diff_cleanupSemantic(diff_d);
  672. var patch_list = dmp.patch_make(earlyData, data, diff_d);
  673. editionData.data = JSON.stringify({"patchs": dmp.patch_toText(patch_list)});
  674. }else{
  675. return false;
  676. }
  677. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  678. //originaData.filetext = this.data.filetext;
  679. if (callback) callback();
  680. }.bind(this));
  681. }
  682. },
  683. // saveNewDataEdition: function(callback){
  684. // if (this.form.businessData.work){
  685. // var editionData = {"category": this.json.id};
  686. // if (this.form.businessData.originalData[this.json.id] && this.form.businessData.originalData[this.json.id].filetext){
  687. // var data = this.data.filetext;
  688. // var earlyData = this.form.businessData.originalData[this.json.id].filetext;
  689. // var dmp = new diff_match_patch();
  690. // var diff_d = dmp.diff_main(earlyData, data);
  691. // dmp.diff_cleanupSemantic(diff_d);
  692. // var patch_list = dmp.patch_make(earlyData, data, diff_d);
  693. // editionData.data = {"patchs": dmp.patch_toText(patch_list)};
  694. //
  695. // }else{
  696. // editionData.data = {"data": this.data.filetext};
  697. // }
  698. // o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  699. // this.form.businessData.originalData[this.json.id] = this.data.filetext;
  700. // if (callback) callback();
  701. // }.bind(this));
  702. // }
  703. // },
  704. resizeToolbar: function(){
  705. if (this.toolbarNode){
  706. var p = this.toolNode.getPosition(this.scrollNode);
  707. var size = this.toolNode.getSize();
  708. var pl = this.toolbarNode.getStyle("padding-left").toInt();
  709. var pr = this.toolbarNode.getStyle("padding-right").toInt();
  710. var x = size.x-pl-pr;
  711. //var pNode = this.toolNode.getOffsetParent();
  712. var paddingTop = this.form.node.getStyle("padding-top");
  713. try {
  714. paddingTop = paddingTop.toInt();
  715. }catch (e) {
  716. paddingTop = 0;
  717. }
  718. if (p.y<paddingTop){
  719. this.toolbarNode.inject(this.scrollNode);
  720. this.toolbarNode.setStyles({
  721. "position": "absolute",
  722. "width": ""+x+"px",
  723. "z-index": 200,
  724. "top": paddingTop+"px",
  725. "left": ""+p.x+"px"
  726. });
  727. }else{
  728. this.toolbarNode.inject(this.toolNode);
  729. this.toolbarNode.setStyles({"position": "static"});
  730. }
  731. }
  732. },
  733. resizeSidebar: function(){
  734. if (this.sidebarNode){
  735. var fileTextNode = this.contentNode.getElement("div.doc_layout_filetext");
  736. if (fileTextNode){
  737. this.sidebarNode.position({
  738. relativeTo: fileTextNode,
  739. position: 'topLeft',
  740. edge: 'topRight',
  741. offset: {"x": -20, "y": 60}
  742. });
  743. var p = fileTextNode.getPosition(this.form.app.content);
  744. var ptop = fileTextNode.getPosition(this.node);
  745. //if ((p.y+s.y)<0) this.sidebarNode.setStyle("top", p.y+s.y);
  746. if (p.y<0){
  747. var top = ptop.y-p.y+200;
  748. this.sidebarNode.setStyle("top", top);
  749. }
  750. // var p = fileTextNode.getPosition();
  751. // this.sidebarNode.setStyle("top", p.y);
  752. }
  753. }
  754. },
  755. loadSideToolbar: function(){
  756. if (this.allowEdit){
  757. if (this.pages.length){
  758. var fileTextNode = this.pages[0].getElement("div.doc_layout_filetext");
  759. if (fileTextNode){
  760. this.sidebarNode = new Element("div", {"styles": this.css.doc_sidebar}).inject(this.node);
  761. this.resizeSidebar();
  762. this.scrollNode = this.sidebarNode.getParentSrcollNode();
  763. if (this.scrollNode){
  764. this.scrollNode.addEvent("scroll", function(){
  765. this.resizeSidebar();
  766. }.bind(this));
  767. }
  768. 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>";
  769. this.sidebarNode.set("html", html);
  770. MWF.require("MWF.widget.Toolbar", function() {
  771. this.sideToolbar = new MWF.widget.Toolbar(this.sidebarNode, {"style": "documentEdit_side"}, this);
  772. this.sideToolbar.load();
  773. }.bind(this));
  774. }
  775. }
  776. }
  777. },
  778. _returnScale: function(){
  779. this.isScale = false;
  780. this.scale = 0;
  781. this.contentNode.setStyles({
  782. "transform":"scale(1)",
  783. });
  784. if (this.pages.length){
  785. this.pages.each(function(page){
  786. page.setStyles({
  787. "transform":"scale(1)",
  788. });
  789. });
  790. }
  791. this.node.setStyles({
  792. "height": "auto"
  793. });
  794. },
  795. _checkScale: function(offset){
  796. offset = 0;
  797. if (this.pages.length){
  798. //var pageSize = this.pages[0].getSize();
  799. var pageSize_x = this.options.docPageFullWidth
  800. var contentSize = this.contentNode.getSize();
  801. var contentWidth = (offset) ? contentSize.x-20-offset : contentSize.x-20;
  802. if (contentWidth<pageSize_x){
  803. this.isScale = true;
  804. var scale = (contentWidth)/pageSize_x;
  805. this.scale = scale;
  806. this.zoom();
  807. this.resetNodeSize();
  808. }
  809. }
  810. },
  811. zoom: function(scale){
  812. if (scale) this.scale = scale;
  813. var w = this.node.getSize().x;
  814. if (this.history && this.history.historyListAreaNode) w = w-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  815. w = w/this.scale;
  816. this.contentNode.setStyles({
  817. "transform":"scale("+this.scale+")",
  818. "transform-origin": "0px 0px",
  819. "overflow": "hidden",
  820. "width": ""+w+"px"
  821. });
  822. },
  823. _switchReadOrEdit: function(){
  824. if (this.editMode){
  825. this._readFiletext();
  826. if (this.allowEdit) {
  827. var button = this.toolbar.childrenButton[0];
  828. button.setText(MWF.xApplication.process.Xform.LP.editdoc);
  829. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png")
  830. }
  831. this.editMode = false;
  832. }else{
  833. this._editFiletext();
  834. if (this.allowEdit) {
  835. var button = this.toolbar.childrenButton[0];
  836. button.setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  837. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png")
  838. }
  839. this.editMode = true;
  840. }
  841. },
  842. _switchReadOrEditInline: function(){
  843. if (this.editMode){
  844. this._readFiletext();
  845. if (this.allowEdit){
  846. if (!layout.mobile) {
  847. var button = this.sideToolbar.childrenButton[0];
  848. button.setText(MWF.xApplication.process.Xform.LP.editdoc);
  849. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png")
  850. }
  851. button = this.toolbar.childrenButton[0];
  852. button.setText(MWF.xApplication.process.Xform.LP.editdoc);
  853. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png")
  854. // if (!layout.mobile)this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  855. // this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  856. }
  857. this.editMode = false;
  858. }else{
  859. this._editFiletext("inline");
  860. if (this.allowEdit){
  861. if (!layout.mobile) {
  862. var button = this.sideToolbar.childrenButton[0];
  863. button.setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  864. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png")
  865. }
  866. button = this.toolbar.childrenButton[0];
  867. button.setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  868. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png")
  869. // if (!layout.mobile) this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  870. // this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  871. }
  872. this.editMode = true;
  873. }
  874. },
  875. _printDoc: function(){
  876. this.toWord(function(data){
  877. if (this.form.businessData.work && !this.form.businessData.work.completedTime){
  878. this.form.workAction.getAttachmentStream(data.id, this.form.businessData.work.id);
  879. }else{
  880. this.form.workAction.getWorkcompletedAttachmentStream(data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  881. }
  882. }.bind(this), "$doc.doc");
  883. },
  884. _historyDoc: function(){
  885. this.getHistory(function(){
  886. //this.history.play();
  887. }.bind(this));
  888. },
  889. getHistory: function(callback){
  890. if (this.history){
  891. this.history.active(function(){
  892. if (callback) callback();
  893. });
  894. }else{
  895. MWF.xDesktop.requireApp("process.Xform", "widget.DocumentHistory", function(){
  896. this.history = new MWF.xApplication.process.Xform.widget.DocumentHistory(this);
  897. this.history.load(function(){
  898. if (callback) callback();
  899. });
  900. }.bind(this));
  901. }
  902. },
  903. htmlToText: function(html){
  904. var tmpdiv = new Element("div", {"html": html});
  905. var text = tmpdiv.get("text");
  906. tmpdiv.destroy();
  907. return text;
  908. },
  909. _readFiletext: function(){
  910. //this._returnScale();
  911. this.zoom(1);
  912. if (this.filetextEditor) this.filetextEditor.destroy();
  913. if (this.filetextScrollNode){
  914. if (this.reLocationFiletextToolbarFun){
  915. this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  916. //this.form.app.removeEvent("resize", this.reLocationFiletextToolbarFun);
  917. this.reLocationFiletextToolbarFun = null;
  918. }
  919. this.filetextScrollNode = null;
  920. }
  921. if (this.filetextToolbarNode) this.filetextToolbarNode = null;
  922. this.layout_filetext.setAttribute('contenteditable', false);
  923. this.data = this.getData();
  924. // debugger;
  925. if (!this.data.filetext){
  926. //this.data.filetext = this.json.defaultValue.filetext;
  927. this.layout_filetext.set("html", this.json.defaultValue.filetext);
  928. }
  929. //this._checkSplitPage(this.pages[0]);
  930. this._repage();
  931. },
  932. _editFiletext: function(inline){
  933. this._returnScale();
  934. this.zoom(1);
  935. this._singlePage();
  936. this.pages = [];
  937. this.contentNode.empty();
  938. this._createPage(function(control){
  939. this._loadPageLayout(control);
  940. // var docData = this._getBusinessData();
  941. // if (!docData) docData = this._getDefaultData();
  942. if (this.data.filetext == this.json.defaultValue.filetext) this.data.filetext = "";
  943. this.setData(this.data);
  944. this._checkScale();
  945. this.node.setStyles({
  946. "height":"auto"
  947. });
  948. this._createEditor(inline);
  949. }.bind(this));
  950. },
  951. _createEditor: function(inline){
  952. if (this.allowEdit){
  953. this.loadCkeditorFiletext(function(e){
  954. e.editor.focus();
  955. e.editor.getSelection().scrollIntoView();
  956. //this.getFiletextToolber();
  957. //this.filetextToolbarNode.inject(this.layout_filetext.getOffsetParent());
  958. this.locationFiletextToolbar();
  959. }.bind(this), inline);
  960. }
  961. },
  962. getFiletextToolber: function(){
  963. if (this.filetextEditor) {
  964. if (!this.filetextToolbarNode) {
  965. var className = "cke_editor_" + this.filetextEditor.name;
  966. var filetextToolbarNode = $$("." + className)[0];
  967. this.filetextToolbarNode = filetextToolbarNode;
  968. //filetextToolbarNode.destroy();
  969. }
  970. }
  971. },
  972. reLocationFiletextToolbar: function(){
  973. this.getFiletextToolber();
  974. // if (this.filetextToolbarNode){
  975. // this.filetextToolbarNode.setStyle("display", "block");
  976. // var offsetNode = this.layout_filetext.getOffsetParent();
  977. //
  978. // this.filetextToolbarNode.setStyle("left", 0);
  979. // var h = this.filetextToolbarNode.getSize().y;
  980. // var p = this.layout_filetext.getPosition(offsetNode).y-h;
  981. //
  982. // var postion = this.layout_filetext.getPosition(this.form.app.content);
  983. // if (postion.y-h<0){
  984. // this.filetextToolbarNode.inject(this.form.app.content);
  985. // this.filetextToolbarNode.setStyle("top", 0);
  986. // this.filetextToolbarNode.setStyle("left", ""+postion.x+"px");
  987. // }else{
  988. // this.filetextToolbarNode.inject(offsetNode);
  989. // this.filetextToolbarNode.setStyle("top", "" + p + "px");
  990. // this.filetextToolbarNode.setStyle("left", 0);
  991. // this.filetextToolbarNode.setStyle("left", "auto");
  992. // }
  993. // }
  994. if (this.filetextToolbarNode){
  995. if (!this.filetextScrollNode){
  996. var scrollNode = this.contentNode;
  997. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  998. scrollNode = scrollNode.getParent();
  999. }
  1000. this.filetextScrollNode = scrollNode;
  1001. }
  1002. var h = this.filetextToolbarNode.getSize().y;
  1003. var position = this.layout_filetext.getPosition();
  1004. var size = this.layout_filetext.getSize();
  1005. var contentSize = this.filetextScrollNode.getSize();
  1006. if (position.y<0 && size.y+position.y+h<contentSize.y){
  1007. var top = size.y+position.y;
  1008. this.filetextToolbarNode.setStyle("top", ""+top+"px");
  1009. }else if (position.y-h<0){
  1010. this.filetextToolbarNode.setStyle("top", 0);
  1011. }else{
  1012. var p = this.layout_filetext.getPosition().y-h;
  1013. this.filetextToolbarNode.setStyle("top", "" + p + "px");
  1014. }
  1015. }
  1016. //
  1017. // this.filetextToolbarNode.inject(offsetNode);
  1018. //
  1019. //
  1020. // this.filetextToolbarNode.setStyle("top", ""+p+"px");
  1021. },
  1022. locationFiletextToolbar: function(){
  1023. this.reLocationFiletextToolbar();
  1024. if (this.filetextToolbarNode) {
  1025. var scrollNode = this.contentNode;
  1026. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  1027. scrollNode = scrollNode.getParent();
  1028. }
  1029. if (scrollNode){
  1030. this.filetextScrollNode = scrollNode;
  1031. this.reLocationFiletextToolbarFun = this.reLocationFiletextToolbar.bind(this);
  1032. this.filetextScrollNode.addEvent("scroll", this.reLocationFiletextToolbarFun);
  1033. }
  1034. }
  1035. },
  1036. _isAllowEdit:function(){
  1037. if (this.readonly) return false;
  1038. if (this.json.allowEdit=="n") return false;
  1039. if (this.json.allowEdit=="s"){
  1040. if (this.json.allowEditScript && this.json.allowEditScript.code){
  1041. return !!this.form.Macro.exec(this.json.allowEditScript.code, this);
  1042. }
  1043. }
  1044. return true;
  1045. },
  1046. _isAllowPrint: function(){
  1047. if (this.json.allowPrint=="n") return false;
  1048. if (this.json.allowPrint=="s"){
  1049. if (this.json.allowPrintScript && this.json.allowPrintScript.code){
  1050. return !!this.form.Macro.exec(this.json.allowPrintScript.code, this);
  1051. }
  1052. }
  1053. return true;
  1054. },
  1055. _isAllowHistory: function(){
  1056. if (this.json.allowHistory=="n") return false;
  1057. if (this.json.allowHistory=="s"){
  1058. if (this.json.allowHistoryScript && this.json.allowHistoryScript.code){
  1059. return !!this.form.Macro.exec(this.json.allowHistoryScript.code, this);
  1060. }
  1061. }
  1062. return true;
  1063. },
  1064. _getEdit: function(name, typeItem, scriptItem){
  1065. switch (this.json[typeItem]) {
  1066. case "y":
  1067. return true;
  1068. case "n":
  1069. return false;
  1070. case "s":
  1071. if (this.json[scriptItem] && this.json[scriptItem].code){
  1072. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  1073. }
  1074. return true;
  1075. }
  1076. },
  1077. loadCkeditorStyle: function(node){
  1078. if (node){
  1079. o2.load("ckeditor", function(){
  1080. //CKEDITOR.disableAutoInline = true;
  1081. node.setAttribute('contenteditable', true);
  1082. var editor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1083. this.filetextEditor.on("instanceReady", function(e){
  1084. if (callback) callback(e);
  1085. }.bind(this));
  1086. }.bind(this));
  1087. }
  1088. },
  1089. _loadToolbars: function(){
  1090. var html ="";
  1091. if (this.allowEdit){
  1092. //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>";
  1093. 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>";
  1094. //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>";
  1095. }
  1096. if (this.allowPrint){
  1097. 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>";
  1098. }
  1099. if (this.allowHistory){
  1100. 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>";
  1101. }
  1102. this.toolbarNode = new Element("div", {"styles": this.css.doc_toolbar_node}).inject(this.toolNode);
  1103. this.toolbarNode.set("html", html);
  1104. MWF.require("MWF.widget.Toolbar", function() {
  1105. this.toolbar = new MWF.widget.Toolbar(this.toolbarNode, {"style": "documentEdit"}, this);
  1106. this.toolbar.load();
  1107. }.bind(this));
  1108. this.scrollNode = this.toolbarNode.getParentSrcollNode();
  1109. if (this.scrollNode){
  1110. this.scrollNode.addEvent("scroll", function(){
  1111. this.resizeToolbar();
  1112. }.bind(this));
  1113. }
  1114. this.doublePageAction = new Element("div", {"styles": this.css.doc_toolbar_doublePage, "text": MWF.xApplication.process.Xform.LP.doublePage}).inject(this.toolbarNode);
  1115. this.doublePageAction.addEvent("click", function(){
  1116. if (this.options.pageShow!=="double"){
  1117. this._doublePage();
  1118. }else{
  1119. this._singlePage();
  1120. }
  1121. }.bind(this));
  1122. // this.zoomSelectAction = new Element("select", {"styles": {"float": "right"}}).inject(this.toolbarNode);
  1123. // var options = "<option value='2'>200%</option> " +
  1124. // "<option value='1.75'>175%</option>" +
  1125. // "<option value='1.5'>150%</option>" +
  1126. // "<option value='1' selected>100%</option>" +
  1127. // "<option value='0.75'>75%</option>" +
  1128. // "<option value='0.5'>50%</option>" +
  1129. // "<option value='0.25'>25%</option>"
  1130. // this.zoomSelectAction.set("html", options);
  1131. // this.zoomSelectAction.addEvent("change", function(e){
  1132. // this._returnScale();
  1133. // this.scale = e.target.options[e.target.selectedIndex].value;
  1134. // this.zoom();
  1135. // }.bind(this));
  1136. },
  1137. _repage: function(delay){
  1138. if (this.options.pageShow!=="double"){
  1139. this._singlePage();
  1140. }else{
  1141. this._doublePage();
  1142. }
  1143. if (delay){
  1144. if (!this.form.isLoaded){
  1145. this.form.addEvent("afterLoad", this._checkScale.bind(this));
  1146. }else{
  1147. this._checkScale();
  1148. }
  1149. }else{
  1150. this._checkScale();
  1151. }
  1152. },
  1153. _singlePage: function(){
  1154. //if (this.editMode) this._readFiletext();
  1155. this.zoom(1);
  1156. this._checkScale();
  1157. var w = this.contentNode.getSize().x;
  1158. var count = 1;
  1159. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1160. //var docPageFullWidth = this.options.docPageFullWidt;
  1161. var pageWidth = count * docPageFullWidth;
  1162. var margin = (w-pageWidth)/(count+1);
  1163. if (this.isScale){
  1164. margin = "10";
  1165. }
  1166. if (this.scale) margin = margin/this.scale;
  1167. this.pages.each(function(page, i){
  1168. page.setStyles({
  1169. "float": "left",
  1170. "margin-left": ""+margin+"px"
  1171. });
  1172. });
  1173. this.resetNodeSize();
  1174. // this.pages.each(function(page){
  1175. // page.setStyle("float", "none");
  1176. // });
  1177. this.resizeSidebar();
  1178. this.options.pageShow="single";
  1179. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
  1180. },
  1181. resetNodeSize: function(){
  1182. var contentSize = this.contentNode.getSize();
  1183. var toolbarSize = this.toolNode.getSize();
  1184. contentHeight = contentSize.y;
  1185. var h = contentHeight+toolbarSize.y+20;
  1186. //h = h - contentSize.y*(1-this.scale);
  1187. this.node.setStyles({
  1188. "height":""+h+"px"
  1189. });
  1190. },
  1191. createWaitSplitPage: function(){
  1192. this.node.mask({
  1193. "style": {
  1194. "background-color": "#cccccc",
  1195. "opacity": 0.3
  1196. }
  1197. });
  1198. this.waitSplitPageNode = new Element("div", {"styles": this.form.css.waitSplitPageNode, "text": MWF.xApplication.process.Xform.LP.computePage}).inject(this.node);
  1199. this.waitSplitPageNode.position({
  1200. "relativeTo": this.node,
  1201. "position": "topRight",
  1202. "edge": "topRight",
  1203. "offset": {
  1204. "x": -10,
  1205. "y": 45
  1206. }
  1207. });
  1208. //this.form.notice(MWF.xApplication.process.Xform.LP.computePage, "info", this.node);
  1209. },
  1210. clearWaitSplitPage: function(){
  1211. this.node.unmask();
  1212. if (this.waitSplitPageNode) this.waitSplitPageNode.destroy();
  1213. this.waitSplitPageNode = null;
  1214. },
  1215. _doublePage: function(){
  1216. if (this.editMode) this._switchReadOrEditInline();
  1217. this.zoom(1);
  1218. this.createWaitSplitPage();
  1219. window.setTimeout(function(){
  1220. this._checkSplitPage(this.pages[0]);
  1221. this.zoom(1);
  1222. var w = this.contentNode.getSize().x;
  1223. var toPageWidth = (w-100)/2;
  1224. scale = toPageWidth/this.options.docPageFullWidth;
  1225. if (scale<1) this.zoom(scale);
  1226. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1227. //var docPageFullWidth = this.options.docPageFullWidth;
  1228. var w = this.contentNode.getSize().x;
  1229. var count = (w/docPageFullWidth).toInt();
  1230. var pages = this.contentNode.getElements(".doc_layout_page");
  1231. count = Math.min(pages.length, count);
  1232. var pageWidth = count * docPageFullWidth;
  1233. var margin = (w-pageWidth)/(count+1);
  1234. if (this.scale) margin = margin/(this.scale);
  1235. this.pages.each(function(page, i){
  1236. page.setStyles({
  1237. "float": "left",
  1238. "margin-left": ""+margin+"px"
  1239. });
  1240. });
  1241. // this.pages.each(function(page, i){
  1242. // if ((i % 2)===0){
  1243. // page.setStyle("float", "left");
  1244. // }else{
  1245. // page.setStyle("float", "right");
  1246. // }
  1247. // });
  1248. this.resetNodeSize();
  1249. this.options.pageShow="double";
  1250. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
  1251. this.resizeSidebar();
  1252. this.clearWaitSplitPage();
  1253. }.bind(this), 1000);
  1254. },
  1255. _getDefaultData: function(){
  1256. return Object.clone(this.json.defaultValue);
  1257. //return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
  1258. },
  1259. _loadFiletextPage: function(callback){
  1260. this.data = this._getBusinessData();
  1261. if (!this.data) this.data = this._getDefaultData();
  1262. this._computeData(true);
  1263. this._createPage(function(control){
  1264. this._loadPageLayout(control);
  1265. // this.data = this._getBusinessData();
  1266. // if (!this.data) this.data = this._getDefaultData();
  1267. this.setData(this.data);
  1268. // this._checkSplitPage(this.pages[0]);
  1269. //this._repage(true);
  1270. //this.loadCkeditorFiletext();
  1271. if (!this.readonly){
  1272. //if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
  1273. // if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
  1274. // if (this.json.allowEditSubject) this.loadCkeditorSubject();
  1275. // if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
  1276. // if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
  1277. // if (this.json.allowEditSigner) this.loadCkeditorSigner();
  1278. // if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
  1279. }
  1280. if (callback) callback();
  1281. }.bind(this));
  1282. },
  1283. _getEditorConfig: function(){
  1284. // var mathElements = [
  1285. // 'math',
  1286. // 'maction',
  1287. // 'maligngroup',
  1288. // 'malignmark',
  1289. // 'menclose',
  1290. // 'merror',
  1291. // 'mfenced',
  1292. // 'mfrac',
  1293. // 'mglyph',
  1294. // 'mi',
  1295. // 'mlabeledtr',
  1296. // 'mlongdiv',
  1297. // 'mmultiscripts',
  1298. // 'mn',
  1299. // 'mo',
  1300. // 'mover',
  1301. // 'mpadded',
  1302. // 'mphantom',
  1303. // 'mroot',
  1304. // 'mrow',
  1305. // 'ms',
  1306. // 'mscarries',
  1307. // 'mscarry',
  1308. // 'msgroup',
  1309. // 'msline',
  1310. // 'mspace',
  1311. // 'msqrt',
  1312. // 'msrow',
  1313. // 'mstack',
  1314. // 'mstyle',
  1315. // 'msub',
  1316. // 'msup',
  1317. // 'msubsup',
  1318. // 'mtable',
  1319. // 'mtd',
  1320. // 'mtext',
  1321. // 'mtr',
  1322. // 'munder',
  1323. // 'munderover',
  1324. // 'semantics',
  1325. // 'annotation',
  1326. // 'annotation-xml'
  1327. // ];
  1328. //CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.13.0/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
  1329. debugger;
  1330. var editorConfig = {
  1331. qtRows: 20, // Count of rows
  1332. qtColumns: 20, // Count of columns
  1333. qtBorder: '1', // Border of inserted table
  1334. qtWidth: '95%', // Width of inserted table
  1335. qtStyle: { 'border-collapse' : 'collapse' },
  1336. qtClass: 'documenteditor_table'+this.form.json.id+this.json.id, // Class of table
  1337. qtCellPadding: '0', // Cell padding table
  1338. qtCellSpacing: '0', // Cell spacing table
  1339. qtPreviewBorder: '4px double black', // preview table border
  1340. qtPreviewSize: '4px', // Preview table cell size
  1341. qtPreviewBackground: '#c8def4', // preview table background (hover)
  1342. // format_tags: '标题一;标题二;标题三;标题四;正文', // entries is displayed in "Paragraph format"
  1343. format_tags: '标题一;标题二;正文(标题三,四)', // entries is displayed in "Paragraph format"
  1344. 'format_标题一': {
  1345. name: '标题一(三号黑体)',
  1346. element: 'div',
  1347. styles: {
  1348. 'font-family': '黑体',
  1349. 'font-size': '16pt'
  1350. }
  1351. },
  1352. 'format_标题二': {
  1353. name: '标题二(三号楷体)',
  1354. element: 'div',
  1355. styles: {
  1356. 'font-family': '楷体',
  1357. 'font-size': '16pt'
  1358. }
  1359. },
  1360. // 'format_标题三': {
  1361. // name: '标题三',
  1362. // element: 'div',
  1363. // styles: {
  1364. // 'font-family': '仿宋',
  1365. // 'font-size': '16pt'
  1366. // }
  1367. // },
  1368. // 'format_标题四': {
  1369. // name: '标题四',
  1370. // element: 'div',
  1371. // styles: {
  1372. // 'font-family': '仿宋',
  1373. // 'font-size': '16pt'
  1374. // }
  1375. // },
  1376. 'format_正文(标题三,四)': {
  1377. name: '正文(标题三,四)',
  1378. element: 'div',
  1379. styles: {
  1380. 'font-family': '仿宋',
  1381. 'font-size': '16pt'
  1382. }
  1383. }
  1384. };
  1385. editorConfig.toolbarGroups = [
  1386. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  1387. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  1388. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  1389. { name: 'forms', groups: [ 'forms' ] },
  1390. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  1391. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  1392. { name: 'links', groups: [ 'links' ] },
  1393. { name: 'insert', groups: [ 'insert' ] },
  1394. { name: 'styles', groups: [ 'styles' ] },
  1395. { name: 'colors', groups: [ 'colors' ] },
  1396. { name: 'tools', groups: [ 'tools' ] },
  1397. { name: 'others', groups: [ 'others' ] },
  1398. { name: 'about', groups: [ 'about' ] }
  1399. ];
  1400. //editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,mathjax,ckeditor_wiris";
  1401. //editorConfig.extraPlugins = "ecnet,colordialog,quicktable,tableresize,eqneditor";
  1402. //editorConfig.extraPlugins = "tableresize,quicktable";
  1403. editorConfig.extraPlugins = "quicktable,tableresize";
  1404. //editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
  1405. 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';
  1406. //editorConfig.extraAllowedContent = mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)';
  1407. editorConfig.pasteFromWordRemoveFontStyles = false;
  1408. editorConfig.pasteFromWordRemoveStyles = false;
  1409. //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';
  1410. editorConfig.removePlugins = ['magicline'];
  1411. editorConfig.enterMode = 3;
  1412. // editorConfig.extraPlugins = ['ecnet','mathjax'];
  1413. // editorConfig.removePlugins = ['magicline'];
  1414. // editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
  1415. return editorConfig;
  1416. },
  1417. _checkSplitPage: function(pageNode){
  1418. if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
  1419. var contentNode = pageNode.getFirst();
  1420. if (contentNode.getSize().y>this.options.docPageHeight){
  1421. this._splitPage(pageNode);
  1422. }
  1423. var i = pageNode.get("data-pagecount").toInt();
  1424. if (i && this.pages.length-1>=i){
  1425. this._checkSplitPage(this.pages[i]);
  1426. }
  1427. if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
  1428. },
  1429. _splitFiletextNodeOneWord:function(lnode, nextPageNode){
  1430. var text = lnode.textContent;
  1431. var len = text.length;
  1432. var left = text.substring(0, len-1);
  1433. var right = text.substring(len-1, len);
  1434. lnode.textContent = left;
  1435. nextPageNode.textContent = right+nextPageNode.textContent;
  1436. //nextPageNode.appendText(right, "top");
  1437. },
  1438. _splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
  1439. var contentNode = pageNode.getFirst();
  1440. var lnode = node.lastChild;
  1441. if (!lnode){
  1442. if (node.parentNode) node.parentNode.removeChild(node);
  1443. //node.remove();
  1444. }else{
  1445. while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
  1446. var tmpnode = lnode.previousSibling;
  1447. var nodeType = lnode.nodeType;
  1448. if (!nextPageNode) nextPageNode = nextFiletextNode;
  1449. if (nodeType == Node.ELEMENT_NODE) {
  1450. if (lnode.tagName == "table") {
  1451. lnode.inject(nextPageNode);
  1452. } else if (lnode.tagName == "BR") {
  1453. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1454. } else {
  1455. var id = lnode.get("data-pagePart");
  1456. if (!id){
  1457. id = (new o2.widget.UUID()).toString();
  1458. lnode.set("data-pagePart", id);
  1459. }
  1460. var tmpNode = nextPageNode.getFirst();
  1461. if (tmpNode && tmpNode.get("data-pagePart")==id){
  1462. nextPageNode = tmpNode;
  1463. }else{
  1464. nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
  1465. }
  1466. //var subnode = lnode.getLast();
  1467. this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
  1468. if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1469. nextPageNode = nextPageNode.getParent();
  1470. }
  1471. } else if (nodeType == Node.TEXT_NODE) {
  1472. var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
  1473. while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
  1474. //console.log(contentNode.getSize().y);
  1475. this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
  1476. }
  1477. if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
  1478. } else {
  1479. //lnode.remove();
  1480. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1481. }
  1482. lnode = tmpnode;
  1483. }
  1484. if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
  1485. }
  1486. //this._checkSplitPage(pageNode);
  1487. },
  1488. _splitPage: function(pageNode){
  1489. var contentNode = pageNode.getFirst();
  1490. var blockNodes = pageNode.getElements(".doc_block");
  1491. if (blockNodes.length){
  1492. var blockNode = blockNodes[blockNodes.length-1];
  1493. var idx = this.pages.indexOf(pageNode);
  1494. if (this.pages.length<=idx+1) this._createNewPage();
  1495. var nextPage = this.pages[idx+1];
  1496. if (blockNode.hasClass("doc_layout_filetext")){
  1497. var filetextNode = nextPage.getElement(".doc_layout_filetext");
  1498. if (!filetextNode){
  1499. filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
  1500. //filetextNode.setAttribute('contenteditable', true);
  1501. }
  1502. if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
  1503. //var nextEditor = filetextNode.retrieve("editor");
  1504. var node = blockNode;
  1505. var nextPageNode = filetextNode;
  1506. this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
  1507. }else{
  1508. blockNode.inject(nextPage.getFirst(), "top");
  1509. //var contentNode = pageNode.getFirst();
  1510. if (contentNode.getSize().y>this.options.docPageHeight){
  1511. this._splitPage(pageNode);
  1512. }
  1513. }
  1514. }
  1515. },
  1516. loadCkeditorFiletext: function(callback, inline){
  1517. if (this.layout_filetext){
  1518. o2.load("../o2_lib/htmleditor/ckeditor4130/ckeditor.js", function(){
  1519. CKEDITOR.disableAutoInline = true;
  1520. this.layout_filetext.setAttribute('contenteditable', true);
  1521. if (inline){
  1522. this.filetextEditor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1523. }else{
  1524. this.filetextEditor = CKEDITOR.replace(this.layout_filetext, this._getEditorConfig());
  1525. }
  1526. this.filetextEditor.on("instanceReady", function(e){
  1527. if (callback) callback(e);
  1528. }.bind(this));
  1529. this.filetextEditor.on( 'focus', function( e ) {
  1530. window.setTimeout(this.reLocationFiletextToolbar.bind(this), 10);
  1531. }.bind(this) );
  1532. this.filetextEditor.on( 'paste', function( e ) {
  1533. var html = e.data.dataValue;
  1534. var tmp = new Element("div")
  1535. tmp.set("html", html);
  1536. var pList = tmp.getElements("p");
  1537. pList.each(function(p, i){
  1538. if (Browser.name=="ie"){
  1539. p.appendText("  ","top");
  1540. }else{
  1541. var textIndent = p.getStyle("text-indent");
  1542. if (textIndent.toInt()) p.appendText("  ","top");
  1543. }
  1544. });
  1545. e.data.dataValue = tmp.get("html");
  1546. tmp.destroy();
  1547. }.bind(this) );
  1548. // this.filetextEditor.on("key", function(e){
  1549. // debugger;
  1550. // }.bind(this));
  1551. }.bind(this));
  1552. }
  1553. },
  1554. _loadEvents: function(editorConfig){
  1555. Object.each(this.json.events, function(e, key){
  1556. if (e.code){
  1557. this.editor.on(key, function(event){
  1558. return this.form.Macro.fire(e.code, this, event);
  1559. }.bind(this), this);
  1560. }
  1561. }.bind(this));
  1562. },
  1563. _bindFieldChange: function(name,dataItem, dom){
  1564. var field = this.form.all[this.json[dataItem]];
  1565. if (field){
  1566. var bindFun = function(){
  1567. this._computeItemFieldData(name, dataItem);
  1568. //if (this.data[name]){
  1569. if (this[dom]){
  1570. if (dom=="layout_redHeader" || dom=="layout_subject"){
  1571. this[dom].set("html", this.data[name]|| "");
  1572. }else if (dom=="layout_attachment"){
  1573. this.setAttachmentData();
  1574. }else{
  1575. this[dom].set("text", this.data[name]|| "");
  1576. }
  1577. }
  1578. this.reSetShow();
  1579. //}
  1580. }.bind(this);
  1581. field.node.store(this.json.id+"bindFun", bindFun);
  1582. field.addModuleEvent("change", bindFun);
  1583. }
  1584. },
  1585. _computeItemFieldData: function(name, dataItem){
  1586. var v = "";
  1587. var module = this.form.all[this.json[dataItem]];
  1588. if (module && module.getData) v = module.getData();
  1589. if (!v) v = this.form.businessData.data[this.json[dataItem]];
  1590. if (v){
  1591. var t = o2.typeOf(v);
  1592. switch (t) {
  1593. case "string":
  1594. switch (name) {
  1595. case "issuanceDate":
  1596. case "editionDate":
  1597. var d = new Date(v);
  1598. debugger;
  1599. if (d.isValid() && d.getFullYear()!=1970){
  1600. var y = d.getFullYear();
  1601. var m = d.getMonth();
  1602. var day = d.getDate();
  1603. m = m +1;
  1604. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  1605. }else{
  1606. this.data[name] = v;
  1607. }
  1608. //this.data[name] = (new Date(v).isValid()) ? Date.parse(v).format("%Y年%m月%d%日") : v;
  1609. break;
  1610. case "mainSend":
  1611. this.data[name] = v + ":";
  1612. break;
  1613. default:
  1614. this.data[name] = v;
  1615. }
  1616. break;
  1617. case "array":
  1618. var strs = [];
  1619. v.each(function(value){
  1620. if (o2.typeOf(value)=="object" && value.distinguishedName){
  1621. strs.push(value.name);
  1622. }else{
  1623. strs.push(value.toString());
  1624. }
  1625. });
  1626. //if (strs.length){
  1627. switch (name) {
  1628. case "attachment":
  1629. // this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>");
  1630. var atts = strs.map(function(a){
  1631. return (a.indexOf(".")!=-1) ? a.substring(0, a.lastIndexOf(".")) : a;
  1632. });
  1633. this.data[name] = atts;
  1634. break;
  1635. case "issuanceDate":
  1636. case "editionDate":
  1637. var tmpStrs = strs.map(function(n, i){
  1638. var d = Date.parse(n);
  1639. if (d.isValid() && d.getFullYear()!=1970){
  1640. var y = d.getFullYear();
  1641. var m = d.getMonth();
  1642. var day = d.getDate();
  1643. m = m +1;
  1644. return ""+y+"年"+m+"月"+day+"日";
  1645. }else{
  1646. return n;
  1647. }
  1648. //return () ? d.format("%Y年%m月%d日") : n;
  1649. });
  1650. this.data[name] = tmpStrs.join(",");
  1651. break;
  1652. case "mainSend":
  1653. this.data[name] = strs.join(",") + ":";
  1654. break;
  1655. default:
  1656. this.data[name] = strs.join(",");
  1657. }
  1658. //}
  1659. break;
  1660. default:
  1661. this.data[name] = v.toString();
  1662. }
  1663. }else{
  1664. this.data[name] = this.json.defaultValue[name];
  1665. }
  1666. },
  1667. computeData: function(){
  1668. this._computeData(false);
  1669. this.setData(this.data);
  1670. },
  1671. _computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
  1672. switch (this.json[typeItem]) {
  1673. case "data":
  1674. if (this.json[dataItem]){
  1675. if (ev) this._bindFieldChange(name, dataItem, dom);
  1676. this._computeItemFieldData(name, dataItem);
  1677. }
  1678. break;
  1679. case "script":
  1680. if (this.json[scriptItem] && this.json[scriptItem].code){
  1681. var v = this.form.Macro.exec(this.json[scriptItem].code, this);
  1682. this.data[name] = v;
  1683. if (name=="attachment"){
  1684. //this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>") : v;
  1685. this.data[name] = (typeOf(v)=="array") ? v : [v];
  1686. }
  1687. if (name=="issuanceDate" || name=="editionDate"){
  1688. var d = Date.parse(v);
  1689. if (d.isValid() && d.getFullYear()!=1970){
  1690. var y = d.getFullYear();
  1691. var m = d.getMonth();
  1692. var day = d.getDate();
  1693. m = m +1;
  1694. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  1695. }else{
  1696. this.data[name] = v;
  1697. }
  1698. //this.data[name] = (d.isValid() && d.getFullYear()!=1970) ? d.format("%Y年%m月%d日") : v;
  1699. }
  1700. }
  1701. break;
  1702. }
  1703. },
  1704. _computeData: function(ev){
  1705. this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
  1706. this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
  1707. this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
  1708. this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
  1709. this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
  1710. this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
  1711. this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
  1712. this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
  1713. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
  1714. this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
  1715. this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
  1716. this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
  1717. this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
  1718. this._computeItemData("copyto2", "copyto2ValueType", "copyto2ValueData", "copyto2ValueScript", ev, "layout_copyto2Content");
  1719. this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
  1720. this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
  1721. this._computeItemData("meetingAttend", "meetingAttendValueType", "meetingAttendValueData", "meetingAttendValueScript", ev, "layout_meetingAttendContent");
  1722. this._computeItemData("meetingLeave", "meetingLeaveValueType", "meetingLeaveValueData", "meetingLeaveValueScript", ev, "layout_meetingLeaveContent");
  1723. this._computeItemData("meetingSit", "meetingSitValueType", "meetingSitValueData", "meetingSitValueScript", ev, "layout_meetingSitContent");
  1724. this._computeItemData("meetingRecord", "meetingRecordValueType", "meetingRecordValueData", "meetingRecordValueScript", ev, "layout_meetingRecordContent");
  1725. },
  1726. _loadValue: function(){
  1727. var data = this._getBusinessData();
  1728. },
  1729. reload: function(){
  1730. this.resetData();
  1731. },
  1732. resetData: function(diffFiletext){
  1733. if (this.editMode){ this._switchReadOrEditInline(); }
  1734. this._computeData(false);
  1735. this.pages = [];
  1736. this.contentNode.empty();
  1737. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  1738. this.editMode = false;
  1739. this._createPage(function(control){
  1740. this._loadPageLayout(control);
  1741. this.setData(this.data, diffFiletext);
  1742. //this._checkSplitPage(this.pages[0]);
  1743. debugger;
  1744. this._repage();
  1745. }.bind(this));
  1746. },
  1747. isEmpty: function(){
  1748. var data = this.getData();
  1749. if( typeOf(data) !== "object" )return true;
  1750. return !data.filetext || data.filetext===this.json.defaultValue.filetext;
  1751. },
  1752. getData: function(){
  1753. //if (this.editMode){
  1754. if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
  1755. if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
  1756. if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
  1757. if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
  1758. if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
  1759. if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
  1760. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  1761. if (this.layout_subject) this.data.subject = this.layout_subject.get("html");
  1762. if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
  1763. if (this.editMode) if (this.layout_filetext) this.data.filetext = this.layout_filetext.get("html");
  1764. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  1765. if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
  1766. if (this.layout_attachment){
  1767. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", false, "layout_attachment");
  1768. // var atts = [];
  1769. // var nodes = this.layout_attachment.getElements(".doc_layout_attachment_content_name");
  1770. // if (nodes.length){
  1771. // nodes.each(function(node){
  1772. // atts.push(node.get("text"));
  1773. // });
  1774. // }
  1775. // this.data.attachment = atts;
  1776. }
  1777. if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("text");
  1778. if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
  1779. if (this.layout_annotation) this.data.annotation = this.layout_annotation.get("text");
  1780. if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
  1781. if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
  1782. if (this.layout_copyto2Title) this.data.copyto2Title = this.layout_copyto2Title.get("text");
  1783. if (this.layout_copyto2Content) this.data.copyto2 = this.layout_copyto2Content.get("text");
  1784. if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
  1785. if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
  1786. if (this.layout_meetingAttendTitle) this.data.meetingAttendTitle = this.layout_meetingAttendTitle.get("text");
  1787. if (this.layout_meetingLeaveTitle) this.data.meetingLeaveTitle = this.layout_meetingLeaveTitle.get("text");
  1788. if (this.layout_meetingSitTitle) this.data.meetingSitTitle = this.layout_meetingSitTitle.get("text");
  1789. if (this.layout_meetingAttendContent) this.data.meetingAttend = this.layout_meetingAttendContent.get("html");
  1790. if (this.layout_meetingLeaveContent) this.data.meetingLeave = this.layout_meetingLeaveContent.get("html");
  1791. if (this.layout_meetingSitContent) this.data.meetingSit = this.layout_meetingSitContent.get("html");
  1792. if (this.layout_meetingRecordContent) this.data.meetingRecord = this.layout_meetingRecordContent.get("html");
  1793. //}
  1794. return this.data;
  1795. },
  1796. setAttachmentData: function(){
  1797. if (!this.attachmentTemplete){
  1798. this.attachmentTemplete = this.layout_attachment.get("html");
  1799. }
  1800. this.layout_attachment.empty();
  1801. if (this.data.attachment && this.data.attachment.length && this.data.attachment.each){
  1802. //var tmpdiv = new Element("div", {"styles": {"display":"none"}}).inject(document.body);
  1803. var tmpdiv = new Element("div");
  1804. this.data.attachment.each(function(name, idx){
  1805. tmpdiv.set("html", this.attachmentTemplete);
  1806. var serialNode = tmpdiv.getElement(".doc_layout_attachment_content_serial");
  1807. var nameNode = tmpdiv.getElement(".doc_layout_attachment_content_name");
  1808. if (serialNode) serialNode.set("text", idx+1);
  1809. if (nameNode) nameNode.set("text", name);
  1810. var html = tmpdiv.get("html");
  1811. tmpdiv.empty();
  1812. this.layout_attachment.appendHTML(html);
  1813. }.bind(this));
  1814. tmpdiv.destroy();
  1815. }
  1816. },
  1817. setData: function(data, diffFiletext){
  1818. if (data){
  1819. this.data = data;
  1820. // this.data["$json"] = this.json;
  1821. this._setBusinessData(data);
  1822. if (this.layout_copies){
  1823. if (data.copies){
  1824. this.layout_copies.set("text", data.copies || " ");
  1825. }else{
  1826. this.layout_copies.set("html", "<span>&nbsp</span>");
  1827. }
  1828. }
  1829. if (this.layout_secret){
  1830. if (data.secret){
  1831. this.layout_secret.set("text", data.secret || " ");
  1832. }else{
  1833. this.layout_secret.set("html", "<span>&nbsp</span>");
  1834. }
  1835. }
  1836. if (this.layout_priority){
  1837. if (data.priority){
  1838. this.layout_priority.set("text", data.priority || " ");
  1839. }else{
  1840. this.layout_priority.set("html", "<span>&nbsp</span>");
  1841. }
  1842. }
  1843. if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
  1844. if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
  1845. if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
  1846. if (this.layout_signer) this.layout_signer.set("text", data.signer || " ");
  1847. if (this.layout_subject) this.layout_subject.set("html", data.subject || " ");
  1848. if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
  1849. if (diffFiletext) {
  1850. this.layout_filetext.set("html", diffFiletext);
  1851. }else if (this.layout_filetext){
  1852. //this.layout_filetext.set("placeholder", this.json.defaultValue.filetext);
  1853. this.layout_filetext.set("html", data.filetext || "");
  1854. }
  1855. if (this.layout_signer) this.layout_signer.set("text", data.signer || "");
  1856. if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
  1857. if (this.layout_attachment){
  1858. this.setAttachmentData();
  1859. }
  1860. if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("text", data.issuanceUnit || " ");
  1861. if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
  1862. if (this.layout_annotation) this.layout_annotation.set("text", data.annotation || " ");
  1863. if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
  1864. if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
  1865. if (this.layout_copyto2Title) this.layout_copyto2Title.set("text", data.copyto2Title || " ");
  1866. if (this.layout_copyto2Content) this.layout_copyto2Content.set("text", data.copyto2 || " ");
  1867. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
  1868. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
  1869. if (this.layout_meetingAttendTitle) this.layout_meetingAttendTitle.set("text", data.meetingAttendTitle || this.json.defaultValue.meetingAttendTitle || " ");
  1870. if (this.layout_meetingLeaveTitle) this.layout_meetingLeaveTitle.set("text", data.meetingLeaveTitle || this.json.defaultValue.meetingLeaveTitle || " ");
  1871. if (this.layout_meetingSitTitle) this.layout_meetingSitTitle.set("text", data.meetingSitTitle || this.json.defaultValue.meetingSitTitle || " ");
  1872. if (this.layout_meetingAttendContent) this.layout_meetingAttendContent.set("html", data.meetingAttend || " ");
  1873. if (this.layout_meetingLeaveContent) this.layout_meetingLeaveContent.set("html", data.meetingLeave || " ");
  1874. if (this.layout_meetingSitContent) this.layout_meetingSitContent.set("html", data.meetingSit || " ");
  1875. if (this.layout_meetingRecordContent) this.layout_meetingRecordContent.set("html", data.meetingRecord || " ");
  1876. }
  1877. },
  1878. createErrorNode: function(text){
  1879. var node = new Element("div");
  1880. var iconNode = new Element("div", {
  1881. "styles": {
  1882. "width": "20px",
  1883. "height": "20px",
  1884. "float": "left",
  1885. "background": "url("+"../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  1886. }
  1887. }).inject(node);
  1888. var textNode = new Element("div", {
  1889. "styles": {
  1890. "line-height": "20px",
  1891. "margin-left": "20px",
  1892. "color": "red",
  1893. "word-break": "keep-all"
  1894. },
  1895. "text": text
  1896. }).inject(node);
  1897. return node;
  1898. },
  1899. notValidationMode: function(text){
  1900. if (!this.isNotValidationMode){
  1901. this.isNotValidationMode = true;
  1902. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  1903. this.node.setStyle("border", "1px solid red");
  1904. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  1905. this.showNotValidationMode(this.node);
  1906. }
  1907. },
  1908. showNotValidationMode: function(node){
  1909. var p = node.getParent("div");
  1910. if (p){
  1911. if (p.get("MWFtype") == "tab$Content"){
  1912. if (p.getParent("div").getStyle("display")=="none"){
  1913. var contentAreaNode = p.getParent("div").getParent("div");
  1914. var tabAreaNode = contentAreaNode.getPrevious("div");
  1915. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  1916. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  1917. tabNode.click();
  1918. p = tabAreaNode.getParent("div");
  1919. }
  1920. }
  1921. this.showNotValidationMode(p);
  1922. }
  1923. },
  1924. validationMode: function(){
  1925. if (this.isNotValidationMode){
  1926. this.isNotValidationMode = false;
  1927. this.node.setStyles(this.node.retrieve("borderStyle"));
  1928. if (this.errNode){
  1929. this.errNode.destroy();
  1930. this.errNode = null;
  1931. }
  1932. }
  1933. },
  1934. validationConfigItem: function(routeName, data){
  1935. var flag = (data.status=="all") ? true: (routeName == data.decision);
  1936. if (flag){
  1937. var n = this.getData();
  1938. var v = (data.valueType=="value") ? n : n.length;
  1939. switch (data.operateor){
  1940. case "isnull":
  1941. if (!v){
  1942. this.notValidationMode(data.prompt);
  1943. return false;
  1944. }
  1945. break;
  1946. case "notnull":
  1947. if (v){
  1948. this.notValidationMode(data.prompt);
  1949. return false;
  1950. }
  1951. break;
  1952. case "gt":
  1953. if (v>data.value){
  1954. this.notValidationMode(data.prompt);
  1955. return false;
  1956. }
  1957. break;
  1958. case "lt":
  1959. if (v<data.value){
  1960. this.notValidationMode(data.prompt);
  1961. return false;
  1962. }
  1963. break;
  1964. case "equal":
  1965. if (v==data.value){
  1966. this.notValidationMode(data.prompt);
  1967. return false;
  1968. }
  1969. break;
  1970. case "neq":
  1971. if (v!=data.value){
  1972. this.notValidationMode(data.prompt);
  1973. return false;
  1974. }
  1975. break;
  1976. case "contain":
  1977. if (v.indexOf(data.value)!=-1){
  1978. this.notValidationMode(data.prompt);
  1979. return false;
  1980. }
  1981. break;
  1982. case "notcontain":
  1983. if (v.indexOf(data.value)==-1){
  1984. this.notValidationMode(data.prompt);
  1985. return false;
  1986. }
  1987. break;
  1988. }
  1989. }
  1990. return true;
  1991. },
  1992. validationConfig: function(routeName, opinion){
  1993. if (this.json.validationConfig){
  1994. if (this.json.validationConfig.length){
  1995. for (var i=0; i<this.json.validationConfig.length; i++) {
  1996. var data = this.json.validationConfig[i];
  1997. if (!this.validationConfigItem(routeName, data)) return false;
  1998. }
  1999. }
  2000. return true;
  2001. }
  2002. return true;
  2003. },
  2004. validation: function(routeName, opinion){
  2005. if (!this.validationConfig(routeName, opinion)) return false;
  2006. if (!this.json.validation) return true;
  2007. if (!this.json.validation.code) return true;
  2008. var flag = this.form.Macro.exec(this.json.validation.code, this);
  2009. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  2010. if (flag.toString()!="true"){
  2011. this.notValidationMode(flag);
  2012. return false;
  2013. }
  2014. return true;
  2015. },
  2016. removeDisplayNone: function(node){
  2017. var n = node.getFirst();
  2018. while (n){
  2019. if (n.getStyle("display")=="none"){
  2020. var tmp = n.getNext();
  2021. n.destroy();
  2022. n = tmp;
  2023. }else{
  2024. n = this.removeDisplayNone(n);
  2025. n = n.getNext();
  2026. }
  2027. }
  2028. return node;
  2029. },
  2030. toWord: function(callback, name){
  2031. debugger;
  2032. var toEdit = false;
  2033. if (this.editMode){
  2034. toEdit = true;
  2035. this._readFiletext();
  2036. }
  2037. //this._returnScale();
  2038. this.zoom(1);
  2039. this.pages = [];
  2040. this.contentNode.empty();
  2041. this._createPage(function(control){
  2042. this._loadPageLayout(control);
  2043. this.setData(this.data);
  2044. this._checkScale();
  2045. this.node.setStyles({
  2046. "height":"auto"
  2047. });
  2048. debugger;
  2049. //var content = this.contentNode.getFirst().getFirst().get("html");
  2050. var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
  2051. var htmlNode = tmpNode.getLast();
  2052. htmlNode = this.removeDisplayNone(htmlNode);
  2053. var content = "<html><head><meta charset=\"UTF-8\" /></head><body>"+tmpNode.get("html")+"</body></html>";
  2054. var body = {
  2055. "fileName": name || this.json.toWordFilename || "$doc.doc",
  2056. "site": this.json.toWordSite || "$doc",
  2057. "content": content
  2058. };
  2059. o2.Actions.get("x_processplatform_assemble_surface").docToWord(this.form.businessData.work.id, body, function(json){
  2060. if (this.form.businessData.workCompleted){
  2061. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id,function(attjson){
  2062. if (callback) callback(attjson.data);
  2063. this.showToWord(attjson.data);
  2064. }.bind(this));
  2065. }else{
  2066. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id,function(attjson){
  2067. if (callback) callback(attjson.data);
  2068. this.showToWord(attjson.data);
  2069. }.bind(this));
  2070. }
  2071. }.bind(this));
  2072. tmpNode.destroy();
  2073. if (!toEdit){
  2074. this._readFiletext();
  2075. }else{
  2076. this._createEditor();
  2077. }
  2078. }.bind(this));
  2079. },
  2080. docToWord: function(){
  2081. var flag = true;
  2082. if (this.json.toWordConditionScript && this.json.toWordConditionScript.code){
  2083. flag = !!this.form.Macro.exec(this.json.toWordConditionScript.code, this);
  2084. }
  2085. if (flag){
  2086. this.toWord();
  2087. }
  2088. },
  2089. showToWord: function(att){
  2090. var site = this.json.toWordSite || "$doc";
  2091. var attModule = this.form.all[site];
  2092. if (attModule){
  2093. attModule.attachmentController.clear();
  2094. attModule.attachmentController.addAttachment(att);
  2095. }
  2096. }
  2097. });