debian-mirror-gitlab/app/assets/javascripts/members.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
export default class Members {
constructor() {
this.addListeners();
this.initGLDropdown();
}
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
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');
}
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
initGLDropdown() {
$('.js-member-permissions-dropdown').each((i, btn) => {
const $btn = $(btn);
$btn.glDropdown({
selectable: true,
isSelectable(selected, $el) {
return !$el.hasClass('is-active');
},
2018-03-27 19:54:05 +05:30
fieldName: $btn.data('fieldName'),
2018-03-17 18:26:18 +05:30
id(selected, $el) {
return $el.data('id');
},
toggleLabel(selected, $el) {
return $el.text();
},
clicked: (options) => {
this.formSubmit(null, options.$el);
},
2017-08-17 22:00:37 +05:30
});
2018-03-17 18:26:18 +05:30
});
}
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
formSubmit(e, $el = null) {
const $this = e ? $(e.currentTarget) : $el;
const { $toggle, $dateInput } = this.getMemberListItems($this);
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
$this.closest('form').trigger('submit.rails');
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
$toggle.disable();
$dateInput.disable();
}
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
formSuccess(e) {
const { $toggle, $dateInput } = this.getMemberListItems($(e.currentTarget).closest('.member'));
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
$toggle.enable();
$dateInput.enable();
2017-08-17 22:00:37 +05:30
}
2018-03-17 18:26:18 +05:30
// eslint-disable-next-line class-methods-use-this
getMemberListItems($el) {
2018-03-27 19:54:05 +05:30
const $memberListItem = $el.is('.member') ? $el : $(`#${$el.data('elId')}`);
2018-03-17 18:26:18 +05:30
return {
$memberListItem,
$toggle: $memberListItem.find('.dropdown-menu-toggle'),
$dateInput: $memberListItem.find('.js-access-expiration-date'),
};
}
}