blob: 6800dfdf8283ddb578afebe06f5c5d38b41ccf51 [file] [log] [blame]
Scott Baker510fdbb2014-08-05 17:19:24 -07001{% extends 'admin/change_form.html' %}
Scott Baker7a61dc42014-09-02 17:08:20 -07002{% block extrahead %}
Scott Baker510fdbb2014-08-05 17:19:24 -07003{{ block.super }}
4<script>
5deployment_nodes = [
6{% for dn in deployment_nodes %}
7 [{{ dn.0 }}, {{ dn.1 }} , "{{ dn.2 }}"],
8{% endfor %}
9];
Scott Baker34b502f2014-08-05 18:33:31 -070010
Scott Baker7a61dc42014-09-02 17:08:20 -070011deployment_flavors = [
12{% for dn in deployment_flavors %}
13 [{{ dn.0 }}, {{ dn.1 }} , "{{ dn.2 }}"],
14{% endfor %}
15];
16
Scott Baker93e80cd2014-09-09 09:58:49 -070017deployment_images = [
18{% for dn in deployment_images %}
19 [{{ dn.0 }}, {{ dn.1 }} , "{{ dn.2 }}"],
20{% endfor %}
21];
22
Tony Mackec23b992014-09-02 21:18:45 -040023site_login_bases = [
24{% for s in site_login_bases %}
25 [{{ s.0 }}, "{{ s.1 }}"],
Tony Mack7283fdf2014-09-02 00:37:36 -040026{% endfor %}
27];
Scott Baker7a61dc42014-09-02 17:08:20 -070028
Scott Baker93e80cd2014-09-09 09:58:49 -070029function 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
Scott Baker32481312014-09-08 12:14:14 -070037function update_nodes(deployment_select, flavor_select, node_select) {
Scott Baker34b502f2014-08-05 18:33:31 -070038 deployment_id = $(deployment_select).val();
Scott Baker93e80cd2014-09-09 09:58:49 -070039 node_id = $(node_select).val();
Scott Baker32481312014-09-08 12:14:14 -070040 flavor_name = $(flavor_select).children(":selected").text()
41 html="";
Scott Baker34b502f2014-08-05 18:33:31 -070042 for (i in deployment_nodes) {
Scott Baker93e80cd2014-09-09 09:58:49 -070043 // this is for EC2, where the node hostnames imply the flavor.
Scott Baker34b502f2014-08-05 18:33:31 -070044 dn = deployment_nodes[i];
Scott Baker32481312014-09-08 12:14:14 -070045 if ((dn[0] == deployment_id) && (dn[2].lastIndexOf(flavor_name,0) === 0)) {
Scott Baker93e80cd2014-09-09 09:58:49 -070046 html = html + option_html(dn[1], dn[2], dn[1]==node_id);
Scott Baker34b502f2014-08-05 18:33:31 -070047 }
48 }
Scott Baker32481312014-09-08 12:14:14 -070049 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) {
Scott Baker93e80cd2014-09-09 09:58:49 -070054 html = html + option_html(dn[1], dn[2], dn[1]==node_id);
Scott Baker32481312014-09-08 12:14:14 -070055 }
56 }
57 }
58 html = "<option value=''>---------</option>\n" + html;
Scott Baker32481312014-09-08 12:14:14 -070059 node_select.empty().append(html);
Scott Baker34b502f2014-08-05 18:33:31 -070060}
Tony Mack7283fdf2014-09-02 00:37:36 -040061
Scott Baker32481312014-09-08 12:14:14 -070062function update_flavors(deployment_select, flavor_select) {
Scott Baker7a61dc42014-09-02 17:08:20 -070063 deployment_id = $(deployment_select).val();
Scott Baker93e80cd2014-09-09 09:58:49 -070064 flavor_id = $(flavor_select).val();
Scott Baker7a61dc42014-09-02 17:08:20 -070065 html = "<option value=''>---------</option>\n";
66 for (i in deployment_flavors) {
67 dn = deployment_flavors[i];
68 if (dn[0] == deployment_id) {
Scott Baker93e80cd2014-09-09 09:58:49 -070069 html = html + option_html(dn[1], dn[2], dn[1] == flavor_id);
Scott Baker7a61dc42014-09-02 17:08:20 -070070 }
71 }
Scott Baker32481312014-09-08 12:14:14 -070072 flavor_select.empty().append(html);
Scott Baker7a61dc42014-09-02 17:08:20 -070073}
74
Scott Baker93e80cd2014-09-09 09:58:49 -070075function 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
Scott Baker32481312014-09-08 12:14:14 -070088function sliver_deployment_changed(any_control) {
Scott Baker39293d72015-01-21 16:24:07 -080089 /* This function handles someone changing the deployment control
Scott Baker32481312014-09-08 12:14:14 -070090 in the add-sliver line. It updats the flavors and nodes dialogs
91 accordingly.
92 */
93
Scott Baker7a61dc42014-09-02 17:08:20 -070094 /* the inscrutable jquery selector below says:
95 find the closest parent "tr" to the current element
Scott Baker39293d72015-01-21 16:24:07 -080096 then find the child with class "field-deployment"
Scott Baker7a61dc42014-09-02 17:08:20 -070097 then find the child with that is a select
Scott Baker32481312014-09-08 12:14:14 -070098 then return it's id
99 then turn it into a jquery object
Scott Baker7a61dc42014-09-02 17:08:20 -0700100 */
Scott Baker39293d72015-01-21 16:24:07 -0800101 deployment_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-deployment select')[0].id);
Scott Baker32481312014-09-08 12:14:14 -0700102 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);
Scott Baker93e80cd2014-09-09 09:58:49 -0700104 image_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-image select')[0].id);
Scott Baker32481312014-09-08 12:14:14 -0700105 update_nodes(deployment_select, flavor_select, node_select);
106 update_flavors(deployment_select, flavor_select);
Scott Baker93e80cd2014-09-09 09:58:49 -0700107 update_images(deployment_select, image_select);
Scott Baker32481312014-09-08 12:14:14 -0700108}
109
110function sliver_flavor_changed(any_control) {
111 /* this is like sliver_flavor changed, but does not update the flavors
112 control
113 */
Scott Baker39293d72015-01-21 16:24:07 -0800114 deployment_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-deployment select')[0].id);
Scott Baker32481312014-09-08 12:14:14 -0700115 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);
Scott Baker7a61dc42014-09-02 17:08:20 -0700118}
119
Tony Mack7283fdf2014-09-02 00:37:36 -0400120function update_slice_prefix(site_select, slice_name_id) {
121 site_id = $(site_select).val();
122 slice_prefix="";
Tony Mackec23b992014-09-02 21:18:45 -0400123 for (i in site_login_bases) {
124 if (site_login_bases[i][0] == site_id) {
125 slice_prefix=site_login_bases[i][1]+"_";
126 }
Tony Mack7283fdf2014-09-02 00:37:36 -0400127 }
128 $("#"+slice_name_id).val(slice_prefix);
129}
Scott Baker510fdbb2014-08-05 17:19:24 -0700130</script>
Scott Baker34b502f2014-08-05 18:33:31 -0700131
Scott Baker510fdbb2014-08-05 17:19:24 -0700132{% endblock %}
133