Skip to content

Commit 879c48c

Browse files
committed
MOBILE-1357 user: Add user content link handler
1 parent e1f0d18 commit 879c48c

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

www/core/components/user/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ angular.module('mm.core.user', [])
1616

1717
.value('mmUserProfileState', 'site.mm_user-profile')
1818

19-
.config(function($stateProvider) {
19+
.config(function($stateProvider, $mmContentLinksDelegateProvider) {
2020

2121
$stateProvider
2222

@@ -34,6 +34,9 @@ angular.module('mm.core.user', [])
3434
}
3535
});
3636

37+
// Register content links handler.
38+
$mmContentLinksDelegateProvider.registerLinkHandler('mmUser', '$mmUserHandlers.linksHandler');
39+
3740
})
3841

3942
.run(function($mmEvents, mmCoreEventLogin, mmCoreEventSiteUpdated, $mmUserDelegate, $mmSite, mmCoreEventUserDeleted, $mmUser) {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

Comments
 (0)