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) »
  • API Newbie - help
Pages: [1]

Author Topic: API Newbie - help  (Read 1673 times)

dowd

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
API Newbie - help
April 18, 2012, 05:40:06 am
Hi,
First off I am a complete newbie to the API and am sure I am just doing something (or not doing something) really simple. I am trying a couple of the examples to start off with and can't seem to get any of them to work.

I have tried to do the example under "Using the jQuery plug-in" on http://www.booki.cc/civicrm-4/api/ to get a "to be checked" button I insert the code into the relevant template file and though I can see the code when I Inspect element in Chrome, no button appears, I then deleted the second qoute mark in the append function as there was a javascript error showing on chrome but though the button appears it doesn't seem to do anything. I tried this on two sites and seemed to have the same effect.

I then tried this one http://civicrm.org/blogs/xavier/improve-your-workflow-ajax-one-click-activity-status-changing (which is most like what I actually want to do which is have a one click change of participant status to sign people in when they arrive at an event) and nothing seemed to change.

Is there somewhere in particular I need to insert the code? Any help very much appreciated.

CiviCRM 3.4.8
Drupal 6.2.0

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: API Newbie - help
April 18, 2012, 06:12:13 am
Can you include the part of the template where you included your code? Here is an example of how I use the API in a template, but that might not necessarily answer your question...and it is using the API V2...
Code: [Select]
{crmAPI var="userGroups" entity="group_contact" action="get" contact_id=$session->get('userID')}
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

dowd

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
Re: API Newbie - help
April 18, 2012, 06:45:21 am
Thanks, below is the code in the context of where I put it (for the To be Checked button example)


   {* Include the Actions and Edit buttons if user has 'edit' permission and contact is NOT in trash. *}
        {if $permission EQ 'edit' and !$isDeleted}
            <li class="crm-contact-activity">
                {include file="CRM/Contact/Form/ActionsButton.tpl"}
            </li>
            <li>
                {assign var='editParams' value=$urlParams|cat:"&action=update&cid=$contactId"}
                <a href="{crmURL p='civicrm/contact/add' q=$editParams}" class="edit button" title="{ts}Edit{/ts}">
                <span><div class="icon edit-icon"></div>{ts}Edit{/ts}</span>
                </a>
            </li>
<li>
{literal}
<script>
jQuery(document).ready(function($){
  $("#actions").append('<li><a href="#" id="tobechecked" class="button" title="If the contact details need to be updated"><span>To be checked</span></a></li>');   $("#tobechecked").click(function(){
     $().crmAPI ('entity_tag','add',{
                  tag_id       : 44
                 ,entity_table : 'civicrm_contact'
                 ,entity_id    : {/literal}{$contactId}{literal}
                 },{
                 success:function (){
                   $("#tobecheked").fadeOut('slow');
                 }
                 });
     return false;
   });

});
</script> {/literal}
</li>

        {/if}

        {* Check for permissions to provide Restore and Delete Permanently buttons for contacts that are in the trash. *}
        {if (call_user_func(array('CRM_Core_Permission','check'), 'access deleted contacts') and
        $is_deleted)}
            <li class="crm-contact-restore">
                <a href="{crmURL p='civicrm/contact/view/delete' q="reset=1&cid=$contactId&restore=1"}" class="delete button" title="{ts}Restore{/ts}">
                <span><div class="icon restore-icon"></div>{ts}Restore from Trash{/ts}</span>
                </a>
            </li>

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: API Newbie - help
April 18, 2012, 06:59:17 am
Okay, so which template did you put this in? I am asking so I can have a go to in my local install :-) And you do not see any button or does the API call not work?

What will you want to achieve in the end? I think the example with the activity status change was actually an example with the previous version of the API, will have a play with that one in an old install. You can still do stuff like that , but the api call will probaly be a little different. I am no jQuery wizard, but I could help you with an example in a template?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

dowd

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
Re: API Newbie - help
April 18, 2012, 07:15:14 am
It is in CRM/Contact/Page/View/Summary.tpl
That code (with the second quote taken out of the append bit) displays a button, but the button doesn't seem to do anything. If it's of any help the button seems to link back to the contact record just with a hash symbol at the end of the URL.
Many Thanks

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API Newbie - help
April 18, 2012, 07:19:20 am
Use firebug, likely it displays an error msg

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

dowd

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
Re: API Newbie - help
April 18, 2012, 07:44:56 am
In Chrome's console (never have got on with firebug) without deleting the second quote mark I get an error of "Uncaught SyntaxError:Unexpected token <"
Without the second quote mark I don't seem to get any errors from it at all.

dowd

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
Re: API Newbie - help
April 21, 2012, 03:01:04 am
Just seen that I do get an error message when the button is actually clicked of

Uncaught TypeError: Object #<Object> has no method 'crmAPI'

Does this give any clues?
Thanks!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API Newbie - help
April 21, 2012, 04:56:40 am
Hi,

Might be some conflict between the site jquery & civicrrm one.

Try replacing

jQuery(document).ready(function($){

by

cj (function ($) {
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

geekdenz

  • I’m new here
  • *
  • Posts: 19
  • Karma: 1
    • Geek.De.NZ
  • CiviCRM version: 4.2 (development)
  • CMS version: Drupal 7.12
  • MySQL version: 5
  • PHP version: 5
Re: API Newbie - help
August 16, 2012, 05:11:21 am
http://issues.civicrm.org/jira/browse/CRM-10670 might fix this. Hope this helps.
Twitter: @geekdenz

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API Newbie - help
August 16, 2012, 05:54:07 am
Doesn't your patch mean that if jQuery (from drupal) is already loaded, it uses it instead of re-defining it?

As jQuery in civi is way more recent than the one in drupal, and that they are a lot of plugins for civi that rely (probably) on a specific version of jquery that is higher than the one provided by drupal (or jquery update module), that's likely that is will break something somewhere.

The root of the problem is that two incompatible libraries (the old and the new ones) are both trying to define the same jQuery variable. Nice problem that I don't see how to solve "properly". The existing solution is the less bad, but so far haven't found a better one.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API Newbie - help

This forum was archived on 2017-11-26.