mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 02:05:49 +08:00
Refactor: move category slug helper to Category model
This commit is contained in:
@ -29,14 +29,6 @@ Discourse.Utilities = {
|
||||
}
|
||||
},
|
||||
|
||||
categoryUrlId: function(category) {
|
||||
if (!category) return "";
|
||||
var id = Em.get(category, 'id');
|
||||
var slug = Em.get(category, 'slug');
|
||||
if ((!slug) || slug.isBlank()) return "" + id + "-category";
|
||||
return slug;
|
||||
},
|
||||
|
||||
// Create a badge like category link
|
||||
categoryLink: function(category) {
|
||||
if (!category) return "";
|
||||
@ -47,7 +39,7 @@ Discourse.Utilities = {
|
||||
var description = Em.get(category, 'description');
|
||||
|
||||
// Build the HTML link
|
||||
var result = "<a href=\"" + Discourse.getURL("/category/") + this.categoryUrlId(category) + "\" class=\"badge-category\" ";
|
||||
var result = "<a href=\"" + Discourse.getURL("/category/") + Discourse.Category.slugFor(category) + "\" class=\"badge-category\" ";
|
||||
|
||||
// Add description if we have it
|
||||
if (description) result += "title=\"" + Handlebars.Utils.escapeExpression(description) + "\" ";
|
||||
|
@ -82,6 +82,14 @@ Discourse.Category.reopenClass({
|
||||
return this.uncategorized;
|
||||
},
|
||||
|
||||
slugFor: function(category) {
|
||||
if (!category) return "";
|
||||
var id = Em.get(category, 'id');
|
||||
var slug = Em.get(category, 'slug');
|
||||
if ((!slug) || slug.isBlank()) return "" + id + "-category";
|
||||
return slug;
|
||||
},
|
||||
|
||||
list: function() {
|
||||
return Discourse.Site.instance().get('categories');
|
||||
},
|
||||
|
@ -36,7 +36,7 @@ Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({
|
||||
}
|
||||
|
||||
var listController = this.controllerFor('list');
|
||||
var urlId = Discourse.Utilities.categoryUrlId(category);
|
||||
var urlId = Discourse.Category.slugFor(category);
|
||||
listController.set('filterMode', "category/" + urlId);
|
||||
|
||||
var router = this;
|
||||
|
@ -152,7 +152,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
||||
this.get('category').save().then(function(result) {
|
||||
// success
|
||||
$('#discourse-modal').modal('hide');
|
||||
Discourse.URL.redirectTo("/category/" + Discourse.Utilities.categoryUrlId(result.category));
|
||||
Discourse.URL.redirectTo("/category/" + Discourse.Category.slugFor(result.category));
|
||||
}, function(errors) {
|
||||
// errors
|
||||
if(errors.length === 0) errors.push(Em.String.i18n("category.creation_error"));
|
||||
|
Reference in New Issue
Block a user