[%# This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  #
  # This Source Code Form is "Incompatible With Secondary Licenses", as
  # defined by the Mozilla Public License, v. 2.0.
  #%]

[% PROCESS global/variables.none.tmpl %]

[% PROCESS global/header.html.tmpl
  title = "My Dashboard"
  generate_api_token = 1
  style_urls = [ "skins/yui3.css",
                 "extensions/MyDashboard/web/styles/mydashboard.css",
                 "extensions/ProdCompSearch/web/styles/prod_comp_search.css" ]
  javascript_urls = [ "js/yui3.js",
                      "extensions/MyDashboard/web/js/query.js",
                      "extensions/MyDashboard/web/js/flags.js",
                      "extensions/ProdCompSearch/web/js/prod_comp_search.js",
                      "js/bug.js" ]
%]

[% standard_queries = [] %]
[% saved_queries    = [] %]
[% FOREACH q = queries %]
  [% standard_queries.push(q) IF !q.saved %]
  [% saved_queries.push(q) IF q.saved %]
[% END %]

<script id="last-changes-stub" type="text/x-handlebars-template">
  <div id="last_changes_stub_{{bug_id}}">Loading...</div>
</script>
<script id="last-changes-template" type="text/x-handlebars-template">
  <div id="last_changes_{{bug_id}}">
    {{#if email}}
      <div id="last_changes_header">
        Last Changes :: {{email}} :: {{when}}
      </div>
      {{#if activity}}
        <table id="activity">
        {{#each activity}}
          <tr>
            <td class="field_label">{{field_desc}}:</td>
            <td class="field_data">
              {{#if removed}}
                {{#unless added}}
                  Removed:
                {{/unless}}
                {{removed}}
              {{/if}}
              {{#if added}}
                {{#if removed}}
                  &rarr;
                {{/if}}
              {{/if}}
              {{#if added}}
                {{#unless removed}}
                  Added:
                {{/unless}}
                {{added}}
              {{/if}}
            </td>
          </tr>
        {{/each}}
        </table>
      {{/if}}
      {{#if comment}}
        <pre class='bz_comment_text'>{{comment}}</pre>
      {{/if}}
    {{else}}
      This is a new [% terms.bug %] and no changes have been made yet.
    {{/if}}
  </div>
</script>

<script [% script_nonce FILTER none %]>
  [% IF Param('splinter_base') %]
    MyDashboard.splinter_base = '[% Bugzilla.splinter_review_base FILTER js %]';
  [% END %]
</script>

<div id="mydashboard">
  <div>
    <label class="switch">
      <input id="auto_refresh" type="checkbox">
      <span class="slider round"></span>
    </label>
    Auto-refresh every 10min
  </div>

  <div class="yui3-skin-sam">
    <div id="left">
      <div id="query_list_container">
        Choose query:
        <select id="query" name="query">
          <optgroup id="standard_queries" label="Standard">
            [% FOREACH r = standard_queries %]
              <option value="[% r.name FILTER html %]">[% r.heading || r.name FILTER html %]</option>
            [% END%]
          </optgroup>
          <optgroup id="saved_queries" label="Saved">
            [% FOREACH r = saved_queries %]
              <option value="[% r.name FILTER html %]">[% r.heading || r.name FILTER html %]</option>
            [% END %]
          </optgroup>
        </select>
        <small>
          (<a href="[% basepath FILTER none %]userprefs.cgi?tab=saved-searches">add or remove saved searches</a>)
        </small>
      </div>

      <div id="query_container">
        <h2 class="query_heading"></h2>
        <div class="query_description"></div>
        <span id="query_loading" class="items_found">Loading...</span>
        <span id="query_count_refresh" class="bz_default_hidden">
          <span class="items_found" id="query_bugs_found">0 [% terms.bugs %] found</span>
          | <a class="refresh"     href="javascript:void(0);" id="query_refresh">Refresh</a>
          <span id="bar_markread">|</span> <a class="markread" href="javascript:void(0);" id="query_markread">none</a>
            <span class="markread bz_default_hidden" id="query_markread_text">none</span>
          | <a class="buglist"     href="javascript:void(0);" id="query_buglist">Buglist</a>
        </span>
        <div id="query_pagination_top"></div>
        <div id="query_table"></div>
      </div>
    </div>

    <div id="right">
      <div id="prod_comp_search_main">
        [% PROCESS prodcompsearch/form.html.tmpl
           input_label = "File a $terms.Bug:"
           script_name = "enter_bug.cgi"
           new_tab     = 1
        %]
      </div>

      [% IF Param('phabricator_enabled') %]
        <h2 class="query_heading requests">
          <a href="[% Param('phabricator_base_uri') %]differential">Phabricator Review Requests</a>
        </h2>
      [% END %]

      [% BLOCK requests_table %]
        <div id="[% name FILTER html %]_container" class="requests">
          <h2 class="query_heading">[% title FILTER html_light %]</h2>
          <span id="[% name FILTER html %]_loading" class="items_found">Loading...</span>
          <span id="[% name FILTER html %]_count_refresh" class="bz_default_hidden">
          <span class="items_found" id="[% name FILTER html %]_flags_found">0 requests found</span>
          | <a class="refresh" href="javascript:void(0);" id="[% name FILTER html %]_refresh">Refresh</a>
          | <a class="buglist" href="javascript:void(0);" id="[% name FILTER html %]_buglist">Buglist</a>
          </span>
          <div id="[% name FILTER html %]_table"></div>
        </div>
      [% END %]

      [% PROCESS requests_table name='requestee' title='Requests for You' %]
      [% PROCESS requests_table name='requester' title='Requests from You' %]
    </div>

    <div style="clear:both;"></div>
    [% IF user.showmybugslink OR user.queries.size OR user.queries_subscribed.size %]
      <hr>
      <section id="saved_searches_container">
        <header>
          <h2 class="query_heading">Saved Searches</h2>
          <a href="[% basepath FILTER none %]userprefs.cgi?tab=saved-searches">Edit</a>
        </header>
        <ul>
          [% IF user.showmybugslink %][% filtered_username = user.login FILTER uri %]
            <li><a href="[% basepath FILTER none %][% Param('mybugstemplate').replace('%userid%', filtered_username) %]">
                My [% terms.Bugs %]</a></li>
          [% END %]
          [% FOREACH q = user.queries %][% IF q.link_in_footer %]
            <li><a href="[% basepath FILTER none %]buglist.cgi?cmdtype=runnamed&amp;namedcmd=[% q.name FILTER uri %]">
                [% q.name FILTER html %]</a></li>
          [% END %][% END %]
          [% FOREACH q = user.queries_subscribed %]
            <li><a href="[% basepath FILTER none %]buglist.cgi?cmdtype=dorem&amp;remaction=run&amp;namedcmd=
                [% q.name FILTER uri %]&amp;sharer_id=[% q.user.id FILTER uri %]"
                title="Shared by [% q.user.identity FILTER html %]">[% q.name FILTER html %]</a></li>
          [% END %]
        </ul>
      </section>
    [% END %]
  </div>
</div>

[% PROCESS global/footer.html.tmpl %]
