Skip to content

Instantly share code, notes, and snippets.

@girishso
Created June 21, 2010 17:26
Show Gist options
  • Save girishso/447172 to your computer and use it in GitHub Desktop.
Save girishso/447172 to your computer and use it in GitHub Desktop.
$(function() {
$('#add_new').click(function() {
TopUp.display($('#topup_div'),
{type: 'dom', title: 'New Todo',
overlayClose: 1, resizable: 0, shaded: 1});
});
$('#topup_frm').submit(function() {
$.post(this.action, $(this).serialize(), null, "script");
return false;
});
// Setup the ajax indicator
$("body").append('<div id="ajaxBusy"><p><img src="/images/loading.gif"></p></div>');
$('#ajaxBusy').css({
display:"none",
margin:"0px",
paddingLeft:"0px",
paddingRight:"0px",
paddingTop:"0px",
paddingBottom:"0px",
position:"fixed",
right:"1px",
top:"1px",
width:"auto"
});
// Ajax activity indicator bound
// to ajax start/stop document events
$(document).ajaxStart(function(){
$('#ajaxBusy').show();
}).ajaxStop(function(){
$('#ajaxBusy').hide();
});
$.ajaxSetup({
error:function(x,e){
if(x.status==0){
alert('You are offline!!\n Please Check Your Network.');
}else if(x.status==404){
$.achtung( {message: 'Error: Requested URL not found.', className: 'achtungFail', timeout: 0} );
}else if(x.status==500){
$.achtung( {message: 'Error: Internel Server Error.', className: 'achtungFail', timeout: 0} );
}else if(e=='parsererror'){
$.achtung( {message: 'Error: Parsing JSON Request failed.', className: 'achtungFail', timeout: 0} );
}else if(e=='timeout'){
$.achtung( {message: 'Error: Request Time Out.', className: 'achtungFail', timeout: 0} );
}else {
$.achtung( {message: 'Error: ' + x.responseText, className: 'achtungFail', timeout: 0} );
}
}
});
});
var elem = "<tr><td><%= @todo.txt -%></td></tr>";
$(elem).insertBefore("#todo_tbl tr:first-child")
<a href='#' id='add_new'>Add new</a>
<table id='todo_tbl'>
<tr>
<td>Todo 1</td>
</tr>
<tr>
<td>Todo 2</td>
</tr>
<tr>
<td>Todo 3</td>
</tr>
</table>
<div id='topup_div'>
<% form_for Todo.new, :html => {:id= > 'topup_frm'} do |f| %>
<%= f.text_field 'text' %>
<%= f.submit 'Save' %>
<% end %>
</div>
def create
@todo = Todo.new(params[:todo])
if @todo.save
respond_to do |fmt|
fmt.js
end
else
respond_to do |fmt|
fmt.js { render :js => 'alert("Error saving todo.");'}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment