2017-11-30 03:55:15 +01:00
|
|
|
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
2017-10-17 09:18:53 +02:00
|
|
|
|
2017-10-22 05:37:58 +02:00
|
|
|
const ACTION_TYPES = [
|
2017-10-30 07:24:51 +01:00
|
|
|
{ id: 'create_topic', name: 'Create Topic' },
|
|
|
|
{ id: 'update_profile', name: 'Update Profile' },
|
2019-06-03 09:09:24 +02:00
|
|
|
{ id: 'send_message', name: 'Send Message' },
|
|
|
|
{ id: 'send_to_api', name: 'Send to API' }
|
2017-10-22 05:37:58 +02:00
|
|
|
];
|
|
|
|
|
2017-10-17 09:18:53 +02:00
|
|
|
const PROFILE_FIELDS = [
|
|
|
|
'name',
|
|
|
|
'date_of_birth',
|
2017-11-24 05:32:15 +01:00
|
|
|
'title',
|
2017-10-17 09:18:53 +02:00
|
|
|
'locale',
|
|
|
|
'location',
|
|
|
|
'website',
|
2017-11-24 05:32:15 +01:00
|
|
|
'bio_raw',
|
2017-10-17 09:18:53 +02:00
|
|
|
'profile_background',
|
2017-11-24 05:32:15 +01:00
|
|
|
'card_background',
|
2018-07-16 06:28:24 +02:00
|
|
|
'theme_id'
|
2017-10-17 09:18:53 +02:00
|
|
|
];
|
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',
|
2017-10-22 05:37:58 +02:00
|
|
|
types: ACTION_TYPES,
|
2017-10-17 09:18:53 +02:00
|
|
|
profileFields: PROFILE_FIELDS,
|
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'),
|
2017-10-17 15:17:53 +02:00
|
|
|
disableId: Ember.computed.not('action.isNew'),
|
2017-10-17 09:18:53 +02:00
|
|
|
|
2017-10-30 07:24:51 +01:00
|
|
|
@computed('currentStepId', 'wizard.save_submissions')
|
|
|
|
availableFields(currentStepId, saveSubmissions) {
|
|
|
|
const allSteps = this.get('wizard.steps');
|
|
|
|
let steps = allSteps;
|
2017-10-17 09:18:53 +02:00
|
|
|
let fields = [];
|
2017-10-30 07:24:51 +01:00
|
|
|
|
|
|
|
if (!saveSubmissions) {
|
|
|
|
steps = [allSteps.findBy('id', currentStepId)];
|
|
|
|
}
|
|
|
|
|
2017-10-17 09:18:53 +02:00
|
|
|
steps.forEach((s) => {
|
2017-10-30 07:24:51 +01:00
|
|
|
if (s.fields && s.fields.length > 0) {
|
|
|
|
let stepFields = s.fields.map((f) => {
|
|
|
|
return Ember.Object.create({
|
|
|
|
id: f.id,
|
|
|
|
label: `${f.id} (${s.id})`
|
|
|
|
});
|
2017-10-17 15:17:53 +02:00
|
|
|
});
|
2017-10-30 07:24:51 +01:00
|
|
|
fields.push(...stepFields);
|
|
|
|
}
|
2017-10-17 09:18:53 +02:00
|
|
|
});
|
2017-10-30 07:24:51 +01:00
|
|
|
|
2017-10-17 09:18:53 +02:00
|
|
|
return fields;
|
2017-11-24 05:32:15 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
@computed('availableFields')
|
|
|
|
builderWizardFields(fields) {
|
|
|
|
return fields.map((f) => ` w{${f.id}}`);
|
|
|
|
},
|
|
|
|
|
|
|
|
@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}}`);
|
2017-11-30 03:55:15 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
@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
|
|
|
});
|