[quote name='vaibhav' timestamp='1325514790' post='209']
Lately I had been posting comments regarding Adding a custom action control, i am very much interested to work on this library.
Yeah, I know i had been posting the same issue again and again, but i am not clear yet..
I have done following steps to add a custom library
1)
$this->grocery_crud->add_action('Approve', 'http://localhost/project3/images/approve.jpeg', 'admin/approve_deal');
2)In.
grocery-crud / assets / grocery_crud / themes / flexigrid / js / flexigrid.js
I have had added following code in flexigrid.js
$('.crud-action').live('click', function(){
var approve_url = $(this).attr('href');
if( confirm( message_alert_delete ) )
{
$.ajax({
url: approve_url,
dataType: 'json',
success: function(data)
{
if(data.success)
{
$('#ajax_refresh_and_loading').trigger('click');
$('#report-success').html( data.success_message ).slideUp('fast').slideDown('slow');
$('#report-error').html('').slideUp('fast');
}
else
{
$('#report-error').html( data.error_message ).slideUp('fast').slideDown('slow');
$('#report-success').html('').slideUp('fast');
}
}
});
}
return false;
});
Here's the problem.
The function admin/approve_deal is called after that,
THE CONTENT IS NOT REFRESHED.
Like , the messages "Your deal has been deleted" and all the UI are not seen.
I just to implement a custom action , just like Delete Action , and all the UI after that action is executed
Can you tell me where i am going wrong ?
If you need more information on this query , please PM me, i will be very happy to reply.
Thank You.
[/quote]
Hello @vaibhav and I am sorry for the delayed reply.
It's a really strange bug actually the only thing I should suggest is to have a 4th parameter with a class_name. So your code will be:
$this->grocery_crud->add_action('Approve', 'http://localhost/project3/images/approve.jpeg', 'admin/approve_deal',"approve_deal_action");
and the only change will be:
$('.approve_deal_action').live('click', function(){
var approve_url = $(this).attr('href');
if( confirm( message_alert_delete ) )
{
$.ajax({
url: approve_url,
dataType: 'json',
success: function(data)
{
if(data.success)
{
$('#ajax_refresh_and_loading').trigger('click');
$('#report-success').html( data.success_message ).slideUp('fast').slideDown('slow');
$('#report-error').html('').slideUp('fast');
}
else
{
$('#report-error').html( data.error_message ).slideUp('fast').slideDown('slow');
$('#report-success').html('').slideUp('fast');
}
}
});
}
return false;
});
Perhaps the wrong thing with your code is that you have 2 live click in the button delete and it has a conflict.
If this doesn't work please tell me where the code stops. So a simple thing to do is to have alerts in every step just to test your code. Do it like that and send again WHERE the code stops. I have many scenarios in my mind what could be wrong but I don't have enough information. Also it is a good thing to use error on your ajax so for example you can test it like that:
$('.approve_deal_action').live('click', function(){
alert("Ok we are at least in :-)");
var approve_url = $(this).attr('href');
if( confirm( message_alert_delete ) )
{
alert("Confirmation sucess let's try the ajax now");
$.ajax({
url: approve_url,
dataType: 'json',
success: function(data)
{
alert("Yeeaaaa everything works fine");
if(data.success === undefined)
{
alert("data.success is undefined something goes wrong with the json");
}
if(data.success)
{
$('#ajax_refresh_and_loading').trigger('click');
$('#report-success').html( data.success_message ).slideUp('fast').slideDown('slow');
$('#report-error').html('').slideUp('fast');
}
else
{
$('#report-error').html( data.error_message ).slideUp('fast').slideDown('slow');
$('#report-success').html('').slideUp('fast');
}
},
error: function(){
alert("Nope, ajax is sended but there was an error, propably the json is not right. Try to change the json type with html ;-)");
}
});
}
return false;
});
I hope this helps a little bit.