app/views/contacts/_side_panel.html.erb
<div class="contacts side">
<div class="btn-group" id="select_department">
<button class="btn btn-small dropdown-toggle" id="select_department_button" data-toggle="dropdown"><%= t("contacts.department") %> <span class="caret"> </span> </button>
<ul class="dropdown-menu" id="select_department_dropdown">
<% ContactsController.select_departments.each do |department| %>
<li><a href="#" id="<%= department.id %>"><%= department.name %></a></li>
<% end %>
<li class="divider"></li>
<li><a href="#" id="all"><%= t("commons.all") %></a></li>
</ul>
</div>
<div class="new">
<div class="contacts-list">
<%= render :partial => 'contacts/list', :locals => { items: @contacts } %>
</div>
<% if can? :create, :contact %>
<%= link_to t("contacts.new.link"), new_customer_contact_path(@customer), :class => "new-link btn btn-primary" %>
<% end %>
</div>
</div>
<script>
//component bt menu selector
var current_department = -1;
var select_department_callback;
$("#select_department li a").on("click", function(e) {
if ($(this).attr("id")=="all") {
current_department = -1;
} else {
current_department = $(this).attr("id");
}
$("#select_department_button").text($(this).html());
select_department_callback(current_department);
})
//page flow
function record_created() {
showMessage("<%= t("helpers.forms.new_sucess") %>");
update_contacts();
}
function update_contacts(id) {
element = $('.contacts.side .new .contacts-list');
if (id>0) {
element.load("<%= customer_contacts_path(@customer) %>.json?department="+id);
} else {
element.load("<%= customer_contacts_path(@customer) %>.json");
}
}
$(document).ready(function() {
//update_contacts();
});
select_department_callback = update_contacts;
</script>