displays a message when a failure happen while creating a new category

This commit is contained in:
Régis Hanol 2013-03-14 22:25:55 +01:00
parent 4f42110e39
commit 3bf6625aa4
5 changed files with 13 additions and 6 deletions

View File

@ -1,7 +1,7 @@
<div class="modal-body">
<div class="modal-body">
<form>
<label>{{i18n category.name}}</label>
{{view Discourse.TextField valueBinding="view.category.name" placeholderKey="category.name_placeholder"}}
{{view Discourse.TextField valueBinding="view.category.name" placeholderKey="category.name_placeholder" maxlength="50"}}
<div class='description-controls' style="margin-bottom: 20px">
<label>{{i18n category.description}}</label>
@ -12,7 +12,7 @@
<a href="#" {{action showCategoryTopic target="view"}}>{{i18n category.change_in_category_topic}}</a>
{{/if}}
{{else}}
{{i18n category.no_description}}
{{i18n category.no_description}}
{{#if view.category.topic_url}}
<a {{action showCategoryTopic target="view"}} href="#">{{i18n category.change_in_category_topic}}</a>
{{/if}}}
@ -31,4 +31,4 @@
</div>
<div class="modal-footer">
<button class='btn btn-primary' {{bindAttr disabled="view.disabled"}} {{action saveCategory target="view"}}>{{view.buttonTitle}}</button>
</div>
</div>

View File

@ -59,7 +59,12 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
_this.saveSuccess(result);
},
error: function(errors) {
// displays a generic error message when none is sent from the server
// this might happen when some "after" callbacks throws an exception server-side
if(errors.length === 0) errors.push(Em.String.i18n("category.creation_error"));
// display the errors
_this.displayErrors(errors);
// not saving anymore
_this.set('saving', false);
}
});

View File

@ -14,7 +14,7 @@ class Category < ActiveRecord::Base
has_many :featured_users, through: :category_featured_users, source: :user
validates :user_id, presence: true
validates :name, presence: true, uniqueness: true
validates :name, presence: true, uniqueness: true, length: { in: 1..50 }
validate :uncategorized_validator
before_save :ensure_slug
@ -27,7 +27,7 @@ class Category < ActiveRecord::Base
delegate :post_template, to: 'self.class'
def create_category_definition
create_topic(title: I18n.t("category.topic_prefix", category: name), user: user, pinned_at: Time.now)
create_topic!(title: I18n.t("category.topic_prefix", category: name), user: user, pinned_at: Time.now)
update_column(:topic_id, topic.id)
topic.update_column(:category_id, id)
topic.posts.create(raw: post_template, user: user)

View File

@ -583,6 +583,7 @@ en:
view: 'View Topics in Category'
delete: 'Delete Category'
create: 'Create Category'
creation_error: There has been an error during the creation of the category.
more_posts: "view all {{posts}}..."
name: "Category Name"
description: "Description"

View File

@ -587,6 +587,7 @@ fr:
view: 'Voir les discussions dans cette catégorie'
delete: 'Supprimer la catégorie'
create: 'Créer la catégorie'
creation_error: "Il y a eu une erreur lors de la création de la catégorie."
more_posts: "voir tous les {{posts}}..."
name: "Nom de la catégorie"
description: "Description"