]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/baculum/protected/JavaScript/slide-window.js
baculum: Search field works with all table cells
[bacula/bacula] / gui / baculum / protected / JavaScript / slide-window.js
index d0d329c02ddcc630ed75b950aee8d26820c646e1..d423f874b9a49df3b0f5ae893c99936a6ad932f9 100644 (file)
@@ -244,7 +244,7 @@ var SlideWindowClass = Class.create({
        },
 
        setWindowElementsEvent: function(opts) {
-               this.repeaterEl = opts.repeater_id;
+               this.repeaterEl = opts.repeater_id + '_Container';
                this.gridEl = opts.grid_id;
                this.loadRequest = opts.request_obj;
                if (opts.hasOwnProperty('actions_obj')) {
@@ -258,11 +258,13 @@ var SlideWindowClass = Class.create({
 
        setLoadRequest: function() {
                var dataList = [];
-               if($(this.gridEl)) {
-                       dataList = $(this.gridEl).select('tr');
+               var repeater = $(this.repeaterEl);
+               var grid = $(this.gridEl);
+               if(grid) {
+                       dataList = grid.select('tr');
                        this.makeSortable();
-               } else if ($(this.repeaterEl + '_Container')) {
-                       dataList = $(this.repeaterEl + '_Container').select('div.slide-window-element');
+               } else if (repeater) {
+                       dataList = repeater.select('div.slide-window-element');
                }
 
                var set_callback_parameter = function(element) {
@@ -274,6 +276,7 @@ var SlideWindowClass = Class.create({
                                this.configurationObj.openConfigurationWindow(this);
                        }
                }.bind(this);
+               this.setSearch();
                dataList.each(function(tr) {
                        $(tr).observe('click', function(index, clickedEl) {
                                var target = clickedEl.target || clickedEl.srcElement;
@@ -372,23 +375,39 @@ var SlideWindowClass = Class.create({
        },
 
        setSearch: function() {
-               var search_pattern = new RegExp(this.search.value)
-               $$('div[id="' + this.windowId + this.elements.containerSuffix + '"] div.' + this.elements.contentItems).each(function(value){
-                               
-                               if(search_pattern.match(value.childNodes[2].textContent) == false) {
+               var search_pattern = new RegExp(this.search.value, 'i');
+               var repeater = $(this.repeaterEl);
+               var grid = $(this.gridEl);
+               if (repeater) {
+                       repeater.select('div.' + this.elements.contentItems).each(function(value){
+                               if(search_pattern.test(value.childNodes[2].textContent) == false) {
                                        value.setStyle({'display' : 'none'});
                                } else {
                                        value.setStyle({'display' : ''});
                                }
                        }.bind(search_pattern));
-                       
-                       $$('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){
-                               if(search_pattern.match(value.down('div').innerHTML) == false) {
-                                       value.setStyle({'display' : 'none'});
+               }
+
+               if (grid) {
+                       grid.select('tr').each(function(value){
+                               var tds = value.select('td');
+                               var td;
+                               var found = false;
+                               for (var i = 0; i < tds.length; i++) {
+                                       td = tds[i].textContent.trim();
+                                       if(search_pattern.test(td) == true) {
+                                               found = true;
+                                               break;
+                                       }
+                               }
+
+                               if(found === true) {
+                                       value.show();
                                } else {
-                                       value.setStyle({'display' : ''});
+                                       value.hide();
                                }
                        }.bind(search_pattern));
+               }
        },
        setElementsCount : function() {
                var elements_count = $$('div[id="' + this.windowId + this.elements.containerSuffix + '"] div.' + this.elements.contentItems).length || $$('div[id="' + this.windowId + this.elements.containerSuffix + '"] tr.' + this.elements.contentItems + ', div[id="' + this.windowId + this.elements.containerSuffix + '"] tr.' + this.elements.contentAlternatingItems).length;
@@ -405,11 +424,10 @@ var SlideWindowClass = Class.create({
                return $(this.windowId + this.elements.toolbarSuffix).visible();
        },
        setActions: function() {
-               var table = $(this.window).down('table');
-               var checkboxes = table.select('input[name="actions_checkbox"]');
+               var checkboxes = this.getCheckboxes();
                checkboxes.each(function(el) {
                        el.observe('change', function() {
-                               var is_checked = this.is_any_checked(checkboxes);
+                               var is_checked = this.isAnyChecked(checkboxes);
                                if(is_checked === true && !this.areActionsOpen()) {
                                        this.showActions();
                                } else if (is_checked === false && this.areActionsOpen()) {
@@ -418,7 +436,7 @@ var SlideWindowClass = Class.create({
                        }.bind(this));
                 }.bind(this));
        },
-       is_any_checked: function(checkboxes) {
+       isAnyChecked: function(checkboxes) {
                var is_checked = false;
                checkboxes.each(function(ch) {
                        if(ch.checked == true) {
@@ -429,10 +447,23 @@ var SlideWindowClass = Class.create({
                return is_checked;
        },
 
+       getCheckboxes: function() {
+               var grid = $(this.gridEl);
+               var checkboxes = [];
+               if (grid) {
+                       checkboxes = grid.select('input[name="actions_checkbox"]');
+               }
+               return checkboxes;
+       },
+
+       areCheckboxesChecked: function() {
+               var checkboxes = this.getCheckboxes();
+               return this.isAnyChecked(checkboxes);
+       },
+
        markAllChecked: function(check) {
                this.checked = [];
-               var table = $(this.window).down('table');
-               var checkboxes = table.select('input[name="actions_checkbox"]');
+               var checkboxes = this.getCheckboxes();
                var containerId;
                if(checkboxes.length > 0) {
                        checkboxes.each(function(ch, index) {