discourse/app/assets/javascripts/wizard/addon/models/wizard.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.7 KiB
JavaScript
Raw Normal View History

import EmberObject from "@ember/object";
import Evented from "@ember/object/evented";
2016-08-26 01:14:56 +08:00
import Step from "wizard/models/step";
import WizardField from "wizard/models/wizard-field";
import { ajax } from "discourse/lib/ajax";
import { readOnly } from "@ember/object/computed";
2016-08-26 01:14:56 +08:00
const Wizard = EmberObject.extend(Evented, {
totalSteps: readOnly("steps.length"),
2016-09-17 04:12:56 +08:00
2016-09-17 05:02:45 +08:00
getTitle() {
const titleStep = this.steps.findBy("id", "forum-title");
2016-09-17 05:02:45 +08:00
if (!titleStep) {
return;
}
return titleStep.get("fieldsById.title.value");
},
getLogoUrl() {
const logoStep = this.steps.findBy("id", "logos");
if (!logoStep) {
return;
}
return logoStep.get("fieldsById.logo.value");
},
get currentColors() {
const colorStep = this.steps.findBy("id", "styling");
2016-09-17 04:12:56 +08:00
if (!colorStep) {
return this.current_color_scheme;
2016-09-17 04:12:56 +08:00
}
const themeChoice = colorStep.fieldsById.color_scheme;
2016-09-17 04:12:56 +08:00
if (!themeChoice) {
return;
}
return themeChoice.choices?.findBy("id", themeChoice.value)?.data.colors;
},
get font() {
const fontChoice = this.steps.findBy("id", "styling")?.fieldsById
?.body_font;
return fontChoice.choices?.findBy("id", fontChoice.value)?.label;
},
get headingFont() {
const fontChoice = this.steps.findBy("id", "styling")?.fieldsById
?.heading_font;
return fontChoice.choices?.findBy("id", fontChoice.value)?.label;
2016-09-17 04:12:56 +08:00
},
2016-08-26 01:14:56 +08:00
});
export function findWizard() {
return ajax({ url: "/wizard.json" }).then(({ wizard }) => {
2016-08-26 01:14:56 +08:00
wizard.steps = wizard.steps.map((step) => {
const stepObj = Step.create(step);
stepObj.fields = stepObj.fields.map((f) => WizardField.create(f));
return stepObj;
});
return Wizard.create(wizard);
});
}