Skip to content
Snippets Groups Projects
Commit 36f33d1a authored by xavier's avatar xavier
Browse files

add groups

parent a640aeb7
Branches OO
No related tags found
No related merge requests found
......@@ -7,13 +7,17 @@
</div>
</div>
<script>
{*
var data={crmAPI entity='GroupContact' action='get' sequential=1 contact_id=$contactId};
to avoid creating javascript global variables, wrap them in an anonymous function and assign the parameters from smarty variables on the last line before {/literal}
*}
{literal}
<style>
.groups .crm-label,#group_add li {cursor:pointer;}
</style>
<script>
(function(contact_id,data){
cj(function($){
......@@ -28,10 +32,35 @@ cj(function($){
$.each(data.values, function(key) {
groups.push(data.values[key].title);
});
$(".groups .crm-content").html(groups);
$(".groups .crm-content").html(groups.join(","));
$(".groups .crm-label").click(function(){
CRM.api('Group', 'get', {'sequential': 1},
{success: function(data) {
var groups= "<ul id='group_add'>";
$.each(data.values, function(key) {
groups = groups + "<li data-id='"+data.values[key].id+"'>"+data.values[key].title+"</li>";
});
groups = groups + "<ul>";
CRM.alert(groups,"add to a group","info",{expires:0});
$("#group_add li").click(function(){
var id = $(this).data("id");
var name = $(this).html();
CRM.api('GroupContact', 'create', {'sequential': 1, 'group_id':id,'contact_id': contact_id},
{success: function(data) {
var groups =$(".groups .crm-content").html();
$(".groups .crm-content").html(groups+","+name);
CRM.alert("group added",name,"success");
}}
);
})
}
});
});
});
}
{/literal}
({$contactId},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment