Revision c45bed88

b/snf-app/synnefo/ui/static/snf/js/models.js
843 843
                }
844 844
                if (progress > 0 && progress < 99) {
845 845
                    this.state("BUILD_COPY");
846
                    var params = this.get_copy_details(true);
847
                    this.set({progress_message: BUILDING_MESSAGES['COPY'].format(params.copy, 
848
                                                                                 params.size, 
849
                                                                                 params.progress)});
846
                    this.get_copy_details(true, undefined, _.bind(function(details){
847
                        this.set({
848
                            progress_message: BUILDING_MESSAGES['COPY'].format(details.copy, 
849
                                                                               details.size, 
850
                                                                               details.progress)
851
                        });
852
                    }, this));
850 853
                }
851 854
                if (progress == 100) {
852 855
                    this.state("BUILD_FINAL");
......
856 859
            }
857 860
        },
858 861

  
859
        get_copy_details: function(human, image) {
862
        get_copy_details: function(human, image, callback) {
860 863
            var human = human || false;
861
            var image = image || this.get_image();
864
            var image = image || this.get_image(_.bind(function(image){
865
                var progress = this.get('progress');
866
                var size = image.get_size();
867
                var size_copied = (size * progress / 100).toFixed(2);
868
                
869
                if (human) {
870
                    size = util.readablizeBytes(size*1024*1024);
871
                    size_copied = util.readablizeBytes(size_copied*1024*1024);
872
                }
862 873

  
863
            var progress = this.get('progress');
864
            var size = image.get_size();
865
            var size_copied = (size * progress / 100).toFixed(2);
866
            
867
            if (human) {
868
                size = util.readablizeBytes(size*1024*1024);
869
                size_copied = util.readablizeBytes(size_copied*1024*1024);
870
            }
871
            return {'progress': progress, 'size': size, 'copy': size_copied};
874
                callback({'progress': progress, 'size': size, 'copy': size_copied})
875
            }, this));
872 876
        },
873 877

  
874 878
        start_stats_update: function(force_if_empty) {
......
1178 1182
        },
1179 1183
        
1180 1184
        // get image object
1181
        get_image: function() {
1185
        get_image: function(callback) {
1182 1186
            var image = storage.images.get(this.get('imageRef'));
1183 1187
            if (!image) {
1184
                storage.images.update_unknown_id(this.get('imageRef'));
1188
                storage.images.update_unknown_id(this.get('imageRef'), callback);
1189
                return;
1185 1190
            }
1191
            callback(image);
1186 1192
            return image;
1187 1193
        },
1188 1194
        
......
1207 1213
        
1208 1214
        // get metadata OS value
1209 1215
        get_os: function() {
1210
            return this.get_meta().OS || (this.get_image() ? this.get_image().get_os() || "okeanos" : "okeanos");
1216
            return this.get_meta().OS || (this.get_image(function(){}) ? this.get_image(function(){}).get_os() || "okeanos" : "okeanos");
1211 1217
        },
1212 1218

  
1213 1219
        // get public ip addresses
......
1552 1558
        // update collection model with id passed
1553 1559
        // making a direct call to the image
1554 1560
        // api url
1555
        update_unknown_id: function(id) {
1561
        update_unknown_id: function(id, callback) {
1556 1562
            var url = getUrl.call(this) + "/" + id;
1557
            this.api_call(this.path + "/" + id, this.read_method, {_options:{async:false, skip_api_error:true}}, undefined, 
1563
            this.api_call(this.path + "/" + id, this.read_method, {_options:{async:true, skip_api_error:true}}, undefined, 
1558 1564
            _.bind(function() {
1559 1565
                this.add({id:id, name:"Unknown image", size:-1, progress:100, status:"DELETED"});
1566
                callback(this.get(id));
1560 1567
            }, this), _.bind(function(image, msg, xhr) {
1561 1568
                var img_data = this._read_image_from_request(image, msg, xhr);
1562 1569
                this.add(img_data);
1570
                callback(this.get(id));
1563 1571
            }, this));
1564 1572
        },
1565 1573

  
......
1642 1650
        // update collection model with id passed
1643 1651
        // making a direct call to the flavor
1644 1652
        // api url
1645
        update_unknown_id: function(id) {
1653
        update_unknown_id: function(id, callback) {
1646 1654
            var url = getUrl.call(this) + "/" + id;
1647 1655
            this.api_call(this.path + "/" + id, "read", {_options:{async:false, skip_api_error:true}}, undefined, 
1648 1656
            _.bind(function() {
b/snf-app/synnefo/ui/static/snf/js/ui/web/ui_custom_images.js
34 34
            this.bind("item:add", this.animate_on_add);
35 35
        },
36 36

  
37
        _get_models: function() {
38
            return this.collection.get_personal_images();
39
        },
40

  
37 41
        animate_on_add: function(list, el, model) {
38 42
            el.hide();
39 43
            el.fadeIn(400);
b/snf-app/synnefo/ui/static/snf/js/ui/web/ui_icon_view.js
582 582
        update_layout: function() {
583 583
            if (!this.visible() && this.parent.details_hidden) { return };
584 584

  
585
            var image = this.vm.get_image();
585
            var image = this.vm.get_image(_.bind(function(image){
586
                this.sel('image_name').text(util.truncate(image.get('name'), 13)).attr("title", image.get('name'));
587
                this.sel('image_size').text(image.get_readable_size()).attr('title', image.get_readable_size());
588
            }, this));
589

  
586 590
            var flavor = this.vm.get_flavor();
587 591
            if (!flavor || !image) {
588 592
                return;
589 593
            }
590 594

  
591
            this.sel('image_name').text(util.truncate(image.get('name'), 13)).attr("title", image.get('name'));
592
            this.sel('image_size').text(image.get_readable_size()).attr('title', image.get_readable_size());
593 595

  
594 596
            this.sel('cpu').text(flavor.get('cpu'));
595 597
            this.sel('ram').text(flavor.get('ram'));
b/snf-app/synnefo/ui/static/snf/js/ui/web/ui_model_views.js
116 116
            this.items = _.map(models, function(m) { return m.id });
117 117
        },
118 118

  
119
        _get_models: function() {
120
            return this.collection.models;
121
        },
122

  
119 123
        handle_reset: function(collection, models) {
120 124
            this.loading.hide();
121 125
            this.content.show();
......
124 128
                this.reset_list();
125 129
            }
126 130

  
127
            this.update_list(this.collection.models);
128
            this.update_removed(this.items, this.collection.models);
131
            this.update_list(this._get_models());
132
            this.update_removed(this.items, this._get_models());
129 133

  
130
            this.set_items(this.collection.models);
134
            this.set_items(this._get_models());
131 135
        },
132 136

  
133 137
        show_form: function(model) {

Also available in: Unified diff