diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2015-09-12 14:21:14 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-09-16 07:23:27 +0200 |
commit | f29b51682bc0be785e1a3e4e5901db3255e4a377 (patch) | |
tree | 93375423f13d63a4ca97cc800b8fb981d48432f5 /core/js | |
parent | 4c702aa8fdfb28bea4b021e55e7df5eeeb6999d2 (diff) | |
download | nextcloud-server-f29b51682bc0be785e1a3e4e5901db3255e4a377.tar.gz nextcloud-server-f29b51682bc0be785e1a3e4e5901db3255e4a377.zip |
share and unshare via link (not yet password). also some internal changes to reduce unnecessary rendering
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/share.js | 74 | ||||
-rw-r--r-- | core/js/shareconfigmodel.js | 23 | ||||
-rw-r--r-- | core/js/sharedialogexpirationview.js | 22 | ||||
-rw-r--r-- | core/js/sharedialoglinkshareview.js | 37 | ||||
-rw-r--r-- | core/js/sharedialogresharerinfoview.js | 7 | ||||
-rw-r--r-- | core/js/sharedialogshareelistview.js | 11 | ||||
-rw-r--r-- | core/js/sharedialogview.js | 22 | ||||
-rw-r--r-- | core/js/shareitemmodel.js | 33 |
8 files changed, 121 insertions, 108 deletions
diff --git a/core/js/share.js b/core/js/share.js index bd87ab10d40..6581c401281 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -956,80 +956,6 @@ $(document).ready(function() { permissions); }); - $(document).on('change', '#dropdown #linkCheckbox', function() { - var $dropDown = $('#dropdown'); - var itemType = $dropDown.data('item-type'); - var itemSource = $dropDown.data('item-source'); - var itemSourceName = $dropDown.data('item-source-name'); - var $loading = $dropDown.find('#link .icon-loading-small'); - var $button = $(this); - - if (!$loading.hasClass('hidden')) { - // already in progress - return false; - } - - if (this.checked) { - // Reset password placeholder - $('#linkPassText').attr('placeholder', t('core', 'Choose a password for the public link')); - // Reset link - $('#linkText').val(''); - $('#showPassword').prop('checked', false); - $('#linkPass').hide(); - $('#sharingDialogAllowPublicUpload').prop('checked', false); - $('#expirationCheckbox').prop('checked', false); - $('#expirationDate').hide(); - var expireDateString = ''; - // Create a link - if (oc_appconfig.core.enforcePasswordForPublicLink === false) { - expireDateString = OC.Share.getDefaultExpirationDate(); - $loading.removeClass('hidden'); - $button.addClass('hidden'); - $button.prop('disabled', true); - - OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, itemSourceName, expireDateString, function(data) { - $loading.addClass('hidden'); - $button.removeClass('hidden'); - $button.prop('disabled', false); - OC.Share.showLink(data.token, null, itemSource); - $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares})); - OC.Share.updateIcon(itemType, itemSource); - }); - } else { - $('#linkPass').slideToggle(OC.menuSpeed); - // TODO drop with IE8 drop - if($('html').hasClass('ie8')) { - $('#linkPassText').attr('placeholder', null); - $('#linkPassText').val(''); - } - $('#linkPassText').focus(); - } - if (expireDateString !== '') { - OC.Share.showExpirationDate(expireDateString); - } - } else { - // Delete private link - OC.Share.hideLink(); - $('#expiration').slideUp(OC.menuSpeed); - if ($('#linkText').val() !== '') { - $loading.removeClass('hidden'); - $button.addClass('hidden'); - $button.prop('disabled', true); - OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() { - $loading.addClass('hidden'); - $button.removeClass('hidden'); - $button.prop('disabled', false); - OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = false; - $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares})); - OC.Share.updateIcon(itemType, itemSource); - if (typeof OC.Share.statuses[itemSource] === 'undefined') { - $('#expiration').slideUp(OC.menuSpeed); - } - }); - } - } - }); - $(document).on('click', '#dropdown #linkText', function() { $(this).focus(); $(this).select(); diff --git a/core/js/shareconfigmodel.js b/core/js/shareconfigmodel.js index 98280e01eb6..c6891154c98 100644 --- a/core/js/shareconfigmodel.js +++ b/core/js/shareconfigmodel.js @@ -19,6 +19,8 @@ publicUploadEnabled: false, enforcePasswordForPublicLink: oc_appconfig.core.enforcePasswordForPublicLink, isDefaultExpireDateEnforced: oc_appconfig.core.defaultExpireDateEnforced === true, + isDefaultExpireDateEnabled: oc_appconfig.core.defaultExpireDateEnabled === true, + isRemoteShareAllowed: oc_appconfig.core.remoteShareAllowed, defaultExpireDate: oc_appconfig.core.defaultExpireDate, isResharingAllowed: oc_appconfig.core.resharingAllowed }, @@ -48,13 +50,6 @@ /** * @returns {boolean} */ - isRemoteShareAllowed: function() { - return oc_appconfig.core.remoteShareAllowed; - }, - - /** - * @returns {boolean} - */ isShareWithLinkAllowed: function() { return $('#allowShareWithLink').val() === 'yes'; }, @@ -64,6 +59,20 @@ */ getFederatedShareDocLink: function() { return oc_appconfig.core.federatedCloudShareDoc; + }, + + getDefaultExpirationDateString: function () { + var expireDateString = ''; + if (this.get('isDefaultExpireDateEnabled')) { + var date = new Date().getTime(); + var expireAfterMs = this.get('defaultExpireDate') * 24 * 60 * 60 * 1000; + var expireDate = new Date(date + expireAfterMs); + var month = expireDate.getMonth() + 1; + var year = expireDate.getFullYear(); + var day = expireDate.getDate(); + expireDateString = year + "-" + month + '-' + day + ' 00:00:00'; + } + return expireDateString; } }); diff --git a/core/js/sharedialogexpirationview.js b/core/js/sharedialogexpirationview.js index 56473cdb1fa..f244fe56548 100644 --- a/core/js/sharedialogexpirationview.js +++ b/core/js/sharedialogexpirationview.js @@ -24,7 +24,7 @@ '<label for="expirationCheckbox">{{setExpirationLabel}}</label>' + ' {{#if isExpirationSet}}' + '<label for="expirationDate" class="hidden-visually" value="{{expirationDate}}">{{expirationLabel}}</label>' + - '<input id="expirationDate" class="datepicker" type="text" placeholder="{{expirationDatePlaceholder}}" />' + + '<input id="expirationDate" class="datepicker" type="text" placeholder="{{expirationDatePlaceholder}}" value="{{expirationValue}}" />' + ' {{/if}}' + ' {{#if isExpirationEnforced}}' + // originally the expire message was shown when a default date was set, however it never had text @@ -64,13 +64,28 @@ } else { throw 'missing OC.Share.ShareConfigModel'; } + + var view = this; + this.configModel.on('change:isDefaultExpireDateEnforced', function() { + view.render(); + }); + + this.model.on('change:itemType', function() { + view.render(); + }); + + this.model.on('change:linkShare', function() { + view.render(); + }); }, render: function() { var defaultExpireMessage = ''; var defaultExpireDays = this.configModel.get('defaultExpireDate'); + var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced'); + if( (this.model.isFolder() || this.model.isFile()) - && this.configModel.get('isDefaultExpireDateEnforced')) { + && isExpirationEnforced) { defaultExpireMessage = t( 'core', 'The public link will expire no later than {days} days after it is created', @@ -79,7 +94,6 @@ } var isExpirationSet = !!this.model.get('linkShare').expiration; - var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced'); var expirationTemplate = this.template(); this.$el.html(expirationTemplate({ @@ -120,6 +134,8 @@ }); } + this.$el.find('.datepicker').datepicker({dateFormat : 'dd-mm-yy'}); + return this; }, diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js index 373d6d180bc..b94f1c3e70b 100644 --- a/core/js/sharedialoglinkshareview.js +++ b/core/js/sharedialoglinkshareview.js @@ -23,13 +23,11 @@ ' {{#if showPasswordCheckBox}}' + '<input type="checkbox" name="showPassword" id="showPassword" {{#if isPasswordSet}}checked="checked"{{/if}} value="1" /><label for="showPassword">{{enablePasswordLabel}}</label>' + ' {{/if}}' + - ' {{#if isPasswordSet}}' + - '<div id="linkPass">' + + '<div id="linkPass" {{#unless isPasswordSet}}class="hidden"{{/unless}}>' + ' <label for="linkPassText" class="hidden-visually">{{passwordLabel}}</label>' + ' <input id="linkPassText" type="password" placeholder="{{passwordPlaceholder}}" />' + ' <span class="icon-loading-small hidden"></span>' + '</div>' + - ' {{/if}}' + ' {{#if publicUpload}}' + '<div id="allowPublicUploadWrapper" class="hidden">' + ' <span class="icon-loading-small hidden"></span>' + @@ -86,11 +84,42 @@ view.render(); }); + this.model.on('change:linkShare', function() { + view.render(); + }); + if(!_.isUndefined(options.configModel)) { this.configModel = options.configModel; } else { throw 'missing OC.Share.ShareConfigModel'; } + + _.bindAll(this, 'onLinkCheckBoxChange'); + }, + + onLinkCheckBoxChange: function() { + var $checkBox = this.$el.find('#linkCheckbox'); + var $loading = $checkBox.siblings('.icon-loading-small'); + if(!$loading.hasClass('hidden')) { + return false; + } + + if($checkBox.is(':checked')) { + if(this.configModel.get('enforcePasswordForPublicLink') === false) { + $loading.removeClass('hidden'); + this.model.addLinkShare(); + } else { + this.$el.find('#linkPass').slideToggle(OC.menuSpeed); + // TODO drop with IE8 drop + if($('html').hasClass('ie8')) { + this.$el.find('#linkPassText').attr('placeholder', null); + this.$el.find('#linkPassText').val(''); + } + this.$el.find('#linkPassText').focus(); + } + } else { + this.model.removeLinkShare(); + } }, render: function() { @@ -142,6 +171,8 @@ mailButtonText: t('core', 'Send') })); + this.$el.find('#linkCheckbox').change(this.onLinkCheckBoxChange); + return this; }, diff --git a/core/js/sharedialogresharerinfoview.js b/core/js/sharedialogresharerinfoview.js index f7de90e264f..f6b927c08c5 100644 --- a/core/js/sharedialogresharerinfoview.js +++ b/core/js/sharedialogresharerinfoview.js @@ -96,6 +96,13 @@ sharedByText: sharedByText })); + if(this.configModel.areAvatarsEnabled()) { + this.$el.find('.avatar').each(function() { + var $this = $(this); + $this.avatar($this.data('username'), 32); + }); + } + return this; }, diff --git a/core/js/sharedialogshareelistview.js b/core/js/sharedialogshareelistview.js index 4ac669ee2b9..895f14508d5 100644 --- a/core/js/sharedialogshareelistview.js +++ b/core/js/sharedialogshareelistview.js @@ -201,6 +201,17 @@ sharees: this.getShareeList() })); + if(this.configModel.areAvatarsEnabled()) { + this.$el.find('.avatar').each(function() { + var $this = $(this); + $this.avatar($this.data('username'), 32); + }); + this.$el.find('.avatar.imageplaceholderseed').each(function() { + var $this = $(this); + $this.imageplaceholder($this.data('seed')); + }); + } + return this; }, diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 6588da7d429..7a7fe692c13 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -68,9 +68,6 @@ initialize: function(options) { var view = this; - this.model.on('change', function() { - view.render(); - }); this.model.on('fetchError', function() { OC.Notification.showTemporary(t('core', 'Share details could not be loaded for this item.')); @@ -82,6 +79,10 @@ throw 'missing OC.Share.ShareConfigModel'; } + this.configModel.on('change:isRemoteShareAllowed', function() { + view.render(); + }); + var subViewOptions = { model: this.model, configModel: this.configModel @@ -188,17 +189,6 @@ this.shareeListView.render(); this.$el.find('.hasTooltip').tooltip(); - if(this.configModel.areAvatarsEnabled()) { - this.$el.find('.avatar').each(function() { - var $this = $(this); - $this.avatar($this.data('username'), 32); - }); - this.$el.find('.avatar.imageplaceholderseed').each(function() { - var $this = $(this); - $this.imageplaceholder($this.data('seed')); - }); - } - this.$el.find('.datepicker').datepicker({dateFormat : 'dd-mm-yy'}); return this; }, @@ -216,7 +206,7 @@ _renderRemoteShareInfoPart: function() { var remoteShareInfo = ''; - if(this.configModel.isRemoteShareAllowed()) { + if(this.configModel.get('isRemoteShareAllowed')) { var infoTemplate = this._getRemoteShareInfoTemplate(); remoteShareInfo = infoTemplate({ docLink: this.configModel.getFederatedShareDocLink(), @@ -229,7 +219,7 @@ _renderSharePlaceholderPart: function () { var sharePlaceholder = t('core', 'Share with users or groups …'); - if (this.configModel.isRemoteShareAllowed()) { + if (this.configModel.get('isRemoteShareAllowed')) { sharePlaceholder = t('core', 'Share with users, groups or remote users …'); } return sharePlaceholder; diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index 81e905b082e..9e153dcb3e5 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -89,12 +89,33 @@ linkShare: {} }, + addLinkShare: function() { + var model = this; + var expiration = this.configModel.getDefaultExpirationDateString(); + var itemType = this.get('itemType'); + var itemSource = this.get('itemSource'); + OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, this.fileInfoModel.get('name'), expiration, function(data) { + model.fetch(); + //FIXME: updateIcon belongs to view + OC.Share.updateIcon(itemType, itemSource); + }); + }, + + removeLinkShare: function() { + var model = this; + var itemType = this.get('itemType'); + var itemSource = this.get('itemSource'); + + OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() { + model.fetch(); + //FIXME: updateIcon belongs to view + OC.Share.updateIcon(itemType, itemSource); + }); + }, + addShare: function(event, selected, options) { event.preventDefault(); - //console.warn(selected); - //return false; - var shareType = selected.item.value.shareType; var shareWith = selected.item.value.shareWith; var fileName = this.fileInfoModel.get('name'); @@ -121,8 +142,10 @@ } var model = this; - OC.Share.share(this.get('itemType'), this.get('itemSource'), shareType, shareWith, permissions, fileName, options.expiration, function() { - model.fetch() + var itemType = this.get('itemType'); + var itemSource = this.get('itemSource'); + OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, fileName, options.expiration, function() { + model.fetch(); //FIXME: updateIcon belongs to view OC.Share.updateIcon(itemType, itemSource); }); |