Removed modelReady hack now that the async router exists

This commit is contained in:
Robin Ward 2013-07-16 13:24:59 -04:00
parent 6929ee9f46
commit 4bfb546942
8 changed files with 22 additions and 42 deletions

View File

@ -238,9 +238,9 @@ Discourse.AdminUser = Discourse.User.extend({
loadDetails: function() {
var model = this;
if (model.get('loadedDetails')) { return; }
if (model.get('loadedDetails')) { return Ember.RSVP.resolve(model); }
Discourse.AdminUser.find(model.get('username_lower')).then(function (result) {
return Discourse.AdminUser.find(model.get('username_lower')).then(function (result) {
model.setProperties(result);
model.set('loadedDetails', true);
});

View File

@ -11,14 +11,16 @@ var oneWeekAgo = function() {
return moment().subtract('days',7).format('YYYY-MM-DD');
};
Discourse.AdminEmailPreviewDigestRoute = Discourse.Route.extend(Discourse.ModelReady, {
Discourse.AdminEmailPreviewDigestRoute = Discourse.Route.extend({
model: function() {
return Discourse.EmailPreview.findDigest(oneWeekAgo());
},
modelReady: function(controller, model) {
afterModel: function(model) {
var controller = this.controllerFor('adminEmailPreviewDigest');
controller.setProperties({
model: model,
lastSeen: oneWeekAgo(),
showHtml: true
});

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminUserRoute = Discourse.Route.extend(Discourse.ModelReady, {
Discourse.AdminUserRoute = Discourse.Route.extend({
serialize: function(params) {
return { username: Em.get(params, 'username').toLowerCase() };
@ -20,10 +20,14 @@ Discourse.AdminUserRoute = Discourse.Route.extend(Discourse.ModelReady, {
this.render({into: 'admin/templates/admin'});
},
modelReady: function(controller, adminUser) {
adminUser.loadDetails();
controller.set('model', adminUser);
adminUser.setOriginalTrustLevel();
afterModel: function(adminUser) {
var controller = this.controllerFor('adminUser');
adminUser.loadDetails().then(function () {
adminUser.setOriginalTrustLevel();
controller.set('model', adminUser);
});
}
});

View File

@ -1,29 +0,0 @@
/**
Until the fully async router is merged into Ember, it is healthy to do some extra checking
that setupController is not passed a promise instead of the model we want.
This mixin handles that case, and calls modelReady instead.
@class Discourse.ModelReady
@extends Ember.Mixin
@namespace Discourse
@module Discourse
**/
Discourse.ModelReady = Em.Mixin.create({
setupController: function(controller, model) {
var route = this;
if (model.then) {
model.then(function (m) {
controller.set('model', m);
if (route.modelReady) { route.modelReady(controller, m); }
});
} else {
controller.set('model', model);
if (route.modelReady) { route.modelReady(controller, model); }
}
}
});

View File

@ -16,6 +16,7 @@ Discourse.InviteList.reopenClass({
findInvitedBy: function(user) {
return Discourse.ajax("/users/" + (user.get('username_lower')) + "/invited.json").then(function (result) {
console.log('wat');
var invitedList = result.invited_list;
if (invitedList.pending) {
invitedList.pending = invitedList.pending.map(function(i) {

View File

@ -8,7 +8,7 @@
**/
Discourse.RestrictedUserRoute = Discourse.Route.extend({
redirect: function() {
afterModel: function() {
var user = this.modelFor('user');
if (!user.get('can_edit')) {
this.transitionTo('user.activity', user);

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.ListCategoriesRoute = Discourse.Route.extend(Discourse.ModelReady, {
Discourse.ListCategoriesRoute = Discourse.Route.extend({
redirect: function() { Discourse.redirectIfLoginRequired(this); },
@ -31,9 +31,11 @@ Discourse.ListCategoriesRoute = Discourse.Route.extend(Discourse.ModelReady, {
this.controllerFor('list').set('canCreateCategory', false);
},
modelReady: function(controller, categoryList) {
renderTemplate: function() {
this.render('listCategories', { into: 'list', outlet: 'listView' });
},
afterModel: function(categoryList) {
this.controllerFor('list').setProperties({
canCreateCategory: categoryList.get('can_create_category'),
canCreateTopic: categoryList.get('can_create_topic'),

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.UserInvitedRoute = Discourse.Route.extend(Discourse.ModelReady, {
Discourse.UserInvitedRoute = Discourse.Route.extend({
renderTemplate: function() {
this.render({ into: 'user', outlet: 'userOutlet' });