Commit 90d5abf4 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

ui: Enable automatic quota handling in collection views

parent 6f633b1a
......@@ -2588,6 +2588,7 @@ div.actions a.selected, div.actions a.selected:hover, div.machine-actions a.sele
margin-left: -15px;
}
.create-button a.disabled,
.createbutton.disabled, #networkscreate.disabled {
background-color: #888 !important;
border-left-color: #aaa !important;
......
......@@ -2361,7 +2361,7 @@
var keysplit = key.split(".");
var limit_active = value.limit;
var usage_active = value.usage;
keysplit[keysplit.length-1] = "active_" + keysplit[keysplit.length-1];
keysplit[keysplit.length-1] = "total_" + keysplit[keysplit.length-1];
var activekey = keysplit.join(".");
var exists = resp.system[activekey];
if (exists) {
......
......@@ -160,6 +160,7 @@
collection_name: 'floating_ips',
model_view_cls: views.IpView,
create_view: undefined, // no create overlay for IPs
quota_key: 'cyclades.floating_ip',
initialize: function() {
views.IpCollectionView.__super__.initialize.apply(this, arguments);
this.connect_view = new views.IPConnectVmOverlay();
......@@ -187,6 +188,9 @@
floatingip: {}
},
{
success: _.bind(function() {
this.post_create();
}, this),
complete: _.bind(function() {
this.creating = false;
this.reset_creating();
......
......@@ -216,6 +216,8 @@
snf.storage.networks.create(name, type, subnet, dhcp, _.bind(function(){
this.hide();
// trigger parent view create handler
this.parent_view.post_create();
}, this));
},
......@@ -499,7 +501,7 @@
}
this.connect_vms(vms, cbinner);
}, this);
view.show_vms(this.model, vms, [], cb, "subtitle");
view.show_vms(this.model, vms, [], cb, "subtitle", this);
}
});
......@@ -509,6 +511,7 @@
collection_name: 'networks',
model_view_cls: views.NetworkView,
create_view_cls: views.NetworkCreateView,
quota_key: 'cyclades.network.private',
init: function() {
this.public_added = false;
......
......@@ -198,6 +198,8 @@
collection: undefined,
model_view_cls: undefined,
animation_speed: 200,
quota_key: undefined,
quota_limit_message: undefined,
init: function() {
var handlers = {};
......@@ -214,6 +216,7 @@
this.empty_el = $(this.$(".empty-list").get(0));
if (this.create_view_cls) {
this._create_view = new this.create_view_cls();
this._create_view.parent_view = this;
}
this.create_button = this.$(".create-button a");
......@@ -221,9 +224,39 @@
e.preventDefault();
this.handle_create_click();
}, this));
if (this.quota_key && !this.quota) {
this.quota = synnefo.storage.quotas.get(this.quota_key);
}
if (this.quota) {
this.quota.bind("change", _.bind(this.update_quota, this));
this.update_quota();
}
},
update_quota: function() {
var available = this.quota.get_available();
if (available) {
this.create_button.removeClass("disabled");
this.create_button.attr("title", this.quota_limit_message || "Quota limit reached")
} else {
this.create_button.addClass("disabled");
this.create_button.attr("title", "");
}
},
post_create: function() {
this.quota && this.quota.increase();
},
post_destroy: function() {
this.quota && this.quota.decrease();
},
handle_create_click: function() {
if (this.create_button.hasClass("disabled")) { return }
if (this._create_view) {
this._create_view.show();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment