From 7b09410a2610f9f14118c77e4a2257353bcc49f0 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 5 Oct 2017 08:36:46 +0800 Subject: [PATCH] various --- app/controllers/admin.rb | 40 +++++++-- app/controllers/steps.rb | 3 +- .../components/wizard-custom-action.js.es6 | 11 ++- .../components/wizard-custom-field.js.es6 | 1 - .../components/wizard-custom-step.js.es6 | 4 + .../custom-wizard-admin-route-map.js.es6 | 3 + .../discourse/models/custom-wizard.js.es6 | 30 ++++++- .../routes/admin-wizard-submissions.js.es6 | 9 ++ .../discourse/routes/admin-wizard.js.es6 | 6 ++ .../routes/admin-wizards-submissions.js.es6 | 11 +++ .../templates/admin-wizard-submissions.hbs | 14 ++++ .../discourse/templates/admin-wizard.hbs | 7 +- .../templates/admin-wizards-submissions.hbs | 15 ++++ .../discourse/templates/admin-wizards.hbs | 3 +- .../components/wizard-custom-action.hbs | 37 ++++---- .../components/wizard-custom-field.hbs | 2 +- .../components/wizard-custom-step.hbs | 7 +- .../wizard/initializers/custom.js.es6 | 30 ++++++- .../javascripts/wizard/models/custom.js.es6 | 2 - config/locales/client.en.yml | 26 +++++- config/locales/server.en.yml | 2 +- lib/builder.rb | 84 ++++++++++++++++++- plugin.rb | 31 +++++-- 23 files changed, 325 insertions(+), 53 deletions(-) create mode 100644 assets/javascripts/discourse/routes/admin-wizard-submissions.js.es6 create mode 100644 assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 create mode 100644 assets/javascripts/discourse/templates/admin-wizard-submissions.hbs create mode 100644 assets/javascripts/discourse/templates/admin-wizards-submissions.hbs diff --git a/app/controllers/admin.rb b/app/controllers/admin.rb index 0fc8a77b..f953d017 100644 --- a/app/controllers/admin.rb +++ b/app/controllers/admin.rb @@ -6,6 +6,10 @@ class CustomWizard::AdminController < ::ApplicationController render nothing: true end + def field_types + render json: { types: CustomWizard::FieldTypes.all } + end + def save params.require(:wizard) @@ -37,21 +41,43 @@ class CustomWizard::AdminController < ::ApplicationController render json: success_json end - def find - params.require(:id) + def find_wizard + params.require(:wizard_id) - wizard = PluginStore.get('custom_wizard', params[:id]) + wizard = PluginStore.get('custom_wizard', params[:wizard_id]) render json: success_json.merge(wizard: wizard) end - def all + def custom_wizards rows = PluginStoreRow.where(plugin_name: 'custom_wizard').order(:id) - wizards = rows ? [*rows].map do |r| - CustomWizard::Wizard.new(r.value) - end : [] + wizards = [*rows].map { |r| CustomWizard::Wizard.new(r.value) } render json: success_json.merge(wizards: wizards) end + + def find_submissions + params.require(:wizard_id) + + wizard = PluginStore.get('custom_wizard_submissions', params[:wizard_id]) + + render json: success_json.merge(submissions: submissions) + end + + def submissions + rows = PluginStoreRow.where(plugin_name: 'custom_wizard_submissions').order(:id) + + all = [*rows].map do |r| + wizard = PluginStore.get('custom_wizard', r.key) + name = wizard ? wizard['name'] : r.key + { + id: r.key, + name: name, + submissions: ::JSON.parse(r.value) + } + end + + render json: success_json.merge(submissions: all) + end end diff --git a/app/controllers/steps.rb b/app/controllers/steps.rb index 8191edcf..3a1fa06f 100644 --- a/app/controllers/steps.rb +++ b/app/controllers/steps.rb @@ -7,7 +7,8 @@ class CustomWizard::StepsController < ApplicationController updater.update if updater.success? - result = { success: 'OK' } + result = success_json + result.merge!(updater.result) if updater.result result[:refresh_required] = true if updater.refresh_required? render json: result else diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 84c5a11b..4ed3b225 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -1,4 +1,11 @@ export default Ember.Component.extend({ - targets: ['topic', 'profile', 'email', 'badge', 'save'], - isTopic: Ember.computed.equal('targets', 'topic') + 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.[]') }); diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 032c96fe..e2693e40 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -2,7 +2,6 @@ import { observes } from 'ember-addons/ember-computed-decorators'; export default Ember.Component.extend({ classNames: 'wizard-custom-field', - fieldTypes: ['dropdown', 'image', 'radio', 'text', 'textarea'], isDropdown: Ember.computed.equal('field.type', 'dropdown'), init() { diff --git a/assets/javascripts/discourse/components/wizard-custom-step.js.es6 b/assets/javascripts/discourse/components/wizard-custom-step.js.es6 index 06cd28d2..9f7139bc 100644 --- a/assets/javascripts/discourse/components/wizard-custom-step.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-step.js.es6 @@ -17,6 +17,10 @@ export default Ember.Component.extend({ removeField(field) { this.get('step.fields').removeObject(field); + }, + + removeAction(action) { + this.get('step.actions').removeObject(action); } } }); diff --git a/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6 b/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6 index 4dca2596..46d0e411 100644 --- a/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6 +++ b/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6 @@ -5,6 +5,9 @@ export default { this.route('adminWizardsCustom', { path: '/custom', resetNamespace: true }, function() { this.route('adminWizard', { path: '/:wizard_id', resetNamespace: true }); }); + this.route('adminWizardsSubmissions', { path: '/submissions', resetNamespace: true }, function() { + this.route('adminWizardSubmissions', { path: '/:wizard_id', resetNamespace: true }); + }); }); } }; diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index 31747d1a..50d7ea55 100644 --- a/assets/javascripts/discourse/models/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard.js.es6 @@ -29,6 +29,13 @@ const CustomWizard = Discourse.Model.extend({ const fields = s.get('fields'); fields.forEach((f) => { f.set('id', Ember.String.dasherize(f.get('label'))); + + if (f.get('type') === 'dropdown') { + const choices = f.get('choices'); + choices.forEach((c) => { + c.set('id', c.get('label')); + }); + } step['fields'].push(f); }); @@ -42,7 +49,8 @@ const CustomWizard = Discourse.Model.extend({ const id = this.get('id'); const name = this.get('name'); - let wizard = { id, name, steps }; + const save_submissions = this.get('save_submissions'); + let wizard = { id, name, save_submissions, steps }; const existingId = this.get('existingId'); if (existingId && existingId !== id) { @@ -76,6 +84,14 @@ CustomWizard.reopenClass({ }); }, + findAllSubmissions() { + return ajax("/admin/wizards/submissions/all", { + type: "GET" + }).then(result => { + return result.submissions; + }); + }, + create(w) { const wizard = this._super.apply(this); @@ -83,20 +99,24 @@ CustomWizard.reopenClass({ let props = { steps }; if (w) { - props['id'] = w.id; props['name'] = w.name; + props['id'] = w.id; + props['name'] = w.name; if (w.steps) { w.steps.forEach((s) => { let fields = Ember.A(); s.fields.forEach((f) => { + let field = Ember.Object.create(f); let choices = Ember.A(); f.choices.forEach((c) => { choices.pushObject(Ember.Object.create(c)); }); - fields.pushObject(Ember.Object.create(f)); + field.set('choices', choices); + + fields.pushObject(field); }); let actions = Ember.A(); @@ -112,7 +132,9 @@ CustomWizard.reopenClass({ actions })); }); - } + }; + } else { + props['save_submissions'] = true; }; wizard.setProperties(props); diff --git a/assets/javascripts/discourse/routes/admin-wizard-submissions.js.es6 b/assets/javascripts/discourse/routes/admin-wizard-submissions.js.es6 new file mode 100644 index 00000000..db19a780 --- /dev/null +++ b/assets/javascripts/discourse/routes/admin-wizard-submissions.js.es6 @@ -0,0 +1,9 @@ +export default Discourse.Route.extend({ + model(params) { + return this.modelFor('admin-wizards-submissions').findBy('id', params.wizard_id); + }, + + setupController(controller, model) { + controller.set("model", model); + } +}); diff --git a/assets/javascripts/discourse/routes/admin-wizard.js.es6 b/assets/javascripts/discourse/routes/admin-wizard.js.es6 index 085e34aa..493aedc8 100644 --- a/assets/javascripts/discourse/routes/admin-wizard.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizard.js.es6 @@ -1,4 +1,5 @@ import CustomWizard from '../models/custom-wizard'; +import { ajax } from 'discourse/lib/ajax'; export default Discourse.Route.extend({ model(params) { @@ -14,6 +15,11 @@ export default Discourse.Route.extend({ return wizard; }, + afterModel(model) { + return ajax('/admin/wizards/field-types') + .then((result) => model.set('fieldTypes', result.types)); + }, + setupController(controller, model) { controller.set("new", this.get('new')); controller.set("model", model); diff --git a/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 new file mode 100644 index 00000000..a014e8e3 --- /dev/null +++ b/assets/javascripts/discourse/routes/admin-wizards-submissions.js.es6 @@ -0,0 +1,11 @@ +import CustomWizard from '../models/custom-wizard'; + +export default Discourse.Route.extend({ + model() { + return CustomWizard.findAllSubmissions(); + }, + + 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 new file mode 100644 index 00000000..3c20109d --- /dev/null +++ b/assets/javascripts/discourse/templates/admin-wizard-submissions.hbs @@ -0,0 +1,14 @@ + + {{#each model.submissions as |s|}} + + {{#each-in s as |k v|}} + + {{/each-in}} + + + {{#each-in s as |k v|}} + + {{/each-in}} + + {{/each}} +
{{k}}
{{v}}
diff --git a/assets/javascripts/discourse/templates/admin-wizard.hbs b/assets/javascripts/discourse/templates/admin-wizard.hbs index 4dc46fbb..6870852b 100644 --- a/assets/javascripts/discourse/templates/admin-wizard.hbs +++ b/assets/javascripts/discourse/templates/admin-wizard.hbs @@ -4,9 +4,14 @@ {{text-field name="name" value=model.name placeholderKey="admin.wizard.name_placeholder"}} +
+ {{input type='checkbox' checked=model.save_submissions}} + {{i18n 'admin.wizard.save_submissions'}} +
+ {{#if model.steps}} {{#each model.steps as |s|}} - {{wizard-custom-step step=s}} + {{wizard-custom-step step=s fieldTypes=model.fieldTypes}} {{d-button action='removeStep' actionParam=s label='admin.wizard.step.remove'}} {{/each}} {{/if}} diff --git a/assets/javascripts/discourse/templates/admin-wizards-submissions.hbs b/assets/javascripts/discourse/templates/admin-wizards-submissions.hbs new file mode 100644 index 00000000..fb5e019e --- /dev/null +++ b/assets/javascripts/discourse/templates/admin-wizards-submissions.hbs @@ -0,0 +1,15 @@ +
+
+
    + {{#each model as |s|}} +
  • + {{#link-to "adminWizardSubmissions" s.id}}{{s.name}}{{/link-to}} +
  • + {{/each}} +
+
+ +
+ {{outlet}} +
+
diff --git a/assets/javascripts/discourse/templates/admin-wizards.hbs b/assets/javascripts/discourse/templates/admin-wizards.hbs index 749c490c..f855b33d 100644 --- a/assets/javascripts/discourse/templates/admin-wizards.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards.hbs @@ -1,5 +1,6 @@ {{#admin-nav}} - {{nav-item route='adminWizardsCustom' label='admin.wizard.label'}} + {{nav-item route='adminWizardsCustom' label='admin.wizard.custom_label'}} + {{nav-item route='adminWizardsSubmissions' label='admin.wizard.submissions_label'}} {{/admin-nav}}
diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index ab7ea9e4..2a2aec51 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -1,17 +1,26 @@ -{{combo-box value=action.data content=stepFields valueAttribute='id' nameProperty='label'}} -{{combo-box value=action.target content=targets}} -{{#if isTopic}} - {{category-select-box value=action.target.category_id tabindex="3"}} +{{combo-box value=action.type content=types}} +{{#if createTopic}} + + {{category-select-box value=action.category_id}} + + {{combo-box value=action.title content=stepFields nameProperty="label"}} + + {{combo-box value=action.post content=stepFields nameProperty="label"}} {{/if}} -{{#if isEmail}} - {{i18n 'admin.wizard.action.email'}} - {{input type='text' value=action.target.email}} +{{#if sendMessage}} + + {{combo-box value=action.title content=stepFields nameProperty="label"}} + + {{combo-box value=action.post content=stepFields nameProperty="label"}} + + {{user-selector single="true" + includeMentionableGroups="true" + usernames=action.username + allowedUsers="true"}} {{/if}} -{{#if isProfile}} - {{i18n 'admin.wizard.action.email'}} - {{combo-box value=action.target.profile_field content=profileFields}} -{{/if}} -{{#if isBadge}} - {{i18n 'admin.wizard.action.badge'}} - {{combo-box value=action.target.badge content=badges}} +{{#if updateProfile}} + + {{combo-box value=action.source content=stepFields nameProperty="label"}} + + {{combo-box value=action.profile_field content=profileFields}} {{/if}} diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index 0a09c58a..ca178c8a 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -9,7 +9,7 @@
{{i18n 'admin.wizard.field.type'}} - {{combo-box value=field.type content=fieldTypes}} + {{combo-box value=field.type content=types}}
{{#if isDropdown}} {{i18n 'admin.wizard.field.choices_label'}} diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs index 4d167d55..641069e4 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs @@ -14,16 +14,17 @@ {{#each step.fields as |f|}} - {{wizard-custom-field field=f}} + {{wizard-custom-field field=f types=fieldTypes}} {{d-button action='removeField' actionParam=f label="admin.wizard.field.remove"}} {{/each}} -{{d-button action='addField' label='admin.wizard.step.add_field'}} +{{d-button action='addField' label='admin.wizard.field.add'}} {{#each step.actions as |a|}} {{wizard-custom-action action=a stepFields=step.fields}} + {{d-button action='removeAction' actionParam=a label="admin.wizard.action.remove"}} {{/each}} {{#if allowAddAction}} - {{d-button action='addAction' label='admin.wizard.step.add_action'}} + {{d-button action='addAction' label='admin.wizard.action.add'}} {{/if}} diff --git a/assets/javascripts/wizard/initializers/custom.js.es6 b/assets/javascripts/wizard/initializers/custom.js.es6 index d8a7acd7..078c9b4d 100644 --- a/assets/javascripts/wizard/initializers/custom.js.es6 +++ b/assets/javascripts/wizard/initializers/custom.js.es6 @@ -1,9 +1,8 @@ - export default { name: 'custom-routes', - initialize(container, app) { - if (app.get('rootElement') !== '#custom-wizard-main') return; + initialize(app) { + if (app.constructor.name !== 'Class' || app.get('rootElement') !== '#custom-wizard-main') return; const WizardApplicationRoute = requirejs('wizard/routes/application').default; const findCustomWizard = requirejs('discourse/plugins/discourse-custom-wizard/wizard/models/custom').findCustomWizard; @@ -11,6 +10,8 @@ export default { const ajax = requirejs('wizard/lib/ajax').ajax; const StepRoute = requirejs('wizard/routes/step').default; const StepModel = requirejs('wizard/models/step').default; + const WizardStep = requirejs('wizard/components/wizard-step').default; + const getUrl = requirejs('discourse-common/lib/get-url').default; Router.map(function() { this.route('custom', { path: '/custom/:id' }, function() { @@ -62,5 +63,28 @@ export default { return model.set("wizardId", wizard.id); } }); + + WizardStep.reopen({ + advance() { + this.set('saving', true); + this.get('step').save() + .then(response => { + if (this.get('finalStep')) { + document.location = getUrl("/"); + } else { + this.sendAction('goNext', response); + } + }) + .catch(() => this.animateInvalidFields()) + .finally(() => this.set('saving', false)); + }, + + actions: { + quit() { + this.set('finalStep', true); + this.send('nextStep'); + } + } + }); } }; diff --git a/assets/javascripts/wizard/models/custom.js.es6 b/assets/javascripts/wizard/models/custom.js.es6 index 47fc3ed5..af992d50 100644 --- a/assets/javascripts/wizard/models/custom.js.es6 +++ b/assets/javascripts/wizard/models/custom.js.es6 @@ -17,8 +17,6 @@ export function findCustomWizard(wizardId) { return stepObj; }); - console.log(wizard) - return CustomWizard.create(wizard); }); }; diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index a2b3d1a2..a955b6fb 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -5,8 +5,10 @@ en: label: "Wizards" new: "New" custom_label: "Custom" + submissions_label: "Submissions" name: "Name" name_placeholder: "name of the wizard" + save_submissions: "Save wizard submissions" save: "Save Wizard" remove: "Delete Wizard" step: @@ -18,15 +20,31 @@ en: description_placeholder: "This will appear underneath the title and / or title" add: "Add Step" remove: "Remove Step" - add_field: "Add Field" - add_action: "Add Action" field: + add: "Add Field" + remove: "Remove Field" label: "Field Name" description: "Field Description" type: "Field Type" choices_label: "Dropdown Choices" add_choice: "Add Choice" required: "Field Required" - remove: "Remove Field" action: - email: "Email" + add: "Add Action" + remove: "Remove Action" + source: "Source" + send_message: + label: "Send Message" + title: "Message Title" + post: "Message Post" + recipient: "Message Recipient" + create_topic: + label: "Create Topic" + title: "Topic Title" + post: "Topic Post" + category: "Topic Category" + update_profile: + label: "Update Profile" + field: "Profile Field" + save_input: + label: "Save Input" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 1b332097..dc2afd2d 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1,3 +1,3 @@ en: - wizard: + custom_wizard: title: "Wizard" diff --git a/lib/builder.rb b/lib/builder.rb index f91beed1..b67aaa84 100644 --- a/lib/builder.rb +++ b/lib/builder.rb @@ -1,9 +1,24 @@ class CustomWizard::Builder + def initialize(user, wizard_id) data = PluginStore.get('custom_wizard', wizard_id) @custom_wizard = CustomWizard::Wizard.new(data) @wizard = Wizard.new(user) @wizard.id = wizard_id + @wizard.save_submissions = data['save_submissions'] + end + + def self.sorted_handlers + @sorted_handlers ||= [] + end + + def self.step_handlers + sorted_handlers.map { |h| { wizard_id: h[:wizard_id], block: h[:block] } } + end + + def self.add_step_handler(priority = 0, wizard_id, &block) + sorted_handlers << { priority: priority, wizard_id: wizard_id, block: block } + @sorted_handlers.sort_by! { |h| -h[:priority] } end def build @@ -27,8 +42,73 @@ class CustomWizard::Builder end step.on_update do |updater| - puts "UPDATER: #{updater}" - ## do stuff + + @updater = updater + input = updater.fields + user = @wizard.user + + if @wizard.save_submissions + store_key = @wizard.id + submissions = Array.wrap(PluginStore.get("custom_wizard_submissions", store_key)) + submission = {} + + if submissions.last && submissions.last['completed'] === false + submission = submissions.last + submissions.pop(1) + end + + submission['user_id'] = @wizard.user.id + submission['completed'] = updater.step.next.nil? + + input.each do |key, value| + submission[key] = value + end + + submissions.push(submission) + + PluginStore.set('custom_wizard_submissions', store_key, submissions) + end + + if s['actions'] && s['actions'].length + s['actions'].each do |a| + if a['type'] === 'create_topic' + creator = PostCreator.new(user, + title: input[a['title']], + raw: input[a['post']], + category: a['category_id'], + skip_validations: true) + + post = creator.create + if creator.errors.present? + raise StandardError, creator.errors.full_messages.join(" ") + end + + updater.result = { topic_id: post.topic.id } + end + + if a['type'] === 'send_message' + creator = PostCreator.new(user, + title: input[a['title']], + raw: input[a['post']], + archetype: Archetype.private_message, + target_usernames: a['username']) + + post = creator.create + + if creator.errors.present? + raise StandardError, creator.errors.full_messages.join(" ") + end + + updater.result = { topic_id: post.topic.id } + end + end + end + + CustomWizard::Builder.step_handlers.each do |handler| + if handler[:wizard_id] == @wizard.id + handler[:block].call(self) + end + end end end end diff --git a/plugin.rb b/plugin.rb index 0d5f2f1c..e60d5c2a 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,5 +1,5 @@ # name: discourse-custom-wizard -# about: Allows the admins to create custom user input forms +# about: Create custom wizards # version: 0.1 # authors: Angus McLeod @@ -37,24 +37,44 @@ after_initialize do end scope module: 'custom_wizard', constraints: AdminConstraint.new do + get 'admin/wizards' => 'admin#index' + get 'admin/wizards/field-types' => 'admin#field_types' get 'admin/wizards/custom' => 'admin#index' get 'admin/wizards/custom/new' => 'admin#index' - get 'admin/wizards/custom/all' => 'admin#all' - get 'admin/wizards/custom/:wizard_id' => 'admin#find' + get 'admin/wizards/custom/all' => 'admin#custom_wizards' + get 'admin/wizards/custom/:wizard_id' => 'admin#find_wizard' put 'admin/wizards/custom/save' => 'admin#save' delete 'admin/wizards/custom/remove' => 'admin#remove' + get 'admin/wizards/submissions' => 'admin#index' + get 'admin/wizards/submissions/all' => 'admin#submissions' + get 'admin/wizards/submissions/:wizard_id' => 'admin#find_submissions' + end + end + + class CustomWizard::FieldTypes + def self.all + @types ||= ['dropdown', 'image', 'radio', 'text', 'textarea'] + end + + def self.add(type) + all.push(*type) end end class ::Wizard - attr_accessor :id + attr_accessor :id, :save_submissions end class ::Wizard::Step attr_accessor :title end - ::Wizard::Field.class_eval do + class ::Wizard::StepUpdater + attr_accessor :result, :step + end + + require_dependency 'wizard/field' + Wizard::Field.class_eval do attr_reader :label, :description def initialize(attrs) @@ -84,7 +104,6 @@ after_initialize do ::WizardFieldSerializer.class_eval do def label - puts "LABEL: #{object.label}" if object.label object.label else