⚠ 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

callback before delete



briggers
  • profile picture
  • Member

Posted 12 September 2013 - 09:16 AM

Hi,

 

I have 2 tables - questions and answers.

 

Before deleting questions I want to check that all answers have been deleted so I have a callback_before_delete function like this

function _delete_callback($primary_key = null)
	{
		$count_answers = $this->faqs_model->count_answers($primary_key);
		if ($count_answers > 0){
			$this->session->set_flashdata('action', 'Warning: There are answers associated with this question. You must delete the answers before deleting the question.<br />No action has been taken.');
			
			return false;
		}

So if there are answers ($count_answers is > 0) we return false , GC does not delete and shows the red "records not deleted" message but it does not reload the grid (using flexigrid) so the flashdata message is not displayed until the user refreshes the page.

 

Is there any way I can get the page to refresh so that the user knows why the delete did not happen?

 

Thanks

Richard


davidoster
  • profile picture
  • Member

Posted 12 September 2013 - 09:46 AM

Which version do you use?


briggers
  • profile picture
  • Member

Posted 12 September 2013 - 09:54 AM

This is GC 1.4.0


Amit Shah
  • profile picture
  • Member

Posted 14 September 2013 - 01:53 AM

Hello briggers

 

Well to your problem / situation, i will recommend you write your custom delete function (javascript) ... that will be better.

Unset the GC edit

and add action (delete) - assign to it a js function call..

let this js function call make an ajax call for the same

as per the response from the ajax.. if record deleted or .. whatever message you wana popup .. just pass it back..

and the script can parse it and display / refresh grid or do whatever you wish to with the same :)


briggers
  • profile picture
  • Member

Posted 19 September 2013 - 11:07 AM

Hi Amit,

 

Hmm... I would like to avoid writing special js if possible. But I did realise that the only logical reason why the delete should fail - other than a catastrophic server problem would be because of my condition and then I found that one can temporaly change the delete fail message, so now we have

if ($state == 'delete')
	{
		$crud->set_lang_string('delete_error_message', 'Your data was not deleted, check that all FAQ answers have been deleted and try again.<br />No changes have been made.');
	}

Probably don't need the if ($state == 'delete')

but I'll leave it in

 

It would be quite nice if one could use $crud->set_lang_string() in a callback function but does not seem to work


Amit Shah
  • profile picture
  • Member

Posted 19 September 2013 - 16:31 PM

Well that wont be much a possibility as the crud is already a rendered output.

Well - only purpose proposed was as u wanted to custom functionality - thats why. Anyways - if things works out the way you want - its good to have it :)