<% unless in_mobile_view? %>

  <script type="text/javascript">
    function reloadToDoLists(){
      $.ajax({type: 'GET', url: '<%= j show_toolbar_easy_to_do_lists_path %>'});
    }

  //<![CDATA[
  registerPanelHandlerTarget({
      containerName: 'easy_servicebar_component',
      easyServicebarTrigger: '#easy_to_do_list_toolbar_trigger',
      allowedEntity: function(entity) {
        return $().easy_to_do_list_accepted_entity(entity);
      },
      handlerAllowed: function(handler) {
        return $().easy_to_do_list_accepted_entity(handler.data().entityType);
      },
      dataAttributes: function(handler) {
        return {"data-handler-entity-id": handler.data().entityId}
      },
      connectToSortable: function() {return ".to-do-list ul"},
      handlerDraggableStart: function(event, ui) {
      }
  });
  $(function(){
    $('#easy_to_do_list_toolbar_trigger').click(function(){
      $.ajax({
        url: '<%=j easy_to_do_lists_path(:format => 'json') %>',
        type: 'GET',
        noLoader: true,
        complete: function(response) {
          if (response.length > 0) {
            var totalToDos = 0;
            $.each(response, function(index, list) {
              totalToDos += list.easy_to_do_list.easy_to_do_list_items.length;
            });
            if (totalToDos > 0) {
              var mark = $("<span/>").attr({"class":"sign count"}).text(totalToDos);
              trigger.addClass('has-sign');
              trigger.append(mark);
            }
          }
        }
      });
    });
  })
  //]]>
  </script>
<% end -%>
