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