/**
* Modul zur Bedienung der Wiedervorlagen-Aufgaben
*/
var ResubmissionTasksUi = (function ($) {
var me = {
storage: {
dataTableName: 'resubmission_tasks',
resubmissionId: null,
$editDialog: null
},
/**
* @param {number} resubmissionId Wiedervorlagen-ID
*/
init: function (resubmissionId) {
me.storage.resubmissionId = parseInt(resubmissionId, 10);
if (isNaN(me.storage.resubmissionId) || me.storage.resubmissionId <= 0) {
throw 'Could not initialize ResubmissionTasksUi. Required parameter is missing: resubmissionId';
}
me.storage.$editDialog = $('#editResubmissionTask');
if (me.storage.$editDialog.length === 0) {
throw 'Could not initialize ResubmissionTasksUi. Required elements are missing: #editResubmissionTask';
}
me.registerEvents();
me.initEditDialog();
me.loadDataTable();
},
/**
* @return {void}
*/
registerEvents: function () {
// Aufgabe anlegen
var $taskCreateButton = $('#resubmissiontask-create');
$taskCreateButton.off('click');
$taskCreateButton.on('click', function (e) {
e.preventDefault();
me.createTask();
});
// Aufgabe bearbeiten
$(document).off('click', '.resubmissiontask-edit-button');
$(document).on('click', '.resubmissiontask-edit-button', function (e) {
e.preventDefault();
var taskId = $(this).data('taskId');
me.editTask(taskId);
});
// Aufgabe löschen
$(document).off('click', '.resubmissiontask-delete-button');
$(document).on('click', '.resubmissiontask-delete-button', function (e) {
e.preventDefault();
var taskId = $(this).data('taskId');
me.deleteTask(taskId);
});
// Aufgaben-Status ändern
$(document).off('click', '.resubmissiontask-state-button');
$(document).on('click', '.resubmissiontask-state-button', function (e) {
e.preventDefault();
var taskId = $(this).data('taskId');
var taskState = $(this).data('taskState');
if (taskState === 'open') {
me.setTaskState(taskId, 'completed');
}
if (taskState === 'completed') {
me.setTaskState(taskId, 'open');
}
});
},
/**
* @return {void}
*/
destroy: function () {
me.destroyDataTable();
if (me.storage.$editDialog !== null) {
me.storage.$editDialog.dialog('destroy');
}
me.storage.$editDialog = null;
me.storage.resubmissionId = null;
},
/**
* Öffnet den Dialog zum Anlegen einer Aufgabe
*
* @return {void}
*/
createTask: function () {
me.resetEditDialog();
$.ajax({
url: 'index.php?module=wiedervorlage&action=edit&cmd=taskstageslist',
data: {
resubmission_id: me.storage.resubmissionId
},
method: 'post',
dataType: 'json',
success: function (data) {
// Stages-Dropdown füllen
var $stageSelect = $('#resubmissiontask-requiredcompletionstage').html('');
if (data.hasOwnProperty('stages')) {
$(''
);
if (CKEDITOR.instances.hasOwnProperty('resubmissiontaskdescription')) {
CKEDITOR.instances.resubmissiontaskdescription.setData('');
}
},
/**
*
*
* @return {void}
*/
loadDataTable: function () {
me.fetchDataTableHtml()
.then(
function () {
// DataTable-Daten laden und anzeigen
me.initDataTable();
},
function () {
// Fehler beim Abrufen der DataTable-Einstellungen
alert('Fehler beim Abrufen der Datatable \'resubmission_tasks\'.');
}
);
},
/**
* DataTable-HTML-Tabelle + Settings-JSON laden
*
* @return {jqXHR} jQuery jqXHR-Objekt
*/
fetchDataTableHtml: function () {
if (me.storage.resubmissionId === null) {
throw 'Could not initialize ResubmissionTasksUi. Required settings are missing: resubmissionId';
}
return $.ajax({
url: 'index.php?module=wiedervorlage&action=edit&cmd=tasktablehtml',
data: { 'id': me.storage.resubmissionId },
type: 'GET',
dataType: 'html',
success: function (htmlResult) {
$('#resubmission-tasks-datatable').html(htmlResult);
}
});
},
/**
* @return {void}
*/
initDataTable: function () {
DataTableHelper.initDataTable(me.storage.dataTableName);
},
/**
* @return {void}
*/
reloadDataTable: function () {
DataTableHelper.refreshDataTable(me.storage.dataTableName);
},
/**
* @return {void}
*/
destroyDataTable: function () {
DataTableHelper.destroyDataTable(me.storage.dataTableName);
}
};
return {
init: me.init,
destroy: me.destroy,
editTask: me.editTask
};
})(jQuery);