From 8194d092e71b1c44a441dddc64b7e7533adbbfb9 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 14 Sep 2015 12:48:01 +0200 Subject: Add expiration date handling in share tab --- core/js/sharedialogexpirationview.js | 49 ++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'core/js/sharedialogexpirationview.js') diff --git a/core/js/sharedialogexpirationview.js b/core/js/sharedialogexpirationview.js index f244fe56548..c5d8c829657 100644 --- a/core/js/sharedialogexpirationview.js +++ b/core/js/sharedialogexpirationview.js @@ -19,13 +19,13 @@ // in the LinkShareView to ease reusing it in future. Then, // modifications (getting rid of IDs) are still necessary. '{{#if isLinkShare}}' + - '' + '' + - ' {{#if isExpirationSet}}' + - '' + - '' + - ' {{/if}}' + + '
' + + ' ' + + ' ' + + '
' + ' {{#if isExpirationEnforced}}' + // originally the expire message was shown when a default date was set, however it never had text '{{defaultExpireMessage}}' + @@ -58,6 +58,11 @@ className: 'hidden', + events: { + 'change .expirationCheckbox': '_onToggleExpiration', + 'change .datepicker': '_onChangeExpirationDate' + }, + initialize: function(options) { if(!_.isUndefined(options.configModel)) { this.configModel = options.configModel; @@ -79,6 +84,38 @@ }); }, + _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 + this.model.setExpirationDate(''); + this.model.saveLinkShare(); + } + }, + + _onChangeExpirationDate: function(event) { + var $target = $(event.target); + $target.tooltip('hide'); + $target.removeClass('error'); + + this.model.setExpirationDate($target.val()); + this.model.saveLinkShare(null, { + 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'); + } + }); + }, + render: function() { var defaultExpireMessage = ''; var defaultExpireDays = this.configModel.get('defaultExpireDate'); @@ -136,6 +173,8 @@ this.$el.find('.datepicker').datepicker({dateFormat : 'dd-mm-yy'}); + this.delegateEvents(); + return this; }, -- cgit v1.2.3