1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/discourse/controllers/admin-wizard.js.es6

69 Zeilen
1,5 KiB
Text

2017-10-06 04:59:02 +02:00
import { default as computed } from 'ember-addons/ember-computed-decorators';
2017-09-23 04:34:07 +02:00
export default Ember.Controller.extend({
2017-10-06 04:59:02 +02:00
@computed('model.steps.[]', 'currentStep')
stepLinks(steps, currentStep) {
return steps.map((s) => {
if (s) {
let link = {
id: s.get('id'),
title: s.get('title')
};
let classes = 'btn';
if (currentStep && s.get('id') === currentStep.get('id')) {
classes += ' btn-primary';
};
link['classes'] = classes;
return link;
}
});
},
@computed('model.id')
wizardUrl(wizardId) {
return window.location.origin + '/wizard/custom/' + wizardId;
},
2017-09-23 04:34:07 +02:00
actions: {
save() {
this.get('model').save().then(() => {
2017-10-06 04:59:02 +02:00
this.send("refreshRoute");
2017-09-23 04:34:07 +02:00
});
},
remove() {
2017-09-24 05:01:18 +02:00
this.get('model').remove().then(() => {
2017-09-23 04:34:07 +02:00
this.transitionToRoute('adminWizardsCustom');
});
},
addStep() {
2017-10-06 04:59:02 +02:00
const steps = this.get('model.steps');
const newNum = steps.length + 1;
const step = Ember.Object.create({
2017-09-23 04:34:07 +02:00
fields: Ember.A(),
2017-10-06 04:59:02 +02:00
actions: Ember.A(),
title: `Step ${newNum}`,
id: `step-${newNum}`
});
steps.pushObject(step);
this.set('currentStep', step);
},
removeStep(stepId) {
const steps = this.get('model.steps');
steps.removeObject(steps.findBy('id', stepId));
2017-09-23 04:34:07 +02:00
},
2017-10-06 04:59:02 +02:00
changeStep(stepId) {
const steps = this.get('model.steps');
this.set('currentStep', steps.findBy('id', stepId));
2017-09-23 04:34:07 +02:00
}
}
});