diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6
index 4ed3b225..8179def1 100644
--- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6
+++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6
@@ -1,11 +1,8 @@
export default Ember.Component.extend({
+ classNames: 'wizard-custom-action',
types: ['create_topic', 'update_profile', 'send_message'],
profileFields: ['name', 'username', 'email'],
createTopic: Ember.computed.equal('action.type', 'create_topic'),
updateProfile: Ember.computed.equal('action.type', 'update_profile'),
- sendMessage: Ember.computed.equal('action.type', 'send_message'),
-
- test: function() {
- console.log(this.get('stepFields'));
- }.observes('stepFields.[]')
+ sendMessage: Ember.computed.equal('action.type', 'send_message')
});
diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6
index e2693e40..fc3698b1 100644
--- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6
+++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6
@@ -1,9 +1,11 @@
-import { observes } from 'ember-addons/ember-computed-decorators';
+import { default as computed, on, observes } from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({
classNames: 'wizard-custom-field',
isDropdown: Ember.computed.equal('field.type', 'dropdown'),
+ @on('init')
+ @observes('field.id')
init() {
this._super(...arguments);
@@ -12,15 +14,16 @@ export default Ember.Component.extend({
}
},
- @observes('field.label')
- setFieldId() {
- const label = this.get('field.label');
- this.set('field.id', Ember.String.underscore(label));
- },
+ @computed('field.choices.[]')
+ dropdownChoices: choices => choices,
actions: {
addChoice() {
this.get('field.choices').pushObject(Ember.Object.create());
+ },
+
+ removeChoice(c) {
+ this.get('field.choices').removeObject(c);
}
}
});
diff --git a/assets/javascripts/discourse/components/wizard-custom-step.js.es6 b/assets/javascripts/discourse/components/wizard-custom-step.js.es6
index 9f7139bc..7127575c 100644
--- a/assets/javascripts/discourse/components/wizard-custom-step.js.es6
+++ b/assets/javascripts/discourse/components/wizard-custom-step.js.es6
@@ -1,26 +1,103 @@
-import { default as computed } from 'ember-addons/ember-computed-decorators';
+import { default as computed, on, observes } from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({
classNames: 'wizard-custom-step',
+ currentField: null,
+ currentAction: null,
- @computed('step.fields.@each.id')
- allowAddAction: stepFields => stepFields.get('firstObject.id'),
+ @on('init')
+ @observes('step.id')
+ setup() {
+ this._super(...arguments);
+ const fields = this.get('step.fields');
+ const actions = this.get('step.actions');
+ this.set('currentField', fields[0]);
+ this.set('currentAction', actions[0]);
+ },
+
+ @computed('step.fields.[]', 'currentField')
+ fieldLinks(fields, current) {
+ return fields.map((f) => {
+ if (f) {
+ let link = {
+ id: f.get('id'),
+ label: f.get('label')
+ };
+
+ let classes = 'btn';
+ if (current && f.get('id') === current.get('id')) {
+ classes += ' btn-primary';
+ };
+
+ link['classes'] = classes;
+
+ return link;
+ }
+ });
+ },
+
+ @computed('step.actions.[]', 'currentAction')
+ actionLinks(actions, current) {
+ return actions.map((a) => {
+ if (a) {
+ let link = {
+ id: a.get('id'),
+ label: a.get('label')
+ };
+
+ let classes = 'btn';
+ if (current && a.get('id') === current.get('id')) {
+ classes += ' btn-primary';
+ };
+
+ link['classes'] = classes;
+
+ return link;
+ }
+ });
+ },
actions: {
addField() {
- this.get('step.fields').pushObject(Ember.Object.create({ id: '', label: '' }));
+ const fields = this.get('step.fields');
+ const newNum = fields.length + 1;
+ const field = Ember.Object.create({
+ id: `field-${newNum}`, label: `Field ${newNum}`
+ });
+ fields.pushObject(field);
+ this.set('currentField', field);
},
addAction() {
- this.get('step.actions').pushObject(Ember.Object.create({ id: '', label: '' }));
+ const actions = this.get('step.actions');
+ const newNum = actions.length + 1;
+ const action = Ember.Object.create({
+ id: `action-${newNum}`, label: `Action ${newNum}`
+ });
+ actions.pushObject(action);
+ this.set('currentAction', action);
},
- removeField(field) {
- this.get('step.fields').removeObject(field);
+ removeField(fieldId) {
+ const fields = this.get('step.fields');
+ fields.removeObject(fields.findBy('id', fieldId));
+ this.set('currentField', fields[fields.length - 1]);
},
- removeAction(action) {
- this.get('step.actions').removeObject(action);
+ removeAction(actionId) {
+ const actions = this.get('step.actions');
+ actions.removeObject(actions.findBy('id', actionId));
+ this.set('currentAction', actions[actions.length - 1]);
+ },
+
+ changeField(fieldId) {
+ const fields = this.get('step.fields');
+ this.set('currentField', fields.findBy('id', fieldId));
+ },
+
+ changeAction(actionId) {
+ const actions = this.get('step.actions');
+ this.set('currentAction', actions.findBy('id', actionId));
}
}
});
diff --git a/assets/javascripts/discourse/controllers/admin-wizard.js.es6 b/assets/javascripts/discourse/controllers/admin-wizard.js.es6
index d4652ec4..7c343bde 100644
--- a/assets/javascripts/discourse/controllers/admin-wizard.js.es6
+++ b/assets/javascripts/discourse/controllers/admin-wizard.js.es6
@@ -1,8 +1,37 @@
+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.transitionToRoute('adminWizardsCustom');
+ this.send("refreshRoute");
});
},
@@ -13,14 +42,27 @@ export default Ember.Controller.extend({
},
addStep() {
- this.get('model.steps').pushObject(Ember.Object.create({
+ const steps = this.get('model.steps');
+ const newNum = steps.length + 1;
+ const step = Ember.Object.create({
fields: Ember.A(),
- actions: Ember.A()
- }));
+ actions: Ember.A(),
+ title: `Step ${newNum}`,
+ id: `step-${newNum}`
+ });
+
+ steps.pushObject(step);
+ this.set('currentStep', step);
},
- removeStep(step) {
- this.get('model.steps').removeObject(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));
}
}
});
diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6
index 50d7ea55..fad4b470 100644
--- a/assets/javascripts/discourse/models/custom-wizard.js.es6
+++ b/assets/javascripts/discourse/models/custom-wizard.js.es6
@@ -8,9 +8,7 @@ const CustomWizard = Discourse.Model.extend({
},
@computed('name')
- id(name) {
- return name ? Ember.String.dasherize(name) : null;
- },
+ id: (name) => name ? Ember.String.dasherize(name) : null,
save() {
const stepsObj = this.get('steps');
@@ -36,11 +34,12 @@ const CustomWizard = Discourse.Model.extend({
c.set('id', c.get('label'));
});
}
+
step['fields'].push(f);
});
s.actions.forEach((a) => {
- a['id'] = Ember.String.dasherize(a.label);
+ a.set('id', Ember.String.dasherize(a.get('label')));
step['actions'].push(a);
});
@@ -128,6 +127,7 @@ CustomWizard.reopenClass({
id: s.id,
title: s.title,
description: s.description,
+ banner: s.banner,
fields,
actions
}));
diff --git a/assets/javascripts/discourse/routes/admin-wizard.js.es6 b/assets/javascripts/discourse/routes/admin-wizard.js.es6
index 493aedc8..d260f253 100644
--- a/assets/javascripts/discourse/routes/admin-wizard.js.es6
+++ b/assets/javascripts/discourse/routes/admin-wizard.js.es6
@@ -21,7 +21,15 @@ export default Discourse.Route.extend({
},
setupController(controller, model) {
- controller.set("new", this.get('new'));
- controller.set("model", model);
+ let props = { new: this.get('new'), model };
+ const steps = model.get('steps');
+ if (steps[0]) props['currentStep'] = steps[0];
+ controller.setProperties(props);
+ },
+
+ actions: {
+ refreshRoute() {
+ this.refresh();
+ }
}
});
diff --git a/assets/javascripts/discourse/routes/admin-wizards-custom.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-custom.js.es6
index 517375ba..10fa40b9 100644
--- a/assets/javascripts/discourse/routes/admin-wizards-custom.js.es6
+++ b/assets/javascripts/discourse/routes/admin-wizards-custom.js.es6
@@ -5,6 +5,12 @@ export default Discourse.Route.extend({
return CustomWizard.findAll();
},
+ afterModel(model, transition) {
+ if (transition.intent.name !== 'adminWizard' && model.length > 0) {
+ this.transitionTo('adminWizard', model[0].id);
+ }
+ },
+
setupController(controller, model){
controller.set("model", model.toArray());
},
diff --git a/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6
index a014e8e3..a30cdd5b 100644
--- a/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6
+++ b/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6
@@ -5,6 +5,12 @@ export default Discourse.Route.extend({
return CustomWizard.findAllSubmissions();
},
+ afterModel(model, transition) {
+ if (transition.intent.name !== 'adminWizardSubmissions' && model.length > 0) {
+ this.transitionTo('adminWizardSubmissions', model[0].id);
+ }
+ },
+
setupController(controller, model){
controller.set("model", model);
}
diff --git a/assets/javascripts/discourse/templates/admin-wizard-submissions.hbs b/assets/javascripts/discourse/templates/admin-wizard-submissions.hbs
index 3c20109d..1effd84f 100644
--- a/assets/javascripts/discourse/templates/admin-wizard-submissions.hbs
+++ b/assets/javascripts/discourse/templates/admin-wizard-submissions.hbs
@@ -1,14 +1,16 @@
-
- {{#each model.submissions as |s|}}
-
- {{#each-in s as |k v|}}
- {{k}} |
- {{/each-in}}
-
-
- {{#each-in s as |k v|}}
- {{v}} |
- {{/each-in}}
-
- {{/each}}
-
+
+
+ {{#each model.submissions as |s|}}
+
+ {{#each-in s as |k v|}}
+ {{k}} |
+ {{/each-in}}
+
+
+ {{#each-in s as |k v|}}
+ {{v}} |
+ {{/each-in}}
+
+ {{/each}}
+
+
diff --git a/assets/javascripts/discourse/templates/admin-wizard.hbs b/assets/javascripts/discourse/templates/admin-wizard.hbs
index 6870852b..7a8516fc 100644
--- a/assets/javascripts/discourse/templates/admin-wizard.hbs
+++ b/assets/javascripts/discourse/templates/admin-wizard.hbs
@@ -1,22 +1,45 @@
-