0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-09-20 07:41:11 +02:00
discourse-custom-wizard/assets/javascripts/discourse/controllers/admin-wizard.js.es6
Angus McLeod 9f40821db0 Various
2017-10-06 10:59:02 +08:00

68 Zeilen
1,5 KiB
JavaScript

import { default as computed } from 'ember-addons/ember-computed-decorators';
export default Ember.Controller.extend({
@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;
},
actions: {
save() {
this.get('model').save().then(() => {
this.send("refreshRoute");
});
},
remove() {
this.get('model').remove().then(() => {
this.transitionToRoute('adminWizardsCustom');
});
},
addStep() {
const steps = this.get('model.steps');
const newNum = steps.length + 1;
const step = Ember.Object.create({
fields: Ember.A(),
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));
},
changeStep(stepId) {
const steps = this.get('model.steps');
this.set('currentStep', steps.findBy('id', stepId));
}
}
});