Skip to content

Commit

Permalink
further work on reimplementing the dialog layout
Browse files Browse the repository at this point in the history
  • Loading branch information
blizzz committed Aug 13, 2015
1 parent 9b7ab23 commit 4e927a3
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 17 deletions.
4 changes: 3 additions & 1 deletion core/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,13 @@ OC.Share = _.extend(OC.Share, {
});
},
showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions, filename) {
var configModel = new OC.Share.ShareConfigModel();
var attributes = {itemType: itemType, itemSource: itemSource, possiblePermissions: possiblePermissions};
var itemModel = new OC.Share.ShareItemModel(attributes);
var itemModel = new OC.Share.ShareItemModel(attributes, {configModel: configModel});
var dialogView = new OC.Share.ShareDialogView({
id: 'dropdown',
model: itemModel,
configModel: configModel,
className: 'drop shareDropDown',
attributes: {
'data-item-source-name': filename,
Expand Down
54 changes: 54 additions & 0 deletions core/js/shareconfigmodel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2015
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

(function() {
if (!OC.Share) {
OC.Share = {};
OC.Share.Types = {};
}

var ShareConfigModel = OC.Backbone.Model.extend({
defaults: {
publicUploadEnabled: false
},

/**
* @returns {boolean}
*/
isPublicUploadEnabled: function() {
var publicUploadEnabled = $('#filestable').data('allow-public-upload');
return !_.isUndefined(publicUploadEnabled);
},

/**
* @returns {boolean}
*/
isMailPublicNotificationEnabled: function() {
return $('input:hidden[name=mailPublicNotificationEnabled]').val() === 'yes';
},

/**
* @returns {boolean}
*/
isDefaultExpireDateEnforced: function() {
return oc_appconfig.core.defaultExpireDateEnforced === true;
},

/**
* @returns {number}
*/
getDefaultExpireDate: function () {
return oc_appconfig.core.defaultExpireDate;
}
});


OC.Share.ShareConfigModel = ShareConfigModel;
})();
112 changes: 106 additions & 6 deletions core/js/sharedialogview.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
'{{{remoteShareInfo}}}' +
'<ul id="shareWithList">' +
'</ul>' +
'{{{linkShare}}}';
'{{#if shareAllowed}}' +
'{{{linkShare}}}' +
'{{else}}' +
'{{{noSharing}}}' +
'{{/if}}' +
'{{{expiration}}}'
;

var TEMPLATE_RESHARER_INFO =
'<span class="reshare">' +
Expand All @@ -50,9 +56,37 @@
' <label for="linkPassText" class="hidden-visually">{{passwordLabel}}</label>' +
' <input id="linkPassText" type="password" placeholder="passwordPlaceholder" />' +
' <span class="icon-loading-small hidden"></span>' +
' </div>'
' </div>' +
' {{#if publicUpload}}' +
' <div id="allowPublicUploadWrapper" class="hidden">' +
' <span class="icon-loading-small hidden"></span>' +
' <input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload" {{{publicUploadChecked}}} />' +
' <label for="sharingDialogAllowPublicUpload">{{publicUploadLabel}}</label>' +
' </div>' +
' {{/if}}' +
' {{#if mailPublicNotificationEnabled}}' +
' <form id="emailPrivateLink">' +
' <input id="email" class="hidden" value="" placeholder="{{mailPrivatePlaceholder}}" type="text" />' +
' <input id="emailButton" class="hidden" type="submit" value="{{mailButtonText}}" />' +
' </form>' +
' {{/if}}' +
'</div>'
;

var TEMPLATE_NO_SHARING =
'<input id="shareWith" type="text" placeholder="{{placeholder}}" disabled="disabled"/>'
;

var TEMPLATE_EXPIRATION =
'<div id="expiration">' +
' <input type="checkbox" name="expirationCheckbox" id="expirationCheckbox" value="1" />' +
' <label for="expirationCheckbox">{{setExpirationLabel}}</label>' +
' <label for="expirationDate" class="hidden-visually">{{expirationLabel}}</label>' +
' <input id="expirationDate" type="text" placeholder="{{expirationDatePlaceholder}}" class="hidden" />' +
' <em id="defaultExpireMessage">{{defaultExpireMessage}}</em>' +
'</div>'
;

/**
* @class OCA.Share.ShareDialogView
* @member {OC.Share.ShareItemModel} model
Expand All @@ -73,7 +107,10 @@
/** @type {string} **/
tagName: 'div',

initialize: function() {
/** @type {OC.Share.ShareConfigModel} **/
configModel: undefined,

initialize: function(options) {
var view = this;
this.model.on('change', function() {
view.render();
Expand All @@ -82,6 +119,12 @@
this.model.on('fetchError', function() {
OC.Notification.showTemporary(t('core', 'Share details could not be loaded for this item.'));
});

if(!_.isUndefined(options.configModel)) {
this.configModel = options.configModel;
} else {
console.warn('missing OC.Share.ShareConfigModel');
}
},

render: function() {
Expand All @@ -92,7 +135,10 @@
resharerInfo: this._renderResharerInfo(),
sharePlaceholder: this._renderSharePlaceholderPart(),
remoteShareInfo: this._renderRemoteShareInfoPart(),
linkShare: this._renderLinkSharePart()
linkShare: this._renderLinkSharePart(),
shareAllowed: this.model.hasSharePermission(),
noSharing: this._renderNoSharing(),
expiration: this._renderExpirationPart()
}));

return this;
Expand Down Expand Up @@ -155,14 +201,34 @@

_renderLinkSharePart: function() {
var linkShare = '';
if(this._showLink && $('#allowShareWithLink').val() === 'yes') {
if( this.model.hasSharePermission()
&& this._showLink
&& $('#allowShareWithLink').val() === 'yes')
{
var linkShareTemplate = this._getLinkShareTemplate();

var publicUpload =
this.model.isFolder()
&& this.model.hasCreatePermission()
&& this.configModel.isPublicUploadEnabled();

var publicUploadChecked = '';
if(this.model.isPublicUploadAllowed) {
publicUploadChecked = 'checked="checked"';
}

linkShare = linkShareTemplate({
linkShareLabel: t('core', 'Share link'),
urlLabel: t('core', 'Link'),
enablePasswordLabel: t('core', 'Password protect'),
passwordLabel: t('core', 'Password'),
passwordPlaceholder: t('core', 'Choose a password for the public link')
passwordPlaceholder: t('core', 'Choose a password for the public link'),
publicUpload: publicUpload,
publicUploadChecked: publicUploadChecked,
publicUploadLabel: t('core', 'Allow editing'),
mailPublicNotificationEnabled: this.configModel.isMailPublicNotificationEnabled(),
mailPrivatePlaceholder: t('core', 'Email link to person'),
mailButtonText: t('core', 'Send')
});
}
return linkShare;
Expand All @@ -176,6 +242,40 @@
return sharePlaceholder;
},

_renderNoSharing: function () {
var noSharing = '';
if(!this.model.hasSharePermission()) {
var noSharingTemplate = this._getTemplate('noSharing', TEMPLATE_NO_SHARING);
noSharing = noSharingTemplate({
placeholder: t('core', 'Resharing is not allowed')
});
}
return noSharing;
},

_renderExpirationPart: function() {
var expirationTemplate = this._getTemplate('expiration', TEMPLATE_EXPIRATION);

var defaultExpireMessage = '';
if(( this.model.isFolder() || this.model.isFile())
&& this.configModel.isDefaultExpireDateEnforced()) {
defaultExpireMessage = t(
'core',
'The public link will expire no later than {days} days after it is created',
{'days': this.configModel.getDefaultExpireDate()}
);
}

var expiration = expirationTemplate({
setExpirationLabel: t('core', 'Set expiration date'),
expirationLabel: t('core', 'Expiration'),
expirationDatePlaceholder: t('core', 'Expiration date'),
defaultExpireMessage: defaultExpireMessage
});

return expiration;
},

/**
*
* @param {string} key - an identifier for the template
Expand Down
39 changes: 29 additions & 10 deletions core/js/shareitemmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
* // FIXME: use OC Share API once #17143 is done
*/
var ShareItemModel = OC.Backbone.Model.extend({
initialize: function() {
initialize: function(attributes, options) {
if(!_.isUndefined(options.configModel)) {
this.configModel = options.configModel;
}
this.fetch();
},

Expand All @@ -62,15 +65,24 @@
},

/**
* @returns {boolean|jQuery}
* @returns {boolean}
*/
isPublicUploadEnabled: function() {
// FIXME: this really needs a better place
var publicUploadEnabled = $('#filestable').data('allow-public-upload');
if (_.isUndefined(publicUploadEnabled)) {
publicUploadEnabled = 'no';
}
return publicUploadEnabled;
isPublicUploadAllowed: function() {
return this.get('allowPublicUploadStatus');
},

/**
* @returns {boolean}
*/
isFolder: function() {
return this.get('itemType') === 'folder';
},

/**
* @returns {boolean}
*/
isFile: function() {
return this.get('itemType') === 'file';
},

/**
Expand Down Expand Up @@ -134,7 +146,14 @@
* @returns {boolean}
*/
hasSharePermission: function() {
return (this.getPermissions & OC.PERMISSION_SHARE) === OC.PERMISSION_SHARE;
return (this.getPermissions() & OC.PERMISSION_SHARE) === OC.PERMISSION_SHARE;
},

/**
* @returns {boolean}
*/
hasCreatePermission: function() {
return (this.getPermissions() & OC.PERMISSION_CREATE) === OC.PERMISSION_CREATE;
},

fetch: function() {
Expand Down
1 change: 1 addition & 0 deletions lib/private/share/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static function registerBackend($itemType, $class, $collectionOf = null,
'supportedFileExtensions' => $supportedFileExtensions
);
if(count(self::$backendTypes) === 1) {
\OC_Util::addScript('core', 'shareconfigmodel');
\OC_Util::addScript('core', 'shareitemmodel');
\OC_Util::addScript('core', 'sharedialogview');
\OC_Util::addScript('core', 'share');
Expand Down

0 comments on commit 4e927a3

Please sign in to comment.