 # Place all the behaviors and hooks related to the matching controller here.
 # All this logic will automatically be available in application.js.
 # You can use CoffeeScript in this file: http://coffeescript.org/
+printer_local_storage_key = "last-printer-used"
 
 $ ->
+  printer_name = localStorage.getItem(printer_local_storage_key)
+  if (printer_name)
+    $('#print_printer').val printer_name
+
   if $('#print_printer').length
     $('#print_printer').chosen
       no_results_text: 'No matches'



    $('.printer-list').on 'click', '.set-printer', ->
      console.log(this.textContent)
      $('#print_printer').val this.textContent
      $('#print_printer').trigger 'chosen:updated'
      $('#print_printer').trigger 'change'

    $('#print_printer').on 'change', ->
      selected = $ 'option:selected', this
      setMedia selected.data('media').split(' ')
      printer_name = selected["0"].textContent
      localStorage.setItem(printer_local_storage_key, printer_name)

    setMedia $('#print_printer option:selected').data('media').split(' ')

