<%inherit file="master.html"/>
<div class="container">
  <div id='js-warning' class="col-md-10 col-md-offset-1 m-t-3">
    <div class="alert alert-warning">
        <h3>
          % if not update:
          Creating a new update requires JavaScript
          % else:
          Editing an update requires JavaScript
          % endif
        </h3>
        <p>If you have JavaScript disabled with a plugin like NoScript, please
        disable that plugin and reload the page.  If you trust Fedora
        Infrastructure, you might find it convenient to enable JavaScript just
        for the domain <code>fedoraproject.org</code>.</p>
        <p>If you are opposed to JavaScript in principle, you're not left out!
        Please use the fully-featured <a href="#">Bodhi command-line
        interface tool</a>.</p>
    </div>
  </div>

  <div id="new-update-form" class="p-t-3" style="display:none;">
    <div class="row">
      <div class="col-md-12">
        % if not update:
          <h2 class="pull-left">New Update</span>
        % else:
          <h2 class="pull-left">Edit
            % if update.alias:
            ${update.alias}
            % else:
            ${update.get_title(', ', 2, ", &hellip;") | n}
            <div>
              <span title="${(', ').join(map(lambda x: x.nvr, update.builds[2:]))}">
                <small>${ "(+ " + str(len(update.builds) - 2) + " more)" if len(update.builds) > 2 else "" }</small>
              </span>
            </div>
          % endif
        </h2>
        % endif
      </div>
    </div>

    <div class="row">

      <div class="col-md-5">
        <div class="card card-form">
          <div class="card-header clearfix">
            <span class="pull-left" data-placement="bottom" data-toggle="tooltip" title="This is a helper field, here only to pre-populate the builds and the bugs lists with relevant options.  You can leave it empty if you like.">
            Packages</span>
          </div>
          <div class="card-block p-a-0">
            <form id="search" role="search">
              <div id="packages-search" class="form-group noui m-b-0">
                <input class="typeahead form-control noui" name="term" type="text"
                       placeholder="Add a package">
              </div>
            </form>
          </div>
        </div>

        <div class="card card-form">
          <div class="card-header clearfix">
            <span class="pull-left" data-placement="bottom" data-toggle="tooltip" title="Here you can add a list of candidate builds that you want to be included in this update.  This is required.  (What is an update without a list of builds anyways... it doesn't make any sense.)">
            Candidate Builds</span>
          </div>
          <div class="card-block p-a-0">
            <div id="builds-adder" class="input-group">
              <input class="form-control noui" type="text"
                  placeholder="Add a build, like package-0.2.1-5.fc26">
              <span class="input-group-btn">
                <button class="btn btn-default" type="button">
                  <span class="fa fa-plus" data-glyph="plus"></span>
                </button>
              </span>
            </div>
            <input name="builds" type="hidden"/>
            <div id="candidate-checkboxes">

              % if update:
                % for build in update.builds:
                  <div class="checkbox"><label>
                      <input name="builds" data-build-nvr="${build.nvr}"
                      type="checkbox" value="${build.nvr}" checked> ${build.nvr}
                  </label></div>
                % endfor
              % endif

            </div>
          </div>
        </div>
      </div>

      <div class="col-md-7">
        <div class="card card-form">
          <div class="card-header clearfix">
            <span class="pull-left" data-placement="bottom" data-toggle="tooltip" title="Here you can add a list of bugzilla bug IDs that you want to be associated with this update.  Associated bugs will prompt testers to test them.  You can furthermore mark bug feedback as required in the 'details' panel at the bottom of this form.">
            Related Bugs</span>
          </div>
          <div class="card-block p-a-0">
            <div id="bugs-adder" class="input-group">
              <input class="form-control noui" type="text"
                     placeholder="Add #RHBZ">
              <span class="input-group-btn">
                <button class="btn btn-default" type="button">
                  <span class="fa fa-plus" data-glyph="plus"></span>
                </button>
              </span>
            </div>
            <input name="bugs" type="hidden"/>
            <div id="bugs-checkboxes">

              % if update:
                % for bug in update.bugs:
                <div class="checkbox">
                  <label>
                    <input name="bugs" type="checkbox" value="${bug.bug_id}" checked>
                    <a href="https://bugzilla.redhat.com/show_bug.cgi?id=${bug.bug_id}">
                      #${bug.bug_id}</a> ${bug.title}
                  </label>
                </div>
                % endfor
              % endif

            </div>
          </div>
        </div>
      </div>
    </div> <!-- end row -->

    <div class="row">
      <div class="col-md-6">
        <div class="card card-form m-b-0">
          <div class="card-header clearfix">
            <span class="pull-left" data-toggle="tooltip" title="Tell people what's new and give them a heads up about what to test.  Any gotchas?  Where's the changelog?">
              Update notes</span>
          </div>
          <div class="card-block p-a-0">
            <textarea class="form-control" id="notes" name="notes" rows="6"
              placeholder="Update notes go here.  Please be as descriptive as possible.  Help testers know what to test, and users know why this update is available and what major changes it brings (if any)." required="true">
% if update:
${update.notes}
% endif
</textarea>
          </div>
        </div>
        <p class="text-xs-right m-b-1"><small>Update notes support <a href="#" data-toggle="modal" data-target="#markdown-help">Fedora-Flavored Markdown</a>.</small></p>
      </div>

      ${self.fragments.markdown_help_modal()}

      <div class="col-md-6">
        <div class="card card-form">
          <div class="card-header clearfix">
            <span class="pull-left" data-toggle="tooltip" title="Perhaps unsurprisingly, this is a preview of how your update notes will be rendered.">
            Preview</span>
          </div>
          <div class="card-block p-a-0">
            <div id="preview"><h3><small>Preview</small></h3></div>
          </div>
        </div>
      </div>
    </div> <!-- end row -->

    <div class="row">
      <div class="col-md-12">
        <div class="card">
          <div class="card-header clearfix">
            <span class="pull-left">Final details</span>
          </div>
          <div class="card-block">
            <div class="row">
              <div class="col-md-7">
                <fieldset class="form-group radio-group">
                  <div data-toggle="tooltip" title="What kind of update is this?"><strong>Type</strong></div>
                  % for value in types:
                  <label class="c-input c-radio">
                    <input type="radio" name="type" value="${value}"
                    % if update and update.type.description == value:
                    checked="checked"
                    % endif
                    > ${value}
                    <span class="c-indicator"></span>
                  </label>
                  % endfor
                </fieldset>
                <fieldset class="form-group radio-group">
                  <div data-toggle="tooltip" title="How important is this update, really?"><strong>Severity</strong></div>
                  % for value in severities:
                  <label class="c-input c-radio">
                    <input type="radio" name="severity" value="${value}"
                    % if update and update.severity.description == value:
                    checked="checked"
                    % endif
                    % if update and update.type.description == 'security' and value == 'unspecified':
                    disabled="disabled"
                    % endif
                    > ${value}
                    <span class="c-indicator"></span>
                  </label>
                  % endfor
                </fieldset>
                <fieldset class="form-group radio-group">
                  <div data-toggle="tooltip" title="What action should testers take after installing the update?  Do they need to update or reboot to see if things are really working?">
                    <strong>Suggestion</strong>
                  </div>
                  % for value in suggestions:
                  <label class="c-input c-radio">
                    <input type="radio" name="suggest" value="${value}"
                    % if update and update.suggest.description == value:
                    checked="checked"
                    % endif
                    > ${value}
                    <span class="c-indicator"></span>
                  </label>
                  % endfor
                </fieldset>
                <dl>
                  <dt data-toggle="tooltip" title="If checked, then associated bugs in RHBZ will be closed once this update is pushed to the stable repository.">
                  Close bugs on stable?</dt>
                  <dd> <input type="checkbox" name="close_bugs" data-singleton="true"
                      % if update and update.close_bugs:
                      checked
                      % elif not update:
                      checked
                      % endif
                    ></dd>
                </dl>
              </div>

              <div class="col-md-5">
                <dl id='radios'>
                  <dt data-toggle="tooltip" title="If checked, this option allows bodhi to automatically move your update from testing to stable once enough positive karma has been given.">
                  Auto-request stable?</dt>
                  <dd> <input type="checkbox" name="autokarma" data-singleton="true"
                      % if update and update.autokarma:
                      checked
                      % elif not update:
                      checked
                      % endif
                    ></dd>
                  <dt data-toggle="tooltip" title="This is the threshold of positive karma required to automatically push an update from testing to stable.">
                  Stable karma</dt>
                  <dd> <input type="number" name="stable_karma" min="1" required
                      % if update:
                      value="${update.stable_karma}"
                      % elif not update:
                      value="3"
                      % endif
                    ></dd>

                  <dt data-toggle="tooltip" title="This is the threshold of negative karma required to automatically unpush an update from testing.">
                  Unstable karma</dt>
                  <dd> <input type="number" name="unstable_karma" max="-1" required
                      % if update:
                      value="${update.unstable_karma}"
                      % elif not update:
                      value="-3"
                      % endif
                    ></dd>

                  <dt data-toggle="tooltip" title="If checked, this will require that positive feedback be given on all associated bugs before the update can pass to stable.  If your update has no associated bugs, this option has no effect.">
                  Require bugs
                  </dt>
                  <dd> <input type="checkbox" name="require_bugs" data-singleton="true"
                      % if update and update.require_bugs:
                      checked
                      % elif not update:
                      checked
                      % endif
                    ></dd>

                  <dt data-toggle="tooltip" title="If checked, this will require that positive feedback be given on all associated wiki test cases before the update can pass to stable.  If your update has no associated wiki test cases, this option has no effect.">
                  Require testcases</dt>
                  <dd> <input type="checkbox" name="require_testcases" data-singleton="true"
                      % if update and update.require_testcases:
                      checked
                      % elif not update:
                      checked
                      % endif
                    ></dd>

                  <dt data-toggle="tooltip" title="If specified, the update will be blocked from stable until all of the listed taskotron tests are passing.">
                  Required checks <a target="_blank" href="https://fedoraproject.org/wiki/Taskotron/Tasks"><span class="glyphicon glyphicon-question-sign"></span></a></dt>
                  <dd> <input type="text" name="requirements"
                  placeholder="Required taskotron tasks"
                      % if update and update.requirements:
                      value="${update.requirements}"
                      % endif
                    ></dd>

                </dl>
              </div>
            </div>

            <input type="hidden" name="csrf_token" value="${request.session.get_csrf_token()}"/>

            % if update:
            <input type="hidden" name="edited" value="${update.title}">
            % endif

            <button id="submit" class="btn btn-success">
              % if update:
              <span class="indicator fa fa-edit" data-spinclass="indicator fa fa-spinner fa-spin"></span>
              Save
              % else:
              <span class="indicator fa fa-save" data-spinclass="indicator fa fa-spinner fa-spin"></span>
              Submit
              % endif
            </button>
          </div>
        </div>
      </div>
    </div> <!-- end row -->

  </div>
</div>
<script src="${request.static_url('bodhi:server/static/js/update_form.js')}"></script>
<script>$("#js-warning").hide();$("#new-update-form").show();</script>
<script> $(document).ready(function() { $('.panel-heading > span, dt').tooltip(); }); </script>
% if not update:
<!-- Pre-select the radio buttons -->
<script> $(document).ready(function() { $(".radio-group > label:first-of-type input").attr('checked', 'checked')}); </script>
% endif
