diff --git a/framework/core/ember/app/components/application/back-button.js b/framework/core/ember/app/components/application/back-button.js index 630104130..5ecaa8090 100755 --- a/framework/core/ember/app/components/application/back-button.js +++ b/framework/core/ember/app/components/application/back-button.js @@ -10,21 +10,30 @@ export default Ember.Component.extend({ active: Ember.computed.or('target.paneIsShowing', 'target.paneIsPinned'), mouseEnter: function() { - this.get('target').send('showPane'); + var target = this.get('target'); + if (target) { + target.send('showPane'); + } }, mouseLeave: function() { - this.get('target').send('hidePane'); + var target = this.get('target'); + if (target) { + target.send('hidePane'); + } }, actions: { + // WE HAVE TO GO BACK. WAAAAAALLLLLLTTTTT back: function() { - this.get('target').send('transitionFromBackButton'); - this.set('target', null); + this.sendAction('goBack'); }, togglePinned: function() { - this.get('target').send('togglePinned'); + var target = this.get('target'); + if (target) { + target.send('togglePinned'); + } }, toggleDrawer: function() { diff --git a/framework/core/ember/app/controllers/application.js b/framework/core/ember/app/controllers/application.js index a9e01f9c4..ec27c72de 100644 --- a/framework/core/ember/app/controllers/application.js +++ b/framework/core/ember/app/controllers/application.js @@ -14,7 +14,41 @@ export default Ember.Controller.extend({ searchQuery: '', searchActive: false, + history: null, + + init: function() { + this._super(); + this.set('history', []); + this.pushHistory('index', '/'); + }, + + pushHistory: function(name, url) { + var url = url || this.get('target.url'); + var last = this.get('history').get('lastObject'); + if (last && last.name === name) { + last.url = url; + } else { + this.get('history').pushObject({name: name, url: url}); + } + }, + + popHistory: function(name) { + var last = this.get('history').get('lastObject'); + if (last && last.name === name) { + this.get('history').popObject(); + } + }, + + canGoBack: Ember.computed('history.length', function() { + return this.get('history.length') > 1; + }), + actions: { + goBack: function() { + this.get('history').popObject(); + var history = this.get('history').get('lastObject'); + this.transitionToRoute.call(this, history.url); + }, search: function(query) { this.transitionToRoute('index', {queryParams: {searchQuery: query, sort: query ? 'relevance' : 'recent'}}); }, diff --git a/framework/core/ember/app/controllers/index.js b/framework/core/ember/app/controllers/index.js index cd6ca95ec..21421ef98 100644 --- a/framework/core/ember/app/controllers/index.js +++ b/framework/core/ember/app/controllers/index.js @@ -32,10 +32,6 @@ export default Ember.Controller.extend(UseComposer, Paneable, { }, actions: { - transitionFromBackButton: function() { - this.transitionToRoute('index'); - }, - loadMore: function() { this.get('index').send('loadMore'); }, diff --git a/framework/core/ember/app/mixins/pushes-history.js b/framework/core/ember/app/mixins/pushes-history.js new file mode 100644 index 000000000..c0ca98d31 --- /dev/null +++ b/framework/core/ember/app/mixins/pushes-history.js @@ -0,0 +1,20 @@ +import Ember from 'ember'; + +export default Ember.Mixin.create({ + pushHistory: function() { + Ember.run.next(this, function() { + this.controllerFor('application').pushHistory(this.get('historyKey'), this.get('url')); + }); + }, + + setupController: function(controller, model) { + this._super(controller, model); + this.pushHistory(); + }, + + actions: { + queryParamsDidChange: function() { + this.pushHistory(); + } + } +}) diff --git a/framework/core/ember/app/routes/discussion.js b/framework/core/ember/app/routes/discussion.js index 980e3366b..802f0ef79 100644 --- a/framework/core/ember/app/routes/discussion.js +++ b/framework/core/ember/app/routes/discussion.js @@ -1,8 +1,11 @@ import Ember from 'ember'; import PostStream from 'flarum/models/post-stream'; +import PushesHistory from 'flarum/mixins/pushes-history'; + +export default Ember.Route.extend(PushesHistory, { + historyKey: 'discussion', -export default Ember.Route.extend({ queryParams: { start: {replace: true} }, @@ -33,7 +36,7 @@ export default Ember.Route.extend({ }, setupController: function(controller, discussion) { - controller.set('model', discussion); + this._super(controller, discussion); this.controllerFor('index/index').set('lastDiscussion', discussion); // Set up the post stream object. It needs to know about the discussion @@ -94,6 +97,8 @@ export default Ember.Route.extend({ actions: { queryParamsDidChange: function(params) { + this._super(params); + // If the ?start param has changed, we want to tell the view to // tell the streamContent component to jump to this start point. // We postpone running this code until the next run loop because diff --git a/framework/core/ember/app/routes/index.js b/framework/core/ember/app/routes/index.js new file mode 100644 index 000000000..2aedef2f3 --- /dev/null +++ b/framework/core/ember/app/routes/index.js @@ -0,0 +1,7 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + deactivate: function() { + this.controllerFor('application').set('backButtonTarget', null); + } +}); diff --git a/framework/core/ember/app/routes/index/index.js b/framework/core/ember/app/routes/index/index.js index e614fae45..c0d543717 100644 --- a/framework/core/ember/app/routes/index/index.js +++ b/framework/core/ember/app/routes/index/index.js @@ -1,8 +1,11 @@ import Ember from 'ember'; import AddCssClassToBody from 'flarum/mixins/add-css-class-to-body'; +import PushesHistory from 'flarum/mixins/pushes-history'; + +export default Ember.Route.extend(AddCssClassToBody, PushesHistory, { + historyKey: 'index', -export default Ember.Route.extend(AddCssClassToBody, { cachedModel: null, model: function() { @@ -13,7 +16,7 @@ export default Ember.Route.extend(AddCssClassToBody, { }, setupController: function(controller, model) { - controller.set('model', model); + this._super(controller, model); if (!model.get('length')) { controller.send('loadResults'); diff --git a/framework/core/ember/app/routes/user/activity.js b/framework/core/ember/app/routes/user/activity.js index 75e94045a..1b5c437de 100644 --- a/framework/core/ember/app/routes/user/activity.js +++ b/framework/core/ember/app/routes/user/activity.js @@ -1,12 +1,17 @@ import Ember from 'ember'; -export default Ember.Route.extend({ +import PushesHistory from 'flarum/mixins/pushes-history'; + +export default Ember.Route.extend(PushesHistory, { + historyKey: 'user', + model: function() { return Ember.RSVP.resolve(Ember.ArrayProxy.create()); }, setupController: function(controller, model) { - controller.set('model', model); + this._super(controller, model); + controller.send('loadResults'); } }); diff --git a/framework/core/ember/app/templates/application.hbs b/framework/core/ember/app/templates/application.hbs index 0aec1a4ba..219c056a6 100644 --- a/framework/core/ember/app/templates/application.hbs +++ b/framework/core/ember/app/templates/application.hbs @@ -1,10 +1,10 @@