Documenteditor.js 110 KB

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