Can add topic templates to categories, prepopulated on compose

This commit is contained in:
Robin Ward 2015-07-02 16:18:59 -04:00
parent 84a1acb2ec
commit 7676c5dfe7
15 changed files with 86 additions and 7 deletions

View file

@ -0,0 +1,11 @@
const CategoryPanelBase = Ember.Component.extend({
classNameBindings: [':modal-tab', 'activeTab::invisible'],
});
export default CategoryPanelBase;
export function buildCategoryPanel(tab, extras) {
return CategoryPanelBase.extend({
activeTab: Ember.computed.equal('selectedTab', tab)
}, extras || {});
}

View file

@ -1,12 +1,19 @@
export default Em.Component.extend({
tagName: 'li',
classNameBindings: ['active'],
classNameBindings: ['active', 'tabClassName'],
tabClassName: function() {
return 'edit-category-' + this.get('tab');
}.property('tab'),
active: Discourse.computed.propertyEqual('selectedTab', 'tab'),
title: Discourse.computed.i18n('tab', 'category.%@'),
title: function() {
return I18n.t('category.' + this.get('tab').replace('-', '_'));
}.property('tab'),
_addToCollection: function() {
this.get('panels').addObject('edit-category-' + this.get('tab'));
this.get('panels').addObject(this.get('tabClassName'));
}.on('didInsertElement'),
actions: {

View file

@ -0,0 +1,11 @@
import { buildCategoryPanel } from 'discourse/components/edit-category-panel';
export default buildCategoryPanel('topic-template', {
_activeTabChanged: function() {
if (this.get('activeTab')) {
Ember.run.schedule('afterRender', function() {
$('#wmd-input').focus();
});
}
}.observes('activeTab')
});

View file

@ -76,7 +76,8 @@ Discourse.Category = Discourse.Model.extend({
logo_url: this.get('logo_url'),
background_url: this.get('background_url'),
allow_badges: this.get('allow_badges'),
custom_fields: this.get('custom_fields')
custom_fields: this.get('custom_fields'),
topic_template: this.get('topic_template')
},
type: this.get('id') ? 'PUT' : 'POST'
});

View file

@ -346,13 +346,24 @@ const Composer = RestModel.extend({
}
}
const categoryId = opts.categoryId || this.get('topic.category.id');
this.setProperties({
categoryId: opts.categoryId || this.get('topic.category.id'),
categoryId,
archetypeId: opts.archetypeId || this.site.get('default_archetype'),
metaData: opts.metaData ? Em.Object.create(opts.metaData) : null,
reply: opts.reply || this.get("reply") || ""
});
if (opts.action === CREATE_TOPIC && categoryId) {
const category = this.site.categories.find((c) => c.get('id') === categoryId);
if (category) {
const topicTemplate = category.get('topic_template');
if (!Ember.isEmpty(topicTemplate)) {
this.set('reply', topicTemplate);
}
}
}
if (opts.postId) {
this.set('loading', true);
this.store.find('post', opts.postId).then(function(post) {

View file

@ -0,0 +1 @@
{{component customComponent tab=tab selectedTab=selectedTab category=category}}

View file

@ -0,0 +1,2 @@
<label>{{i18n 'category.topic_template'}}</label>
{{pagedown-editor value=category.topic_template}}

View file

@ -6,6 +6,7 @@
{{/unless}}
{{edit-category-tab panels=panels selectedTab=selectedTab tab="settings"}}
{{edit-category-tab panels=panels selectedTab=selectedTab tab="images"}}
{{edit-category-tab panels=panels selectedTab=selectedTab tab="topic-template"}}
</ul>
<div class="modal-body">

View file

@ -102,8 +102,20 @@
clear: both;
}
.modal.edit-category-modal {
.modal-body {
#pagedown-editor {
width: 98%;
}
textarea {
height: 10em;
}
}
}
.modal {
.nav {
.nav {
padding: 10px 30px 10px 15px;
background-color: dark-light-diff($secondary, $primary, 10%, -15%);
li > a {

View file

@ -151,6 +151,7 @@
.modal-tab {
position: absolute;
width: 95%;
}
.split-modal {

View file

@ -146,6 +146,7 @@ class CategoriesController < ApplicationController
:background_url,
:allow_badges,
:slug,
:topic_template,
:custom_fields => [params[:custom_fields].try(:keys)],
:permissions => [*p.try(:keys)])
end

View file

@ -16,7 +16,8 @@ class BasicCategorySerializer < ApplicationSerializer
:notification_level,
:logo_url,
:background_url,
:can_edit
:can_edit,
:topic_template
def include_parent_category_id?
parent_category_id

View file

@ -1417,6 +1417,7 @@ en:
view: 'View Topics in Category'
general: 'General'
settings: 'Settings'
topic_template: "Topic Template"
delete: 'Delete Category'
create: 'New Category'
save: 'Save Category'

View file

@ -0,0 +1,5 @@
class AddTopicTemplateToCategories < ActiveRecord::Migration
def change
add_column :categories, :topic_template, :text, null: true
end
end

View file

@ -27,3 +27,16 @@ test("Change the category color", (assert) => {
assert.equal(Discourse.URL.redirectedTo, '/c/bug', 'it does one of the rare full page redirects');
});
});
test("Change the topic template", (assert) => {
visit("/c/bug");
click('.edit-category');
click('.edit-category-topic-template');
fillIn('#wmd-input', 'this is the new topic template');
click('#save-category');
andThen(() => {
assert.ok(!visible('#discourse-modal'), 'it closes the modal');
assert.equal(Discourse.URL.redirectedTo, '/c/bug', 'it does one of the rare full page redirects');
});
});