From 5b33992604a852c189fb07a25e14a9a21bcfd288 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Fri, 3 May 2013 18:26:49 -0400 Subject: [PATCH] Fix a case when editing uncategorized all the hidden form controls become visible --- app/assets/javascripts/discourse/models/category.js | 9 +++++---- .../templates/modal/edit_category.js.handlebars | 2 +- .../discourse/views/modal/edit_category_view.js | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/discourse/models/category.js b/app/assets/javascripts/discourse/models/category.js index f99f8058a3d..2b3f14ca763 100644 --- a/app/assets/javascripts/discourse/models/category.js +++ b/app/assets/javascripts/discourse/models/category.js @@ -8,6 +8,11 @@ **/ Discourse.Category = Discourse.Model.extend({ + init: function() { + this._super(); + if (!this.get('id') && this.get('name')) this.set('is_uncategorized', true); + }, + url: function() { return Discourse.getURL("/category/") + (this.get('slug')); }.property('name'), @@ -20,10 +25,6 @@ Discourse.Category = Discourse.Model.extend({ return this.get('topic_count') > Discourse.SiteSettings.category_featured_topics; }.property('topic_count'), - isUncategorized: function() { - return (!this.get('id') && this.get('name')); - }.property('id', 'name'), - save: function(args) { var url = Discourse.getURL("/categories"); if (this.get('id')) { diff --git a/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars b/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars index c86e26649aa..b927eca690e 100644 --- a/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars @@ -8,7 +8,7 @@ {{view Discourse.TextField valueBinding="name" placeholderKey="category.name_placeholder" maxlength="50"}} - {{#unless isUncategorized}} + {{#unless is_uncategorized}}
diff --git a/app/assets/javascripts/discourse/views/modal/edit_category_view.js b/app/assets/javascripts/discourse/views/modal/edit_category_view.js index 257429be72c..32ec4f98a38 100644 --- a/app/assets/javascripts/discourse/views/modal/edit_category_view.js +++ b/app/assets/javascripts/discourse/views/modal/edit_category_view.js @@ -47,7 +47,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({ title: function() { if (this.get('category.id')) return Em.String.i18n("category.edit_long"); - if (this.get('category.isUncategorized')) return Em.String.i18n("category.edit_uncategorized"); + if (this.get('category.is_uncategorized')) return Em.String.i18n("category.edit_uncategorized"); return Em.String.i18n("category.create"); }.property('category.id'), @@ -58,7 +58,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({ buttonTitle: function() { if (this.get('saving')) return Em.String.i18n("saving"); - if (this.get('category.isUncategorized')) return Em.String.i18n("save"); + if (this.get('category.is_uncategorized')) return Em.String.i18n("save"); return (this.get('category.id') ? Em.String.i18n("category.save") : Em.String.i18n("category.create")); }.property('saving', 'category.id'), @@ -80,7 +80,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({ categoryView.set('id', categoryView.get('category.slug')); categoryView.set('loading', false); }); - } else if( this.get('category.isUncategorized') ) { + } else if( this.get('category.is_uncategorized') ) { this.set('category', this.get('category')); } else { this.set('category', Discourse.Category.create({ color: 'AB9364', text_color: 'FFFFFF', hotness: 5 })); @@ -96,7 +96,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({ saveCategory: function() { var categoryView = this; this.set('saving', true); - if( this.get('category.isUncategorized') ) { + if( this.get('category.is_uncategorized') ) { $.when( Discourse.SiteSetting.update('uncategorized_color', this.get('category.color')), Discourse.SiteSetting.update('uncategorized_text_color', this.get('category.text_color')),