Module: PrintsHelper

Defined in:
app/helpers/prints_helper.rb

Instance Method Summary collapse

Instance Method Details

#record_print(printable, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/prints_helper.rb', line 2

def record_print(printable,options={})
  options.reverse_merge!({
    :remote => true
  })
  
  if options[:remote]
    '<script>      
    (function(){
      var ua = navigator.userAgent.toLowerCase();
      if (!window.ActiveXObject) {
        request = new XMLHttpRequest();
      } else if (ua.indexOf("msie 5") == -1) {
        request = new ActiveXObject("Msxml2.XMLHTTP");
      } else {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      var params = {};
      request.open("POST", "'+printable.class.name.underscore.pluralize+'/'+printable.id.to_s+'/prints.json");
      request.send(params);
    }());
    </script>'.html_safe
  end
end