[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 // This file is part of Moodle - http://moodle.org/ 2 // 3 // Moodle is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // (at your option) any later version. 7 // 8 // Moodle is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 15 16 /** 17 * Custom auto-complete adapter to load users from the assignment list_participants webservice. 18 * 19 * @module mod_assign/participants_selector 20 * @copyright 2015 Damyon Wiese <damyon@moodle.com> 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 define(['core/ajax', 'jquery', 'core/templates'], function(ajax, $, templates) { 24 25 26 return /** @alias module:mod_assign/participants_selector */ { 27 28 // Public variables and functions. 29 /** 30 * Process the results returned from transport (convert to value + label) 31 * 32 * @method processResults 33 * @param {String} selector 34 * @param {Array} data 35 * @return {Array} 36 */ 37 processResults: function(selector, data) { 38 var results = []; 39 var i = 0; 40 for (i = 0; i < data.length; i++) { 41 results[i] = {value: data[i].id, label: data[i].label}; 42 } 43 return results; 44 }, 45 46 /** 47 * Fetch results based on the current query. This also renders each result from a template before returning them. 48 * 49 * @method transport 50 * @param {String} selector Selector for the original select element 51 * @param {String} query Current search string 52 * @param {Function} success Success handler 53 * @param {Function} failure Failure handler 54 */ 55 transport: function(selector, query, success, failure) { 56 var assignmentid = $(selector).attr('data-assignmentid'); 57 var filters = $('[data-region="configure-filters"] input[type="checkbox"]'); 58 var filterstrings = []; 59 60 filters.each(function(index, element) { 61 filterstrings[$(element).attr('name')] = $(element).prop('checked'); 62 }); 63 64 var promise = ajax.call([{ 65 methodname: 'mod_assign_list_participants', args: {assignid: assignmentid, groupid: 0, filter: query, limit: 30} 66 }]); 67 68 promise[0].then(function(results) { 69 var promises = []; 70 var identityfields = $('[data-showuseridentity]').data('showuseridentity').split(','); 71 72 // We got the results, now we loop over them and render each one from a template. 73 $.each(results, function(index, user) { 74 var ctx = user, 75 identity = [], 76 show = true; 77 78 if (filterstrings.filter_submitted && !user.submitted) { 79 show = false; 80 } 81 if (filterstrings.filter_notsubmitted && user.submitted) { 82 show = false; 83 } 84 if (filterstrings.filter_requiregrading && !user.requiregrading) { 85 show = false; 86 } 87 if (show) { 88 $.each(identityfields, function(i, k) { 89 if (typeof user[k] !== 'undefined' && user[k] !== '') { 90 ctx.hasidentity = true; 91 identity.push(user[k]); 92 } 93 }); 94 ctx.identity = identity.join(', '); 95 promises.push(templates.render('mod_assign/list_participant_user_summary', ctx)); 96 } 97 }); 98 99 // When all the templates have been rendered, call the success handler. 100 $.when.apply($.when, promises).then(function() { 101 var args = arguments, 102 i = 0; 103 104 $.each(results, function(index, user) { 105 user.label = args[i]; 106 i++; 107 }); 108 109 success(results); 110 }); 111 }, failure); 112 } 113 }; 114 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |