Class: Naf::ApplicationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/naf/applications_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/naf/applications_controller.rb', line 45

def create
  @application = Naf::Application.new(params[:application])
  check_application_run_group_name
  set_application_run_group_name
  if @application.save
    app_schedule = @application.application_schedule
    @application.update_attributes(params[:application])
    if app_schedule.present?
      prerequisites =
      app_schedule.prerequisites.map do |prerequisite|
        prerequisite.title
      end.join(', ')
    end
    redirect_to(@application,
                notice: "Application #{@application.title} was successfully created. #{'Prerequisites: ' + prerequisites if app_schedule.try(:prerequisites).try(:present?) }")
  else
    set_shown_schedule_and_prerequisite
    @application.build_application_schedule unless params[:application].try(:[], :application_schedule_attributes).try(:[], :_destroy) == "0"
    render action: "new"
  end
end

#editObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/naf/applications_controller.rb', line 67

def edit
  @application = Naf::Application.find(params[:id])
  check_application_run_group_name
  app_schedule = @application.application_schedule
  if app_schedule.blank?
    build_app_schedule = @application.build_application_schedule
    build_app_schedule.application_schedule_prerequisites.build
  else
    @show_app_schedule = true
    if app_schedule.application_schedule_prerequisites.blank?
      app_schedule.application_schedule_prerequisites.build
    else
      @show_prerequisite = true
    end
  end
end

#indexObject



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
# File 'app/controllers/naf/applications_controller.rb', line 7

def index
  respond_to do |format|
    format.html
    format.json do
      set_page

      applications = []
      application = []
      params[:search][:visible] = params[:search][:visible] ? false : true
      params[:search][:deleted] = params[:search][:deleted] ? false : "false"
      @total_records = Naf::Application.count(:all)
      Logical::Naf::Application.search(params[:search]).map(&:to_hash).map do |hash|
        hash.map do |key, value|
          value = '' if value.nil?
          application << value
        end
        applications << application
        application =[]
      end
      @total_display_records = applications.count
      @applications = applications.paginate(page: @page, per_page: @rows_per_page)

      render layout: 'naf/layouts/jquery_datatables'
    end
  end
end

#newObject



39
40
41
42
43
# File 'app/controllers/naf/applications_controller.rb', line 39

def new
  @application = Naf::Application.new
  app_schedule = @application.build_application_schedule
  app_schedule.application_schedule_prerequisites.build
end

#showObject



34
35
36
37
# File 'app/controllers/naf/applications_controller.rb', line 34

def show
  @application = Naf::Application.find(params[:id])
  @logical_application = Logical::Naf::Application.new(@application)
end

#updateObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/naf/applications_controller.rb', line 84

def update
  @application = Naf::Application.find(params[:id])
  set_application_run_group_name
  if @application.update_attributes(params[:application])
    app_schedule = @application.application_schedule
    if app_schedule.present?
      prerequisites =
      app_schedule.prerequisites.map do |prerequisite|
        prerequisite.title
      end.join(', ')
    end
    redirect_to(@application,
                notice: "Application #{@application.title} was successfully updated. #{'Prerequisites: ' + prerequisites if app_schedule.try(:prerequisites).try(:present?) }")
  else
    set_shown_schedule_and_prerequisite
    render action: "edit"
  end
end