Module: PrintControl
- Extended by:
- ActiveSupport::Concern
- Included in:
- AbstractResourcesController
- Defined in:
- app/controllers/concerns/print_control.rb
Instance Method Summary collapse
-
#display_print_result ⇒ Object
send HTML or PDF down the wire.
-
#download_print_result ⇒ Object
send PDF down the wire.
-
#email_print_result ⇒ Object
send PDF via email.
-
#print ⇒ Object
print this view - let the Class handle everything returning either the ID to a print_job or false (in which case something went terribly wrong).
- #print_print_result ⇒ Object
-
#print_resources ⇒ Object
print_resources will try to add a print_job return error code.
Instance Method Details
#display_print_result ⇒ Object
send HTML or PDF down the wire
107 108 109 110 111 112 113 114 |
# File 'app/controllers/concerns/print_control.rb', line 107 def display_print_result params[:print][:output_type] ||= 'html' case params[:print][:output_type].downcase # when 'html'; render params[:print][:view_template_path], layout: 'print' when 'html'; render "stock_items/print/_stock_items_list", layout: 'print' when 'pdf'; render action: :new, status: :unprocessable_entity end end |
#download_print_result ⇒ Object
send PDF down the wire
119 120 121 |
# File 'app/controllers/concerns/print_control.rb', line 119 def download_print_result params[:print][:output_type] ||= 'pdf' end |
#email_print_result ⇒ Object
send PDF via email
126 127 128 129 130 131 132 133 134 135 |
# File 'app/controllers/concerns/print_control.rb', line 126 def email_print_result params[:print][:output_type] ||= 'pdf' if params[:print][:email_to].blank? flash[:error] = t('output.email.email_address_missing') return 301 else flash[:info] = t('output.email.email_sent') return 200 end end |
#print ⇒ Object
print this view - let the Class handle everything returning either the ID to a print_job or false (in which case something went terribly wrong)
always an Ajax call - hence will always update the print_jobs link with ‘yellow’-blink POST /printers/print.js params holds records to be printed
from the print-dialog:
from a link tag
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/concerns/print_control.rb', line 75 def print resource, :print? if resources.any? params[:printed_by] = current_user || User.first params[:print] ||= {} params[:print][:collation] ||= 'list' params[:print_job] ||= {} # params[:print_job][:view_template] ||= current_user.account.find_print_template(params[:print][:template]) || Template.new( template_path: 'list.html.haml') # params[:print_job][:print_driver] = params[:print][:print_driver] || params[:print_job][:view_template].template_print_driver # params[:print_job][:paper] = params[:print_job][:view_template].template_paper || params[:print][:paper] || "A4" params[:print_job][:paper] = params[:print][:paper] || "A4" # # ok so we have items to print! status = case params[:print][:medium] when "display" ; display_print_result and return when "email" ; email_print_result when "printer" ; print_print_result when "download" ; download_print_result and return else flash[:error] = t('output.medium.no_medium_found'); 301 end end render :print, layout: false, status: status and return rescue Exception => e scoop_from_error e end |
#print_print_result ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'app/controllers/concerns/print_control.rb', line 137 def print_print_result params[:print][:output_type] ||= 'pdf' if (result = print_resources) > 0 flash[:info] = t(:resources_printed_correct) status = 200 else case result when NOQUEUE; flash[:error] = t(:noqueue_created) when NOUSER; flash[:error] = t(:no_user_present) when PRINTRECERROR; flash[:error] = t(:printing_record_error) when PRINTCMDERROR; flash[:error] = t(:print_command_error) when PRINTLISTERROR; flash[:error] = t(:printing_list_error) when PRINTEXCEPTION ; flash[:error] = t(:exception_in_print_engine) end status = 301 end status end |
#print_resources ⇒ Object
print_resources will try to add a print_job return error code
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'app/controllers/concerns/print_control.rb', line 160 def print_resources if resource_class == PrintJob resources.each do |res| return NOQUEUE unless Delayed::Job.enqueue res, :queue => 'printing' end return PRINTSUCCESS else return NOUSER if params[:printed_by].nil? case params[:print][:collation] when 'record' if params[:print][:cmd].blank? resources.each do |res| return PRINTRECERROR unless res.print_record params.merge context: self end else resources.each do |res| return PRINTCMDERROR unless res.send(params[:print][:cmd],params) end end when 'list' params[:resources] = resources return PRINTLISTERROR unless resource_class.print_list( params ) end end return PRINTSUCCESS end |