cirandas.net

ref: master

plugins/orders/controllers/myprofile/orders_plugin_message_controller.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class OrdersPluginMessageController < MyProfileController

  #protect 'edit_profile', :profile

  include OrdersPlugin::TranslationHelper

  helper OrdersPlugin::TranslationHelper
  helper OrdersPlugin::FieldHelper

  def new_to_admins
    @member = user
    if params[:commit]
      OrdersPlugin::Mailer.message_to_admins(profile, @member, params[:email][:subject], params[:email][:message]).deliver
      page_reload
    end
  end

  def new_to_supplier
    @order = profile.purchases.find params[:order_id]
    @supplier = @order.profile
    if params[:commit]
      options = {order: @order, include_order: params[:include_order]}
      OrdersPlugin::Mailer.message_to_supplier(profile, @supplier, params[:email][:subject], params[:email][:message], options).deliver
      page_reload
    end
  end

  def new_to_consumer
    @order = profile.sales.find params[:order_id]
    if params[:commit]
      options = {order: @order, include_order: params[:include_order]}
      OrdersPlugin::Mailer.message_to_consumer(profile, @order.consumer, params[:email][:subject], params[:email][:message], options).deliver
      page_reload
    end
  end

  protected

  def page_reload
    session[:notice] = t'orders_cycle_plugin.controllers.myprofile.message_controller.message_sent'
    respond_to do |format|
      format.js { render partial: 'orders_plugin_shared/pagereload' }
    end
  end

  extend HMVC::ClassMethods
  hmvc OrdersPlugin

end