]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/JavaScript/configuration-window.js
baculum: Add possibility to open configuration windows from URL
[bacula/bacula] / gui / baculum / protected / JavaScript / configuration-window.js
1 var ConfigurationWindowClass = new Class.create({
2         objects: {},
3
4         initialize: function(id) {
5                 if(typeof(id) == "undefined") {
6                         return;
7                 }
8                 var prefix = id.replace('Window', 'Configuration');
9                 this.window_id = prefix + 'configuration';
10                 this.progress_id = 'configuration-progress';
11                 this.lock = false;
12         },
13
14         show: function() {
15                 this.hideAll();
16                 this.initTabs();
17                 $(this.window_id).setStyle({'display' : 'block'});
18                 $$('div[id=' + this.window_id + '] input[type="submit"]').each(function(el) {
19                         el.observe('click', function() {
20                                 this.progress(true);
21                         }.bind(this));
22                 }.bind(this));
23         },
24
25         objectExists: function(key) {
26                 return this.objects.hasOwnProperty(key);
27         },
28
29         registerObj: function(key, obj) {
30                 if(this.objectExists(key) === false) {
31                         this.objects[key] = obj;
32                 }
33         },
34
35         getObj: function(key) {
36                 var obj = null;
37                 if(this.objectExists(key) === true) {
38                         obj = this.objects[key];
39                 }
40                 return obj;
41         },
42
43         hide: function() {
44                 $(this.window_id).setStyle({'display' : 'none'});
45         },
46
47         hideAll: function() {
48                 $$('div.configuration').each(function(el){
49                         el.setStyle({'display' : 'none'});
50                 });
51         },
52
53         progress: function(show) {
54                 if(show) {
55                         $(this.progress_id).setStyle({'display' : 'block'});
56                 } else {
57                         $(this.progress_id).setStyle({'display' : 'none'});
58                 }
59         },
60
61         is_progress: function() {
62                 return $(this.progress_id).getStyle('display') == 'block';
63         },
64
65         initTabs: function() {
66                 var show_elements = [];
67                 var element;
68                 var tabs = $$('div[id=' + this.window_id + '] span.tab');
69                 tabs.each(function(el) {
70                         element = el.readAttribute('rel');
71                         show_elements.push($(element));
72                         el.observe('click', function() {
73                                 show_elements.invoke('hide');
74                                 tabs.invoke('removeClassName', 'tab_active');
75                                 el.addClassName('tab_active');
76                                 var show_el = $(el.readAttribute('rel'));
77                                 $(show_el).show();
78                         }.bind(this));
79                 }.bind(this));
80         },
81
82         switchTab: function(tab_rel) {
83                 var tabs = $$('div[id=' + this.window_id + '] span.tab');
84                 tabs.each(function(el) {
85                         element = el.readAttribute('rel');
86                         if (element == tab_rel) {
87                                 el.addClassName('tab_active');
88                         } else {
89                                 el.removeClassName('tab_active');
90                         }
91                         $(element).hide();
92                 });
93                 $(tab_rel).show();
94         },
95
96         switchTabByNo: function(tab_no) {
97                 var tab_rel;
98                 var tabs = $$('div[id=' + this.window_id + '] span.tab');
99                 for (var i = 0, j = 1; i < tabs.length; i++, j++) {
100                         if (tab_no === j) {
101                                 tab_rel = tabs[i].readAttribute('rel');
102                                 break;
103                         }
104                 }
105
106                 if (tab_rel) {
107                         this.switchTab(tab_rel);
108                 }
109         },
110
111         openConfigurationWindow: function(slideWindowObj) {
112                 if(this.is_progress() === false) {
113                         this.progress(true);
114                         if(slideWindowObj.isFullSize() === true) {
115                                 slideWindowObj.resetSize();
116                         }
117                 }
118         }
119 });
120
121 var ConfigurationWindow = new ConfigurationWindowClass();