Si necesitamos realizar el cambio de estado de un registro mediante Ajax, Jquery podemos utilizar lo siguiente:
JQuery
$("body").on("click", ".userStatus", function(){
/**/
var status_new = 0;
if( $(this).is(':checked') ){
status_new = 1;
}else{
status_new = 0;
}
/**/
$div = $(this).parent().parent().parent();
/**/
$($div).css("width", "20px");
$($div).css("height", "20px");
$($div).css('background-image', 'url(http://blog.juliopari.com/wp-content/uploads/2013/06/ajax-loader-.gif)');
$($div).css('background-size', '20px');
$($div).empty();
/**/
$.post("/backend/ajax/updatestatususer",{
user_id: $(this).attr("data-user-id"),
status: status_new
},function(data){
$($div).css('background-image', 'none');
$($div).css("width", "auto");
$($div).css("height", "auto");
$($div).html(data);
});
});
Controller:
public function action_updatestatususer(){
$ms = "vacio";
if($this->request->post('status')==0){
$rs_user = ORM::factory('user_user', $this->request->post('user_id'));
$rs_user->status='des';
$rs_user->save();
$flag = 0;
}
if($this->request->post('status')==1){
$rs_user = ORM::factory('user_user', $this->request->post('user_id'));
$rs_user->status='act';
$rs_user->save();
$flag = 1;
//Envio de correo de activacion
}
$view_status = View::factory('backend/user/status')
->set("flag", $flag)
->set("rs_user", $rs_user);
$this->response->body($view_status);
}