Revision 8f53cfa3 snf-cyclades-app/synnefo/ui/static/snf/js/models.js

b/snf-cyclades-app/synnefo/ui/static/snf/js/models.js
229 229
    // Image model
230 230
    models.Image = models.Model.extend({
231 231
        path: 'images',
232

  
232
        
233 233
        get_size: function() {
234 234
            return parseInt(this.get('metadata') ? this.get('metadata').values.size : -1)
235 235
        },
......
261 261
            return this.get('owner') || _.keys(synnefo.config.system_images_owners)[0];
262 262
        },
263 263

  
264
        get_owner_uuid: function() {
265
            return this.get('owner_uuid');
266
        },
267

  
264 268
        is_system_image: function() {
265 269
          var owner = this.get_owner();
266 270
          return _.include(_.keys(synnefo.config.system_images_owners), owner)
......
268 272

  
269 273
        owned_by: function(user) {
270 274
          if (!user) { user = synnefo.user }
271
          return user.username == this.get_owner();
275
          return user.username == this.get('owner_uuid');
272 276
        },
273 277

  
274 278
        display_owner: function() {
......
1740 1744
        },
1741 1745

  
1742 1746
        parse: function (resp, xhr) {
1743
            var data = _.map(resp.images.values, _.bind(this.parse_meta, this));
1744
            return resp.images.values;
1747
            var parsed = _.map(resp.images.values, _.bind(this.parse_meta, this));
1748
            parsed = this.fill_owners(parsed);
1749
            return parsed;
1750
        },
1751

  
1752
        fill_owners: function(images) {
1753
            // do translate uuid->displayname if needed
1754
            // store display name in owner attribute for compatibility
1755
            var uuids = [];
1756

  
1757
            var images = _.map(images, function(img, index) {
1758
                if (synnefo.config.translate_uuids) {
1759
                    uuids.push(img['owner']);
1760
                }
1761
                img['owner_uuid'] = img['owner'];
1762
                return img;
1763
            });
1764
            
1765
            if (uuids.length > 0) {
1766
                var handle_results = function(data) {
1767
                    _.each(images, function (img) {
1768
                        img['owner'] = data.uuid_catalog[img['owner_uuid']];
1769
                    });
1770
                }
1771
                // notice the async false
1772
                var uuid_map = this.translate_uuids(uuids, false, 
1773
                                                    handle_results)
1774
            }
1775
            return images;
1776
        },
1777

  
1778
        translate_uuids: function(uuids, async, cb) {
1779
            var url = synnefo.config.user_catalog_url;
1780
            var data = JSON.stringify({'uuids': uuids});
1781
          
1782
            // post to user_catalogs api
1783
            snf.api.sync('create', undefined, {
1784
                url: url,
1785
                data: data,
1786
                async: async,
1787
                success:  cb
1788
            });
1745 1789
        },
1746 1790

  
1747 1791
        get_meta_key: function(img, key) {

Also available in: Unified diff