Revision 885a592b ui/static/snf/js/ui/web/ui_create_view.js

b/ui/static/snf/js/ui/web/ui_create_view.js
58 58
                this.clipboard.setText(this.pass);
59 59
                this.copy.show();
60 60
            } catch (err) {
61
                console.error(err);
62 61
                this.copy.hide();
63 62
            }
64 63
        },
......
407 406
            return true;
408 407
        },
409 408
            
409
        set_valid_current_for: function(t, val) {
410
            var found = this.flavors[0];
411
            _.each(this.flavors, function(flv) {
412
                if (flv.get(t) == val) {
413
                    found = flv;
414
                }
415
            });
416

  
417
            this.set_current(found);
418
        },
419

  
410 420
        set_current: function(flv) {
411
            //console.log(flv);
412
            //if (!this.flavor_is_valid(flv)) { flv = undefined };
413
            
421

  
422
            if (!flv) {
423
                // user clicked on invalid combination
424
                // force the first available choice for the
425
                // type of option he last clicked
426
                this.set_valid_current_for.apply(this, this.last_choice);
427
                return;
428
            }
429

  
414 430
            this.current_flavor = flv;
415 431
            this.trigger("change");
416 432
            this.update_selected_flavor();
......
428 444
        update_disabled_flavors: function() {
429 445
            this.$(".flavor-options.disk li").removeClass("disabled");
430 446
            if (!this.unavailable_values) { return }
431

  
432
            this.$(".flavor-options.disk li").each(_.bind(function(i, el){
433
                var el_value = $(el).data("value") * 1024;
447
            
448
            this.$("#create-vm-flavor-options .flavor-options.disk li").each(_.bind(function(i, el){
449
                var el_value = $(el).data("value") * 1000;
434 450
                if (this.unavailable_values.disk.indexOf(el_value) > -1) {
435 451
                    $(el).addClass("disabled");
436 452
                };
......
440 456
        create_flavors: function() {
441 457
            var flavors = this.get_active_flavors();
442 458
            var valid_flavors = this.get_valid_flavors();
459
            this.__added_flavors = {'cpu':[], 'ram':[], 'disk':[]};
443 460

  
444 461
            _.each(flavors, _.bind(function(flv){
445 462
                this.add_flavor(flv);
......
454 471
                el.parent().find(".option").removeClass("selected");
455 472
                el.addClass("selected");
456 473
                
457
                if (el.hasClass("mem")) { this.last_choice = "mem" }
458
                if (el.hasClass("cpu")) { this.last_choice = "cpu" }
459
                if (el.hasClass("disk")) { this.last_choice = "disk" }
474
                if (el.hasClass("mem")) { self.last_choice = ["ram", $(this).data("value")] }
475
                if (el.hasClass("cpu")) { self.last_choice = ["cpu", $(this).data("value")] }
476
                if (el.hasClass("disk")) { self.last_choice = ["disk", $(this).data("value")] }
460 477

  
461 478
                self.update_selected_from_ui();
462 479
            })
......
480 497
            this.$(".option.mem.value-" + flv.get("ram")).addClass("selected");
481 498
            this.$(".option.disk.value-" + flv.get("disk")).addClass("selected");
482 499
        },
483

  
500
        
501
        __added_flavors: {'cpu':[], 'ram':[], 'disk':[]},
484 502
        add_flavor: function(flv) {
485 503
            var values = {'cpu': flv.get('cpu'), 'mem': flv.get('ram'), 'disk': flv.get('disk')};
486 504

  
487 505
            disabled = "";
488

  
489
            if (this.$('li.option.cpu.value-{0}'.format(values.cpu)).length == 0) {
506
            
507
            if (this.__added_flavors.cpu.indexOf(values.cpu) == -1) {
490 508
                var cpu = $(('<li class="option cpu value-{0} {1}">' + 
491 509
                             '<span class="value">{0}</span>' + 
492 510
                             '<span class="metric">x</span></li>').format(values.cpu, disabled)).data('value', values.cpu);
493

  
494 511
                this.cpus.append(cpu);
512
                this.__added_flavors.cpu.push(values.cpu);
495 513
            }
496
            if (this.$('li.option.mem.value-{0}'.format(values.mem)).length == 0) {
514

  
515
            if (this.__added_flavors.ram.indexOf(values.mem) == -1) {
497 516
                var mem = $(('<li class="option mem value-{0}">' + 
498 517
                             '<span class="value">{0}</span>' + 
499 518
                             '<span class="metric">MB</span></li>').format(values.mem)).data('value', values.mem);
500

  
501 519
                this.mems.append(mem);
520
                this.__added_flavors.ram.push(values.mem);
502 521
            }
503
            if (this.$('li.option.disk.value-{0}'.format(values.disk)).length == 0) {
522

  
523
            if (this.__added_flavors.disk.indexOf(values.disk) == -1) {
504 524
                var disk = $(('<li class="option disk value-{0}">' + 
505 525
                              '<span class="value">{0}</span>' + 
506 526
                              '<span class="metric">GB</span></li>').format(values.disk)).data('value', values.disk);
507

  
508 527
                this.disks.append(disk);
528
                this.__added_flavors.disk.push(values.disk)
509 529
            }
530

  
510 531
            
511 532
        },
512 533
        
......
528 549
            this.flavors = [];
529 550
            this.flavors_data = {'cpu':[], 'mem':[], 'disk':[]};
530 551
            this.update_flavors_data();
531
            this.reset_flavors();
532 552
        },
533 553

  
534 554
        get: function() {
......
711 731
            this.submit_btn = this.$(".create-controls .submit")
712 732
            
713 733
            this.init_handlers();
714
            this.update_layout();
715

  
716 734
        },
717 735

  
718 736
        init_handlers: function() {

Also available in: Unified diff