Add ability to edit the uncategorized category name, color, and text_color in a modal
This commit is contained in:
parent
74a238b7e9
commit
c6370a3479
|
@ -98,6 +98,13 @@ Discourse.SiteSetting.reopenClass({
|
|||
result.set('diags', settings.diags);
|
||||
});
|
||||
return result;
|
||||
},
|
||||
|
||||
update: function(key, value) {
|
||||
return Discourse.ajax(Discourse.getURL("/admin/site_settings/") + key, {
|
||||
type: 'PUT',
|
||||
data: { value: value }
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -20,6 +20,10 @@ 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')) {
|
||||
|
|
|
@ -8,25 +8,26 @@
|
|||
{{view Discourse.TextField valueBinding="name" placeholderKey="category.name_placeholder" maxlength="50"}}
|
||||
</section>
|
||||
|
||||
<section class='field'>
|
||||
<label>{{i18n category.description}}</label>
|
||||
{{#unless isUncategorized}}
|
||||
<section class='field'>
|
||||
<label>{{i18n category.description}}</label>
|
||||
|
||||
{{#if description}}
|
||||
{{description}}
|
||||
{{else}}
|
||||
{{i18n category.no_description}}
|
||||
{{/if}}
|
||||
{{#if topic_url}}
|
||||
<br/>
|
||||
<button class="btn btn-small" {{action showCategoryTopic target="view"}}>{{i18n category.change_in_category_topic}}</button>
|
||||
{{/if}}
|
||||
</section>
|
||||
|
||||
<section class='field'>
|
||||
<label>{{i18n category.hotness}}</label>
|
||||
{{view Discourse.HotnessView hotnessBinding="hotness"}}
|
||||
</section>
|
||||
{{#if description}}
|
||||
{{description}}
|
||||
{{else}}
|
||||
{{i18n category.no_description}}
|
||||
{{/if}}
|
||||
{{#if topic_url}}
|
||||
<br/>
|
||||
<button class="btn btn-small" {{action showCategoryTopic target="view"}}>{{i18n category.change_in_category_topic}}</button>
|
||||
{{/if}}
|
||||
</section>
|
||||
|
||||
<section class='field'>
|
||||
<label>{{i18n category.hotness}}</label>
|
||||
{{view Discourse.HotnessView hotnessBinding="hotness"}}
|
||||
</section>
|
||||
{{/unless}}
|
||||
|
||||
<section class='field'>
|
||||
<label>{{i18n category.badge_colors}}</label>
|
||||
|
|
|
@ -47,6 +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");
|
||||
return Em.String.i18n("category.create");
|
||||
}.property('category.id'),
|
||||
|
||||
|
@ -57,6 +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");
|
||||
return (this.get('category.id') ? Em.String.i18n("category.save") : Em.String.i18n("category.create"));
|
||||
}.property('saving', 'category.id'),
|
||||
|
||||
|
@ -78,6 +80,8 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||
categoryView.set('id', categoryView.get('category.slug'));
|
||||
categoryView.set('loading', false);
|
||||
});
|
||||
} else if( this.get('category.isUncategorized') ) {
|
||||
this.set('category', this.get('category'));
|
||||
} else {
|
||||
this.set('category', Discourse.Category.create({ color: 'AB9364', text_color: 'FFFFFF', hotness: 5 }));
|
||||
}
|
||||
|
@ -92,17 +96,35 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||
saveCategory: function() {
|
||||
var categoryView = this;
|
||||
this.set('saving', true);
|
||||
this.get('category').save().then(function(result) {
|
||||
// success
|
||||
$('#discourse-modal').modal('hide');
|
||||
var url = Discourse.getURL("/category/") + (Discourse.Utilities.categoryUrlId(result.category));
|
||||
Discourse.URL.redirectTo(url);
|
||||
}, function(errors) {
|
||||
// errors
|
||||
if(errors.length === 0) errors.push(Em.String.i18n("category.creation_error"));
|
||||
categoryView.displayErrors(errors);
|
||||
categoryView.set('saving', false);
|
||||
});
|
||||
if( this.get('category.isUncategorized') ) {
|
||||
$.when(
|
||||
Discourse.SiteSetting.update('uncategorized_color', this.get('category.color')),
|
||||
Discourse.SiteSetting.update('uncategorized_text_color', this.get('category.text_color')),
|
||||
Discourse.SiteSetting.update('uncategorized_name', this.get('category.name'))
|
||||
).then(function() {
|
||||
// success
|
||||
$('#discourse-modal').modal('hide');
|
||||
var url = Discourse.getURL("/category/") + categoryView.get('category.name');
|
||||
Discourse.URL.redirectTo(url);
|
||||
}, function(errors) {
|
||||
// errors
|
||||
if(errors.length === 0) errors.push(Em.String.i18n("category.save_error"));
|
||||
categoryView.displayErrors(errors);
|
||||
categoryView.set('saving', false);
|
||||
});
|
||||
} else {
|
||||
this.get('category').save().then(function(result) {
|
||||
// success
|
||||
$('#discourse-modal').modal('hide');
|
||||
var url = Discourse.getURL("/category/") + (Discourse.Utilities.categoryUrlId(result.category));
|
||||
Discourse.URL.redirectTo(url);
|
||||
}, function(errors) {
|
||||
// errors
|
||||
if(errors.length === 0) errors.push(Em.String.i18n("category.creation_error"));
|
||||
categoryView.displayErrors(errors);
|
||||
categoryView.set('saving', false);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
deleteCategory: function() {
|
||||
|
|
|
@ -32,6 +32,8 @@ class CategoryList
|
|||
|
||||
uncategorized = Category.new({name: SiteSetting.uncategorized_name,
|
||||
slug: Slug.for(SiteSetting.uncategorized_name),
|
||||
color: SiteSetting.uncategorized_color,
|
||||
text_color: SiteSetting.uncategorized_text_color,
|
||||
featured_topics: uncategorized_topics}.merge(totals))
|
||||
|
||||
# Find the appropriate place to insert it:
|
||||
|
|
|
@ -86,6 +86,8 @@ class SiteSetting < ActiveRecord::Base
|
|||
setting(:newuser_max_mentions_per_post, 2)
|
||||
|
||||
setting(:uncategorized_name, 'uncategorized')
|
||||
setting(:uncategorized_color, 'AB9364');
|
||||
setting(:uncategorized_text_color, 'FFFFFF');
|
||||
|
||||
setting(:unique_posts_mins, Rails.env.test? ? 0 : 5)
|
||||
|
||||
|
|
|
@ -735,11 +735,13 @@ en:
|
|||
none: '(no category)'
|
||||
edit: 'edit'
|
||||
edit_long: "Edit Category"
|
||||
edit_uncategorized: "Edit Uncategorized"
|
||||
view: 'View Topics in Category'
|
||||
delete: 'Delete Category'
|
||||
create: 'Create Category'
|
||||
save: 'Save Category'
|
||||
creation_error: There has been an error during the creation of the category.
|
||||
save_error: There was an error saving the category.
|
||||
more_posts: "view all {{posts}}..."
|
||||
name: "Category Name"
|
||||
description: "Description"
|
||||
|
|
|
@ -497,6 +497,8 @@ en:
|
|||
previous_visit_timeout_hours: "How long a visit lasts before we consider it the 'previous' visit, in hours"
|
||||
|
||||
uncategorized_name: "The default category for topics that have no category in the /categories page"
|
||||
uncategorized_color: "The background color of the badge for the category with topics that have no category"
|
||||
uncategorized_text_color: "The text color of the badge for the category with topics that have no category"
|
||||
|
||||
rate_limit_create_topic: "How many seconds, after creating a topic, before you can create another topic"
|
||||
rate_limit_create_post: "How many seconds, after creating a post, before you can create another post"
|
||||
|
|
Loading…
Reference in New Issue