X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/9d566b4741eb66bf09b5c7d213aa8541886e100a..11135898543370ecf4ffa95dbea14cba4c33f57c:/src/redakcja/static/js/wiki/base.js diff --git a/src/redakcja/static/js/wiki/base.js b/src/redakcja/static/js/wiki/base.js index 7018b1a6..ad0ca835 100644 --- a/src/redakcja/static/js/wiki/base.js +++ b/src/redakcja/static/js/wiki/base.js @@ -65,8 +65,7 @@ return (!!CurrentDocument && CurrentDocument.has_local_changes) || ap.dirty(); }; - $.wiki.newTab = function(doc, title, klass) { - var base_id = 'id' + Math.floor(Math.random()* 5000000000); + $.wiki.newTab = function(doc, title, klass, base_id) { var id = (''+klass)+'_' + base_id; var $tab = $(''); @@ -89,15 +88,12 @@ $.wiki.initTab = function(options) { var klass = $(options.tab).attr('data-ui-jsclass'); - return new $.wiki[klass]({ + let perspective = new $.wiki[klass]({ doc: options.doc, id: $(options.tab).attr('id'), - callback: function() { - $.wiki.perspectives[this.perspective_id] = this; - if(options.callback) - options.callback.call(this); - } }); + $.wiki.perspectives[perspective.perspective_id] = perspective; + return perspective; }; $.wiki.perspectiveForTab = function(tab) { // element or id @@ -107,7 +103,7 @@ $.wiki.exitTab = function(tab){ var self = this; var $tab = $(tab); - if (!('.active', $tab)) return; + if (!('.active', $tab).length) return; $('.active', $tab).removeClass('active'); self.perspectives[$tab.attr('id')].onExit(); $('#' + $tab.attr('data-ui-related')).hide(); @@ -117,6 +113,17 @@ var self = this; var $tab = $(tab); + // Create dynamic tabs (for diffs). + if ($tab.length != 1) { + let parts = tab.split('_'); + if (parts.length > 1) { + // TODO: register perspectives for it. + if (parts[0] == '#DiffPerspective') { + $tab = $($.wiki.DiffPerspective.openId(parts[1])); + } + } + } + if($tab.length != 1) $tab = $(DEFAULT_PERSPECTIVE); @@ -144,18 +151,8 @@ */ $.wiki.Perspective = class Perspective { constructor(options) { - if(!options) return; - this.doc = options.doc; - if (options.id) { - this.perspective_id = options.id; - } - else { - this.perspective_id = ''; - } - - if(options.callback) - options.callback.call(this); + this.perspective_id = options.id || '' }; config() { @@ -187,14 +184,6 @@ destroy() { // pass } - - freezeState() { - // free UI state (don't store data here) - } - - unfreezeState(frozenState) { - // restore UI state - } } /* @@ -207,8 +196,7 @@ $elem.removeClass('row-stub'); params.container.append($elem); - $('*[data-stub-value]', $elem).each(function() { - var $this = $(this); + var populate = function($this) { var field = $this.attr('data-stub-value'); var value = params.data[field]; @@ -226,7 +214,9 @@ $this.removeAttr('data-stub-target'); $this.removeAttr('data-stub-value'); } - }); + } + if ($elem.attr('data-stub-value')) populate($elem); + $('*[data-stub-value]', $elem).each(function() {populate($(this))}); $elem.show(); return $elem; @@ -318,7 +308,7 @@ var span = $("*[data-ui-error-for='"+field_name+"']", this.$elem); if(!span.length) { - unassigned.push(field_name); + unassigned.push(errors[field_name]); continue; } @@ -326,7 +316,8 @@ } if(unassigned.length > 0) - global.text( global.text() + 'W formularzu wystąpiły błędy'); + global.text( + global.text() + 'Wystąpił błąd: ' + unassigned.join(', ')); } } @@ -355,6 +346,7 @@ $.ajax("/editor/editor-user-area/", { success: function(d) { $("#user-area")[0].innerHTML = d; + $('#history-view-editor').toggleClass('can-approve', $('#user-area #pubmark_dialog').length > 0); } }); }, false);