cirandas.net

ref: master

plugins/networks/controllers/myprofile/networks_plugin_node_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
50
51
52
53
54
55
56
57
58
59
60
61
class NetworksPluginNodeController < MyProfileController

  include NetworksPlugin::TranslationHelper

  before_filter :load_node, :only => [:associate]

  helper NetworksPlugin::DisplayHelper

  def associate
    @new_node = NetworksPlugin::Node.new((params[:node] || {}).merge(:environment => environment, :parent => @node))

    if params[:commit]
      @new_node.save
    else
      respond_to{ |format| format.html{ render :layout => false } }
    end
  end

  def edit
    @node = NetworksPlugin::Node.find params[:id]

    if request.patch?
      @node.update params[:profile_data]
      @node.home_page.update params[:home_page]
      session[:notice] = t('controllers.node.edit')
      redirect_to :controller => :networks_plugin_network, :action => :structure, :node_id => @node.parent.id
    end
  end

  def destroy
    @node = NetworksPlugin::Node.find params[:id]
    @node.destroy

    @node.parent.reload
    @node = @node.parent
  end

  def orders_management
    @node = NetworksPlugin::Node.find params[:id]
    @managers = environment.people.find params[:orders_managers].to_a
    @role = Profile::Roles.orders_manager environment

    @node.networks_settings.orders_forward = params[:orders_forward]
    @node.save

    @node.role_assignments.where(:role_id => @role.id).each{ |ra| ra.destroy }
    @managers.each do |manager|
      RoleAssignment.create! :role => @role, :resource => @node, :accessor => manager
    end

    redirect_to :action => :edit, :id => @node.id
  end

  protected

  def load_node
    @network = profile
    @node = NetworksPlugin::Node.find_by_id(params[:id]) || @network
  end

end