Skip to content

Commit 841b85c

Browse files
committed
Merge pull request #374 from dpalou/MOBILE-1404
Mobile 1404
2 parents 5b44a8d + 1f3f051 commit 841b85c

File tree

29 files changed

+551
-54
lines changed

29 files changed

+551
-54
lines changed

www/addons/grades/services/handlers.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ angular.module('mm.addons.grades')
191191
*/
192192
self.getActions = function(siteIds, url) {
193193
// Check it's a grade URL.
194-
if (url.indexOf('/grade/report/user/index.php') > -1) {
194+
if (typeof self.handles(url) != 'undefined') {
195195
var params = $mmUtil.extractUrlParams(url);
196196
if (typeof params.id != 'undefined') {
197197
var courseId = parseInt(params.id, 10);
@@ -220,6 +220,19 @@ angular.module('mm.addons.grades')
220220
return [];
221221
};
222222

223+
/**
224+
* Check if the URL is handled by this handler. If so, returns the URL of the site.
225+
*
226+
* @param {String} url URL to check.
227+
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
228+
*/
229+
self.handles = function(url) {
230+
var position = url.indexOf('/grade/report/user/index.php');
231+
if (position > -1) {
232+
return url.substr(0, position);
233+
}
234+
};
235+
223236
return self;
224237
};
225238

www/addons/messages/services/handlers.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ angular.module('mm.addons.messages')
312312
*/
313313
self.getActions = function(siteIds, url) {
314314
// Check it's a messages URL.
315-
if (url.indexOf('/message/index.php') > -1) {
315+
if (typeof self.handles(url) != 'undefined') {
316316
// Pass false because all sites should have the same siteurl.
317317
return $mmContentLinksHelper.filterSupportedSites(siteIds, isEnabledForSite, false).then(function(ids) {
318318
if (!ids.length) {
@@ -364,6 +364,19 @@ angular.module('mm.addons.messages')
364364
return [];
365365
};
366366

367+
/**
368+
* Check if the URL is handled by this handler. If so, returns the URL of the site.
369+
*
370+
* @param {String} url URL to check.
371+
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
372+
*/
373+
self.handles = function(url) {
374+
var position = url.indexOf('/message/index.php');
375+
if (position > -1) {
376+
return url.substr(0, position);
377+
}
378+
};
379+
367380
return self;
368381
};
369382

www/addons/mod_assign/services/handlers.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,25 @@ angular.module('mm.addons.mod_assign')
106106
*/
107107
self.getActions = function(siteIds, url, courseId) {
108108
// Check it's an assign URL.
109-
if (url.indexOf('/mod/assign/view.php') > -1) {
109+
if (typeof self.handles(url) != 'undefined') {
110110
return $mmContentLinksHelper.treatModuleIndexUrl(siteIds, url, isEnabled, courseId);
111111
}
112112
return $q.when([]);
113113
};
114114

115+
/**
116+
* Check if the URL is handled by this handler. If so, returns the URL of the site.
117+
*
118+
* @param {String} url URL to check.
119+
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
120+
*/
121+
self.handles = function(url) {
122+
var position = url.indexOf('/mod/assign/view.php');
123+
if (position > -1) {
124+
return url.substr(0, position);
125+
}
126+
};
127+
115128
return self;
116129
};
117130

www/addons/mod_book/services/handlers.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,25 @@ angular.module('mm.addons.mod_book')
173173
*/
174174
self.getActions = function(siteIds, url, courseId) {
175175
// Check it's a book URL.
176-
if (url.indexOf('/mod/book/view.php') > -1) {
176+
if (typeof self.handles(url) != 'undefined') {
177177
return $mmContentLinksHelper.treatModuleIndexUrl(siteIds, url, isEnabled, courseId);
178178
}
179179
return $q.when([]);
180180
};
181181

182+
/**
183+
* Check if the URL is handled by this handler. If so, returns the URL of the site.
184+
*
185+
* @param {String} url URL to check.
186+
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
187+
*/
188+
self.handles = function(url) {
189+
var position = url.indexOf('/mod/book/view.php');
190+
if (position > -1) {
191+
return url.substr(0, position);
192+
}
193+
};
194+
182195
return self;
183196
};
184197

www/addons/mod_chat/services/handlers.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,25 @@ angular.module('mm.addons.mod_chat')
101101
*/
102102
self.getActions = function(siteIds, url, courseId) {
103103
// Check it's a chat URL.
104-
if (url.indexOf('/mod/chat/view.php') > -1) {
104+
if (typeof self.handles(url) != 'undefined') {
105105
return $mmContentLinksHelper.treatModuleIndexUrl(siteIds, url, isEnabled, courseId);
106106
}
107107
return $q.when([]);
108108
};
109109

110+
/**
111+
* Check if the URL is handled by this handler. If so, returns the URL of the site.
112+
*
113+
* @param {String} url URL to check.
114+
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
115+
*/
116+
self.handles = function(url) {
117+
var position = url.indexOf('/mod/chat/view.php');
118+
if (position > -1) {
119+
return url.substr(0, position);
120+
}
121+
};
122+
110123
return self;
111124
};
112125

www/addons/mod_choice/services/handlers.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,25 @@ angular.module('mm.addons.mod_choice')
102102
*/
103103
self.getActions = function(siteIds, url, courseId) {
104104
// Check it's a choice URL.
105-
if (url.indexOf('/mod/choice/view.php') > -1) {
105+
if (typeof self.handles(url) != 'undefined') {
106106
return $mmContentLinksHelper.treatModuleIndexUrl(siteIds, url, isEnabled, courseId);
107107
}
108108
return $q.when([]);
109109
};
110110

111+
/**
112+
* Check if the URL is handled by this handler. If so, returns the URL of the site.
113+
*
114+
* @param {String} url URL to check.
115+
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
116+
*/
117+
self.handles = function(url) {
118+
var position = url.indexOf('/mod/choice/view.php');
119+
if (position > -1) {
120+
return url.substr(0, position);
121+
}
122+
};
123+
111124
return self;
112125
};
113126

www/addons/mod_folder/services/handlers.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,25 @@ angular.module('mm.addons.mod_folder')
168168
*/
169169
self.getActions = function(siteIds, url, courseId) {
170170
// Check it's a folder URL.
171-
if (url.indexOf('/mod/folder/view.php') > -1) {
171+
if (typeof self.handles(url) != 'undefined') {
172172
return $mmContentLinksHelper.treatModuleIndexUrl(siteIds, url, isEnabled, courseId);
173173
}
174174
return $q.when([]);
175175
};
176176

177+
/**
178+
* Check if the URL is handled by this handler. If so, returns the URL of the site.
179+
*
180+
* @param {String} url URL to check.
181+
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
182+
*/
183+
self.handles = function(url) {
184+
var position = url.indexOf('/mod/folder/view.php');
185+
if (position > -1) {
186+
return url.substr(0, position);
187+
}
188+
};
189+
177190
return self;
178191
};
179192

www/addons/mod_forum/services/handlers.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ angular.module('mm.addons.mod_forum')
8282
*/
8383
self.linksHandler = function() {
8484

85-
var self = {};
85+
var self = {},
86+
patterns = ['/mod/forum/view.php', '/mod/forum/discuss.php'];
8687

8788
/**
8889
* Whether or not the handler is enabled for a certain site.
@@ -122,13 +123,16 @@ angular.module('mm.addons.mod_forum')
122123
*/
123124
self.getActions = function(siteIds, url, courseId) {
124125
// Check it's a forum URL.
125-
if (url.indexOf('/mod/forum/view.php') > -1) {
126+
if (url.indexOf(patterns[0]) > -1) {
126127
// Forum index.
127128
return $mmContentLinksHelper.treatModuleIndexUrl(siteIds, url, isIndexEnabled, courseId);
128-
} else if (url.indexOf('/mod/forum/discuss.php') > -1) {
129+
} else if (url.indexOf(patterns[1]) > -1) {
129130
// Forum discussion.
130131
var params = $mmUtil.extractUrlParams(url);
131132
if (params.d != 'undefined') {
133+
// If courseId is not set we check if it's set in the URL as a param.
134+
courseId = courseId || params.courseid || params.cid;
135+
132136
// Pass false because all sites should have the same siteurl.
133137
return $mmContentLinksHelper.filterSupportedSites(siteIds, isDiscEnabled, false, courseId).then(function(ids) {
134138
if (!ids.length) {
@@ -154,6 +158,21 @@ angular.module('mm.addons.mod_forum')
154158
return $q.when([]);
155159
};
156160

161+
/**
162+
* Check if the URL is handled by this handler. If so, returns the URL of the site.
163+
*
164+
* @param {String} url URL to check.
165+
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
166+
*/
167+
self.handles = function(url) {
168+
for (var i = 0; i < patterns.length; i++) {
169+
var position = url.indexOf(patterns[i]);
170+
if (position > -1) {
171+
return url.substr(0, position);
172+
}
173+
}
174+
};
175+
157176
return self;
158177
};
159178

www/addons/mod_glossary/services/handlers.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ angular.module('mm.addons.mod_glossary')
7878
*/
7979
self.linksHandler = function() {
8080

81-
var self = {};
81+
var self = {},
82+
patterns = ['/mod/glossary/view.php', '/mod/glossary/showentry.php'];
8283

8384
/**
8485
* Whether or not the handler is enabled to see glossary index for a certain site.
@@ -136,6 +137,9 @@ angular.module('mm.addons.mod_glossary')
136137
function treatEntryLink(siteIds, url, courseId) {
137138
var params = $mmUtil.extractUrlParams(url);
138139
if (params.eid != 'undefined') {
140+
// If courseId is not set we check if it's set in the URL as a param.
141+
courseId = courseId || params.courseid || params.cid;
142+
139143
// Pass false because all sites should have the same siteurl.
140144
return $mmContentLinksHelper.filterSupportedSites(siteIds, isEntryEnabled, false, courseId).then(function(ids) {
141145
if (!ids.length) {
@@ -184,16 +188,31 @@ angular.module('mm.addons.mod_glossary')
184188
*/
185189
self.getActions = function(siteIds, url, courseId) {
186190
// Check it's a glossary URL.
187-
if (url.indexOf('/mod/glossary/view.php') > -1) {
191+
if (url.indexOf(patterns[0]) > -1) {
188192
// Glossary index.
189193
return $mmContentLinksHelper.treatModuleIndexUrl(siteIds, url, isIndexEnabled, courseId);
190-
} else if (url.indexOf('/mod/glossary/showentry.php') > -1) {
194+
} else if (url.indexOf(patterns[1]) > -1) {
191195
// Glossary entry.
192196
return treatEntryLink(siteIds, url, courseId);
193197
}
194198
return $q.when([]);
195199
};
196200

201+
/**
202+
* Check if the URL is handled by this handler. If so, returns the URL of the site.
203+
*
204+
* @param {String} url URL to check.
205+
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
206+
*/
207+
self.handles = function(url) {
208+
for (var i = 0; i < patterns.length; i++) {
209+
var position = url.indexOf(patterns[i]);
210+
if (position > -1) {
211+
return url.substr(0, position);
212+
}
213+
}
214+
};
215+
197216
return self;
198217
};
199218

www/addons/mod_imscp/services/handlers.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,25 @@ angular.module('mm.addons.mod_imscp')
177177
*/
178178
self.getActions = function(siteIds, url, courseId) {
179179
// Check it's an IMSCP URL.
180-
if (url.indexOf('/mod/imscp/view.php') > -1) {
180+
if (typeof self.handles(url) != 'undefined') {
181181
return $mmContentLinksHelper.treatModuleIndexUrl(siteIds, url, isEnabled, courseId);
182182
}
183183
return $q.when([]);
184184
};
185185

186+
/**
187+
* Check if the URL is handled by this handler. If so, returns the URL of the site.
188+
*
189+
* @param {String} url URL to check.
190+
* @return {String} Site URL. Undefined if the URL doesn't belong to this handler.
191+
*/
192+
self.handles = function(url) {
193+
var position = url.indexOf('/mod/imscp/view.php');
194+
if (position > -1) {
195+
return url.substr(0, position);
196+
}
197+
};
198+
186199
return self;
187200
};
188201

0 commit comments

Comments
 (0)