0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-10 04:12:53 +01:00
discourse-custom-wizard/assets/javascripts/discourse/controllers/admin-wizard.js.es6

72 Zeilen
1,7 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) {
2017-10-07 04:27:38 +02:00
const id = s.get('id');
const title = s.get('title');
let link = { id, title: title || id };
2017-10-06 04:59:02 +02:00
let classes = 'btn';
2017-10-07 04:27:38 +02:00
if (currentStep && id === currentStep.get('id')) {
2017-10-06 04:59:02 +02:00
classes += ' btn-primary';
};
link['classes'] = classes;
return link;
}
});
},
2017-10-07 04:27:38 +02:00
@computed('model.id', 'model.name')
2017-10-06 04:59:02 +02:00
wizardUrl(wizardId) {
2017-10-07 04:27:38 +02:00
return window.location.origin + '/wizard/custom/' + Ember.String.dasherize(wizardId);
2017-10-06 04:59:02 +02:00
},
2017-09-23 04:34:07 +02:00
actions: {
save() {
this.get('model').save().then(() => {
2017-10-07 04:27:38 +02:00
if (this.get('newWizard')) {
this.send("refreshAllWizards");
} else {
this.send("refreshWizard");
}
2017-09-23 04:34:07 +02:00
});
},
remove() {
2017-09-24 05:01:18 +02:00
this.get('model').remove().then(() => {
2017-10-07 04:27:38 +02:00
this.send("refreshAllWizards");
2017-09-23 04:34:07 +02:00
});
},
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(),
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-10-07 04:27:38 +02:00
this.set('currentStep', steps[steps.length - 1]);
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
}
}
});