Browse Source

Add existing profile values to fields associated with profile update actions

Angus McLeod 7 years ago
parent
commit
5d8dce986d
1 changed files with 16 additions and 0 deletions
  1. 16 0
      lib/builder.rb

+ 16 - 0
lib/builder.rb

@@ -61,6 +61,22 @@ class CustomWizard::Builder
                 params[:value] = submission[f['id']] if submission[f['id']]
               end
 
+              if s['actions'].any?
+                profile_actions = s['actions'].select { |a| a['type'] === 'update_profile' }
+                if profile_actions.any?
+                  profile_actions.each do |action|
+                    if update = action['profile_updates'].select { |u| u['key'] === f['id'] }.first
+                      attribute = update['value']
+                      if UserProfile.column_names.include? attribute
+                        params[:value] = UserProfile.find_by(user_id: @wizard.user.id).send(attribute)
+                      elsif User.column_names.include? attribute
+                        params[:value] = User.find(@wizard.user.id).send(attribute)
+                      end
+                    end
+                  end
+                end
+              end
+
               field = step.add_field(params)
 
               if f['type'] === 'dropdown'