|
| 1 | +// (C) Copyright 2015 Martin Dougiamas |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +angular.module('mm.core.user') |
| 16 | + |
| 17 | +/** |
| 18 | + * User handlers factory. |
| 19 | + * |
| 20 | + * @module mm.core.user |
| 21 | + * @ngdoc service |
| 22 | + * @name $mmUserHandlers |
| 23 | + */ |
| 24 | +.factory('$mmUserHandlers', function($mmUtil, $mmContentLinksHelper) { |
| 25 | + |
| 26 | + var self = {}; |
| 27 | + |
| 28 | + /** |
| 29 | + * Content links handler. |
| 30 | + * |
| 31 | + * @module mm.core.user |
| 32 | + * @ngdoc method |
| 33 | + * @name $mmUserHandlers#linksHandler |
| 34 | + */ |
| 35 | + self.linksHandler = function() { |
| 36 | + |
| 37 | + var self = {}; |
| 38 | + |
| 39 | + /** |
| 40 | + * Whether or not the handler is enabled for the site. |
| 41 | + * |
| 42 | + * @return {Boolean} |
| 43 | + */ |
| 44 | + self.isEnabled = function() { |
| 45 | + return true; |
| 46 | + }; |
| 47 | + |
| 48 | + /** |
| 49 | + * Get actions to perform with the link. |
| 50 | + * |
| 51 | + * @param {String} url URL to treat. |
| 52 | + * @return {Object[]} List of actions. See {@link $mmContentLinksDelegate#registerLinkHandler}. |
| 53 | + */ |
| 54 | + self.getActions = function(url) { |
| 55 | + // Check it's a user URL. |
| 56 | + if (url.indexOf('grade/report/user') == -1 && |
| 57 | + (url.indexOf('/user/view.php') > -1 || url.indexOf('/user/profile.php') > -1)) { |
| 58 | + var params = $mmUtil.extractUrlParams(url); |
| 59 | + if (typeof params.id != 'undefined') { |
| 60 | + // Return actions. |
| 61 | + return [{ |
| 62 | + message: 'mm.core.view', |
| 63 | + icon: 'ion-eye', |
| 64 | + action: function(siteId) { |
| 65 | + var stateParams = { |
| 66 | + courseid: params.course, |
| 67 | + userid: parseInt(params.id, 10) |
| 68 | + }; |
| 69 | + $mmContentLinksHelper.goInSite('site.mm_user-profile', stateParams, siteId); |
| 70 | + } |
| 71 | + }]; |
| 72 | + } |
| 73 | + } |
| 74 | + return []; |
| 75 | + }; |
| 76 | + |
| 77 | + return self; |
| 78 | + }; |
| 79 | + |
| 80 | + return self; |
| 81 | +}); |
0 commit comments