Project

General

Profile

« Previous | Next » 

Revision 9b51b2b2

Added by Ohad Levy over 5 years ago

fixes #24191 - moves auth_source_selected JS function to webpack

View differences:

app/assets/javascripts/application.js
$('#ntsh').hide();
}
}
function auth_source_selected(){
var auth_source_id = $('#user_auth_source_id option:selected').text();
if (auth_source_id == 'INTERNAL') {
$("#password").show();
} else {
$("#password").hide();
}
}
function show_release(element){
var os_family = $(element).val();
if ($.inArray(os_family, ['Debian', 'Solaris', 'Coreos']) != -1) {
app/views/users/_form.html.erb
<%= select_f(f, :auth_source_id, AuthSource.except_hidden.to_a.delete_if { |a| a.to_label.nil? } , :id,
:to_label, { :include_blank => true } ,
{ :onchange => 'auth_source_selected()',
{ :onchange => 'tfm.users.authSourceSelected(this)',
:label => _('Authorized by') } ) unless @editing_self %>
<div id='password' <%= display? !@user.manage_password? %>>
webpack/assets/javascripts/foreman_users.js
},
});
}
export function authSourceSelected(param) {
const id = param.selectedOptions[0].textContent;
$('#password').toggle(id === 'INTERNAL');
}
webpack/assets/javascripts/foreman_users.test.js
expect($('#user_default_organization_id option').length).toEqual(1);
});
});
describe('users Password', () => {
// the following test is disabled as I wasn't able to simulate a change event on a select2 dropdown.
xit('should toggle password field', () => {
document.body.innerHTML = `
<div>
<select onchange="users.authSourceSelected(this)" name="user[auth_source_id]"
id="user_auth_source_id">
<option value=""></option>
<option value="8">LDAP-QA</option>
<option value="9">INTERNAL</option>
<option value="10">LDAP-CORP</option>
</select>
<div id="password" style="display:none;">
<input type="password" name="user[password]" id="user_password" class="ReactPasswordStrength-input form-control" value="">
<input id="password_confirmation" name="user[password_confirmation]" type="password" class="form-control">
</div>
</div>`;
$('#user_auth_source_id')
.val('9')
.change();
expect($('#password input').filter(':visible').length).toEqual(2);
$('#user_auth_source_id')
.val('')
.change();
expect($('#password input').filter(':visible').length).toEqual(0);
});
});

Also available in: Unified diff