blob: 274040e7db53a86ac630ae69df99f0ca615efd5f [file] [log] [blame]
Scott Baker2c3cb642014-05-19 17:55:56 -07001<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>
13 <div class="btn btn-success" id="btn-add">Add &raquo;</div><br><br>
14 <div class="btn btn-success" id="btn-remove">&laquo; Remove</div>
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>
24 <div class="btn btn-high btn-info" id="btn-save">Save</div>
25 </div>
26 <div class="customize_column">
27 <br>
28 <div class="btn btn-success" id="btn-up">Up</div><br><br>
29 <div class="btn btn-success" id="btn-down">Down</div>
30 </div>
31 </div>
32</form>
33
34<script>
35$(document).ready(function() {
36 $('#btn-add').click(function(){
37 $('#select-from option:selected').each( function() {
38 $('#select-to').append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
39 $(this).remove();
40 });
41 });
42 $('#btn-remove').click(function(){
43 $('#select-to option:selected').each( function() {
44 $('#select-from').append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
45 $(this).remove();
46 });
47 });
48 $('#btn-up').bind('click', function() {
49 $('#select-to option:selected').each( function() {
50 var newPos = $('#select-to option').index(this) - 1;
51 if (newPos > -1) {
52 $('#select-to option').eq(newPos).before("<option value='"+$(this).val()+"' selected='selected'>"+$(this).text()+"</option>");
53 $(this).remove();
54 }
55 });
56 });
57 $('#btn-down').bind('click', function() {
58 var countOptions = $('#select-to option').size();
59 $('#select-to option:selected').each( function() {
60 var newPos = $('#select-to option').index(this) + 1;
61 if (newPos < countOptions) {
62 $('#select-to option').eq(newPos).after("<option value='"+$(this).val()+"' selected='selected'>"+$(this).text()+"</option>");
63 $(this).remove();
64 }
65 });
66 });
67 $('#btn-save').bind('click', function() {
Scott Baker2aed9b02014-05-21 10:10:55 -070068 $( "#btn-save").unbind()
69 $( "#btn-save" ).html("<div class='loading'>Saving ...</div>");
Scott Baker2c3cb642014-05-19 17:55:56 -070070 var items=[];
71 $("#select-to option").each(function() { items.push($(this).val()); });
72 $.ajax({
73 url: '/customize/',
74 dataType: 'json',
75 data: {
76 dashboards: items.join(","),
77 csrfmiddlewaretoken: "{{ csrf_token }}" // < here
78 },
79 type: 'POST',
80 complete: function () {
81 location.reload();
82 }
83 });
84 });
85});
86</script>
87