]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/JavaScript/slide-window.js
baculum: Improvement loader for dynamic contents
[bacula/bacula] / gui / baculum / protected / JavaScript / slide-window.js
1 var SlideWindowClass = Class.create({
2
3         windowId: null,
4         window: null,
5         showEl: null,
6         hideEl: null,
7         fullSizeEl : null,
8         search: null,
9         toolbar: null,
10
11         size: {
12                 widthNormal : '437px',
13                 heightNormal : '325px',
14                 widthHalf : '437px',
15                 heightHalf : '586px',
16                 widthFull : '899px',
17                 heightFull : '586px'
18         },
19
20         elements : {
21                 containerSuffix : '-slide-window-container',
22                 configurationWindows : 'div.configuration',
23                 configurationProgress: 'div.configuration-progress',
24                 contentItems : 'slide-window-element',
25                 contentAlternatingItems : 'slide-window-element-alternating',
26                 toolsButtonSuffix : '-slide-window-tools',
27                 toolbarSuffix : '-slide-window-toolbar'
28         },
29
30         initialize: function(windowId, data) {
31
32                 this.windowId = windowId;
33                 this.window = $(this.windowId + this.elements.containerSuffix);
34                 this.tools = $(this.windowId + this.elements.toolsButtonSuffix);
35                 
36                 if(data.hasOwnProperty('showId')) {
37                                 this.showEl = $(data.showId);
38                 } else {
39                         alert('slide-window.js - "showId" property does not exists.');
40                         return false;
41                 }
42
43                 if(data.hasOwnProperty('hideId')) {
44                         this.hideEl = $(data.hideId);
45                 } else {
46                         alert('slide-window.js - "hideId" property does not exists.');
47                         return false;
48                 }
49
50                 if(data.hasOwnProperty('fullSizeId')) {
51                         this.fullSizeEl = $(data.fullSizeId);
52                 } else {
53                         alert('slide-window.js - "fullSizeId" property does not exists.');
54                         return false;
55                 }
56
57                 if(data.hasOwnProperty('search')) {
58                         this.search = $(data.search);
59                 } else {
60                         alert('slide-window.js - "search" property does not exists.');
61                         return false;
62                 }
63
64                 this.setEvents();
65         },
66
67         setEvents: function() {
68                 this.showEl.observe('click', function(){
69                         this.openWindow();
70                 }.bind(this));
71
72                 this.hideEl.observe('click', function(){
73                         this.closeWindow();
74                 }.bind(this));
75                 
76                 this.fullSizeEl.observe('click', function(){
77                         this.resetSize();
78                 }.bind(this));
79
80                 this.search.observe('keyup', function(){
81                         this.setSearch();
82                 }.bind(this));
83
84                 this.tools.observe('click', function() {
85                         this.toggleToolbar();
86                 }.bind(this));
87         },
88         
89         openWindow : function() {
90                 this.hideOtherWindows();
91                 Effect.toggle(this.window, 'slide', { duration: 0.3, afterFinish : function() {
92                                 this.normalSizeWindow();
93                         }.bind(this)
94                 });
95         },
96
97         closeWindow : function() {
98                 Effect.toggle(this.window, 'slide', { duration: 0.3, afterFinish : function() {
99                                 this.resetSize();
100                         }.bind(this)
101                 });
102         },
103         
104         resetSize : function() {
105                 if(this.isConfigurationOpen()) {
106                         if(this.isFullSize()) {
107                                 this.halfSizeWindow();
108                         } else if(this.isHalfSize()) {
109                                         this.normalSizeWindow();
110                         } else if (this.isNormalSize()){
111                                 this.halfSizeWindow();
112                         } else {
113                                 this.normalSizeWindow();
114                         }
115                 } else {
116                         if(this.isFullSize()) {
117                                 this.normalSizeWindow();
118                         } else if(this.isHalfSize() || this.isNormalSize()) {
119                                 this.fullSizeWindow();
120                         }
121                 }
122         },
123
124         isNormalSize: function() {
125                 return (this.window.getWidth()  + 'px' == this.size.widthNormal && this.window.getHeight()  + 'px' == this.size.heightNormal);
126         },
127
128         isHalfSize: function() {
129                 return (this.window.getWidth()  + 'px' == this.size.widthHalf && this.window.getHeight()  + 'px' == this.size.heightHalf);
130         },
131
132         isFullSize: function() {
133                 return (this.window.getWidth()  + 'px' == this.size.widthFull && this.window.getHeight()  + 'px' == this.size.heightFull);
134         },
135
136         normalSizeWindow: function() {
137                         new Effect.Morph(this.window, {style : 'width: ' + this.size.widthNormal + '; height: ' + this.size.heightNormal + ';', duration : 0.4});
138         },
139         
140         halfSizeWindow: function() {
141                         new Effect.Morph(this.window, {style : 'width: ' + this.size.widthHalf + '; height: ' + this.size.heightHalf + ';', duration : 0.4});
142         },
143         
144         fullSizeWindow: function() {
145                         new Effect.Morph(this.window, {style : 'width: ' + this.size.widthFull + '; height: ' + this.size.heightFull + ';', duration : 0.4});
146         },
147
148         hideOtherWindows: function() {
149                 $$('.slide-window-container').each(function(el, index) {
150                         el.setStyle({
151                                 display : 'none',
152                                 width : this.size.widthNormal,
153                                 height : this.size.heightNormal
154                         });
155                 }.bind(this));
156         },
157
158         isConfigurationOpen: function() {
159                 var is_open = false;
160                 $$(this.elements.configurationWindows, this.elements.configurationProgress).each(function(el) {
161                         console.log(el);
162                         if(el.getStyle('display') == 'block') {
163                                 is_open = true;
164                                 throw $break;
165                         }
166                 }.bind(is_open));
167                 return is_open;
168         },
169
170         setSearch: function() {
171                 var search_pattern = new RegExp(this.search.value)
172                 $$('div[id=' + this.windowId + this.elements.containerSuffix + '] div.' + this.elements.contentItems).each(function(value){
173                                 
174                                 if(search_pattern.match(value.childNodes[2].textContent) == false) {
175                                         value.setStyle({'display' : 'none'});
176                                 } else {
177                                         value.setStyle({'display' : ''});
178                                 }
179                         }.bind(search_pattern));
180                         
181                         $$('div[id=' + this.windowId + this.elements.containerSuffix + '] tr.' + this.elements.contentItems + ', div[id=' + this.windowId + this.elements.containerSuffix + '] tr.' + this.elements.contentAlternatingItems).each(function(value){
182                                 if(search_pattern.match(value.down('div').innerHTML) == false) {
183                                         value.setStyle({'display' : 'none'});
184                                 } else {
185                                         value.setStyle({'display' : ''});
186                                 }
187                         }.bind(search_pattern));
188         },
189
190         toggleToolbar: function() {
191                 Effect.toggle($(this.windowId + this.elements.toolbarSuffix), 'slide', { duration: 0.2});
192         }
193 });
194
195 document.observe("dom:loaded", function() {
196         if(Prototype.Browser.IE  || Prototype.Browser.Gecko) {
197                 $$('input[type=checkbox], input[type=submit], input[type=radio], a').each(function(el) {
198                         el.observe('focus', function() {
199                                 el.blur();
200                         }.bind(el));
201                 });
202         }
203 });