2013-02-22 15:41:12 -05:00
|
|
|
/**
|
|
|
|
A data model that represents a category
|
|
|
|
|
|
|
|
@class Category
|
|
|
|
@extends Discourse.Model
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
|
|
|
**/
|
|
|
|
Discourse.Category = Discourse.Model.extend({
|
|
|
|
|
|
|
|
url: (function() {
|
2013-03-14 08:01:52 -04:00
|
|
|
return Discourse.getURL("/category/") + (this.get('slug'));
|
2013-02-22 15:41:12 -05:00
|
|
|
}).property('name'),
|
|
|
|
|
|
|
|
style: (function() {
|
2013-03-14 09:16:57 -04:00
|
|
|
return "background-color: #" + (this.get('category.color')) + "; color: #" + (this.get('category.text_color')) + ";";
|
|
|
|
}).property('color', 'text_color'),
|
2013-02-22 15:41:12 -05:00
|
|
|
|
|
|
|
moreTopics: (function() {
|
|
|
|
return this.get('topic_count') > Discourse.SiteSettings.category_featured_topics;
|
|
|
|
}).property('topic_count'),
|
|
|
|
|
|
|
|
save: function(args) {
|
2013-03-21 15:10:34 -04:00
|
|
|
var url = Discourse.getURL("/categories");
|
2013-02-22 15:41:12 -05:00
|
|
|
if (this.get('id')) {
|
2013-03-14 08:01:52 -04:00
|
|
|
url = Discourse.getURL("/categories/") + (this.get('id'));
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
return this.ajax(url, {
|
|
|
|
data: {
|
|
|
|
name: this.get('name'),
|
2013-03-14 09:16:57 -04:00
|
|
|
color: this.get('color'),
|
|
|
|
text_color: this.get('text_color')
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
type: this.get('id') ? 'PUT' : 'POST',
|
|
|
|
success: function(result) { return args.success(result); },
|
|
|
|
error: function(errors) { return args.error(errors); }
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-03-21 15:10:34 -04:00
|
|
|
destroy: function(callback) {
|
|
|
|
return $.ajax(Discourse.getURL("/categories/") + (this.get('slug')), { type: 'DELETE' });
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|