Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 1 | <form> |
| 2 | <div class="customize_row">
|
| 3 | <div class="customize_column">
|
| 4 | <div>Available Dashboard Views</div>
|
| 5 | <select name="selectfrom" id="select-from" multiple size="5">
|
| 6 | {% for cp in unusedDashboards %}
|
| 7 | <option value="{{ cp }}">{{ cp }}</option> |
| 8 | {% endfor %}
|
| 9 | </select>
|
| 10 | </div>
|
| 11 | <div class="customize_column">
|
| 12 | <br>
|
Scott Baker | ea41779 | 2014-05-21 17:52:44 -0700 | [diff] [blame] | 13 | <div class="btn btn-success" id="customize-btn-add">Add »</div><br><br>
|
| 14 | <div class="btn btn-success" id="customize-btn-remove">« Remove</div>
|
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 15 | </div>
|
| 16 | <div class="customize_column">
|
| 17 | <div>Selected Dashboard Views</div>
|
| 18 | <select name="selectto" id="select-to" multiple size="5">
|
| 19 | {% for cp in dashboards %}
|
| 20 | <option value="{{ cp }}">{{ cp }}</option> |
| 21 | {% endfor %}
|
| 22 | </select>
|
| 23 | <br>
|
Scott Baker | ea41779 | 2014-05-21 17:52:44 -0700 | [diff] [blame] | 24 | <div class="btn btn-high btn-info" id="customize-btn-save">Save</div>
|
| 25 | <div style="display: none" id="customize-msg-saving">Saving...</div>
|
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 26 | </div>
|
| 27 | <div class="customize_column">
|
| 28 | <br>
|
Scott Baker | ea41779 | 2014-05-21 17:52:44 -0700 | [diff] [blame] | 29 | <div class="btn btn-success" id="customize-btn-up">Up</div><br><br>
|
| 30 | <div class="btn btn-success" id="customize-btn-down">Down</div>
|
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 31 | </div>
|
| 32 | </div>
|
| 33 | </form>
|
| 34 | |
| 35 | <script> |
| 36 | $(document).ready(function() { |
Scott Baker | ea41779 | 2014-05-21 17:52:44 -0700 | [diff] [blame] | 37 | $('#customize-btn-add').click(function(){
|
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 38 | $('#select-from option:selected').each( function() {
|
| 39 | $('#select-to').append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
|
| 40 | $(this).remove();
|
| 41 | });
|
| 42 | });
|
Scott Baker | ea41779 | 2014-05-21 17:52:44 -0700 | [diff] [blame] | 43 | $('#customize-btn-remove').click(function(){
|
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 44 | $('#select-to option:selected').each( function() {
|
| 45 | $('#select-from').append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
|
| 46 | $(this).remove();
|
| 47 | });
|
| 48 | });
|
Scott Baker | ea41779 | 2014-05-21 17:52:44 -0700 | [diff] [blame] | 49 | $('#customize-btn-up').bind('click', function() {
|
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 50 | $('#select-to option:selected').each( function() {
|
| 51 | var newPos = $('#select-to option').index(this) - 1;
|
| 52 | if (newPos > -1) {
|
| 53 | $('#select-to option').eq(newPos).before("<option value='"+$(this).val()+"' selected='selected'>"+$(this).text()+"</option>");
|
| 54 | $(this).remove();
|
| 55 | }
|
| 56 | });
|
| 57 | });
|
Scott Baker | ea41779 | 2014-05-21 17:52:44 -0700 | [diff] [blame] | 58 | $('#customize-btn-down').bind('click', function() {
|
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 59 | var countOptions = $('#select-to option').size();
|
| 60 | $('#select-to option:selected').each( function() {
|
| 61 | var newPos = $('#select-to option').index(this) + 1;
|
| 62 | if (newPos < countOptions) {
|
| 63 | $('#select-to option').eq(newPos).after("<option value='"+$(this).val()+"' selected='selected'>"+$(this).text()+"</option>");
|
| 64 | $(this).remove();
|
| 65 | }
|
| 66 | });
|
| 67 | });
|
Scott Baker | ea41779 | 2014-05-21 17:52:44 -0700 | [diff] [blame] | 68 | $('#customize-btn-save').bind('click', function() {
|
| 69 | $("#customize-btn-save").hide();
|
| 70 | $("#customize-msg-saving").show();
|
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 71 | var items=[];
|
| 72 | $("#select-to option").each(function() { items.push($(this).val()); });
|
| 73 | $.ajax({
|
| 74 | url: '/customize/', |
| 75 | dataType: 'json', |
| 76 | data: { |
| 77 | dashboards: items.join(","), |
| 78 | csrfmiddlewaretoken: "{{ csrf_token }}" // < here |
| 79 | }, |
| 80 | type: 'POST', |
Scott Baker | ea41779 | 2014-05-21 17:52:44 -0700 | [diff] [blame] | 81 | error: function (jqXHR, textStatus, errorThrown) { |
| 82 | errorDialog("Error", textStatus + " " + jqXHR.responseText); |
| 83 | $("#customize-btn-save").show(); |
| 84 | $("#customize-msg-saving").hide(); |
| 85 | }, |
| 86 | success: function () { |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 87 | location.reload(); |
| 88 | } |
| 89 | });
|
| 90 | }); |
| 91 | }); |
| 92 | </script> |
| 93 | |