Fixes to pull/push logic.
[redakcja.git] / platforma / static / js / views / view.js
1 /*globals Editor render_template*/
2 var View = Editor.Object.extend({
3     _className: 'View',
4     element: null,
5     model: null,
6     template: null,
7     overlayClass: 'view-overlay',
8     overlay: null,
9   
10     init: function(element, model, template)
11     {
12         console.log("init for view");
13         this.element = $(element);
14         this.model = model;
15         this.template = template || this.template;
16     
17         if (this.template) this.render();
18     
19         this._resizeHandler = this.resized.bind(this);
20         $(window).bind('resize', this._resizeHandler);
21         $(this.element).bind('resize', this._resizeHandler);
22     },
23
24     render: function() {
25         console.log('rendering:', this._className);
26         this.element.html(render_template(this.template, this));
27     },
28   
29     frozen: function() {
30         return !!this.overlay;
31     },
32   
33     freeze: function(message) {
34         if (this.frozen()) {
35             this.unfreeze();
36         }
37         this.overlay = this.overlay || $('<div><div>' + message + '</div></div>');
38
39         this.overlay.addClass(this.overlayClass)
40         .css({
41             
42         }).attr('unselectable', 'on')
43
44         this.overlay.appendTo(this.element);
45
46         var ovc = this.overlay.children('div');        
47         var padV = (this.overlay.height() - ovc.outerHeight())/2;
48         var padH = (this.overlay.width() - ovc.outerWidth())/2;
49                    
50         this.overlay.children('div').css({
51             top: padV, left: padH
52         });    
53     },
54   
55     unfreeze: function() {
56         if (this.frozen()) {
57             this.overlay.remove();
58             this.overlay = null;
59         }
60     },
61
62     resized: function(event) {
63         if(this.overlay) {
64             var ovc = this.overlay.children('div');
65             var padV = (this.overlay.height() - ovc.outerHeight())/2;
66             var padH = (this.overlay.width() - ovc.outerWidth())/2;
67
68             this.overlay.children('div').css({
69                 top: padV,
70                 left: padH
71             });
72         }
73     },
74   
75     dispose: function() {
76         console.log('disposing:', this._className);
77         $(window).unbind('resize', this._resizeHandler);
78         $(this.element).unbind('resize', this._resizeHandler);
79         this.unfreeze();
80         this.element.html('');
81     }
82 });