Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1 | <!-- |
| 2 | modal dialog shown on the build dashboard, for editing an existing custom image; |
| 3 | only shown if more than one custom image was built, so the user needs to |
| 4 | choose which one to edit |
| 5 | |
| 6 | required context: |
| 7 | build - a Build object |
| 8 | --> |
| 9 | <div class="modal hide fade in" aria-hidden="false" id="edit-custom-image-modal"> |
| 10 | <div class="modal-header"> |
| 11 | <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
| 12 | <h3>Which image do you want to edit?</h3> |
| 13 | </div> |
| 14 | |
| 15 | <div class="modal-body"> |
| 16 | <div class="row-fluid"> |
| 17 | {% for recipe in build.get_custom_image_recipes %} |
| 18 | <label class="radio"> |
| 19 | {{recipe.name}} |
| 20 | <input type="radio" class="form-control" name="select-custom-image" |
| 21 | data-url="{% url 'customrecipe' build.project.id recipe.id %}"> |
| 22 | </label> |
| 23 | {% endfor %} |
| 24 | </div> |
| 25 | <span class="help-block error" id="invalid-custom-image-help" style="display:none"> |
| 26 | Please select a custom image to edit. |
| 27 | </span> |
| 28 | </div> |
| 29 | |
| 30 | <div class="modal-footer"> |
| 31 | <button class="btn btn-primary btn-large" data-url="#" |
| 32 | data-action="edit-custom-image" disabled> |
| 33 | Edit custom image |
| 34 | </button> |
| 35 | </div> |
| 36 | </div> |
| 37 | |
| 38 | <script> |
| 39 | $(document).ready(function () { |
| 40 | var editCustomImageButton = $('[data-action="edit-custom-image"]'); |
| 41 | var error = $('#invalid-custom-image-help'); |
| 42 | var radios = $('[name="select-custom-image"]'); |
| 43 | |
| 44 | // return custom image radio buttons which are selected |
| 45 | var getSelectedRadios = function () { |
| 46 | return $('[name="select-custom-image"]:checked'); |
| 47 | }; |
| 48 | |
| 49 | radios.change(function () { |
| 50 | if (getSelectedRadios().length === 1) { |
| 51 | editCustomImageButton.removeAttr('disabled'); |
| 52 | error.hide(); |
| 53 | } |
| 54 | else { |
| 55 | editCustomImageButton.attr('disabled', 'disabled'); |
| 56 | error.show(); |
| 57 | } |
| 58 | }); |
| 59 | |
| 60 | editCustomImageButton.click(function () { |
| 61 | var selectedRadios = getSelectedRadios(); |
| 62 | |
| 63 | if (selectedRadios.length === 1) { |
| 64 | document.location.href = selectedRadios.first().attr('data-url'); |
| 65 | } |
| 66 | else { |
| 67 | error.show(); |
| 68 | } |
| 69 | }); |
| 70 | }); |
| 71 | </script> |