Permalink
Browse files

formatting for js methods and save_as_image setup method

  • Loading branch information...
Charles J Snider
Charles J Snider committed Jan 6, 2010
1 parent 4fa8356 commit 14ff9735c67e9b424caa129e8e06dc910e73681f
Showing with 92 additions and 66 deletions.
  1. +92 −66 lib/open_flash_chart/ofc_ajax.rb
@@ -8,83 +8,109 @@ def periodically_call_function(function, options = {})
def js_open_flash_chart_object(div_name, width, height, base="/")
<<-OUTPUT
<script type="text/javascript">
swfobject.embedSWF("#{base}open-flash-chart.swf", "#{div_name}", "#{width}", "#{height}", "9.0.0", "expressInstall.swf", {"get-data":"open_data_#{div_name}"});
</script>
#{self.to_open_flash_chart_data(div_name)}
<div id="#{div_name}"></div>
<script type="text/javascript">
swfobject.embedSWF("#{base}open-flash-chart.swf", "#{div_name}", "#{width}", "#{height}", "9.0.0", "expressInstall.swf", {"get-data":"open_data_#{div_name}"});
</script>
#{self.to_open_flash_chart_data(div_name)}
<div id="#{div_name}"></div>
OUTPUT
end
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
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
<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
def periodically_call_to_remote_ofc_load(div_name, url, options={})
fx_name = "#{div_name.gsub(" ","_")}"
# fix a bug in rails with url_for
url = url.gsub("&amp;","&")
<<-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}()", options)}
OUTPUT
end
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
def periodically_call_to_remote_ofc_load(div_name, url, options={})
fx_name = "#{div_name.gsub(" ","_")}"
# fix a bug in rails with url_for
url = url.gsub("&amp;","&")
<<-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}()", options)}
OUTPUT
end
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() {
}
function open_flash_chart_data_#{id}() {
return Object.toJSON(data_#{id});
}
function findSWF(movieName) {
if (navigator.appName.indexOf("Microsoft")!= -1) {
return window[movieName];
} else {
return document[movieName];
def findSWF_method
<<-OUTPUT
function findSWF(movieName) {
if (navigator.appName.indexOf("Microsoft")!= -1) {
return window[movieName];
} else {
return document[movieName];
}
}
}
var data_#{id} = #{self.render};
</script>
OUTPUT
end
def to_open_flash_chart_data(id="in", options={})
# this builds the open_flash_chart_data js function
<<-OUTPUT
<script type="text/javascript">
function ofc_ready() {
#{options[: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
def save_as_image(post_url, options={})
id = options[: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, '#{options[:post_image_callback_method]}', debug );
}
function ofc_ready() {
#{options[:ofc_ready_callback_method]};
}
</script>
OUTPUT
end
end
end

0 comments on commit 14ff973

Please sign in to comment.