⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Adding Custom Actions Issue



vaibhav

vaibhav
  • profile picture
  • Member

Posted 02 January 2012 - 14:33 PM

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.

vaibhav

vaibhav
  • profile picture
  • Member

Posted 03 January 2012 - 16:25 PM

Please , can any one reply ?

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 03 January 2012 - 21:22 PM

[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.

vaibhav

vaibhav
  • profile picture
  • Member

Posted 04 January 2012 - 10:24 AM

Hey thanks for replying,
I tested the code..

if(data.success === undefined)
{
alert("data.success is undefined something goes wrong with the json");
}


This code isn't executed..
What do u think ?

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 January 2012 - 20:32 PM

[quote name='vaibhav' timestamp='1325672654' post='219']
Hey thanks for replying,
I tested the code..

if(data.success === undefined)
{
alert("data.success is undefined something goes wrong with the json");
}


This code isn't executed..
What do u think ?
[/quote]

So that's easy. As the message say something goes wrong with your json. It will be helpful if you copy your function that approve_url have. Even though I have 3 solutions for you.

1. You can add just a header to your function and after the echo json_encode just have a die(); So for example a code should be:


header("Content-type: application/json");
......
echo json_encode($custom_output);
die();


2. If this doesn't work so test this:

$('.approve_deal_action').live('click', function(){
var approve_url = $(this).attr('href');
if( confirm( message_alert_delete ) )
{
$.ajax({
url: approve_url,
dataType: 'html',
success: function(results)
{
var data = $.parseJSON(results);

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;
});


3. If this doesn't work , then just add this to your project and it will work fine:

$('.approve_deal_action').live('click', function(){
var approve_url = $(this).attr('href');
if( confirm( message_alert_delete ) )
{
$.ajax({
url: approve_url,
dataType: 'html',
success: function(data)
{
$('#ajax_refresh_and_loading').trigger('click');
$('#report-success').html( data.success_message ).slideUp('fast').slideDown('slow');
$('#report-error').html('').slideUp('fast');
}
});
}

return false;
});


If this doesn't still work send the function code here to find a solution for you.

vaibhav

vaibhav
  • profile picture
  • Member

Posted 05 January 2012 - 13:11 PM

Hey Thanks for taking time to reply ...
the third option worked ..
but the pReload pButton keeps on rotating ..
The code is all same..
and also i have added

$lang['alert_approve'] = 'Are you sure that you want to approve this deal?';

in language/english.php file..
and in list_template.php file i have addded

var message_alert_approve = "<?php echo $this->l('alert_approve'); ?>";


These are the only changes i have made..
What other changes are required..??

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 05 January 2012 - 19:17 PM

[quote name='vaibhav' timestamp='1325769064' post='223']
Hey Thanks for taking time to reply ...
the third option worked ..
but the pReload pButton keeps on rotating ..
The code is all same..
and also i have added

$lang['alert_approve'] = 'Are you sure that you want to approve this deal?';

in language/english.php file..
and in list_template.php file i have addded

var message_alert_approve = "<?php echo $this->l('alert_approve'); ?>";


These are the only changes i have made..
What other changes are required..??
[/quote]

Can you please send be a printscreen of your firebug when the ajax is called? For example:[attachment=9:example.png]

vaibhav

vaibhav
  • profile picture
  • Member

Posted 06 January 2012 - 11:29 AM

Here's the print screen, I hope this is what you asked for :)[attachment=12:firebug_screenshot.PNG]

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 06 January 2012 - 21:24 PM

[quote name='vaibhav' timestamp='1325849358' post='233']
Here's the print screen, I hope this is what you asked for :)[attachment=12:firebug_screenshot.PNG]
[/quote]

I really don't know what happens and the loading is rotating without stoping. If everything works well and you don't have any problem just have a setTimeout after one second to STOP the loading.

so you will have:


$('.approve_deal_action').live('click', function(){
var approve_url = $(this).attr('href');
if( confirm( message_alert_delete ) )
{
$.ajax({
url: approve_url,
dataType: 'html',
success: function(data)
{
$('#ajax_refresh_and_loading').trigger('click');
$('#report-success').html( data.success_message ).slideUp('fast').slideDown('slow');
$('#report-error').html('').slideUp('fast');
setTimeout("$('#ajax_refresh_and_loading').removeClass('loading')",1000);

}
});
}
return false;
});


and that's it.

I know that this is not the best solution but I can find where the problem is. The loading rotates all the time only if there is an error on database e.t.c.

vaibhav

vaibhav
  • profile picture
  • Member

Posted 09 January 2012 - 13:17 PM

Okay..I will work on it.Will let u know, if i find any bug..
Thanks :)

qeipami

qeipami
  • profile picture
  • Member

Posted 17 January 2015 - 11:32 AM

The loading rotates all the time also in my project.. Do you find the problem?


qeipami

qeipami
  • profile picture
  • Member

Posted 17 January 2015 - 13:49 PM

it was depended by firebug.... :C