aboutsummaryrefslogtreecommitdiffstats
path: root/lib/toaster/toastergui/templates/editcustomimage_modal.html
blob: 8046c08fb59564cd293dd41de7d62cbf6afad694 (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
<!--
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 hide fade in" aria-hidden="false" id="edit-custom-image-modal">
  <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">
    <div class="row-fluid">
      {% for recipe in build.get_custom_image_recipes %}
        <label class="radio">
          {{recipe.name}}
          <input type="radio" class="form-control" name="select-custom-image"
                 data-url="{% url 'customrecipe' build.project.id recipe.id %}">
        </label>
      {% endfor %}
    </div>
    <span class="help-block error" 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-large" data-url="#"
       data-action="edit-custom-image" disabled>
      Edit custom image
    </button>
  </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');
  };

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

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

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