PageSourceSearch

http://kwartz.lyceejeanbart.fr:8080/owncloud/core/js/sharedialogex…?v=ff0de99913ec549c4e34d726896dcac1

js lyceejeanbart.fr collected 2026-10-01 23:47:39 UTC 5,437 bytes, 188 lines download raw bytes

1/*
2 * Copyright (c) 2015
3 *
4 * This file is licensed under the Affero General Public License version 3
5 * or later.
6 *
7 * See the COPYING-README file.
8 *
9 */
10
11/* global moment */
12
13(function() {
14	if (!OC.Share) {
15		OC.Share = {};
16	}
17
18	var TEMPLATE =
19		'<div id="linkPass-{{cid}}" class="public-link-modal--item">' +
20			'<label class="public-link-modal--label" for="expirationDate-{{cid}}" value="{{expirationDate}}">{{expirationLabel}} {{#if isExpirationEnforced}}<span class="required-indicator">*</span>{{/if}}</label>' +
21			'<input class="public-link-modal--input datepicker expirationDate" id="linkPassText-{{cid}}" type="text" placeholder="{{expirationDatePlaceholder}}" value="{{expirationValue}}" />' +
22			'<span class="error-message hidden"></span>' +
23			'{{#if isExpirationEnforced}}' +
24			// originally the expire message was shown when a default date was set, however it never had text
25			'<em id="defaultExpireMessage" class="defaultExpireMessage">{{defaultExpireMessage}}</em>' +
26			'{{/if}}' +
27		'</div>'
28		;
29
30	/**
31	 * @class OCA.Share.ShareDialogExpirationView
32	 * @member {OC.Share.ShareItemModel} model
33	 * @member {jQuery} $el
34	 * @memberof OCA.Sharing
35	 * @classdesc
36	 *
37	 * Represents the expiration part in the GUI of the share dialogue
38	 *
39	 */
40	var ShareDialogExpirationView = OC.Backbone.View.extend({
41		/** @type {string} **/
42		id: 'shareDialogExpirationView',
43
44		/** @type {OC.Share.ShareConfigModel} **/
45		configModel: undefined,
46
47		/** @type {Function} **/
48		_template: undefined,
49
50		className: 'shareDialogExpirationView',
51
52		events: {
53			'change .expirationCheckbox': '_onToggleExpiration',
54			'change .datepicker': '_onChangeExpirationDate'
55		},
56
57		initialize: function(options) {
58			if(!_.isUndefined(options.itemModel)) {
59				this.itemModel = options.itemModel;
60				this.configModel = this.itemModel.configModel;
61			} else {
62				throw 'missing OC.Share.ShareItemModel';
63			}
64
65			var view = this;
66			this.configModel.on('change:isDefaultExpireDateEnforced', function() {
67				view.render();
68			});
69		},
70
71		_onToggleExpiration: function(event) {
72			var $checkbox = $(event.target);
73			var state = $checkbox.prop('checked');
74			// TODO: slide animation
75			this.$el.find('.expirationDateContainer').toggleClass('hidden', !state);
76			if (!state) {
77				// discard expiration date
78				this.model.unset('expireDate');
79			}
80		},
81
82		_onChangeExpirationDate: function(event) {
83			var $target = $(event.target);
84			$target.tooltip('hide');
85			$target.removeClass('error');
86
87			var expiration = moment($target.val(), 'DD-MM-YYYY').format('YYYY-MM-DD');
88			this.model.set('expireDate', expiration);
89		},
90
91		render: function() {
92			var defaultExpireMessage = '';
93			var defaultExpireDays = this.configModel.get('defaultExpireDate');
94			var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced');
95
96			if(    (this.itemModel.isFolder() || this.itemModel.isFile())
97				&& isExpirationEnforced) {
98				defaultExpireMessage = t(
99					'core',
100					'The public link will expire no later than {days} days after it is created',
101					{'days': defaultExpireDays }
102				);
103			}
104
105			var isExpirationSet = !!this.model.get('expireDate') || isExpirationEnforced;
106
107			var expiration;
108			if (isExpirationSet) {
109				expiration = moment(this.model.get('expireDate'), 'YYYY-MM-DD').format('DD-MM-YYYY');
110			}
111
112			this.$el.html(this.template({
113				cid: this.cid,
114				setExpirationLabel: t('core', 'Set expiration date'),
115				expirationLabel: t('core', 'Expiration'),
116				expirationDatePlaceholder: t('core', 'Choose an expiration date'),
117				defaultExpireMessage: defaultExpireMessage,
118				isExpirationSet: isExpirationSet,
119				isExpirationEnforced: isExpirationEnforced,
120				disableCheckbox: isExpirationEnforced && isExpirationSet,
121				expirationValue: expiration
122			}));
123
124			// what if there is another date picker on that page?
125			var minDate = new Date();
126			var maxDate = null;
127			// min date should always be the next day
128			minDate.setDate(minDate.getDate()+1);
129
130			if(isExpirationSet) {
131				if(isExpirationEnforced) {
132					// TODO: hack: backend returns string instead of integer
133					var shareTime = this.model.get('stime');
134					if (_.isNumber(shareTime)) {
135						shareTime = new Date(shareTime * 1000);
136					}
137					if (!shareTime) {
138						shareTime = new Date(); // now
139					}
140					shareTime = OC.Util.stripTime(shareTime).getTime();
141					maxDate = new Date(shareTime + defaultExpireDays * 24 * 3600 * 1000);
142				}
143			}
144			$.datepicker.setDefaults({
145				minDate: minDate,
146				maxDate: maxDate
147			});
148
149			this.$('.datepicker').datepicker({dateFormat : 'dd-mm-yy'});
150
151			this.$field = this.$('.expirationDate');
152
153			this.delegateEvents();
154
155			return this;
156		},
157
158		getValue: function() {
159			return this.$field.val().trim();
160		},
161
162		validate: function() {
163			this.$field.removeClass('error');
164			this.$field.next('.error-message').addClass('hidden');
165			if (this.configModel.get('isDefaultExpireDateEnforced') && !this.getValue()) {
166				this.$field.addClass('error');
167				this.$field.next('.error-message').removeClass('hidden').text(t('core', 'Expiration date is required'));
168				return false;
169			}
170			return true;
171		},
172
173		/**
174		 * @returns {Function} from Handlebars
175		 * @private
176		 */
177		template: function (data) {
178			if (!this._template) {
179				this._template = Handlebars.compile(TEMPLATE);
180			}
181			return this._template(data);
182		}
183
184	});
185
186	OC.Share.ShareDialogExpirationView = ShareDialogExpirationView;
187
188})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.