1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/discourse/components/wizard-custom-action.js.es6

82 Zeilen
2,5 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-04-05 03:37:09 +02:00
import { actionTypes, generateName, selectKitContent, profileFields } from '../lib/wizard';
import Component from "@ember/component";
2017-10-13 15:02:34 +02:00
2020-04-05 03:37:09 +02:00
export default 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-07 15:33:11 +02:00
hasAdvanced: or('hasCustomFields', 'routeTo'),
hasCustomFields: or('basicTopicFields', 'updateProfile'),
2020-04-02 07:21:57 +02:00
@on('didInsertElement')
@observes('action.type')
2020-04-06 03:54:16 +02:00
setLabel() {
if (this.action.type) {
this.set('action.label', generateName(this.action.type));
};
2020-04-02 07:21:57 +02:00
},
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
});