Sha256: 0c69ed3a115b9deed0cabd2952c2cbb393856ad8b06a651fed5f89f42a327f90

Contents?: true

Size: 1.58 KB

Versions: 13

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true
module ContentProviders
  # Provides a form for a Participant to compose a new Message.
  class NewMessageFormProvider < BitCore::ContentProvider
    def render_current(options)
      view = options.view_context
      authorize! options.participant, view
      view.render(
        template: "think_feel_do_engine/messages/new",
        locals: {
          compose_path: view.params[:compose_path],
          create_path: view.participant_data_path,
          message: message_for_reply(options),
          new_message: message(options.participant),
          recipient: view.params[:recipient],
          recipient_id: view.params[:recipient_id],
          recipient_type: view.params[:recipient_type],
          subject: view.params[:subject],
          tool: content_module.tool
        }
      )
    end

    def data_class_name
      "Message"
    end

    def data_attributes
      [:body, :recipient_id, :recipient_type, :subject]
    end

    def show_nav_link?
      false
    end

    private

    def message_for_reply(options)
      if options.view_context.params[:message_id]
        options
          .participant
          .received_messages
          .find(options.view_context.params[:message_id])
      end
    end

    def message(participant)
      coach = participant.coach

      participant.sent_messages.build(
        recipient_id: coach.id,
        recipient_type: coach.class.to_s
      )
    end

    def authorize!(participant, view)
      unless participant.active_membership.present?
        view.controller.redirect_to view.root_url
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
think_feel_do_engine-3.22.9 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.22.8 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.22.7 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.22.6 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.22.5 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.22.4 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.22.2 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.22.1 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.22.0 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.21.2 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.21.1 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.21.0 app/models/content_providers/new_message_form_provider.rb
think_feel_do_engine-3.20.1 app/models/content_providers/new_message_form_provider.rb