2017-10-06 04:59:02 +02:00
|
|
|
import { default as computed, on, observes } from 'ember-addons/ember-computed-decorators';
|
2017-09-23 04:34:07 +02:00
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
|
|
|
classNames: 'wizard-custom-step',
|
2017-10-06 04:59:02 +02:00
|
|
|
currentField: null,
|
|
|
|
currentAction: null,
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2017-10-06 04:59:02 +02:00
|
|
|
@on('init')
|
2017-10-07 04:27:38 +02:00
|
|
|
@observes('step')
|
2017-10-13 15:02:34 +02:00
|
|
|
setCurrent() {
|
|
|
|
this.set('existingId', this.get('step.id'));
|
2017-10-07 04:27:38 +02:00
|
|
|
const fields = this.get('step.fields') || [];
|
|
|
|
const actions = this.get('step.actions') || [];
|
2017-10-06 04:59:02 +02:00
|
|
|
this.set('currentField', fields[0]);
|
|
|
|
this.set('currentAction', actions[0]);
|
|
|
|
},
|
|
|
|
|
2017-10-13 15:02:34 +02:00
|
|
|
@computed('step.fields.@each.id', 'currentField')
|
2017-10-06 04:59:02 +02:00
|
|
|
fieldLinks(fields, current) {
|
2017-10-07 04:27:38 +02:00
|
|
|
if (!fields) return;
|
|
|
|
|
2017-10-06 04:59:02 +02:00
|
|
|
return fields.map((f) => {
|
|
|
|
if (f) {
|
2017-10-07 04:27:38 +02:00
|
|
|
const id = f.get('id');
|
|
|
|
const label = f.get('label');
|
|
|
|
|
2017-10-13 15:02:34 +02:00
|
|
|
let link = { id, label: label || id || 'new' };
|
2017-10-06 04:59:02 +02:00
|
|
|
|
|
|
|
let classes = 'btn';
|
|
|
|
if (current && f.get('id') === current.get('id')) {
|
|
|
|
classes += ' btn-primary';
|
|
|
|
};
|
|
|
|
|
|
|
|
link['classes'] = classes;
|
|
|
|
|
|
|
|
return link;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-10-13 15:02:34 +02:00
|
|
|
@computed('step.actions.@each.id', 'currentAction')
|
2017-10-06 04:59:02 +02:00
|
|
|
actionLinks(actions, current) {
|
2017-10-07 04:27:38 +02:00
|
|
|
if (!actions) return;
|
|
|
|
|
2017-10-06 04:59:02 +02:00
|
|
|
return actions.map((a) => {
|
|
|
|
if (a) {
|
2017-10-07 04:27:38 +02:00
|
|
|
const id = a.get('id');
|
|
|
|
const label = a.get('label');
|
|
|
|
|
2017-10-13 15:02:34 +02:00
|
|
|
let link = { id, label: label || id || 'new' };
|
2017-10-06 04:59:02 +02:00
|
|
|
|
|
|
|
let classes = 'btn';
|
|
|
|
if (current && a.get('id') === current.get('id')) {
|
|
|
|
classes += ' btn-primary';
|
|
|
|
};
|
|
|
|
|
|
|
|
link['classes'] = classes;
|
|
|
|
|
|
|
|
return link;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2017-09-23 04:34:07 +02:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
addField() {
|
2017-10-06 04:59:02 +02:00
|
|
|
const fields = this.get('step.fields');
|
2017-10-13 15:02:34 +02:00
|
|
|
const field = Ember.Object.create();
|
2017-10-06 04:59:02 +02:00
|
|
|
fields.pushObject(field);
|
|
|
|
this.set('currentField', field);
|
2017-09-23 04:34:07 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
addAction() {
|
2017-10-06 04:59:02 +02:00
|
|
|
const actions = this.get('step.actions');
|
2017-10-13 15:02:34 +02:00
|
|
|
const action = Ember.Object.create();
|
2017-10-06 04:59:02 +02:00
|
|
|
actions.pushObject(action);
|
|
|
|
this.set('currentAction', action);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeField(fieldId) {
|
|
|
|
const fields = this.get('step.fields');
|
|
|
|
fields.removeObject(fields.findBy('id', fieldId));
|
|
|
|
this.set('currentField', fields[fields.length - 1]);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeAction(actionId) {
|
|
|
|
const actions = this.get('step.actions');
|
|
|
|
actions.removeObject(actions.findBy('id', actionId));
|
|
|
|
this.set('currentAction', actions[actions.length - 1]);
|
2017-09-23 04:34:07 +02:00
|
|
|
},
|
|
|
|
|
2017-10-06 04:59:02 +02:00
|
|
|
changeField(fieldId) {
|
|
|
|
const fields = this.get('step.fields');
|
|
|
|
this.set('currentField', fields.findBy('id', fieldId));
|
2017-10-05 02:36:46 +02:00
|
|
|
},
|
|
|
|
|
2017-10-06 04:59:02 +02:00
|
|
|
changeAction(actionId) {
|
|
|
|
const actions = this.get('step.actions');
|
|
|
|
this.set('currentAction', actions.findBy('id', actionId));
|
2017-09-23 04:34:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|