$(function(){ var cheesecakeData = { container: { id: "contacts_cheesecake", width: 440, height: 440 }, grid: { id: "contacts_grid", divIdPrefix: "actor_" }, rMax : 200, center: {x : 220, y : 220} }; cheesecakeData.highlightedSectorCallback = function(cheesecake){ $("#contacts_grid").css("overflow-y","hidden"); var sector = cheesecake.highlightedSector; var actors = []; var visibles = 0; var extra_text = ["<%= t('cheesecake.hidden_contact.one')%>","<%= t('cheesecake.hidden_contact.other')%>"]; if(sector){ actors = sector.actors; }else{ actors = cheesecake.grid.actors; } for(var i in actors){ if(actors[i].isVisible()){ visibles++; } } if(visibles <= 30){ $("#contacts_grid_extra").hide(); }else{ $("#contacts_grid_extra_total").html(visibles - 30); if((visibles - 30) == 1){ $("#contacts_grid_extra_text").html(extra_text[0]); }else{ $("#contacts_grid_extra_text").html(extra_text[1]); } $("#contacts_grid_extra").show(); $("#contacts_grid").scrollTo(0, 1000); } } cheesecakeData.sectors = <%= raw(current_subject.cheesecake_json) %>.sectors; var cheese = new socialCheesecake.Cheesecake(cheesecakeData); $("#contacts_filter_input").keyup(function(){ cheese.searchEngine.filter($("#contacts_filter_input").val()); cheesecakeData.highlightedSectorCallback(cheese); }); cheese.onChange = function(cheesecake){ var initial = cheesecake.getInitialState(); var changes = cheesecake.getChanges(); var changes_html = ""; var actors = changes.actors; $("#contacts_save_changes").val(JSON.stringify(changes)); for(var i in actors){ actor = actors[i]; if(actor.justAdded){ var new_subsectors = actor.subsectors; var new_subsectors_string = ""; for(var i in new_subsectors){ if(i > 0) new_subsectors_string += ", "; new_subsectors_string += cheesecake.getSubsectorById(new_subsectors[i]).label; } changes_html += "
" + actor.name + " has been removed from " + old_subsectors_string + "
"; }else if(actor.subsectors.length==0){ var old_subsectors = []; var old_subsectors_string = ""; for(var i in initial.actors){ if(actor.id==initial.actors[i].id){ old_subsectors = initial.actors[i].subsectors; break; } } for(var i in old_subsectors){ if(i > 0) old_subsectors_string += ", "; old_subsectors_string += cheesecake.getSubsectorById(old_subsectors[i]).label; } changes_html += "
" + actor.name + " has been removed from " + old_subsectors_string + "
"; }else{ var old_subsectors = []; var new_subsectors = actor.subsectors; var left_subsectors = ""; var joined_subsectors = ""; for(var i in initial.actors){ if(actor.id==initial.actors[i].id){ old_subsectors = initial.actors[i].subsectors; break; } } for(var i in old_subsectors){ if(new_subsectors.indexOf(old_subsectors[i])==-1){ if(left_subsectors.length!=0){ left_subsectors += ", "; } left_subsectors += cheesecake.getSubsectorById(old_subsectors[i]).label; } } for(var i in new_subsectors){ if(old_subsectors.indexOf(new_subsectors[i])==-1){ if(joined_subsectors.length!=0){ joined_subsectors += ", "; } joined_subsectors += cheesecake.getSubsectorById(new_subsectors[i]).label; } } if((joined_subsectors.length!=0)&&(left_subsectors.length!=0)){ changes_html += "
" + actor.name + " has been removed from " + left_subsectors + " and added to " + joined_subsectors + "
"; }else if(joined_subsectors.length!=0){ changes_html += "
" + actor.name + " has been added to " + joined_subsectors + "
"; }else{ changes_html += "
" + actor.name + " has been removed from " + left_subsectors + "
"; } } } $("#contacts_changes_details").html(changes_html); if (!$("#contacts_changes_details").is (":visible")){ $("#contacts_changes_details").slideToggle("slow"); } } if(cheese.grid.actors.length > 30){ var extra_text = ["<%= t('cheesecake.hidden_contact.one')%>","<%= t('cheesecake.hidden_contact.other')%>"]; $("#contacts_grid_extra_total").html(cheese.grid.actors.length - 30); if((cheese.grid.actors.length - 30) == 1){ $("#contacts_grid_extra_text").html(extra_text[0]); }else{ $("#contacts_grid_extra_text").html(extra_text[1]); } $("#contacts_grid_extra").show(); } });