2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2019-12-21 20:55:43 +05:30
|
|
|
import '~/gl_dropdown';
|
2020-05-24 23:13:21 +05:30
|
|
|
import { escape } from 'lodash';
|
2019-07-31 22:56:46 +05:30
|
|
|
import { __ } from '~/locale';
|
2018-05-01 15:08:00 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
function isValidProjectId(id) {
|
|
|
|
return id > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
class SidebarMoveIssue {
|
|
|
|
constructor(mediator, dropdownToggle, confirmButton) {
|
|
|
|
this.mediator = mediator;
|
|
|
|
|
|
|
|
this.$dropdownToggle = $(dropdownToggle);
|
|
|
|
this.$confirmButton = $(confirmButton);
|
|
|
|
|
|
|
|
this.onConfirmClickedWrapper = this.onConfirmClicked.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this.initDropdown();
|
|
|
|
this.addEventListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
this.removeEventListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
initDropdown() {
|
|
|
|
this.$dropdownToggle.glDropdown({
|
|
|
|
search: {
|
|
|
|
fields: ['name_with_namespace'],
|
|
|
|
},
|
|
|
|
showMenuAbove: true,
|
|
|
|
selectable: true,
|
|
|
|
filterable: true,
|
|
|
|
filterRemote: true,
|
|
|
|
multiSelect: false,
|
|
|
|
// Keep the dropdown open after selecting an option
|
|
|
|
shouldPropagate: false,
|
|
|
|
data: (searchTerm, callback) => {
|
2018-12-13 13:39:08 +05:30
|
|
|
this.mediator
|
|
|
|
.fetchAutocompleteProjects(searchTerm)
|
2018-03-17 18:26:18 +05:30
|
|
|
.then(callback)
|
2019-07-31 22:56:46 +05:30
|
|
|
.catch(
|
|
|
|
() => new window.Flash(__('An error occurred while fetching projects autocomplete.')),
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
|
|
|
renderRow: project => `
|
|
|
|
<li>
|
|
|
|
<a href="#" class="js-move-issue-dropdown-item">
|
2020-05-24 23:13:21 +05:30
|
|
|
${escape(project.name_with_namespace)}
|
2018-03-17 18:26:18 +05:30
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
`,
|
2018-12-13 13:39:08 +05:30
|
|
|
clicked: options => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const project = options.selectedObj;
|
|
|
|
const selectedProjectId = options.isMarking ? project.id : 0;
|
|
|
|
this.mediator.setMoveToProjectId(selectedProjectId);
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
this.$confirmButton.prop('disabled', !isValidProjectId(selectedProjectId));
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addEventListeners() {
|
|
|
|
this.$confirmButton.on('click', this.onConfirmClickedWrapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
removeEventListeners() {
|
|
|
|
this.$confirmButton.off('click', this.onConfirmClickedWrapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
onConfirmClicked() {
|
|
|
|
if (isValidProjectId(this.mediator.store.moveToProjectId)) {
|
2018-12-13 13:39:08 +05:30
|
|
|
this.$confirmButton.disable().addClass('is-loading');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
this.mediator.moveIssue().catch(() => {
|
2019-07-31 22:56:46 +05:30
|
|
|
window.Flash(__('An error occurred while moving the issue.'));
|
2018-12-13 13:39:08 +05:30
|
|
|
this.$confirmButton.enable().removeClass('is-loading');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SidebarMoveIssue;
|