Documenteditor.js 99 KB

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