fix links to site contents, fix it so the site contents page is refreshable

This commit is contained in:
Sam 2013-07-17 14:15:09 +10:00
parent d1dbcf52fc
commit 63cbe8dd17
4 changed files with 35 additions and 7 deletions

View File

@ -10,12 +10,14 @@ Discourse.SiteContentType = Discourse.Model.extend({});
Discourse.SiteContentType.reopenClass({
findAll: function() {
var contentTypes = Em.A();
promise = new Em.Deferred();
Discourse.ajax("/admin/site_content_types").then(function(data) {
var contentTypes = Em.A();
data.forEach(function (ct) {
contentTypes.pushObject(Discourse.SiteContentType.create(ct));
});
promise.resolve(contentTypes);
});
return contentTypes;
return promise;
}
});

View File

@ -13,7 +13,29 @@ Discourse.AdminSiteContentEditRoute = Discourse.Route.extend({
},
model: function(params) {
return {content_type: params.content_type};
var list = this.controllerFor('adminSiteContents').get('model');
var model;
// ember routing is fun ... this is what happens
//
// linkTo creates an Ember.LinkView , it marks an <a> with the class "active"
// if the "context" of this dynamic route is equal to the model in the linkTo
// the route "context" is set here, so we want to make sure we have the exact
// same object, from Ember we have:
//
// if (handlerInfo.context !== object) { return false; }
//
// we could avoid this hack if Ember just compared .serialize(model) with .serialize(context)
//
// alternatively we could use some sort of identity map
list.forEach(function(orig){
if(orig.get("content_type") === params.content_type){
model = orig;
}
});
return model;
},
renderTemplate: function() {
@ -26,6 +48,7 @@ Discourse.AdminSiteContentEditRoute = Discourse.Route.extend({
},
setupController: function(controller, model) {
controller.set('loaded', false);
controller.setProperties({
model: model,
@ -33,7 +56,7 @@ Discourse.AdminSiteContentEditRoute = Discourse.Route.extend({
saved: false
});
Discourse.SiteContent.find(Em.get(model, 'content_type')).then(function (sc) {
Discourse.SiteContent.find(model.get('content_type')).then(function (sc) {
controller.set('content', sc);
controller.set('loaded', true);
});

View File

@ -13,9 +13,12 @@ Discourse.AdminSiteContentsRoute = Discourse.Route.extend({
},
renderTemplate: function(controller, model) {
controller.set('model', model);
this.render('admin/templates/site_contents', {into: 'admin/templates/admin'});
this.render('admin/templates/site_contents_empty', {into: 'admin/templates/site_contents'});
},
setupController: function(controller, model) {
controller.set('model', model);
}
});

View File

@ -2,7 +2,7 @@
<div class='content-list span6'>
<h3>{{i18n admin.site_content.edit}}</h3>
<ul>
{{#each type in content}}
{{#each type in model}}
<li>
{{#linkTo 'adminSiteContentEdit' type}}{{type.title}}{{/linkTo}}
</li>
@ -13,4 +13,4 @@
<div class='content-editor'>
{{outlet}}
</div>
</div>
</div>