Commit dd4784f3 authored by Sean McGivern's avatar Sean McGivern

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.
parent c90d167b
...@@ -126,6 +126,7 @@ ...@@ -126,6 +126,7 @@
new UsersSelect(); new UsersSelect();
break; break;
case 'projects:project_members:index': case 'projects:project_members:index':
new MemberExpirationDate();
new ProjectMembers(); new ProjectMembers();
new UsersSelect(); new UsersSelect();
break; break;
......
(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);
...@@ -4,17 +4,7 @@ ...@@ -4,17 +4,7 @@
$('li.project_member').bind('ajax:success', function() { $('li.project_member').bind('ajax:success', function() {
return $(this).fadeOut(); return $(this).fadeOut();
}); });
$('.js-project-members-page').on('focus', '.js-access-expiration-date', function() {
$(this).datepicker({
dateFormat: 'yy-mm-dd',
minDate: 1
});
});
} }
return ProjectMembers; return ProjectMembers;
})(); })();
}).call(this); }).call(this);
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
%strong= link_to "here", help_page_path("user/permissions"), class: "vlink" %strong= link_to "here", help_page_path("user/permissions"), class: "vlink"
.form-group .form-group
= label_tag :expires_at, 'Access expiration date', class: 'control-label' = f.label :expires_at, 'Access expiration date', class: 'control-label'
.col-sm-10 .col-sm-10
.clearable-input
= text_field_tag :expires_at, nil, class: 'form-control js-access-expiration-date', placeholder: 'Select access expiration date' = text_field_tag :expires_at, nil, class: 'form-control js-access-expiration-date', placeholder: 'Select access expiration date'
.help-block %i.clear-icon.js-clear-input
Leave it empty if you do not want this user's access to expire.
.form-actions .form-actions
= f.submit 'Add users to project', class: "btn btn-create" = f.submit 'Add users to project', class: "btn btn-create"
...@@ -77,11 +77,17 @@ ...@@ -77,11 +77,17 @@
- if show_roles - if show_roles
.edit-member.hide.js-toggle-content .edit-member.hide.js-toggle-content
%br %br
= form_for member, remote: true do |f| = form_for member, remote: true, html: { class: 'form-horizontal' } do |f|
.prepend-top-10 .form-group
= label_tag :expires_at, 'Project access', class: 'control-label'
.col-sm-10
= f.select :access_level, options_for_select(member.class.access_level_roles, member.access_level), {}, class: 'form-control' = f.select :access_level, options_for_select(member.class.access_level_roles, member.access_level), {}, class: 'form-control'
- if member.is_a?(ProjectMember) - if member.is_a?(ProjectMember)
.prepend-top-10 .form-group
= f.text_field :expires_at, class: 'form-control js-access-expiration-date', placeholder: 'Access expiration date', id: "member_expires_at_#{member.id}" = label_tag :expires_at, 'Access expiration date', class: 'control-label'
.col-sm-10
.clearable-input
= f.text_field :expires_at, class: 'form-control js-access-expiration-date', placeholder: 'Select access expiration date', id: "member_expires_at_#{member.id}"
%i.clear-icon.js-clear-input
.prepend-top-10 .prepend-top-10
= f.submit 'Save', class: 'btn btn-save btn-sm' = f.submit 'Save', class: 'btn btn-save btn-sm'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment