Class: ErpApp::Desktop::UserManagement::ApplicationManagementController

Inherits:
BaseController show all
Defined in:
app/controllers/erp_app/desktop/user_management/application_management_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#delete, #get_details, #index, #new

Methods inherited from BaseController

#index

Instance Method Details

#available_applicationsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/erp_app/desktop/user_management/application_management_controller.rb', line 6

def available_applications
     user_id            = params[:user_id]
     app_container_type = params[:app_container_type]

     user = User.find(user_id)
     app_container = "::#{app_container_type}".constantize.find_by_user(user)
     applications  = "#{app_container_type}Application".constantize.all

     current_applications = app_container.applications
     applications.delete_if{|r| current_applications.collect(&:id).include?(r.id)}

     render :json => applications.map{|application| {:text => application.description, :app_id => application.id, :iconCls => application.icon, :leaf => true}}
end

#current_applicationsObject



20
21
22
23
24
25
26
27
28
# File 'app/controllers/erp_app/desktop/user_management/application_management_controller.rb', line 20

def current_applications
     user_id            = params[:user_id]
     app_container_type = params[:app_container_type]

     user = User.find(user_id)
     app_container = "::#{app_container_type}".constantize.find_by_user(user)
     
     render :json => app_container.applications.map{|application| {:text => application.description, :app_id => application.id, :iconCls => application.icon, :leaf => true}}
end

#save_applicationsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/erp_app/desktop/user_management/application_management_controller.rb', line 30

def save_applications
     app_ids            = params[:app_ids]
     user_id            = params[:user_id]
     app_container_type = params[:app_container_type]

     user = User.find(user_id)
     app_container = "::#{app_container_type}".constantize.find_by_user(user)
     app_container.applications = []
     app_container.save

     unless app_ids.blank?
       app_ids.each do |app_id|
         app_container.applications << Application.find(app_id)
       end
     end
     app_container.save
				
     render :json => {:success => true, :message => 'Application(s) Saved'}
end