Revision 9555268a snf-cyclades-app/synnefo/ui/static/snf/js/ui/web/ui_networks_view.js
b/snf-cyclades-app/synnefo/ui/static/snf/js/ui/web/ui_networks_view.js | ||
---|---|---|
498 | 498 |
|
499 | 499 |
disconnect_nic: function() { |
500 | 500 |
this.$("a.selected").removeClass("selected"); |
501 |
this.parent.network.remove_nic(this.nic);
|
|
501 |
this.nic.get_network().remove_nic(this.nic);
|
|
502 | 502 |
}, |
503 | 503 |
}) |
504 | 504 |
|
... | ... | |
714 | 714 |
initialize: function(network, view) { |
715 | 715 |
this.parent_view = view; |
716 | 716 |
this.network = network; |
717 |
this.main_view_id = this.main_view_id ? this.main_view_id : "networks_view_" + network.id; |
|
717 | 718 |
this.is_public = network.is_public(); |
718 | 719 |
|
719 | 720 |
this.init_nics_handlers(); |
720 |
|
|
721 |
|
|
721 | 722 |
this.view_id = "networks_view_" + network.id; |
722 | 723 |
views.NetworkModelView.__super__.initialize.call(this); |
723 | 724 |
|
... | ... | |
730 | 731 |
this.nics_list_toggler = this.$(".list-toggle"); |
731 | 732 |
|
732 | 733 |
this.init_handlers(); |
734 |
this.init_toggler_handlers(); |
|
733 | 735 |
this.update_nics(); |
734 | 736 |
this.update_layout(); |
735 | 737 |
|
... | ... | |
745 | 747 |
var self = this; |
746 | 748 |
this.network.bind('change:status', function() { |
747 | 749 |
self.update_layout(); |
748 |
}) |
|
750 |
}); |
|
751 |
|
|
749 | 752 |
}, |
750 | 753 |
|
751 | 754 |
init_nics_handlers: function() { |
... | ... | |
775 | 778 |
this.nics_visible = false; |
776 | 779 |
}, |
777 | 780 |
|
778 |
init_handlers: function() { |
|
779 |
var self = this; |
|
780 |
|
|
781 |
init_toggler_handlers: function() { |
|
781 | 782 |
this.nics_list_toggler.click(_.bind(function(){ |
782 | 783 |
if (this.nics_list.is(":visible")) { |
783 | 784 |
this.hide_nics_list(); |
... | ... | |
788 | 789 |
|
789 | 790 |
this.check_empty_nics(); |
790 | 791 |
}, this)); |
792 |
}, |
|
793 |
|
|
794 |
init_handlers: function() { |
|
795 |
var self = this; |
|
796 |
|
|
791 | 797 |
|
792 | 798 |
this.$(".action-add").click(_.bind(function(e){ |
793 | 799 |
e.preventDefault(); |
... | ... | |
883 | 889 |
}, |
884 | 890 |
|
885 | 891 |
create_el: function() { |
886 |
var el = this.$(this.tpl).clone().attr("id", "network-" + this.network.id); |
|
887 |
return el; |
|
892 |
return this.$(this.tpl).clone().attr("id", this.main_view_id); |
|
888 | 893 |
}, |
889 | 894 |
|
890 | 895 |
get_nic_id: function(nic) { |
... | ... | |
894 | 899 |
get_nic_view: function(nic) { |
895 | 900 |
return $(this.get_nic_id(nic)); |
896 | 901 |
}, |
902 |
|
|
903 |
nic_in_network: function(nic) { |
|
904 |
return nic.get_network().id != this.network.id; |
|
905 |
}, |
|
897 | 906 |
|
898 | 907 |
nic_added_handler: function(action, nic) { |
899 |
if (nic.get_network().id != this.network.id) { return };
|
|
908 |
if (!this.nic_in_network(nic)) { return };
|
|
900 | 909 |
this.add_or_update_nic(nic); |
901 | 910 |
this.update_layout(); |
902 | 911 |
this.fix_left_border(); |
... | ... | |
915 | 924 |
} |
916 | 925 |
|
917 | 926 |
_.each(nics, _.bind(function(nic) { |
918 |
if (nic.get_network().id != this.network.id) { return };
|
|
927 |
if (!this.nic_in_network(nic)) { return };
|
|
919 | 928 |
this.add_or_update_nic(nic); |
920 | 929 |
}, this)); |
921 | 930 |
|
... | ... | |
923 | 932 |
}, |
924 | 933 |
|
925 | 934 |
nic_removed_handler: function(action, nic, model) { |
926 |
if (nic.get_network().id != this.network.id) { return };
|
|
935 |
if (!this.nic_in_network(nic)) { return };
|
|
927 | 936 |
this.fix_left_border(); |
928 | 937 |
this.remove_nic(nic); |
929 | 938 |
this.update_layout(); |
... | ... | |
971 | 980 |
update_nic: function(vm){}, |
972 | 981 |
post_nic_add: function(vm){}, |
973 | 982 |
post_nic_update: function(vm){}, |
983 |
|
|
984 |
get_nics: function() { |
|
985 |
return this.network.get_nics(); |
|
986 |
}, |
|
974 | 987 |
|
975 | 988 |
update_nics: function(nics) { |
976 |
if (!nics) { nics = this.network.get_nics() };
|
|
989 |
if (!nics) { nics = this.get_nics() }; |
|
977 | 990 |
_.each(nics, _.bind(function(nic){ |
978 | 991 |
this.add_or_update_nic(nic); |
979 | 992 |
}, this)); |
980 | 993 |
}, |
981 | 994 |
|
982 | 995 |
check_empty_nics: function() { |
983 |
if (this.network.get_nics() == 0) {
|
|
996 |
if (this.get_nics().length == 0) {
|
|
984 | 997 |
this.hide_nics_list(); |
985 | 998 |
} |
986 | 999 |
}, |
987 | 1000 |
|
988 | 1001 |
nics_empty: function() { |
989 |
return this.network.get_nics().length == 0;
|
|
1002 |
return this.get_nics().length == 0; |
|
990 | 1003 |
}, |
991 | 1004 |
|
992 | 1005 |
remove: function() { |
... | ... | |
995 | 1008 |
|
996 | 1009 |
update_layout: function() { |
997 | 1010 |
// has vms ??? |
998 |
this.check_empty_nics(this.network.get_nics());
|
|
1011 |
this.check_empty_nics(); |
|
999 | 1012 |
|
1000 | 1013 |
// is expanded ??? |
1001 | 1014 |
// |
1002 | 1015 |
// whats the network status ??? |
1003 | 1016 |
// |
1004 |
this.$(".machines-count").text(this.network.get_nics().length);
|
|
1017 |
this.$(".machines-count").text(this.get_nics().length); |
|
1005 | 1018 |
|
1006 | 1019 |
var net_name = this.network.get("name"); |
1007 | 1020 |
if (net_name == "public") { net_name = "Internet" } |
... | ... | |
1036 | 1049 |
} |
1037 | 1050 |
|
1038 | 1051 |
if (synnefo.config.network_strict_destroy) { |
1039 |
if (this.network.get_nics().length == 0 &&
|
|
1052 |
if (this.get_nics().length == 0 && |
|
1040 | 1053 |
!this.network.in_progress()) { |
1041 | 1054 |
this.el.removeClass("disable-destroy"); |
1042 | 1055 |
} else { |
... | ... | |
1086 | 1099 |
tpl: "#public-template", |
1087 | 1100 |
nic_tpl: "#public-nic-template", |
1088 | 1101 |
nic_id_tpl: "#nic-{0}", |
1102 |
|
|
1103 |
initialize: function(network, view) { |
|
1104 |
views.PublicNetworkView.__super__.initialize.call(this, network, view); |
|
1105 |
}, |
|
1106 |
|
|
1107 |
init_handlers: function(vm) {} |
|
1108 |
}); |
|
1109 |
|
|
1110 |
views.GroupedPublicNetworkView = views.PublicNetworkView.extend({ |
|
1111 |
main_view_id: "grouped-public", |
|
1112 |
|
|
1113 |
initialize: function(network, view) { |
|
1114 |
this.networks = {}; |
|
1115 |
this.add_network(network); |
|
1116 |
views.GroupedPublicNetworkView.__super__.initialize.call(this, |
|
1117 |
network, |
|
1118 |
view); |
|
1119 |
}, |
|
1120 |
|
|
1121 |
nic_in_network: function(nic) { |
|
1122 |
var nic_net = nic.get_network(); |
|
1123 |
return _.filter(this.networks, function(n) { |
|
1124 |
return nic_net.id == n.id; |
|
1125 |
}).length > 0; |
|
1126 |
}, |
|
1127 |
|
|
1128 |
get_nics: function() { |
|
1129 |
var n = _.flatten(_.map(this.networks, function(n){ return n.get_nics(); })); |
|
1130 |
return n |
|
1131 |
}, |
|
1132 |
|
|
1133 |
add_network: function(net) { |
|
1134 |
this.networks[net.id] = net; |
|
1135 |
}, |
|
1089 | 1136 |
|
1090 |
update_vm: function(vm) { |
|
1137 |
remove_network: function(net) { |
|
1138 |
delete this.networks[net.id]; |
|
1139 |
this.update_nics(); |
|
1091 | 1140 |
} |
1141 |
|
|
1092 | 1142 |
}) |
1093 | 1143 |
|
1094 | 1144 |
views.PrivateNetworkView = views.NetworkModelView.extend({ |
... | ... | |
1112 | 1162 |
views.NetworksView.__super__.initialize.call(this); |
1113 | 1163 |
this.init_handlers(); |
1114 | 1164 |
this.network_views = {}; |
1165 |
this.public_network = false; |
|
1115 | 1166 |
this.update_networks(storage.networks.models); |
1116 | 1167 |
this.create_view = new views.NetworkCreateView(); |
1117 | 1168 |
this.connect_machines_view = new views.NetworkConnectVMsOverlay(); |
... | ... | |
1124 | 1175 |
add_or_update: function(net) { |
1125 | 1176 |
var nv = this.exists(net); |
1126 | 1177 |
if (!nv) { |
1127 |
nv = this.create_network_view(net); |
|
1178 |
if (net.is_public()){ |
|
1179 |
if (synnefo.config.group_public_networks) { |
|
1180 |
if (!this.public_network) { |
|
1181 |
// grouped public not initialized |
|
1182 |
this.public_network = this.create_network_view(net); |
|
1183 |
} else { |
|
1184 |
// grouped public initialized, append |
|
1185 |
this.public_network.add_network(net); |
|
1186 |
} |
|
1187 |
nv = this.public_network; |
|
1188 |
} else { |
|
1189 |
// no grouped view asked, fallback to default create |
|
1190 |
nv = this.create_network_view(net); |
|
1191 |
} |
|
1192 |
} else { |
|
1193 |
nv = this.create_network_view(net); |
|
1194 |
} |
|
1195 |
|
|
1128 | 1196 |
this.network_views[net.id] = nv; |
1129 | 1197 |
|
1130 | 1198 |
if (net.is_public()) { |
... | ... | |
1147 | 1215 |
|
1148 | 1216 |
create_network_view: function(net) { |
1149 | 1217 |
if (net.is_public()) { |
1150 |
return new views.PublicNetworkView(net, this); |
|
1218 |
if (synnefo.config.group_public_networks) { |
|
1219 |
if (self.public_network) { return self.public_network } |
|
1220 |
return new views.GroupedPublicNetworkView(net, this); |
|
1221 |
} else { |
|
1222 |
return new views.PublicNetworkView(net, this); |
|
1223 |
} |
|
1151 | 1224 |
} |
1152 | 1225 |
return new views.PrivateNetworkView(net, this); |
1153 | 1226 |
}, |
... | ... | |
1211 | 1284 |
remove_net: function(net) { |
1212 | 1285 |
if (this.network_added(net)) { |
1213 | 1286 |
var view = this.get_network_view(net); |
1214 |
view.remove(); |
|
1287 |
if (view == this.public_network) { |
|
1288 |
this.public_network.remove_network(net); |
|
1289 |
} else { |
|
1290 |
view.remove(); |
|
1291 |
} |
|
1215 | 1292 |
delete this.network_views[net.id]; |
1216 | 1293 |
} |
1217 | 1294 |
}, |
Also available in: Unified diff