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> <form>
<label>{{i18n category.name}}</label> <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"> <div class='description-controls' style="margin-bottom: 20px">
<label>{{i18n category.description}}</label> <label>{{i18n category.description}}</label>

View File

@ -59,7 +59,12 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
_this.saveSuccess(result); _this.saveSuccess(result);
}, },
error: function(errors) { 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); _this.displayErrors(errors);
// not saving anymore
_this.set('saving', false); _this.set('saving', false);
} }
}); });

View File

@ -14,7 +14,7 @@ class Category < ActiveRecord::Base
has_many :featured_users, through: :category_featured_users, source: :user has_many :featured_users, through: :category_featured_users, source: :user
validates :user_id, presence: true validates :user_id, presence: true
validates :name, presence: true, uniqueness: true validates :name, presence: true, uniqueness: true, length: { in: 1..50 }
validate :uncategorized_validator validate :uncategorized_validator
before_save :ensure_slug before_save :ensure_slug
@ -27,7 +27,7 @@ class Category < ActiveRecord::Base
delegate :post_template, to: 'self.class' delegate :post_template, to: 'self.class'
def create_category_definition 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) update_column(:topic_id, topic.id)
topic.update_column(:category_id, id) topic.update_column(:category_id, id)
topic.posts.create(raw: post_template, user: user) topic.posts.create(raw: post_template, user: user)

View File

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

View File

@ -587,6 +587,7 @@ fr:
view: 'Voir les discussions dans cette catégorie' view: 'Voir les discussions dans cette catégorie'
delete: 'Supprimer la catégorie' delete: 'Supprimer la catégorie'
create: 'Créer 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}}..." more_posts: "voir tous les {{posts}}..."
name: "Nom de la catégorie" name: "Nom de la catégorie"
description: "Description" description: "Description"