2020-07-22 15:45:56 +08:00
|
|
|
/* global animateSpinner */
|
|
|
|
|
|
|
|
(function() {
|
2023-06-29 19:38:59 +08:00
|
|
|
$('.task-sharing-and-flows').on('click', '#viewTaskFlow', function() {
|
2020-07-27 22:36:21 +08:00
|
|
|
$('#statusFlowModal').modal('show');
|
|
|
|
});
|
|
|
|
|
2020-07-22 15:45:56 +08:00
|
|
|
$('#statusFlowModal').on('show.bs.modal', function() {
|
|
|
|
var $modalBody = $(this).find('.modal-body');
|
|
|
|
animateSpinner($modalBody);
|
|
|
|
$.get($(this).data('status-flow-url'), function(result) {
|
|
|
|
animateSpinner($modalBody, false);
|
|
|
|
$modalBody.html(result.html);
|
|
|
|
});
|
|
|
|
});
|
2023-08-23 20:02:11 +08:00
|
|
|
|
|
|
|
function checkStatusState() {
|
|
|
|
$.getJSON($('.status-flow-dropdown').data('status-check-url'), (statusData) => {
|
|
|
|
if (statusData.status_changing) {
|
|
|
|
setTimeout(() => { checkStatusState(); }, STATUS_POLLING_INTERVAL);
|
|
|
|
} else {
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function applyTaskStatusChangeCallBack() {
|
|
|
|
if ($('.status-flow-dropdown').data('status-changing')) {
|
|
|
|
setTimeout(() => { checkStatusState(); }, STATUS_POLLING_INTERVAL);
|
|
|
|
}
|
|
|
|
$('.task-sharing-and-flows').on('click', '#dropdownTaskFlowList > li[data-state-id]', function() {
|
|
|
|
var list = $('#dropdownTaskFlowList');
|
|
|
|
var item = $(this);
|
|
|
|
animateSpinner();
|
|
|
|
$.ajax({
|
|
|
|
url: list.data('link-url'),
|
|
|
|
beforeSend: function(e, ajaxSettings) {
|
|
|
|
if (item.data('beforeSend') instanceof Function) {
|
|
|
|
return item.data('beforeSend')(item, ajaxSettings)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
type: 'PATCH',
|
|
|
|
data: { my_module: { status_id: item.data('state-id') } },
|
|
|
|
success: function(result) {
|
|
|
|
animateSpinner(null, false);
|
|
|
|
location.reload();
|
|
|
|
},
|
|
|
|
error: function(e) {
|
|
|
|
animateSpinner(null, false);
|
|
|
|
if (e.status === 403) {
|
|
|
|
HelperModule.flashAlertMsg(I18n.t('my_module_statuses.update_status.error.no_permission'), 'danger');
|
|
|
|
} else if (e.status === 422) {
|
|
|
|
HelperModule.flashAlertMsg(e.responseJSON.errors, 'danger');
|
|
|
|
} else {
|
|
|
|
HelperModule.flashAlertMsg('error', 'danger');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
applyTaskStatusChangeCallBack();
|
2020-07-22 15:45:56 +08:00
|
|
|
}());
|