Hi all,
For the training in london, we wanted a simple example that illustrates how to customise and improve civicrm for specific usages using the ajax interface. I'm sharing the result with you, hoping you will find it useful.
One common workflow we have is to change the status of an activity from "scheduled" to "complete". The default way is to click on edit, go to the full form, change the status, save, and go back to the list of activities
We are going to improve it with a "one click click complete": on the list of activities, we transform the status column into an action (when "scheduled"), and when I click on it, it changes it to Completed, without changing screen. For that, we are using the ajax interface and the activity api. Copy the template templates/CRM/Activity/Selector/Activity.tpl into your override directory, and add a few lines of jQuery at the top:
{literal}
<script>
jQuery(function ($){
$("td.crm-activity-status_1")
.attr("title","Change the status to completed")
.css("cursor","pointer")
.click (function () {
aid=$(this).parent("tr").attr('id');
var activity_id = aid.replace("crm-activity_", "");
cj().crmAPI ('activity','update',{id:activity_id,status_id:2},
{callBack: function(result,settings){
if (result.is_error == 1) {
$(settings.msgbox)
.addClass('msgnok')
.html(result.error_message);
return false;
} else {
$('#crm-activity_'+activity_id)
.removeClass('status-overdue')
.find('td.crm-activity-status_1')
.removeClass('crm-activity-status_1')
.addClass('crm-activity-status_2')
.html("Completed");
}
}
});
});
});
</script>
{/literal}
Oh, it's magic! What does it do in detail ? Well, you should attend a developer training, you will discover it, and way more ;)
X+