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) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Getting crmAutocomplete working for current_employer - successfully
Pages: [1]

Author Topic: Getting crmAutocomplete working for current_employer - successfully  (Read 1634 times)

Schurli

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.1 beta3
  • CMS version: Joomla 1.7.5
  • MySQL version: 5.1.58
  • PHP version: 5.3.6
Getting crmAutocomplete working for current_employer - successfully
February 06, 2012, 09:56:38 am
Hi guys!

I stuck up into a - maybe for you specialists little - problem getting autocomplete to work in front end.
I've searched all the threads and blogs across the web, but non of the code-examples ended up in success.

I published a registration form for new individuals in the front end for registered users and added the field "current_employer".
So i wanted to set up this field with the autocomplete functionality, for this i added the following code to the Dynamic.tpl :

{if $session->get('userID') > 0}

<script type="text/javascript" src="{$config->resourceBase}js/rest.js"></script>{literal}
<script>
cj(document).ready(function($){
  $('#current_employer').crmAutocomplete({params:{contact_type:'Organization'}});
});
</script>
{/literal}

{/if}

I also tried several other code examples with autocomplete instead of crmAutocomplete and filled it with all kind of urls,
but i think this code should work with version 4.0.8

I even get the field working as autocomplete-field, but when i start searching, i'm getting ..... nothing, really nothing.
In the back-end this autocomplete works fine, but it would be great to get it work in front-end.

There are also no errors when i use debuging, everthing seems ok, but i'm getting no returns.

My configuration:

Ubuntu 11.10
Apache 2.2
PHP 5.3.2
MySql 5.1
Joomla 1.7.5
civiCRM 4.0.8

I appreciate any help.
« Last Edit: February 06, 2012, 12:51:26 pm by Schurli »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Getting crmAutocomplete working for current_employer - still no success
February 06, 2012, 10:43:50 am

We've addressed this issue in 4.1, i.e. allowing users with minimal permissions to see a restricted list of contacts for an auto complete field

in prior version, that permissions are being enforced as designed and hence no contacts are returned. I dont think there is an easy workaround for this, other than writing your own custom url to expose data

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Schurli

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.1 beta3
  • CMS version: Joomla 1.7.5
  • MySQL version: 5.1.58
  • PHP version: 5.3.6
Re: Getting crmAutocomplete working for current_employer - still no success
February 06, 2012, 10:50:30 am
Thanks Donald for your reply!

So if i understand you right, there is no way in 4.0.8, even when i'm logged in as admin in the front-end?

And is there a hope to get it work in version 4.1 soon?

thanks

Georg

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Getting crmAutocomplete working for current_employer - still no success
February 06, 2012, 11:20:23 am

joomla front end has different permissioning than backend.

its already in 4.1, so would be great if you download the 4.1 beta and test it and ensure it works :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Schurli

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.1 beta3
  • CMS version: Joomla 1.7.5
  • MySQL version: 5.1.58
  • PHP version: 5.3.6
Re: Getting crmAutocomplete working for current_employer - still no success
February 06, 2012, 12:47:22 pm
Hi Lobo!

Finaly.....IT WORKS!

The update from 4.0.8 to 4.1 Beta3 worked without any Problems.
But this wasn't really a solution, because nothing changed.

So what i did was, i copied the script from the backend into the Dynamic.tpl so for now when i'm logged in in frontend as user with enough permissions the field will autofill with the organizations.

here's the code i used:

<script type="text/javascript">
var dataUrl        = "/administrator/?option=com_civicrm&task=civicrm/ajax/rest&className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1&employee_id=";
var newContactText = "(neuen Kontakteintrag erstellen)";
cj('#current_employer').autocomplete( dataUrl, {
                                      width        : 250,
                                      selectFirst  : false,
                                      matchCase    : true,
                                      matchContains: true
    }).result( function(event, data, formatted) {
        var foundContact   = ( parseInt( data[1] ) ) ? cj( "#current_employer_id" ).val( data[1] ) : cj( "#current_employer_id" ).val('');
        if ( ! foundContact.val() ) {
            cj('div#employer_address').html(newContactText).show();   
        } else {
            cj('div#employer_address').html('').hide();   
        }
    }).bind('change blur', function() {
        if ( !cj( "#current_employer_id" ).val( ) ) {
            cj('div#employer_address').html(newContactText).show();   
        }
});

// remove current employer id when current employer removed.
cj("form").submit(function() {
  if ( !cj('#current_employer').val() ) cj( "#current_employer_id" ).val('');
});

//current employer default setting
var employerId = "";
if ( employerId ) {
    var dataUrl = "/administrator/?option=com_civicrm&task=civicrm/ajax/rest&className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1&id=" + employerId + "&employee_id=" + cid ;
    cj.ajax({
        url     : dataUrl,   
        async   : false,
        success : function(html){
            //fixme for showing address in div
            htmlText = html.split( '|' , 2);
            cj('input#current_employer').val(htmlText[0]);
            cj('input#current_employer_id').val(htmlText[1]);
        }
    });
}

cj("input#current_employer").click( function( ) {
    cj("input#current_employer_id").val('');
});
</script>

thanks for your post, this was what i needed to get success!

I will keep on testing the beta and come back, if i find any bugs

rgds

Georg

Schurli

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.1 beta3
  • CMS version: Joomla 1.7.5
  • MySQL version: 5.1.58
  • PHP version: 5.3.6
Re: Getting crmAutocomplete working for current_employer - successfully
February 06, 2012, 10:24:56 pm
Morning guys!

Ok, permission in Joomla is more tricky than i thought.
This workaround only works, if i'm logged in as admin in the backend, if i'm not logged in, i get a 404.

I will figure out how to solve this and come back with informations.

Georg

edit: k, had a little mess up in the code, because i pasted the url as hardcopy into the code.
works now, if i remove "/administrator", in this way the script doesn't need to access the admin directory.
« Last Edit: February 06, 2012, 11:30:52 pm by Schurli »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Getting crmAutocomplete working for current_employer - successfully

This forum was archived on 2017-11-26.