Merge branch 'MDL-60579-master' of https://github.com/mihailges/moodle
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Name and page filter JS module for the course participants page.
|
||||
*
|
||||
* @module core_user/name_page_filter
|
||||
* @package core_user
|
||||
* @copyright 2017 Mihail Geshoski
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery', 'core_user/unified_filter'],
|
||||
function($, UnifiedFilter) {
|
||||
|
||||
/**
|
||||
* Selectors.
|
||||
*
|
||||
* @access private
|
||||
* @type {{NAME_FILTERS: string, PAGE_FILTERS: string}}
|
||||
*/
|
||||
var SELECTORS = {
|
||||
NAME_FILTERS: 'a.letter',
|
||||
PAGE_FILTERS: 'a.page-link'
|
||||
};
|
||||
|
||||
/**
|
||||
* Init function.
|
||||
*
|
||||
* @method init
|
||||
* @private
|
||||
*/
|
||||
var init = function() {
|
||||
$(SELECTORS.NAME_FILTERS + ', ' + SELECTORS.PAGE_FILTERS).on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var href = $(this).attr('href');
|
||||
UnifiedFilter.getForm().attr('action', href);
|
||||
UnifiedFilter.getForm().submit();
|
||||
});
|
||||
};
|
||||
|
||||
return /** @alias module:core/form-autocomplete */ {
|
||||
// Public variables and functions.
|
||||
/**
|
||||
* Initialise the name and page user filter.
|
||||
*
|
||||
* @method init
|
||||
*/
|
||||
'init': function() {
|
||||
init();
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -126,6 +126,8 @@ define(['core/templates',
|
||||
* @private
|
||||
*/
|
||||
StatusFieldActions.prototype.bindUnenrol = function() {
|
||||
var statusFieldInstsance = this;
|
||||
|
||||
$(SELECTORS.UNENROL).click(function(e) {
|
||||
e.preventDefault();
|
||||
var unenrolLink = $(this);
|
||||
@@ -161,12 +163,12 @@ define(['core/templates',
|
||||
modal.getRoot().on(ModalEvents.save, function() {
|
||||
// Build params.
|
||||
var unenrolParams = {
|
||||
confirm: 1,
|
||||
sesskey: Config.sesskey,
|
||||
ue: $(unenrolLink).attr('rel')
|
||||
'ueid': $(unenrolLink).attr('rel')
|
||||
};
|
||||
// Send data to unenrol page (which will redirect back to the participants page after unenrol).
|
||||
window.location.href = Config.wwwroot + '/enrol/unenroluser.php?' + $.param(unenrolParams);
|
||||
// Don't close the modal yet.
|
||||
e.preventDefault();
|
||||
// Submit data.
|
||||
statusFieldInstsance.submitUnenrolFormAjax(modal, unenrolParams);
|
||||
});
|
||||
|
||||
// Handle hidden event.
|
||||
@@ -306,7 +308,6 @@ define(['core/templates',
|
||||
window.M.core_formchangechecker.reset_form_dirty_state();
|
||||
}
|
||||
window.location.reload();
|
||||
|
||||
} else {
|
||||
// Serialise the form data and reload the form fragment to show validation errors.
|
||||
var formData = JSON.stringify(form.serialize());
|
||||
@@ -315,6 +316,37 @@ define(['core/templates',
|
||||
}).fail(Notification.exception);
|
||||
};
|
||||
|
||||
/**
|
||||
* Private method
|
||||
*
|
||||
* @method submitUnenrolFormAjax
|
||||
* @param {Object} modal The the AMD modal object containing the form.
|
||||
* @param {Object} unenrolParams The unenrol parameters.
|
||||
* @private
|
||||
*/
|
||||
StatusFieldActions.prototype.submitUnenrolFormAjax = function(modal, unenrolParams) {
|
||||
var request = {
|
||||
methodname: 'core_enrol_unenrol_user_enrolment',
|
||||
args: unenrolParams
|
||||
};
|
||||
|
||||
Ajax.call([request])[0].done(function(data) {
|
||||
if (data.result) {
|
||||
// Dismiss the modal.
|
||||
modal.hide();
|
||||
|
||||
// Reload the page, don't show changed data warnings.
|
||||
if (typeof window.M.core_formchangechecker !== "undefined") {
|
||||
window.M.core_formchangechecker.reset_form_dirty_state();
|
||||
}
|
||||
window.location.reload();
|
||||
} else {
|
||||
// Display an alert containing the error message
|
||||
Notification.alert(data.errors[0].key, data.errors[0].message);
|
||||
}
|
||||
}).fail(Notification.exception);
|
||||
};
|
||||
|
||||
/**
|
||||
* Private method
|
||||
*
|
||||
|
||||
@@ -104,6 +104,17 @@ define(['jquery', 'core/form-autocomplete', 'core/str', 'core/notification'],
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the unified user filter form.
|
||||
*
|
||||
* @method getForm
|
||||
* @private
|
||||
* @return {Form object}
|
||||
*/
|
||||
var getForm = function() {
|
||||
return $(SELECTORS.UNIFIED_FILTERS).closest('form');
|
||||
};
|
||||
|
||||
return /** @alias module:core/form-autocomplete */ {
|
||||
// Public variables and functions.
|
||||
/**
|
||||
@@ -113,6 +124,15 @@ define(['jquery', 'core/form-autocomplete', 'core/str', 'core/notification'],
|
||||
*/
|
||||
'init': function() {
|
||||
init();
|
||||
},
|
||||
/**
|
||||
* Return the unified user filter form.
|
||||
*
|
||||
* @method getForm
|
||||
* @return {Form object}
|
||||
*/
|
||||
'getForm': function() {
|
||||
return getForm();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user