diff options
author | Sean McGivern <sean@gitlab.com> | 2016-08-18 14:12:48 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2016-08-18 14:14:22 +0100 |
commit | dd4784f3b16218cadfa3f73dce2250d4276ffb1f (patch) | |
tree | be35a0f37a75d445d5351f18957a615747d98e34 /app/assets/javascripts/member_expiration_date.js | |
parent | c90d167b5ec020138f7d72cb1006d1436c980a2a (diff) | |
download | gitlab-ce-dd4784f3b16218cadfa3f73dce2250d4276ffb1f.tar.gz |
Add MemberExpirationDate JS helper
This helper adds a datepicker to all `js-access-expiration-date`
elements. If that element is a child of a `clearable-input` element and
has a sibling `js-clear-input` element, then it will show a working
clear button to the right of the input field.
Diffstat (limited to 'app/assets/javascripts/member_expiration_date.js')
-rw-r--r-- | app/assets/javascripts/member_expiration_date.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/app/assets/javascripts/member_expiration_date.js b/app/assets/javascripts/member_expiration_date.js new file mode 100644 index 00000000000..fdcf3b115b7 --- /dev/null +++ b/app/assets/javascripts/member_expiration_date.js @@ -0,0 +1,32 @@ +(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. + // + this.MemberExpirationDate = function() { + $('.js-access-expiration-date').each(function(i, element) { + var expirationDateInput = $(element); + + function toggleClearInput() { + expirationDateInput.parent().toggleClass('has-value', !!expirationDateInput.val()); + } + + expirationDateInput.datepicker({ + dateFormat: 'yy-mm-dd', + minDate: 1, + onSelect: toggleClearInput + }); + + expirationDateInput.on('blur', toggleClearInput); + + toggleClearInput(); + + expirationDateInput.next('.js-clear-input').on('click', function(event) { + event.preventDefault(); + expirationDateInput.datepicker('setDate', null); + toggleClearInput(); + }); + }); + }; +}).call(this); |