Class: Quby::AnswersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/quby/answers_controller.rb

Constant Summary collapse

DISPLAY_MODES =
%w(paged bulk single_page).freeze

Instance Method Summary collapse

Instance Method Details

#bad_authorization(exception) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'app/controllers/quby/answers_controller.rb', line 82

def bad_authorization(exception)
  if @return_url
    redirect_to return_url(status: 'error', error: exception.class.to_s)
  else
    @error = "U probeert een vragenlijst te openen waar u geen toegang toe heeft op dit moment."
    render template: 'quby/errors/generic', layout: 'quby/dialog'
    handle_exception exception
  end
end

#bad_questionnaire(exception) ⇒ Object



92
93
94
95
96
97
98
99
# File 'app/controllers/quby/answers_controller.rb', line 92

def bad_questionnaire(exception)
  if @return_url
    redirect_to return_url(status: 'error', error: exception.class.to_s)
  else
    @error = exception
    render template: "quby/errors/questionnaire_not_found", layout: "quby/dialog", status: 404
  end
end

#bad_questionnaire_definition(exception) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/quby/answers_controller.rb', line 101

def bad_questionnaire_definition(exception)
  if Quby.show_exceptions
    render action: :show_questionnaire_errors
  elsif @return_url
    redirect_to return_url(status: 'error', error: exception.class.to_s)
    handle_exception exception
  else
    @error = "Er is iets mis met de vragenlijst zoals deze in ons systeem is ingebouwd."
    render template: 'quby/errors/generic', layout: 'quby/dialog'
    handle_exception exception
  end
end

#editObject



40
41
42
43
# File 'app/controllers/quby/answers_controller.rb', line 40

def edit
  default_to_textvar_values(@answer)
  render versioned_template_options(@display_mode)
end

#pdfObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/quby/answers_controller.rb', line 62

def pdf
  if defined?(Appsignal) && on_ios_safari?
    session[:has_downloaded_pdf_for] = @answer.id
    Appsignal.increment_counter("ios_safari_downloaded_pdf", 1)
  end

  update_or_fail do
    template_string = render_to_string versioned_template_options("print", layout: "pdf")
    begin
      pdf_binary = Quby::PdfRenderer.render_pdf(template_string)
      # type is not a application/pdf, to prevent previews on ios
      send_data pdf_binary, filename: "#{@questionnaire.title} #{Time.zone.now.to_fs(:filename)}.pdf",
                          type: 'application/octet-stream', disposition: :attachment
    rescue StandardError
      flash.now[:notice] = I18n.t('pdf_download_failed_message')
      render versioned_template_options(@display_mode, layout: request.xhr? ? "content_only" : 'application')
    end
  end
end

#showObject



36
37
38
# File 'app/controllers/quby/answers_controller.rb', line 36

def show
  redirect_to action: "edit"
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/quby/answers_controller.rb', line 45

def update
  if session[:has_downloaded_pdf_for] == @answer.id && defined?(Appsignal) && on_ios_safari?
    Appsignal.increment_counter("ios_safari_downloaded_pdf_and_pressed_done", 1)
  end

  update_or_fail do
    if @return_url.blank?
      render versioned_template_options("completed", layout: request.xhr? ? "content_only" : 'application')
    else
      redirect_url = return_url(status: 'updated', go: form_action)
      request.xhr? ?
        render(js: "window.location = '#{redirect_url}'") :
        redirect_to(redirect_url)
    end
  end
end