DocumentHistory.js 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. MWF.xApplication.process.Xform.widget = MWF.xApplication.process.Xform.widget || {};
  2. MWF.xApplication.process.Xform.widget.DocumentHistory = new Class({
  3. Implements: [Options, Events],
  4. options: {
  5. "speed": 1,
  6. "fxTime": 500,
  7. "inforTime": 2000
  8. },
  9. initialize: function(documentEditor, options){
  10. this.setOptions(options);
  11. this.documentEditor = documentEditor;
  12. this.css = this.documentEditor.css;
  13. },
  14. is_iPad: function(){
  15. var ua = navigator.userAgent.toLowerCase();
  16. return (ua.match(/iPad/i)=="ipad");
  17. },
  18. load: function(callback, nodiff){
  19. this.getHistroyDocumentList(function(){
  20. if (this.historyDocumentList && this.historyDocumentList.length){
  21. this.getHistoryDataList(function(){
  22. this.createHistoryToolbar();
  23. if (!layout.mobile || this.is_iPad()) this.createHistoryListNode();
  24. this.documentEditor.options.pageShow = "single";
  25. this.beginDiffHistory();
  26. this.loadHistoryToolbar();
  27. if (!layout.mobile) this.loadHistoryList();
  28. this.documentEditor.resetData(false, function(){
  29. this.documentEditor._readFiletext();
  30. if (callback) callback();
  31. }.bind(this));
  32. }.bind(this));
  33. }else{
  34. this.documentEditor.form.app.notice(MWF.xApplication.process.Xform.LP.documentHistory.nodiff, "info", this.documentEditor.node);
  35. if (nodiff) nodiff();
  36. }
  37. }.bind(this));
  38. },
  39. createHistoryToolbar: function(){
  40. this.documentEditor.documentToolbarNode = this.documentEditor.toolbarNode;
  41. this.toolbarNode = this.documentEditor.toolbarNode.clone(true);
  42. this.toolbarNode.inject(this.documentEditor.toolbarNode, "after");
  43. this.documentEditor.toolbarNode = this.toolbarNode;
  44. this.documentEditor.documentToolbarNode.hide();
  45. this.toolbarNode.empty();
  46. if (this.documentEditor.sidebarNode) this.documentEditor.sidebarNode.hide();
  47. },
  48. loadHistoryToolbar: function(){
  49. var html = "";
  50. if (this.historyDataList && this.historyDataList.length && this.historyDataList[0].json.v!="6"){
  51. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/documenteditoricon/play.png\" title=\""+MWF.xApplication.process.Xform.LP.documentHistory.play+"\" MWFButtonAction=\"play\"></span>";
  52. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/documenteditoricon/pause.png\" title=\""+MWF.xApplication.process.Xform.LP.documentHistory.pause+"\" MWFButtonAction=\"pause\"></span>";
  53. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/documenteditoricon/stop.png\" title=\""+MWF.xApplication.process.Xform.LP.documentHistory.stop+"\" MWFButtonAction=\"stopPlay\"></span>";
  54. html += "<span MWFnodetype=\"MWFToolBarSeparator\"></span>";
  55. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/documenteditoricon/prev.png\" title=\""+MWF.xApplication.process.Xform.LP.documentHistory.prev+"\" MWFButtonAction=\"prev\"></span>";
  56. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/documenteditoricon/next.png\" title=\""+MWF.xApplication.process.Xform.LP.documentHistory.next+"\" MWFButtonAction=\"next\"></span>";
  57. html += "<span MWFnodetype=\"MWFToolBarSeparator\"></span>";
  58. }
  59. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/documenteditoricon/exit.png\" title=\""+MWF.xApplication.process.Xform.LP.documentHistory.exit+"\" MWFButtonAction=\"exit\" MWFButtonText=\""+MWF.xApplication.process.Xform.LP.documentHistory.exit+"\"></span>";
  60. html += "<span MWFnodetype=\"MWFToolBarSeparator\"></span>";
  61. var text = MWF.xApplication.process.Xform.LP.documentHistory.diff_patch_count;
  62. text = text.replace(/{history}/, this.historyDataList.length).replace(/{diff}/, this.diffCount);
  63. html += "<span style='float: left; line-height: 24px; color: #666666; margin-left: 10px'>"+text+"</span>";
  64. this.toolbarNode.set("html", html);
  65. MWF.require("MWF.widget.Toolbar", function() {
  66. this.toolbar = new MWF.widget.Toolbar(this.toolbarNode, {"style": "documentEdit"}, this);
  67. this.toolbar.load();
  68. this.checkToolbar();
  69. }.bind(this));
  70. this.toolbarNode.setStyle("overflow", "visible");
  71. if (this.historyListAreaNode) this.historyListAreaNode.inject(this.toolbarNode);
  72. },
  73. checkToolbar: function(){
  74. if (this.historyDataList && this.historyDataList.length && this.historyDataList[0].json.v!="6"){
  75. if (this.toolbar){
  76. if (this.playing){
  77. if (this.stop){
  78. this.toolbar.childrenButton[0].enable();
  79. this.toolbar.childrenButton[1].disable();
  80. if (this.patchIndex==0 && this.diffIndex==0){
  81. this.toolbar.childrenButton[3].disable();
  82. if (this.diffPatch.length) this.toolbar.childrenButton[4].enable();
  83. }else{
  84. if (this.patchIndex<this.diffPatch.length-1){
  85. this.toolbar.childrenButton[3].enable();
  86. this.toolbar.childrenButton[4].enable();
  87. }else if (this.patchIndex<this.diffPatch.length && this.diffIndex < this.diffPatch[this.patchIndex].patch.diffs.length){
  88. this.toolbar.childrenButton[3].enable();
  89. this.toolbar.childrenButton[4].enable();
  90. }else{
  91. if (this.diffPatch.length) this.toolbar.childrenButton[3].enable();
  92. this.toolbar.childrenButton[4].disable();
  93. }
  94. }
  95. }else{
  96. this.toolbar.childrenButton[0].disable();
  97. this.toolbar.childrenButton[1].enable();
  98. this.toolbar.childrenButton[3].disable();
  99. this.toolbar.childrenButton[4].disable();
  100. }
  101. this.toolbar.childrenButton[2].enable();
  102. }else{
  103. this.toolbar.childrenButton[0].enable();
  104. this.toolbar.childrenButton[1].disable();
  105. this.toolbar.childrenButton[2].disable();
  106. if (this.patchIndex==0 && this.diffIndex==0){
  107. this.toolbar.childrenButton[3].disable();
  108. if (this.diffPatch.length) this.toolbar.childrenButton[4].enable();
  109. }else{
  110. if (this.patchIndex<this.diffPatch.length-1){
  111. this.toolbar.childrenButton[3].enable();
  112. this.toolbar.childrenButton[4].enable();
  113. }else if (this.patchIndex<this.diffPatch.length && this.diffIndex < this.diffPatch[this.patchIndex].patch.diffs.length){
  114. this.toolbar.childrenButton[3].enable();
  115. this.toolbar.childrenButton[4].enable();
  116. }else{
  117. if (this.diffPatch.length) this.toolbar.childrenButton[3].enable();
  118. this.toolbar.childrenButton[4].disable();
  119. }
  120. }
  121. }
  122. }
  123. }else{
  124. // 不做动画效果,不需要处理工具条
  125. }
  126. },
  127. createHistoryListNode: function(){
  128. this.historyListAreaNode = new Element("div", {"styles": this.css.historyListAreaNode}).inject(this.documentEditor.contentNode, "before");
  129. this.documentEditor.contentNode.setStyle("width", "auto");
  130. //this.documentEditor.zoom(1);
  131. this.documentEditor._checkScale();
  132. // var size = this.documentEditor.node.getSize();
  133. // var toolbarSize = this.documentEditor.toolbarNode.getSize();
  134. // var h = size.y-toolbarSize.y;
  135. // this.historyListAreaNode.setStyle("height", ""+h+"px");
  136. var size = this.documentEditor.form.app.content.getSize();
  137. var toolbarSize = this.documentEditor.toolbarNode.getSize();
  138. var h = size.y-toolbarSize.y;
  139. this.historyListAreaNode.setStyle("height", ""+h+"px");
  140. this.historyListTitleAreaNode = new Element("div", {"styles": this.css.historyListTitleAreaNode}).inject(this.historyListAreaNode);
  141. this.historyListContentAreaNode = new Element("div", {"styles": this.css.historyListContentAreaNode}).inject(this.historyListAreaNode);
  142. var y = this.historyListContentAreaNode.getEdgeHeight();
  143. var title_y = this.historyListTitleAreaNode.getComputedSize().totalHeight;
  144. h = h-y-title_y;
  145. this.historyListContentAreaNode.setStyle("height", ""+h+"px");
  146. this.historyListTitleNode = new Element("div", {"styles": this.css.historyListTitleNode}).inject(this.historyListTitleAreaNode);
  147. this.historyListTitleInsertNode = new Element("div", {"styles": this.css.historyListTitleInsertNode}).inject(this.historyListTitleAreaNode);
  148. this.historyListTitleDeleteNode = new Element("div", {"styles": this.css.historyListTitleDeleteNode}).inject(this.historyListTitleAreaNode);
  149. },
  150. loadHistoryList: function(){
  151. var text = MWF.xApplication.process.Xform.LP.documentHistory.diff_patch_count;
  152. text = text.replace(/{history}/, this.historyDataList.length).replace(/{diff}/, this.diffCount);
  153. var insertStr = MWF.xApplication.process.Xform.LP.documentHistory.insertTimes;
  154. var deleteStr = MWF.xApplication.process.Xform.LP.documentHistory.deleteTimes;
  155. insertStr = insertStr.replace(/{times}/, this.diffInsertCount);
  156. deleteStr = deleteStr.replace(/{times}/, this.diffDeleteCount);
  157. this.historyListTitleNode.set("text", text);
  158. this.historyListTitleInsertNode.set("text", insertStr);
  159. this.historyListTitleDeleteNode.set("text", deleteStr);
  160. //var original = this.historyDataList[0];
  161. //this.createHistoryListItem(original);
  162. this.historyDataList.each(function(historyData){
  163. this.createHistoryListItem(historyData);
  164. }.bind(this));
  165. new Element("button.mainColor_bg", {
  166. "styles": {
  167. "padding": "5px 20px",
  168. "border": "1px solid #cccccc",
  169. "border-radius": "100px",
  170. "margin": "20px auto",
  171. "display": "block"
  172. },
  173. "text": MWF.xApplication.process.Xform.LP.documentHistory.showAll,
  174. "events": {
  175. "click": function(){
  176. this.showAllHistory();
  177. }.bind(this)
  178. }
  179. }).inject(this.historyListContentAreaNode);
  180. // this.diffPatch.each(function(patchObj){
  181. // this.createHistoryListItem(patchObj);
  182. // }.bind(this));
  183. },
  184. showAllHistory(){
  185. if (this.documentHistoryItems && this.documentHistoryItems.length){
  186. this.documentHistoryItems.each(function(item){
  187. if (item.histroyObj) item.histroyObj.hideCurrent();
  188. });
  189. }
  190. var data = this.historyDataList[0];
  191. this.documentEditor.resetData(false, function(){
  192. o2.load("../o2_lib/diff-match-patch/diff_match_patch_uncompressed.js", function(){
  193. var dmp = new diff_match_patch();
  194. var text2 = this.documentEditor.getFiletextText(data.json.data);
  195. var text1 = this.documentEditor.getFiletextText(this.documentEditor.data.filetext);
  196. var d = dmp.diff_main(text2, text1);
  197. dmp.diff_cleanupSemantic(d);
  198. var ds = dmp.diff_prettyHtml(d);
  199. //ds = ds.replace(/[\n\r]+/g, "<br>");
  200. ds = ds.replace(/(?<!\>)(?:&para;)/g, '');
  201. ds = ds.replace(/(\n\t\t\t)+/g, " | ")
  202. .replace(/(\n\t\t)+/g,"\n")
  203. .replace(/(\n\t)+/g,"\n")
  204. .replace(/\n+/g,"<br>")
  205. .replace(/\t+/g,"");
  206. //ds = ds.replace(/(\n\t)+/g,"<table width=100% border=1 style='border-collapse: collapse'>");
  207. //ds = ds.replace(/\n+/g, "<br>");
  208. this.documentEditor.layout_filetext.set("html", ds);
  209. var node = this.documentEditor.layout_filetext.querySelector('ins,del');
  210. if (node){
  211. node.scrollIntoView({behavior: "smooth", block: "center", inline: "nearest"});
  212. }
  213. var node = this.documentEditor.layout_filetext.querySelector('ins,del');
  214. if (node){
  215. node.scrollIntoView({behavior: "smooth", block: "center", inline: "nearest"});
  216. }
  217. }.bind(this));
  218. }.bind(this));
  219. },
  220. createHistoryListItem: function(historyData){
  221. if (!this.documentHistoryItems) this.documentHistoryItems = [];
  222. this.documentHistoryItems.push(new MWF.xApplication.process.Xform.widget.DocumentHistory.Item(this, historyData));
  223. },
  224. getHistoryDataList: function(callback){
  225. // if (this.historyDataList && this.historyDataList.length){
  226. // this.getHistoryDataListFinish(this.historyDataList);
  227. // if (callback) callback();
  228. // }else{
  229. var historyDataList = [];
  230. var getDataCount = 0;
  231. var idx = 0;
  232. var checkBeginDiffHistory = function(){
  233. if (getDataCount>=this.historyDocumentList.length){
  234. this.getHistoryDataListFinish(historyDataList, callback);
  235. }
  236. }.bind(this);
  237. for (var i=this.historyDocumentList.length-1; i>=0; i--){
  238. historyDataList.push(null);
  239. this.getHistroyDocumentData(this.historyDocumentList[i].id, function(){
  240. getDataCount++;
  241. checkBeginDiffHistory();
  242. }.bind(this), idx, historyDataList);
  243. idx++;
  244. }
  245. //}
  246. },
  247. getHistoryDataListFinish: function(historyDataList, callback){
  248. this.historyDataList = historyDataList;
  249. this.originaHistoryData = historyDataList[0].json.data || null;
  250. if (this.documentEditor.allowEdit){
  251. o2.load("../o2_lib/diff-match-patch/diff_match_patch_uncompressed.js", function(){
  252. var originaData = this.documentEditor.form.businessData.originalData[this.documentEditor.json.id];
  253. //var data = this.documentEditor.getFiletextText(this.documentEditor.data.filetext);
  254. var data = this.documentEditor.data.filetext.replace(/<br><\/div>/g, '</div>');
  255. var earlyData = originaData.filetext.replace(/<br><\/div>/g, '</div>');
  256. // var data = this.documentEditor.data.filetext;
  257. // var earlyData = originaData.filetext;
  258. if (data!=earlyData){
  259. dataTxt = this.documentEditor.getFiletextText(data);
  260. earlyDataTxt = this.documentEditor.getFiletextText(earlyData);
  261. var dmp = new diff_match_patch();
  262. var diff_d = dmp.diff_main(earlyDataTxt, dataTxt);
  263. dmp.diff_cleanupSemantic(diff_d);
  264. var patch_list = dmp.patch_make(earlyDataTxt, dataTxt, diff_d);
  265. if (patch_list.length){
  266. var patch = dmp.patch_toText(patch_list);
  267. var patchData = JSON.stringify({"patchs": patch, "v": "6"});
  268. var currentData = {
  269. "data": patchData,
  270. "json": {"patchs": patch, "data": data, "current": true, "v": "6"},
  271. "person": layout.session.user.distinguishedName,
  272. "activityName": this.documentEditor.form.businessData.activity.name,
  273. "createTime" : (new Date()).format("db")
  274. };
  275. this.historyDataList.push(currentData);
  276. }
  277. }
  278. if (callback) callback();
  279. }.bind(this));
  280. }else{
  281. if (callback) callback();
  282. }
  283. },
  284. getHistroyDocumentData: function(id, callback, i, historyDataList){
  285. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.get(id, function(json){
  286. var obj = JSON.parse(json.data.data);
  287. json.data.json = obj;
  288. if (historyDataList) historyDataList[i] = json.data;
  289. if (callback) callback(json.data);
  290. }.bind(this));
  291. },
  292. getHistroyDocumentList: function(callback){
  293. //if (!this.historyDocumentList){
  294. var id = this.documentEditor.form.businessData.work.job;
  295. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.listWithJobCategory(id, this.documentEditor.json.id, function(json){
  296. this.historyDocumentList = json.data;
  297. if (callback) callback();
  298. }.bind(this));
  299. //}else{
  300. // if (callback) callback();
  301. //}
  302. },
  303. beginDiffHistory: function(){
  304. //o2.load("../o2_lib/diff-match-patch/diff_match_patch_uncompressed.js", function(){
  305. this.initAnimation();
  306. //if (callback) callback();
  307. //}.bind(this));
  308. },
  309. initAnimation: function(){
  310. this.diffPatch = this.diffHistroy();
  311. this.diffCount = 0;
  312. this.diffInsertCount = 0;
  313. this.diffDeleteCount = 0;
  314. this.diffPatch.each(function(patch){
  315. patch.patch.diffs.each(function(diff){
  316. if (diff[0]!=0) this.diffCount++;
  317. if (diff[0]==-1) this.diffDeleteCount++;
  318. if (diff[0]==1) this.diffInsertCount++;
  319. }.bind(this));
  320. }.bind(this));
  321. // this.initData();
  322. this.initAnimationStatus();
  323. },
  324. initData: function(data, diffObj){
  325. this.currentHistoryData = data || this.originaHistoryData;
  326. this.documentEditor.layout_filetext.set("html", this.currentHistoryData);
  327. this.patchIndex = 0;
  328. this.diffIndex = 0;
  329. if (this.documentHistoryItems && this.documentHistoryItems.length){
  330. this.documentHistoryItems.each(function(item){
  331. if (item.histroyObj) item.histroyObj.hideCurrent();
  332. });
  333. }
  334. if (diffObj || this.originaDiff) (diffObj || this.originaDiff).showCurrent();
  335. },
  336. initAnimationStatus: function(){
  337. this.patchIndex = 0;
  338. this.diffIndex = 0;
  339. this.currentDiffs = null;
  340. this.stop = true;
  341. this.step = false;
  342. this.playing = false;
  343. this.reverse = false;
  344. this.options.fxTime = 500;
  345. this.options.inforTime = 2000;
  346. this.checkToolbar();
  347. },
  348. doAnimationAuto: function(){
  349. this.playing = true;
  350. this.checkToolbar();
  351. this.doPatchAnimation(function(){
  352. this.patchIndex = 0;
  353. this.diffIndex = 0;
  354. this.playing = false;
  355. this.stop = true;
  356. this.documentEditor.resetData();
  357. this.checkToolbar();
  358. }.bind(this));
  359. },
  360. do: function(){
  361. if (this.nextPlayPrefixFunction){
  362. this.nextPlayPrefixFunction();
  363. this.nextPlayPrefixFunction = null;
  364. }else{
  365. this.doAnimationAuto();
  366. }
  367. },
  368. play: function(){
  369. if (!this.playing){
  370. this.initData();
  371. this.initAnimationStatus();
  372. }
  373. this.reverse = false;
  374. this.stop = false;
  375. this.stopWhile = "";
  376. this.options.fxTime = 500;
  377. this.options.inforTime = 2000;
  378. this.toolbar.childrenButton[0].disable();
  379. this.toolbar.childrenButton[3].disable();
  380. this.toolbar.childrenButton[4].disable();
  381. this.do();
  382. },
  383. stopPlay: function(){
  384. if (this.playing){
  385. this.stop = true;
  386. this.playing = false;
  387. if (this.nextPlayPrefixFunction){
  388. this.nextPlayPrefixFunction();
  389. this.nextPlayPrefixFunction = null;
  390. }
  391. this.patchIndex = 0;
  392. this.diffIndex = 0;
  393. this.toolbar.childrenButton[1].disable();
  394. this.toolbar.childrenButton[2].disable();
  395. }
  396. },
  397. pause: function(){
  398. if (this.playing){
  399. this.stop = true;
  400. this.toolbar.childrenButton[1].disable();
  401. this.toolbar.childrenButton[2].disable();
  402. }
  403. },
  404. next: function(){
  405. this.reverse = false;
  406. this.options.fxTime = 0;
  407. this.options.inforTime = 0;
  408. this.stop = true;
  409. this.toolbar.childrenButton[3].disable();
  410. this.toolbar.childrenButton[4].disable();
  411. if (!this.playing) this.initData();
  412. this.do();
  413. },
  414. prev: function(){
  415. this.reverse = true;
  416. this.options.fxTime = 0;
  417. this.options.inforTime = 0;
  418. this.stop = true;
  419. this.toolbar.childrenButton[3].disable();
  420. this.toolbar.childrenButton[4].disable();
  421. if (!this.playing) this.initData();
  422. this.do();
  423. },
  424. to: function(diff){
  425. if (this.nextPlayPrefixFunction){
  426. this.playing = false;
  427. this.nextPlayPrefixFunction(function(){
  428. this.initData();
  429. this.initAnimationStatus();
  430. this.reverse = false;
  431. this.options.fxTime = 0;
  432. this.options.inforTime = 0;
  433. this.stop = false;
  434. this.stopWhile = diff.id;
  435. // this.toolbar.childrenButton[3].disable();
  436. // this.toolbar.childrenButton[4].disable();
  437. this.doAnimationAuto(diff.id);
  438. }.bind(this));
  439. //this.nextPlayPrefixFunction = null;
  440. }else{
  441. this.initData();
  442. this.initAnimationStatus();
  443. this.reverse = false;
  444. this.options.fxTime = 0;
  445. this.options.inforTime = 0;
  446. this.stop = false;
  447. this.stopWhile = diff.id;
  448. // this.toolbar.childrenButton[3].disable();
  449. // this.toolbar.childrenButton[4].disable();
  450. this.doAnimationAuto(diff.id);
  451. }
  452. },
  453. origina: function(data, diffObj){
  454. if (this.nextPlayPrefixFunction){
  455. this.playing = false;
  456. this.nextPlayPrefixFunction(function(){
  457. this.initData(data, diffObj);
  458. this.initAnimationStatus();
  459. }.bind(this));
  460. this.nextPlayPrefixFunction = null;
  461. }else{
  462. this.initData(data, diffObj);
  463. this.initAnimationStatus();
  464. }
  465. },
  466. exit: function(){
  467. this.initAnimationStatus();
  468. this.options.fxTime = 0;
  469. this.options.inforTime = 0;
  470. if (this.nextPlayPrefixFunction){
  471. this.nextPlayPrefixFunction(function(){
  472. this.documentEditor.toolbarNode = this.documentEditor.documentToolbarNode;
  473. this.documentEditor.toolbarNode.show();
  474. if (this.documentEditor.sidebarNode) this.documentEditor.sidebarNode.show();
  475. this.documentEditor.resizeToolbar();
  476. }.bind(this));
  477. this.nextPlayPrefixFunction = null;
  478. }else{
  479. this.documentEditor.toolbarNode = this.documentEditor.documentToolbarNode;
  480. this.documentEditor.toolbarNode.show();
  481. if (this.documentEditor.sidebarNode) this.documentEditor.sidebarNode.show();
  482. this.documentEditor.resizeToolbar();
  483. }
  484. if (this.historyListAreaNode) this.historyListAreaNode.destroy();
  485. this.documentHistoryItems = [];
  486. this.historyListAreaNode = null;
  487. this.documentEditor.zoom(1);
  488. this.documentEditor._checkScale();
  489. this.documentEditor.historyMode = false;
  490. this.documentEditor.resetData();
  491. this.toolbarNode.hide();
  492. this.documentEditor._returnScreen();
  493. },
  494. active: function(callback, nodiff){
  495. this.getHistroyDocumentList(function(){
  496. if (this.historyDocumentList && this.historyDocumentList.length){
  497. this.getHistoryDataList(function(){
  498. this.documentEditor.options.pageShow = "single";
  499. this.documentEditor.resetData();
  500. this.beginDiffHistory();
  501. this.documentEditor.resetData();
  502. this.toolbarNode.show();
  503. this.documentEditor.documentToolbarNode = this.documentEditor.toolbarNode;
  504. this.documentEditor.documentToolbarNode.hide();
  505. if (this.documentEditor.sidebarNode) this.documentEditor.sidebarNode.hide();
  506. this.documentEditor.toolbarNode = this.toolbarNode;
  507. this.documentEditor.resizeToolbar();
  508. var text = MWF.xApplication.process.Xform.LP.documentHistory.diff_patch_count;
  509. text = text.replace(/{history}/, this.historyDataList.length).replace(/{diff}/, this.diffCount);
  510. this.toolbarNode.getLast().set("html", text);
  511. if (!layout.mobile || this.is_iPad()) {
  512. this.createHistoryListNode();
  513. if (this.toolbarNode){
  514. this.toolbarNode.setStyle("overflow", "visible");
  515. if (this.historyListAreaNode) this.historyListAreaNode.inject(this.toolbarNode);
  516. }
  517. this.loadHistoryList();
  518. }
  519. this.documentEditor.options.pageShow = "single";
  520. this.documentEditor.resetData(false, function (){
  521. this.documentEditor._readFiletext();
  522. }.bind(this));
  523. if (callback) callback();
  524. }.bind(this));
  525. }else{
  526. this.documentEditor.form.app.notice(MWF.xApplication.process.Xform.LP.documentHistory.nodiff, "info", this.documentEditor.node);
  527. if (nodiff) nodiff();
  528. }
  529. }.bind(this));
  530. },
  531. diffHistroy: function(){
  532. var diffPatch = [];
  533. //var historyPatchs = [];
  534. for (var i=1; i<this.historyDataList.length; i++){
  535. // var earlyDataText = this.historyDataList[i-1].data;
  536. // var laterData = this.historyDataList[i];
  537. //
  538. // var dmp = new diff_match_patch();
  539. // // dmp.Diff_Timeout = parseFloat(10);
  540. // // dmp.Diff_EditCost = parseFloat(4);
  541. // var diff_d = dmp.diff_main(earlyDataText, laterData.data);
  542. // dmp.diff_cleanupSemantic(diff_d);
  543. // var patch_list = dmp.patch_make(earlyDataText, laterData.data, diff_d);
  544. //historyPatchs.push({"patch_list": patch_list, "obj": laterData});
  545. var history = this.historyDataList[i];
  546. var data = history.json;
  547. history.json = data;
  548. if (data.patchs){
  549. var dmp = new diff_match_patch();
  550. var patch_list = dmp.patch_fromText(data.patchs);
  551. history.json.patchObj = patch_list;
  552. patch_list.each(function(patch){
  553. diffPatch.push({"patch":patch, "obj": history});
  554. }.bind(this));
  555. }
  556. }
  557. return diffPatch;
  558. },
  559. doPatchAnimation: function(callback){
  560. var patchObj = this.diffPatch[this.patchIndex];
  561. var patch = patchObj.patch;
  562. var obj = patchObj.obj;
  563. this.currentDiffs = patch.diffs;
  564. this.diffIndex = (this.reverse) ? patch.diffs.length-1 : 0;
  565. var start = (this.reverse) ? patch.start1+patch.length2 : patch.start1;
  566. this.doDiffsAnimation(obj, start, function(){
  567. if (this.reverse){
  568. this.patchIndex--;
  569. if (this.patchIndex>=0){
  570. this.currentHistoryData = this.documentEditor.layout_filetext.get("html");
  571. this.doPatchAnimation(callback);
  572. }else{
  573. if (callback) callback();
  574. }
  575. }else{
  576. this.patchIndex++;
  577. if (this.patchIndex<this.diffPatch.length){
  578. this.currentHistoryData = this.documentEditor.layout_filetext.get("html");
  579. this.doPatchAnimation(callback);
  580. }else{
  581. if (callback) callback();
  582. }
  583. }
  584. }.bind(this));
  585. },
  586. doPatchAnimationStep: function(i){
  587. if (this.patchIndex>this.diffPatch.length || this.patchIndex<0){
  588. this.initAnimationStatus();
  589. this.documentEditor.resetData();
  590. this.checkToolbar();
  591. }else{
  592. var patchObj = this.diffPatch[this.patchIndex];
  593. var patch = patchObj.patch;
  594. var obj = patchObj.obj;
  595. this.currentDiffs = patch.diffs;
  596. this.diffIndex = 0;
  597. this.doDiffsAnimation(obj, patch.start1);
  598. this.patchIndex = this.patchIndex+i;
  599. }
  600. },
  601. createDiifInforNode: function(obj, node, color, insertInfor){
  602. if (this.historyInforDiv){
  603. this.historyInforDiv.dispose();
  604. this.historyInforDiv = null;
  605. }
  606. var styles = (!layout.mobile) ? this.css.historyInforNode : this.css.historyInforMobileNode
  607. var insertInforDiv = new Element("div", { "styles": styles }).inject(this.documentEditor.node);
  608. insertInforDiv.setStyle("background", color);
  609. insertInfor = insertInfor.replace(/{name}/, o2.name.cn(obj.person))
  610. .replace(/{activity}/, obj.activityName)
  611. .replace(/{time}/, obj.createTime);
  612. insertInforDiv.set("html", insertInfor);
  613. if (!layout.mobile){
  614. insertInforDiv.position({
  615. "relativeTo": node,
  616. "position": 'upperCenter',
  617. "edge": 'bottomCenter',
  618. "offset": {
  619. "x": 0, "y": -10
  620. }
  621. });
  622. }else{
  623. }
  624. // var p = node.getPosition(node.getOffsetParent());
  625. // if (p.x<0) p.x=0;
  626. // var y = (p.y-10-insertInforDiv.getSize().y);
  627. // var x = p.x;
  628. // alert(x)
  629. // var scale = (this.documentEditor.scale<0.7) ? 0.7 : this.documentEditor.scale;
  630. // insertInforDiv.setStyles({
  631. // "left": ""+x+"px",
  632. // "top": ""+y+"px",
  633. // "transform":"scale("+scale+")",
  634. // "transform-origin": "0px 0px",
  635. // });
  636. this.historyInforDiv = insertInforDiv;
  637. return insertInforDiv;
  638. },
  639. doDiffsAnimation: function(obj, start, callback){
  640. var diff = this.currentDiffs[this.diffIndex];
  641. var filetextNode = this.documentEditor.layout_filetext;
  642. switch (diff[0]) {
  643. case DIFF_INSERT:
  644. if (diff["item"]) diff["item"].showCurrent((!this.stopWhile || this.stopWhile == diff["id"]));
  645. if (this.originaDiff) this.originaDiff.hideCurrent();
  646. var text = diff[1];
  647. if (this.reverse){
  648. start -= text.length;
  649. var left = this.currentHistoryData.substring(0, start);
  650. var middle = this.currentHistoryData.substring(start, start+diff[1].length);
  651. var right = this.currentHistoryData.substring(start+diff[1].length);
  652. filetextNode.set("html", left+"<ins style='color:blue;'></ins>"+right);
  653. }else{
  654. var left = this.currentHistoryData.substring(0, start);
  655. var right = this.currentHistoryData.substring(start);
  656. filetextNode.set("html", left+"<ins style='color:blue;'></ins>"+right);
  657. }
  658. var ins = filetextNode.getElement("ins");
  659. if (!this.stopWhile || this.stopWhile == diff["id"]) ins.scrollIn();
  660. this.doInsetAnimation(ins,
  661. [1], function(invisible){
  662. var insertInforDiv = null;
  663. if (!invisible && (!this.stopWhile || this.stopWhile == diff["id"]) ){
  664. insertInforDiv = this.createDiifInforNode(obj, ins, "#e2edfb", MWF.xApplication.process.Xform.LP.documentHistory.insertContent);
  665. }
  666. window.setTimeout(function(){
  667. var endFunction = function(cb){
  668. if (insertInforDiv) insertInforDiv.fade("out");
  669. var fx = new Fx.Tween(ins, {property: 'opacity', duration:this.options.speed*this.options.fxTime});
  670. fx.start(1.1).chain(function(){
  671. if (insertInforDiv) insertInforDiv.destroy();
  672. if (diff["item"]) diff["item"].hideCurrent();
  673. if (this.reverse){
  674. ins.destroy();
  675. this.currentHistoryData = filetextNode.get("html");
  676. }else{
  677. data = filetextNode.get("html");
  678. this.currentHistoryData = data.replace(/<ins[\s\S]*\/ins>/m, text);
  679. filetextNode.set("html", this.currentHistoryData);
  680. }
  681. if (this.playing){
  682. if (this.reverse){
  683. this.diffIndex--;
  684. if (this.diffIndex>=0){
  685. window.setTimeout(function(){this.doDiffsAnimation(obj, start, function(){
  686. if (callback) callback();
  687. if (cb) cb();
  688. });}.bind(this), this.options.speed*this.options.fxTime);
  689. //this.doDiffsAnimation(obj, start, callback);
  690. }else{
  691. if (callback) callback();
  692. }
  693. }else{
  694. start += text.length;
  695. this.diffIndex++;
  696. if (this.diffIndex<this.currentDiffs.length){
  697. window.setTimeout(function(){this.doDiffsAnimation(obj, start, function(){
  698. if (callback) callback();
  699. if (cb) cb();
  700. });}.bind(this), this.options.speed*this.options.fxTime);
  701. //this.doDiffsAnimation(obj, start, callback);
  702. }else{
  703. if (callback) callback();
  704. }
  705. }
  706. }else{
  707. this.initAnimationStatus();
  708. this.documentEditor.resetData();
  709. if (cb) cb();
  710. }
  711. }.bind(this));
  712. if (this.nextPlayPrefixFunction) this.nextPlayPrefixFunction = null;
  713. }.bind(this)
  714. if (this.stopWhile) if (this.stopWhile == diff["id"]) this.stop = true;
  715. if (!this.stop || !this.playing) {
  716. endFunction();
  717. } else{
  718. if (this.stopWhile){
  719. this.stopWhile = "";
  720. //this.playing = false;
  721. }
  722. this.nextPlayPrefixFunction = endFunction;
  723. }
  724. this.checkToolbar();
  725. }.bind(this), (invisible ? 100: this.options.speed*this.options.inforTime));
  726. }.bind(this));
  727. break;
  728. case DIFF_DELETE:
  729. if (diff["item"]) diff["item"].showCurrent((!this.stopWhile || this.stopWhile == diff["id"]));
  730. if (this.originaDiff) this.originaDiff.hideCurrent();
  731. var text = diff[1];
  732. if (this.reverse){
  733. var left = this.currentHistoryData.substring(0, start);
  734. //var middle = this.currentHistoryData.substring(start, start+diff[1].length);
  735. var right = this.currentHistoryData.substring(start);
  736. filetextNode.set("html", left+"<del style='color: red'>"+text+"</del>"+right);
  737. start -= text.length;
  738. }else{
  739. var left = this.currentHistoryData.substring(0, start);
  740. var middle = this.currentHistoryData.substring(start, start+diff[1].length);
  741. var right = this.currentHistoryData.substring(start+diff[1].length);
  742. //start -= .length;
  743. filetextNode.set("html", left+"<del style='color: red'>"+middle+"</del>"+right);
  744. }
  745. var del = filetextNode.getElement("del");
  746. if (!this.stopWhile || this.stopWhile == diff["id"]) del.scrollIn();
  747. this.doDeleteAnimation(del, diff, obj, function(deleteInforDiv){
  748. // var deleteInforDiv = null;
  749. // if (!invisible){
  750. // deleteInforDiv = this.createDiifInforNode(obj, del, "#fbe0e7", MWF.xApplication.process.Xform.LP.documentHistory.deleteContent);
  751. // }
  752. var invisible = !deleteInforDiv;
  753. window.setTimeout(function(){
  754. var endFunction = function(cb){
  755. if (deleteInforDiv) deleteInforDiv.fade("out");
  756. var fx = new Fx.Tween(del, {property: 'opacity', duration:this.options.speed*this.options.fxTime});
  757. fx.start(0.5,0).chain(function(){
  758. if (deleteInforDiv) deleteInforDiv.destroy();
  759. if (diff["item"]) diff["item"].hideCurrent();
  760. if (this.reverse){
  761. data = filetextNode.get("html");
  762. this.currentHistoryData = data.replace(/<del[\s\S]*\/del>/m, text);
  763. filetextNode.set("html", this.currentHistoryData);
  764. }else{
  765. del.destroy();
  766. this.currentHistoryData = filetextNode.get("html");
  767. }
  768. if (this.playing){
  769. if (this.reverse){
  770. this.diffIndex--;
  771. if (this.diffIndex>=0){
  772. window.setTimeout(function(){this.doDiffsAnimation(obj, start, function(){
  773. if (callback) callback();
  774. if (cb) cb();
  775. });}.bind(this), this.options.speed*this.options.fxTime);
  776. }else{
  777. if (callback) callback();
  778. }
  779. }else{
  780. this.diffIndex++;
  781. if (this.diffIndex<this.currentDiffs.length){
  782. window.setTimeout(function(){this.doDiffsAnimation(obj, start, function(){
  783. if (callback) callback();
  784. if (cb) cb();
  785. });}.bind(this), this.options.speed*this.options.fxTime);
  786. }else{
  787. if (callback) callback();
  788. }
  789. }
  790. }else{
  791. this.initAnimationStatus();
  792. this.documentEditor.resetData();
  793. if (cb) cb();
  794. }
  795. }.bind(this));
  796. if (this.nextPlayPrefixFunction) this.nextPlayPrefixFunction = null;
  797. }.bind(this)
  798. if (this.stopWhile){
  799. if (this.stopWhile == diff["id"]) this.stop = true;
  800. }
  801. if (!this.stop || !this.playing) {
  802. endFunction();
  803. } else{
  804. if (this.stopWhile){
  805. this.stopWhile = "";
  806. //this.playing = false;
  807. }
  808. this.nextPlayPrefixFunction = endFunction;
  809. }
  810. this.checkToolbar();
  811. }.bind(this), (invisible ? 100: this.options.speed*this.options.inforTime));
  812. }.bind(this));
  813. break;
  814. case DIFF_EQUAL:
  815. if (this.reverse){
  816. start -= diff[1].length;
  817. this.diffIndex--;
  818. if (this.diffIndex>=0){
  819. this.doDiffsAnimation(obj, start, callback);
  820. }else{
  821. if (callback) callback();
  822. }
  823. }else{
  824. start += diff[1].length;
  825. this.diffIndex++;
  826. if (this.diffIndex<this.currentDiffs.length){
  827. this.doDiffsAnimation(obj, start, callback);
  828. }else{
  829. if (callback) callback();
  830. }
  831. }
  832. break;
  833. }
  834. },
  835. doInsetAnimation: function(node, str, callback){
  836. var tmp = new Element("div", {"html": str});
  837. if (!tmp.get("text").trim()){
  838. if (callback) callback(true);
  839. }else{
  840. var nodes = tmp.childNodes;
  841. this.doInsetNodeAnimation(node, nodes, 0, callback);
  842. }
  843. },
  844. doInsetNodeAnimation: function(ins, nodes, idx, callback){
  845. var node = nodes[idx];
  846. if (node.nodeType == Node.TEXT_NODE){
  847. this.doCharAnimation(ins, node.nodeValue, 0, function(){
  848. idx++;
  849. if (idx<nodes.length){
  850. this.doInsetNodeAnimation(ins, nodes, idx, callback);
  851. }else{
  852. if (callback) callback();
  853. }
  854. }.bind(this));
  855. }else{
  856. var duration = this.options.speed*this.options.fxTime/nodes.length;
  857. if (!duration){
  858. ins.appendChild(node);
  859. idx++;
  860. if (idx<nodes.length){
  861. this.doInsetNodeAnimation(ins, nodes, idx, callback);
  862. }else{
  863. if (callback) callback();
  864. }
  865. }else{
  866. var span = new Element("span", {"styles": {"opacity": 0}}).inject(ins);
  867. span.appendChild(node);
  868. var fx = new Fx.Tween(span, {property: 'opacity', duration:duration});
  869. fx.start(0,1).chain(function(){
  870. idx++;
  871. if (idx<nodes.length){
  872. this.doInsetNodeAnimation(ins, nodes, idx, callback);
  873. }else{
  874. if (callback) callback();
  875. }
  876. }.bind(this));
  877. }
  878. }
  879. },
  880. doCharAnimation: function(node, str, idx, callback){
  881. var duration = this.options.speed*this.options.fxTime/str.length;
  882. if (!duration){
  883. node.set("html", str);
  884. idx = str.length;
  885. if (callback) callback();
  886. }else{
  887. var char = str.charAt(idx);
  888. var span = new Element("span", {"styles": {"opacity": 0}, "html": char}).inject(node);
  889. var fx = new Fx.Tween(span, {property: 'opacity', duration:duration});
  890. fx.start(0,1).chain(function(){
  891. idx++;
  892. if (idx<str.length){
  893. this.doCharAnimation(node, str, idx, callback);
  894. }else{
  895. if (callback) callback();
  896. }
  897. }.bind(this));
  898. }
  899. },
  900. doDeleteAnimation: function(node, diff, obj, callback){
  901. var str = diff[1];
  902. var tmp = new Element("div", {"html": str});
  903. if (!tmp.get("text").trim()){
  904. if (callback) callback(null);
  905. }else{
  906. var deleteInforDiv = (!this.stopWhile || this.stopWhile == diff["id"]) ? this.createDiifInforNode(obj, node, "#fbe0e7", MWF.xApplication.process.Xform.LP.documentHistory.deleteContent) : null;
  907. var fx = new Fx.Tween(node, {property: 'opacity', duration:this.options.speed*this.options.fxTime});
  908. fx.start(1,0.5).chain(function(){
  909. if (callback) callback(deleteInforDiv);
  910. }.bind(this));
  911. }
  912. }
  913. });
  914. MWF.xApplication.process.Xform.widget.DocumentHistory.Item = new Class({
  915. initialize: function(history, historyData){
  916. this.history = history;
  917. this.documentEditor = this.history.documentEditor;
  918. this.css = this.history.css;
  919. this.historyData = historyData;
  920. this.load();
  921. },
  922. launch: function () {
  923. o2.load("../o2_lib/diff-match-patch/diff_match_patch_uncompressed.js", function(){
  924. var dmp = new diff_match_patch();
  925. var text1 = this.documentEditor.getFiletextText(this.historyData.json.data);
  926. var i = this.history.documentHistoryItems.indexOf(this)-1;
  927. if (i>=0){
  928. var text2 = this.documentEditor.getFiletextText(this.history.documentHistoryItems[i].historyData.json.data);
  929. // dmp.Diff_Timeout = parseFloat(document.getElementById('timeout').value);
  930. // dmp.Diff_EditCost = parseFloat(document.getElementById('editcost').value);
  931. var d = dmp.diff_main(text2, text1);
  932. dmp.diff_cleanupSemantic(d);
  933. var ds = dmp.diff_prettyHtml(d);
  934. //ds = ds.replace(/[\n\r]+/g, "<br>");
  935. ds = ds.replace(/(?<!\>)(?:&para;)/g, '');
  936. ds = ds.replace(/(\n\t\t\t)+/g, " | ")
  937. .replace(/(\n\t\t)+/g,"\n")
  938. .replace(/(\n\t)+/g,"\n")
  939. .replace(/\n+/g,"<br>")
  940. .replace(/\t+/g,"");
  941. //ds = ds.replace(/(\n\t)+/g,"<table width=100% border=1 style='border-collapse: collapse'>");
  942. //ds = ds.replace(/\n+/g, "<br>");
  943. this.documentEditor.layout_filetext.set("html", ds);
  944. var node = this.documentEditor.layout_filetext.querySelector('ins,del');
  945. if (node){
  946. node.scrollIntoView({behavior: "smooth", block: "center", inline: "nearest"});
  947. }
  948. }else{
  949. this.documentEditor.layout_filetext.set("html",this.historyData.json.data);
  950. }
  951. }.bind(this));
  952. },
  953. diffCurrent: function(){
  954. if (this.history.documentHistoryItems && this.history.documentHistoryItems.length){
  955. this.history.documentHistoryItems.each(function(item){
  956. if (item.histroyObj) item.histroyObj.hideCurrent();
  957. });
  958. }
  959. this.histroyObj.showCurrent();
  960. this.launch();
  961. },
  962. createTitleNode: function(){
  963. this.node = new Element("div", {"styles": this.css.historyListItemNode}).inject(this.history.historyListContentAreaNode);
  964. if (this.historyData.json.v && this.historyData.json.v=="6"){
  965. if (this.history.documentHistoryItems && this.history.documentHistoryItems.length){
  966. this.actionNode = new Element("div", {"styles": this.css.historyListItemActionNode, "text": MWF.xApplication.process.Xform.LP.documentHistory.diff, "title": MWF.xApplication.process.Xform.LP.documentHistory.diffTitle}).inject(this.node);
  967. this.actionNode.addEvent("click", function(e){
  968. this.diffCurrent();
  969. }.bind(this));
  970. }
  971. }
  972. var obj = this.historyData;
  973. var patchHtml = "";
  974. if (this.historyData.json.data){
  975. var d = this.documentEditor.getFiletextText(this.historyData.json.data);
  976. var s = d.length+" "+MWF.xApplication.process.Xform.LP.documentHistory.word;
  977. patchHtml = "<div style='font-weight: bold; min-height: 30px; word-break: break-all; padding: 5px 0;'>"+o2.name.cn(obj.person)+" ["+obj.activityName+"] ("+s+")</div><div style='height: 20px; line-height: 20px; color:#666666'>"+obj.createTime+"</div>"
  978. }else{
  979. patchHtml = "<div style='font-weight: bold; min-height: 30px; word-break: break-all; padding: 5px 0;'>"+o2.name.cn(obj.person)+" ["+obj.activityName+"]</div><div style='height: 20px; line-height: 20px; color:#666666'>"+obj.createTime+"</div>"
  980. }
  981. this.patchNode = new Element("div", {"styles": this.css.historyListItemPatchNode, "html": patchHtml}).inject(this.node);
  982. this.diffsNode = new Element("div", {"styles": this.css.historyListItemDiffsNode}).inject(this.node);
  983. },
  984. createDataNode:function(){
  985. var infor = MWF.xApplication.process.Xform.LP.documentHistory.original;
  986. var histroyObj = {
  987. "node": this.node,
  988. "showCurrent": function(){
  989. this.node.setStyles({"background-color": "#e2edfb"});
  990. //if (show) this.node.scrollIn();
  991. },
  992. "hideCurrent": function(){
  993. this.node.setStyles(_self.css.historyListItemDiffNode);
  994. }
  995. };
  996. var _self = this;
  997. this.histroyObj = histroyObj;
  998. this.node.addEvents({
  999. "click": function(){
  1000. // if (_self.history.stop){
  1001. // _self.history.origina(_self.historyData.json.data, histroyObj);
  1002. // }
  1003. _self.diffCurrent();
  1004. }
  1005. });
  1006. },
  1007. createPatchNode: function(patch){
  1008. var _self = this;
  1009. patch.diffs.each(function(diff){
  1010. if (diff[0]!=0){
  1011. diff["id"] = (new o2.widget.UUID()).toString();
  1012. var tmp = new Element("div", {"html": diff[1]});
  1013. infor = tmp.get("text");
  1014. var infor = ((infor.length>50) ? infor.substring(0, 50)+"..." : infor);
  1015. tmp.destroy();
  1016. if (diff[0]==-1){
  1017. infor = MWF.xApplication.process.Xform.LP.documentHistory.delete +": "+"<span style='color:red; word-break: break-all;'><del>"+infor+"</del></span>"
  1018. }else{
  1019. infor = MWF.xApplication.process.Xform.LP.documentHistory.insert +": "+"<span style='color:blue;word-break: break-all;'><ins>"+infor+"</ins></span>"
  1020. }
  1021. diffNode = new Element("div", {"styles": this.css.historyListItemDiffNode, "html": infor}).inject(this.diffsNode);
  1022. diffNode.store("diff", diff);
  1023. diff["item"] = {
  1024. "node": diffNode,
  1025. "showCurrent": function(show){
  1026. var thisDiff = this.node.retrieve("diff");
  1027. var color = (thisDiff[0]==-1) ? "#fbe0e7": "#e2edfb";
  1028. this.node.setStyles({"background-color": color});
  1029. var ss = _self.history.historyListContentAreaNode.getScrollSize();
  1030. var s = _self.history.historyListContentAreaNode.getSize();
  1031. if (ss.y>s.y) if (show) this.node.scrollIn();
  1032. },
  1033. "hideCurrent": function(){
  1034. this.node.setStyles(_self.css.historyListItemDiffNode);
  1035. }
  1036. };
  1037. }
  1038. }.bind(this));
  1039. },
  1040. load: function(){
  1041. this.createTitleNode();
  1042. var patchs = this.historyData.json.patchObj || null;
  1043. if (this.historyData.json.v && this.historyData.json.v=="6"){
  1044. if (this.historyData.json.data) this.createDataNode();
  1045. if (patchs){
  1046. patchs.each(function(patch){
  1047. this.createPatchNode(patch);
  1048. }.bind(this));
  1049. }else{
  1050. new Element("div", {"styles": this.css.historyListItemDiffNode, "text": MWF.xApplication.process.Xform.LP.documentHistory.original}).inject(this.diffsNode);
  1051. }
  1052. }else{
  1053. var _self = this;
  1054. if (patchs){
  1055. patchs.each(function(patch){
  1056. patch.diffs.each(function(diff){
  1057. if (diff[0]!=0){
  1058. diff["id"] = (new o2.widget.UUID()).toString();
  1059. var tmp = new Element("div", {"html": diff[1]});
  1060. infor = tmp.get("text");
  1061. var infor = ((infor.length>50) ? infor.substring(0, 50)+"..." : infor);
  1062. tmp.destroy();
  1063. if (diff[0]==-1){
  1064. infor = MWF.xApplication.process.Xform.LP.documentHistory.delete +": "+"<span style='color:red'><del>"+infor+"</del></span>"
  1065. }else{
  1066. infor = MWF.xApplication.process.Xform.LP.documentHistory.insert +": "+"<span style='color:blue'><ins>"+infor+"</ins></span>"
  1067. }
  1068. diffNode = new Element("div", {"styles": this.css.historyListItemDiffNode, "html": infor}).inject(this.diffsNode);
  1069. diffNode.store("diff", diff);
  1070. diff["item"] = {
  1071. "node": diffNode,
  1072. "showCurrent": function(show){
  1073. var thisDiff = this.node.retrieve("diff");
  1074. var color = (thisDiff[0]==-1) ? "#fbe0e7": "#e2edfb";
  1075. this.node.setStyles({"background-color": color});
  1076. var ss = _self.history.historyListContentAreaNode.getScrollSize();
  1077. var s = _self.history.historyListContentAreaNode.getSize();
  1078. if (ss.y>s.y) if (show) this.node.scrollIn();
  1079. },
  1080. "hideCurrent": function(){
  1081. this.node.setStyles(_self.css.historyListItemDiffNode);
  1082. }
  1083. };
  1084. diffNode.addEvents({
  1085. "click": function(){
  1086. if (_self.history.stop){
  1087. var diff = this.retrieve("diff");
  1088. _self.history.to(diff);
  1089. }
  1090. }
  1091. });
  1092. }
  1093. }.bind(this));
  1094. }.bind(this));
  1095. }else{
  1096. infor = MWF.xApplication.process.Xform.LP.documentHistory.original;
  1097. diffNode = new Element("div", {"styles": this.css.historyListItemDiffNode, "html": infor}).inject(this.diffsNode);
  1098. this.history.originaDiff = {
  1099. "node": diffNode,
  1100. "showCurrent": function(){
  1101. this.node.setStyles({"background-color": "#e2edfb"});
  1102. },
  1103. "hideCurrent": function(){
  1104. this.node.setStyles(_self.css.historyListItemDiffNode);
  1105. }
  1106. };
  1107. diffNode.addEvents({
  1108. "click": function(){
  1109. if (_self.history.stop){
  1110. _self.history.origina();
  1111. }
  1112. }
  1113. });
  1114. }
  1115. }
  1116. }
  1117. })