#*
 * Copyright 2012 LinkedIn Corp.
 *
 * 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.
*#

<!DOCTYPE html>
<html lang="en">
<head>

  #parse("azkaban/webapp/servlet/velocity/style.vm")
  #parse("azkaban/webapp/servlet/velocity/javascript.vm")

  <script type="text/javascript" src="${context}/js/azkaban/view/table-sort.js"></script>
  <script type="text/javascript" src="${context}/js/azkaban/view/main.js"></script>
  <script type="text/javascript">
    var contextURL = "${context}";
    var currentTime = ${currentTime};
    var timezone = "${timezone}";
    var errorMessage = null;
    var successMessage = null;
  </script>
</head>
<body>

  #set ($current_page="all")
  #parse ("azkaban/webapp/servlet/velocity/nav.vm")

## Page Header and project search form.

<div class="az-page-header">
  <div class="container-full">
    <div class="row">
      <div class="header-title">
        <h1><a href="${context}/index">Projects</a></h1>
      </div>
      <div class="header-control">
        <form id="search-form" method="get" class="form-inline header-form" role="form">
          <input type="hidden" name="doaction" value="search">
          #if ($viewProjects == 'all')
            <input type="hidden" name="all" value="true">
          #end
          <div class="form-group col-xs-9">
            <div class="input-group">
            <input id="search-textbox" type="text"
                   placeholder="Project name containing..." value=#if($search_term) "$esc.html(${search_term})" #else
              "" #end class="form-control input-sm" name="searchterm">
              <span class="input-group-btn">
                    <button class="btn btn-sm btn-primary">Quick Search</button>
                  </span>
            </div>
          </div>
          #if (!$hideCreateProject)
            <div class="form-group col-xs-3" id="create-project">
            ## Note: The Create Project button is not completely flush to the right because
            ## form-group has padding.
              <div class="pull-right">
                <button type="button" id="create-project-btn" class="btn btn-sm btn-success"><span
                    class="glyphicon glyphicon-plus"></span> Create Project
                </button>
              </div>
            </div>
          #end
        </form>
      </div>
    </div>
  </div>
</div>

<div class="container-full">

  #parse ("azkaban/webapp/servlet/velocity/alerts.vm")

## Table of projects.

  <div class="row row-offcanvas row-offcanvas-left">
    <div class="col-xs-6 col-sm-3 sidebar-offcanvas">
      <ul class="nav nav-pills nav-stacked">
        <li#if ($viewProjects == 'personal') class="active"#end><a
            href="${context}/index">Personal</a></li>
        <li#if ($viewProjects == 'group') class="active"#end><a
            href="${context}/index?group">Group</a></li>
        <li#if ($viewProjects == 'all') class="active"#end><a href="${context}/index?all">All</a>
        </li>
      </ul>
    </div>
    <div class="col-xs-12 col-sm-9 col-content">
      #if (!$projects.isEmpty())
        <ul id="project-list">
          #foreach ($project in $projects)
            <li>
              <div class="project-info">
              ## The UI logic elsewhere enforces that $project.name must start with a letter, followed by any number
              ## of letters, digits, '-' or '_'. Escape it just to play it safe.
              ## todo: make escaping the default.
                <h4><a
                    href="${context}/manager?project=${project.name}">$esc.html($project.name)</a>
                </h4>
                <p class="project-description">$esc.html($project.description)</p>
                <p class="project-last-modified">Last modified on
                  <strong>$utils.formatDate($project.lastModifiedTimestamp)</strong> by
                  <strong>$project.lastModifiedUser</strong>.</p>
              </div>
              <div class="project-expander" id="${project.name}">
                <span class="glyphicon glyphicon-chevron-down project-expander-icon"></span>
              </div>
              <div class="clearfix"></div>
              <div class="project-flows" id="${project.name}-child">
                <h5>Flows</h5>
                <div class="list-group" id="${project.name}-tbody">
                </div>
              </div>
            </li>
          #end
        </ul>
      #else
        <div class="callout callout-default">
          <h4>No Viewable Projects</h4>
          <p>Click Create Project to create a new project.</p>
        </div>
      #end
    </div>
  </div>

## Modal dialog to be displayed to create a new project.

  <div class="modal" id="create-project-modal">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
          </button>
          <h4 class="modal-title">Create Project</h4>
        </div>
        <div class="modal-body">
          <div class="alert alert-danger" id="modal-error-msg">$error_msg</div>
          <fieldset class="form-horizontal">
            <div class="form-group">
              <label for="path" class="col-sm-2 control-label">Name</label>
              <div class="col-sm-10">
                <input id="path" name="project" type="text" class="form-control"
                       placeholder="Project name">
              </div>
            </div>
            <div class="form-group">
              <label for="description" class="col-sm-2 control-label">Description</label>
              <div class="col-sm-10">
                <textarea id="description" name="description" rows="2" cols="40"
                          class="form-control" placeholder="Project description"></textarea>
              </div>
            </div>
          </fieldset>
        </div>
        <div class="modal-footer">
          <input name="action" type="hidden" value="create">
          <input name="redirect" type="hidden" value="$!context/">
          <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
          <button type="button" class="btn btn-primary" id="create-btn">Create Project</button>
        </div>
      </div>
    </div>
  </div>

  #parse ("azkaban/webapp/servlet/velocity/invalidsessionmodal.vm")
</div><!-- /container -->
</body>
</html>


