# HG changeset patch # User Ludovic Chabant # Date 1384471308 28800 # Node ID 827e236aa7c6b719c1592db6824de6f3c1ac794d # Parent f0172c5d8e2c70f68fa9a6f25f2c3c07514e2f65 Various front-end fixes: - Handle absolute URLs correctly. - Show the state warning only after the page has rendered. diff -r f0172c5d8e2c -r 827e236aa7c6 static/js/wikked/models.js --- a/static/js/wikked/models.js Tue Nov 12 13:54:29 2013 -0800 +++ b/static/js/wikked/models.js Thu Nov 14 15:21:48 2013 -0800 @@ -226,17 +226,22 @@ this.footer.addExtraUrl('JSON', function() { return '/api/read/' + model.id; }); }, _onChange: function() { - if (this.getMeta('redirect') && - !this.get('no_redirect') && - !this.get('redirected_from')) { + if (this.getMeta('redirect')) { // Handle redirects. - var oldPath = this.get('path'); - this.set({ - 'path': this.getMeta('redirect'), - 'redirected_from': oldPath - }); - this.fetch(); - this.navigate('/read/' + this.getMeta('redirect'), { replace: true, trigger: false }); + var newPath = this.getMeta('redirect').replace(/^\//, ""); + if (this.get('no_redirect')) { + this.set({ 'redirects_to': newPath }, { 'silent': true }); + } else { + var oldPath = this.get('path'); + this.set({ + 'path': newPath, + 'redirected_from': oldPath + }, { + 'silent': true + }); + this.fetch(); + this.navigate('/read/' + newPath, { replace: true, trigger: false }); + } } } }); diff -r f0172c5d8e2c -r 827e236aa7c6 static/js/wikked/views.js --- a/static/js/wikked/views.js Tue Nov 12 13:54:29 2013 -0800 +++ b/static/js/wikked/views.js Thu Nov 14 15:21:48 2013 -0800 @@ -247,14 +247,19 @@ this.$('a.wiki-link[data-wiki-url]').each(function(i) { var jel = $(this); if (jel.hasClass('missing') || jel.attr('data-action') == 'edit') - jel.attr('href', '/#/edit/' + jel.attr('data-wiki-url')); + jel.attr('href', '/#/edit' + jel.attr('data-wiki-url')); else - jel.attr('href', '/#/read/' + jel.attr('data-wiki-url')); + jel.attr('href', '/#/read' + jel.attr('data-wiki-url')); }); - // If we've already rendered the content, and we need to display - // a warning, do so now. + // If we've already rendered the content, see if need to display a + // warning about the page's state. if (this.model.get('content')) { - this._showPageStateWarning(); + if (this._pageState === undefined) { + if (!this._isCheckingPageState) + this._checkPageState(); + } else { + this._showPageStateWarning(); + } } }, _showPageStateWarning: function() { @@ -263,10 +268,11 @@ var state = this._pageState.get('state'); if (state == 'new' || state == 'modified') { + var article = $('.wrapper>article'); var warning = $(this.warningTemplate(this._pageState.toJSON())); $('[rel="tooltip"]', warning).tooltip({container:'body'}); //warning.css('display', 'none'); - warning.prependTo($('.wrapper>article')); + warning.prependTo(article); //warning.slideDown(); $('.dismiss', warning).click(function() { //warning.slideUp(); @@ -275,29 +281,20 @@ }); } }, + _isCheckingPageState: false, _checkPageState: function() { + this._isCheckingPageState = true; var $view = this; var stateModel = new Models.PageStateModel({ path: this.model.get('path') }); stateModel.fetch({ success: function(model, response, options) { $view._pageState = model; - // If we've already rendered the content, display - // the warning, if any, now. + $view._isCheckingPageState = false; if ($view.model && $view.model.get('content')) { $view._showPageStateWarning(); } } }); - }, - _firstRender: true, - _onModelChange: function() { - PageReadView.__super__._onModelChange.apply(this, arguments); - - // Fetch the state if the current page changed. - if (!this.isError && (this.model.hasChanged('path') || this._firstRender)) { - this._checkPageState(); - this._firstRender = false; - } } }); diff -r f0172c5d8e2c -r 827e236aa7c6 static/tpl/read-page.html --- a/static/tpl/read-page.html Tue Nov 12 13:54:29 2013 -0800 +++ b/static/tpl/read-page.html Thu Nov 14 15:21:48 2013 -0800 @@ -6,7 +6,7 @@ Redirected from {{redirected_from}} {{/if}} {{#if meta.redirect}} - Redirects to {{meta.redirect}} + Redirects to {{redirects_to}} {{/if}} {{/ifnot}} diff -r f0172c5d8e2c -r 827e236aa7c6 static/tpl/search-results.html --- a/static/tpl/search-results.html Tue Nov 12 13:54:29 2013 -0800 +++ b/static/tpl/search-results.html Thu Nov 14 15:21:48 2013 -0800 @@ -10,7 +10,7 @@