<%= stylesheet_link_tag "lib/wrap-nav" %>
<%= stylesheet_link_tag "lib/main-list" %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload.css" %>
<%= stylesheet_link_tag "lib/togglebox.css" %>
<%= stylesheet_link_tag "lib/list-check.css" %>

<%= javascript_include_tag "lib/site_set" %>
<%= javascript_include_tag "lib/list-check" %>

<% content_for :side_bar do %>
  <%= render :partial => 'layouts/side_bar', :locals => {:link_name => t('site.settings'), :link_url => admin_site_site_info_path(@site), :icon => 'icons-cog', :side_bar_content => 'admin/sites/side_bar'} %>
<% end %>

<form class="form-horizontal main-forms">
  <fieldset>
    <div class="input-area">
      <div class="nav-name"><strong><%= t("preferences.classification") %></strong></div>
      <ul class="nav nav-pills language-nav">
        <li class="active"><a href="#overview" data-toggle="tab"><%= t("site.system_preference_.tab_summary") %></a></li>
        <li><a href="#user-actions" data-toggle="tab"><%= t("user_actions") %></a></li>
        <li><a href="#mail-cron-logs" data-toggle="tab"><%= t("site.system_preference_.tab_send_reminders_log") %></a></li>
      </ul>
       
      <div class="tab-content">
        <!-- Overview -->
        <div id="overview" class="tab-pane fade in active">
          <h3 class="muted"><%= t("site.system_preference_.summary.disk_space") %></h3>
          <blockquote>
            <p>
              <%= @disk_free %>
            </p>
          </blockquote>
          <h3 class="muted">Nginx <%= t("site.system_preference_.summary.version") %></h3>
          <blockquote>
            <p>
              <%= @nginx_version  %>
            </p>
          </blockquote>
          </span>
          <h3 class="muted">MongoDB <%= t("site.system_preference_.summary.version") %></h3>
          <blockquote>
            <p>
              <%= @mongo_version  %>
            </p>
          </blockquote>
          <h3 class="muted">Linux <%= t("site.system_preference_.summary.version") %></h3>
          <blockquote>
            <p>
              <%= @linux_version  %>
            </p>
          </blockquote>
          </span>   
        </div>

        <!-- User Actions -->
        <div id="user-actions" class="tab-pane fade">
          <h3 class="muted"><%= t("user_actions") %></h3>
          <table class="table" id="user_actions">
            <tr>
              <th><%= I18n.t 'user_action.time' %></th>
              <th><%= I18n.t 'user_action.name' %></th>
              <th><%= I18n.t 'user_action.page' %></th>
            </tr>
            <%= render :partial => "user_action", :collection=> @user_actions%>
          </table>

          <div class="user-paginate text-center" style="display:none">
            <%= paginate @user_actions, :remote => true %>
          </div>
        </div>

        <!-- Email Log -->
        <div id="mail-cron-logs" class="tab-pane fade">
          <ul class="nav nav-pills">
            <li class="active">
              <a href="#send-log" data-toggle="tab"><%= t(:email_log) %></a>
            </li>
            <li>
              <a href="#waiting-sent" data-toggle="tab"><%= t(:email_queue) %></a>
            </li>
          </ul>
          <div class="tab-content">
            <div class="tab-pane fade in active list-check" id="send-log">
              <p class="">
                <%=  link_to(content_tag(:i, nil, :class => "icons-trash"), '#', :class => "btn list-active-btn disabled", :rel => delete_admin_mail_cron_logs_path) if at_least_module_manager %>
              </p>
              <table id="mail_cron_logs" class="table main-list table-striped">
                <thead>
                  <tr>
                    <th>
                      <input type="checkbox" name="to_delete[]" value="b" />
                    </th>
                    <th><%= t(:sent_date) %></th>
                    <th><%= t(:subject) %></th>
                    <th><%= t(:mail_user) %></th>
                    <th><%= t(:mail_from_app) %></th>
                  </tr>
                </thead>
                <tbody>
                  <%= render :partial => "mail_cron_log", :collection=> @mail_cron_logs%>
                </tbody>
              </table>

              <div class="paginate text-center" style="display:none">
                <%= paginate @mail_cron_logs, :remote => true %>
              </div>
              
            </div>
            <div class="tab-pane fade in list-check" id="waiting-sent">
              <p class="">
                <%=  link_to(content_tag(:i, nil, :class => "icons-trash"), '#', :class => "btn list-active-btn disabled", :rel => delete_admin_mail_crons_path) if at_least_module_manager %>
              </p>
              <table class="table main-list table-striped">
                <thead>
                  <tr>
                    <th>
                      <input type="checkbox" name="to_delete[]" value="b" />
                    </th>
                    <th><%= t(:sent_date) %></th>
                    <th><%= t(:subject) %></th>
                    <th><%= t(:mail_from_app) %></th>
                  </tr>
                </thead>
                <tbody>
                  <%= render :partial => "mail_cron",:collection=> @mail_crons%>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </fieldset>
</form>

<div id="dialog" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="Delete item" aria-hidden="true">
  <div class="modal-header">
    <a class="close" data-dismiss="modal">×</a>
    <h3><%= t(:sure?) %></h3>
  </div>
  <div class="modal-body">
    <span class="text-warning text-center"><%= t(:this_action_can_not_be_restore) %></span>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true"><%= t(:close) %></button>
    <button class="delete-item btn btn-danger"><%= t(:delete_) %></button>
  </div>
</div>


<script>

  function checkScroll() {
    if (nearBottomOfPage()) {
      if($(".next a").length != 0){
        $.rails.handleRemote($(".next a"));
      }
    } else {
      setTimeout("checkScroll()", 250);
    }
  }

  function nearBottomOfPage() {
    return scrollDistanceFromBottom() < 150;
  }

  function scrollDistanceFromBottom(argument) {
    return pageHeight() - (window.pageYOffset + self.innerHeight);
  }

  function pageHeight() {
    return Math.max(document.body.scrollHeight, document.body.offsetHeight);
  }

  $(document).ready(function(){
    checkScroll();
  });

</script>
