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

89 Zeilen
2,6 KiB
Text

2020-03-21 18:30:11 +01:00
import {
default as computed,
observes
} from 'discourse-common/utils/decorators';
import {
actionTypes,
generateName,
generateSelectKitContent
} from '../lib/custom-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) })),
2017-10-05 02:36:46 +02:00
createTopic: Ember.computed.equal('action.type', 'create_topic'),
updateProfile: Ember.computed.equal('action.type', 'update_profile'),
2017-10-13 15:02:34 +02:00
sendMessage: Ember.computed.equal('action.type', 'send_message'),
2019-06-03 09:09:24 +02:00
sendToApi: Ember.computed.equal('action.type', 'send_to_api'),
apiEmpty: Ember.computed.empty('action.api'),
2019-07-01 04:31:50 +02:00
addToGroup: Ember.computed.equal('action.type', 'add_to_group'),
routeTo: Ember.computed.equal('action.type', 'route_to'),
2017-10-17 15:17:53 +02:00
disableId: Ember.computed.not('action.isNew'),
2020-03-21 18:30:11 +01:00
groupPropertyTypes: generateSelectKitContent(['id', 'name']),
2017-10-17 09:18:53 +02:00
2019-08-27 08:05:24 +02:00
@computed('action.type')
basicTopicFields(actionType) {
return ['create_topic', 'send_message', 'open_composer'].indexOf(actionType) > -1;
},
@computed('action.type')
publicTopicFields(actionType) {
return ['create_topic', 'open_composer'].indexOf(actionType) > -1;
},
@computed('action.type')
newTopicFields(actionType) {
return ['create_topic', 'send_message'].indexOf(actionType) > -1;
},
2020-03-21 18:30:11 +01:00
@computed('wizardFields')
2017-11-24 05:32:15 +01:00
builderWizardFields(fields) {
return fields.map((f) => ` w{${f.id}}`);
},
2020-03-21 18:30:11 +01:00
@computed('wizardFields')
categoryFields(fields) {
return fields.filter(f => f.type == 'category');
},
2020-03-21 18:30:11 +01:00
@computed('wizardFields')
tagFields(fields) {
return fields.filter(f => f.type == 'tag');
},
2017-11-24 05:32:15 +01:00
@computed()
builderUserFields() {
2018-07-16 06:28:24 +02:00
const noTheme = PROFILE_FIELDS.filter((f) => f !== 'theme_id');
const fields = noTheme.concat(['email', 'username']);
2017-11-24 05:32:15 +01:00
return fields.map((f) => ` u{${f}}`);
},
@observes('action.custom_category_wizard_field')
toggleCustomCategoryUserField() {
const wizard = this.get('action.custom_category_wizard_field');
if (wizard) this.set('action.custom_category_user_field', false);
},
@observes('action.custom_category_user_field')
toggleCustomCategoryWizardField() {
const user = this.get('action.custom_category_user_field');
if (user) this.set('action.custom_category_wizard_field', false);
2019-06-03 09:09:24 +02:00
},
@computed('wizard.apis')
availableApis(apis) {
return apis.map(a => {
return {
id: a.name,
name: a.title
};
});
},
@computed('wizard.apis', 'action.api')
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
});