Revision ddb7229d 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
227 227
            this.flavors_view = undefined; 
228 228
            views.VmResizeView.__super__.initialize.apply(this);
229 229
            _.bindAll(this);
230
            this.submit = this.$(".form-action");
230
            this.submit = this.$(".form-action.resize");
231
            this.shutdown = this.$(".form-action.shutdown");
231 232
            this.pre_init_handlers();
233
            this.handle_shutdown_complete = _.bind(this.handle_shutdown_complete, this);
232 234
        },
233 235

  
234 236
        pre_init_handlers: function() {
......
238 240
                };
239 241
                this.submit_resize(this.flavors_view.selected_flavor);
240 242
            }, this));
243
            this.shutdown.click(_.bind(this.handle_shutdown, this));
241 244
        },
242 245
        
246
        handle_shutdown: function() {
247
          if (this.shutdown.hasClass("in-progress") || 
248
              this.shutdown.hasClass("disabled")) {
249
            return;
250
          }
251
          
252
          this.shutdown.addClass("in-progress");
253

  
254
          this.vm.unbind("change:status", this.handle_shutdown_complete);
255
          this.vm.bind("change:status", this.handle_shutdown_complete);
256

  
257
          var self = this;
258
          this.vm.call("shutdown");
259
        },
260

  
261
        handle_shutdown_complete: function(vm) {
262
          if (vm.get("status") == "STOPPED") {
263
            this.shutdown.removeClass("in-progress");
264
            this.vm.unbind("change:status", this.handle_shutdown_complete);
265
          }
266
        },
267

  
243 268
        submit_resize: function(flv) {
269
            if (this.submit.hasClass("in-progress")) { return }
244 270
            this.submit.addClass("in-progress");
245 271
            var complete = _.bind(function() {
246 272
              this.vm.set({'flavor': flv});
247 273
              this.vm.set({'flavorRef': flv.id});
248
              this.hide()
274
              this.hide();
249 275
            }, this);
250 276
            this.vm.call("resize", complete, complete, {flavor:flv.id});
251 277
        },
......
257 283
            if (this.flavors_view) {
258 284
                this.flavors_view.remove();
259 285
            }
260

  
261
            if (!this.vm.can_resize()) {
262
                this.$(".warning").show();
263
                this.submit.hide();
264
            } else {
265
                this.$(".warning").hide();
266
                this.submit.show();
267
                this.$(".flavor-options-inner-cont").append("<div>");
268
                this.flavors_view = new snf.views.FlavorOptionsView({
269
                    flavors:this.vm.get_resize_flavors(),
270
                    el: this.$(".flavor-options-inner-cont div"),
271
                    hidden_choices:['disk', 'disk_template'],
272
                    selected_flavor: this.vm.get_flavor(),
273
                    extra_quotas: this.vm.get_flavor_quotas()
274
                });
275
                this.flavors_view.bind("flavor:select", this.handle_flavor_select)
276
                this.submit.addClass("disabled");
277
            }
286
            this.warning = this.$(".warning");
287
            this.warning.hide();
288
            this.submit.show();
289
            this.$(".flavor-options-inner-cont").append("<div>");
290
            this.flavors_view = new snf.views.FlavorOptionsView({
291
                flavors:this.vm.get_resize_flavors(),
292
                el: this.$(".flavor-options-inner-cont div"),
293
                hidden_choices:['disk', 'disk_template'],
294
                selected_flavor: this.vm.get_flavor(),
295
                extra_quotas: this.vm.get_flavor_quotas()
296
            });
297
            this.flavors_view.bind("flavor:select", this.handle_flavor_select)
298
            this.submit.addClass("disabled");
278 299
            views.VmResizeView.__super__.show.apply(this);
279 300
        },
280 301

  
281 302
        handle_flavor_select: function(flv) {
282 303
            if (flv.id == this.vm.get_flavor().id) {
283 304
                this.submit.addClass("disabled");
305
                this.shutdown.addClass("disabled");
284 306
            } else {
285
                this.submit.removeClass("disabled");
307
                if (this.vm.can_resize()) {
308
                  this.submit.removeClass("disabled");
309
                } else {
310
                  this.shutdown.removeClass("disabled hidden");
311
                  this.warning.show();
312
                }
286 313
            }
314
            this.update_vm_status();
315
        },
316

  
317
        update_vm_status: function() {
318
          if (this.selected_flavor) {
319
            this.handle_flavor_select(this.selected_flavor);
320
          }
321
          if (this.vm.get("status") == "SHUTDOWN") {
322
            this.shutdown.addClass("in-progress").removeClass("disabled");
323
            this.warning.hide();
324
          }
287 325
        },
288 326

  
289 327
        beforeOpen: function() {
......
292 330
        },
293 331

  
294 332
        update_layout: function() {
333
            this.update_actions();
295 334
            this.update_vm_details();
296 335
            this.render_choices();
336
            this.update_vm_status();
337
        },
338

  
339
        update_actions: function() {
340
          if (!this.vm.can_resize()) {
341
            this.shutdown.show();
342
            this.warning.show();
343
            this.shutdown.removeClass("disabled");
344
            if (this.selected_flavor) {
345
              this.handle_flavor_select(this.selected_flavor);
346
            } else {
347
              this.shutdown.addClass("disabled");
348
            }
349
            this.submit.addClass("disabled");
350
          } else {
351
            this.submit.removeClass("disabled");
352
            this.shutdown.hide();
353
          }
297 354
        },
298 355
          
299 356
        render_choices: function() {
......
301 358

  
302 359
        update_vm_details: function() {
303 360
            var name = _.escape(util.truncate(this.vm.get("name"), 70));
304
            this.set_subtitle(name + 
305
                              snf.ui.helpers.vm_icon_tag(this.vm, 
306
                                                         "small"));
361
            this.set_subtitle(name + snf.ui.helpers.vm_icon_tag(this.vm, "small"));
307 362
        },
308 363

  
309 364
        handle_vm_change: function() {
......
316 371
        onClose: function() {
317 372
            this.editing = false;
318 373
            this.vm.unbind("change", this.handle_vm_change);
374
            this.vm.unbind("change:status", this.handle_shutdown_complete);
319 375
            this.vm = undefined;
320 376
        }
321 377
    });

Also available in: Unified diff