From 0362c50698902586b939dc93b7c11c304c76fdd1 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 15 May 2015 11:03:27 -0400 Subject: [PATCH] Remove deprecations from edit-category and add skeleton acceptance test --- .../discourse/components/color-picker.js.es6 | 2 +- .../controllers/edit-category.js.es6 | 86 ++++++++++--------- .../templates/modal/edit-category-general.hbs | 20 ++--- .../templates/modal/edit-category-images.hbs | 4 +- .../modal/edit-category-security.hbs | 2 +- .../modal/edit-category-settings.hbs | 6 +- .../templates/modal/edit-category.hbs | 8 +- .../templates/navigation/category.hbs | 2 +- .../acceptance/category-edit-test.js.es6 | 17 ++++ .../fixtures/category-fixtures.js.es6 | 3 + .../javascripts/fixtures/site_fixtures.js.es6 | 2 +- 11 files changed, 89 insertions(+), 63 deletions(-) create mode 100644 test/javascripts/acceptance/category-edit-test.js.es6 create mode 100644 test/javascripts/fixtures/category-fixtures.js.es6 diff --git a/app/assets/javascripts/discourse/components/color-picker.js.es6 b/app/assets/javascripts/discourse/components/color-picker.js.es6 index 519bf2aa9..d1acf7d81 100644 --- a/app/assets/javascripts/discourse/components/color-picker.js.es6 +++ b/app/assets/javascripts/discourse/components/color-picker.js.es6 @@ -17,7 +17,7 @@ export default DiscourseContainerView.extend({ tagName: 'button', attributeBindings: ['style', 'title'], classNames: ['colorpicker'].concat( isUsed ? ['used-color'] : ['unused-color'] ), - style: 'background-color: #' + color + ';', + style: ('background-color: #' + color + ';').htmlSafe(), title: isUsed ? I18n.t("category.already_used") : null, click: function() { self.set("value", color); diff --git a/app/assets/javascripts/discourse/controllers/edit-category.js.es6 b/app/assets/javascripts/discourse/controllers/edit-category.js.es6 index 09f6d0655..e667d447d 100644 --- a/app/assets/javascripts/discourse/controllers/edit-category.js.es6 +++ b/app/assets/javascripts/discourse/controllers/edit-category.js.es6 @@ -6,6 +6,10 @@ import { categoryBadgeHTML } from 'discourse/helpers/category-link'; export default ObjectController.extend(ModalFunctionality, { foregroundColors: ['FFFFFF', '000000'], categoryUploadUrl: '/category/uploads', + editingPermissions: false, + selectedTab: null, + saving: false, + deleting: false, parentCategories: function() { return Discourse.Category.list().filter(function (c) { @@ -15,31 +19,31 @@ export default ObjectController.extend(ModalFunctionality, { // We can change the parent if there are no children subCategories: function() { - if (Em.isEmpty(this.get('id'))) { return null; } - return Discourse.Category.list().filterBy('parent_category_id', this.get('id')); + if (Em.isEmpty(this.get('model.id'))) { return null; } + return Discourse.Category.list().filterBy('parent_category_id', this.get('model.id')); }.property('model.id'), - canSelectParentCategory: Em.computed.not('isUncategorizedCategory'), + canSelectParentCategory: Em.computed.not('model.isUncategorizedCategory'), - onShow: function() { + onShow() { this.changeSize(); this.titleChanged(); }, changeSize: function() { - if (this.present('description')) { + if (this.present('model.description')) { this.set('controllers.modal.modalClass', 'edit-category-modal full'); } else { this.set('controllers.modal.modalClass', 'edit-category-modal small'); } - }.observes('description'), + }.observes('model.description'), title: function() { - if (this.get('id')) { + if (this.get('model.id')) { return I18n.t("category.edit_long") + " : " + this.get('model.name'); } return I18n.t("category.create") + (this.get('model.name') ? (" : " + this.get('model.name')) : ''); - }.property('id', 'model.name'), + }.property('model.id', 'model.name'), titleChanged: function() { this.set('controllers.modal.title', this.get('title')); @@ -47,10 +51,10 @@ export default ObjectController.extend(ModalFunctionality, { disabled: function() { if (this.get('saving') || this.get('deleting')) return true; - if (!this.get('name')) return true; - if (!this.get('color')) return true; + if (!this.get('model.name')) return true; + if (!this.get('model.color')) return true; return false; - }.property('saving', 'name', 'color', 'deleting'), + }.property('saving', 'model.name', 'model.color', 'deleting'), emailInEnabled: Discourse.computed.setting('email_in'), @@ -59,80 +63,82 @@ export default ObjectController.extend(ModalFunctionality, { }.property('disabled', 'saving', 'deleting'), colorStyle: function() { - return "background-color: #" + (this.get('color')) + "; color: #" + (this.get('text_color')) + ";"; - }.property('color', 'text_color'), + return "background-color: #" + this.get('model.color') + "; color: #" + this.get('model.text_color') + ";"; + }.property('model.color', 'model.text_color'), categoryBadgePreview: function() { - var c = Discourse.Category.create({ - name: this.get('categoryName'), - color: this.get('color'), - text_color: this.get('text_color'), - parent_category_id: parseInt(this.get('parent_category_id'),10), - read_restricted: this.get('model.read_restricted') + const model = this.get('model'); + const c = Discourse.Category.create({ + name: model.get('categoryName'), + color: model.get('color'), + text_color: model.get('text_color'), + parent_category_id: parseInt(model.get('parent_category_id'),10), + read_restricted: model.get('read_restricted') }); return categoryBadgeHTML(c, {link: false}); - }.property('parent_category_id', 'categoryName', 'color', 'text_color'), + }.property('model.parent_category_id', 'model.categoryName', 'model.color', 'model.text_color'), // background colors are available as a pipe-separated string backgroundColors: function() { - var categories = Discourse.Category.list(); + const categories = Discourse.Category.list(); return Discourse.SiteSettings.category_colors.split("|").map(function(i) { return i.toUpperCase(); }).concat( categories.map(function(c) { return c.color.toUpperCase(); }) ).uniq(); }.property('Discourse.SiteSettings.category_colors'), usedBackgroundColors: function() { - var categories = Discourse.Category.list(); + const categories = Discourse.Category.list(); - var currentCat = this.get('model'); + const currentCat = this.get('model'); return categories.map(function(c) { // If editing a category, don't include its color: return (currentCat.get('id') && currentCat.get('color').toUpperCase() === c.color.toUpperCase()) ? null : c.color.toUpperCase(); }, this).compact(); - }.property('id', 'color'), + }.property('model.id', 'model.color'), categoryName: function() { - var name = this.get('name') || ""; + const name = this.get('name') || ""; return name.trim().length > 0 ? name : I18n.t("preview"); }.property('name'), buttonTitle: function() { if (this.get('saving')) return I18n.t("saving"); - if (this.get('isUncategorizedCategory')) return I18n.t("save"); - return (this.get('id') ? I18n.t("category.save") : I18n.t("category.create")); - }.property('saving', 'id'), + if (this.get('model.isUncategorizedCategory')) return I18n.t("save"); + return (this.get('model.id') ? I18n.t("category.save") : I18n.t("category.create")); + }.property('saving', 'model.id'), deleteButtonTitle: function() { return I18n.t('category.delete'); }.property(), showDescription: function() { - return !this.get('isUncategorizedCategory') && this.get('id'); - }.property('isUncategorizedCategory', 'id'), + return !this.get('model.isUncategorizedCategory') && this.get('model.id'); + }.property('model.isUncategorizedCategory', 'model.id'), showPositionInput: Discourse.computed.setting('fixed_category_positions'), actions: { - showCategoryTopic: function() { + showCategoryTopic() { this.send('closeModal'); - Discourse.URL.routeTo(this.get('topic_url')); + Discourse.URL.routeTo(this.get('model.topic_url')); return false; }, - editPermissions: function(){ + editPermissions() { this.set('editingPermissions', true); }, - addPermission: function(group, permission_id){ - this.get('model').addPermission({group_name: group + "", permission: Discourse.PermissionType.create({id: permission_id})}); + addPermission(group, id) { + this.get('model').addPermission({group_name: group + "", + permission: Discourse.PermissionType.create({id})}); }, - removePermission: function(permission){ + removePermission(permission) { this.get('model').removePermission(permission); }, - saveCategory: function() { - var self = this, + saveCategory() { + const self = this, model = this.get('model'), parentCategory = Discourse.Category.list().findBy('id', parseInt(model.get('parent_category_id'), 10)); @@ -155,8 +161,8 @@ export default ObjectController.extend(ModalFunctionality, { }); }, - deleteCategory: function() { - var self = this; + deleteCategory() { + const self = this; this.set('deleting', true); this.send('hideModal'); diff --git a/app/assets/javascripts/discourse/templates/modal/edit-category-general.hbs b/app/assets/javascripts/discourse/templates/modal/edit-category-general.hbs index 0ce793b70..e04fd2a76 100644 --- a/app/assets/javascripts/discourse/templates/modal/edit-category-general.hbs +++ b/app/assets/javascripts/discourse/templates/modal/edit-category-general.hbs @@ -2,11 +2,11 @@
- {{text-field value=name placeholderKey="category.name_placeholder" maxlength="50"}} + {{text-field value=model.name placeholderKey="category.name_placeholder" maxlength="50"}}
- {{text-field value=slug placeholderKey="category.slug_placeholder" maxlength="255"}} + {{text-field value=model.slug placeholderKey="category.slug_placeholder" maxlength="255"}}
@@ -19,7 +19,7 @@ {{/each}} {{else}} - {{category-chooser valueAttribute="id" value=parent_category_id categories=parentCategories rootNone=true}} + {{category-chooser valueAttribute="id" value=model.parent_category_id categories=parentCategories rootNone=true}} {{/if}} {{/if}} @@ -27,12 +27,12 @@ {{#if showDescription}}
- {{#if description}} - {{{description}}} + {{#if model.description}} + {{{model.description}}} {{else}} {{i18n 'category.no_description'}} {{/if}} - {{#if topic_url}} + {{#if model.topic_url}}
{{d-button class="btn-small" action="showCategoryTopic" icon="pencil" label="category.change_in_category_topic"}} {{/if}} @@ -46,14 +46,14 @@
{{i18n 'category.background_color'}}: - #{{text-field value=color placeholderKey="category.color_placeholder" maxlength="6"}} - {{color-picker colors=backgroundColors usedColors=usedBackgroundColors value=color}} + #{{text-field value=model.color placeholderKey="category.color_placeholder" maxlength="6"}} + {{color-picker colors=backgroundColors usedColors=usedBackgroundColors value=model.color}}
{{i18n 'category.foreground_color'}}: - #{{text-field value=text_color placeholderKey="category.color_placeholder" maxlength="6"}} - {{color-picker colors=foregroundColors value=text_color}} + #{{text-field value=model.text_color placeholderKey="category.color_placeholder" maxlength="6"}} + {{color-picker colors=foregroundColors value=model.text_color}}
diff --git a/app/assets/javascripts/discourse/templates/modal/edit-category-images.hbs b/app/assets/javascripts/discourse/templates/modal/edit-category-images.hbs index e1bacab39..e5f65a5b1 100644 --- a/app/assets/javascripts/discourse/templates/modal/edit-category-images.hbs +++ b/app/assets/javascripts/discourse/templates/modal/edit-category-images.hbs @@ -1,9 +1,9 @@
- {{image-uploader uploadUrl=categoryUploadUrl imageUrl=logo_url type="logo"}} + {{image-uploader uploadUrl=categoryUploadUrl imageUrl=model.logo_url type="logo"}}
- {{image-uploader uploadUrl=categoryUploadUrl imageUrl=background_url type="background"}} + {{image-uploader uploadUrl=categoryUploadUrl imageUrl=model.background_url type="background"}}
diff --git a/app/assets/javascripts/discourse/templates/modal/edit-category-security.hbs b/app/assets/javascripts/discourse/templates/modal/edit-category-security.hbs index ef70bd291..99c8a98a6 100644 --- a/app/assets/javascripts/discourse/templates/modal/edit-category-security.hbs +++ b/app/assets/javascripts/discourse/templates/modal/edit-category-security.hbs @@ -1,6 +1,6 @@