From c966ad60e718f6cf96b7224c9db501363a7c7dc9 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 16 May 2018 16:46:00 -0400 Subject: [PATCH] (js) Fix download of exported folders under iOS Whenever possible, we no longer rely on the FileSaver.js library to download zip archives. Instead, we do a simple GET on the resource by changing the window location. --- NEWS | 2 ++ .../js/Common/Resource.service.js | 16 +++++++++++++--- .../js/Contacts/AddressBook.service.js | 7 ++++++- .../js/Mailer/Mailbox.service.js | 2 +- .../js/Scheduler/Calendar.service.js | 2 +- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index fc891a030..17d7418f8 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ Enhancements - [web] show current ordering setting in lists - [web] remove invalid occurrences when modifying a recurrent event - [web] updated Angular Material to version 1.1.9 + - [web] allow mail flag addition/edition on mobile Bug fixes - [core] properly update the last-modified attribute (#4313) @@ -14,6 +15,7 @@ Bug fixes - [web] prevent deletion of special folders using del key - [web] fixed SAML2 session timeout handling during XHR requests - [web] fixed renaming a folder under iOS + - [web] fixed download of exported folders under iOS - [eas] improved alarms syncing with EAS devices (#4351) - [eas] avoid potential cache update when breaking sync queries (#4422) diff --git a/UI/WebServerResources/js/Common/Resource.service.js b/UI/WebServerResources/js/Common/Resource.service.js index 10977044e..6cca6434e 100644 --- a/UI/WebServerResources/js/Common/Resource.service.js +++ b/UI/WebServerResources/js/Common/Resource.service.js @@ -11,10 +11,11 @@ * @param {String} path - the base path of the external resource * @param {Object} options - extra attributes to be associated to the object */ - function Resource($http, $q, path, activeUser, options) { + function Resource($http, $q, $window, path, activeUser, options) { angular.extend(this, { _http: $http, _q: $q, + _window: $window, _path: path, _activeUser: activeUser }); @@ -28,9 +29,9 @@ * @desc The factory we'll use to register with Angular. * @return a new Resource object */ - Resource.$factory = ['$http', '$q', function($http, $q) { + Resource.$factory = ['$http', '$q', '$window', function($http, $q, $window) { return function(path, activeUser, options) { - return new Resource($http, $q, path, activeUser, options); + return new Resource($http, $q, $window, path, activeUser, options); }; }]; @@ -232,6 +233,15 @@ }); }; + Resource.prototype.open = function(id, action) { + var path = [this._path]; + if (id) path.push(id); + if (action) path.push(action); + path = _.compact(_.flatten(path)).join('/'); + + this._window.location.href = path; + }; + /** * @function remove * @memberof Resource.prototype diff --git a/UI/WebServerResources/js/Contacts/AddressBook.service.js b/UI/WebServerResources/js/Contacts/AddressBook.service.js index 1e0446c73..fe4578f32 100644 --- a/UI/WebServerResources/js/Contacts/AddressBook.service.js +++ b/UI/WebServerResources/js/Contacts/AddressBook.service.js @@ -723,7 +723,12 @@ data = { uids: _.map(selectedCards, 'id') }; } - return AddressBook.$$resource.download(this.id, 'export', data, options); + if (data) { + return AddressBook.$$resource.download(this.id, 'export', data, options); + } + else { + return AddressBook.$$resource.open(this.id, 'export', data, options); + } }; /** diff --git a/UI/WebServerResources/js/Mailer/Mailbox.service.js b/UI/WebServerResources/js/Mailer/Mailbox.service.js index 6f7e9a89e..099df4986 100644 --- a/UI/WebServerResources/js/Mailer/Mailbox.service.js +++ b/UI/WebServerResources/js/Mailer/Mailbox.service.js @@ -683,7 +683,7 @@ options = { filename: this.name + '.zip' }; - return Mailbox.$$resource.download(this.id, 'exportFolder', null, options); + return Mailbox.$$resource.open(this.id, 'exportFolder', null, options); }; /** diff --git a/UI/WebServerResources/js/Scheduler/Calendar.service.js b/UI/WebServerResources/js/Scheduler/Calendar.service.js index d01311d83..5fc3c2313 100644 --- a/UI/WebServerResources/js/Scheduler/Calendar.service.js +++ b/UI/WebServerResources/js/Scheduler/Calendar.service.js @@ -554,7 +554,7 @@ filename: this.name + '.ics' }; - return Calendar.$$resource.download(this.id + '.ics', 'export', null, options); + return Calendar.$$resource.open(this.id + '.ics', 'export', null, options); }; /**