]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Web/JavaScript/bacula-config.js
baculum: Fix opening configuration tabs bug reported by Heitor Faria
[bacula/bacula] / gui / baculum / protected / Web / JavaScript / bacula-config.js
1 var BaculaConfigClass = jQuery.klass({
2         show_item: function(element, show, after_finish) {
3                 var el = $(element);
4                 var duration;
5                 if (show === true && el.is(':visible') === false) {
6                         el.slideDown({duration: 400, complete: after_finish});
7                 } else if (show === false && el.is(':visible') === true) {
8                         el.slideUp({duration: 500, complete: after_finish});
9                 }
10         },
11         show_items: function(selector, show, callback) {
12                 $(selector).each(function(index, el) {
13                         var cb = function() {
14                                 callback(el);
15                         }
16                         this.show_item(el, show, cb);
17                 }.bind(this));
18         },
19         show_new_config: function(sender, component_type, component_name, resource_type) {
20                 var container = $('div.config_directives[rel="' + sender + '"]');
21                 var h2 = container.find('h2');
22                 var text = h2[0].getAttribute('rel');
23                 text = text.replace('%component_type', component_type);
24                 text = text.replace('%component_name', component_name);
25                 text = text.replace('%resource_type', resource_type);
26                 h2[0].textContent = text;
27                 container.find('div.config_directives').show();
28                 this.show_item(container, true);
29                 this.scroll_to_element(container);
30         },
31         scroll_to_element: function(selector) {
32                 $('html,body').animate({scrollTop: $(selector).offset().top}, 'slow');
33         },
34         get_child_container: function(sender) {
35                 var child_container = $('#' + sender).closest('table').next('div');
36                 return child_container;
37         },
38         get_element_sender: function(el) {
39                 var element_sender = el.closest('table').prev('a');
40                 return element_sender;
41         },
42         set_config_items: function(id) {
43                 var child_container = this.get_child_container(id);
44                 var show = !child_container.is(':visible');
45                 this.show_item(child_container, show);
46                 this.loader_stop(id);
47         },
48         unset_config_items: function(id) {
49                 var child_container = this.get_child_container(id);
50                 var selector = [child_container[0].nodeName.toLowerCase(), child_container[0].className].join('.');
51                 var callback = function(el) {
52                         if (el.style.display === 'none' && !el.classList.contains('new_resource')) {
53                                 // element closed
54                                 var divs = el.getElementsByTagName('DIV');
55                                 if (divs.length > 0) {
56                                         var fc = divs[0];
57                                         // clear by removing elements
58                                         while (fc.firstChild) {
59                                                 fc.removeChild(fc.firstChild);
60                                         }
61                                 }
62                         }
63                 }
64                 this.show_items(selector, false, callback);
65                 /**
66                  * Send request about items only if items are invisible to avoid
67                  * asking about items when they are visible already.
68                  */
69                 var send = !child_container.is(':visible');
70                 return send;
71         },
72         get_loader: function(id) {
73                 var loader = $('#' + id).next('img');
74                 return loader;
75         },
76         loader_start: function(id) {
77                 var loader = this.get_loader(id);
78                 $(loader).show();
79         },
80         loader_stop: function(id) {
81                 var loader = this.get_loader(id);
82                 $(loader).hide();
83         }
84 });
85
86 var BaculaConfigOptionsClass = jQuery.klass({
87         css: {
88                 options_container: 'directive_setting'
89         },
90         options_id: null,
91         action_obj: null,
92         initialize: function(opts) {
93                 if (opts.hasOwnProperty('options_id')) {
94                         this.options_id = opts.options_id;
95                 }
96                 if (opts.hasOwnProperty('action_obj')) {
97                         this.action_obj = opts.action_obj;
98                 }
99                 this.set_events();
100         },
101         set_events: function() {
102                 var element = document.getElementById(this.options_id);
103                 var opts = element.getElementsByTagName('LI');
104                 for (var i = 0; i < opts.length; i++) {
105                         opts[i].addEventListener('click', function(e) {
106                                 var el = e.srcElement || e.target;
107                                 var action = el.getAttribute('rel');
108                                 this.do_action(action);
109                         }.bind(this));
110                 }
111         },
112         get_options: function() {
113                 ;
114         },
115         do_action: function(param) {
116                 if (typeof(this.action_obj) === "object") {
117                         this.action_obj.setCallbackParameter(param);
118                         this.action_obj.dispatch();
119                 }
120         }
121 });
122
123 var BaculaConfig = new BaculaConfigClass();