Documenteditor.js 103 KB

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