Revision 80bb2140 snf-cyclades-app/synnefo/ui/static/snf/js/ui/web/ui_vm_resize_view.js
b/snf-cyclades-app/synnefo/ui/static/snf/js/ui/web/ui_vm_resize_view.js | ||
---|---|---|
101 | 101 |
this.init_handlers(); |
102 | 102 |
}, |
103 | 103 |
|
104 |
get_current: function(choice, value) { |
|
105 |
var found = false; |
|
106 |
_.each(this.flavors, _.bind(function(f){ |
|
107 |
if (found) { return } |
|
108 |
if (f.get(choice) == value) { |
|
109 |
found = true; |
|
110 |
to_select = f; |
|
111 |
} |
|
112 |
}, this)); |
|
113 |
}, |
|
114 |
|
|
104 | 115 |
init_handlers: function() { |
105 | 116 |
this.$el.on('click', 'li.choice', _.bind(function(e) { |
106 | 117 |
var el = $(e.target).closest('li'); |
107 |
if (el.hasClass('disabled')) { return } |
|
108 | 118 |
var choice = el.data('type'); |
109 | 119 |
var value = el.data('value'); |
110 | 120 |
var to_select = this.selected_flavor; |
... | ... | |
117 | 127 |
} |
118 | 128 |
|
119 | 129 |
if (!to_select) { |
120 |
var found = false; |
|
121 |
_.each(this.flavors, _.bind(function(f){ |
|
122 |
if (found) { return } |
|
123 |
if (f.get(choice) == value) { |
|
124 |
found = true; |
|
125 |
to_select = f; |
|
126 |
} |
|
127 |
}, this)); |
|
130 |
to_select = this.get_current(choice, value); |
|
128 | 131 |
} |
129 | 132 |
this.set_flavor(to_select); |
130 | 133 |
}, this)); |
... | ... | |
159 | 162 |
var extra_quotas = this.extra_quotas; |
160 | 163 |
var user_excluded = storage.flavors.unavailable_values_for_quotas( |
161 | 164 |
quotas, |
162 |
storage.flavors.active()); |
|
165 |
storage.flavors.active(), extra_quotas);
|
|
163 | 166 |
_.each(user_excluded, _.bind(function(values, key) { |
164 | 167 |
_.each(values, _.bind(function(value) { |
165 | 168 |
var choice_el = this.select_choice(key, value); |
166 |
choice_el.addClass("disabled"); |
|
169 |
choice_el.addClass("disabled").removeClass("selected");
|
|
167 | 170 |
}, this)); |
168 | 171 |
}, this)); |
169 | 172 |
}, |
... | ... | |
199 | 202 |
set_flavor: function(flavor) { |
200 | 203 |
this.$el.find("li").removeClass("selected"); |
201 | 204 |
if (!flavor) {this.selected_flavor = undefined; return} |
205 |
var no_select = false; |
|
206 |
var self = this; |
|
202 | 207 |
this.each_choice(function(choice){ |
203 | 208 |
var el = this[choice + '_el']; |
204 | 209 |
var choice = el.find('.choice-'+choice+'[data-value='+flavor.get(choice)+']'); |
... | ... | |
206 | 211 |
}); |
207 | 212 |
this.selected_flavor = flavor; |
208 | 213 |
this.trigger("flavor:select", this.selected_flavor); |
214 |
return this.selected_flavor; |
|
209 | 215 |
}, |
210 | 216 |
|
211 | 217 |
each_choice: function(f) { |
... | ... | |
263 | 269 |
}, |
264 | 270 |
|
265 | 271 |
handle_shutdown_complete: function(vm) { |
266 |
if (vm.get("status") == "STOPPED") {
|
|
272 |
if (!vm.is_active()) {
|
|
267 | 273 |
this.shutdown.removeClass("in-progress"); |
268 | 274 |
this.vm.unbind("change:status", this.handle_shutdown_complete); |
269 | 275 |
} |
... | ... | |
279 | 285 |
}, this); |
280 | 286 |
this.vm.call("resize", complete, complete, {flavor:flv.id}); |
281 | 287 |
}, |
288 |
|
|
289 |
show_with_warning: function(vm) { |
|
290 |
this.show(vm); |
|
291 |
this.start_warning.show(); |
|
292 |
}, |
|
282 | 293 |
|
283 | 294 |
show: function(vm) { |
295 |
this.start_warning = this.$(".warning.start").hide(); |
|
296 |
this.start_warning.hide(); |
|
284 | 297 |
this.submit.removeClass("in-progress"); |
285 | 298 |
this.vm = vm; |
286 | 299 |
this.vm.bind("change", this.handle_vm_change); |
287 | 300 |
if (this.flavors_view) { |
288 | 301 |
this.flavors_view.remove(); |
289 | 302 |
} |
290 |
this.warning = this.$(".warning"); |
|
303 |
this.warning = this.$(".warning.shutdown");
|
|
291 | 304 |
this.warning.hide(); |
292 | 305 |
this.submit.show(); |
306 |
this.shutdown.removeClass("in-progress"); |
|
293 | 307 |
this.$(".flavor-options-inner-cont").append("<div>"); |
308 |
var extra_quota = this.vm.get_flavor_quotas(); |
|
309 |
if (!this.vm.is_active()) { |
|
310 |
extra_quota = undefined; |
|
311 |
} |
|
294 | 312 |
this.flavors_view = new snf.views.FlavorOptionsView({ |
295 | 313 |
flavors:this.vm.get_resize_flavors(), |
296 | 314 |
el: this.$(".flavor-options-inner-cont div"), |
297 | 315 |
hidden_choices:['disk', 'disk_template'], |
298 | 316 |
selected_flavor: this.vm.get_flavor(), |
299 |
extra_quotas: this.vm.get_flavor_quotas()
|
|
317 |
extra_quotas: extra_quota
|
|
300 | 318 |
}); |
301 | 319 |
this.flavors_view.bind("flavor:select", this.handle_flavor_select) |
302 | 320 |
this.submit.addClass("disabled"); |
... | ... | |
304 | 322 |
}, |
305 | 323 |
|
306 | 324 |
handle_flavor_select: function(flv) { |
307 |
if (flv.id == this.vm.get_flavor().id) { |
|
325 |
this.selected_flavor = flv; |
|
326 |
if (!flv || (flv.id == this.vm.get_flavor().id)) { |
|
308 | 327 |
this.submit.addClass("disabled"); |
309 | 328 |
if (!this.shutdown.hasClass("in-progress")) { |
310 | 329 |
this.shutdown.addClass("disabled"); |
... | ... | |
317 | 336 |
this.warning.show(); |
318 | 337 |
} |
319 | 338 |
} |
339 |
if (flv && !this.vm.can_start(flv, true)) { |
|
340 |
if (!this.vm.is_active()) { |
|
341 |
this.start_warning.show(); |
|
342 |
} |
|
343 |
} else { |
|
344 |
this.start_warning.hide(); |
|
345 |
} |
|
320 | 346 |
this.update_vm_status(); |
321 | 347 |
}, |
322 | 348 |
|
323 | 349 |
update_vm_status: function() { |
324 |
if (this.selected_flavor) {
|
|
325 |
this.handle_flavor_select(this.selected_flavor);
|
|
350 |
if (this.vm.get("status") == "STOPPED") {
|
|
351 |
this.warning.hide();
|
|
326 | 352 |
} |
327 | 353 |
if (this.vm.get("status") == "SHUTDOWN") { |
328 | 354 |
this.shutdown.addClass("in-progress").removeClass("disabled"); |
... | ... | |
356 | 382 |
} |
357 | 383 |
this.submit.addClass("disabled"); |
358 | 384 |
} else { |
359 |
this.submit.removeClass("disabled"); |
|
385 |
if (this.selected_flavor) { |
|
386 |
this.submit.removeClass("disabled"); |
|
387 |
} |
|
360 | 388 |
this.shutdown.hide(); |
361 | 389 |
} |
362 | 390 |
}, |
Also available in: Unified diff