CiviCRM Community > APIs and Hooks

API Newbie - help

(1/3) > >>

dowd:
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:
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: ---{crmAPI var="userGroups" entity="group_contact" action="get" contact_id=$session->get('userID')}

--- End code ---

dowd:
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:
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?

dowd:
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

Navigation

[0] Message Index

[#] Next page

Go to full version