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 (Moderator: Donald Lobo) »
  • Trying to change the autocomplete with Activity Assignee
Pages: [1]

Author Topic: Trying to change the autocomplete with Activity Assignee  (Read 1731 times)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Trying to change the autocomplete with Activity Assignee
April 26, 2011, 04:11:45 am
Problem: my customer is implementing CiviCRM, and have about 35000 contacts in the DB. They will use activities (and cases) fairly extensively to plan colleagues. In the core functionality autocomplete is used on the template CRM/Activity/Form/Activity.tpl for assignee_contact_id and for target_contact_id like so:
Code: [Select]
    var sourceDataUrl = "{/literal}{$dataUrl}{literal}";
    var tokenDataUrl  = "{/literal}{$tokenUrl}{literal}";
    var hintText = "{/literal}{ts}Type in a partial or complete name of an existing contact.{/ts}{literal}";
    cj( "#target_contact_id"  ).tokenInput( tokenDataUrl, { prePopulate: target_contact,   classes: tokenClass, hintText: hintText });
    cj( "#assignee_contact_id").tokenInput( tokenDataUrl, { prePopulate: assignee_contact, classes: tokenClass, hintText: hintText });
    cj( 'ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px' );
    cj('#source_contact_id').autocomplete( sourceDataUrl, { width : 180, selectFirst : false, hintText: hintText, matchContains: true, minChars: 1
                                }).result( function(event, data, formatted) { cj( "#source_contact_qid" ).val( data[1] );
                                }).bind( 'click', function( ) { cj( "#source_contact_qid" ).val(''); });
    });

I am trying to replace the autocomplete for assignee_contact_id by commenting out the line
Code: [Select]
    cj( "#assignee_contact_id").tokenInput( tokenDataUrl, { prePopulate: assignee_contact, classes: tokenClass, hintText: hintText });

and adding:
Code: [Select]
    <script type="text/javascript">

 jQuery(document).ready(function($) {
    $('#assignee_contact_id').autocomplete(
      "/civicrm/ajax/rest&json=1&fnName=civicrm/contact/search&group=44",
    {
     dataType:"json",
     extraParams:{sort_name:function () {return $("#assignee_contact_id").val();}},
     formatItem: function(data,i,max,value,term){ return value;},
     parse: function(data){
         var acd = new Array();
         for(cid in data){
           acd.push({ data:data[cid], value:data[cid].sort_name, result:data[cid].sort_name });
         }
         return acd;
     },
       width: 180,
       delay:50,
       max:200,
       mustMatch: true,
       autoFill:true,
       selectFirst: true
   )};
 )};

 </script>

but no luck.......help much appreciated?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Trying to change the autocomplete with Activity Assignee
April 26, 2011, 05:30:10 am
try this:

Code: [Select]
var tokenDataUrl_assignee  = "{/literal}{$tokenUrl}&context=activity_assignee{literal}";
var assigneeDataUrl  = "{/literal}{crmURL p='civicrm/ajax/rest?fnName=civicrm/contact/search&json=1&return[contact_id]&group=3&context=activity_assignee'}{literal}";

then use tokenDataUrl_assignee instead of tokenDataUrl for the assignee
(where group is a group that contains the contacts you want available)

i'm more of a hook person myself, and have some code where these two autocomplete fields are run through the contactlist hook for modification. if you prefer that i can post it.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Trying to change the autocomplete with Activity Assignee
April 26, 2011, 05:36:28 am
Thanks! I will have a play with that, and if that fails go through the hook. I figured I could do hooks but thought it was high time I had a play with jQuery and all that sort of magic stuff :-)
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Trying to change the autocomplete with Activity Assignee
April 26, 2011, 11:09:08 am
Still no result....my problem is not so much the crmAPI or the crmURL statement, as it is the confusing bit with the target and assignee contact id? I succeed in removing the autocomplete from the assignee, but no way can I get a new one. Either both the target and assignee do the same, or only the target works. And what I need is that the target still can show all contacts, and the assignee only members of the group.....well I guess tomorrow is going to be another day :-)
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Trying to change the autocomplete with Activity Assignee
April 26, 2011, 01:27:55 pm
Quote from: lcdweb on April 26, 2011, 05:30:10 am
i'm more of a hook person myself, and have some code where these two autocomplete fields are run through the contactlist hook for modification. if you prefer that i can post it.

autocomplete_field hook is used on these as well? might be useful indeed.

X+

@erik, pretty sure this code reminds me something I shared ;). I'm pretty sure I wrote a jquery plugin to do a crmAutocomplete, might be worthwhile having a look one of these days...
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Trying to change the autocomplete with Activity Assignee
April 27, 2011, 12:12:46 am
X, I did see your post about crmAutocomplete, in the flossmanual I think.....will have another look and play and throw Marmite at you if it does not work  ;D


Marmite coming at you, the crmAutoComplete does not take uncleanURL into account, for that it should be:
Code: [Select]
http://<your site>/?q=civicrm/ajax/rest&rowCount=35&json=1&fnName=civicrm/contact/search&group=4&return[sort_name]&return[email]&&s=h&limit=25&timestamp=1303893557557&sort_name=H
I thought the hook used here was the ContactListQuery hook? Will have a second read.............age and eyesight?
« Last Edit: April 27, 2011, 01:42:24 am by Erik Hommel »
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Trying to change the autocomplete with Activity Assignee
April 27, 2011, 06:13:36 am
unless there's an undocumented hook, i believe Xavier is referring to:
http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmcontactListQuery

which is not called on the activity form page query.

to add the hook to this, modify: CRM/Contact/Page/AJAX.php

add the following in two places, around line 650 (before the dao execute query statement) and before the next dao/executequery a few lines later (in the else clause)

Code: [Select]
              // send query to hook to be modified if needed
              require_once 'CRM/Utils/Hook.php';
              CRM_Utils_Hook::contactListQuery( $query,
                                               $name,
                                               CRM_Utils_Array::value( 'context', $_GET ),
                                               CRM_Utils_Array::value( 'cid', $_GET ) );
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Trying to change the autocomplete with Activity Assignee
April 27, 2011, 06:17:54 am
Would it not make sense to have that in core?
Code: [Select]
              // send query to hook to be modified if needed
              require_once 'CRM/Utils/Hook.php';
              CRM_Utils_Hook::contactListQuery( $query,
                                               $name,
                                               CRM_Utils_Array::value( 'context', $_GET ),
                                               CRM_Utils_Array::value( 'cid', $_GET ) );

I have solved my issue for now with the
Quote
var tokenDataUrl_assignee  = "{/literal}{$tokenUrl}&context=activity_assignee{literal}";
and changing the select in CRM_Contact_Page_AJAX to take care of the groups if the context is activity_assignee. Thanks!
Will do some more testing on the crmAutocomplete as I do not have cleanURL's on my sandbox but I do on the client side.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Trying to change the autocomplete with Activity Assignee
April 27, 2011, 06:31:34 am
kurund had wanted to restructure some of those ajax queries.
so yes -- it should be in core. but i think he wanted to do some additional general cleanup rather than just drop in the hook call. but he is aware of it.

this hook was originally intended for use with the autocomplete custom fields. since the activity form fields we're talking about are not actually custom fields, one could argue this isn't technically what you'd expect to use. personally i think it makes sense to have a common hook that can modify all autocomplete contact fields, regardless of whether its custom or core.

i've had a number of clients that want to do what you're doing -- restrict activity assignee and also case role assignment to a "staff" group. so i think there's value in a more permanent solution for calling the hook.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Trying to change the autocomplete with Activity Assignee
April 27, 2011, 06:36:33 am
The functional request certainly makes sense, is there already an issue raised for this?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Trying to change the autocomplete with Activity Assignee
April 27, 2011, 07:08:29 am
Quote from: lcdweb on April 27, 2011, 06:31:34 am
personally i think it makes sense to have a common hook that can modify all autocomplete contact fields, regardless of whether its custom or core.

I agree w/ Brian on that, and would vote for adding that functionality w/o waiting for code restructure. Brian, wanna file an issue + patch?
Protect your investment in CiviCRM by  becoming a Member!

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Trying to change the autocomplete with Activity Assignee
April 27, 2011, 07:14:28 am
yes -- i'll file the issue
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Trying to change the autocomplete with Activity Assignee

This forum was archived on 2017-11-26.