Leave pop-up box on save

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
TheSpooki
Posts: 14
Joined: 2016-05-19 13:29

Leave pop-up box on save

Post by TheSpooki » 2016-07-01 15:17

I would like the pop up box to hide after I save a child record. Can someone please help me?

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Leave pop-up box on save

Post by grimblefritz » 2016-08-09 19:56

Can you give a bit more detail? I don't see a popup when I save, only the message bar below the navbar header - and that disappears automatically after a few seconds.

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Leave pop-up box on save

Post by DevGiu » 2016-08-09 20:13

I think he talks about the modal thath opens when you add a child record from a master form, for example, a new category from a product form. Save&Close
/Giuseppe
Professional Outsourcing Services

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Leave pop-up box on save

Post by grimblefritz » 2016-08-09 20:21

I don't use that mode (yet) but I can investigate. It is probably just a matter of a little jquery in a hook.

I'm working on a new project that will use the embedded mode for children, so it might be useful to poke around anyway.

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Leave pop-up box on save

Post by DevGiu » 2016-08-09 20:52

Embebbed Mode?
/Giuseppe
Professional Outsourcing Services

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Leave pop-up box on save

Post by grimblefritz » 2016-08-10 02:39

grep the AG code for 'embedded'

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Leave pop-up box on save

Post by DevGiu » 2016-08-10 07:22

grimblefritz wrote:grep the AG code for 'embedded'
I'm looking into the code, and I'm not totally sure what embedded mode is, or how to enable, sorry.
/Giuseppe
Professional Outsourcing Services

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Leave pop-up box on save

Post by grimblefritz » 2016-08-10 11:03

It's a var set in the AG code when you're not opening details in a new window.

TheSpooki
Posts: 14
Joined: 2016-05-19 13:29

Re: Leave pop-up box on save

Post by TheSpooki » 2016-08-29 13:55

Yes I am talking about the modal that pops up when creating a child record. I just want to know how to close it automatically when you save a new entry. This is an awesome community and I'm sure someone will figure it out.

Aya Adel
Posts: 7
Joined: 2016-08-08 07:29

Re: Leave pop-up box on save

Post by Aya Adel » 2016-09-01 12:15

Add the below code to the hooks/tablename-dv.js (where tablename is the name of the child table). This should do the job.

Code: Select all

$j(function(){
          if(($j('input[name=Embedded]').val()==1)){
               $j('form').submit(function(){
                        window.parent.jQuery('.modal').modal('hide');
               }
           })
})

TheSpooki
Posts: 14
Joined: 2016-05-19 13:29

Re: Leave pop-up box on save

Post by TheSpooki » 2016-09-03 01:28

It says there is a missing syntax

SyntaxError: missing ) after argument list
})

I tried to fix it but it's not working.

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Leave pop-up box on save

Post by grimblefritz » 2016-09-03 12:56

Try this:

Code: Select all

$j(function(){
          if($j('input[name=Embedded]').val()==1){
               $j('form').submit(function(){
                        window.parent.jQuery('.modal').modal('hide');
               }
           });
});

TheSpooki
Posts: 14
Joined: 2016-05-19 13:29

Re: Leave pop-up box on save

Post by TheSpooki » 2016-09-03 22:40

you were all on the right track!! This did the trick,

Code: Select all

$j(function(){
          if($j('input[name=Embedded]').val()==1){
               $j('form').submit(function(){
                        window.parent.jQuery('.modal').modal('hide');
               })
           }
})
Thanks for the help! This community is awesome!

Strider27
Posts: 8
Joined: 2016-08-21 22:49

Re: Leave pop-up box on save

Post by Strider27 » 2016-09-12 00:02

I've used this and it works perfectly. Quick question.

I have a need to run a function on delete. Is there something similar to "$j('form').submit" for delete, as my function currently only works when creating and updating records.

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Leave pop-up box on save

Post by grimblefritz » 2016-09-12 00:49

You can use something like:

Code: Select all

$j('#delete-button-id').on('click', function() {
    // your function code
});

Strider27
Posts: 8
Joined: 2016-08-21 22:49

Re: Leave pop-up box on save

Post by Strider27 » 2016-09-12 09:25

Thanks for the response. Sorry, I should have been clearer.
I need the function to run after the child has been deleted in the modal window of the parent, as the function calls an ajax file to recalculate a subtotal value of a field in the parent. I think with the above code it will run while the record is being deleted which may lead to inconsistent results, unless something like setTimeout is used.
The function itself is in the tablename-dv.js of the parent. I'm having slight issues with it at the moment but got it to work on submit, just not on delete. I posted on stackoverflow with regard to another related issue. You can see the relevant code there. http://stackoverflow.com/questions/3944 ... ting-child
Thanks for all your help.

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Leave pop-up box on save

Post by grimblefritz » 2016-09-12 19:56

Ah, I see your point. I don't use the parent-child window mode, so I don't have any suggestions.

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Leave pop-up box on save

Post by grimblefritz » 2016-09-12 22:25

I only had a moment to look at the AG code, but it looks to me like the tablename_after_delete() hook function is called even when the child is modal.

Strider27
Posts: 8
Joined: 2016-08-21 22:49

Re: Leave pop-up box on save

Post by Strider27 » 2016-09-12 23:45

I tried including it there, that did not work (keep in mind that I could have been doing something wrong as I'm new to this).
I ended up creating another function in the parent-dv.js, in that function I set a small delay so the child record actually gets written to the DB before calling the function that would calculate the subtotal sum of all children. See the two functions below:

Code: Select all

function update_lineitems_subtotal_delay(){
	setTimeout(update_lineitems_subtotal, 100);
	//alert('Delay Triggerred'); //for testing
};


function update_lineitems_subtotal(){
	var qid = $j('[name=SelectedID]').val();
		if(!isNaN(qid)){
			$j.ajax({
				url: 'hooks/ajax_quote_subtotal.php',
				data: { qid: qid },
				success: function(data){
					$j('#LineItemsSubtotal').val(data);
					$j('#Shipping').keyup();
					//alert('Update Triggerred'); //for testing
				}
			});
		}else{
			$j('#LineItemsSubtotal').val('0');
			$j('#Shipping').keyup();
			//alert('submitted!'); //for testing
		}
};
And in the child-dv.js I just used this:

Code: Select all

	if($j('input[name=Embedded]').val()==1){
		$j('form').submit(function(){
			parent.update_lineitems_subtotal_delay();
			window.parent.jQuery('.modal').modal('hide');
		});
	};
That seems to work for creating, updating and deleting records. Unfortunately setting the delay in the child itself did not seem to work consistently and did not work when deleting records.
One can argue that I could just set the delay in the main function of the parent, but I also call it on page load so don't really want to mess with it.
It is not pretty, but it works.

I have tried a number of different ways, even tried to trigger the function on modal close as documented in bootstrap docs, with something like

Code: Select all

$j('#myModal').on('hidden.bs.modal', function () {// do something…})
, which proved problematic as the modal ID's are randomly generated and for the life of me I could not tie it to the class itself.

Thanks for trying to help. Even though my solution is not pretty, if you look closely, some of the code above is yours from around the forum. Thank you for your contributions, without them I wouldn't have even gotten this far.

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Leave pop-up box on save

Post by grimblefritz » 2016-09-14 13:20

You're welcome, but I can't take credit for the code. Like most people, sometimes I code from scratch, and sometimes I see how others have done things and adapt for my needs. Posting the end result here, however? That is purely to give back.

Post Reply