filter nodes by flavor dropdown, primarily intended for EC2 deployment where nodes...
[plstackapi.git] / planetstack / templates / admin / core / slice / change_form.html
1 {% extends 'admin/change_form.html' %}
2 {% block extrahead %}
3 {{ block.super }} 
4 <script>
5 deployment_nodes = [
6 {% for dn in deployment_nodes %}
7    [{{ dn.0 }}, {{ dn.1 }} , "{{ dn.2 }}"],
8 {% endfor %}
9 ];
10
11 deployment_flavors = [
12 {% for dn in deployment_flavors %}
13    [{{ dn.0 }}, {{ dn.1 }} , "{{ dn.2 }}"],
14 {% endfor %}
15 ];
16
17 site_login_bases = [
18 {% for s in site_login_bases %}
19   [{{ s.0 }}, "{{ s.1 }}"],
20 {% endfor %}
21 ];
22
23 function update_nodes(deployment_select, flavor_select, node_select) {
24     deployment_id = $(deployment_select).val();
25     flavor_name = $(flavor_select).children(":selected").text()
26     html="";
27     for (i in deployment_nodes) {
28         dn = deployment_nodes[i];
29         if ((dn[0] == deployment_id) && (dn[2].lastIndexOf(flavor_name,0) === 0)) {
30             html = html + '<option value="' + dn[1] + '">' + dn[2] + '</option>\n'
31         }
32     }
33     if (!html) {
34         // now try it without the flavor hostname prefix matching
35         for (i in deployment_nodes) {
36             dn = deployment_nodes[i];
37             if (dn[0] == deployment_id) {
38                 html = html + '<option value="' + dn[1] + '">' + dn[2] + '</option>\n'
39             }
40         }
41     }
42     html = "<option value=''>---------</option>\n" + html;
43     //console.log(html);
44     node_select.empty().append(html);
45 }
46
47 function update_flavors(deployment_select, flavor_select) {
48     deployment_id = $(deployment_select).val();
49     html = "<option value=''>---------</option>\n";
50     for (i in deployment_flavors) {
51         dn = deployment_flavors[i];
52         if (dn[0] == deployment_id) {
53             html = html + '<option value="' + dn[1] + '">' + dn[2] + '</option>\n'
54         }
55     }
56     //console.log(html);
57     flavor_select.empty().append(html);
58 }
59
60 function sliver_deployment_changed(any_control) {
61    /* This function handles someone changing the deploymentNetwork control
62       in the add-sliver line. It updats the flavors and nodes dialogs
63       accordingly.
64    */
65
66    /* the inscrutable jquery selector below says:
67       find the closest parent "tr" to the current element
68       then find the child with class "field-deploymentNetwork"
69       then find the child with that is a select
70       then return it's id
71       then turn it into a jquery object
72     */
73     deployment_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-deploymentNetwork select')[0].id);
74     node_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-node select')[0].id);
75     flavor_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-flavor select')[0].id);
76     update_nodes(deployment_select, flavor_select, node_select);
77     update_flavors(deployment_select, flavor_select);
78 }
79
80 function sliver_flavor_changed(any_control) {
81     /* this is like sliver_flavor changed, but does not update the flavors
82        control
83     */
84     deployment_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-deploymentNetwork select')[0].id);
85     node_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-node select')[0].id);
86     flavor_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-flavor select')[0].id);
87     update_nodes(deployment_select, flavor_select, node_select);
88 }
89
90 function update_slice_prefix(site_select, slice_name_id) {
91     site_id = $(site_select).val();
92     slice_prefix="";
93     for (i in site_login_bases) {
94         if (site_login_bases[i][0] == site_id) {
95             slice_prefix=site_login_bases[i][1]+"_";
96         }
97     }
98     $("#"+slice_name_id).val(slice_prefix); 
99 }
100 </script>
101
102 {% endblock %}
103