[ 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 * Cohort selector module. 18 * 19 * @module tool_lp/form-cohort-selector 20 * @class form-cohort-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-cohort-selector */ { 29 30 processResults: function(selector, results) { 31 var cohorts = []; 32 $.each(results, function(index, cohort) { 33 cohorts.push({ 34 value: cohort.id, 35 label: cohort._label 36 }); 37 }); 38 return cohorts; 39 }, 40 41 transport: function(selector, query, success, failure) { 42 var promise, 43 contextid = parseInt($(selector).data('contextid'), 10), 44 includes = $(selector).data('includes'); 45 46 promise = Ajax.call([{ 47 methodname: 'tool_lp_search_cohorts', 48 args: { 49 query: query, 50 context: {contextid: contextid}, 51 includes: includes 52 } 53 }]); 54 55 promise[0].then(function(results) { 56 var promises = [], 57 i = 0; 58 59 // Render the label. 60 $.each(results.cohorts, function(index, cohort) { 61 promises.push(Templates.render('tool_lp/form-cohort-selector-suggestion', cohort)); 62 }); 63 64 // Apply the label to the results. 65 return $.when.apply($.when, promises).then(function() { 66 var args = arguments; 67 $.each(results.cohorts, function(index, cohort) { 68 cohort._label = args[i]; 69 i++; 70 }); 71 success(results.cohorts); 72 }); 73 74 }, failure); 75 } 76 77 }; 78 79 });
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 |