Documenteditor.js 98 KB

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