@@ -28,6 +28,7 @@ angular.module('mm.core')
2828 * @param {Object } file Required. Object with the following attributes:
2929 * 'filename': Name of the file.
3030 * 'fileurl' or 'url': File URL.
31+ * 'filesize': Optional. Size of the file.
3132 * @param {String } [component] Component the file belongs to.
3233 * @param {Number } [componentId] Component ID.
3334 * @param {Boolean } [timemodified] If set, the value will be used to check if the file is outdated.
@@ -94,6 +95,7 @@ angular.module('mm.core')
9495 link : function ( scope , element , attrs ) {
9596 var fileurl = scope . file . fileurl || scope . file . url ,
9697 filename = scope . file . filename ,
98+ filesize = scope . file . filesize ,
9799 timemodified = attrs . timemodified || 0 ,
98100 siteid = $mmSite . getId ( ) ,
99101 component = attrs . component ,
@@ -116,6 +118,7 @@ angular.module('mm.core')
116118 scope . download = function ( e , openAfterDownload ) {
117119 e . preventDefault ( ) ;
118120 e . stopPropagation ( ) ;
121+ var promise ;
119122
120123 if ( scope . isDownloading ) {
121124 return ;
@@ -134,13 +137,17 @@ angular.module('mm.core')
134137 } ) ;
135138 } ) ;
136139 } else {
137- // File doesn't need to be opened, add it to queue.
138- $mmFilepool . invalidateFileByUrl ( siteid , fileurl ) . finally ( function ( ) {
139- scope . isDownloading = true ;
140- $mmFilepool . addToQueueByUrl ( siteid , fileurl , component , componentid , timemodified ) ;
140+ // File doesn't need to be opened (it's a prefetch). Show confirm modal if file size is defined and it's big.
141+ promise = filesize ? $mmUtil . confirmDownloadSize ( filesize ) : $q . when ( ) ;
142+ promise . then ( function ( ) {
143+ // User confirmed, add the file to queue.
144+ $mmFilepool . invalidateFileByUrl ( siteid , fileurl ) . finally ( function ( ) {
145+ scope . isDownloading = true ;
146+ $mmFilepool . addToQueueByUrl ( siteid , fileurl , component , componentid , timemodified ) ;
147+ } ) ;
141148 } ) ;
142149 }
143- }
150+ } ;
144151
145152 scope . $on ( '$destroy' , function ( ) {
146153 if ( observer && observer . off ) {
0 commit comments