Answers.Body: <p>If you want the entire page to refresh during a popup form submission, then essentially you want to disable the ajax submit. You can do so in your _pre hook by writing:</p>
  
  <pre><code>$form-&gt;preventAjaxSubmit();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-04T21:54:33.603Z
Answers.Text: It works, thanks! But what if I a) want to refresh only part of the page b) this page is outside of civicrm/ path c) would  be nice to call fancy crm.status message after page/part of the page refresh?
Answers.UserDisplayName: yurg
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-05T02:18:04.550Z
Answers.Text: Using ajax to refresh part of the page in Drupal really has nothing to do with CiviCRM - you'll need to consult Drupal docs for that. If you get that working, calling CRM.status would be the easy part.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-06T22:17:28.380Z
Answers.Text: You're right, main question here is not in how to update a page in Drupal, but rather in how to update page in Drupal  **after Civicrm form submit** (where Civicrm form has been called in modal frame from Drupal page using .crm-popup link class). Parts of a puzzle, which I'm not able to put together yet.
Answers.UserDisplayName: yurg
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T01:43:37.730Z
Answers.Text: You want to listen for the "crmPopupFormSuccess" event. See https://wiki.civicrm.org/confluence/display/CRMDOC/Ajax+Pages+and+Forms
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T16:32:41.247Z
Answers.Text: How do you do it?!!  Have read this page a million times, was blind until you cast your spells upon me, so now I can see!!!
Answers.UserDisplayName: yurg
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-02T01:18:33.523Z
Answers.LastActivityDate: 2016-03-02T01:18:33.523Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>Here is a code for copy&amp;paste, in case anyone wants it:</p>
  
  <pre><code> $('#main-content')
      .on('click', 'a.LINK_CLASS_or_ID', CRM.popup)
          .on('crmPopupFormSuccess', 'a.LINK_CLASS_or_ID', function() {     
   // Die, default CRM.alert!! I was looking how to kill you for weeks
          CRM.alert= function() {}; 
  // Attaching civicrm magic to any page element              
         $('#ELEMENT_ID_to_REFRESH').crmSnippet(); 
    // Here we go
         $('#ELEMENT_ID_to_REFRESH').crmSnippet('refresh');
    // Let us tell users what we are doing  
         CRM.status('Success! Refreshing a corresponded piece of content', 'Success', 'success' ); 
          });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T19:21:25.883Z
Answers.Text: Instead of calling `crmSnippet('refresh')` directly, take a look at the `CRM.refreshParent` helper function - it will do it for you without you needing to know the exact element of the ajax container.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T20:46:07.203Z
Answers.Text: You might won't believe, have tried to make use of CRM.refreshParent almost the whole day, but all I've got is ' Cannot read property 'stopPropagation' of undefined'. Basically, I'd like to reload a DataTable - powered table, not the whole page, but this gets even more complicated, so  only thing which more or less works is make whole page refresh, unfortunately.
Answers.UserDisplayName: yurg
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T16:40:14.247Z
Answers.LastActivityDate: 2016-03-07T16:40:14.247Z
Answers.UserDisplayName: yurg
Body: <p>We've a page (in Drupal) outside of CiviCRM  for "editors" (mean, users with restricted permissions) to perform some civicrm tasks.</p>
  
  <p>From this page civicrm forms is being opened in modal frame via <strong>.crm-popup</strong> class added  to form open links. There are also hooks being used (_pre and _postProcess) for these forms.</p>
  
  <p>Drupal page should be refreshed after form submit (in order to show editors their edits); but each form submit summons a js status message <code>CRM_Core_Session::setStatus(ts('Your information has been saved.'), ts('Thank you.'), 'success');</code> from <code>civicrm\CRM\Profile\Form\Edit.php</code>. </p>
  
  <p>And  we're lost in how (mean, <strong>where would be a right place</strong>) to add something like <strong>location.reload</strong> which, ideally, should be fired right after status message close. Or, may be, it should be added at hook_postProcess level via "header(refresh)" (we've made some attempts doing this and failed though)?  </p>
  
  <p>Any clue form true js / jquery experts, please! </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-01T00:47:22.087Z
Comments.Text: yurg - can you share more about how you approached getting a modal popup of civi function for a drupal user. my goal is to provide a drupal user who has no access to CiviCRM to create a new CiviCRM Group. Sounds like you are doing something along those lines.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-01T09:11:59.887Z
Comments.Text: petednz: I've learned user has to have an access to some civicrm parts (in your case it'd be "CiviCRM: edit groups" and may be "Access Civicrm"). In order to prevent users from accidental access to /civicrm/ path, I use drupal_goto() (not smart, but works). As for modals: there are basically two options: #1. add "crm-popup" class: l(t('Add group'), 'civicrm/group/add', array('attributes' => array('class' => 'crm-popup'), 'query' => array('cid' => $contact['cid'], 'reset' => 1)); or #2. catch link in JS file:  $('#MyLinkID').on('click', CRM.popup); #2 allows further Civi JS API usage.
Comments.UserDisplayName: yurg
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-01T19:24:30.710Z
Comments.Text: Thank you yurg. I don't have a problem with the users having drupal permission for 'edit groups' etc. This is more to keep their life easy than to lock them out of civi entirely. So either of your solutions (just) require a custom module? Did you ever consider piggy-backing on something like https://www.drupal.org/project/modal_forms
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-01T21:40:23.470Z
Comments.Text: civicrm has it's own modal forms tool (presumable based on jQueryUI), so there is no need to add smth. on top of it; there is no need of an extra module either if only thing you need is a form opened in a modal frame. In this case you can print simple HTML link (in case you don't want to utilize drupal l() function I mentioned in a prev.comment). It can be as simple as: **< a class=crm-popup href=civicrm/group/add?reset=1 > Create a New Group < / a > **
Comments.UserDisplayName: yurg
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-01T23:38:18.167Z
Comments.Text: really appreciate your trying to help me on this. and glad to hear this could be simple. so presumably once i figure what i need to put in the theme for that class to function then the link as you gave me (cleaned up to <a class="crm-popup" href="/civicrm/group/add?reset=1"> Create a New Group </a>) may be enough. but i haven't followed what I would need to add to the theme. sorry.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-03T15:35:48.780Z
Comments.Text: Let's start simple and see where it goes. So: 1. Create a new block in Drupal 2. Put <a class="crm-popup" href="/civicrm/group/add?reset=1"> Create a New Group </a> into block body (Full HTML input format). 3. Make the block visible somewhere and try to click the link. Ideally it should open the form in the modal frame. Please let me know.
Comments.UserDisplayName: yurg
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-03T20:31:41.913Z
Comments.Text: hi yurg - it only works as a link to the page, the pop-up does not appear. On chat.civicrm.org totten said "i don't recall the rules for crm-popup per se, but generally... if using a special crm-* class that's defined by civi, you would need to have some JS files and/or CSS files files loaded from Civi. It may be enough to fire civicrm_initialize() somewhere in the initial page-request.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-03T20:31:53.307Z
Comments.Text: and "Also: you may need to ensure that the <a> tag sits somewhere inside the crm-container. (Most of the CSS and JS functionality in Civi only applies within crm-container.) e.g. <div class="crm-container"><a class="crm-popup"...>...</a></div>"
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-04T05:09:28.193Z
Comments.Text: i started off a new question here http://civicrm.stackexchange.com/questions/12759/how-to-get-a-civicrm-popup-form-working-via-a-drupal-link with a solution. happy to understand better how you got civicrm initialised.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-04T14:52:04.900Z
Comments.Text: Indeed, civicrm has to be initialized using civicrm_initialize() (in  Drupal's hook_page_build()); sorry, totally forgot about that, seemed so obvious :-) Glad to hear you've found the solution!
Comments.UserDisplayName: yurg
Tags: <drupal><hooks><ajax><javascript>
Title: Refresh page after closing modal opened by .crm-popup outside of CiviCRM
ThreadText: # Refresh page after closing modal opened by .crm-popup outside of CiviCRM
  
  (Asked by: username_0 on 2016-02-16)
  
  We've a page (in Drupal) outside of CiviCRM for "editors" (mean, users with restricted permissions) to perform some civicrm tasks.
  
  From this page civicrm forms is being opened in modal frame via **.crm-popup** class added to form open links. There are also hooks being used (\_pre and \_postProcess) for these forms.
  
  Drupal page should be refreshed after form submit (in order to show editors their edits); but each form submit summons a js status message `CRM_Core_Session::setStatus(ts('Your information has been saved.'), ts('Thank you.'), 'success');` from `civicrm\CRM\Profile\Form\Edit.php`.
  
  And we're lost in how (mean, **where would be a right place**) to add something like **location.reload** which, ideally, should be fired right after status message close. Or, may be, it should be added at hook\_postProcess level via "header(refresh)" (we've made some attempts doing this and failed though)?
  
  Any clue form true js / jquery experts, please!
  
  **Tags:** drupal, hooks, ajax, javascript
  
  > **Comments:**
  > **username_1**: username_0 - can you share more about how you approached getting a modal popup of civi function for a drupal user. my goal is to provide a drupal user who has no access to CiviCRM to create a new CiviCRM Group. Sounds like you are doing something along those lines.  
  > **username_0**: petednz: I've learned user has to have an access to some civicrm parts (in your case it'd be "CiviCRM: edit groups" and may be "Access Civicrm"). In order to prevent users from accidental access to /civicrm/ path, I use drupal_goto() (not smart, but works). As for modals: there are basically two options: #1. add "crm-popup" class: l(t('Add group'), 'civicrm/group/add', array('attributes' => array('class' => 'crm-popup'), 'query' => array('cid' => $contact['cid'], 'reset' => 1)); or #2. catch link in JS file:  $('#MyLinkID').on('click', CRM.popup); #2 allows further Civi JS API usage.  
  > **username_1**: Thank you username_0. I don't have a problem with the users having drupal permission for 'edit groups' etc. This is more to keep their life easy than to lock them out of civi entirely. So either of your solutions (just) require a custom module? Did you ever consider piggy-backing on something like https://www.drupal.org/project/modal_forms  
  > **username_0**: civicrm has it's own modal forms tool (presumable based on jQueryUI), so there is no need to add smth. on top of it; there is no need of an extra module either if only thing you need is a form opened in a modal frame. In this case you can print simple HTML link (in case you don't want to utilize drupal l() function I mentioned in a prev.comment). It can be as simple as: **< a class=crm-popup href=civicrm/group/add?reset=1 > Create a New Group < / a > **  
  > **username_1**: really appreciate your trying to help me on this. and glad to hear this could be simple. so presumably once i figure what i need to put in the theme for that class to function then the link as you gave me (cleaned up to <a class="crm-popup" href="/civicrm/group/add?reset=1"> Create a New Group </a>) may be enough. but i haven't followed what I would need to add to the theme. sorry.  
  > **username_0**: Let's start simple and see where it goes. So: 1. Create a new block in Drupal 2. Put <a class="crm-popup" href="/civicrm/group/add?reset=1"> Create a New Group </a> into block body (Full HTML input format). 3. Make the block visible somewhere and try to click the link. Ideally it should open the form in the modal frame. Please let me know.  
  > **username_1**: hi username_0 - it only works as a link to the page, the pop-up does not appear. On chat.civicrm.org totten said "i don't recall the rules for crm-popup per se, but generally... if using a special crm-* class that's defined by civi, you would need to have some JS files and/or CSS files files loaded from Civi. It may be enough to fire civicrm_initialize() somewhere in the initial page-request.  
  > **username_1**: and "Also: you may need to ensure that the <a> tag sits somewhere inside the crm-container. (Most of the CSS and JS functionality in Civi only applies within crm-container.) e.g. <div class="crm-container"><a class="crm-popup"...>...</a></div>"  
  > **username_1**: i started off a new question here http://civicrm.stackexchange.com/questions/12759/how-to-get-a-civicrm-popup-form-working-via-a-drupal-link with a solution. happy to understand better how you got civicrm initialised.  
  > **username_0**: Indeed, civicrm has to be initialized using civicrm_initialize() (in  Drupal's hook_page_build()); sorry, totally forgot about that, seemed so obvious :-) Glad to hear you've found the solution!  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-03-02. Score: 1 | Accepted answer
  
  If you want the entire page to refresh during a popup form submission, then essentially you want to disable the ajax submit. You can do so in your _pre hook by writing:
  $form->preventAjaxSubmit();
  
  > **Comments:**
  > **username_0**: It works, thanks! But what if I a) want to refresh only part of the page b) this page is outside of civicrm/ path c) would  be nice to call fancy crm.status message after page/part of the page refresh?  
  > **username_2**: Using ajax to refresh part of the page in Drupal really has nothing to do with CiviCRM - you'll need to consult Drupal docs for that. If you get that working, calling CRM.status would be the easy part.  
  > **username_0**: You're right, main question here is not in how to update a page in Drupal, but rather in how to update page in Drupal  **after Civicrm form submit** (where Civicrm form has been called in modal frame from Drupal page using .crm-popup link class). Parts of a puzzle, which I'm not able to put together yet.  
  > **username_2**: You want to listen for the "crmPopupFormSuccess" event. See https://wiki.civicrm.org/confluence/display/CRMDOC/Ajax+Pages+and+Forms  
  > **username_0**: How do you do it?!!  Have read this page a million times, was blind until you cast your spells upon me, so now I can see!!!  
  
  ---
  
  ### Answer by username_0 on 2016-03-07. Score: 1
  
  Here is a code for copy&paste, in case anyone wants it:
   $('#main-content')
      .on('click', 'a.LINK_CLASS_or_ID', CRM.popup)
          .on('crmPopupFormSuccess', 'a.LINK_CLASS_or_ID', function() {     
   // Die, default CRM.alert!! I was looking how to kill you for weeks
          CRM.alert= function() {}; 
  // Attaching civicrm magic to any page element              
         $('#ELEMENT_ID_to_REFRESH').crmSnippet(); 
    // Here we go
         $('#ELEMENT_ID_to_REFRESH').crmSnippet('refresh');
    // Let us tell users what we are doing  
         CRM.status('Success! Refreshing a corresponded piece of content', 'Success', 'success' ); 
          });
  
  > **Comments:**
  > **username_2**: Instead of calling `crmSnippet('refresh')` directly, take a look at the `CRM.refreshParent` helper function - it will do it for you without you needing to know the exact element of the ajax container.  
  > **username_0**: You might won't believe, have tried to make use of CRM.refreshParent almost the whole day, but all I've got is ' Cannot read property 'stopPropagation' of undefined'. Basically, I'd like to reload a DataTable - powered table, not the whole page, but this gets even more complicated, so  only thing which more or less works is make whole page refresh, unfortunately.  
  
  ---
  
  