2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
|
|
|
|
2017-10-12 05:42:13 -04:00
|
|
|
export default class Members {
|
|
|
|
constructor() {
|
|
|
|
this.addListeners();
|
|
|
|
this.initGLDropdown();
|
|
|
|
}
|
2016-08-31 10:28:58 -04:00
|
|
|
|
2017-10-12 05:42:13 -04:00
|
|
|
addListeners() {
|
|
|
|
$('.js-member-update-control').off('change').on('change', this.formSubmit.bind(this));
|
|
|
|
$('.js-edit-member-form').off('ajax:success').on('ajax:success', this.formSuccess.bind(this));
|
|
|
|
gl.utils.disableButtonIfEmptyField('#user_ids', 'input[name=commit]', 'change');
|
|
|
|
}
|
2016-08-31 10:28:58 -04:00
|
|
|
|
2017-10-12 05:42:13 -04:00
|
|
|
initGLDropdown() {
|
|
|
|
$('.js-member-permissions-dropdown').each((i, btn) => {
|
|
|
|
const $btn = $(btn);
|
2016-12-07 10:27:14 -05:00
|
|
|
|
2017-10-12 05:42:13 -04:00
|
|
|
$btn.glDropdown({
|
|
|
|
selectable: true,
|
|
|
|
isSelectable(selected, $el) {
|
|
|
|
return !$el.hasClass('is-active');
|
|
|
|
},
|
2018-02-20 17:20:48 -05:00
|
|
|
fieldName: $btn.data('fieldName'),
|
2017-10-12 05:42:13 -04:00
|
|
|
id(selected, $el) {
|
|
|
|
return $el.data('id');
|
|
|
|
},
|
|
|
|
toggleLabel(selected, $el) {
|
|
|
|
return $el.text();
|
|
|
|
},
|
|
|
|
clicked: (options) => {
|
|
|
|
this.formSubmit(null, options.$el);
|
|
|
|
},
|
2016-12-07 10:27:14 -05:00
|
|
|
});
|
2017-10-12 05:42:13 -04:00
|
|
|
});
|
|
|
|
}
|
2016-08-31 10:28:58 -04:00
|
|
|
|
2017-10-12 05:42:13 -04:00
|
|
|
formSubmit(e, $el = null) {
|
|
|
|
const $this = e ? $(e.currentTarget) : $el;
|
|
|
|
const { $toggle, $dateInput } = this.getMemberListItems($this);
|
2016-09-05 10:11:45 -04:00
|
|
|
|
2017-10-12 05:42:13 -04:00
|
|
|
$this.closest('form').trigger('submit.rails');
|
2016-12-07 10:27:14 -05:00
|
|
|
|
2017-10-12 05:42:13 -04:00
|
|
|
$toggle.disable();
|
|
|
|
$dateInput.disable();
|
|
|
|
}
|
2016-12-07 10:27:14 -05:00
|
|
|
|
2017-10-12 05:42:13 -04:00
|
|
|
formSuccess(e) {
|
|
|
|
const { $toggle, $dateInput } = this.getMemberListItems($(e.currentTarget).closest('.member'));
|
2016-12-07 10:27:14 -05:00
|
|
|
|
2017-10-12 05:42:13 -04:00
|
|
|
$toggle.enable();
|
|
|
|
$dateInput.enable();
|
2016-08-31 10:28:58 -04:00
|
|
|
}
|
2017-10-12 05:42:13 -04:00
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
getMemberListItems($el) {
|
2018-02-20 17:20:48 -05:00
|
|
|
const $memberListItem = $el.is('.member') ? $el : $(`#${$el.data('elId')}`);
|
2016-08-31 10:28:58 -04:00
|
|
|
|
2017-10-12 05:42:13 -04:00
|
|
|
return {
|
|
|
|
$memberListItem,
|
|
|
|
$toggle: $memberListItem.find('.dropdown-menu-toggle'),
|
|
|
|
$dateInput: $memberListItem.find('.js-access-expiration-date'),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|