Can assign a parent category to a category.

This commit is contained in:
Robin Ward
2013-10-24 17:03:28 -04:00
parent ee2dd9d24c
commit 61468f6f27
10 changed files with 67 additions and 27 deletions
@@ -13,6 +13,12 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
settingsSelected: Ember.computed.equal('selectedTab', 'settings'),
foregroundColors: ['FFFFFF', '000000'],
parentCategories: function() {
return Discourse.Category.list().filter(function (c) {
return !c.get('parentCategory');
});
}.property(),
onShow: function() {
this.changeSize();
this.titleChanged();
@@ -122,17 +128,27 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
},
saveCategory: function() {
var categoryController = this;
var self = this,
model = this.get('model'),
parentCategory = Discourse.Category.list().findBy('id', parseInt(model.get('parent_category_id'), 10));
this.set('saving', true);
model.set('parentCategory', parentCategory);
var newSlug = Discourse.Category.slugFor(this.get('model'));
this.get('model').save().then(function(result) {
// success
categoryController.send('closeModal');
Discourse.URL.redirectTo("/category/" + Discourse.Category.slugFor(result.category));
}, function(errors) {
// errors
if(errors.length === 0) errors.push(I18n.t("category.creation_error"));
categoryController.displayErrors(errors);
categoryController.set('saving', false);
self.send('closeModal');
Discourse.URL.redirectTo("/category/" + newSlug);
}, function(error) {
if (error && error.responseText) {
self.flash($.parseJSON(error.responseText).errors[0]);
} else {
self.flash(I18n.t('generic_error'));
}
self.set('saving', false);
});
},
@@ -147,8 +163,14 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
// success
self.send('closeModal');
Discourse.URL.redirectTo("/categories");
}, function(jqXHR){
// error
}, function(error){
if (error && error.responseText) {
self.flash($.parseJSON(error.responseText).errors[0]);
} else {
self.flash(I18n.t('generic_error'));
}
self.send('showModal');
self.displayErrors([I18n.t("category.delete_error")]);
self.set('deleting', false);
@@ -58,7 +58,8 @@ Discourse.Category = Discourse.Model.extend({
secure: this.get('secure'),
permissions: this.get('permissionsForUpdate'),
auto_close_days: this.get('auto_close_days'),
position: this.get('position')
position: this.get('position'),
parent_category_id: this.get('parent_category_id')
},
type: this.get('id') ? 'PUT' : 'POST'
});
@@ -21,6 +21,11 @@
{{textField value=name placeholderKey="category.name_placeholder" maxlength="50"}}
</section>
<section class='field'>
<label>{{i18n category.parent}}</label>
{{categoryChooser valueAttribute="id" value=parent_category_id categories=parentCategories}}
</section>
{{#unless isUncategorized}}
<section class='field'>
<label>{{i18n category.description}}</label>
@@ -12,14 +12,16 @@ Discourse.CategoryChooserView = Discourse.ComboboxView.extend({
dataAttributes: ['name', 'color', 'text_color', 'description_text', 'topic_count'],
valueBinding: Ember.Binding.oneWay('source'),
content: Em.computed.filter('categories', function(c) {
var uncategorized_id = Discourse.Site.currentProp("uncategorized_category_id");
return c.get('permission') === Discourse.PermissionType.FULL && c.get('id') !== uncategorized_id;
}),
init: function() {
this._super();
// TODO perhaps allow passing a param in to select if we need full or not
var uncategorized_id = Discourse.Site.currentProp("uncategorized_category_id");
this.set('content', _.filter(Discourse.Category.list(), function(c){
return c.permission === Discourse.PermissionType.FULL && c.id !== uncategorized_id;
}));
if (!this.get('categories')) {
this.set('categories', Discourse.Category.list());
}
},
none: function() {
@@ -27,12 +27,6 @@ Discourse.ModalBodyView = Discourse.View.extend({
}
},
// Pass the errors to our errors view
displayErrors: function(errors, callback) {
this.set('parentView.parentView.modalErrorsView.errors', errors);
if (typeof callback === "function") callback();
},
flashMessageChanged: function() {
var flashMessage = this.get('controller.flashMessage');
if (flashMessage) {