blob: d2e8a20cfff11316e431696c0aea6ec0be96ec9e [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>
Scott Bakerea417792014-05-21 17:52:44 -070013 <div class="btn btn-success" id="customize-btn-add">Add &raquo;</div><br><br>
14 <div class="btn btn-success" id="customize-btn-remove">&laquo; Remove</div>
Scott Baker2c3cb642014-05-19 17:55:56 -070015 </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 Bakerea417792014-05-21 17:52:44 -070024 <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 Baker2c3cb642014-05-19 17:55:56 -070026 </div>
27 <div class="customize_column">
28 <br>
Scott Bakerea417792014-05-21 17:52:44 -070029 <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 Baker2c3cb642014-05-19 17:55:56 -070031 </div>
32 </div>
33</form>
34
35<script>
36$(document).ready(function() {
Scott Bakerea417792014-05-21 17:52:44 -070037 $('#customize-btn-add').click(function(){
Scott Baker2c3cb642014-05-19 17:55:56 -070038 $('#select-from option:selected').each( function() {
39 $('#select-to').append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
40 $(this).remove();
41 });
42 });
Scott Bakerea417792014-05-21 17:52:44 -070043 $('#customize-btn-remove').click(function(){
Scott Baker2c3cb642014-05-19 17:55:56 -070044 $('#select-to option:selected').each( function() {
45 $('#select-from').append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
46 $(this).remove();
47 });
48 });
Scott Bakerea417792014-05-21 17:52:44 -070049 $('#customize-btn-up').bind('click', function() {
Scott Baker2c3cb642014-05-19 17:55:56 -070050 $('#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 Bakerea417792014-05-21 17:52:44 -070058 $('#customize-btn-down').bind('click', function() {
Scott Baker2c3cb642014-05-19 17:55:56 -070059 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 Bakerea417792014-05-21 17:52:44 -070068 $('#customize-btn-save').bind('click', function() {
69 $("#customize-btn-save").hide();
70 $("#customize-msg-saving").show();
Scott Baker2c3cb642014-05-19 17:55:56 -070071 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 Bakerea417792014-05-21 17:52:44 -070081 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 Baker2c3cb642014-05-19 17:55:56 -070087 location.reload();
88 }
89 });
90 });
91});
92</script>
93