Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 4 additions & 71 deletions app/assets/javascripts/miq_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,13 @@ function miqUpdateAllCheckboxes(button_div) {
var crows = miqGridGetCheckedRows();

ManageIQ.gridChecks = crows;
miqSetButtons(crows.length, button_div);
} else if ($("input.listcheckbox").length) {
// No list_grid on the screen
var cbs = $("input.listcheckbox")
.prop('checked', state)
.trigger('change');

miqUpdateButtons(cbs[0], button_div);
miqUpdateButtons(cbs[0]);
} else if ($("input[id^='storage_cb']").length) {
// to handle check/uncheck all for C&U collection
$("input[id^='storage_cb']")
Expand All @@ -402,75 +401,9 @@ function miqUpdateAllCheckboxes(button_div) {
}

// Update buttons based on number of checkboxes that are checked
// parms: obj=<checkbox element>, button_div=<id of div with buttons to update>
function miqUpdateButtons(obj, button_div) {
var count = 0;

sendDataWithRx({rowSelect: obj});

if (typeof obj.id != "undefined") {
$("input[id^='check_']").each(function () {
if (this.checked && !this.disabled) {
count++;
}
if (count > 1) {
return false;
}
});
// Check for number object, as passed from snapshot tree
} else if (typeof obj == 'number') {
count = 1;
}
miqSetButtons(count, button_div);
}

// Set button enabled or disabled according to the number of selected items
function miqButtonOnWhen(button, onwhen, count) {
if (typeof onwhen != "undefined") {
var toggle = true;
switch(onwhen) {
case 1:
case '1':
toggle = count == 1;
break;
case '1+':
toggle = count >= 1;
break;
case '2+':
toggle = count >= 2;
break;
}
button.toggleClass('disabled', !toggle);
}
}

// Set the buttons in a div based on the count of checked items passed in
function miqSetButtons(count, button_div) {
if (!miqDomElementExists(button_div)) {
return
}

if (button_div.match("_tb$")) {
var toolbar = $('#' + button_div);

// Non-dropdown master buttons
toolbar.find('button:not(.dropdown-toggle)').each(function (_k, v) {
var button = $(v);
miqButtonOnWhen(button, button.data('onwhen'), count);
});

// Dropdown master buttons
toolbar.find('button.dropdown-toggle').each(function (_k, v) {
var button = $(v);
miqButtonOnWhen(button, button.data('onwhen'), count);
});

// Dropdown button items
toolbar.find('ul.dropdown-menu > li > a').each(function (_k, v) {
var button = $(v);
miqButtonOnWhen(button.parent(), button.data('onwhen'), count);
});
}
// parms: obj=<checkbox element>
function miqUpdateButtons(obj) {
sendDataWithRx({ rowSelect: obj });
}

// go to the specified URL when a table cell is clicked
Expand Down
3 changes: 1 addition & 2 deletions app/assets/javascripts/miq_grid.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global miqJqueryRequest miqSetButtons miqSparkleOn */
/* global miqJqueryRequest miqSparkleOn */

(function($) {
$.fn.miqGrid = function() {
Expand All @@ -25,7 +25,6 @@

sendDataWithRx({rowSelect: e.delegateTarget});
ManageIQ.gridChecks = checked;
miqSetButtons(checked.length, 'center_tb');

// if all the checkboxes were checked, make checkall checked too,
// if some aren't, make it unchecked => no trigger here
Expand Down
4 changes: 1 addition & 3 deletions app/assets/javascripts/miq_list_grid.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global DoNav miqDomElementExists miqJqueryRequest miqSetButtons miqUpdateButtons */
/* global DoNav miqDomElementExists miqJqueryRequest miqUpdateButtons */

// Handle row click (ajax or normal html trans)
function miqRowClick(row_id, row_url, row_url_ajax) {
Expand Down Expand Up @@ -64,8 +64,6 @@ function miqGridOnCheck(elem, button_div, grid) {

var crows = miqGridGetCheckedRows(grid);
ManageIQ.gridChecks = crows;

miqSetButtons(crows.length, "center_tb");
}

// Handle sort
Expand Down
6 changes: 1 addition & 5 deletions app/assets/javascripts/miq_tree.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global DoNav miqClearTreeState miqDomElementExists miqJqueryRequest miqSetButtons miqSparkle */
/* global DoNav miqClearTreeState miqDomElementExists miqJqueryRequest miqSparkle */

function miqTreeObject(tree) {
return $('#' + tree + 'box').treeview(true);
Expand Down Expand Up @@ -248,8 +248,6 @@ function miqGetChecked(node, treename) {
var selectedKeys = tree.getChecked().map(function (item) {
return item.key;
});
// Activate toolbar items according to the selection
miqSetButtons(selectedKeys.length, 'center_tb');
// Inform the backend about the checkbox changes
if (selectedKeys.length > 0) {
miqJqueryRequest(ManageIQ.tree.checkUrl + '?all_checked=' + selectedKeys, {beforeSend: true, complete: true});
Expand All @@ -268,8 +266,6 @@ function miqCheckAll(cb, treename) {
var selectedKeys = tree.getChecked().map(function (item) {
return item.key;
});
// Activate toolbar items according to the selection
miqSetButtons(selectedKeys.length, 'center_tb');
// Inform the backend about the checkbox changes
if (selectedKeys.length > 0) {
miqJqueryRequest(ManageIQ.tree.checkUrl + '?check_all=' + cb.checked + '&all_checked=' + selectedKeys);
Expand Down
1 change: 0 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,6 @@ def replace_gtl_main_div(options = {})
render :update do |page|
page << javascript_prologue
page.replace(:flash_msg_div, :partial => "layouts/flash_msg") # Replace the flash message
page << "miqSetButtons(0, 'center_tb');" # Reset the center toolbar
if layout_uses_listnav?
page.replace(:listnav_div, :partial => "layouts/listnav") # Replace accordion, if list_nav_div is there
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/availability_zone_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def button
page.replace(@refresh_div, :partial => @refresh_partial)
else
if ["images", "instances"].include?(@display) # If displaying vms, action_url s/b show
page << "miqSetButtons(0, 'center_tb');"
page.replace_html("main_div", :partial => "layouts/gtl", :locals => {:action_url => "show/#{@availability_zone.id}"})
else
page.replace_html(@refresh_div, :partial => @refresh_partial)
Expand Down
1 change: 0 additions & 1 deletion app/controllers/host_aggregate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def button
if @refresh_div == "flash_msg_div"
page.replace(@refresh_div, :partial => @refresh_partial)
elsif ["images", "instances"].include?(@display) # If displaying vms, action_url s/b show
page << "miqSetButtons(0, 'center_tb');"
page.replace_html("main_div", :partial => "layouts/gtl", :locals => {:action_url => "show/#{@host_aggregate.id}"})
else
page.replace_html(@refresh_div, :partial => @refresh_partial)
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/miq_task_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,8 @@ def button
page << javascript_prologue
unless @refresh_partial.nil?
if @refresh_div == "flash_msg_div"
page << "miqSetButtons(0, 'center_tb');" # Reset the center toolbar
page.replace(@refresh_div, :partial => @refresh_partial)
else
page << "miqSetButtons(0, 'center_tb');" # Reset the center toolbar
page.replace_html("main_div", :partial => @refresh_partial)
page.replace_html("paging_div", :partial => 'layouts/pagingcontrols',
:locals => {:pages => @pages,
Expand Down Expand Up @@ -290,7 +288,6 @@ def tasks_button
render :update do |page|
page << javascript_prologue
page.replace("flash_msg_div", :partial => "layouts/flash_msg")
page << "miqSetButtons(0, 'center_tb');" # Reset the center toolbar
page.replace("main_div", :partial => "layouts/tasks")
page.replace_html("paging_div", :partial => 'layouts/pagingcontrols',
:locals => {:pages => @pages,
Expand Down
65 changes: 0 additions & 65 deletions spec/javascripts/miq_application_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,71 +61,6 @@ describe('miq_application.js', function() {
});
});

describe('miqButtonOnWhen', function () {
beforeEach(function () {
var html = '<button id="button">Click me!</button>';
setFixtures(html);
});

describe('nothing selected', function () {
$.each(['1', '1+', '2+'], function (k, v) {
it('disables the button when onwhen is ' + v, function () {
var button = $('#button');
miqButtonOnWhen(button, v, 0);
expect(button.hasClass('disabled')).toBe(true);
});
});
});

describe('one selected', function () {
$.each(['1', '1+'], function (k, v) {
it('enables the button when onwhen is ' + v, function () {
var button = $('#button');
miqButtonOnWhen(button, v, 1);
expect(button.hasClass('disabled')).toBe(false);
});
});

it('disables the button when onwhen is 2+', function () {
var button = $('#button');
miqButtonOnWhen(button, '2+', 1);
expect(button.hasClass('disabled')).toBe(true);
});
});

describe('two selected', function () {
$.each(['1+', '2+'], function (k, v) {
it('enables the button when onwhen is ' + v, function () {
var button = $('#button');
miqButtonOnWhen(button, v, 2);
expect(button.hasClass('disabled')).toBe(false);
});
});

it('disables the button when onwhen is 1', function () {
var button = $('#button');
miqButtonOnWhen(button, '1', 2);
expect(button.hasClass('disabled')).toBe(true);
});
});

describe('three selected', function () {
$.each(['1+', '2+'], function (k, v) {
it('enables the button when onwhen is ' + v, function () {
var button = $('#button');
miqButtonOnWhen(button, v, 3);
expect(button.hasClass('disabled')).toBe(false);
});
});

it('disables the button when onwhen is 1', function () {
var button = $('#button');
miqButtonOnWhen(button, '1', 3);
expect(button.hasClass('disabled')).toBe(true);
});
})
});

describe('miqShowAE_Tree', function () {
it('uses url with the current controller', function() {
ManageIQ.controller = 'catalog';
Expand Down
1 change: 0 additions & 1 deletion spec/javascripts/miq_grid_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
describe('miq_grid.js', function () {
beforeEach(function () {
window.miqSetButtons = function() {}; // mock toolbar
var html = "<table class=\"table-clickable table-checkable\"><thead><tr><th><input type=\"checkbox\" class=\"checkall\"/></th><th>Title</th></tr></thead><tbody data-click-url=\"/test/\"><tr data-click-id=\"check_1\"><td class=\"noclick\"><input type=\"checkbox\" value=\"check_1\"/></td><td>Item 1</td></tr><tr data-click-id=\"check_2\"><td class=\"noclick\"><input type=\"checkbox\" value=\"check_2\" /></td><td>Item 2</td></tr><tr data-click-id=\"check_3\"><td class=\"noclick\"><input type=\"checkbox\" value=\"check_3\" /></td><td>Item 3</td></tr></tbody></table>";
setFixtures(html);
$('table').miqGrid();
Expand Down