mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Can add topic templates to categories, prepopulated on compose
This commit is contained in:
parent
84a1acb2ec
commit
7676c5dfe7
15 changed files with 86 additions and 7 deletions
|
@ -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 || {});
|
||||
}
|
|
@ -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: {
|
||||
|
|
|
@ -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')
|
||||
});
|
|
@ -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'
|
||||
});
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{{component customComponent tab=tab selectedTab=selectedTab category=category}}
|
|
@ -0,0 +1,2 @@
|
|||
<label>{{i18n 'category.topic_template'}}</label>
|
||||
{{pagedown-editor value=category.topic_template}}
|
|
@ -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">
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -151,6 +151,7 @@
|
|||
|
||||
.modal-tab {
|
||||
position: absolute;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
.split-modal {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddTopicTemplateToCategories < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :categories, :topic_template, :text, null: true
|
||||
end
|
||||
end
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue