Documenteditor.js 99 KB

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