Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: eclarizio/manageiq-ui-classic
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 071e3cd2bfcae791ee72b092a3d091183ecbc0e7~
Choose a base ref
...
head repository: eclarizio/manageiq-ui-classic
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 21f52206e37066e12b7fb25c67040a5cd03bf8d1
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 28, 2017

  1. Copy the full SHA
    071e3cd View commit details
  2. Copy the full SHA
    c14a702 View commit details
  3. Copy the full SHA
    21f5220 View commit details
Showing with 71 additions and 14 deletions.
  1. +12 −8 app/assets/javascripts/dialog_field_refresh.js
  2. +4 −0 app/views/shared/dialogs/_dialog_provision.html.haml
  3. +55 −6 spec/javascripts/dialog_field_refresh_spec.js
20 changes: 12 additions & 8 deletions app/assets/javascripts/dialog_field_refresh.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
/* global miqInitSelectPicker miqSelectPickerEvent miqSparkle miqSparkleOn */

var dialogFieldRefresh = {
unbindAllPreviousListeners: function() {
$(document).off('dialog::autoRefresh');
},

listenForAutoRefreshMessages: function(autoRefreshOptions, callbackFunction) {
var thisIsTheFieldToUpdate = function(event) {
var tabIndex = event.data.tabIndex;
var groupIndex = event.data.groupIndex;
var fieldIndex = event.data.fieldIndex;
var thisIsTheFieldToUpdate = function(data) {
var tabIndex = data.tabIndex;
var groupIndex = data.groupIndex;
var fieldIndex = data.fieldIndex;
return tabIndex === autoRefreshOptions.tab_index && groupIndex === autoRefreshOptions.group_index && fieldIndex === autoRefreshOptions.field_index;
};

window.addEventListener('message', function(event) {
if (thisIsTheFieldToUpdate(event)) {
$(document).on('dialog::autoRefresh', function(_event, data) {
if (thisIsTheFieldToUpdate(data)) {
callbackFunction.call();
}
});
@@ -181,11 +185,11 @@ var dialogFieldRefresh = {
nextAvailable = nextAvailable[0];

if (nextAvailable !== undefined) {
parent.postMessage({
$(document).trigger('dialog::autoRefresh', {
tabIndex: nextAvailable.tab_index,
groupIndex: nextAvailable.group_index,
fieldIndex: nextAvailable.field_index,
}, '*');
});
}
}
},
4 changes: 4 additions & 0 deletions app/views/shared/dialogs/_dialog_provision.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
- wf = @edit[:wf] if @edit && @edit[:wf]
= render :partial => "layouts/flash_msg"

:javascript
dialogFieldRefresh.unbindAllPreviousListeners();

.row
.col-md-12.col-lg-12
#dialog_tabs
61 changes: 55 additions & 6 deletions spec/javascripts/dialog_field_refresh_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
describe('dialogFieldRefresh', function() {
describe('#listenForAutoRefreshMessages', function() {
context('when an autoRefresh event gets triggered', function() {
var callback;
var autoRefreshOptions;

beforeEach(function() {
callback = jasmine.createSpyObj('callback', ['call']);
autoRefreshOptions = {
tab_index: 1,
group_index: 2,
field_index: 3
};
dialogFieldRefresh.listenForAutoRefreshMessages(autoRefreshOptions, callback);
});

context('when the tab index, group index, and field index match the corresponding field', function() {
beforeEach(function() {
$(document).trigger('dialog::autoRefresh', {tabIndex: 1, groupIndex: 2, fieldIndex: 3});
});

it('executes the callback', function() {
expect(callback.call).toHaveBeenCalled();
});
});

context('when the tab index, group index, and field index do not match the corresponding field', function() {
beforeEach(function() {
$(document).trigger('dialog::autoRefresh', {tabIndex: 1, groupIndex: 1, fieldIndex: 3});
});

it('does not execute the callback', function() {
expect(callback.call).not.toHaveBeenCalled();
});
});
});
});

describe('#unbindAllPreviousListeners', function() {
beforeEach(function() {
spyOn($.fn, 'off');
});

it('unbinds all autoRefresh messages from the document', function() {
dialogFieldRefresh.unbindAllPreviousListeners();
expect($.fn.off.calls.mostRecent().object).toEqual(document);
expect($.fn.off).toHaveBeenCalledWith('dialog::autoRefresh');
});
});

describe('#addOptionsToDropDownList', function() {
var data = {};

@@ -581,13 +630,13 @@ describe('dialogFieldRefresh', function() {

describe('#triggerAutoRefresh', function() {
beforeEach(function() {
spyOn(parent, 'postMessage');
spyOn($.fn, 'trigger');
});

context('when the trigger passed in falsy', function() {
it('does not post any messages', function() {
dialogFieldRefresh.triggerAutoRefresh({trigger: ""});
expect(parent.postMessage).not.toHaveBeenCalled();
expect($.fn.trigger).not.toHaveBeenCalled();
});
});

@@ -602,7 +651,7 @@ describe('dialogFieldRefresh', function() {
});

it('does not post a message', function() {
expect(parent.postMessage).not.toHaveBeenCalled();
expect($.fn.trigger).not.toHaveBeenCalled();
});
});

@@ -619,7 +668,7 @@ describe('dialogFieldRefresh', function() {
});

it('posts a message', function() {
expect(parent.postMessage).toHaveBeenCalledWith({tabIndex: 1, groupIndex: 1, fieldIndex: 2}, '*');
expect($.fn.trigger).toHaveBeenCalledWith('dialog::autoRefresh', {tabIndex: 1, groupIndex: 1, fieldIndex: 2});
});
});
});
@@ -635,7 +684,7 @@ describe('dialogFieldRefresh', function() {
});

it('does not post a message', function() {
expect(parent.postMessage).not.toHaveBeenCalled();
expect($.fn.trigger).not.toHaveBeenCalled();
});
});

@@ -652,7 +701,7 @@ describe('dialogFieldRefresh', function() {
});

it('posts a message', function() {
expect(parent.postMessage).toHaveBeenCalledWith({tabIndex: 1, groupIndex: 1, fieldIndex: 2}, '*');
expect($.fn.trigger).toHaveBeenCalledWith('dialog::autoRefresh', {tabIndex: 1, groupIndex: 1, fieldIndex: 2});
});
});
});