gitlab-org--gitlab-foss/app/assets/javascripts/member_expiration_date.js

42 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-11-15 09:08:06 -05:00
/* eslint-disable func-names, space-before-function-paren, vars-on-top, no-var, object-shorthand, comma-dangle, max-len */
(function() {
// Add datepickers to all `js-access-expiration-date` elements. If those elements are
// children of an element with the `clearable-input` class, and have a sibling
// `js-clear-input` element, then show that element when there is a value in the
// datepicker, and make clicking on that element clear the field.
//
gl.MemberExpirationDate = function(newSelector) {
2016-08-18 20:41:18 -04:00
function toggleClearInput() {
$(this).closest('.clearable-input').toggleClass('has-value', $(this).val() !== '');
}
var selector = '.js-access-expiration-date';
if (typeof newSelector !== 'undefined' && newSelector !== '') {
selector = newSelector;
}
var inputs = $(selector);
2016-08-18 20:41:18 -04:00
inputs.datepicker({
dateFormat: 'yy-mm-dd',
minDate: 1,
onSelect: function () {
$(this).trigger('change');
toggleClearInput.call(this);
}
2016-08-18 20:41:18 -04:00
});
2016-08-18 20:41:18 -04:00
inputs.next('.js-clear-input').on('click', function(event) {
event.preventDefault();
var input = $(this).closest('.clearable-input').find(selector);
input.datepicker('setDate', null)
.trigger('change');
2016-08-18 20:41:18 -04:00
toggleClearInput.call(input);
});
2016-08-18 20:41:18 -04:00
inputs.on('blur', toggleClearInput);
2016-08-18 20:41:18 -04:00
inputs.each(toggleClearInput);
};
}).call(this);