fix filter code in sliver inline
[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 deployment_images = [
18 {% for dn in deployment_images %}
19    [{{ dn.0 }}, {{ dn.1 }} , "{{ dn.2 }}"],
20 {% endfor %}
21 ];
22
23 site_login_bases = [
24 {% for s in site_login_bases %}
25   [{{ s.0 }}, "{{ s.1 }}"],
26 {% endfor %}
27 ];
28
29 function option_html(val, text, selected) {
30     if (selected) {
31         return '<option value="' + val + '" selected>' + text + '</option>\n';
32     } else {
33         return '<option value="' + val + '">' + text + '</option>\n';
34     }
35 }
36
37 function update_nodes(deployment_select, flavor_select, node_select) {
38     deployment_id = $(deployment_select).val();
39     node_id = $(node_select).val();
40     flavor_name = $(flavor_select).children(":selected").text()
41     html="";
42     for (i in deployment_nodes) {
43         // this is for EC2, where the node hostnames imply the flavor.
44         dn = deployment_nodes[i];
45         if ((dn[0] == deployment_id) && (dn[2].lastIndexOf(flavor_name,0) === 0)) {
46             html = html + option_html(dn[1], dn[2], dn[1]==node_id);
47         }
48     }
49     if (!html) {
50         // now try it without the flavor hostname prefix matching
51         for (i in deployment_nodes) {
52             dn = deployment_nodes[i];
53             if (dn[0] == deployment_id) {
54                 html = html + option_html(dn[1], dn[2], dn[1]==node_id);
55             }
56         }
57     }
58     html = "<option value=''>---------</option>\n" + html;
59     node_select.empty().append(html);
60 }
61
62 function update_flavors(deployment_select, flavor_select) {
63     deployment_id = $(deployment_select).val();
64     flavor_id = $(flavor_select).val();
65     html = "<option value=''>---------</option>\n";
66     for (i in deployment_flavors) {
67         dn = deployment_flavors[i];
68         if (dn[0] == deployment_id) {
69             html = html + option_html(dn[1], dn[2], dn[1] == flavor_id);
70         }
71     }
72     flavor_select.empty().append(html);
73 }
74
75 function update_images(deployment_select, image_select) {
76     deployment_id = $(deployment_select).val();
77     image_id = $(image_select).val();
78     html = "<option value=''>---------</option>\n";
79     for (i in deployment_images) {
80         dn = deployment_images[i];
81         if (dn[0] == deployment_id) {
82             html = html + option_html(dn[1], dn[2], dn[1] == image_id);
83         }
84     }
85     image_select.empty().append(html);
86 }
87
88 function sliver_deployment_changed(any_control) {
89    /* This function handles someone changing the deployment control
90       in the add-sliver line. It updats the flavors and nodes dialogs
91       accordingly.
92    */
93
94    /* the inscrutable jquery selector below says:
95       find the closest parent "tr" to the current element
96       then find the child with class "field-deployment"
97       then find the child with that is a select
98       then return it's id
99       then turn it into a jquery object
100     */
101     deployment_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-deployment select')[0].id);
102     node_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-node select')[0].id);
103     flavor_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-flavor select')[0].id);
104     image_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-image select')[0].id);
105     update_nodes(deployment_select, flavor_select, node_select);
106     update_flavors(deployment_select, flavor_select);
107     update_images(deployment_select, image_select);
108 }
109
110 function sliver_flavor_changed(any_control) {
111     /* this is like sliver_flavor changed, but does not update the flavors
112        control
113     */
114     deployment_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-deployment select')[0].id);
115     node_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-node select')[0].id);
116     flavor_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-flavor select')[0].id);
117     update_nodes(deployment_select, flavor_select, node_select);
118 }
119
120 function update_slice_prefix(site_select, slice_name_id) {
121     site_id = $(site_select).val();
122     slice_prefix="";
123     for (i in site_login_bases) {
124         if (site_login_bases[i][0] == site_id) {
125             slice_prefix=site_login_bases[i][1]+"_";
126         }
127     }
128     $("#"+slice_name_id).val(slice_prefix); 
129 }
130 </script>
131
132 {% endblock %}
133