DocumentHistory.js 56 KB

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