2017-01-04 08:16:14 -05:00
|
|
|
/* global Pikaday */
|
|
|
|
/* global dateFormat */
|
2016-12-27 12:24:28 -05:00
|
|
|
(() => {
|
2016-08-18 09:12:48 -04:00
|
|
|
// 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.
|
|
|
|
//
|
2017-01-03 13:55:36 -05:00
|
|
|
window.gl = window.gl || {};
|
2016-12-27 12:24:28 -05:00
|
|
|
gl.MemberExpirationDate = (selector = '.js-access-expiration-date') => {
|
2016-08-18 20:41:18 -04:00
|
|
|
function toggleClearInput() {
|
|
|
|
$(this).closest('.clearable-input').toggleClass('has-value', $(this).val() !== '');
|
|
|
|
}
|
2017-01-03 13:55:36 -05:00
|
|
|
const inputs = $(selector);
|
2016-08-18 09:12:48 -04:00
|
|
|
|
2017-01-04 08:16:14 -05:00
|
|
|
inputs.each((i, el) => {
|
|
|
|
const $input = $(el);
|
|
|
|
|
|
|
|
const calendar = new Pikaday({
|
|
|
|
field: $input.get(0),
|
2017-04-21 11:05:38 -04:00
|
|
|
theme: 'gitlab-theme animate-picker',
|
2017-02-14 16:45:36 -05:00
|
|
|
format: 'yyyy-mm-dd',
|
2017-01-04 08:16:14 -05:00
|
|
|
minDate: new Date(),
|
2017-04-21 11:05:38 -04:00
|
|
|
container: $input.parent().get(0),
|
2017-01-06 09:43:21 -05:00
|
|
|
onSelect(dateText) {
|
2017-01-04 08:16:14 -05:00
|
|
|
$input.val(dateFormat(new Date(dateText), 'yyyy-mm-dd'));
|
|
|
|
|
|
|
|
$input.trigger('change');
|
|
|
|
|
2017-01-06 09:43:21 -05:00
|
|
|
toggleClearInput.call($input);
|
2017-01-04 08:16:14 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-02-14 16:45:36 -05:00
|
|
|
calendar.setDate(new Date($input.val()));
|
2017-01-04 08:16:14 -05:00
|
|
|
$input.data('pikaday', calendar);
|
2016-08-18 20:41:18 -04:00
|
|
|
});
|
2016-08-18 09:12:48 -04:00
|
|
|
|
2017-01-04 14:51:40 -05:00
|
|
|
inputs.next('.js-clear-input').on('click', function clicked(event) {
|
2016-08-18 20:41:18 -04:00
|
|
|
event.preventDefault();
|
2016-08-18 09:12:48 -04:00
|
|
|
|
2017-01-03 13:55:36 -05:00
|
|
|
const input = $(this).closest('.clearable-input').find(selector);
|
2017-01-04 08:16:14 -05:00
|
|
|
const calendar = input.data('pikaday');
|
|
|
|
|
|
|
|
calendar.setDate(null);
|
|
|
|
input.trigger('change');
|
2016-08-18 20:41:18 -04:00
|
|
|
toggleClearInput.call(input);
|
|
|
|
});
|
2016-08-18 09:12:48 -04:00
|
|
|
|
2016-08-18 20:41:18 -04:00
|
|
|
inputs.on('blur', toggleClearInput);
|
2016-08-18 09:12:48 -04:00
|
|
|
|
2016-08-18 20:41:18 -04:00
|
|
|
inputs.each(toggleClearInput);
|
2016-08-18 09:12:48 -04:00
|
|
|
};
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|