0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 18:50:27 +01:00

Add add_to_group action

Dieser Commit ist enthalten in:
Angus McLeod 2019-07-01 12:31:50 +10:00
Ursprung 20f605b899
Commit f693a2d25a
5 geänderte Dateien mit 55 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -3,7 +3,8 @@ import { default as computed, observes } from 'ember-addons/ember-computed-decor
const ACTION_TYPES = [ const ACTION_TYPES = [
{ id: 'create_topic', name: 'Create Topic' }, { id: 'create_topic', name: 'Create Topic' },
{ id: 'update_profile', name: 'Update Profile' }, { id: 'update_profile', name: 'Update Profile' },
{ id: 'send_message', name: 'Send Message' } { id: 'send_message', name: 'Send Message' },
{ id: 'add_to_group', name: 'Add to Group' }
]; ];
const PROFILE_FIELDS = [ const PROFILE_FIELDS = [
@ -26,6 +27,7 @@ export default Ember.Component.extend({
createTopic: Ember.computed.equal('action.type', 'create_topic'), createTopic: Ember.computed.equal('action.type', 'create_topic'),
updateProfile: Ember.computed.equal('action.type', 'update_profile'), updateProfile: Ember.computed.equal('action.type', 'update_profile'),
sendMessage: Ember.computed.equal('action.type', 'send_message'), sendMessage: Ember.computed.equal('action.type', 'send_message'),
addToGroup: Ember.computed.equal('action.type', 'add_to_group'),
disableId: Ember.computed.not('action.isNew'), disableId: Ember.computed.not('action.isNew'),
@computed('currentStepId', 'wizard.save_submissions') @computed('currentStepId', 'wizard.save_submissions')

Datei anzeigen

@ -15,7 +15,13 @@ export default Ember.Component.extend({
@computed() @computed()
presetChoices() { presetChoices() {
return [ return [
{ id: 'categories', name: I18n.t('admin.wizard.field.choices_preset.categories') } {
id: 'categories',
name: I18n.t('admin.wizard.field.choices_preset.categories')
},{
id: 'groups',
name: I18n.t('admin.wizard.field.choices_preset.groups')
}
]; ];
}, },
}); });

Datei anzeigen

@ -204,3 +204,25 @@
allowUserField=true}} allowUserField=true}}
</div> </div>
{{/if}} {{/if}}
{{#if addToGroup}}
<div class="setting">
<div class="setting-label">
<h3>{{i18n "admin.wizard.action.add_to_group.group_selection"}}</h3>
</div>
<div class="setting-value">
{{combo-box value=action.group_id
content=availableFields
nameProperty="label"
none='admin.wizard.select_field'
isDisabled=action.custom_group_enabled}}
<div class="setting-gutter">
{{input type='checkbox' checked=action.custom_group_enabled}}
<span>{{i18n 'admin.wizard.action.add_to_group.custom_group'}}</span>
{{#if action.custom_group_enabled}}
{{input value=action.group_id}}
{{/if}}
</div>
</div>
</div>
{{/if}}

Datei anzeigen

@ -87,6 +87,7 @@ en:
choices_preset: choices_preset:
label: "Preset" label: "Preset"
categories: "Categories" categories: "Categories"
groups: "Groups"
filter: "Preset Filter" filter: "Preset Filter"
choice: choice:
value: "Value" value: "Value"
@ -121,6 +122,11 @@ en:
user_fields: "User Fields: " user_fields: "User Fields: "
wizard_fields: "Wizard Fields: " wizard_fields: "Wizard Fields: "
placeholder: "Insert wizard fields using the field_id in w{}. Insert user fields using field key in u{}." placeholder: "Insert wizard fields using the field_id in w{}. Insert user fields using field key in u{}."
add_to_group:
label: "Add to Group"
group: "Group"
group_selection: "Group Selection"
custom_group: "Custom Group"
custom_title: "Custom Title" custom_title: "Custom Title"
custom_category: custom_category:
label: "Custom Category" label: "Custom Category"

Datei anzeigen

@ -202,9 +202,14 @@ class CustomWizard::Builder
end end
elsif field_template['choices_preset'] && field_template['choices_preset'].length > 0 elsif field_template['choices_preset'] && field_template['choices_preset'].length > 0
objects = [] objects = []
site = Site.new(Guardian.new(@wizard.user))
if field_template['choices_preset'] === 'categories' if field_template['choices_preset'] === 'categories'
objects = Site.new(Guardian.new(@wizard.user)).categories objects = site.categories
end
if field_template['choices_preset'] === 'groups'
objects = site.groups
end end
if field_template['choices_filters'] && field_template['choices_filters'].length > 0 if field_template['choices_filters'] && field_template['choices_filters'].length > 0
@ -404,6 +409,17 @@ class CustomWizard::Builder
end end
end end
def add_to_group(user, action, data)
puts "GROUP NAME: #{data[action['group_id']]}"
if group_id = data[action['group_id']]
puts "GROUP: #{Group.find(group_id)}"
if group = Group.find(group_id)
puts "HERE IS THE GROUP: #{group.inspect}"
group.add(user)
end
end
end
def save_submissions(data, final_step) def save_submissions(data, final_step)
if final_step if final_step
data['submitted_at'] = Time.now.iso8601 data['submitted_at'] = Time.now.iso8601