diff options
Diffstat (limited to 'apps/files/js')
-rw-r--r-- | apps/files/js/file-upload.js | 84 | ||||
-rw-r--r-- | apps/files/js/fileinfomodel.js | 47 | ||||
-rw-r--r-- | apps/files/js/filelist.js | 29 | ||||
-rw-r--r-- | apps/files/js/mainfileinfodetailview.js | 20 | ||||
-rw-r--r-- | apps/files/js/newfilemenu.js | 10 | ||||
-rw-r--r-- | apps/files/js/tagsplugin.js | 17 |
6 files changed, 111 insertions, 96 deletions
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index b3a59b54241..0fbf3f559fe 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -130,6 +130,16 @@ OC.FileUpload.prototype = { }, /** + * Get full path for the target file, + * including relative path and file name. + * + * @return {String} full path + */ + getFullFilePath: function() { + return OC.joinPaths(this.getFullPath(), this.getFile().name); + }, + + /** * Returns conflict resolution mode. * * @return {int} conflict mode @@ -148,15 +158,6 @@ OC.FileUpload.prototype = { this._conflictMode = mode; }, - /** - * Returns whether the upload is in progress - * - * @return {boolean} - */ - isPending: function() { - return this.data.state() === 'pending'; - }, - deleteUpload: function() { delete this.data.jqXHR; }, @@ -508,9 +509,10 @@ OC.Uploader.prototype = _.extend({ return; } // retrieve more info about this file - this.filesClient.getFileInfo(fileUpload.getFullPath()).then(function(status, fileInfo) { + this.filesClient.getFileInfo(fileUpload.getFullFilePath()).then(function(status, fileInfo) { var original = fileInfo; var replacement = file; + original.directory = original.path; OC.dialogs.fileexists(fileUpload, original, replacement, self); }); }, @@ -550,21 +552,6 @@ OC.Uploader.prototype = _.extend({ OC.Notification.showTemporary(t('files', 'Upload cancelled.'), {timeout: 10}); }, 500), /** - * Checks the currently known uploads. - * returns true if any hxr has the state 'pending' - * @returns {boolean} - */ - isProcessing:function() { - var count = 0; - - jQuery.each(this._uploads, function(i, upload) { - if (upload.isPending()) { - count++; - } - }); - return count > 0; - }, - /** * callback for the conflicts dialog */ onCancel:function() { @@ -1029,43 +1016,9 @@ OC.Uploader.prototype = _.extend({ bufferIndex = (bufferIndex + 1) % bufferSize; } var smoothRemainingSeconds = (bufferTotal / bufferSize); //seconds - var date = new Date(smoothRemainingSeconds * 1000); - var timeStringDesktop = ""; - var timeStringMobile = ""; - if(date.getUTCHours() > 0){ - timeStringDesktop = t('files', '{hours}:{minutes}:{seconds} hour{plural_s} left' , { - hours:date.getUTCHours(), - minutes: ('0' + date.getUTCMinutes()).slice(-2), - seconds: ('0' + date.getUTCSeconds()).slice(-2), - plural_s: ( smoothRemainingSeconds === 3600 ? "": "s") // 1 hour = 1*60m*60s = 3600s - }); - timeStringMobile = t('files', '{hours}:{minutes}h' , { - hours:date.getUTCHours(), - minutes: ('0' + date.getUTCMinutes()).slice(-2), - seconds: ('0' + date.getUTCSeconds()).slice(-2) - }); - } else if(date.getUTCMinutes() > 0){ - timeStringDesktop = t('files', '{minutes}:{seconds} minute{plural_s} left' , { - minutes: date.getUTCMinutes(), - seconds: ('0' + date.getUTCSeconds()).slice(-2), - plural_s: (smoothRemainingSeconds === 60 ? "": "s") // 1 minute = 1*60s = 60s - }); - timeStringMobile = t('files', '{minutes}:{seconds}m' , { - minutes: date.getUTCMinutes(), - seconds: ('0' + date.getUTCSeconds()).slice(-2) - }); - } else if(date.getUTCSeconds() > 0){ - timeStringDesktop = t('files', '{seconds} second{plural_s} left' , { - seconds: date.getUTCSeconds(), - plural_s: (smoothRemainingSeconds === 1 ? "": "s") // 1 second = 1s = 1s - }); - timeStringMobile = t('files', '{seconds}s' , {seconds: date.getUTCSeconds()}); - } else { - timeStringDesktop = t('files', 'Any moment now...'); - timeStringMobile = t('files', 'Soon...'); - } - $('#uploadprogressbar .label .mobile').text(timeStringMobile); - $('#uploadprogressbar .label .desktop').text(timeStringDesktop); + var h = moment.duration(smoothRemainingSeconds, "seconds").humanize(); + $('#uploadprogressbar .label .mobile').text(h); + $('#uploadprogressbar .label .desktop').text(h); $('#uploadprogressbar').attr('original-title', t('files', '{loadedSize} of {totalSize} ({bitrate})' , { loadedSize: humanFileSize(data.loaded), @@ -1157,13 +1110,6 @@ OC.Uploader.prototype = _.extend({ } } - // warn user not to leave the page while upload is in progress - $(window).on('beforeunload', function(e) { - if (self.isProcessing()) { - return t('files', 'File upload is in progress. Leaving the page now will cancel the upload.'); - } - }); - //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used) if (navigator.userAgent.search(/konqueror/i) === -1) { this.$uploadEl.attr('multiple', 'multiple'); 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..3a59da53517 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) { @@ -1175,7 +1180,7 @@ var innernameSpan = $('<span></span>').addClass('innernametext').text(basename); if (path && path !== '/') { - var conflictingItems = this.$fileList.find('tr[data-file="' + name.replace( /(:|\.|\[|\]|,|=)/g, "\\$1") + '"]'); + var conflictingItems = this.$fileList.find('tr[data-file="' + this._jqSelEscape(name) + '"]'); if (conflictingItems.length !== 0) { if (conflictingItems.length === 1) { // Update the path on the first conflicting item @@ -1261,6 +1266,14 @@ return tr; }, + /* escape a selector expression for jQuery */ + _jqSelEscape: function (expression) { + if (expression) { + return expression.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~]/g, '\\$&'); + } + return null; + }, + /** * Adds an entry to the files array and also into the DOM * in a sorted manner. @@ -2465,6 +2478,11 @@ if (!_.isArray(file)) { file = [file]; } + if (file.length === 1) { + _.defer(function() { + this.showDetailsView(file[0]); + }.bind(this)); + } this.highlightFiles(file, function($tr) { $tr.addClass('searchresult'); $tr.one('hover', function() { @@ -2828,7 +2846,6 @@ }); uploader.on('fail', function(e, data) { self._uploader.log('filelist handle fileuploadfail', e, data); - self._uploads = []; //if user pressed cancel hide upload chrome @@ -2939,7 +2956,7 @@ this._newFileMenu = new OCA.Files.NewFileMenu({ fileList: this }); - $('body').append(this._newFileMenu.$el); + $('.actions').append(this._newFileMenu.$el); } this._newFileMenu.showAt($target); diff --git a/apps/files/js/mainfileinfodetailview.js b/apps/files/js/mainfileinfodetailview.js index e9259f75ba1..e815fa70ecb 100644 --- a/apps/files/js/mainfileinfodetailview.js +++ b/apps/files/js/mainfileinfodetailview.js @@ -20,9 +20,8 @@ '</a>' + '</div>' + ' <div class="file-details ellipsis">' + - ' <a href="#" ' + - ' class="action action-favorite favorite">' + - ' <img class="svg" alt="{{starAltText}}" src="{{starIcon}}" />' + + ' <a href="#" class="action action-favorite favorite permanent">' + + ' <span class="icon {{starClass}}" title="{{starAltText}}"></span>' + ' </a>' + ' {{#if hasSize}}<span class="size" title="{{altSize}}">{{size}}</span>, {{/if}}<span class="date live-relative-timestamp" data-timestamp="{{timestamp}}" title="{{altDate}}">{{date}}</span>' + ' </div>' + @@ -131,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(); }, @@ -155,7 +167,7 @@ timestamp: this.model.get('mtime'), date: OC.Util.relativeModifiedDate(this.model.get('mtime')), starAltText: isFavorite ? t('files', 'Favorited') : t('files', 'Favorite'), - starIcon: OC.imagePath('core', isFavorite ? 'actions/starred' : 'actions/star'), + starClass: isFavorite ? 'icon-starred' : 'icon-star', permalink: this._makePermalink(this.model.get('id')), permalinkTitle: t('files', 'Copy local link') })); diff --git a/apps/files/js/newfilemenu.js b/apps/files/js/newfilemenu.js index 75c4cdcc0ba..e4023c62342 100644 --- a/apps/files/js/newfilemenu.js +++ b/apps/files/js/newfilemenu.js @@ -38,7 +38,8 @@ */ var NewFileMenu = OC.Backbone.View.extend({ tagName: 'div', - className: 'newFileMenu popovermenu bubble hidden open menu', + // Menu is opened by default because it's rendered on "add-button" click + className: 'newFileMenu popovermenu bubble menu open menu-left', events: { 'click .menuitem': '_onClickAction' @@ -235,13 +236,6 @@ */ showAt: function($target) { this.render(); - var targetOffset = $target.offset(); - this.$el.css({ - left: targetOffset.left, - top: targetOffset.top + $target.height() - }); - this.$el.removeClass('hidden'); - OC.showMenu(null, this.$el); } }); 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(); |