Dodanie KVC/KVO. Przeniesienie modeli do models.js.
[redakcja.git] / project / static / js / views / view.js
1 /*globals Editor render_template*/
2 var View = Editor.Object.extend({
3   element: null,
4   model: null,
5   template: null,
6   overlayClass: 'view-overlay',
7   overlay: null,
8   id: null,
9   
10   init: function(element, model, template) {
11     this.element = $(element);
12     this.model = model;
13     this.template = template || this.template;
14     
15     if (this.template) {
16       this.element.html(render_template(this.template, this));
17     }
18     
19     View.lastId = View.lastId + 1;
20     this.id = 'view-' + View.lastId;
21   },
22   
23   // Identyczność
24   hash: function() {
25     
26   },
27   
28   frozen: function() {
29     return !!this.overlay;
30   },
31   
32   freeze: function(message) {
33     this.overlay = this.overlay 
34       || $('<div><div>' + message + '</div></div>')
35             .addClass(this.overlayClass)
36             .css({
37               position: 'absolute',
38               width: this.element.width(),
39               height: this.element.height(),
40               top: this.element.position().top,
41               left: this.element.position().left
42             })
43             .appendTo(this.element.parent());
44             
45     this.overlay.children('div').css({
46       position: 'relative',
47       top: this.overlay.height() / 2 - 20
48     });
49   },
50   
51   unfreeze: function() {
52     if (this.frozen()) {
53       this.overlay.remove();
54       this.overlay = null;      
55     }
56   },
57
58   dispose: function() {
59     this.unfreeze();
60     this.element.contents().remove();
61   }
62 });
63
64
65 View.lastId = 0;