aboutsummaryrefslogtreecommitdiffstats
path: root/lib/toaster/toastergui/templates/editcustomimage_modal.html
blob: baa36c0e1b22e533b5ca2a66d74f4608ed37569f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!--
modal dialog shown on the build dashboard, for editing an existing custom image;
only shown if more than one custom image was built, so the user needs to
choose which one to edit

required context:
  build - a Build object
-->
<div class="modal fade" aria-hidden="false" id="edit-custom-image-modal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3>Which image do you want to edit?</h3>
      </div>

      <div class="modal-body">
        {% for recipe in build.get_custom_image_recipes %}
        <div class="radio">
          <label>
            <input type="radio" name="select-custom-image"
                                data-url="{% url 'customrecipe' build.project.id recipe.id %}">
            {{recipe.name}}
          </label>
        </div>
        {% endfor %}
        <span class="help-block text-danger" id="invalid-custom-image-help" style="display:none">
          Please select a custom image to edit.
        </span>
      </div>

      <div class="modal-footer">
        <button class="btn btn-primary btn-lg" data-url="#"
                                               data-action="edit-custom-image" disabled>
          Edit custom image
        </button>
      </div>
    </div>
  </div>
</div>

<script>
$(document).ready(function () {
  var editCustomImageButton = $('[data-action="edit-custom-image"]');
  var error = $('#invalid-custom-image-help');
  var radios = $('[name="select-custom-image"]');

  // return custom image radio buttons which are selected
  var getSelectedRadios = function () {
    return $('[name="select-custom-image"]:checked');
  };

  function enableSubmit() {
    if (getSelectedRadios().length === 1) {
      editCustomImageButton.removeAttr('disabled');
      error.hide();
    }
    else {
      editCustomImageButton.attr('disabled', 'disabled');
      error.show();
    }
  };

  $("#edit-custom-image-modal").on("shown.bs.modal", function() {
    enableSubmit();
  });

  radios.change(function () {
    enableSubmit();
  });

  editCustomImageButton.click(function () {
    var selectedRadios = getSelectedRadios();

    if (selectedRadios.length === 1) {
      document.location.href = selectedRadios.first().attr('data-url');
    }
    else {
      error.show();
    }
  });

  // Select the first custom image listed. Radio button groups
  // should always have an option selected by default
  $("input:radio:first").attr("checked", "checked");

});
</script>