From 57e2687de4c4c3005dfe3056f800d32dada2e324 Mon Sep 17 00:00:00 2001 From: Matthias Opitz Date: Wed, 18 Dec 2024 15:48:39 +0000 Subject: [PATCH] trying amd --- amd/src/coursework.js | 330 +++++++++++++ amd/src/coursework_edit.js | 967 +++++++++++++++++++++++++++++++++++++ coursework.js | 515 ++++++++++---------- module.js | 2 + view.php | 4 +- 5 files changed, 1561 insertions(+), 257 deletions(-) create mode 100644 amd/src/coursework.js create mode 100644 amd/src/coursework_edit.js diff --git a/amd/src/coursework.js b/amd/src/coursework.js new file mode 100644 index 0000000..6fb3ffc --- /dev/null +++ b/amd/src/coursework.js @@ -0,0 +1,330 @@ +define('mod_coursework/coursework', ['jquery', 'core/log'], function($) { + return { + init: function() { + var table_obj_list = []; +// var is_responsive = false; + var tableobject = 0; + + $(document).ready(function() { + var langmessage = JSON.parse($('#element_lang_messages').attr('data-lang')); + var base_url = window.location.origin + '/mod/coursework/datatables/js/'; + + require.config({ + paths: { + 'datatables.net': base_url + 'jquery.datatables', + 'datatables.searchpanes': base_url + 'datatables.searchpanes', + 'datatables.buttons': base_url + 'datatables.buttons', + 'datatables.select': base_url + 'datatables.select', + 'datatables.responsive': base_url + 'datatables.responsive.min', + } + }); + + require(['datatables.net'], function(DataTable) { + + // Ensure jQuery access. + if (!$.fn.dataTable) { + $.fn.dataTable = DataTable; + } + + $.fn.DataTable = DataTable; + $.fn.DataTableSettings = DataTable.settings; + $.fn.dataTableExt = DataTable.ext; + DataTable.$ = $; + $.fn.DataTable = function(opts) { + return $(this).dataTable(opts).api(); + }; + + $.fn.dataTable.Api.register('row().show()', function() { + var page_info = this.table().page.info(); + // Get row index. + var new_row_index = this.index(); + // Row position. + var row_position = this.table() + .rows({search: 'applied'})[0] + .indexOf(new_row_index); + // Already on right page ? + if ((row_position >= page_info.start && row_position < page_info.end) || row_position < 0) { + // Return row object. + return this; + } + // Find page number. + var page_to_display = Math.floor(row_position / this.table().page.len()); + // Go to that page. + this.table().page(page_to_display); + // Return row object. + return this; + }); + require(['datatables.searchpanes', + 'datatables.select', + 'datatables.buttons', + 'datatables.responsive'], + function() { + if (isMobileDevice() && $(window).width() < 768) { +// is_responsive = true; + initDatatable(); + + $('.datatabletest').on('order.dt', function() { + $('.submissionrowmulti').removeClass("shown"); + }); + } else { + initDatatable(); + } + }); + }); + + /** + * + * @param {string} tableid + */ + function background_load_table(tableid) { + var tableelement = $('#' + tableid); + var wrapperelement = tableelement.parent('.dataTables_wrapper'); + var paginationelement = wrapperelement.find('.dataTables_paginate'); + tableobject = table_obj_list[tableid]; + var submissionswrapper = tableelement.parent('.dataTables_wrapper'); + + // Hide buttons. + wrapperelement.find('.dataTables_paginate, .dataTables_info, .dataTables_length,' + + ' .dataTables_filter').css('visibility', 'hidden'); + wrapperelement.find('thead, .dt-button').each(function() { + var me = $(this); + me.css('pointer-events', 'none'); + if (me.hasClass('dt-button')) { + me.find('span').html(' ' + me.find('span').html()); + } + }); +// console.log(submissionswrapper); + + $('
' + + ' ' + langmessage.loadingpagination + '
'). + insertBefore(submissionswrapper); + $('
' + + langmessage.loadingpagination + '
').insertAfter(paginationelement); + $('').insertBefore(wrapperelement. + find('.dt-button > span')); + + // Prepare params for ajax request. + var params = { + group: tableelement.attr('group'), + perpage: tableelement.attr('perpage'), + sortby: tableelement.attr('sortby'), + sorthow: tableelement.attr('sorthow'), + firstnamealpha: tableelement.attr('firstnamealpha'), + lastnamealpha: tableelement.attr('lastnamealpha'), + groupnamealpha: tableelement.attr('groupnamealpha'), + substatus: tableelement.attr('substatus'), + unallocated: tableelement.attr('unallocated'), + courseworkid: tableelement.attr('courseworkid') + }; + + $.ajax({ + url: '/mod/coursework/actions/ajax/datatable/grading.php', + type: 'POST', + data: params + }).done(function(response) { +// console.log('test remove 1'); + $("#datatable_top_loading_message").remove(); + tableobject.rows.add($(response)).draw(false); + wrapperelement.find('.submission-loading').remove(); + }).fail(function() {}).always(function() { + // Show buttons. + wrapperelement.find('.pagination-loading').remove(); + wrapperelement.find('.submission-loading').remove(); + wrapperelement.find('thead, .dt-button').css('pointer-events', 'auto'); + wrapperelement.find('.dataTables_paginate, .dataTables_info, .dataTables_length,' + + ' .dataTables_filter').css('visibility', 'visible'); + }); + } + + /** + * + */ + function initDatatable() { + $(".datatabletest").each(function() { + // Class that determines whether all data for the databale has been full loaded. + var fullloaded = $(this).hasClass('full-loaded'); + + table_obj_list[$(this).attr('id')] = $(this).DataTable({ + 'order': [], + stateSave: true, + language: { + searchPanes: { + collapse: {"0": $('#search_pane_button').val() || 'Filter', + _: ($('#search_pane_button').val() || 'Filter') + ' (%d)'} + } + }, + buttons: [ + + ], + dom: 'Blfrtip', + columnDefs: [ + { + searchPanes: {show: false}, + targets: ['studentname', 'addition-multiple-button'], + bSortable: false + }, + { + searchPanes: {show: false}, + targets: ['lastname_cell', 'firstname_cell', 'tableheadpersonaldeadline', + 'tableheaddate', 'tableheadfilename', 'tableheadplagiarismalert', + 'plagiarism', 'agreedgrade', 'feedbackandgrading', 'provisionalgrade', + 'tableheadmoderationagreement'] + }, + { + searchPanes: { + show: true, + header: $('#search_pane_group').val() || 'Group', + }, + targets: 'tableheadgroups', + }, + { + searchPanes: { + show: true, + header: $('#search_pane_status').val() || 'Status', + getFullText: true, + }, + targets: 'tableheadstatus', + }, + { + searchPanes: { + show: true, + header: $('#search_pane_firstname').val() || 'First Name Initial', + }, + targets: 'firstname_letter_cell', + }, + { + searchPanes: { + show: true, + header: $('#search_pane_lastname').val() || 'Last Name Initial', + }, + targets: 'lastname_letter_cell', + }, + {"visible": false, "targets": ['lastname_letter_cell', 'firstname_letter_cell', + 'lastname_cell', 'firstname_cell']} + ], + select: { + style: 'multi', + selector: '.select-checkbox' + }, + stateSaveParams: function(settings, data) { + data.columns = []; + } + + }); + + if (!fullloaded) { + background_load_table($(this).attr('id')); + } + }); + } + + if (isMobileDevice() && $(window).width() < 768) { + // For small screens. + var table = $('.datatabletest tbody').on('click', 'td.details-control', function() { + var tr = $(this).closest("tr"); + var row_id = tr.attr('id').replace('allocatable_', ''); + var table_id = 'assessorfeedbacktable_' + row_id; + + if ($(tr).next('tr.row_assessors').length > 0) { + $(tr).next('tr.row_assessors').remove(); + } else { + // As originally written this code created a new table with duplicate IDs. + // See comment on CTP-3783 below for more info. + const oldTable = $('#' + table_id); + const newRow = $( + '' + ); + oldTable.addClass('assessors_expanded').css('width', '95%').appendTo(newRow.find('td')); + } + $(tr).toggleClass('shown'); + }); + } else { + // Add event listener for opening and closing details. + $('.datatabletest tbody').on('click', 'td.details-control', function() { + var tr = $(this).closest("tr"); + var table_key = $(this).closest('.datatabletest').attr('id'); + var table = table_obj_list[table_key]; + if (table) { + var row = table.row(tr); + + var row_id = tr.attr('id').replace('allocatable_', ''); + var table_id = 'assessorfeedbacktable_' + row_id; + const oldTable = $('#' + table_id); + const subRow = $('#sub-row-' + tr.data('allocatable')); + if (oldTable.length) { + if (subRow.length === 0) { + // Open this row - create as sub-row. + // CTP-3783 As originally written this code cloned the old table and + // added its HTML again to the new row. + // This meant that we had 2 x tables do duplicate IDs, with the old table hidden and + // new one visible. + // Then multiple behat tests failed when trying to click the hidden feedback button + // not visible one. + const newRow = $( + '' + ); + oldTable.addClass('assessors_expanded').css('width', '95%').appendTo(newRow.find('td')); + oldTable.show(); + row.child(newRow).show(); + tr.addClass('shown'); + } else { + // Sub-row already exists. + if (subRow.css('display') === 'none') { + subRow.show(); + tr.addClass('shown'); + } else { + // This row is already open - close it. + tr.removeClass('shown'); + subRow.hide(); + } + } + } else { + // No need to move table - just open/close. + if (subRow.css('display') === 'none') { + subRow.show(); + tr.addClass('shown'); + } else { + // This row is already open - close it. + subRow.hide(); + tr.removeClass('shown'); + } + } + } + }); + } + + $('.datatabletest').on('click', '.splitter-firstname, .splitter-lastname, .splitter-email', function(event) { + event.preventDefault(); + var node = $(event.target), + isAscending = node.hasClass('sorting_asc'), + currentsort = 'asc', + sortby = 'desc'; + if (!isAscending) { + currentsort = 'desc'; + sortby = 'asc'; + } + var table_id = $(this).closest('.datatabletest').attr('id'); + table = table_obj_list[table_id]; + var headerclass = $(this).hasClass('splitter-firstname') ? 'firstname_cell' : 'lastname_cell'; + headerclass = $(this).hasClass('splitter-email') ? 'email_cell' : headerclass; +// console.log(headerclass); + var sortColumn = table.column('.' + headerclass).index(); + table.order([sortColumn, sortby]).draw(); + + node.addClass('sorting_' + sortby).removeClass('sorting sorting_' + currentsort); + node.parent().removeClass('sorting sorting_asc sorting_desc'); + node.siblings().removeClass('sorting_asc sorting_desc').addClass('sorting'); + }); + }); + + /** + * + */ + function isMobileDevice() { + return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)); + } + } + }; +}); + diff --git a/amd/src/coursework_edit.js b/amd/src/coursework_edit.js new file mode 100644 index 0000000..2ec943c --- /dev/null +++ b/amd/src/coursework_edit.js @@ -0,0 +1,967 @@ +define('mod_coursework/coursework_edit', ['jquery', 'core/log'], function($) { + return { + init: function() { +// Add the init function: + /** + * + * @param {object} row + * @returns {boolean} + */ + function compare_row(row) { + return (this == row.DT_RowId); + } + + + var now = new Date(); + var extension_form_change = false; + window.addEventListener('beforeunload', (table_obj_list) => { + if (table_obj_list) { + for (var table_id in table_obj_list) { + table_obj_list[table_id].state.save(); + } + } + }); + $(document).ready(function () { + /** + * + * @param {object} tr + */ + function log_datatable_navigate(tr) { + var row_id = tr.attr('id'); + var tableid = tr.closest('table').attr('id'); + var key = 'datatable_navigate_' + window.location.href + tableid; + localStorage.setItem(key, row_id); + } + + /* plagiarism flag */ + $('.datatabletest').on('click', '.new_plagiarism_flag', function() { + log_datatable_navigate($(this).closest('tr')); + }); + + $('.datatabletest').on('click', '.edit_plagiarism_flag', function() { + log_datatable_navigate($(this).closest('tr')); + }); + + /* feedback */ + $('.datatabletest').on('click', '.new_final_feedback', function() { + log_datatable_navigate($(this).closest('tr')); + }); + + $('.datatabletest').on('click', '.edit_final_feedback', function() { + log_datatable_navigate($(this).closest('tr')); + }); + + $('.datatabletest').on('click', '.show_feedback', function() { + log_datatable_navigate($(this).closest('tr')); + }); + + /* assessor feedback */ + $('.datatabletest').on('click', '.assessor_feedback_grade .new_feedback', function() { + log_datatable_navigate($(this).closest('td.assessors').closest('table.assessors').closest('tr').prev()); + }); + + $('.datatabletest').on('click', '.assessor_feedback_grade .show_feedback', function() { + log_datatable_navigate($(this).closest('td.assessors').closest('table.assessors').closest('tr').prev()); + }); + + $('.datatabletest').on('click', '.assessor_feedback_grade .edit_feedback', function() { + log_datatable_navigate($(this).closest('td.assessors').closest('table.assessors').closest('tr').prev()); + }); + + /* deadline extension */ + $('.datatabletest').on('click', '.new_deadline_extension', function() { + log_datatable_navigate($(this).closest('tr')); + }); + + $('.datatabletest').on('click', '.edit_deadline_extension', function() { + log_datatable_navigate($(this).closest('tr')); + }); + + /* submission */ + $('.datatabletest').on('click', '.new_submission', function() { + log_datatable_navigate($(this).closest('tr')); + }); + + // Prepare Message + var datatables_lang_messages = JSON.parse($('#datatables_lang_messages').attr('data-lang')); + + /** + * Personal Deadline + */ + $('.datatabletest').on('click', '.edit_personal_deadline',function (e) { + e.preventDefault(); + var parent = $(this).closest('.personal_deadline_cell'); + parent.children('.show_personal_dealine').addClass('display-none'); + var change_form = parent.children('.show_edit_personal_dealine'); + var data_get = $(this).attr('data-get'); + var data_time = $(this).attr('data-time-iso-8601'); + if (change_form.html().length === 1) { + var form = ''; + form += '
'; + form += '
'; + $(change_form).html(form); + } + $(change_form).removeClass('display-none'); + }); + + $('.datatabletest').on('click', '.cancel-personal-deadline', function (e) { + e.preventDefault(); + $(this).closest('.show_edit_personal_dealine').addClass('display-none'); + $(this).closest('.personal_deadline_cell').children('.show_personal_dealine').removeClass('display-none'); + }); + + $('.datatabletest').on('click', '.approve-personal-deadline', function (e) { + e.preventDefault(); + var deadline = $(this); + var data_get = $(deadline).attr('data-get'); + var value = $(deadline).closest('.show_edit_personal_dealine').children('.input-personal-deadline').val(); + var input_date = new Date(value); + if (input_date <= Date.parse(now)) { + (new M.core.alert({ + message: datatables_lang_messages.alert_validate_deadline.replace(/\_/g, ' '), + title: datatables_lang_messages.notification_info, + })).show(); + return 0; + } + + var url = datatables_lang_messages.url_root + "/mod/coursework/actions/personal_deadline.php"; + var param = JSON.parse(data_get); + param.personal_deadline_time = value; + + $.ajax({ + type: "POST", + url: url, + data: param, + beforeSend: function () { + $('html, body').css("cursor", "wait"); + $(self).prev('img').css('visibility', 'visible'); + }, + success: function (response, table_obj_list) { + $('html, body').css("cursor", "auto"); + var data_response = JSON.parse(response); + if (data_response.error == 1) { + (new M.core.alert({ + message: data_response.message, + title: datatables_lang_messages.notification_info, + })).show(); + } else { + var parent = $(deadline).closest('.personal_deadline_cell'); + $(parent).attr('data-order', data_response.timestamp); + var table = table_obj_list[Object.keys(table_obj_list)[0]]; + table.row('#' + $(parent).closest('tr').attr('id')).invalidate(); + + $(parent).children('.show_personal_dealine').children('.content_personal_deadline'). + html(data_response.time); + $(parent).children('.show_edit_personal_dealine').addClass('display-none'); + $(parent).children('.show_personal_dealine').removeClass('display-none'); + (new M.core.alert({ + message: datatables_lang_messages.alert_personaldeadline_save_successful.replace(/\_/g, ' '), + title: datatables_lang_messages.notification_info, + })).show(); + } + }, + error: function () { + $('html, body').css("cursor", "auto"); + }, + complete: function () { + $('html, body').css("cursor", "auto"); + } + }); + + }); + + /*************************** + * Extensions + */ + + /** + * Add new extension + */ + $('.datatabletest').on('click', '.new_deadline_extension', function (e) { + e.preventDefault(); + var data_name = $(this).attr('data-name'); + var data_params = JSON.parse($(this).attr('data-params')); + var data_time = JSON.parse($(this).attr('data-time')); + var current_rowid = $(this).closest('tr').attr('id'); + extension_new_change_data_form(data_name, data_params, data_time, current_rowid); + $('#modal-ajax').modal('show'); + }); + + /** + * Edit extensions + */ + $('.datatabletest').on('click', '.edit_deadline_extension', function (e) { + + e.preventDefault(); + var data_name = $(this).attr('data-name'); + var data_params = JSON.parse($(this).attr('data-params')); + var data_time = JSON.parse($(this).attr('data-time')); + var current_rowid = $(this).closest('tr').attr('id'); + extension_edit_change_data_form(data_name, data_params, data_time, current_rowid); + $('#modal-ajax').modal('show'); + }); + + /** + * Submit save extension + */ + $('.modal-footer').on('click', '#extension-submit', function (e) { + e.preventDefault(); + var params = {}; + params.allocatabletype = $('#extension-allocatabletype').val(); + params.allocatableid = $('#extension-allocatableid').val(); + params.courseworkid = $('#extension-courseworkid').val(); + params.id = $('#extension-id').val(); + params.extended_deadline = $('#extension-extend-deadline').val(); + params.editor = $('#extension-time-content').html(); + params.text = $('#id_extra_information').val(); + params.submissionid = $('#extension-submissionid').val(); + params.pre_defined_reason = $('#extension-reason-select').val(); + params.requesttype = 'submit'; + var current_rowid = $('#button-id').val(); + var url = datatables_lang_messages.url_root; + $.ajax({ + type: "POST", + url: url + "/mod/coursework/actions/ajax/deadline_extension/submit.php", + data: params, + beforeSend: function () { + $('html, body').css("cursor", "wait"); + $('.modal-footer').children('img').css('visibility', 'visible'); + }, + success: function (response, table_obj_list) { + var data_response = JSON.parse(response); + $('html, body').css("cursor", "auto"); + $('.modal-footer').children('img').css('visibility', 'hidden'); + if (data_response.error == 1) { + (new M.core.alert({ + message: data_response.messages, + title: datatables_lang_messages.notification_info, + })).show(); + } else { + if (Object.keys(table_obj_list).length > 0) { + // Get the first datatable object. + var table = table_obj_list[Object.keys(table_obj_list)[0]]; + alert('gnupf'); + window.console.log('--------------'); + window.console.log(table); + window.console.log('--------------'); + var current_row_data = table.row('#' + current_rowid).data(); + var submissiondateindex = table.column('.tableheaddate').index(); + var current_moderation_cell_data = data_response.content; + current_row_data[submissiondateindex] = current_moderation_cell_data; + var table_row = table.row('#' + current_rowid); + table_row.data(current_row_data); + var dom_row = $('#' + current_rowid); + dom_row.find('.time_submitted_cell').attr('data-order', + current_moderation_cell_data['@data-order']); + dom_row.find('.edit_personal_deadline').remove(); + table_row.invalidate(); + $('#extension-id').val(data_response.data.id); + } + + change__status_extension_submit_button(true); + save_extension_form_data(); + + (new M.core.alert({ + message: datatables_lang_messages.alert_extension_save_successful.replace(/\_/g, ' '), + title: datatables_lang_messages.notification_info, + })).show(); + } + }, + error: function () { + $('html, body').css("cursor", "auto"); + }, + complete: function () { + $('html, body').css("cursor", "auto"); + } + }); + }); + + + /** + * Function close button + */ + $('#modal-ajax').on('hide.bs.modal', function() { + var self = this; + if(is_data_extension_form_change()) { + var confirm = new M.core.confirm({ + title: datatables_lang_messages.notification_leave_form_title.replace(/\_/g, ' '), + question: datatables_lang_messages.notification_leave_form_message.replace(/\_/g, ' '), + yesLabel: datatables_lang_messages.notification_yes_label, + noLabel: datatables_lang_messages.notification_no_label, + }); + + confirm.on('complete-yes',function() { + save_extension_form_data(); + confirm.hide(); + confirm.destroy(); + $(self).modal('hide'); + }); + + confirm.on('complete-no',function() { + confirm.hide(); + confirm.destroy(); + return false; + }); + + confirm.show(); + return false; + } + return true; + }); + + /** + * Function next button + */ + $('.modal-footer').on('click', '#extension-next', function (e, table_obj_list) { + e.preventDefault(); + + if (is_data_extension_form_change()) { + var confirm = new M.core.confirm({ + title: datatables_lang_messages.notification_leave_form_title.replace(/\_/g, ' '), + question: datatables_lang_messages.notification_leave_form_message.replace(/\_/g, ' '), + yesLabel: datatables_lang_messages.notification_yes_label, + noLabel: datatables_lang_messages.notification_no_label, + }); + + confirm.on('complete-yes', function(table_obj_list) { + confirm.hide(); + confirm.destroy(); + if (Object.keys(table_obj_list).length > 0) { + + var prev_rowid = $('#button-id').val(); + + // Get the first datatable object. + var table = table_obj_list[Object.keys(table_obj_list)[0]]; + + var prev_row_index = table.row('#' + prev_rowid).index(); + + + var current_row_index = prev_row_index + 1; + + if (table.row(current_row_index)) { + var current_row_data = table.row(current_row_index).data(); + if (current_row_data) { + var current_rowid = table.row(current_row_index).id(); + + var submissiondateindex = table.column('.tableheaddate').index(); + var current_cell_data = current_row_data[submissiondateindex]; + if (current_cell_data) { + var tmp_node = $('
').html(current_cell_data.display); + var submisiondate = $(tmp_node).find('.new_deadline_extension'); + if (submisiondate.length > 0) { + var data_params = JSON.parse(submisiondate.attr('data-params')); + var data_name = submisiondate.attr('data-name'); + var data_time = JSON.parse(submisiondate.attr('data-time')); + extension_new_change_data_form(data_name, data_params, data_time, current_rowid); + } else { + submisiondate = $(tmp_node).find('.edit_deadline_extension'); + var data_params = JSON.parse(submisiondate.attr('data-params')); + var data_name = submisiondate.attr('data-name'); + var data_time = JSON.parse(submisiondate.attr('data-time')); + extension_edit_change_data_form(data_name, data_params, data_time, current_rowid); + } + } + } + else { + $('#extension-next').prop('disabled', true); + (new M.core.alert({ + message: datatables_lang_messages.alert_no_extension.replace(/\_/g, ' '), + title: datatables_lang_messages.notification_info, + })).show(); + } + } + } + }); + + confirm.on('complete-no', function () { + confirm.hide(); + confirm.destroy(); + + }); + + confirm.show(); + } else { + if (Object.keys(table_obj_list).length > 0) { + + var prev_rowid = $('#button-id').val(); + + // Get the first datatable object. + var table = table_obj_list[Object.keys(table_obj_list)[0]]; + + var ordereddata = table.rows( { order: 'applied', search: 'applied' } ).data().toArray(); + var prev_row_index = ordereddata.findIndex(compare_row, prev_rowid); + + + var current_row_index = prev_row_index + 1; + + if (table.row(current_row_index)) { + var current_row_data = ordereddata[current_row_index]; + if (typeof current_row_data != 'undefined') { + var current_rowid = current_row_data.DT_RowId; + + var submissiondateindex = table.column('.tableheaddate').index(); + var current_cell_data = current_row_data[submissiondateindex]; + if (current_cell_data) { + var tmp_node = $('
').html(current_cell_data.display); + var submisiondate = $(tmp_node).find('.new_deadline_extension'); + if (submisiondate.length > 0) { + var data_params = JSON.parse(submisiondate.attr('data-params')); + var data_name = submisiondate.attr('data-name'); + var data_time = JSON.parse(submisiondate.attr('data-time')); + extension_new_change_data_form(data_name, data_params, data_time, current_rowid); + } else { + submisiondate = $(tmp_node).find('.edit_deadline_extension'); + var data_params = JSON.parse(submisiondate.attr('data-params')); + var data_name = submisiondate.attr('data-name'); + var data_time = JSON.parse(submisiondate.attr('data-time')); + extension_edit_change_data_form(data_name, data_params, data_time, current_rowid); + } + } + } + else { + $('#extension-next').prop('disabled', true); + (new M.core.alert({ + message: datatables_lang_messages.alert_no_mitigation.replace(/\_/g, ' '), + title: datatables_lang_messages.notification_info, + })).show(); + } + } + } + } + + + }); + + /** + * Function back button + */ + $('.modal-footer').on('click', '#extension-back', function (e, table_obj_list) { + e.preventDefault(); + if (is_data_extension_form_change()) { + var confirm = new M.core.confirm({ + title: datatables_lang_messages.notification_leave_form_title.replace(/\_/g, ' '), + question: datatables_lang_messages.notification_leave_form_message.replace(/\_/g, ' '), + yesLabel: datatables_lang_messages.notification_yes_label, + noLabel: datatables_lang_messages.notification_no_label, + }); + + confirm.on('complete-yes', function (table_obj_list) { + confirm.hide(); + confirm.destroy(); + if (Object.keys(table_obj_list).length > 0) { + + var prev_rowid = $('#button-id').val(); + + // Get the first datatable object. + var table = table_obj_list[Object.keys(table_obj_list)[0]]; + + var prev_row_index = table.row('#' + prev_rowid).index(); + + + var current_row_index = prev_row_index - 1; + + if (table.row(current_row_index)) { + var current_row_data = table.row(current_row_index).data(); + if (current_row_data) { + var current_rowid = table.row(current_row_index).id(); + + var submissiondateindex = table.column('.tableheaddate').index(); + var current_cell_data = current_row_data[submissiondateindex]; + if (current_cell_data) { + var tmp_node = $('
').html(current_cell_data.display); + var submisiondate = $(tmp_node).find('.new_deadline_extension'); + if (submisiondate.length > 0) { + var data_params = JSON.parse(submisiondate.attr('data-params')); + var data_name = submisiondate.attr('data-name'); + var data_time = JSON.parse(submisiondate.attr('data-time')); + extension_new_change_data_form(data_name, data_params, data_time, current_rowid); + } else { + submisiondate = $(tmp_node).find('.edit_deadline_extension'); + var data_params = JSON.parse(submisiondate.attr('data-params')); + var data_name = submisiondate.attr('data-name'); + var data_time = JSON.parse(submisiondate.attr('data-time')); + extension_edit_change_data_form(data_name, data_params, data_time, current_rowid); + } + } + } + else { + $('#extension-back').prop('disabled', true); + (new M.core.alert({ + message: datatables_lang_messages.alert_no_mitigation.replace(/\_/g, ' '), + title: datatables_lang_messages.notification_info, + })).show(); + } + } + } + }); + + confirm.on('complete-no', function () { + confirm.hide(); + confirm.destroy(); + }); + + confirm.show(); + } else { + if (Object.keys(table_obj_list).length > 0) { + + var prev_rowid = $('#button-id').val(); + + // Get the first datatable object. + var table = table_obj_list[Object.keys(table_obj_list)[0]]; + + var ordereddata = table.rows( { order: 'applied', search: 'applied' } ).data().toArray(); + var prev_row_index = ordereddata.findIndex(compare_row, prev_rowid); + + + var current_row_index = prev_row_index - 1; + + if (table.row(current_row_index)) { + var current_row_data = ordereddata[current_row_index]; + if (typeof current_row_data != 'undefined') { + var current_rowid = current_row_data.DT_RowId; + + var submissiondateindex = table.column('.tableheaddate').index(); + var current_cell_data = current_row_data[submissiondateindex]; + if (current_cell_data) { + var tmp_node = $('
').html(current_cell_data.display); + var submisiondate = $(tmp_node).find('.new_deadline_extension'); + if (submisiondate.length > 0) { + var data_params = JSON.parse(submisiondate.attr('data-params')); + var data_name = submisiondate.attr('data-name'); + var data_time = JSON.parse(submisiondate.attr('data-time')); + extension_new_change_data_form(data_name, data_params, data_time, current_rowid); + } else { + submisiondate = $(tmp_node).find('.edit_deadline_extension'); + var data_params = JSON.parse(submisiondate.attr('data-params')); + var data_name = submisiondate.attr('data-name'); + var data_time = JSON.parse(submisiondate.attr('data-time')); + extension_edit_change_data_form(data_name, data_params, data_time, current_rowid); + } + } + } + else { + $('#extension-back').prop('disabled', true); + (new M.core.alert({ + message: datatables_lang_messages.alert_no_mitigation.replace(/\_/g, ' '), + title: datatables_lang_messages.notification_info, + })).show(); + } + } + } + } + + + }); + + /** + * + * @param {string} data_name + * @param {object} data_params + * @param {string} data_time + * @param {string} current_rowid + */ + function extension_edit_change_data_form(data_name, data_params, data_time, current_rowid) { + var title = 'Editing the extension for ' + data_name; + var time_content = 'Default deadline: ' + data_time.time_content; + $('#extension-modal-title').html(title); + $('#form-extension').find('input[type=hidden]').val(""); + $('#form-extension').find('textarea').val(""); + $('#button-id').val(current_rowid); + $('#extension-submissionid').val(data_params.submissionid); + $('#extension-name').val(data_name); + data_params.requesttype = 'edit'; + var url = datatables_lang_messages.url_root; + $.ajax({ + type: "GET", + url: url + "/mod/coursework/actions/ajax/deadline_extension/edit.php", + data: data_params, + beforeSend: function () { + change__status_extension_submit_button(true); + $('html, body').css("cursor", "wait"); + $('.modal-footer').children('img').css('visibility', 'visible'); + }, + success: function (response) { + var data_response = JSON.parse(response); + $('html, body').css("cursor", "auto"); + $('.modal-footer').children('img').css('visibility', 'hidden'); + if (data_response.error == 1) { + (new M.core.alert({ + message: data_response.message + ' .Please reload the page!', + title: datatables_lang_messages.notification_info, + })).show(); + } else { + var extension = data_response.data; + if (extension.time_content) { + $('#extension-time-content').html(extension.time_content); + } else { + $('#extension-time-content').html(time_content); + } + document.getElementById('extension-extend-deadline'). + value = data_response.data.time_iso_8601.slice(0,16); + $('#extension-reason-select').val(extension.pre_defined_reason); + $('#extension-allocatabletype').val(extension.allocatabletype); + $('#extension-allocatableid').val(extension.allocatableid); + $('#extension-courseworkid').val(extension.courseworkid); + $('#extension-id').val(extension.id); + + $('#id_extra_information').val(extension.text); + + $('#id_extra_information').prop('disabled', false); + $('#extension-extend-deadline').prop('disabled', false); + $('#extension-reason-select').prop('disabled', false); + save_extension_form_data(); + } + }, + error: function () { + $('html, body').css("cursor", "auto"); + change__status_extension_submit_button(false); + }, + complete: function () { + $('html, body').css("cursor", "auto"); + change__status_extension_submit_button(false); + } + }); + } + + /** + * + * @param {string} data_name + * @param {object} data_params + * @param {string} data_time + * @param {string} current_rowid + */ + function extension_new_change_data_form(data_name, data_params, data_time, current_rowid) { + var title = 'New extension for ' + data_name; + $('#extension-modal-title').html(title); + $('#form-extension').find('input[type=hidden]').val(''); + $('#form-extension').find('textarea').val(''); + + if(data_time.is_have_deadline == '1') { + var url = datatables_lang_messages.url_root; + $.ajax({ + type: "GET", + url: url + "/mod/coursework/actions/ajax/deadline_extension/new.php", + data: data_params, + beforeSend: function () { + change__status_extension_submit_button(true); + $('html, body').css("cursor", "wait"); + $('.modal-footer').children('img').css('visibility', 'visible'); + }, + success: function (response) { + $('html, body').css("cursor", "auto"); + $('.modal-footer').children('img').css('visibility', 'hidden'); + var data_response = JSON.parse(response); + $('#extension-time-content').html(data_response.data.time_content); + document.getElementById('extension-extend-deadline'). + value = data_response.data.time_iso_8601.slice(0,16); + save_extension_form_data(); + }, + error: function () { + $('html, body').css("cursor", "auto"); + }, + complete: function () { + $('html, body').css("cursor", "auto"); + } + }); + } else { + save_extension_form_data(); + } + $('#extension-reason-select').val(''); + $('#extension-allocatabletype').val(data_params.allocatabletype); + $('#extension-allocatableid').val(data_params.allocatableid); + $('#extension-courseworkid').val(data_params.courseworkid); + $('#extension-submissionid').val(data_params.submissionid); + $('#extension-name').val(data_name); + $('#button-id').val(current_rowid); + + $('#id_extra_information').prop('disabled', false); + $('#extension-extend-deadline').prop('disabled', false); + $('#extension-reason-select').prop('disabled', false); + } + + + $("#form-extension :input").change(function () { + extension_form_change = true; + change__status_extension_submit_button(false); + }); + + /** + * + * @param {string} status + */ + function change__status_extension_submit_button(status) { + $('#extension-submit').prop('disabled', status); + } + + /** + * + */ + function save_extension_form_data() { + extension_form_change = false; + } + + /** + * + */ + function is_data_extension_form_change() { + return extension_form_change; + } + + /** + * Feedback + */ + $('.datatabletest').on('click', '.new_final_feedback, .new_feedback,' + + ' .edit_final_feedback, .edit_feedback, .show_feedback', function (e) { + e.preventDefault(); + var url = $(this).attr('href'); + $.ajax({ + type: "GET", + url: url+'&ajax=1' + }).done(function(response) { + response = $.parseJSON(response); + var modalbody = $('#modal-grading').find('.modal-body'); + // Careful as not all requests return a response.success value. Only if it's false, show error. + if ((response.success ?? true) === false && (response.message ?? null)) { + modalbody.html(response.message); + } else { + modalbody.html(response.formhtml); + var filemanager = modalbody.find('.filemanager'); + if (response.filemanageroptions && filemanager.length) { + var elementid = filemanager.attr('id'); + var clientid = elementid.substr(12); + if (clientid) { + response.filemanageroptions.client_id = clientid; + M.form_filemanager.init(Y, response.filemanageroptions); + } + } + if (response.editoroptions) { + require(['editor_tiny/editor'], (Tiny) => { + Tiny.setupForElementId({ + elementId: 'id_feedbackcomment', + options: JSON.parse(response.editoroptions), + }); + }); + } + + if (response.commentoptions) { + M.util.js_pending('gradingform_guide/comment_chooser'); + require(['gradingform_guide/comment_chooser'], function(amd) { + $(".remark").each( function (i,ele) { + var buttonele = $(ele).find(".commentchooser"); + var textele = $(ele).find(".markingguideremark"); + var buttonid = $(buttonele).attr("id"); + var textid = $(textele).attr("id"); + amd.initialise(1, buttonid, textid, response.commentoptions); + M.util.js_complete('gradingform_guide/comment_chooser'); + + }); + + }); + } + } + }); + var cell_td = $(this).closest('td'); + var cell_selector = get_td_cell_selector(cell_td); + var cell_type = cell_td.attr('data-class-name'); + show_loading_modal_grading(cell_selector, cell_type); + }); + + /** + * + * @param {object} td_cell + * @returns {string} + */ + function get_td_cell_selector(td_cell) { + var result = '.' + td_cell.attr('class').replaceAll(' ', '.'); + var tr_cell = td_cell.closest('tr'); + if (tr_cell.attr('id')) { + result = '#' + tr_cell.attr('id') + ' ' + result; + } else { + result = '.' + tr_cell.attr('class').replaceAll(' ', '.') + ' ' + result; + } + return result; + } + + /** + * + * @param {object} cell_selector + * @param {object} cell_type + */ + function show_loading_modal_grading(cell_selector, cell_type) { + // Set row id. + var modal = $('#modal-grading'); + modal.find('#cell_selector').val(cell_selector); + modal.find('#cell_type').val(cell_type); + modal.find('.modal-body').html(' loading'); + $('#modal-grading').modal('show'); + } + + $('#modal-grading').on('click', '#id_submitfeedbackbutton, #id_submitbutton', function (e) { + e.preventDefault(); + var button = $(this); + button.prop('disabled', true); + var submitbutton = (button.attr('id') == 'id_submitbutton') ? 1 : 0; + var removefeedbackbutton = (button.attr('id') == 'id_removefeedbackbutton') ? 1 : 0; + var submitfeedbackbutton = (button.attr('id') == 'id_submitfeedbackbutton') ? 1 : 0; + var modal = $('#modal-grading'); + var url = '/mod/coursework/actions/feedbacks/create.php'; + var form_data = modal.find('form').serializeArray(); + for (var i = 0, length = form_data.length; i < length; i++) { + if (form_data[i].name == 'feedbackid' && !isNaN(parseInt(form_data[i].value)) && + form_data[i].value != '0') { + url = '/mod/coursework/actions/feedbacks/update.php'; + break; + } + } + var cell_type = modal.find('#cell_type').val(); + update_feedback(form_data,url,cell_type,submitbutton,removefeedbackbutton,submitfeedbackbutton,0,button); + /* + form_data = form_data.concat({name: 'ajax', value: 1}, + {name: 'cell_type', value: cell_type}, + {name: 'submitbutton', value: submitbutton}, + {name: 'removefeedbackbutton', value: removefeedbackbutton}); + $.ajax({ + type: 'POST', + data: form_data, + url: url, + dataType: 'json' + }).done(function(response) { + console.log(response); + if (response.success) { + var cell_selector = modal.find('#cell_selector').val(); + $(cell_selector).html(response.html); + $('#modal-grading').modal('hide'); + if (submitbutton == 1) { + alert('Your data has been saved.'); + } else { + alert('The feedback has been removed.'); + } + } else { + alert('Sorry! There was an error with your request.'); + } + }).always(function() { + me.prop('disabled', false); + });*/ + }); + + $('#modal-grading').on('click', '#id_cancel', function (e) { + e.preventDefault(); + $('#modal-grading').modal('hide'); + }); + + $('#modal-grading').on('click', '#id_removefeedbackbutton', function (e) { + e.preventDefault(); + var button = $(this); + button.prop('disabled', true); + if (confirm('do you want to remove feedback')) { + var submitbutton = (button.attr('id') == 'id_submitbutton') ? 1 : 0; + var removefeedbackbutton = (button.attr('id') == 'id_removefeedbackbutton') ? 1 : 0; + var submitfeedbackbutton = (button.attr('id') == 'id_submitfeedbackbutton') ? 1 : 0; + var modal = $('#modal-grading'); + var url = '/mod/coursework/actions/feedbacks/update.php'; + var form_data = modal.find('form').serializeArray(); + var cell_type = modal.find('#cell_type').val(); + update_feedback(form_data, url, cell_type, submitbutton, removefeedbackbutton, + submitfeedbackbutton,1, button); + } + }); + + /** + * + * @param {object} form_data + * @param {string} url + * @param {string} celltype + * @param {object} submitbutton + * @param {object} removefeedbackbutton + * @param {object} submitfeedbackbutton + * @param {object} confirm + * @param {object} button + */ + function update_feedback(form_data, url, celltype, submitbutton, removefeedbackbutton, + submitfeedbackbutton, confirm,button) { + + form_data = form_data.concat({name: 'ajax', value: 1}, + {name: 'cell_type', value: celltype}, + {name: 'submitbutton', value: submitbutton}, + {name: 'submitfeedbackbutton', value: submitfeedbackbutton}, + {name: 'removefeedbackbutton', value: removefeedbackbutton}, + {name: 'confirm', value: confirm}); + + $.ajax({ + type: 'POST', + data: form_data, + url: url, + dataType: 'json' + }).done(function(response) { + if ((response.success ?? true) === false && (response.message ?? null)) { + // Could be an error like "Please provide a valid grade for each criterion". + $('#modal-grading').find('.modal-body').html( + '
' + response.message + '
' + ); + } else if (response.success) { + var cell_selector = $('#modal-grading').find('#cell_selector').val(); + $(cell_selector).html(response.html); + + if (typeof response.extrahtml !== 'undefined' && response.extrahtml != '') { + $(cell_selector).next('td').html(response.extrahtml); + } + if (typeof response.assessdate !== 'undefined' && response.assessdate != '') { + $(cell_selector).next('td').html(response.assessdate); + } + + if (typeof response.assessorname !== 'undefined' && response.assessorname != '') { + $(cell_selector).prev('td').html(response.assessorname); + } + + if (typeof response.assessortwo !== 'undefined' && response.assessortwo != '') { + var tdcell = $(cell_selector).closest('tr').next().find('td')[1]; + $(tdcell).html(response.assessortwo); + } + + if (typeof response.finalhtml !== 'undefined' && response.assessortwo != '') { + var tablerowid = 'allocatable_' + response.allocatableid; + var tdcell2 = $('#' + tablerowid).find('.multiple_agreed_grade_cell')[0]; + $(tdcell2).html(response.finalhtml); + } + var datatables_lang_messages_two = JSON.parse($('#datatables_lang_messages').attr('data-lang')); + $('#modal-grading').modal('hide'); + if (submitbutton === 1) { + (new M.core.alert({ + message: datatables_lang_messages_two.alert_feedback_save_successful.replace(/\_/g, ' '), + title: datatables_lang_messages_two.notification_info, + })).show(); + + } else if (submitfeedbackbutton === 1) { + (new M.core.alert({ + message: datatables_lang_messages_two.alert_feedback_draft_save_successful.replace(/\_/g, ' '), + title: datatables_lang_messages_two.notification_info, + })).show(); + + } else { + (new M.core.alert({ + message: datatables_lang_messages_two.alert_feedback_remove_successful.replace(/\_/g, ' '), + title: datatables_lang_messages_two.notification_info, + })).show(); + } + } else { + (new M.core.alert({ + message: response.message, + title: datatables_lang_messages_two.notification_info, + })).show(); + +// error_wrapper_element.prepend('
' + response.message + '
'); + + } + }).always(function(){ + button.prop('disabled', false); + }); + } + }); + } + }; +}); + diff --git a/coursework.js b/coursework.js index d36eb4b..4d07644 100644 --- a/coursework.js +++ b/coursework.js @@ -1,302 +1,305 @@ var table_obj_list = []; -var id = 0; +//var id = 0; var is_responsive = false; var tableobject = 0; -$( document ).ready(function() { - var langmessage = JSON.parse($('#element_lang_messages').attr('data-lang')); - var base_url = window.location.origin + '/mod/coursework/datatables/js/'; +define('mod_coursework/coursework', ['jquery', 'core/log'], function($, log) { + function isMobileDevice() { + return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)); + } - require.config({ - paths: { - 'datatables.net': base_url + 'jquery.datatables', - 'datatables.searchpanes': base_url + 'datatables.searchpanes', - 'datatables.buttons': base_url + 'datatables.buttons', - 'datatables.select': base_url + 'datatables.select', - 'datatables.responsive': base_url + 'datatables.responsive.min', - } - }); + $( document ).ready(function() { + var langmessage = JSON.parse($('#element_lang_messages').attr('data-lang')); + var base_url = window.location.origin + '/mod/coursework/datatables/js/'; + + require.config({ + paths: { + 'datatables.net': base_url + 'jquery.datatables', + 'datatables.searchpanes': base_url + 'datatables.searchpanes', + 'datatables.buttons': base_url + 'datatables.buttons', + 'datatables.select': base_url + 'datatables.select', + 'datatables.responsive': base_url + 'datatables.responsive.min', + } + }); - require(['datatables.net'], function (DataTable) { + require(['datatables.net'], function (DataTable) { - // Ensure jQuery access. - if (!$.fn.dataTable) { - $.fn.dataTable = DataTable; - } + // Ensure jQuery access. + if (!$.fn.dataTable) { + $.fn.dataTable = DataTable; + } - $.fn.DataTable = DataTable; - $.fn.DataTableSettings = DataTable.settings; - $.fn.dataTableExt = DataTable.ext; - DataTable.$ = $; - $.fn.DataTable = function ( opts ) { - return $(this).dataTable( opts ).api(); - }; + $.fn.DataTable = DataTable; + $.fn.DataTableSettings = DataTable.settings; + $.fn.dataTableExt = DataTable.ext; + DataTable.$ = $; + $.fn.DataTable = function ( opts ) { + return $(this).dataTable( opts ).api(); + }; - $.fn.dataTable.Api.register('row().show()', function() { - var page_info = this.table().page.info(); - // Get row index. - var new_row_index = this.index(); - // Row position. - var row_position = this.table() - .rows({ search: 'applied' })[0] - .indexOf(new_row_index); - // Already on right page ? - if ((row_position >= page_info.start && row_position < page_info.end) || row_position < 0) { + $.fn.dataTable.Api.register('row().show()', function() { + var page_info = this.table().page.info(); + // Get row index. + var new_row_index = this.index(); + // Row position. + var row_position = this.table() + .rows({ search: 'applied' })[0] + .indexOf(new_row_index); + // Already on right page ? + if ((row_position >= page_info.start && row_position < page_info.end) || row_position < 0) { + // Return row object. + return this; + } + // Find page number. + var page_to_display = Math.floor(row_position / this.table().page.len()); + // Go to that page. + this.table().page(page_to_display); // Return row object. return this; - } - // Find page number. - var page_to_display = Math.floor(row_position / this.table().page.len()); - // Go to that page. - this.table().page(page_to_display); - // Return row object. - return this; - }); - require(['datatables.searchpanes', 'datatables.select', 'datatables.buttons', 'datatables.responsive'], function() { - if(isMobileDevice() && $(window).width() < 768) { - is_responsive = true; - initDatatable(is_responsive); + }); + require(['datatables.searchpanes', 'datatables.select', 'datatables.buttons', 'datatables.responsive'], function() { + if(isMobileDevice() && $(window).width() < 768) { + is_responsive = true; + initDatatable(is_responsive); - $('.datatabletest').on('order.dt', function(e) { - $('.submissionrowmulti').removeClass("shown"); - }); - } - else { - initDatatable(is_responsive); - } + $('.datatabletest').on('order.dt', function(e) { + $('.submissionrowmulti').removeClass("shown"); + }); + } + else { + initDatatable(is_responsive); + } + }); }); - }); - /** - * - * @param tableid - */ - function background_load_table(tableid) { - var tableelement = $('#' + tableid); - var wrapperelement = tableelement.parent('.dataTables_wrapper'); - var paginationelement = wrapperelement.find('.dataTables_paginate'); - tableobject = table_obj_list[tableid]; - var submissionswrapper = tableelement.parent('.dataTables_wrapper'); + /** + * + * @param tableid + */ + function background_load_table(tableid) { + var tableelement = $('#' + tableid); + var wrapperelement = tableelement.parent('.dataTables_wrapper'); + var paginationelement = wrapperelement.find('.dataTables_paginate'); + tableobject = table_obj_list[tableid]; + var submissionswrapper = tableelement.parent('.dataTables_wrapper'); - // Hide buttons. - wrapperelement.find('.dataTables_paginate, .dataTables_info, .dataTables_length, .dataTables_filter').css('visibility', 'hidden'); - wrapperelement.find('thead, .dt-button').each(function() { - var me = $(this); - me.css('pointer-events', 'none'); - if (me.hasClass('dt-button')) { - me.find('span').html(' ' + me.find('span').html()); - } - }); - console.log(submissionswrapper); - - $('
' + langmessage.loadingpagination + '
').insertBefore(submissionswrapper); - $('
' + langmessage.loadingpagination + '
').insertAfter(paginationelement); - $('').insertBefore(wrapperelement.find('.dt-button > span')); + // Hide buttons. + wrapperelement.find('.dataTables_paginate, .dataTables_info, .dataTables_length, .dataTables_filter').css('visibility', 'hidden'); + wrapperelement.find('thead, .dt-button').each(function() { + var me = $(this); + me.css('pointer-events', 'none'); + if (me.hasClass('dt-button')) { + me.find('span').html(' ' + me.find('span').html()); + } + }); + console.log(submissionswrapper); - // Prepare params for ajax request. - var params = { - group: tableelement.attr('group'), - perpage: tableelement.attr('perpage'), - sortby: tableelement.attr('sortby'), - sorthow: tableelement.attr('sorthow'), - firstnamealpha: tableelement.attr('firstnamealpha'), - lastnamealpha: tableelement.attr('lastnamealpha'), - groupnamealpha: tableelement.attr('groupnamealpha'), - substatus: tableelement.attr('substatus'), - unallocated: tableelement.attr('unallocated'), - courseworkid: tableelement.attr('courseworkid') - }; + $('
' + langmessage.loadingpagination + '
').insertBefore(submissionswrapper); + $('
' + langmessage.loadingpagination + '
').insertAfter(paginationelement); + $('').insertBefore(wrapperelement.find('.dt-button > span')); - $.ajax({ - url: '/mod/coursework/actions/ajax/datatable/grading.php', - type: 'POST', - data: params - }).done(function(response) { - console.log('test remove 1'); - $("#datatable_top_loading_message").remove(); - tableobject.rows.add($(response)).draw(false); - wrapperelement.find('.submission-loading').remove(); - }).fail(function() {}).always(function() { - // Show buttons. - wrapperelement.find('.pagination-loading').remove(); - wrapperelement.find('.submission-loading').remove(); - wrapperelement.find('thead, .dt-button').css('pointer-events', 'auto'); - wrapperelement.find('.dataTables_paginate, .dataTables_info, .dataTables_length, .dataTables_filter').css('visibility', 'visible'); - }); - } + // Prepare params for ajax request. + var params = { + group: tableelement.attr('group'), + perpage: tableelement.attr('perpage'), + sortby: tableelement.attr('sortby'), + sorthow: tableelement.attr('sorthow'), + firstnamealpha: tableelement.attr('firstnamealpha'), + lastnamealpha: tableelement.attr('lastnamealpha'), + groupnamealpha: tableelement.attr('groupnamealpha'), + substatus: tableelement.attr('substatus'), + unallocated: tableelement.attr('unallocated'), + courseworkid: tableelement.attr('courseworkid') + }; - function initDatatable(is_responsive) { - $(".datatabletest").each(function () { - // Class that determines whether all data for the databale has been full loaded. - var fullloaded = $(this).hasClass('full-loaded'); + $.ajax({ + url: '/mod/coursework/actions/ajax/datatable/grading.php', + type: 'POST', + data: params + }).done(function(response) { + console.log('test remove 1'); + $("#datatable_top_loading_message").remove(); + tableobject.rows.add($(response)).draw(false); + wrapperelement.find('.submission-loading').remove(); + }).fail(function() {}).always(function() { + // Show buttons. + wrapperelement.find('.pagination-loading').remove(); + wrapperelement.find('.submission-loading').remove(); + wrapperelement.find('thead, .dt-button').css('pointer-events', 'auto'); + wrapperelement.find('.dataTables_paginate, .dataTables_info, .dataTables_length, .dataTables_filter').css('visibility', 'visible'); + }); + } - table_obj_list[$(this).attr('id')] = $(this).DataTable( { - 'order': [], - stateSave: true, - language: { - searchPanes: { - collapse: {0: $('#search_pane_button').val() || 'Filter', _:($('#search_pane_button').val() || 'Filter') + ' (%d)'} - } - }, - buttons:[ + function initDatatable(is_responsive) { + $(".datatabletest").each(function () { + // Class that determines whether all data for the databale has been full loaded. + var fullloaded = $(this).hasClass('full-loaded'); - ], - dom: 'Blfrtip', - columnDefs:[ - { - searchPanes:{show: false}, - targets: ['studentname','addition-multiple-button'], - bSortable: false - }, - { - searchPanes: {show: false}, - targets: ['lastname_cell','firstname_cell','tableheadpersonaldeadline', 'tableheaddate', 'tableheadfilename', 'tableheadplagiarismalert', 'plagiarism', 'agreedgrade', 'feedbackandgrading', 'provisionalgrade', 'tableheadmoderationagreement'] + table_obj_list[$(this).attr('id')] = $(this).DataTable( { + 'order': [], + stateSave: true, + language: { + searchPanes: { + collapse: {0: $('#search_pane_button').val() || 'Filter', _:($('#search_pane_button').val() || 'Filter') + ' (%d)'} + } }, - { - searchPanes:{ - show: true, - header: $('#search_pane_group').val() || 'Group', + buttons:[ + + ], + dom: 'Blfrtip', + columnDefs:[ + { + searchPanes:{show: false}, + targets: ['studentname','addition-multiple-button'], + bSortable: false }, - targets: 'tableheadgroups', - }, - { - searchPanes:{ - show: true, - header: $('#search_pane_status').val() || 'Status', - getFullText: true, + { + searchPanes: {show: false}, + targets: ['lastname_cell','firstname_cell','tableheadpersonaldeadline', 'tableheaddate', 'tableheadfilename', 'tableheadplagiarismalert', 'plagiarism', 'agreedgrade', 'feedbackandgrading', 'provisionalgrade', 'tableheadmoderationagreement'] }, - targets: 'tableheadstatus', - }, - { - searchPanes:{ - show: true, - header: $('#search_pane_firstname').val() || 'First Name Initial', + { + searchPanes:{ + show: true, + header: $('#search_pane_group').val() || 'Group', + }, + targets: 'tableheadgroups', }, - targets: 'firstname_letter_cell', - }, - { - searchPanes:{ - show: true, - header: $('#search_pane_lastname').val() || 'Last Name Initial', + { + searchPanes:{ + show: true, + header: $('#search_pane_status').val() || 'Status', + getFullText: true, + }, + targets: 'tableheadstatus', + }, + { + searchPanes:{ + show: true, + header: $('#search_pane_firstname').val() || 'First Name Initial', + }, + targets: 'firstname_letter_cell', }, - targets: 'lastname_letter_cell', + { + searchPanes:{ + show: true, + header: $('#search_pane_lastname').val() || 'Last Name Initial', + }, + targets: 'lastname_letter_cell', + }, + { "visible": false, "targets": [ 'lastname_letter_cell','firstname_letter_cell', 'lastname_cell','firstname_cell'] } + ], + select: { + style: 'multi', + selector: '.select-checkbox' }, - { "visible": false, "targets": [ 'lastname_letter_cell','firstname_letter_cell', 'lastname_cell','firstname_cell'] } - ], - select: { - style: 'multi', - selector: '.select-checkbox' - }, - stateSaveParams: function (settings, data) { - data.columns = []; - } - - }); - - if (!fullloaded) { - background_load_table($(this).attr('id')); - } - }); - } + stateSaveParams: function (settings, data) { + data.columns = []; + } - if(isMobileDevice() && $(window).width() < 768) { - // For small screens. - var table = $('.datatabletest tbody').on('click', 'td.details-control', function () { - var tr = $(this).closest("tr"); - var row_id = tr.attr('id').replace('allocatable_', ''); - var table_id = 'assessorfeedbacktable_' + row_id; + }); - if ($(tr).next('tr.row_assessors').length > 0) { - $(tr).next('tr.row_assessors').remove(); - } - else { - // As originally written this code created a new table with duplicate IDs. - // See comment on CTP-3783 below for more info. - const oldTable = $('#' + table_id); - const newRow = $( - '' - ); - oldTable.addClass('assessors_expanded').css('width', '95%').appendTo(newRow.find('td')); - } - $(tr).toggleClass('shown'); - }); - } - else { - // Add event listener for opening and closing details. - $('.datatabletest tbody').on('click', 'td.details-control', function () { - var tr = $(this).closest("tr"); - var table_key = $(this).closest('.datatabletest').attr('id'); - var table = table_obj_list[table_key]; - if (table) { - var row = table.row( tr ); + if (!fullloaded) { + background_load_table($(this).attr('id')); + } + }); + } + if(isMobileDevice() && $(window).width() < 768) { + // For small screens. + var table = $('.datatabletest tbody').on('click', 'td.details-control', function () { + var tr = $(this).closest("tr"); var row_id = tr.attr('id').replace('allocatable_', ''); var table_id = 'assessorfeedbacktable_' + row_id; - const oldTable = $('#' + table_id); - if (oldTable.length) { - const subRow = $('#sub-row-' + tr.data('allocatable')); - if (subRow.length === 0) { - // Open this row - create as sub-row. - // CTP-3783 As originally written this code cloned the old table and added its HTML again to the new row. - // This meant that we had 2 x tables do duplicate IDs, with the old table hidden and new one visible. - // Then multiple behat tests failed when trying to click the hidden feedback button not visible one. - const newRow = $( - '' + ); + oldTable.addClass('assessors_expanded').css('width', '95%').appendTo(newRow.find('td')); + } + $(tr).toggleClass('shown'); + }); + } + else { + // Add event listener for opening and closing details. + $('.datatabletest tbody').on('click', 'td.details-control', function () { + var tr = $(this).closest("tr"); + var table_key = $(this).closest('.datatabletest').attr('id'); + var table = table_obj_list[table_key]; + if (table) { + var row = table.row( tr ); + + var row_id = tr.attr('id').replace('allocatable_', ''); + var table_id = 'assessorfeedbacktable_' + row_id; + const oldTable = $('#' + table_id); + if (oldTable.length) { + const subRow = $('#sub-row-' + tr.data('allocatable')); + if (subRow.length === 0) { + // Open this row - create as sub-row. + // CTP-3783 As originally written this code cloned the old table and added its HTML again to the new row. + // This meant that we had 2 x tables do duplicate IDs, with the old table hidden and new one visible. + // Then multiple behat tests failed when trying to click the hidden feedback button not visible one. + const newRow = $( + '' - ); - oldTable.addClass('assessors_expanded').css('width', '95%').appendTo(newRow.find('td')); - oldTable.show(); - row.child(newRow).show(); - tr.addClass('shown'); + ); + oldTable.addClass('assessors_expanded').css('width', '95%').appendTo(newRow.find('td')); + oldTable.show(); + row.child(newRow).show(); + tr.addClass('shown'); + } else { + // Sub-row already exists. + if (subRow.css('display') === 'none') { + subRow.show(); + tr.addClass('shown'); + } else { + // This row is already open - close it. + tr.removeClass('shown'); + subRow.hide(); + } + } } else { - // Sub-row already exists. + // No need to move table - just open/close. if (subRow.css('display') === 'none') { subRow.show(); tr.addClass('shown'); } else { // This row is already open - close it. - tr.removeClass('shown'); subRow.hide(); + tr.removeClass('shown'); } } - } else { - // No need to move table - just open/close. - if (subRow.css('display') === 'none') { - subRow.show(); - tr.addClass('shown'); - } else { - // This row is already open - close it. - subRow.hide(); - tr.removeClass('shown'); - } } - } - }); - } - - $('.datatabletest').on('click', '.splitter-firstname, .splitter-lastname, .splitter-email', function (event) { - event.preventDefault(); - var node = $(event.target), - isAscending = node.hasClass('sorting_asc'), - currentsort = 'asc', sortby = 'desc'; - if (!isAscending) { - currentsort = 'desc'; - sortby = 'asc'; + }); } - var table_id = $(this).closest('.datatabletest').attr('id'); - table = table_obj_list[table_id]; - var headerclass = $(this).hasClass('splitter-firstname') ? 'firstname_cell' : 'lastname_cell'; - headerclass = $(this).hasClass('splitter-email') ? 'email_cell' : headerclass; - console.log(headerclass); - var sortColumn = table.column('.' + headerclass).index(); - table.order([sortColumn, sortby]).draw(); - node.addClass('sorting_' + sortby).removeClass('sorting sorting_' + currentsort); - node.parent().removeClass('sorting sorting_asc sorting_desc'); - node.siblings().removeClass('sorting_asc sorting_desc').addClass('sorting'); + $('.datatabletest').on('click', '.splitter-firstname, .splitter-lastname, .splitter-email', function (event) { + event.preventDefault(); + var node = $(event.target), + isAscending = node.hasClass('sorting_asc'), + currentsort = 'asc', sortby = 'desc'; + if (!isAscending) { + currentsort = 'desc'; + sortby = 'asc'; + } + var table_id = $(this).closest('.datatabletest').attr('id'); + table = table_obj_list[table_id]; + var headerclass = $(this).hasClass('splitter-firstname') ? 'firstname_cell' : 'lastname_cell'; + headerclass = $(this).hasClass('splitter-email') ? 'email_cell' : headerclass; + console.log(headerclass); + var sortColumn = table.column('.' + headerclass).index(); + table.order([sortColumn, sortby]).draw(); + + node.addClass('sorting_' + sortby).removeClass('sorting sorting_' + currentsort); + node.parent().removeClass('sorting sorting_asc sorting_desc'); + node.siblings().removeClass('sorting_asc sorting_desc').addClass('sorting'); + }); }); -}); -function isMobileDevice() { - return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)); -} +}); diff --git a/module.js b/module.js index edb3a89..b92f86f 100644 --- a/module.js +++ b/module.js @@ -30,6 +30,7 @@ M.mod_coursework = { init_allocate_page: function (e, wwwroot, coursemoduleid) { "use strict"; + alert('module.js here!'); // Make the changes to the moderations set dropdowns set the 'in moderations set' // checkboxes automatically. @@ -476,6 +477,7 @@ M.mod_coursework = { * This is to set up the listeners etc for the page elements on the allocations page. */ init_personal_deadlines_page: function () { + alert('module.js - deadlines here!'); $('#selectall').change(function () { diff --git a/view.php b/view.php index 91f7a7e..346208c 100644 --- a/view.php +++ b/view.php @@ -50,7 +50,7 @@ 'strings' => [], ]; -$PAGE->requires->yui_module('moodle-core-notification', 'notification_init'); +//$PAGE->requires->yui_module('moodle-core-notification', 'notification_init'); // Course_module ID, or coursework instance ID - it should be named as the first character of the module. $coursemoduleid = optional_param('id', 0, PARAM_INT); @@ -529,6 +529,8 @@ // Require JS files. // Note that jquery datatables files not included as called by coursework.js. if ($cangrade || $canviewstudents) { +// $PAGE->requires->js_call_amd('mod_coursework/coursework', 'init'); +// $PAGE->requires->js_call_amd('mod_coursework/coursework_edit', 'init'); // TODO make these into AMD modules. $jsfiles = ['coursework.js', 'coursework_edit.js']; foreach ($jsfiles as $jsfile) {