0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-10 04:12:53 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-custom-action.js.es6
Angus McLeod 2046648862 various
2020-04-01 21:58:30 +11:00

75 Zeilen
2,2 KiB
JavaScript

import { default as discourseComputed, observes } from 'discourse-common/utils/decorators';
import { equal, not, empty } from "@ember/object/computed";
import {
actionTypes,
generateName,
generateSelectKitContent,
profileFields
} from '../lib/custom-wizard';
export default Ember.Component.extend({
classNames: 'wizard-custom-action',
types: actionTypes.map(t => ({ id: t, name: generateName(t) })),
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'),
groupPropertyTypes: generateSelectKitContent(['id', 'name']),
@discourseComputed('action.type')
basicTopicFields(actionType) {
return ['create_topic', 'send_message', 'open_composer'].indexOf(actionType) > -1;
},
@discourseComputed('action.type')
publicTopicFields(actionType) {
return ['create_topic', 'open_composer'].indexOf(actionType) > -1;
},
@discourseComputed('action.type')
newTopicFields(actionType) {
return ['create_topic', 'send_message'].indexOf(actionType) > -1;
},
@discourseComputed('wizardFields')
categoryFields(fields) {
return fields.filter(f => f.type == 'category');
},
@discourseComputed('wizardFields')
tagFields(fields) {
return fields.filter(f => f.type == 'tag');
},
@observes('action.custom_category_wizard_field')
toggleCustomCategoryUserField() {
if (this.action.custom_category_wizard_field)
this.set('action.custom_category_user_field', false);
},
@observes('action.custom_category_user_field')
toggleCustomCategoryWizardField() {
if (this.action.custom_category_user_field)
this.set('action.custom_category_wizard_field', false);
},
@discourseComputed('wizard.apis')
availableApis(apis) {
return apis.map(a => {
return {
id: a.name,
name: a.title
};
});
},
@discourseComputed('wizard.apis', 'action.api')
availableEndpoints(apis, api) {
if (!api) return [];
return apis.find(a => a.name === api).endpoints;
}
});