Revision 550d9733 ui/static/snf/js/views.js

b/ui/static/snf/js/views.js
221 221
            } else {
222 222
                delay = 0;
223 223
            }
224
            
225 224
            window.setTimeout(_.bind(function(){ this.overlay.load() }, this), delay)
226 225
            return this;
227 226
        },
228 227

  
229 228
        hide: function() {
230
            this.overlay.close();
229
            if (!this.overlay.isOpened()) {
230
                // if its not opened events wont trigger
231
                this._onClose()
232
            } else {
233
                this.overlay.close();
234
            }
231 235
            return this;
232 236
        }
233 237
    });
234 238

  
239
    
240
    // overlay view helper
241
    views.VMOverlay = views.Overlay.extend({
242

  
243
        initialize: function() {
244
            views.VMOverlay.__super__.initialize.apply(this);
245
            this.vm = undefined;
246
            this.view_id_tpl = this.view_id;
247

  
248
            _.bindAll(this, "handle_vm_change", "handle_vm_remove");
249
        },
250

  
251
        set_vm: function(vm) {
252
            if (this.vm) { this.unbind_vm_handlers };
253
            this.vm = vm;
254
            this.view_id = this.view_id + "_" + vm.id;
255
            this.bind_vm_handlers();
256
        },
257

  
258
        bind_vm_handlers: function() {
259
            this.log.debug("binding handlers");
260
            this.vm.bind("change", this.handle_vm_change);
261
            storage.vms.bind("remove", this.handle_vm_remove);
262
        },
263
        
264
        unbind_vm_handlers: function() {
265
            this.log.debug("unbinding handlers", this.vm);
266
            if (!this.vm) { return };
267
            this.vm.unbind("change", this.handle_vm_change);
268
            storage.vms.unbind("remove", this.handle_vm_remove);
269
        },
270
        
271
        _update_vm_details: function() { 
272
            if (!this.vm) { console.error("invalid view state"); return }
273
            this.set_subtitle(this.vm.get("name") + snf.ui.helpers.vm_icon_tag(this.vm, "small"));
274

  
275
            var ico_path = snf.ui.helpers.os_icon_path(this.vm.get("OS"), "oslarge");
276
            this.$(".content").css({"background-image":"url(" + ico_path +")"})
277
            this.update_vm_details() 
278
        },
279

  
280
        update_vm_details: function() {},
281

  
282
        handle_vm_remove: function(vm, collection) {
283
            if (this.vm && vm.id == this.vm.id) {
284
                this.hide();
285
            }
286
        },
287

  
288
        handle_vm_change: function(vm) {
289
            this._update_vm_details();
290
        },
291
        
292
        beforeClose: function() {
293
            this.unbind_vm_handlers();
294
            this.vm = undefined;
295
        },
296

  
297
        show: function(vm) {
298
            this.set_vm(vm);
299
            views.VMOverlay.__super__.show.apply(this, arguments);
300
            this._update_vm_details();
301
        }
302

  
303
    });
304

  
235 305
})(this);

Also available in: Unified diff