Documenteditor.js 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164
  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.scrollNode);
  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. //var pNode = this.toolNode.getOffsetParent();
  650. var paddingTop = this.form.node.getStyle("padding-top");
  651. try {
  652. paddingTop = paddingTop.toInt();
  653. }catch (e) {
  654. paddingTop = 0;
  655. }
  656. if (p.y<paddingTop){
  657. this.toolbarNode.inject(this.scrollNode);
  658. this.toolbarNode.setStyles({
  659. "position": "absolute",
  660. "width": ""+x+"px",
  661. "z-index": 20000,
  662. "top": paddingTop+"px",
  663. "left": ""+p.x+"px"
  664. });
  665. }else{
  666. this.toolbarNode.inject(this.toolNode);
  667. this.toolbarNode.setStyles({"position": "static"});
  668. }
  669. }
  670. },
  671. resizeSidebar: function(){
  672. if (this.sidebarNode){
  673. var fileTextNode = this.contentNode.getElement("div.doc_layout_filetext");
  674. if (fileTextNode){
  675. this.sidebarNode.position({
  676. relativeTo: fileTextNode,
  677. position: 'topLeft',
  678. edge: 'topRight',
  679. offset: {"x": -20, "y": 60}
  680. });
  681. var p = fileTextNode.getPosition(this.form.app.content);
  682. var ptop = fileTextNode.getPosition(this.node);
  683. //if ((p.y+s.y)<0) this.sidebarNode.setStyle("top", p.y+s.y);
  684. if (p.y<0){
  685. var top = ptop.y-p.y+200;
  686. this.sidebarNode.setStyle("top", top);
  687. }
  688. // var p = fileTextNode.getPosition();
  689. // this.sidebarNode.setStyle("top", p.y);
  690. }
  691. }
  692. },
  693. loadSideToolbar: function(){
  694. if (this.allowEdit){
  695. if (this.pages.length){
  696. var fileTextNode = this.pages[0].getElement("div.doc_layout_filetext");
  697. if (fileTextNode){
  698. this.sidebarNode = new Element("div", {"styles": this.css.doc_sidebar}).inject(this.node);
  699. this.resizeSidebar();
  700. this.scrollNode = this.sidebarNode.getParentSrcollNode();
  701. if (this.scrollNode){
  702. this.scrollNode.addEvent("scroll", function(){
  703. this.resizeSidebar();
  704. }.bind(this));
  705. }
  706. 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>";
  707. this.sidebarNode.set("html", html);
  708. MWF.require("MWF.widget.Toolbar", function() {
  709. this.sideToolbar = new MWF.widget.Toolbar(this.sidebarNode, {"style": "documentEdit_side"}, this);
  710. this.sideToolbar.load();
  711. }.bind(this));
  712. }
  713. }
  714. }
  715. },
  716. _returnScale: function(){
  717. this.isScale = false;
  718. this.scale = 0;
  719. this.contentNode.setStyles({
  720. "transform":"scale(1)",
  721. });
  722. if (this.pages.length){
  723. this.pages.each(function(page){
  724. page.setStyles({
  725. "transform":"scale(1)",
  726. });
  727. });
  728. }
  729. this.node.setStyles({
  730. "height": "auto"
  731. });
  732. },
  733. _checkScale: function(offset){
  734. offset = 0;
  735. if (this.pages.length){
  736. //var pageSize = this.pages[0].getSize();
  737. var pageSize_x = this.options.docPageFullWidth
  738. var contentSize = this.contentNode.getSize();
  739. var contentWidth = (offset) ? contentSize.x-20-offset : contentSize.x-20;
  740. if (contentWidth<pageSize_x){
  741. this.isScale = true;
  742. var scale = (contentWidth)/pageSize_x;
  743. this.scale = scale;
  744. this.zoom();
  745. this.resetNodeSize();
  746. }
  747. }
  748. },
  749. zoom: function(scale){
  750. if (scale) this.scale = scale;
  751. var w = this.node.getSize().x;
  752. if (this.history && this.history.historyListAreaNode) w = w-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  753. w = w/this.scale;
  754. this.contentNode.setStyles({
  755. "transform":"scale("+this.scale+")",
  756. "transform-origin": "0px 0px",
  757. "overflow": "hidden",
  758. "width": ""+w+"px"
  759. });
  760. },
  761. _switchReadOrEdit: function(){
  762. if (this.editMode){
  763. this._readFiletext();
  764. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  765. this.editMode = false;
  766. }else{
  767. this._editFiletext();
  768. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted)
  769. this.editMode = true;
  770. }
  771. },
  772. _switchReadOrEditInline: function(){
  773. if (this.editMode){
  774. this._readFiletext();
  775. if (this.allowEdit){
  776. if (!layout.mobile) this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  777. this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  778. }
  779. this.editMode = false;
  780. }else{
  781. this._editFiletext("inline");
  782. if (this.allowEdit){
  783. if (!layout.mobile) this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  784. this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  785. }
  786. this.editMode = true;
  787. }
  788. },
  789. _printDoc: function(){
  790. this.toWord(function(data){
  791. if (this.form.businessData.work && !this.form.businessData.work.completedTime){
  792. this.form.workAction.getAttachmentStream(data.id, this.form.businessData.work.id);
  793. }else{
  794. this.form.workAction.getWorkcompletedAttachmentStream(data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  795. }
  796. }.bind(this), "$doc.doc");
  797. },
  798. _historyDoc: function(){
  799. this.getHistory(function(){
  800. //this.history.play();
  801. }.bind(this));
  802. },
  803. getHistory: function(callback){
  804. if (this.history){
  805. this.history.active(function(){
  806. if (callback) callback();
  807. });
  808. }else{
  809. MWF.xDesktop.requireApp("process.Xform", "widget.DocumentHistory", function(){
  810. this.history = new MWF.xApplication.process.Xform.widget.DocumentHistory(this);
  811. this.history.load(function(){
  812. if (callback) callback();
  813. });
  814. }.bind(this));
  815. }
  816. },
  817. htmlToText: function(html){
  818. var tmpdiv = new Element("div", {"html": html});
  819. var text = tmpdiv.get("text");
  820. tmpdiv.destroy();
  821. return text;
  822. },
  823. _readFiletext: function(){
  824. //this._returnScale();
  825. this.zoom(1);
  826. if (this.filetextEditor) this.filetextEditor.destroy();
  827. if (this.filetextScrollNode){
  828. if (this.reLocationFiletextToolbarFun){
  829. this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  830. //this.form.app.removeEvent("resize", this.reLocationFiletextToolbarFun);
  831. this.reLocationFiletextToolbarFun = null;
  832. }
  833. this.filetextScrollNode = null;
  834. }
  835. if (this.filetextToolbarNode) this.filetextToolbarNode = null;
  836. this.layout_filetext.setAttribute('contenteditable', false);
  837. this.data = this.getData();
  838. // debugger;
  839. if (!this.data.filetext){
  840. //this.data.filetext = this.json.defaultValue.filetext;
  841. this.layout_filetext.set("html", this.json.defaultValue.filetext);
  842. }
  843. //this._checkSplitPage(this.pages[0]);
  844. this._repage();
  845. },
  846. _editFiletext: function(inline){
  847. this._returnScale();
  848. this.zoom(1);
  849. this._singlePage();
  850. this.pages = [];
  851. this.contentNode.empty();
  852. this._createPage(function(control){
  853. this._loadPageLayout(control);
  854. // var docData = this._getBusinessData();
  855. // if (!docData) docData = this._getDefaultData();
  856. if (this.data.filetext == this.json.defaultValue.filetext) this.data.filetext = "";
  857. this.setData(this.data);
  858. this._checkScale();
  859. this.node.setStyles({
  860. "height":"auto"
  861. });
  862. this._createEditor(inline);
  863. }.bind(this));
  864. },
  865. _createEditor: function(inline){
  866. if (this.allowEdit){
  867. this.loadCkeditorFiletext(function(e){
  868. e.editor.focus();
  869. e.editor.getSelection().scrollIntoView();
  870. //this.getFiletextToolber();
  871. //this.filetextToolbarNode.inject(this.layout_filetext.getOffsetParent());
  872. this.locationFiletextToolbar();
  873. }.bind(this), inline);
  874. }
  875. },
  876. getFiletextToolber: function(){
  877. if (this.filetextEditor) {
  878. if (!this.filetextToolbarNode) {
  879. var className = "cke_editor_" + this.filetextEditor.name;
  880. var filetextToolbarNode = $$("." + className)[0];
  881. this.filetextToolbarNode = filetextToolbarNode;
  882. //filetextToolbarNode.destroy();
  883. }
  884. }
  885. },
  886. reLocationFiletextToolbar: function(){
  887. this.getFiletextToolber();
  888. // if (this.filetextToolbarNode){
  889. // this.filetextToolbarNode.setStyle("display", "block");
  890. // var offsetNode = this.layout_filetext.getOffsetParent();
  891. //
  892. // this.filetextToolbarNode.setStyle("left", 0);
  893. // var h = this.filetextToolbarNode.getSize().y;
  894. // var p = this.layout_filetext.getPosition(offsetNode).y-h;
  895. //
  896. // var postion = this.layout_filetext.getPosition(this.form.app.content);
  897. // if (postion.y-h<0){
  898. // this.filetextToolbarNode.inject(this.form.app.content);
  899. // this.filetextToolbarNode.setStyle("top", 0);
  900. // this.filetextToolbarNode.setStyle("left", ""+postion.x+"px");
  901. // }else{
  902. // this.filetextToolbarNode.inject(offsetNode);
  903. // this.filetextToolbarNode.setStyle("top", "" + p + "px");
  904. // this.filetextToolbarNode.setStyle("left", 0);
  905. // this.filetextToolbarNode.setStyle("left", "auto");
  906. // }
  907. // }
  908. if (this.filetextToolbarNode){
  909. if (!this.filetextScrollNode){
  910. var scrollNode = this.contentNode;
  911. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  912. scrollNode = scrollNode.getParent();
  913. }
  914. this.filetextScrollNode = scrollNode;
  915. }
  916. var h = this.filetextToolbarNode.getSize().y;
  917. var position = this.layout_filetext.getPosition();
  918. var size = this.layout_filetext.getSize();
  919. var contentSize = this.filetextScrollNode.getSize();
  920. if (position.y<0 && size.y+position.y+h<contentSize.y){
  921. var top = size.y+position.y;
  922. this.filetextToolbarNode.setStyle("top", ""+top+"px");
  923. }else if (position.y-h<0){
  924. this.filetextToolbarNode.setStyle("top", 0);
  925. }else{
  926. var p = this.layout_filetext.getPosition().y-h;
  927. this.filetextToolbarNode.setStyle("top", "" + p + "px");
  928. }
  929. }
  930. //
  931. // this.filetextToolbarNode.inject(offsetNode);
  932. //
  933. //
  934. // this.filetextToolbarNode.setStyle("top", ""+p+"px");
  935. },
  936. locationFiletextToolbar: function(){
  937. this.reLocationFiletextToolbar();
  938. if (this.filetextToolbarNode) {
  939. var scrollNode = this.contentNode;
  940. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  941. scrollNode = scrollNode.getParent();
  942. }
  943. if (scrollNode){
  944. this.filetextScrollNode = scrollNode;
  945. this.reLocationFiletextToolbarFun = this.reLocationFiletextToolbar.bind(this);
  946. this.filetextScrollNode.addEvent("scroll", this.reLocationFiletextToolbarFun);
  947. }
  948. }
  949. },
  950. _isAllowEdit:function(){
  951. if (this.readonly) return false;
  952. if (this.json.allowEdit=="n") return false;
  953. if (this.json.allowEdit=="s"){
  954. if (this.json.allowEditScript && this.json.allowEditScript.code){
  955. return !!this.form.Macro.exec(this.json.allowEditScript.code, this);
  956. }
  957. }
  958. return true;
  959. },
  960. _isAllowPrint: function(){
  961. if (this.json.allowPrint=="n") return false;
  962. if (this.json.allowPrint=="s"){
  963. if (this.json.allowPrintScript && this.json.allowPrintScript.code){
  964. return !!this.form.Macro.exec(this.json.allowPrintScript.code, this);
  965. }
  966. }
  967. return true;
  968. },
  969. _isAllowHistory: function(){
  970. if (this.json.allowHistory=="n") return false;
  971. if (this.json.allowHistory=="s"){
  972. if (this.json.allowHistoryScript && this.json.allowHistoryScript.code){
  973. return !!this.form.Macro.exec(this.json.allowHistoryScript.code, this);
  974. }
  975. }
  976. return true;
  977. },
  978. _getEdit: function(name, typeItem, scriptItem){
  979. switch (this.json[typeItem]) {
  980. case "y":
  981. return true;
  982. case "n":
  983. return false;
  984. case "s":
  985. if (this.json[scriptItem] && this.json[scriptItem].code){
  986. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  987. }
  988. return true;
  989. }
  990. },
  991. loadCkeditorStyle: function(node){
  992. if (node){
  993. o2.load("ckeditor", function(){
  994. //CKEDITOR.disableAutoInline = true;
  995. node.setAttribute('contenteditable', true);
  996. var editor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  997. this.filetextEditor.on("instanceReady", function(e){
  998. if (callback) callback(e);
  999. }.bind(this));
  1000. }.bind(this));
  1001. }
  1002. },
  1003. _loadToolbars: function(){
  1004. var html ="";
  1005. if (this.allowEdit){
  1006. //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>";
  1007. 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>";
  1008. //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>";
  1009. }
  1010. if (this.allowPrint){
  1011. 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>";
  1012. }
  1013. if (this.allowHistory){
  1014. 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>";
  1015. }
  1016. this.toolbarNode = new Element("div", {"styles": this.css.doc_toolbar_node}).inject(this.toolNode);
  1017. this.toolbarNode.set("html", html);
  1018. MWF.require("MWF.widget.Toolbar", function() {
  1019. this.toolbar = new MWF.widget.Toolbar(this.toolbarNode, {"style": "documentEdit"}, this);
  1020. this.toolbar.load();
  1021. }.bind(this));
  1022. this.scrollNode = this.toolbarNode.getParentSrcollNode();
  1023. if (this.scrollNode){
  1024. this.scrollNode.addEvent("scroll", function(){
  1025. this.resizeToolbar();
  1026. }.bind(this));
  1027. }
  1028. this.doublePageAction = new Element("div", {"styles": this.css.doc_toolbar_doublePage, "text": MWF.xApplication.process.Xform.LP.doublePage}).inject(this.toolbarNode);
  1029. this.doublePageAction.addEvent("click", function(){
  1030. if (this.options.pageShow!=="double"){
  1031. this._doublePage();
  1032. }else{
  1033. this._singlePage();
  1034. }
  1035. }.bind(this));
  1036. // this.zoomSelectAction = new Element("select", {"styles": {"float": "right"}}).inject(this.toolbarNode);
  1037. // var options = "<option value='2'>200%</option> " +
  1038. // "<option value='1.75'>175%</option>" +
  1039. // "<option value='1.5'>150%</option>" +
  1040. // "<option value='1' selected>100%</option>" +
  1041. // "<option value='0.75'>75%</option>" +
  1042. // "<option value='0.5'>50%</option>" +
  1043. // "<option value='0.25'>25%</option>"
  1044. // this.zoomSelectAction.set("html", options);
  1045. // this.zoomSelectAction.addEvent("change", function(e){
  1046. // this._returnScale();
  1047. // this.scale = e.target.options[e.target.selectedIndex].value;
  1048. // this.zoom();
  1049. // }.bind(this));
  1050. },
  1051. _repage: function(delay){
  1052. if (this.options.pageShow!=="double"){
  1053. this._singlePage();
  1054. }else{
  1055. this._doublePage();
  1056. }
  1057. if (delay){
  1058. if (!this.form.isLoaded){
  1059. this.form.addEvent("afterLoad", this._checkScale.bind(this));
  1060. }else{
  1061. this._checkScale();
  1062. }
  1063. }else{
  1064. this._checkScale();
  1065. }
  1066. },
  1067. _singlePage: function(){
  1068. //if (this.editMode) this._readFiletext();
  1069. this.zoom(1);
  1070. this._checkScale();
  1071. var w = this.contentNode.getSize().x;
  1072. var count = 1;
  1073. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1074. //var docPageFullWidth = this.options.docPageFullWidt;
  1075. var pageWidth = count * docPageFullWidth;
  1076. var margin = (w-pageWidth)/(count+1);
  1077. if (this.isScale){
  1078. margin = "10";
  1079. }
  1080. if (this.scale) margin = margin/this.scale;
  1081. this.pages.each(function(page, i){
  1082. page.setStyles({
  1083. "float": "left",
  1084. "margin-left": ""+margin+"px"
  1085. });
  1086. });
  1087. this.resetNodeSize();
  1088. // this.pages.each(function(page){
  1089. // page.setStyle("float", "none");
  1090. // });
  1091. this.resizeSidebar();
  1092. this.options.pageShow="single";
  1093. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
  1094. },
  1095. resetNodeSize: function(){
  1096. var contentSize = this.contentNode.getSize();
  1097. var toolbarSize = this.toolNode.getSize();
  1098. contentHeight = contentSize.y;
  1099. var h = contentHeight+toolbarSize.y+20;
  1100. //h = h - contentSize.y*(1-this.scale);
  1101. this.node.setStyles({
  1102. "height":""+h+"px"
  1103. });
  1104. },
  1105. createWaitSplitPage: function(){
  1106. this.node.mask({
  1107. "style": {
  1108. "background-color": "#cccccc",
  1109. "opacity": 0.3
  1110. }
  1111. });
  1112. this.waitSplitPageNode = new Element("div", {"styles": this.form.css.waitSplitPageNode, "text": MWF.xApplication.process.Xform.LP.computePage}).inject(this.node);
  1113. this.waitSplitPageNode.position({
  1114. "relativeTo": this.node,
  1115. "position": "topRight",
  1116. "edge": "topRight",
  1117. "offset": {
  1118. "x": -10,
  1119. "y": 45
  1120. }
  1121. });
  1122. //this.form.notice(MWF.xApplication.process.Xform.LP.computePage, "info", this.node);
  1123. },
  1124. clearWaitSplitPage: function(){
  1125. this.node.unmask();
  1126. if (this.waitSplitPageNode) this.waitSplitPageNode.destroy();
  1127. this.waitSplitPageNode = null;
  1128. },
  1129. _doublePage: function(){
  1130. if (this.editMode) this._switchReadOrEditInline();
  1131. this.zoom(1);
  1132. this.createWaitSplitPage();
  1133. window.setTimeout(function(){
  1134. this._checkSplitPage(this.pages[0]);
  1135. this.zoom(1);
  1136. var w = this.contentNode.getSize().x;
  1137. var toPageWidth = (w-100)/2;
  1138. scale = toPageWidth/this.options.docPageFullWidth;
  1139. if (scale<1) this.zoom(scale);
  1140. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1141. //var docPageFullWidth = this.options.docPageFullWidth;
  1142. var w = this.contentNode.getSize().x;
  1143. var count = (w/docPageFullWidth).toInt();
  1144. var pages = this.contentNode.getElements(".doc_layout_page");
  1145. count = Math.min(pages.length, count);
  1146. var pageWidth = count * docPageFullWidth;
  1147. var margin = (w-pageWidth)/(count+1);
  1148. if (this.scale) margin = margin/(this.scale);
  1149. this.pages.each(function(page, i){
  1150. page.setStyles({
  1151. "float": "left",
  1152. "margin-left": ""+margin+"px"
  1153. });
  1154. });
  1155. // this.pages.each(function(page, i){
  1156. // if ((i % 2)===0){
  1157. // page.setStyle("float", "left");
  1158. // }else{
  1159. // page.setStyle("float", "right");
  1160. // }
  1161. // });
  1162. this.resetNodeSize();
  1163. this.options.pageShow="double";
  1164. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
  1165. this.resizeSidebar();
  1166. this.clearWaitSplitPage();
  1167. }.bind(this), 1000);
  1168. },
  1169. _getDefaultData: function(){
  1170. return Object.clone(this.json.defaultValue);
  1171. //return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
  1172. },
  1173. _loadFiletextPage: function(callback){
  1174. this.data = this._getBusinessData();
  1175. if (!this.data) this.data = this._getDefaultData();
  1176. this._computeData(true);
  1177. this._createPage(function(control){
  1178. this._loadPageLayout(control);
  1179. // this.data = this._getBusinessData();
  1180. // if (!this.data) this.data = this._getDefaultData();
  1181. this.setData(this.data);
  1182. // this._checkSplitPage(this.pages[0]);
  1183. //this._repage(true);
  1184. //this.loadCkeditorFiletext();
  1185. if (!this.readonly){
  1186. //if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
  1187. // if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
  1188. // if (this.json.allowEditSubject) this.loadCkeditorSubject();
  1189. // if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
  1190. // if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
  1191. // if (this.json.allowEditSigner) this.loadCkeditorSigner();
  1192. // if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
  1193. }
  1194. if (callback) callback();
  1195. }.bind(this));
  1196. },
  1197. _getEditorConfig: function(){
  1198. // var mathElements = [
  1199. // 'math',
  1200. // 'maction',
  1201. // 'maligngroup',
  1202. // 'malignmark',
  1203. // 'menclose',
  1204. // 'merror',
  1205. // 'mfenced',
  1206. // 'mfrac',
  1207. // 'mglyph',
  1208. // 'mi',
  1209. // 'mlabeledtr',
  1210. // 'mlongdiv',
  1211. // 'mmultiscripts',
  1212. // 'mn',
  1213. // 'mo',
  1214. // 'mover',
  1215. // 'mpadded',
  1216. // 'mphantom',
  1217. // 'mroot',
  1218. // 'mrow',
  1219. // 'ms',
  1220. // 'mscarries',
  1221. // 'mscarry',
  1222. // 'msgroup',
  1223. // 'msline',
  1224. // 'mspace',
  1225. // 'msqrt',
  1226. // 'msrow',
  1227. // 'mstack',
  1228. // 'mstyle',
  1229. // 'msub',
  1230. // 'msup',
  1231. // 'msubsup',
  1232. // 'mtable',
  1233. // 'mtd',
  1234. // 'mtext',
  1235. // 'mtr',
  1236. // 'munder',
  1237. // 'munderover',
  1238. // 'semantics',
  1239. // 'annotation',
  1240. // 'annotation-xml'
  1241. // ];
  1242. //CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.13.0/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
  1243. var editorConfig = {
  1244. qtRows: 20, // Count of rows
  1245. qtColumns: 20, // Count of columns
  1246. qtBorder: '1', // Border of inserted table
  1247. qtWidth: '95%', // Width of inserted table
  1248. qtStyle: { 'border-collapse' : 'collapse' },
  1249. qtClass: 'test', // Class of table
  1250. qtCellPadding: '0', // Cell padding table
  1251. qtCellSpacing: '0', // Cell spacing table
  1252. qtPreviewBorder: '4px double black', // preview table border
  1253. qtPreviewSize: '4px', // Preview table cell size
  1254. qtPreviewBackground: '#c8def4', // preview table background (hover)
  1255. // format_tags: '标题一;标题二;标题三;标题四;正文', // entries is displayed in "Paragraph format"
  1256. format_tags: '标题一;标题二;正文(标题三,四)', // entries is displayed in "Paragraph format"
  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. 'format_正文(标题三,四)': {
  1290. name: '正文(标题三,四)',
  1291. element: 'div',
  1292. styles: {
  1293. 'font-family': '仿宋',
  1294. 'font-size': '16pt'
  1295. }
  1296. }
  1297. };
  1298. editorConfig.toolbarGroups = [
  1299. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  1300. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  1301. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  1302. { name: 'forms', groups: [ 'forms' ] },
  1303. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  1304. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  1305. { name: 'links', groups: [ 'links' ] },
  1306. { name: 'insert', groups: [ 'insert' ] },
  1307. { name: 'styles', groups: [ 'styles' ] },
  1308. { name: 'colors', groups: [ 'colors' ] },
  1309. { name: 'tools', groups: [ 'tools' ] },
  1310. { name: 'others', groups: [ 'others' ] },
  1311. { name: 'about', groups: [ 'about' ] }
  1312. ];
  1313. //editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,mathjax,ckeditor_wiris";
  1314. //editorConfig.extraPlugins = "ecnet,colordialog,quicktable,tableresize,eqneditor";
  1315. //editorConfig.extraPlugins = "tableresize,quicktable";
  1316. editorConfig.extraPlugins = "quicktable,tableresize";
  1317. //editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
  1318. 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';
  1319. //editorConfig.extraAllowedContent = mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)';
  1320. //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';
  1321. editorConfig.removePlugins = ['magicline'];
  1322. editorConfig.enterMode = 3;
  1323. // editorConfig.extraPlugins = ['ecnet','mathjax'];
  1324. // editorConfig.removePlugins = ['magicline'];
  1325. // editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
  1326. return editorConfig;
  1327. },
  1328. _checkSplitPage: function(pageNode){
  1329. if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
  1330. var contentNode = pageNode.getFirst();
  1331. if (contentNode.getSize().y>this.options.docPageHeight){
  1332. this._splitPage(pageNode);
  1333. }
  1334. var i = pageNode.get("data-pagecount").toInt();
  1335. if (i && this.pages.length-1>=i){
  1336. this._checkSplitPage(this.pages[i]);
  1337. }
  1338. if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
  1339. },
  1340. _splitFiletextNodeOneWord:function(lnode, nextPageNode){
  1341. var text = lnode.textContent;
  1342. var len = text.length;
  1343. var left = text.substring(0, len-1);
  1344. var right = text.substring(len-1, len);
  1345. lnode.textContent = left;
  1346. nextPageNode.textContent = right+nextPageNode.textContent;
  1347. //nextPageNode.appendText(right, "top");
  1348. },
  1349. _splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
  1350. var contentNode = pageNode.getFirst();
  1351. var lnode = node.lastChild;
  1352. if (!lnode){
  1353. if (node.parentNode) node.parentNode.removeChild(node);
  1354. //node.remove();
  1355. }else{
  1356. while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
  1357. var tmpnode = lnode.previousSibling;
  1358. var nodeType = lnode.nodeType;
  1359. if (!nextPageNode) nextPageNode = nextFiletextNode;
  1360. if (nodeType == Node.ELEMENT_NODE) {
  1361. if (lnode.tagName == "table") {
  1362. lnode.inject(nextPageNode);
  1363. } else if (lnode.tagName == "BR") {
  1364. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1365. } else {
  1366. var id = lnode.get("data-pagePart");
  1367. if (!id){
  1368. id = (new o2.widget.UUID()).toString();
  1369. lnode.set("data-pagePart", id);
  1370. }
  1371. var tmpNode = nextPageNode.getFirst();
  1372. if (tmpNode && tmpNode.get("data-pagePart")==id){
  1373. nextPageNode = tmpNode;
  1374. }else{
  1375. nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
  1376. }
  1377. //var subnode = lnode.getLast();
  1378. this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
  1379. if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1380. nextPageNode = nextPageNode.getParent();
  1381. }
  1382. } else if (nodeType == Node.TEXT_NODE) {
  1383. var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
  1384. while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
  1385. //console.log(contentNode.getSize().y);
  1386. this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
  1387. }
  1388. if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
  1389. } else {
  1390. //lnode.remove();
  1391. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1392. }
  1393. lnode = tmpnode;
  1394. }
  1395. if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
  1396. }
  1397. //this._checkSplitPage(pageNode);
  1398. },
  1399. _splitPage: function(pageNode){
  1400. var contentNode = pageNode.getFirst();
  1401. var blockNodes = pageNode.getElements(".doc_block");
  1402. if (blockNodes.length){
  1403. var blockNode = blockNodes[blockNodes.length-1];
  1404. var idx = this.pages.indexOf(pageNode);
  1405. if (this.pages.length<=idx+1) this._createNewPage();
  1406. var nextPage = this.pages[idx+1];
  1407. if (blockNode.hasClass("doc_layout_filetext")){
  1408. var filetextNode = nextPage.getElement(".doc_layout_filetext");
  1409. if (!filetextNode){
  1410. filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
  1411. //filetextNode.setAttribute('contenteditable', true);
  1412. }
  1413. if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
  1414. //var nextEditor = filetextNode.retrieve("editor");
  1415. var node = blockNode;
  1416. var nextPageNode = filetextNode;
  1417. this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
  1418. }else{
  1419. blockNode.inject(nextPage.getFirst(), "top");
  1420. //var contentNode = pageNode.getFirst();
  1421. if (contentNode.getSize().y>this.options.docPageHeight){
  1422. this._splitPage(pageNode);
  1423. }
  1424. }
  1425. }
  1426. },
  1427. loadCkeditorFiletext: function(callback, inline){
  1428. if (this.layout_filetext){
  1429. o2.load("../o2_lib/htmleditor/ckeditor4130/ckeditor.js", function(){
  1430. CKEDITOR.disableAutoInline = true;
  1431. this.layout_filetext.setAttribute('contenteditable', true);
  1432. if (inline){
  1433. this.filetextEditor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1434. }else{
  1435. this.filetextEditor = CKEDITOR.replace(this.layout_filetext, this._getEditorConfig());
  1436. }
  1437. this.filetextEditor.on("instanceReady", function(e){
  1438. if (callback) callback(e);
  1439. }.bind(this));
  1440. this.filetextEditor.on( 'focus', function( e ) {
  1441. window.setTimeout(this.reLocationFiletextToolbar.bind(this), 10);
  1442. }.bind(this) );
  1443. // this.filetextEditor.on("key", function(e){
  1444. // debugger;
  1445. // }.bind(this));
  1446. }.bind(this));
  1447. }
  1448. },
  1449. _loadEvents: function(editorConfig){
  1450. Object.each(this.json.events, function(e, key){
  1451. if (e.code){
  1452. this.editor.on(key, function(event){
  1453. return this.form.Macro.fire(e.code, this, event);
  1454. }.bind(this), this);
  1455. }
  1456. }.bind(this));
  1457. },
  1458. _bindFieldChange: function(name,dataItem, dom){
  1459. var field = this.form.all[this.json[dataItem]];
  1460. if (field){
  1461. var bindFun = function(){
  1462. this._computeItemFieldData(name, dataItem);
  1463. //if (this.data[name]){
  1464. if (this[dom]){
  1465. if (dom=="layout_redHeader" || dom=="layout_subject"){
  1466. this[dom].set("html", this.data[name]|| "");
  1467. }else if (dom=="layout_attachment"){
  1468. this.setAttachmentData();
  1469. }else{
  1470. this[dom].set("text", this.data[name]|| "");
  1471. }
  1472. }
  1473. this.reSetShow();
  1474. //}
  1475. }.bind(this);
  1476. field.node.store(this.json.id+"bindFun", bindFun);
  1477. field.addModuleEvent("change", bindFun);
  1478. }
  1479. },
  1480. _computeItemFieldData: function(name, dataItem){
  1481. var v = "";
  1482. var module = this.form.all[this.json[dataItem]];
  1483. if (module && module.getData) v = module.getData();
  1484. if (!v) v = this.form.businessData.data[this.json[dataItem]];
  1485. if (v){
  1486. var t = o2.typeOf(v);
  1487. switch (t) {
  1488. case "string":
  1489. switch (name) {
  1490. case "issuanceDate":
  1491. case "editionDate":
  1492. var d = new Date(v);
  1493. if (d.isValid()){
  1494. var y = d.getFullYear();
  1495. var m = d.getMonth();
  1496. var day = d.getDate();
  1497. m = m +1;
  1498. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  1499. }else{
  1500. this.data[name] = v;
  1501. }
  1502. //this.data[name] = (new Date(v).isValid()) ? Date.parse(v).format("%Y年%m月%d%日") : v;
  1503. break;
  1504. case "mainSend":
  1505. this.data[name] = v + ":";
  1506. break;
  1507. default:
  1508. this.data[name] = v;
  1509. }
  1510. break;
  1511. case "array":
  1512. var strs = [];
  1513. v.each(function(value){
  1514. if (o2.typeOf(value)=="object" && value.distinguishedName){
  1515. strs.push(value.name);
  1516. }else{
  1517. strs.push(value.toString());
  1518. }
  1519. });
  1520. //if (strs.length){
  1521. switch (name) {
  1522. case "attachment":
  1523. // this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>");
  1524. var atts = strs.map(function(a){
  1525. return (a.indexOf(".")!=-1) ? a.substring(0, a.lastIndexOf(".")) : a;
  1526. });
  1527. this.data[name] = atts;
  1528. break;
  1529. case "issuanceDate":
  1530. case "editionDate":
  1531. var tmpStrs = strs.map(function(n, i){
  1532. var d = Date.parse(n);
  1533. return (d.isValid()) ? d.format("%Y年%m月%d日") : n;
  1534. });
  1535. this.data[name] = tmpStrs.join(",");
  1536. break;
  1537. case "mainSend":
  1538. this.data[name] = strs.join(",") + ":";
  1539. break;
  1540. default:
  1541. this.data[name] = strs.join(",");
  1542. }
  1543. //}
  1544. break;
  1545. default:
  1546. this.data[name] = v.toString();
  1547. }
  1548. }else{
  1549. this.data[name] = this.json.defaultValue[name];
  1550. }
  1551. },
  1552. computeData: function(){
  1553. this._computeData(false);
  1554. this.setData(this.data);
  1555. },
  1556. _computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
  1557. switch (this.json[typeItem]) {
  1558. case "data":
  1559. if (this.json[dataItem]){
  1560. if (ev) this._bindFieldChange(name, dataItem, dom);
  1561. this._computeItemFieldData(name, dataItem);
  1562. }
  1563. break;
  1564. case "script":
  1565. if (this.json[scriptItem] && this.json[scriptItem].code){
  1566. var v = this.form.Macro.exec(this.json[scriptItem].code, this);
  1567. this.data[name] = v;
  1568. if (name=="attachment"){
  1569. //this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>") : v;
  1570. this.data[name] = (typeOf(v)=="array") ? v : [v];
  1571. }
  1572. if (name=="issuanceDate" || name=="editionDate"){
  1573. var d = Date.parse(v);
  1574. this.data[name] = (d.isValid()) ? d.format("%Y年%m月%d日") : v;
  1575. }
  1576. }
  1577. break;
  1578. }
  1579. },
  1580. _computeData: function(ev){
  1581. this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
  1582. this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
  1583. this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
  1584. this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
  1585. this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
  1586. this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
  1587. this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
  1588. this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
  1589. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
  1590. this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
  1591. this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
  1592. this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
  1593. this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
  1594. this._computeItemData("copyto2", "copyto2ValueType", "copyto2ValueData", "copyto2ValueScript", ev, "layout_copyto2Content");
  1595. this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
  1596. this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
  1597. this._computeItemData("meetingAttend", "meetingAttendValueType", "meetingAttendValueData", "meetingAttendValueScript", ev, "layout_meetingAttendContent");
  1598. this._computeItemData("meetingLeave", "meetingLeaveValueType", "meetingLeaveValueData", "meetingLeaveValueScript", ev, "layout_meetingLeaveContent");
  1599. this._computeItemData("meetingSit", "meetingSitValueType", "meetingSitValueData", "meetingSitValueScript", ev, "layout_meetingSitContent");
  1600. },
  1601. _loadValue: function(){
  1602. var data = this._getBusinessData();
  1603. },
  1604. reload: function(){
  1605. this.resetData();
  1606. },
  1607. resetData: function(diffFiletext){
  1608. if (this.editMode){ this._switchReadOrEditInline(); }
  1609. this._computeData(false);
  1610. this.pages = [];
  1611. this.contentNode.empty();
  1612. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  1613. this.editMode = false;
  1614. this._createPage(function(control){
  1615. this._loadPageLayout(control);
  1616. this.setData(this.data, diffFiletext);
  1617. //this._checkSplitPage(this.pages[0]);
  1618. debugger;
  1619. this._repage();
  1620. }.bind(this));
  1621. },
  1622. isEmpty: function(){
  1623. var data = this.getData();
  1624. if( typeOf(data) !== "object" )return true;
  1625. return !!data.filetext;
  1626. },
  1627. getData: function(){
  1628. //if (this.editMode){
  1629. if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
  1630. if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
  1631. if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
  1632. if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
  1633. if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
  1634. if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
  1635. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  1636. if (this.layout_subject) this.data.subject = this.layout_subject.get("html");
  1637. if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
  1638. if (this.editMode) if (this.layout_filetext) this.data.filetext = this.layout_filetext.get("html");
  1639. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  1640. if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
  1641. if (this.layout_attachment){
  1642. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", false, "layout_attachment");
  1643. // var atts = [];
  1644. // var nodes = this.layout_attachment.getElements(".doc_layout_attachment_content_name");
  1645. // if (nodes.length){
  1646. // nodes.each(function(node){
  1647. // atts.push(node.get("text"));
  1648. // });
  1649. // }
  1650. // this.data.attachment = atts;
  1651. }
  1652. if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("text");
  1653. if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
  1654. if (this.layout_annotation) this.data.annotation = this.layout_annotation.get("text");
  1655. if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
  1656. if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
  1657. if (this.layout_copyto2Title) this.data.copyto2Title = this.layout_copyto2Title.get("text");
  1658. if (this.layout_copyto2Content) this.data.copyto2 = this.layout_copyto2Content.get("text");
  1659. if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
  1660. if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
  1661. if (this.layout_meetingAttendTitle) this.data.meetingAttendTitle = this.layout_meetingAttendTitle.get("text");
  1662. if (this.layout_meetingLeaveTitle) this.data.meetingLeaveTitle = this.layout_meetingLeaveTitle.get("text");
  1663. if (this.layout_meetingSitTitle) this.data.meetingSitTitle = this.layout_meetingSitTitle.get("text");
  1664. if (this.layout_meetingAttendContent) this.data.meetingAttend = this.layout_meetingAttendContent.get("html");
  1665. if (this.layout_meetingLeaveContent) this.data.meetingLeave = this.layout_meetingLeaveContent.get("html");
  1666. if (this.layout_meetingSitContent) this.data.meetingSit = this.layout_meetingSitContent.get("html");
  1667. //}
  1668. return this.data;
  1669. },
  1670. setAttachmentData: function(){
  1671. if (!this.attachmentTemplete){
  1672. this.attachmentTemplete = this.layout_attachment.get("html");
  1673. }
  1674. this.layout_attachment.empty();
  1675. if (this.data.attachment && this.data.attachment.length && this.data.attachment.each){
  1676. //var tmpdiv = new Element("div", {"styles": {"display":"none"}}).inject(document.body);
  1677. var tmpdiv = new Element("div");
  1678. this.data.attachment.each(function(name, idx){
  1679. tmpdiv.set("html", this.attachmentTemplete);
  1680. var serialNode = tmpdiv.getElement(".doc_layout_attachment_content_serial");
  1681. var nameNode = tmpdiv.getElement(".doc_layout_attachment_content_name");
  1682. if (serialNode) serialNode.set("text", idx+1);
  1683. if (nameNode) nameNode.set("text", name);
  1684. var html = tmpdiv.get("html");
  1685. tmpdiv.empty();
  1686. this.layout_attachment.appendHTML(html);
  1687. }.bind(this));
  1688. tmpdiv.destroy();
  1689. }
  1690. },
  1691. setData: function(data, diffFiletext){
  1692. if (data){
  1693. this.data = data;
  1694. // this.data["$json"] = this.json;
  1695. this._setBusinessData(data);
  1696. if (this.layout_copies){
  1697. if (data.copies){
  1698. this.layout_copies.set("text", data.copies || " ");
  1699. }else{
  1700. this.layout_copies.set("html", "<span>&nbsp</span>");
  1701. }
  1702. }
  1703. if (this.layout_secret){
  1704. if (data.secret){
  1705. this.layout_secret.set("text", data.secret || " ");
  1706. }else{
  1707. this.layout_secret.set("html", "<span>&nbsp</span>");
  1708. }
  1709. }
  1710. if (this.layout_priority){
  1711. if (data.priority){
  1712. this.layout_priority.set("text", data.priority || " ");
  1713. }else{
  1714. this.layout_priority.set("html", "<span>&nbsp</span>");
  1715. }
  1716. }
  1717. if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
  1718. if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
  1719. if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
  1720. if (this.layout_signer) this.layout_signer.set("text", data.signer || " ");
  1721. if (this.layout_subject) this.layout_subject.set("html", data.subject || " ");
  1722. if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
  1723. if (diffFiletext) {
  1724. this.layout_filetext.set("html", diffFiletext);
  1725. }else if (this.layout_filetext){
  1726. //this.layout_filetext.set("placeholder", this.json.defaultValue.filetext);
  1727. this.layout_filetext.set("html", data.filetext || "");
  1728. }
  1729. if (this.layout_signer) this.layout_signer.set("text", data.signer || "");
  1730. if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
  1731. if (this.layout_attachment){
  1732. this.setAttachmentData();
  1733. }
  1734. if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("text", data.issuanceUnit || " ");
  1735. if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
  1736. if (this.layout_annotation) this.layout_annotation.set("text", data.annotation || " ");
  1737. if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
  1738. if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
  1739. if (this.layout_copyto2Title) this.layout_copyto2Title.set("text", data.copyto2Title || " ");
  1740. if (this.layout_copyto2Content) this.layout_copyto2Content.set("text", data.copyto2 || " ");
  1741. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
  1742. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
  1743. if (this.layout_meetingAttendTitle) this.layout_meetingAttendTitle.set("text", data.meetingAttendTitle || this.json.defaultValue.meetingAttendTitle || " ");
  1744. if (this.layout_meetingLeaveTitle) this.layout_meetingLeaveTitle.set("text", data.meetingLeaveTitle || this.json.defaultValue.meetingLeaveTitle || " ");
  1745. if (this.layout_meetingSitTitle) this.layout_meetingSitTitle.set("text", data.meetingSitTitle || this.json.defaultValue.meetingSitTitle || " ");
  1746. if (this.layout_meetingAttendContent) this.layout_meetingAttendContent.set("html", data.meetingAttend || " ");
  1747. if (this.layout_meetingLeaveContent) this.layout_meetingLeaveContent.set("html", data.meetingLeave || " ");
  1748. if (this.layout_meetingSitContent) this.layout_meetingSitContent.set("html", data.meetingSit || " ");
  1749. }
  1750. },
  1751. createErrorNode: function(text){
  1752. var node = new Element("div");
  1753. var iconNode = new Element("div", {
  1754. "styles": {
  1755. "width": "20px",
  1756. "height": "20px",
  1757. "float": "left",
  1758. "background": "url("+"../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  1759. }
  1760. }).inject(node);
  1761. var textNode = new Element("div", {
  1762. "styles": {
  1763. "line-height": "20px",
  1764. "margin-left": "20px",
  1765. "color": "red",
  1766. "word-break": "keep-all"
  1767. },
  1768. "text": text
  1769. }).inject(node);
  1770. return node;
  1771. },
  1772. notValidationMode: function(text){
  1773. if (!this.isNotValidationMode){
  1774. this.isNotValidationMode = true;
  1775. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  1776. this.node.setStyle("border", "1px solid red");
  1777. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  1778. this.showNotValidationMode(this.node);
  1779. }
  1780. },
  1781. showNotValidationMode: function(node){
  1782. var p = node.getParent("div");
  1783. if (p){
  1784. if (p.get("MWFtype") == "tab$Content"){
  1785. if (p.getParent("div").getStyle("display")=="none"){
  1786. var contentAreaNode = p.getParent("div").getParent("div");
  1787. var tabAreaNode = contentAreaNode.getPrevious("div");
  1788. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  1789. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  1790. tabNode.click();
  1791. p = tabAreaNode.getParent("div");
  1792. }
  1793. }
  1794. this.showNotValidationMode(p);
  1795. }
  1796. },
  1797. validationMode: function(){
  1798. if (this.isNotValidationMode){
  1799. this.isNotValidationMode = false;
  1800. this.node.setStyles(this.node.retrieve("borderStyle"));
  1801. if (this.errNode){
  1802. this.errNode.destroy();
  1803. this.errNode = null;
  1804. }
  1805. }
  1806. },
  1807. validationConfigItem: function(routeName, data){
  1808. var flag = (data.status=="all") ? true: (routeName == data.decision);
  1809. if (flag){
  1810. var n = this.getData();
  1811. var v = (data.valueType=="value") ? n : n.length;
  1812. switch (data.operateor){
  1813. case "isnull":
  1814. if (!v){
  1815. this.notValidationMode(data.prompt);
  1816. return false;
  1817. }
  1818. break;
  1819. case "notnull":
  1820. if (v){
  1821. this.notValidationMode(data.prompt);
  1822. return false;
  1823. }
  1824. break;
  1825. case "gt":
  1826. if (v>data.value){
  1827. this.notValidationMode(data.prompt);
  1828. return false;
  1829. }
  1830. break;
  1831. case "lt":
  1832. if (v<data.value){
  1833. this.notValidationMode(data.prompt);
  1834. return false;
  1835. }
  1836. break;
  1837. case "equal":
  1838. if (v==data.value){
  1839. this.notValidationMode(data.prompt);
  1840. return false;
  1841. }
  1842. break;
  1843. case "neq":
  1844. if (v!=data.value){
  1845. this.notValidationMode(data.prompt);
  1846. return false;
  1847. }
  1848. break;
  1849. case "contain":
  1850. if (v.indexOf(data.value)!=-1){
  1851. this.notValidationMode(data.prompt);
  1852. return false;
  1853. }
  1854. break;
  1855. case "notcontain":
  1856. if (v.indexOf(data.value)==-1){
  1857. this.notValidationMode(data.prompt);
  1858. return false;
  1859. }
  1860. break;
  1861. }
  1862. }
  1863. return true;
  1864. },
  1865. validationConfig: function(routeName, opinion){
  1866. if (this.json.validationConfig){
  1867. if (this.json.validationConfig.length){
  1868. for (var i=0; i<this.json.validationConfig.length; i++) {
  1869. var data = this.json.validationConfig[i];
  1870. if (!this.validationConfigItem(routeName, data)) return false;
  1871. }
  1872. }
  1873. return true;
  1874. }
  1875. return true;
  1876. },
  1877. validation: function(routeName, opinion){
  1878. if (!this.validationConfig(routeName, opinion)) return false;
  1879. if (!this.json.validation) return true;
  1880. if (!this.json.validation.code) return true;
  1881. var flag = this.form.Macro.exec(this.json.validation.code, this);
  1882. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  1883. if (flag.toString()!="true"){
  1884. this.notValidationMode(flag);
  1885. return false;
  1886. }
  1887. return true;
  1888. },
  1889. removeDisplayNone: function(node){
  1890. var n = node.getFirst();
  1891. while (n){
  1892. if (n.getStyle("display")=="none"){
  1893. var tmp = n.getNext();
  1894. n.destroy();
  1895. n = tmp;
  1896. }else{
  1897. n = this.removeDisplayNone(n);
  1898. n = n.getNext();
  1899. }
  1900. }
  1901. return node;
  1902. },
  1903. toWord: function(callback, name){
  1904. var toEdit = false;
  1905. if (this.editMode){
  1906. toEdit = true;
  1907. this._readFiletext();
  1908. }
  1909. //this._returnScale();
  1910. this.zoom(1);
  1911. this.pages = [];
  1912. this.contentNode.empty();
  1913. this._createPage(function(control){
  1914. this._loadPageLayout(control);
  1915. this.setData(this.data);
  1916. this._checkScale();
  1917. this.node.setStyles({
  1918. "height":"auto"
  1919. });
  1920. //var content = this.contentNode.getFirst().getFirst().get("html");
  1921. var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
  1922. var htmlNode = tmpNode.getLast();
  1923. htmlNode = this.removeDisplayNone(htmlNode);
  1924. var content = "<html><head><meta charset=\"UTF-8\" /></head><body>"+tmpNode.get("html")+"</body></html>";
  1925. var body = {
  1926. "fileName": name || this.json.toWordFilename || "$doc.doc",
  1927. "site": this.json.toWordSite || "$doc",
  1928. "content": content
  1929. };
  1930. o2.Actions.get("x_processplatform_assemble_surface").docToWord(this.form.businessData.work.id, body, function(json){
  1931. if (this.form.businessData.workCompleted){
  1932. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id,function(attjson){
  1933. if (callback) callback(attjson.data);
  1934. this.showToWord(attjson.data);
  1935. }.bind(this));
  1936. }else{
  1937. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id,function(attjson){
  1938. if (callback) callback(attjson.data);
  1939. this.showToWord(attjson.data);
  1940. }.bind(this));
  1941. }
  1942. }.bind(this));
  1943. tmpNode.destroy();
  1944. if (!toEdit){
  1945. this._readFiletext();
  1946. }else{
  1947. this._createEditor();
  1948. }
  1949. }.bind(this));
  1950. },
  1951. docToWord: function(){
  1952. var flag = true;
  1953. if (this.json.toWordConditionScript && this.json.toWordConditionScript.code){
  1954. flag = !!this.form.Macro.exec(this.json.toWordConditionScript.code, this);
  1955. }
  1956. if (flag){
  1957. this.toWord();
  1958. }
  1959. },
  1960. showToWord: function(att){
  1961. var site = this.json.toWordSite || "$doc";
  1962. var attModule = this.form.all[site];
  1963. if (attModule){
  1964. attModule.attachmentController.clear();
  1965. attModule.attachmentController.addAttachment(att);
  1966. }
  1967. }
  1968. });