Module: OpenFlashChart::View
- Defined in:
- lib/plugins/open_flash_chart/lib/open_flash_chart/ofc_ajax.rb
Instance Method Summary (collapse)
- - (Object) findSWF_method
- - (Object) js_open_flash_chart_object(div_name, width, height, base = "/", options = {})
- - (Object) link_to_ofc_load(link_text, div_name)
- - (Object) link_to_remote_ofc_load(link_text, div_name, url)
- - (Object) periodically_call_function(function, options = {})
- - (Object) periodically_call_to_remote_ofc_load(div_name, url, options = {})
- - (Object) save_as_image(post_url, options = {})
- - (Object) to_open_flash_chart_data(id = "in", options = {})
Instance Method Details
- (Object) findSWF_method
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/plugins/open_flash_chart/lib/open_flash_chart/ofc_ajax.rb', line 67 def findSWF_method <<-OUTPUT function findSWF(movieName) { if (navigator.appName.indexOf("Microsoft")!= -1) { return window[movieName]; } else { return document[movieName]; } } OUTPUT end |
- (Object) js_open_flash_chart_object(div_name, width, height, base = "/", options = {})
9 10 11 12 13 14 15 16 17 |
# File 'lib/plugins/open_flash_chart/lib/open_flash_chart/ofc_ajax.rb', line 9 def js_open_flash_chart_object(div_name, width, height, base="/", ={}) <<-OUTPUT <script type="text/javascript"> swfobject.embedSWF("#{base}#{[:open_flash_chart_swf] || "open-flash-chart.swf"}", "#{div_name}", "#{width}", "#{height}", "9.0.0", "expressInstall.swf", {"get-data":"open_flash_chart_data_#{div_name}"}); </script> #{self.to_open_flash_chart_data(div_name)} <div id="#{div_name}"></div> OUTPUT end |
- (Object) link_to_ofc_load(link_text, div_name)
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/plugins/open_flash_chart/lib/open_flash_chart/ofc_ajax.rb', line 19 def link_to_ofc_load(link_text, div_name) data_name = "#{link_text.gsub(" ","_")}_#{div_name.gsub(" ","_")}" <<-OUTPUT <script type="text/javascript"> function load_#{data_name}() { tmp_#{div_name} = findSWF("#{div_name}"); x = tmp_#{div_name}.load(Object.toJSON(data_#{data_name})); } var data_#{data_name} = #{self.render}; </script> #{ActionView::Base.new.link_to_function link_text, "load_#{data_name}()"} OUTPUT end |
- (Object) link_to_remote_ofc_load(link_text, div_name, url)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/plugins/open_flash_chart/lib/open_flash_chart/ofc_ajax.rb', line 33 def link_to_remote_ofc_load(link_text, div_name, url) fx_name = "#{link_text.gsub(" ","_")}_#{div_name.gsub(" ","_")}" <<-OUTPUT <script type="text/javascript"> function reload_#{fx_name}() { tmp_#{div_name} = findSWF("#{div_name}"); new Ajax.Request('#{url}', { method : 'get', onSuccess : function(obj) {tmp_#{div_name}.load(obj.responseText);}, onFailure : function(obj) {alert("Failed to request #{url}");}}); } </script> #{ActionView::Base.new.link_to_function link_text, "reload_#{fx_name}()"} OUTPUT end |
- (Object) periodically_call_function(function, options = {})
3 4 5 6 7 |
# File 'lib/plugins/open_flash_chart/lib/open_flash_chart/ofc_ajax.rb', line 3 def periodically_call_function(function, = {}) frequency = [:frequency] || 10 # every ten seconds by default code = "new PeriodicalExecuter(function() {#{function}}, #{frequency})" ActionView::Base.new.javascript_tag(code) end |
- (Object) periodically_call_to_remote_ofc_load(div_name, url, options = {})
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/plugins/open_flash_chart/lib/open_flash_chart/ofc_ajax.rb', line 49 def periodically_call_to_remote_ofc_load(div_name, url, ={}) fx_name = "#{div_name.gsub(" ","_")}" # fix a bug in rails with url_for url = url.gsub("&","&") <<-OUTPUT <script type="text/javascript"> function reload_#{fx_name}() { tmp_#{div_name} = findSWF("#{div_name}"); new Ajax.Request('#{url}', { method : 'get', onSuccess : function(obj) {tmp_#{div_name}.load(obj.responseText);}, onFailure : function(obj) {alert("Failed to request #{url}");}}); } </script> #{periodically_call_function("reload_#{fx_name}()", )} OUTPUT end |
- (Object) save_as_image(post_url, options = {})
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/plugins/open_flash_chart/lib/open_flash_chart/ofc_ajax.rb', line 95 def save_as_image(post_url, ={}) id = [:id] || "in" <<-OUTPUT <script type="text/javascript"> #{findSWF_method} function post_image(debug) { url = '#{post_url}'; var ofc = findSWF('#{id}'); x = ofc.post_image( url, '#{[:post_image_callback_method]}', debug ); } function ofc_ready() { #{[:ofc_ready_callback_method]}; } </script> OUTPUT end |
- (Object) to_open_flash_chart_data(id = "in", options = {})
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/plugins/open_flash_chart/lib/open_flash_chart/ofc_ajax.rb', line 79 def to_open_flash_chart_data(id="in", ={}) # this builds the open_flash_chart_data js function <<-OUTPUT <script type="text/javascript"> function ofc_ready() { #{[:ofc_ready_callback_method]}; } function open_flash_chart_data_#{id}() { return Object.toJSON(data_#{id}); } #{findSWF_method} var data_#{id} = #{self.render}; </script> OUTPUT end |