diff options
author | Michael Jobst <mjobst+github@tecratech.de> | 2016-11-21 15:03:45 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2016-12-23 16:56:55 +0100 |
commit | 969c19b2e926331e2686208507c2643107caf5a1 (patch) | |
tree | c0c03ac7bbcdc7760e97e35ddacef8919ed527e6 /apps/files/js | |
parent | 56c016946d0695a62e418839cf19786a223b4ae7 (diff) | |
download | nextcloud-server-969c19b2e926331e2686208507c2643107caf5a1.tar.gz nextcloud-server-969c19b2e926331e2686208507c2643107caf5a1.zip |
Fixed size issues on main detail view and disappearing of share recipients (#26603)
* fixed size issues on main detail view and disappearing of share recipients
* Changes due to code comments
* Moved reloadProperties() to FileInfoModel
* Solved Scrutinizer issues
* Bugfix: undefined value used on error
* check if options are set for FileInfoModel.initialize()
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/files/js')
-rw-r--r-- | apps/files/js/fileinfomodel.js | 47 | ||||
-rw-r--r-- | apps/files/js/filelist.js | 12 | ||||
-rw-r--r-- | apps/files/js/mainfileinfodetailview.js | 13 | ||||
-rw-r--r-- | apps/files/js/tagsplugin.js | 17 |
4 files changed, 76 insertions, 13 deletions
diff --git a/apps/files/js/fileinfomodel.js b/apps/files/js/fileinfomodel.js index de1b143a160..9d1eac31940 100644 --- a/apps/files/js/fileinfomodel.js +++ b/apps/files/js/fileinfomodel.js @@ -36,10 +36,18 @@ path: '' }, - initialize: function(data) { + _filesClient: null, + + initialize: function(data, options) { if (!_.isUndefined(data.id)) { data.id = parseInt(data.id, 10); } + + if( options ){ + if (options.filesClient) { + this._filesClient = options.filesClient; + } + } }, /** @@ -73,6 +81,42 @@ */ getFullPath: function() { return OC.joinPaths(this.get('path'), this.get('name')); + }, + + /** + * Reloads missing properties from server and set them in the model. + * @param properties array of properties to be reloaded + * @return ajax call object + */ + reloadProperties: function(properties) { + if( !this._filesClient ){ + return; + } + + var self = this; + var deferred = $.Deferred(); + + var targetPath = OC.joinPaths(this.get('path') + '/', this.get('name')); + + this._filesClient.getFileInfo(targetPath, { + properties: properties + }) + .then(function(status, data) { + // the following lines should be extracted to a mapper + + if( properties.indexOf(OC.Files.Client.PROPERTY_GETCONTENTLENGTH) !== -1 + || properties.indexOf(OC.Files.Client.PROPERTY_SIZE) !== -1 ) { + self.set('size', data.size); + } + + deferred.resolve(status, data); + }) + .fail(function(status) { + OC.Notification.showTemporary(t('files', 'Could not load info for file "{file}"', {file: self.get('name')})); + deferred.reject(status); + }); + + return deferred.promise(); } }); @@ -82,4 +126,3 @@ OCA.Files.FileInfoModel = FileInfoModel; })(OC, OCA); - diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index a8daeadfd26..cd0eb390ee3 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -442,7 +442,9 @@ // In the future the FileList should work with Backbone.Collection // and contain existing models that can be used. // This method would in the future simply retrieve the matching model from the collection. - var model = new OCA.Files.FileInfoModel(this.elementToFile($tr)); + var model = new OCA.Files.FileInfoModel(this.elementToFile($tr), { + filesClient: this.filesClient + }); if (!model.get('path')) { model.set('path', this.getCurrentDirectory(), {silent: true}); } @@ -891,11 +893,14 @@ mimetype: $el.attr('data-mime'), mtime: parseInt($el.attr('data-mtime'), 10), type: $el.attr('data-type'), - size: parseInt($el.attr('data-size'), 10), etag: $el.attr('data-etag'), permissions: parseInt($el.attr('data-permissions'), 10), hasPreview: $el.attr('data-has-preview') === 'true' }; + var size = $el.attr('data-size'); + if (size) { + data.size = parseInt(size, 10); + } var icon = $el.attr('data-icon'); if (icon) { data.icon = icon; @@ -1029,7 +1034,7 @@ * Returns whether the given file info must be hidden * * @param {OC.Files.FileInfo} fileInfo file info - * + * * @return {boolean} true if the file is a hidden file, false otherwise */ _isHiddenFile: function(file) { @@ -2828,7 +2833,6 @@ }); uploader.on('fail', function(e, data) { self._uploader.log('filelist handle fileuploadfail', e, data); - self._uploads = []; //if user pressed cancel hide upload chrome diff --git a/apps/files/js/mainfileinfodetailview.js b/apps/files/js/mainfileinfodetailview.js index 1a69528fd17..e815fa70ecb 100644 --- a/apps/files/js/mainfileinfodetailview.js +++ b/apps/files/js/mainfileinfodetailview.js @@ -130,6 +130,19 @@ if (this.model) { this.model.on('change', this._onModelChanged, this); } + + if (this.model) { + var properties = []; + if( !this.model.has('size') ) { + properties.push(OC.Files.Client.PROPERTY_SIZE); + properties.push(OC.Files.Client.PROPERTY_GETCONTENTLENGTH); + } + + if( properties.length > 0){ + this.model.reloadProperties(properties); + } + } + this.render(); }, diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js index 3c0a231d003..9bb4ba33598 100644 --- a/apps/files/js/tagsplugin.js +++ b/apps/files/js/tagsplugin.js @@ -12,6 +12,11 @@ (function(OCA) { + _.extend(OC.Files.Client, { + PROPERTY_TAGS: '{' + OC.Files.Client.NS_OWNCLOUD + '}tags', + PROPERTY_FAVORITE: '{' + OC.Files.Client.NS_OWNCLOUD + '}favorite' + }); + var TEMPLATE_FAVORITE_ACTION = '<a href="#" ' + 'class="action action-favorite {{#isFavorite}}permanent{{/isFavorite}}">' + @@ -162,24 +167,22 @@ return fileInfo; }; - var NS_OC = 'http://owncloud.org/ns'; - var oldGetWebdavProperties = fileList._getWebdavProperties; fileList._getWebdavProperties = function() { var props = oldGetWebdavProperties.apply(this, arguments); - props.push('{' + NS_OC + '}tags'); - props.push('{' + NS_OC + '}favorite'); + props.push(OC.Files.Client.PROPERTY_TAGS); + props.push(OC.Files.Client.PROPERTY_FAVORITE); return props; }; fileList.filesClient.addFileInfoParser(function(response) { var data = {}; var props = response.propStat[0].properties; - var tags = props['{' + NS_OC + '}tags']; - var favorite = props['{' + NS_OC + '}favorite']; + var tags = props[OC.Files.Client.PROPERTY_TAGS]; + var favorite = props[OC.Files.Client.PROPERTY_FAVORITE]; if (tags && tags.length) { tags = _.chain(tags).filter(function(xmlvalue) { - return (xmlvalue.namespaceURI === NS_OC && xmlvalue.nodeName.split(':')[1] === 'tag'); + return (xmlvalue.namespaceURI === OC.Files.Client.NS_OWNCLOUD && xmlvalue.nodeName.split(':')[1] === 'tag'); }).map(function(xmlvalue) { return xmlvalue.textContent || xmlvalue.text; }).value(); |