mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -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({
|
export default Em.Component.extend({
|
||||||
tagName: 'li',
|
tagName: 'li',
|
||||||
classNameBindings: ['active'],
|
classNameBindings: ['active', 'tabClassName'],
|
||||||
|
|
||||||
|
tabClassName: function() {
|
||||||
|
return 'edit-category-' + this.get('tab');
|
||||||
|
}.property('tab'),
|
||||||
|
|
||||||
active: Discourse.computed.propertyEqual('selectedTab', '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() {
|
_addToCollection: function() {
|
||||||
this.get('panels').addObject('edit-category-' + this.get('tab'));
|
this.get('panels').addObject(this.get('tabClassName'));
|
||||||
}.on('didInsertElement'),
|
}.on('didInsertElement'),
|
||||||
|
|
||||||
actions: {
|
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'),
|
logo_url: this.get('logo_url'),
|
||||||
background_url: this.get('background_url'),
|
background_url: this.get('background_url'),
|
||||||
allow_badges: this.get('allow_badges'),
|
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'
|
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({
|
this.setProperties({
|
||||||
categoryId: opts.categoryId || this.get('topic.category.id'),
|
categoryId,
|
||||||
archetypeId: opts.archetypeId || this.site.get('default_archetype'),
|
archetypeId: opts.archetypeId || this.site.get('default_archetype'),
|
||||||
metaData: opts.metaData ? Em.Object.create(opts.metaData) : null,
|
metaData: opts.metaData ? Em.Object.create(opts.metaData) : null,
|
||||||
reply: opts.reply || this.get("reply") || ""
|
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) {
|
if (opts.postId) {
|
||||||
this.set('loading', true);
|
this.set('loading', true);
|
||||||
this.store.find('post', opts.postId).then(function(post) {
|
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}}
|
{{/unless}}
|
||||||
{{edit-category-tab panels=panels selectedTab=selectedTab tab="settings"}}
|
{{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="images"}}
|
||||||
|
{{edit-category-tab panels=panels selectedTab=selectedTab tab="topic-template"}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
|
|
@ -102,8 +102,20 @@
|
||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.modal.edit-category-modal {
|
||||||
|
.modal-body {
|
||||||
|
#pagedown-editor {
|
||||||
|
width: 98%;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
height: 10em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.modal {
|
.modal {
|
||||||
.nav {
|
.nav {
|
||||||
padding: 10px 30px 10px 15px;
|
padding: 10px 30px 10px 15px;
|
||||||
background-color: dark-light-diff($secondary, $primary, 10%, -15%);
|
background-color: dark-light-diff($secondary, $primary, 10%, -15%);
|
||||||
li > a {
|
li > a {
|
||||||
|
|
|
@ -151,6 +151,7 @@
|
||||||
|
|
||||||
.modal-tab {
|
.modal-tab {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
width: 95%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.split-modal {
|
.split-modal {
|
||||||
|
|
|
@ -146,6 +146,7 @@ class CategoriesController < ApplicationController
|
||||||
:background_url,
|
:background_url,
|
||||||
:allow_badges,
|
:allow_badges,
|
||||||
:slug,
|
:slug,
|
||||||
|
:topic_template,
|
||||||
:custom_fields => [params[:custom_fields].try(:keys)],
|
:custom_fields => [params[:custom_fields].try(:keys)],
|
||||||
:permissions => [*p.try(:keys)])
|
:permissions => [*p.try(:keys)])
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,8 @@ class BasicCategorySerializer < ApplicationSerializer
|
||||||
:notification_level,
|
:notification_level,
|
||||||
:logo_url,
|
:logo_url,
|
||||||
:background_url,
|
:background_url,
|
||||||
:can_edit
|
:can_edit,
|
||||||
|
:topic_template
|
||||||
|
|
||||||
def include_parent_category_id?
|
def include_parent_category_id?
|
||||||
parent_category_id
|
parent_category_id
|
||||||
|
|
|
@ -1417,6 +1417,7 @@ en:
|
||||||
view: 'View Topics in Category'
|
view: 'View Topics in Category'
|
||||||
general: 'General'
|
general: 'General'
|
||||||
settings: 'Settings'
|
settings: 'Settings'
|
||||||
|
topic_template: "Topic Template"
|
||||||
delete: 'Delete Category'
|
delete: 'Delete Category'
|
||||||
create: 'New Category'
|
create: 'New Category'
|
||||||
save: 'Save 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');
|
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