Class: SurveyorGui::DependencysController

Inherits:
ApplicationController show all
Defined in:
app/controllers/surveyor_gui/dependencys_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 19

def create
  @question = Question.new(question_params)
  if @question.save
    redirect_to :back
  else
    render :action => 'new', :layout => 'surveyor_gui/surveyor_gui_blank'
  end
end

#destroyObject



47
48
49
50
51
52
53
54
55
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 47

def destroy
  question = Question.find(params[:id])
  if question.part_of_group?
    question.question_group.dependency.destroy
  else
    question.dependency.destroy
  end
  render :nothing=>true
end

#editObject



14
15
16
17
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 14

def edit
  prep_variables
  @title = "Edit Logic for Question "+@this_question
end

#get_answersObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 75

def get_answers    
  options=""
  question_id               = params[:question_id]
  question                  = Question.find(question_id)
  column_id                 = params[:column_id].blank? ? _default_column_id(question) : params[:column_id]
  dependency_condition_id   = params[:dependency_condition_id]
  dependency_condition      = dependency_condition_id.blank? ? nil : DependencyCondition.find(dependency_condition_id)
  if question && question.answers
    question.answers.where('column_id = ? OR column_id IS NULL',column_id.to_i).each_with_index do |a, index|
      options += '<option ' + _get_selected_answer(index, dependency_condition, a, column_id) +
       'value="' + a.id.to_s + '"' +
       '>'+a.text.to_s+"</option>"
    end
  end
  render :inline=>options
end

#get_columnsObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 92

def get_columns
  options=""
  question_id               = params[:question_id]
  dependency_condition_id   = params[:dependency_condition_id]
  dependency_condition      = dependency_condition_id.blank? ? nil : DependencyCondition.find(dependency_condition_id)
  question = Question.find(question_id)
  if question && question.question_group
    question.question_group.columns.each_with_index do |c, index|
      options += '<option ' +
       _get_selected_column(index, dependency_condition, c) +
       'value="' + c.id.to_s + '"' +
       '>'+c.text.to_s+"</option>"
    end
  end
  render :inline=>options
end

#get_question_typeObject



109
110
111
112
113
114
115
116
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 109

def get_question_type
  question_id =  params[:question_id]
  question = Question.find(question_id)
  response=question.pick
  response += ','+question.question_type_id.to_s
  response += ','+question_id
  render :inline=>response
end

#newObject



4
5
6
7
8
9
10
11
12
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 4

def new
  prep_variables
  @title = "Add Logic for "+@this_question
  if @question.part_of_group?
    @question.question_group.build_dependency(:rule=>'A')
  else
    @question.build_dependency(:rule=>'A')
  end
end

#render_dependency_conditions_partialObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 57

def render_dependency_conditions_partial
  prep_variables
  @question_or_group = @question.part_of_group? ? @question.question_group : @question
  @dependency = Dependency.find(params[:dependency_id]) if !params[:dependency_id].blank?
  if @dependency.nil?
    @question_or_group.build_dependency(:rule=>'A').dependency_conditions.build()
  end
  if @question_or_group.dependency.dependency_conditions.empty?
    @question_or_group.dependency.dependency_conditions.build()
  else
    if params[:add_row]
      @question_or_group = eval(@question_or_group.class.name).new
      @question_or_group.build_dependency.dependency_conditions.build()
    end
  end
  render :partial => 'dependency_condition_fields'
end

#updateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 28

def update
  @title = "Update Question"
  @question = Question.includes(:answers).find(params[:id])
  if @question.part_of_group?
    update_object = @question.question_group
    update_params = question_group_params
  else
    update_object = @question
    update_params = question_params
  end
  if update_object.update_attributes(update_params)
    update_object.dependency.destroy if update_object.dependency.dependency_conditions.blank?
    render :blank, :layout => 'surveyor_gui/surveyor_gui_blank'
  else
    prep_variables
    render :action => 'edit', :layout => 'surveyor_gui/surveyor_gui_blank'
  end
end