<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta name="viewport" content="width=device-width">
<title><%= content_for?(:page_title) ? yield(:page_title) : "Puavo Users" %></title>
<%= csrf_meta_tags %>
<%= favicon_link_tag 'favicon.png', skip_pipeline: true %>
<%= stylesheet_link_tag 'font/fontello-puavo/css/puavo-icons', media: 'screen' %>
<%= stylesheet_link_tag 'stylesheets/application_bundle', media: 'all' %>
<%= yield :style %>
<script charset="utf-8">
I18n = {};
I18n.defaultLocale = "<%= I18n.default_locale %>";
I18n.locale = "<%= I18n.locale %>";
</script>
<%= javascript_include_tag "application" %>
<%= yield :javascript %>
</head>

<body>

<div id="topbar">
  <nav>
    <div id="left">
      <% if current_user %>
      <ul class="asFlex">
        <% unless current_user.organisation_owner? %>
        <li class="asFlex noDropdown"><span class="menuTitle"><%= current_organisation.name %></span></li>
        <% else %>
        <li class="asFlex haveTopDropdown"><span class="menuTitle"><%= current_organisation.name %></span>
          <ul class="topDropdown">
            <li><%= link_to t('.about'), organisation_path %></li>
            <li class="org-separator"></li>
            <% if Puavo::CONFIG %>
            <li><%= link_to t('.servers'), "/devices/servers" %></li>
            <li><%= link_to t('.printers'), "/devices/printers" %></li>
            <li><%= link_to t('.all_devices'), "/all_devices" %></li>
            <li><%= link_to t('.all_images'), "/all_images" %></li>
            <% end %>
            <li><%= link_to t('.wlan'),  wlan_organisation_path %></li>
            <li class="org-separator"></li>
            <li><%= link_to t('.owners'), owners_organisation_path %></li>
            <li><%= link_to t('.all_admins'), all_admins_organisation_path %></li>
            <li><%= link_to t('.all_users'), "/all_users" %></li>
            <li class="org-separator"></li>
            <li><%= link_to t('.all_groups'), "/all_groups" %></li>
            <li class="org-separator"></li>
            <li><%= link_to t('external_services.title'),  organisation_external_services_path %></li>
            <% if Puavo::EXTERNAL_FILES %>
            <li><%= link_to t('.external_files'), external_files_path %></li>
            <% end %>
            <li class="org-separator"></li>
            <li><%= link_to t('.ldap_services'),  ldap_services_path %></li>
            <% if @pme_enabled %>
            <li class="org-separator"></li>
            <li><%= link_to t('.puavomenu_editor'), organisation_puavomenu_path %></li>
            <% end %>
          </ul>
        </li>
        <% end %>

        <li class="asFlex haveTopDropdown"><span class="menuTitle"><%= t('.schools') %></span>
          <ul class="topDropdown separators schools">
            <% if @is_owner || School.all_with_permissions(current_user).count > 1 %>
            <li><a href="/users"><%= t('.index') %></a></li>
            <% end %>
            <% school_list.each do |school| %>
            <li><span class="schoolTitle"><%= link_to school.displayName, school_path(school) %></span>
              <ul class="schoolLinks">
<% if current_user.organisation_owner? %>
                <li><%= link_to t('schools.menu.admins'), admins_school_path(school) %></li>
<% end %>
                <li><%= link_to t('.users'), users_path(school) %></li>
                <li><%= link_to t('.groups'), groups_path(school) %></li>
                <li><%= link_to t('.devices'), devices_path(school) %></li>
              </ul>
            </li>
            <% end %>
          </ul>
        </li>
      </ul>
      <% end %>
    </div>

    <div id="middle">
      <div>
      <%= text_field_tag('search',
                         nil,
                         class: 'searchBox quickSearch',
                         size: 30,
                         placeholder: t('.search_placeholder'),
                         title: t('.search_title')) %>

      <% if current_user && current_user.organisation_owner? %>
      <a href="/extended_search" id="extendedSearchButton" class="ownersOnly" title="<%= t('.extended_search_title') %>">
        <img src="<%= image_path('magnifier.png', skip_pipeline: true) %>"></a>
      <% end %>
      </div>
    </div>

    <div id="right">
      <ul class="asFlex">
        <% if show_language_selector? %>
        <%= topbar_language_selector %>
        <% end %>

        <li class="asFlex haveTopDropdown"><span class="menuTitle" id="loggedInName"><%= h current_user.displayName %></span>
          <ul class="topDropdown dropRight">
            <li><%= link_to t('.your_account'), user_path(current_user.primary_school.id, current_user) %></li>
            <li>
              <%= link_to logout_path, method: :delete, class: 'logoutButton' do %>
                <i class="icon-logout"></i> <%= t('.logout') %>
              <% end %>
            </li>
          </ul>
        </li>
      </ul>
    </div>
  </nav>
</div>

<div id="pageWrapper">
  <div id="pageContainer">
    <% if current_organisation? %>
    <% if @school && !@school.id.nil? && controller_name != 'password' %>

    <div id="schoolHeader">
      <header id="schoolName"><%= @school.displayName %></header>

      <% unless @school.displayName == 'Administration' %>
<%= render :partial => "layouts/integrations", :locals => {
        :integrations_by_type => get_school_integrations_by_type(@organisation_name, @school.id),
        :integration_names => get_school_integration_names(@organisation_name, @school.id),
        :next_updates => get_school_integration_next_updates(@organisation_name, @school.id, Time.now),
        :extraClass => ""
    } %>
      <% end %>
    </div>

<%= render :partial => "layouts/menu" %>
    <% end %>
    <% end %>

    <div id="content">
      <% if message_keys = flash.keys.select { |key| ["error", "notice", "success", "alert"].include?(key) } %>
      <% message_keys.each do |key| %>
      <p class="message_<%= key %>"><%= flash[key].html_safe %></p>
      <% end %>
      <% end %>

      <% if current_user && content_for?(:page_tools) %>
      <ul class="pageTools">
      <%= yield :page_tools %>
      </ul>
      <% end %>

      <%= yield %>
    </div>
    <footer><%= debug_footer %></footer>
  </div> <!-- pageContainer -->
</div> <!-- pageWrapper -->
<%= yield :post_load_javascript %>
</body>
</html>
