<%-# Fedena
#Copyright 2010 Foradian Technologies Private Limited
#
#This product includes software developed at
#Project Fedena - http://www.projectfedena.org/
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing,
#software distributed under the License is distributed on an
#"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#KIND, either express or implied.  See the License for the
#specific language governing permissions and limitations
#under the License. -%>
<div id="content-header">
<%#*<img src="/images/show_timetable.png" />%>
  <%= link_to  image_tag("/images/show_timetable.png"),:controller=>:timetable %>
  <h1><%= t('timetable_text') %></h1>
  <h3><%= t('work_allotment') %></h3>
  <div id="app-back-button">
    <%= link_to_function image_tag("/images/buttons/back.png",:border => 0), "history.back()" %>
  </div>
</div>
<div id="inner-tab-menu">
  <ul>
    <li>
      <%= link_to t('assign_multiple_teachers'), :controller=>"employee", :action=>"subject_assignment"%>
    </li>
  </ul>
</div>
<div id="page-yield">
  <% unless flash[:notice].nil? %>
    <p class="flash-msg">
      <%= flash[:notice] %>
    </p>
  <% end %>

  <% form_for :employee_subjects,:html=>{:id=>'work_allotment_form'} do |f| %>
    <% @batches.each do |batch| %>
      <ul class="category-list">
        <li class="heading">
          <%= batch.full_name %>
        </li>
        <% batch.subjects.each do |subj| %>
          <% subj.employees.each do |e|  %>
            <% ep=@employees.find_by_id(e.id) %>
            <% if ep.present? %>
              <% ep.total_time = (ep.total_time.to_i - subj.max_weekly_classes.to_i) %>
            <% end %>
          <% end %>
          <li class="list<%=cycle('odd','even')%>">
            <div class="category-subject-name"><%= "#{subj.name}" %></div>
            <div class="category-employee-options">
              <%= select_tag   "employee_subjects[#{subj.id}]", options_for_select([[t('select_employee'),""]]+@employees.map{|em| [em.full_name,em.id]},subj.employees.first.try(:id)) %>
            </div>
            <div class="category-employee-names"><%= "#{subj.employees.collect(&:full_name).join(',')}" %></div>
          </li>
        <% end %>
      </ul>
    <% end %>
    <%= f.submit "► #{t('update')}",:class=>:submit_button %>
  <% end %>
  <ul id="teacher_status" class="category-list">
    <% @employees.each do |emp| %>
      <li class="listodd" ><%= emp.full_name %><span id="emp_status_<%=emp.id%>">
          <% if emp.total_time.to_i < 0 %>
            <span class='deficit'><%= 0-emp.total_time.to_i %> deficit</span>
          <% elsif emp.total_time.to_i==0 %>
            <span class='ok'>OK</span>
          <% else %>
            <span class='remaining'><%= emp.total_time.to_i %> remaining</span>
          <% end %>
        </span></li>
    <% end %>
  </ul>
</div>