CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Forcing page reload at end of hooks
Pages: [1]

Author Topic: Forcing page reload at end of hooks  (Read 2227 times)

ollyb

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal
  • MySQL version: 5.1
  • PHP version: 5.3
Forcing page reload at end of hooks
August 06, 2013, 09:33:50 am
Hi!

We have a module that we have developed that interacts quite closely with civicase. One of the things that we do quite frequently in this module is to show status messages to the user with drupal_set_message. It used to be the case that when activities were updated in civicase that it did a full page reload, which then showed all the messages we had generated in the pre and post hooks. Nowadays when activities get updated it's all done via AJAX, so there is no page reload. This breaks our messages :(

Is there a way to force a page reload with the API, and hence show the list of queued messages? Or is there a better way to show messages to users?

Cheers!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Forcing page reload at end of hooks
August 06, 2013, 10:05:02 am
Check out http://wiki.civicrm.org/confluence/display/CRM/Notifications+in+CiviCRM
Try asking your question on the new CiviCRM help site.

ollyb

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Forcing page reload at end of hooks
August 06, 2013, 12:34:27 pm
Perfect! Thanks.

ollyb

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Forcing page reload at end of hooks
August 07, 2013, 03:48:09 am
Actually I am still a bit stuck on this.

We have a module that uses the _civicrm_post hook, when an activity status is updated in civicase this hook gets called ok. After a bit of logic we want to give the user a bit of feedback on the screen. If I stick

Code: [Select]
CRM_Core_Session::setStatus(ts('Message body'), ts('Title'), 'alert');

in our module php then it behaves in the same way as drupal_set_message - i.e. it needs a page reload before it shows the message. So I guess I need to do it the Javascript way? I can't figure out how to do this. Is it still something I need to do in the hooks?

JohnFF

  • I post frequently
  • ***
  • Posts: 235
  • Karma: 6
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.28
  • MySQL version: 5.5.31-1
  • PHP version: 5.3.27
Re: Forcing page reload at end of hooks
August 08, 2013, 08:12:39 am
What is the nature of the messages you're showing?

It seems to me that if you've got your own module for this then it's not much harder to include a bit of JQuery to show messages - not using the browser popup box, which is a dreadful thing, but by appending them to the top of the page as the drupal thing does, or by creating a cool overlaying div  8).
If you like empowering charities in a free and open way, then you're going to love Civi.

Email Amender: https://civicrm.org/extensions/email-amender
UK Phone Validator: https://civicrm.org/extensions/uk-phone-number-validator
http://civifirst.com
https://twitter.com/civifirst

ollyb

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Forcing page reload at end of hooks
August 08, 2013, 09:50:51 am
Hi John,

our module doesn't have any viewable pages that we can edit - it just does things when activities are updated in civicase. So as an example, one of our activities in our case is based around consent to take part in a study, once we have received a letter back from a potential participant saying they want to be involved then we mark the consent activity status as accepted. When this happens we automatically (using the _civicrm_post hook) create an ID for the participant and stick it in their contact object. Once that has completed we have a message that pops up (while we are still on the civicase page) saying e.g. 'Dave's study ID is ABC12345'.

Does that make sense?

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Forcing page reload at end of hooks
August 08, 2013, 09:58:34 am
@JohnFF Civi creates cool overlay div's automatically when you call CRM.alert('something') from js. No need to reinvent the wheel there.

@ollyb In my opinion this is a general problem that can be stated as "We need to display status messages during ajax callbacks" If we get that infrastructure into Civi, then your job will be as simple as sticking in that 1-line setStatus() call you mentioned.
Would you like to help make that happen? We are very close - the server is already responding with json, it just needs to add messages to that json, and on the clientside it needs to iterate through them and feed them to CRM.alert().
Try asking your question on the new CiviCRM help site.

ollyb

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Forcing page reload at end of hooks
August 13, 2013, 02:54:56 am
I think that is a much better way of stating the issue I am having! I now at least understand what is going on :)

As for helping with the dev; I'm going to have to weasel out of that for now - we are still playing with civi as a proof of concept part of our stack, so it's only getting played with as time permits. If it all works as we hope then we should have much more resource to dedicate to civi - including bug fixing/developing etc :)

JohnFF

  • I post frequently
  • ***
  • Posts: 235
  • Karma: 6
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.28
  • MySQL version: 5.5.31-1
  • PHP version: 5.3.27
Re: Forcing page reload at end of hooks
August 15, 2013, 04:54:34 am
... Learn something new every day - thanks for the assist!
If you like empowering charities in a free and open way, then you're going to love Civi.

Email Amender: https://civicrm.org/extensions/email-amender
UK Phone Validator: https://civicrm.org/extensions/uk-phone-number-validator
http://civifirst.com
https://twitter.com/civifirst

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Forcing page reload at end of hooks

This forum was archived on 2017-11-26.