mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 10:58:48 +08:00
Add ability to edit the uncategorized category name, color, and text_color in a modal
This commit is contained in:
@ -98,6 +98,13 @@ Discourse.SiteSetting.reopenClass({
|
|||||||
result.set('diags', settings.diags);
|
result.set('diags', settings.diags);
|
||||||
});
|
});
|
||||||
return result;
|
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;
|
return this.get('topic_count') > Discourse.SiteSettings.category_featured_topics;
|
||||||
}.property('topic_count'),
|
}.property('topic_count'),
|
||||||
|
|
||||||
|
isUncategorized: function() {
|
||||||
|
return (!this.get('id') && this.get('name'));
|
||||||
|
}.property('id', 'name'),
|
||||||
|
|
||||||
save: function(args) {
|
save: function(args) {
|
||||||
var url = Discourse.getURL("/categories");
|
var url = Discourse.getURL("/categories");
|
||||||
if (this.get('id')) {
|
if (this.get('id')) {
|
||||||
|
@ -8,25 +8,26 @@
|
|||||||
{{view Discourse.TextField valueBinding="name" placeholderKey="category.name_placeholder" maxlength="50"}}
|
{{view Discourse.TextField valueBinding="name" placeholderKey="category.name_placeholder" maxlength="50"}}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class='field'>
|
{{#unless isUncategorized}}
|
||||||
<label>{{i18n category.description}}</label>
|
<section class='field'>
|
||||||
|
<label>{{i18n category.description}}</label>
|
||||||
|
|
||||||
{{#if description}}
|
{{#if description}}
|
||||||
{{description}}
|
{{description}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{i18n category.no_description}}
|
{{i18n category.no_description}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if topic_url}}
|
{{#if topic_url}}
|
||||||
<br/>
|
<br/>
|
||||||
<button class="btn btn-small" {{action showCategoryTopic target="view"}}>{{i18n category.change_in_category_topic}}</button>
|
<button class="btn btn-small" {{action showCategoryTopic target="view"}}>{{i18n category.change_in_category_topic}}</button>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class='field'>
|
|
||||||
<label>{{i18n category.hotness}}</label>
|
|
||||||
{{view Discourse.HotnessView hotnessBinding="hotness"}}
|
|
||||||
</section>
|
|
||||||
|
|
||||||
|
<section class='field'>
|
||||||
|
<label>{{i18n category.hotness}}</label>
|
||||||
|
{{view Discourse.HotnessView hotnessBinding="hotness"}}
|
||||||
|
</section>
|
||||||
|
{{/unless}}
|
||||||
|
|
||||||
<section class='field'>
|
<section class='field'>
|
||||||
<label>{{i18n category.badge_colors}}</label>
|
<label>{{i18n category.badge_colors}}</label>
|
||||||
|
@ -47,6 +47,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||||||
|
|
||||||
title: function() {
|
title: function() {
|
||||||
if (this.get('category.id')) return Em.String.i18n("category.edit_long");
|
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");
|
return Em.String.i18n("category.create");
|
||||||
}.property('category.id'),
|
}.property('category.id'),
|
||||||
|
|
||||||
@ -57,6 +58,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||||||
|
|
||||||
buttonTitle: function() {
|
buttonTitle: function() {
|
||||||
if (this.get('saving')) return Em.String.i18n("saving");
|
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"));
|
return (this.get('category.id') ? Em.String.i18n("category.save") : Em.String.i18n("category.create"));
|
||||||
}.property('saving', 'category.id'),
|
}.property('saving', 'category.id'),
|
||||||
|
|
||||||
@ -78,6 +80,8 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||||||
categoryView.set('id', categoryView.get('category.slug'));
|
categoryView.set('id', categoryView.get('category.slug'));
|
||||||
categoryView.set('loading', false);
|
categoryView.set('loading', false);
|
||||||
});
|
});
|
||||||
|
} else if( this.get('category.isUncategorized') ) {
|
||||||
|
this.set('category', this.get('category'));
|
||||||
} else {
|
} else {
|
||||||
this.set('category', Discourse.Category.create({ color: 'AB9364', text_color: 'FFFFFF', hotness: 5 }));
|
this.set('category', Discourse.Category.create({ color: 'AB9364', text_color: 'FFFFFF', hotness: 5 }));
|
||||||
}
|
}
|
||||||
@ -92,17 +96,35 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||||||
saveCategory: function() {
|
saveCategory: function() {
|
||||||
var categoryView = this;
|
var categoryView = this;
|
||||||
this.set('saving', true);
|
this.set('saving', true);
|
||||||
this.get('category').save().then(function(result) {
|
if( this.get('category.isUncategorized') ) {
|
||||||
// success
|
$.when(
|
||||||
$('#discourse-modal').modal('hide');
|
Discourse.SiteSetting.update('uncategorized_color', this.get('category.color')),
|
||||||
var url = Discourse.getURL("/category/") + (Discourse.Utilities.categoryUrlId(result.category));
|
Discourse.SiteSetting.update('uncategorized_text_color', this.get('category.text_color')),
|
||||||
Discourse.URL.redirectTo(url);
|
Discourse.SiteSetting.update('uncategorized_name', this.get('category.name'))
|
||||||
}, function(errors) {
|
).then(function() {
|
||||||
// errors
|
// success
|
||||||
if(errors.length === 0) errors.push(Em.String.i18n("category.creation_error"));
|
$('#discourse-modal').modal('hide');
|
||||||
categoryView.displayErrors(errors);
|
var url = Discourse.getURL("/category/") + categoryView.get('category.name');
|
||||||
categoryView.set('saving', false);
|
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() {
|
deleteCategory: function() {
|
||||||
|
@ -32,6 +32,8 @@ class CategoryList
|
|||||||
|
|
||||||
uncategorized = Category.new({name: SiteSetting.uncategorized_name,
|
uncategorized = Category.new({name: SiteSetting.uncategorized_name,
|
||||||
slug: Slug.for(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))
|
featured_topics: uncategorized_topics}.merge(totals))
|
||||||
|
|
||||||
# Find the appropriate place to insert it:
|
# Find the appropriate place to insert it:
|
||||||
|
@ -86,6 +86,8 @@ class SiteSetting < ActiveRecord::Base
|
|||||||
setting(:newuser_max_mentions_per_post, 2)
|
setting(:newuser_max_mentions_per_post, 2)
|
||||||
|
|
||||||
setting(:uncategorized_name, 'uncategorized')
|
setting(:uncategorized_name, 'uncategorized')
|
||||||
|
setting(:uncategorized_color, 'AB9364');
|
||||||
|
setting(:uncategorized_text_color, 'FFFFFF');
|
||||||
|
|
||||||
setting(:unique_posts_mins, Rails.env.test? ? 0 : 5)
|
setting(:unique_posts_mins, Rails.env.test? ? 0 : 5)
|
||||||
|
|
||||||
|
@ -735,11 +735,13 @@ en:
|
|||||||
none: '(no category)'
|
none: '(no category)'
|
||||||
edit: 'edit'
|
edit: 'edit'
|
||||||
edit_long: "Edit Category"
|
edit_long: "Edit Category"
|
||||||
|
edit_uncategorized: "Edit Uncategorized"
|
||||||
view: 'View Topics in Category'
|
view: 'View Topics in Category'
|
||||||
delete: 'Delete Category'
|
delete: 'Delete Category'
|
||||||
create: 'Create Category'
|
create: 'Create Category'
|
||||||
save: 'Save Category'
|
save: 'Save Category'
|
||||||
creation_error: There has been an error during the creation of the 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}}..."
|
more_posts: "view all {{posts}}..."
|
||||||
name: "Category Name"
|
name: "Category Name"
|
||||||
description: "Description"
|
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"
|
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_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_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"
|
rate_limit_create_post: "How many seconds, after creating a post, before you can create another post"
|
||||||
|
Reference in New Issue
Block a user