Created
April 12, 2012 10:27
-
-
Save pgaertig/2366316 to your computer and use it in GitHub Desktop.
JsonCommand
This file contains hidden or 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
def destroy | |
#... | |
flash[:success] = t("entity_name.delete.success", :name => entity.name) | |
respond_to do |format| | |
format.html do | |
redirect_to :action=>:index | |
end | |
format.json { render :json => { | |
'delete-row'=>dom_id(entity)), | |
'flash-success' => flash.discard[:success]} } | |
end | |
end |
This file contains hidden or 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
JsonCommand = new function() { | |
var self = this; | |
function exec(data) { | |
for(var prop in data) { | |
if(data.hasOwnProperty(prop)) { | |
if(self.hasOwnProperty(prop)) { | |
self[prop](data[prop]); | |
} else { | |
alert('noop'); | |
} | |
} | |
} | |
} | |
this.exec = exec; | |
} | |
JsonCommand['delete-row'] = function(data) { | |
$('#'+data).fadeOut(); | |
} | |
JsonCommand['flash-success'] = function(data) { | |
$.blockUI({ | |
message: data, | |
fadeIn: 700, | |
fadeOut: 700, | |
timeout: 2000, | |
showOverlay: false, | |
centerY: false, | |
css: { | |
width: '350px', | |
top: '10px', | |
left: '', | |
right: '10px', | |
border: 'none', | |
padding: '5px', | |
backgroundColor: 'green', | |
'-webkit-border-radius': '10px', | |
'-moz-border-radius': '10px', | |
opacity: .6, | |
color: '#fff' | |
} | |
}); | |
} | |
$(function() { | |
$('.json-command').closest('form').attr('data-type','json'). | |
bind('ajax:success',function(xhr,data){ | |
JsonCommand.exec(data); | |
}). | |
bind('ajax:error', function(xhr,status, error){ | |
alert("Operation failed: "+error) | |
}); | |
$('.toggler').live('click',function(ev) { | |
$('#'+$(this).attr('id')+'-toggled').toggle(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment