2015-08-21 20:35:13 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-10-16 11:54:45 +03:00
|
|
|
/* global moment */
|
|
|
|
|
2015-08-21 20:35:13 +03:00
|
|
|
(function() {
|
|
|
|
if (!OC.Share) {
|
|
|
|
OC.Share = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
var TEMPLATE =
|
2015-09-04 16:31:45 +03:00
|
|
|
// currently expiration is only effective for link share.
|
|
|
|
// this is about to change in future. Therefore this is not included
|
|
|
|
// in the LinkShareView to ease reusing it in future. Then,
|
|
|
|
// modifications (getting rid of IDs) are still necessary.
|
2015-09-03 16:53:17 +03:00
|
|
|
'{{#if isLinkShare}}' +
|
2015-10-16 11:54:45 +03:00
|
|
|
'<input type="checkbox" name="expirationCheckbox" class="expirationCheckbox checkbox" id="expirationCheckbox-{{cid}}" value="1" ' +
|
2015-09-04 16:31:45 +03:00
|
|
|
'{{#if isExpirationSet}}checked="checked"{{/if}} {{#if disableCheckbox}}disabled="disabled"{{/if}} />' +
|
2015-10-16 11:54:45 +03:00
|
|
|
'<label for="expirationCheckbox-{{cid}}">{{setExpirationLabel}}</label>' +
|
2015-09-14 13:48:01 +03:00
|
|
|
'<div class="expirationDateContainer {{#unless isExpirationSet}}hidden{{/unless}}">' +
|
|
|
|
' <label for="expirationDate" class="hidden-visually" value="{{expirationDate}}">{{expirationLabel}}</label>' +
|
|
|
|
' <input id="expirationDate" class="datepicker" type="text" placeholder="{{expirationDatePlaceholder}}" value="{{expirationValue}}" />' +
|
|
|
|
'</div>' +
|
2015-09-04 16:31:45 +03:00
|
|
|
' {{#if isExpirationEnforced}}' +
|
|
|
|
// originally the expire message was shown when a default date was set, however it never had text
|
2015-09-03 16:53:17 +03:00
|
|
|
'<em id="defaultExpireMessage">{{defaultExpireMessage}}</em>' +
|
2015-09-04 16:31:45 +03:00
|
|
|
' {{/if}}' +
|
2015-09-03 16:53:17 +03:00
|
|
|
'{{/if}}'
|
2015-08-21 20:35:13 +03:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class OCA.Share.ShareDialogExpirationView
|
|
|
|
* @member {OC.Share.ShareItemModel} model
|
|
|
|
* @member {jQuery} $el
|
|
|
|
* @memberof OCA.Sharing
|
|
|
|
* @classdesc
|
|
|
|
*
|
|
|
|
* Represents the expiration part in the GUI of the share dialogue
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
var ShareDialogExpirationView = OC.Backbone.View.extend({
|
|
|
|
/** @type {string} **/
|
|
|
|
id: 'shareDialogLinkShare',
|
|
|
|
|
|
|
|
/** @type {OC.Share.ShareConfigModel} **/
|
|
|
|
configModel: undefined,
|
|
|
|
|
|
|
|
/** @type {Function} **/
|
|
|
|
_template: undefined,
|
|
|
|
|
|
|
|
/** @type {boolean} **/
|
|
|
|
showLink: true,
|
|
|
|
|
2015-09-03 16:53:17 +03:00
|
|
|
className: 'hidden',
|
|
|
|
|
2015-09-14 13:48:01 +03:00
|
|
|
events: {
|
|
|
|
'change .expirationCheckbox': '_onToggleExpiration',
|
|
|
|
'change .datepicker': '_onChangeExpirationDate'
|
|
|
|
},
|
|
|
|
|
2015-08-21 20:35:13 +03:00
|
|
|
initialize: function(options) {
|
|
|
|
if(!_.isUndefined(options.configModel)) {
|
|
|
|
this.configModel = options.configModel;
|
|
|
|
} else {
|
2015-08-25 00:20:01 +03:00
|
|
|
throw 'missing OC.Share.ShareConfigModel';
|
2015-08-21 20:35:13 +03:00
|
|
|
}
|
2015-09-12 15:21:14 +03:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
2015-08-21 20:35:13 +03:00
|
|
|
},
|
|
|
|
|
2015-09-14 13:48:01 +03:00
|
|
|
_onToggleExpiration: function(event) {
|
|
|
|
var $checkbox = $(event.target);
|
|
|
|
var state = $checkbox.prop('checked');
|
|
|
|
// TODO: slide animation
|
|
|
|
this.$el.find('.expirationDateContainer').toggleClass('hidden', !state);
|
|
|
|
if (!state) {
|
|
|
|
// discard expiration date
|
2016-08-11 11:11:24 +03:00
|
|
|
this.model.get('linkShare').expiration = '';
|
2016-01-22 19:30:18 +03:00
|
|
|
this.model.saveLinkShare({
|
|
|
|
expireDate: ''
|
|
|
|
});
|
2016-08-09 20:55:58 +03:00
|
|
|
} else {
|
|
|
|
this.$el.find('#expirationDate').focus();
|
2015-09-14 13:48:01 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onChangeExpirationDate: function(event) {
|
|
|
|
var $target = $(event.target);
|
|
|
|
$target.tooltip('hide');
|
|
|
|
$target.removeClass('error');
|
|
|
|
|
2016-08-11 11:11:24 +03:00
|
|
|
expiration = moment($target.val(), 'DD-MM-YYYY').format('YYYY-MM-DD');
|
|
|
|
this.model.get('linkShare').expiration = expiration;
|
2016-01-22 19:30:18 +03:00
|
|
|
this.model.saveLinkShare({
|
2016-08-11 11:11:24 +03:00
|
|
|
expiration: expiration
|
2016-01-22 19:30:18 +03:00
|
|
|
}, {
|
2015-09-14 13:48:01 +03:00
|
|
|
error: function(model, message) {
|
|
|
|
if (!message) {
|
|
|
|
$target.attr('title', t('core', 'Error setting expiration date'));
|
|
|
|
} else {
|
|
|
|
$target.attr('title', message);
|
|
|
|
}
|
|
|
|
$target.tooltip({gravity: 'n'});
|
|
|
|
$target.tooltip('show');
|
|
|
|
$target.addClass('error');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-08-21 20:35:13 +03:00
|
|
|
render: function() {
|
|
|
|
var defaultExpireMessage = '';
|
2015-09-04 16:31:45 +03:00
|
|
|
var defaultExpireDays = this.configModel.get('defaultExpireDate');
|
2015-09-12 15:21:14 +03:00
|
|
|
var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced');
|
|
|
|
|
2015-08-21 20:35:13 +03:00
|
|
|
if( (this.model.isFolder() || this.model.isFile())
|
2015-09-12 15:21:14 +03:00
|
|
|
&& isExpirationEnforced) {
|
2015-08-21 20:35:13 +03:00
|
|
|
defaultExpireMessage = t(
|
|
|
|
'core',
|
|
|
|
'The public link will expire no later than {days} days after it is created',
|
2015-09-04 16:31:45 +03:00
|
|
|
{'days': defaultExpireDays }
|
2015-08-21 20:35:13 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-15 16:29:30 +03:00
|
|
|
var isExpirationSet = !!this.model.get('linkShare').expiration || isExpirationEnforced;
|
2015-09-04 16:31:45 +03:00
|
|
|
|
2015-10-03 18:06:48 +03:00
|
|
|
var expiration;
|
|
|
|
if (isExpirationSet) {
|
2015-10-16 11:54:45 +03:00
|
|
|
expiration = moment(this.model.get('linkShare').expiration, 'YYYY-MM-DD').format('DD-MM-YYYY');
|
2015-10-03 18:06:48 +03:00
|
|
|
}
|
|
|
|
|
2015-10-16 11:54:45 +03:00
|
|
|
this.$el.html(this.template({
|
|
|
|
cid: this.cid,
|
2015-08-21 20:35:13 +03:00
|
|
|
setExpirationLabel: t('core', 'Set expiration date'),
|
|
|
|
expirationLabel: t('core', 'Expiration'),
|
|
|
|
expirationDatePlaceholder: t('core', 'Expiration date'),
|
2015-09-03 16:53:17 +03:00
|
|
|
defaultExpireMessage: defaultExpireMessage,
|
2015-09-04 16:31:45 +03:00
|
|
|
isLinkShare: this.model.get('linkShare').isLinkShare,
|
|
|
|
isExpirationSet: isExpirationSet,
|
|
|
|
isExpirationEnforced: isExpirationEnforced,
|
|
|
|
disableCheckbox: isExpirationEnforced && isExpirationSet,
|
2015-10-03 18:06:48 +03:00
|
|
|
expirationValue: expiration
|
2015-08-21 20:35:13 +03:00
|
|
|
}));
|
|
|
|
|
2015-09-15 16:29:30 +03:00
|
|
|
// what if there is another date picker on that page?
|
|
|
|
var minDate = new Date();
|
|
|
|
var maxDate = null;
|
|
|
|
// min date should always be the next day
|
|
|
|
minDate.setDate(minDate.getDate()+1);
|
2015-09-04 16:31:45 +03:00
|
|
|
|
2015-09-15 16:29:30 +03:00
|
|
|
if(isExpirationSet) {
|
2015-09-04 16:31:45 +03:00
|
|
|
if(isExpirationEnforced) {
|
|
|
|
// TODO: hack: backend returns string instead of integer
|
|
|
|
var shareTime = this.model.get('linkShare').stime;
|
|
|
|
if (_.isNumber(shareTime)) {
|
|
|
|
shareTime = new Date(shareTime * 1000);
|
|
|
|
}
|
|
|
|
if (!shareTime) {
|
|
|
|
shareTime = new Date(); // now
|
|
|
|
}
|
|
|
|
shareTime = OC.Util.stripTime(shareTime).getTime();
|
|
|
|
maxDate = new Date(shareTime + defaultExpireDays * 24 * 3600 * 1000);
|
|
|
|
}
|
|
|
|
}
|
2015-09-15 16:29:30 +03:00
|
|
|
$.datepicker.setDefaults({
|
|
|
|
minDate: minDate,
|
|
|
|
maxDate: maxDate
|
|
|
|
});
|
2015-09-04 16:31:45 +03:00
|
|
|
|
2015-09-12 15:21:14 +03:00
|
|
|
this.$el.find('.datepicker').datepicker({dateFormat : 'dd-mm-yy'});
|
|
|
|
|
2015-09-14 13:48:01 +03:00
|
|
|
this.delegateEvents();
|
|
|
|
|
2015-08-21 20:35:13 +03:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {Function} from Handlebars
|
|
|
|
* @private
|
|
|
|
*/
|
2015-10-16 11:54:45 +03:00
|
|
|
template: function (data) {
|
2015-08-21 20:35:13 +03:00
|
|
|
if (!this._template) {
|
|
|
|
this._template = Handlebars.compile(TEMPLATE);
|
|
|
|
}
|
2015-10-16 11:54:45 +03:00
|
|
|
return this._template(data);
|
2015-08-21 20:35:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
OC.Share.ShareDialogExpirationView = ShareDialogExpirationView;
|
|
|
|
|
|
|
|
})();
|