Module: Auth::Concerns::Work::CommunicationControllerConcern

Extended by:
ActiveSupport::Concern
Included in:
Work::CommunicationsController
Defined in:
app/controllers/auth/concerns/work/communication_controller_concern.rb

Instance Method Summary collapse

Instance Method Details

#createObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/auth/concerns/work/communication_controller_concern.rb', line 76

def create
  if @auth_shopping_product
    @auth_work_instruction.communications << @auth_work_communication
    @auth_shopping_product.instructions[@instruction_index] = @auth_work_instruction
    @auth_shopping_product.save
  end
  respond_to do |format|
    format.html do 
      render "show"
    end
    format.json do 
      render :json => @auth_work_communication.to_json
    end
  end
end

#destroyObject



112
113
114
# File 'app/controllers/auth/concerns/work/communication_controller_concern.rb', line 112

def destroy

end

#editObject



96
97
98
# File 'app/controllers/auth/concerns/work/communication_controller_concern.rb', line 96

def edit

end

#indexObject



100
101
102
# File 'app/controllers/auth/concerns/work/communication_controller_concern.rb', line 100

def index

end

#initialize_varsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/auth/concerns/work/communication_controller_concern.rb', line 42

def initialize_vars

  instantiate_work_classes
  
  @auth_work_communication_params = permitted_params.fetch(:communication,{})

  @auth_work_cycle = nil

  @auth_work_instruction = nil

  if @auth_work_communication_params[:cycle_id]
      set_cycle
  elsif @auth_work_communication_params[:instruction_id]
      set_instruction
  else
      not_found("please provide a cycle id or an instruction id")
  end      

  not_found("instruction not found") unless @auth_work_instruction 

  ## if the communication id is found, otherwise instantiate a new communication from the params.
  if params[:id]
    begin
      @auth_work_communication = @auth_work_communication_class.find(params[:id])
    rescue Mongoid::Errors::DocumentNotFound
      @auth_work_communication = @auth_work_communication_class.new(@auth_work_communication_params)  
    end
  else
    @auth_work_communication = @auth_work_communication_class.new(@auth_work_communication_params)
  end


end

#newObject



92
93
94
# File 'app/controllers/auth/concerns/work/communication_controller_concern.rb', line 92

def new
  
end

#permitted_paramsObject



116
117
118
# File 'app/controllers/auth/concerns/work/communication_controller_concern.rb', line 116

def permitted_params
	pr = params.permit({:communication => [:send_email,:email_template_path,:method_to_determine_recipients,:repeat,:repeat_times,:method_to_determine_communication_timing,:enqueue_at_time,:instruction_id,:cycle_id,:cart_item_id, :product_id, :name, :description]}, :id)
end

#set_cycleObject



37
38
39
# File 'app/controllers/auth/concerns/work/communication_controller_concern.rb', line 37

def set_cycle

end

#set_instructionObject



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
# File 'app/controllers/auth/concerns/work/communication_controller_concern.rb', line 5

def set_instruction
  if product_id = @auth_work_communication_params[:product_id]
    if instruction_id = @auth_work_communication_params[:instruction_id]
      if @auth_shopping_product = Auth.configuration.product_class.constantize.find(product_id)
        @auth_work_instruction = nil
        @instruction_index = 0
        @auth_shopping_product.instructions.each do |inst|
          if inst.id.to_s == instruction_id
            @auth_work_instruction = inst
            break
          end
          @instruction_index+=1
        end
      end
    end
  elsif cart_item_id = @auth_work_communication_params[:cart_item_id]
    if instruction_id = @auth_work_communication_params[:instruction_id]
      if @auth_shopping_cart_item = Auth.configuration.cart_item_class.constantize.find(cart_item_id)
        @auth_work_instruction = nil
        @instruction_index = 0
        @auth_shopping_cart_item.instructions.each do |inst|
          if inst.id.to_s == instruction_id
            @auth_work_instruction = inst
            break
          end
          @instruction_index+=1
        end
      end
    end
  end
end

#showObject



108
109
110
# File 'app/controllers/auth/concerns/work/communication_controller_concern.rb', line 108

def show

end

#updateObject



104
105
106
# File 'app/controllers/auth/concerns/work/communication_controller_concern.rb', line 104

def update
  ## now this still needs to be coded but will come to that later.
end