Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 1 addition & 39 deletions www/addons/mod_resource/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ angular.module('mm.addons.mod_resource')
* @ngdoc controller
* @name mmaModResourceIndexCtrl
*/
.controller('mmaModResourceIndexCtrl', function($scope, $stateParams, $mmUtil, $mmaModResource, $log, $mmApp, $mmCourse, $timeout,
mmaModResourceComponent) {
.controller('mmaModResourceIndexCtrl', function($scope, $stateParams, $mmUtil, $mmaModResource, $log, $mmApp, $mmCourse, $timeout) {
$log = $log.getInstance('mmaModResourceIndexCtrl');

var module = $stateParams.module || {},
courseid = $stateParams.courseid;

$scope.title = module.name;
$scope.description = module.description;
$scope.component = mmaModResourceComponent;
$scope.componentId = module.id;
$scope.externalUrl = module.url;
$scope.mode = false;
$scope.loaded = false;
Expand Down Expand Up @@ -59,29 +56,6 @@ angular.module('mm.addons.mod_resource')
$mmaModResource.logView(module.instance).then(function() {
$mmCourse.checkModuleCompletion(courseid, module.completionstatus);
});
if (downloadFailed && $mmApp.isOnline()) {
// We could load the main file but the download failed. Show error message.
$mmUtil.showErrorModal('mm.core.errordownloadingsomefiles', true);
}
}).catch(function() {
$mmUtil.showErrorModal('mma.mod_resource.errorwhileloadingthecontent', true);
}).finally(function() {
$scope.loaded = true;
});
});
} else if ($mmaModResource.isDisplayedInline(module)) {
var downloadFailed = false;
return $mmaModResource.downloadAllContent(module).catch(function(err) {
// Mark download as failed but go on since the main files could have been downloaded.
downloadFailed = true;
}).finally(function() {
$mmaModResource.getResourceHtml(module.contents, module.id).then(function(content) {
$scope.mode = 'inline';
$scope.content = content;
$mmaModResource.logView(module.instance).then(function() {
$mmCourse.checkModuleCompletion(courseid, module.completionstatus);
});

if (downloadFailed && $mmApp.isOnline()) {
// We could load the main file but the download failed. Show error message.
$mmUtil.showErrorModal('mm.core.errordownloadingsomefiles', true);
Expand Down Expand Up @@ -119,18 +93,6 @@ angular.module('mm.addons.mod_resource')
}
}

// Event sent by the directive mmaModResourceHtmlLink when we click an HTML link.
$scope.$on('mmaModResourceHtmlLinkClicked', function(e, target) {
$scope.loaded = false;
$mmaModResource.getResourceHtml(module.contents, module.id, target).then(function(content) {
$scope.content = content;
}).catch(function() {
$mmUtil.showErrorModal('mma.mod_resource.errorwhileloadingthecontent', true);
}).finally(function() {
$scope.loaded = true;
});
});

$scope.doRefresh = function() {
$mmaModResource.invalidateContent(module.id).then(function() {
return fetchContent();
Expand Down
3 changes: 3 additions & 0 deletions www/addons/mod_resource/directives/html_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ angular.module('mm.addons.mod_resource')
* @module mm.addons.mod_resource
* @ngdoc directive
* @name mmaModResourceHtmlLink
*
* @deprecated since version 2.10
* This function was used to show resources inline
*/
.directive('mmaModResourceHtmlLink', function() {
return {
Expand Down
25 changes: 10 additions & 15 deletions www/addons/mod_resource/services/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ angular.module('mm.addons.mod_resource')
* @param {Number} moduleId The module ID.
* @param {String} [target] The HTML file that the user wants to open, if not defined uses the main file.
* @return {Promise}
*
* @deprecated since version 2.10
* This function was used to show resources inline
*/
self.getResourceHtml = function(contents, moduleId, target) {
var indexUrl,
Expand Down Expand Up @@ -262,18 +265,12 @@ angular.module('mm.addons.mod_resource')
* @return {Boolean}
*/
self.isDisplayedInIframe = function(module) {
var inline = self.isDisplayedInline(module);

if (inline && $mmFS.isAvailable()) {
for (var i = 0; i < module.contents.length; i++) {
var ext = $mmFS.getFileExtension(module.contents[i].filename);
if (ext == 'js' || ext == 'swf' || ext == 'css') {
return true;
}
}
if (!module.contents.length) {
return false;
}
var ext = $mmFS.getFileExtension(module.contents[0].filename);

return false;
return (ext === 'htm' || ext === 'html') && $mmFS.isAvailable();
};

/**
Expand All @@ -284,13 +281,11 @@ angular.module('mm.addons.mod_resource')
* @name $mmaModResource#isDisplayedInline
* @param {Object} module The module object.
* @return {Boolean}
*
* @deprecated since version 2.10
*/
self.isDisplayedInline = function(module) {
if (!module.contents.length) {
return false;
}
var ext = $mmFS.getFileExtension(module.contents[0].filename);
return ext === 'htm' || ext === 'html';
return self.isDisplayedInIframe(module);
};

/**
Expand Down
4 changes: 0 additions & 4 deletions www/addons/mod_resource/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
<mm-iframe src="src"></mm-iframe>
</div>

<div ng-if="mode == 'inline'">
<mm-format-text class="mm-content-with-float" watch="true" component="{{ component }}" component-id="{{ componentId }}">{{ content }}</mm-format-text>
</div>

<div ng-if="mode == 'external'">
<a ng-click="open()" class="button button-block"><i class="icon ion-document"></i> {{ 'mma.mod_resource.openthefile' | translate }}</a>
</div>
Expand Down