<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% provide :page_title, t(:page_title, "Rubrics") %>
<% add_crumb t('#crumbs.rubrics', "Rubrics") %>
<% if !!js_env.dig(:PERMISSIONS, :manage_rubrics)%>
  <% provide :right_side do %>
    <a href="<%= context_url(@context, :context_rubrics_url) %>" class="btn button-sidebar-wide add_rubric_link">
      <i class="icon-add"></i>
      <%= t('buttons.add_rubric', 'Add Rubric') %>
    </a>
  <% end %>
<% end %>

<% js_bundle :edit_rubric %>
<% css_bundle :learning_outcomes %>
<% css_bundle :proficiency_table %>

  <style>
    #rubrics .find_rubric_link {
      display: none;
    }
    #right-side-wrapper {
      height: 100%;
    }
  </style>

<% js_bundle 'legacy/rubrics_index' %>
<h1>
  <% case @context.class.to_s %>
    <% when 'Course' %>
      <%= t 'course_rubrics', "Course Rubrics" %>
    <% when 'User' %>
      <%= t 'user_rubrics', "User Rubrics" %>
    <% when 'Account' %>
      <%= t 'account_rubrics', "Account Rubrics" %>
  <% end %>
</h1>
<a href="<%= context_url(@context, :context_rubrics_url) %>" id="add_rubric_url" style="display: none;">&nbsp;</a>
<% if @context.class.to_s == 'Account' %>
<div id="rubric_management"></div>
<% end %>
<div id="rubrics" class="raw_listing">
  <ul>
  <% @rubric_associations.each do |association| %>
    <% rubric = association.rubric %>
    <li>
      <a href="<%= context_url(@context, :context_rubric_url, association.rubric_id) %>" class="title"><%= rubric.title %></a>
      <span class="links">
        <% if can_do(rubric, @current_user, :update) %>
          <a href="<%= context_url(@context, :context_rubric_url, association.rubric_id) %>#edit" class="hide-till-hover" title="<%= t('Edit Rubric: %{title}', title: rubric.title) %>" aria-label="<%= t('Edit Rubric: %{title}', title: rubric.title) %>"><i class="icon-edit standalone-icon"></i></a>
        <% end %>
        <% if can_do(association, @current_user, :delete) %>
          <a href="<%= context_url(@context, :context_rubric_url, rubric.id) %>" class="delete_rubric_link hide-till-hover" title="<%= t('Delete Rubric: %{title}', title: rubric.title) %>" aria-label="<%= t('Delete Rubric: %{title}', title: rubric.title) %>"><i class="icon-end standalone-icon"></i></a>
        <% end %>
      </span>
      <span class="details">
        <%= t({:one => "1 criterion", :other => "%{count} criteria"}, :count => rubric.criteria.length) %><br/>
        <%= t('points_possible', {:one => "1 point possible", :other => "%{count} points possible"}, :count => round_if_whole(rubric.points_possible)) unless rubric.points_possible.nil? %>
      </span>
    </li>
  <% end %>
  </ul>
  <div style="display: none;" id="rubric_parameters">
    <input type="hidden" name="rubric_association[association_type]" value="<%= @context.class.to_s %>"/>
    <input type="hidden" name="rubric_association[association_id]" value="<%= @context.id %>"/>
    <input type="hidden" name="rubric_association[purpose]" value="bookmark"/>
  </div>
  <span class="current_user_id" style="display: none;"><%= @current_user.id %></span>
  <a href="<%= context_url(@context, :context_rubrics_url) %>" class="add_rubric_association_url" style="display: none;">&nbsp;</a>
</div>
<div id="rubric_attic" style="display: none;"></div>
<%= render :partial => "shared/find_outcome" %>
<%= render :partial => "shared/rubric", :object => nil, :locals => {:for_context => true} %>
<%= render :partial => "shared/rubric_criterion_dialog" %>
