diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 0142d216..65299958 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -5,7 +5,8 @@ import { import { actionTypes, generateName, - generateSelectKitContent + generateSelectKitContent, + profileFields } from '../lib/custom-wizard'; export default Ember.Component.extend({ @@ -35,11 +36,6 @@ export default Ember.Component.extend({ newTopicFields(actionType) { return ['create_topic', 'send_message'].indexOf(actionType) > -1; }, - - @computed('wizardFields') - builderWizardFields(fields) { - return fields.map((f) => ` w{${f.id}}`); - }, @computed('wizardFields') categoryFields(fields) { @@ -51,13 +47,6 @@ export default Ember.Component.extend({ return fields.filter(f => f.type == 'tag'); }, - @computed() - builderUserFields() { - const noTheme = PROFILE_FIELDS.filter((f) => f !== 'theme_id'); - const fields = noTheme.concat(['email', 'username']); - return fields.map((f) => ` u{${f}}`); - }, - @observes('action.custom_category_wizard_field') toggleCustomCategoryUserField() { const wizard = this.get('action.custom_category_wizard_field'); diff --git a/assets/javascripts/discourse/components/wizard-custom-input-selector.js.es6 b/assets/javascripts/discourse/components/wizard-custom-input-selector.js.es6 index abcef1fa..cc9a6b66 100644 --- a/assets/javascripts/discourse/components/wizard-custom-input-selector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-input-selector.js.es6 @@ -2,9 +2,11 @@ import { alias, equal } from "@ember/object/computed"; import { computed } from "@ember/object"; import { default as discourseComputed, - observes + observes, + on } from "discourse-common/utils/decorators"; import { defaultSelectionType } from '../lib/custom-wizard'; +import { getOwner } from 'discourse-common/lib/get-owner'; export default Ember.Component.extend({ classNames: 'input-selector', @@ -13,6 +15,12 @@ export default Ember.Component.extend({ return this.site.categories.map(c => ({ id: c.id, name: c.name })); }), + @discourseComputed + userFields() { + const controller = getOwner(this).lookup('controller:admin-wizard'); + return controller.get('model.userFields'); + }, + @observes('options.@each') resetActiveType() { this.set('activeType', defaultSelectionType(this.selectorType, this.options)); diff --git a/assets/javascripts/discourse/components/wizard-links.js.es6 b/assets/javascripts/discourse/components/wizard-links.js.es6 index 993b75bf..e7113c17 100644 --- a/assets/javascripts/discourse/components/wizard-links.js.es6 +++ b/assets/javascripts/discourse/components/wizard-links.js.es6 @@ -1,19 +1,19 @@ import { default as computed, on, observes } from 'discourse-common/utils/decorators'; +import { notEmpty } from "@ember/object/computed"; export default Ember.Component.extend({ classNames: 'wizard-links', items: Ember.A(), + anyLinks: notEmpty('links'), @on('didInsertElement') @observes('links.@each') didInsertElement() { - Ember.run.scheduleOnce('afterRender', () => { - this.applySortable(); - }); + Ember.run.scheduleOnce('afterRender', () => (this.applySortable())); }, applySortable() { - this.$("ul").sortable({tolerance: 'pointer'}).on('sortupdate', (e, ui) => { + $(this.element).find("ul").sortable({tolerance: 'pointer'}).on('sortupdate', (e, ui) => { const itemId = ui.item.data('id'); const index = ui.item.index(); Ember.run.bind(this, this.updateItemOrder(itemId, index)); @@ -69,7 +69,6 @@ export default Ember.Component.extend({ const newItem = Ember.Object.create(params); items.pushObject(newItem); this.set('current', newItem); - this.sendAction('isNew'); }, change(itemId) { diff --git a/assets/javascripts/discourse/components/wizard-text-editor.js.es6 b/assets/javascripts/discourse/components/wizard-text-editor.js.es6 new file mode 100644 index 00000000..2a24cd0b --- /dev/null +++ b/assets/javascripts/discourse/components/wizard-text-editor.js.es6 @@ -0,0 +1,40 @@ +import { default as discourseComputed } from 'discourse-common/utils/decorators'; +import { profileFields } from '../lib/custom-wizard'; + +export default Ember.Component.extend({ + classNames: 'wizard-text-editor', + + @discourseComputed('forcePreview') + previewLabel(forcePreview) { + return I18n.t("admin.wizard.editor.preview", { + action: I18n.t(`admin.wizard.editor.${forcePreview ? 'hide' : 'show'}`) + }); + }, + + @discourseComputed('showPopover') + popoverLabel(showPopover) { + return I18n.t("admin.wizard.editor.popover", { + action: I18n.t(`admin.wizard.editor.${showPopover ? 'hide' : 'show'}`) + }); + }, + + @discourseComputed() + userFieldList() { + return profileFields.map((f) => ` u{${f}}`); + }, + + @discourseComputed('wizardFields') + wizardFieldList(wizardFields) { + return wizardFields.map((f) => ` w{${f.id}}`); + }, + + actions: { + togglePreview() { + this.toggleProperty('forcePreview'); + }, + + togglePopover() { + this.toggleProperty('showPopover'); + } + } +}); \ No newline at end of file diff --git a/assets/javascripts/discourse/controllers/admin-wizard.js.es6 b/assets/javascripts/discourse/controllers/admin-wizard.js.es6 index bb659329..acd25f95 100644 --- a/assets/javascripts/discourse/controllers/admin-wizard.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizard.js.es6 @@ -9,8 +9,9 @@ export default Ember.Controller.extend({ @computed('model.after_time_scheduled') nextSessionScheduledLabel(scheduled) { - return scheduled ? moment(scheduled).format('MMMM Do, HH:mm') : - I18n.t('admin.wizard.after_time_time_label'); + return scheduled ? + moment(scheduled).format('MMMM Do, HH:mm') : + I18n.t('admin.wizard.after_time_time_label'); }, actions: { @@ -19,7 +20,9 @@ export default Ember.Controller.extend({ saving: true, error: null }); + const wizard = this.get('model'); + wizard.save().then(() => { this.set('saving', false); if (this.get('newWizard')) { diff --git a/assets/javascripts/discourse/routes/admin-wizard.js.es6 b/assets/javascripts/discourse/routes/admin-wizard.js.es6 index f2ebefbd..7a880ded 100644 --- a/assets/javascripts/discourse/routes/admin-wizard.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizard.js.es6 @@ -22,18 +22,20 @@ export default DiscourseRoute.extend({ model(params) { const wizardId = params.wizard_id; - - if (wizardId === 'new') { - this.set('newWizard', true); + this.set('newWizard', wizardId === 'new'); + + if (this.newWizard) { return CustomWizard.create(); - }; - this.set('newWizard', false); - - const wizard = this.modelFor('admin-wizards-custom').findBy('id', wizardId.underscore()); - - if (!wizard) return this.transitionTo('adminWizard', 'new'); - - return wizard; + } else { + const wizard = this.modelFor('admin-wizards-custom') + .findBy('id', wizardId.underscore()); + + if (!wizard) { + return this.transitionTo('adminWizard', 'new'); + } else { + return wizard; + } + } }, afterModel(model) { @@ -56,9 +58,15 @@ export default DiscourseRoute.extend({ }, _getThemes(model) { - return this.store.findAll('theme').then((result) => { - model.set('themes', result.content); - }); + return ajax('/admin/themes') + .then((result) => { + model.set('themes', result.themes.map(t => { + return { + id: t.id, + name: t.name + } + })); + }); }, _getApis(model) { @@ -69,13 +77,17 @@ export default DiscourseRoute.extend({ _getUserFields(model) { return this.store.findAll('user-field').then((result) => { if (result && result.content) { - let userContent = result.content.map((f) => { - return { id: `user_field_${f.id}`, name: f.name}; - }); - let profileContent = profileFields.map((f) => { - return { id: f, name: generateName(f) }; - }); - model.set('userFields', userContent.concat(profileContent)); + model.set('userFields', + result.content.map((f) => ({ + id: `user_field_${f.id}`, + name: f.name + })).concat( + profileFields.map((f) => ({ + id: f, + name: generateName(f) + })) + ) + ); } }); }, diff --git a/assets/javascripts/discourse/templates/admin-wizard.hbs b/assets/javascripts/discourse/templates/admin-wizard.hbs index fe5d0965..87265cc2 100644 --- a/assets/javascripts/discourse/templates/admin-wizard.hbs +++ b/assets/javascripts/discourse/templates/admin-wizard.hbs @@ -1,150 +1,195 @@