X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5913c54d19b8f6775633176032161d49f9b2f1aa..51ea493dd4c46246c80ed3190b43ebfc0d75d67c:/src/redakcja/static/js/wiki/view_column_diff.js?ds=inline diff --git a/src/redakcja/static/js/wiki/view_column_diff.js b/src/redakcja/static/js/wiki/view_column_diff.js index 33ffb6a0..30ef1bd4 100644 --- a/src/redakcja/static/js/wiki/view_column_diff.js +++ b/src/redakcja/static/js/wiki/view_column_diff.js @@ -1,35 +1,51 @@ (function($){ - function DiffPerspective(options) { - var old_callback = options.callback || function() {}; - var self = this; - - options.callback = function(){ - self.base_id = options.base_id; - old_callback.call(this); - }; - - $.wiki.Perspective.call(this, options); - }; - - DiffPerspective.prototype = new $.wiki.Perspective(); - - DiffPerspective.prototype.freezeState = function(){ - // must - }; - - DiffPerspective.prototype.destroy = function() { - $.wiki.switchToTab('#HistoryPerspective'); - $('#' + this.base_id).remove(); - $('#' + this.perspective_id).remove(); - }; - - DiffPerspective.prototype.onEnter = function(success, failure){ - $.wiki.Perspective.prototype.onEnter.call(this); - console.log("Entered diff view"); - }; - - $.wiki.DiffPerspective = DiffPerspective; + class DiffPerspective extends $.wiki.Perspective { + constructor(options) { + super(options); + this.base_id = options.base_id; + } + + static openId(id) { + let match = id.match(/R(\d+)-(\d+)/); + if (!match) + return []; + return this.open(match[1], match[2]); + } + + static open(revFrom, revTo) { + let tabId = 'R' + revFrom + '-' + revTo; + let tab = $(".tabs #DiffPerspective_" + tabId); + if (tab.length) { + $.wiki.switchToTab(tab); + } else { + let result = $.wiki.newTab(CurrentDocument, ''+revFrom +' → ' + revTo, 'DiffPerspective', tabId); + $.blockUI({ + message: 'Wczytywanie porównania...' + }); + + CurrentDocument.fetchDiff({ + from: revFrom, + to: revTo, + success: function(doc, data){ + $(result.view).html(data); + $.wiki.switchToTab(result.tab); + $.unblockUI(); + }, + failure: function(doc){ + $.unblockUI(); + } + }); + return result.tab; + } + } + + destroy() { + $.wiki.switchToTab('#HistoryPerspective'); + $('#' + this.base_id).remove(); + $('#' + this.perspective_id).remove(); + } + } + $.wiki.DiffPerspective = DiffPerspective; })(jQuery); -