[ 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 * User selector module. 18 * 19 * @module tool_lp/form-user-selector 20 * @class form-user-selector 21 * @package tool_lp 22 * @copyright 2015 Frédéric Massart - FMCorz.net 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 define(['jquery', 'core/ajax', 'core/templates'], function($, Ajax, Templates) { 27 28 return /** @alias module:tool_lp/form-user-selector */ { 29 30 processResults: function(selector, results) { 31 var users = []; 32 $.each(results, function(index, user) { 33 users.push({ 34 value: user.id, 35 label: user._label 36 }); 37 }); 38 return users; 39 }, 40 41 transport: function(selector, query, success, failure) { 42 var promise; 43 var capability = $(selector).data('capability'); 44 if (typeof capability === "undefined") { 45 capability = ''; 46 } 47 48 promise = Ajax.call([{ 49 methodname: 'tool_lp_search_users', 50 args: { 51 query: query, 52 capability: capability 53 } 54 }]); 55 56 promise[0].then(function(results) { 57 var promises = [], 58 i = 0; 59 60 // Render the label. 61 $.each(results.users, function(index, user) { 62 var ctx = user, 63 identity = []; 64 $.each(['idnumber', 'email', 'phone1', 'phone2', 'department', 'institution'], function(i, k) { 65 if (typeof user[k] !== 'undefined' && user[k] !== '') { 66 ctx.hasidentity = true; 67 identity.push(user[k]); 68 } 69 }); 70 ctx.identity = identity.join(', '); 71 promises.push(Templates.render('tool_lp/form-user-selector-suggestion', ctx)); 72 }); 73 74 // Apply the label to the results. 75 return $.when.apply($.when, promises).then(function() { 76 var args = arguments; 77 $.each(results.users, function(index, user) { 78 user._label = args[i]; 79 i++; 80 }); 81 success(results.users); 82 }); 83 84 }, failure); 85 } 86 87 }; 88 89 });
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 |