Category is fetched from server when loading edit category modal, because topic_count needs to be up-to-date for the delete button to show/hide in a sane way
This commit is contained in:
parent
5d46478e38
commit
03047b0ab0
|
@ -43,4 +43,10 @@ Discourse.Category = Discourse.Model.extend({
|
|||
|
||||
});
|
||||
|
||||
|
||||
Discourse.Category.reopenClass({
|
||||
findBySlug: function(categorySlug) {
|
||||
return Discourse.ajax({url: Discourse.getURL("/categories/") + categorySlug + ".json"}).then(function (result) {
|
||||
return Discourse.Category.create(result.category);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{{#with view.category}}
|
||||
|
||||
<div {{bindAttr class="view.loading:invisible"}}>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<section class='field'>
|
||||
|
@ -56,5 +57,6 @@
|
|||
<button class='btn btn-danger pull-right' {{bindAttr disabled="view.deleteDisabled"}} {{action deleteCategory target="view"}}><i class="icon icon-trash"></i>{{view.deleteButtonTitle}}</button>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{/with}}
|
|
@ -67,8 +67,17 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||
didInsertElement: function() {
|
||||
this._super();
|
||||
|
||||
if (this.get('category')) {
|
||||
this.set('id', this.get('category.slug'));
|
||||
if( this.get('category.id') ) {
|
||||
this.set('loading', true);
|
||||
var categoryView = this;
|
||||
|
||||
// We need the topic_count to be correct, so get the most up-to-date info about this category from the server.
|
||||
Discourse.Category.findBySlug( this.get('category.slug') ).then( function(cat) {
|
||||
categoryView.set('category', cat);
|
||||
Discourse.get('site').updateCategory(cat);
|
||||
categoryView.set('id', categoryView.get('category.slug'));
|
||||
categoryView.set('loading', false);
|
||||
});
|
||||
} else {
|
||||
this.set('category', Discourse.Category.create({ color: 'AB9364', text_color: 'FFFFFF', hotness: 5 }));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue