0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-09-20 07:41:11 +02:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-custom-action.js.es6

83 Zeilen
2,4 KiB
Text

2020-04-02 07:21:57 +02:00
import { default as discourseComputed, observes, on } from 'discourse-common/utils/decorators';
import { equal, not, empty, or } from "@ember/object/computed";
2020-03-21 18:30:11 +01:00
import {
actionTypes,
generateName,
2020-04-02 10:21:03 +02:00
selectKitContent,
2020-03-29 09:49:33 +02:00
profileFields
2020-04-02 07:21:57 +02:00
} from '../lib/wizard';
2017-10-13 15:02:34 +02:00
2017-09-23 04:34:07 +02:00
export default Ember.Component.extend({
2017-10-06 04:59:02 +02:00
classNames: 'wizard-custom-action',
2020-03-21 18:30:11 +01:00
types: actionTypes.map(t => ({ id: t, name: generateName(t) })),
2020-04-01 12:58:30 +02:00
createTopic: equal('action.type', 'create_topic'),
updateProfile: equal('action.type', 'update_profile'),
sendMessage: equal('action.type', 'send_message'),
sendToApi: equal('action.type', 'send_to_api'),
apiEmpty: empty('action.api'),
addToGroup: equal('action.type', 'add_to_group'),
routeTo: equal('action.type', 'route_to'),
disableId: not('action.isNew'),
2020-04-02 10:21:03 +02:00
groupPropertyTypes: selectKitContent(['id', 'name']),
2020-04-02 07:21:57 +02:00
hasAdvanced: or('basicTopicFields', 'routeTo'),
@on('didInsertElement')
@observes('action.type')
updateId() {
if (this.action.type) this.set('action.id', generateName(this.action.type));
},
2017-10-17 09:18:53 +02:00
2020-04-01 12:58:30 +02:00
@discourseComputed('action.type')
2019-08-27 08:05:24 +02:00
basicTopicFields(actionType) {
return ['create_topic', 'send_message', 'open_composer'].indexOf(actionType) > -1;
},
2020-04-01 12:58:30 +02:00
@discourseComputed('action.type')
2019-08-27 08:05:24 +02:00
publicTopicFields(actionType) {
return ['create_topic', 'open_composer'].indexOf(actionType) > -1;
},
2020-04-01 12:58:30 +02:00
@discourseComputed('action.type')
2019-08-27 08:05:24 +02:00
newTopicFields(actionType) {
return ['create_topic', 'send_message'].indexOf(actionType) > -1;
},
2020-04-01 12:58:30 +02:00
@discourseComputed('wizardFields')
categoryFields(fields) {
return fields.filter(f => f.type == 'category');
},
2020-04-01 12:58:30 +02:00
@discourseComputed('wizardFields')
tagFields(fields) {
return fields.filter(f => f.type == 'tag');
},
2017-11-24 05:32:15 +01:00
@observes('action.custom_category_wizard_field')
toggleCustomCategoryUserField() {
2020-04-01 07:03:26 +02:00
if (this.action.custom_category_wizard_field)
this.set('action.custom_category_user_field', false);
},
@observes('action.custom_category_user_field')
toggleCustomCategoryWizardField() {
2020-04-01 07:03:26 +02:00
if (this.action.custom_category_user_field)
this.set('action.custom_category_wizard_field', false);
2019-06-03 09:09:24 +02:00
},
2020-04-01 12:58:30 +02:00
@discourseComputed('wizard.apis')
2019-06-03 09:09:24 +02:00
availableApis(apis) {
return apis.map(a => {
return {
id: a.name,
name: a.title
};
});
},
2020-04-01 12:58:30 +02:00
@discourseComputed('wizard.apis', 'action.api')
2019-06-03 09:09:24 +02:00
availableEndpoints(apis, api) {
if (!api) return [];
return apis.find(a => a.name === api).endpoints;
2017-10-13 15:02:34 +02:00
}
2017-09-23 04:34:07 +02:00
});