Created
January 12, 2013 04:43
-
-
Save rmahnovetsky/4516155 to your computer and use it in GitHub Desktop.
Apotomo ajax widget example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Apotomo | |
class AjaxWidget < Apotomo::Widget | |
responds_to_event :ajax_display | |
def display | |
render :view => :display | |
end | |
def ajax_display | |
render :text => "To be overridden" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= widget_div :id => "portlet-#{widget_id}" do %> | |
<div class="section"> | |
<%= image_tag "loading.gif" %> | |
</div> | |
<% end %> | |
<script> | |
$(document).ready(function () { | |
$.ajax({ | |
url: '<%= url_for_event(:ajax_display) %>', | |
dataType: 'html' | |
}).done(function(data, textStatus, jqXHR) { | |
$("#<%="portlet-#{widget_id}"%>").find(".section").html(data); | |
}).fail(function() { | |
$("#<%="portlet-#{widget_id}"%>").find(".section").html("error retrieving section"); | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SiteTrafficWidget < Apotomo::AjaxWidget | |
def ajax_display | |
render :text => "Yey it works" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment