Issues (493)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

js/share.js (18 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
/* global escapeHTML */
2
3
(function(OC) {
4
	// copied and stripped out from the old core
5
	OC.Share = _.extend(OC.Share, {
6
		/**
7
		 * @deprecated use OC.Share.currentShares instead
8
		 */
9
		itemShares:[],
10
		/**
11
		 * Full list of all share statuses
12
		 */
13
		statuses:{},
14
		/**
15
		 * Shares for the currently selected file.
16
		 * (for which the dropdown is open)
17
		 *
18
		 * Key is item type and value is an array or
19
		 * shares of the given item type.
20
		 */
21
		currentShares: {},
22
		/**
23
		 * Whether the share dropdown is opened.
24
		 */
25
		droppedDown:false,
26
		/**
27
		 * Loads ALL share statuses from server, stores them in
28
		 * OC.Share.statuses then calls OC.Share.updateIcons() to update the
29
		 * files "Share" icon to "Shared" according to their share status and
30
		 * share type.
31
		 *
32
		 * If a callback is specified, the update step is skipped.
33
		 *
34
		 * @param itemType item type
35
		 * @param fileList file list instance, defaults to OCA.Files.App.fileList
36
		 * @param callback function to call after the shares were loaded
37
		 */
38
		loadIcons:function(itemType, fileList, callback) {
39
			// Load all share icons
40
			$.get(
41
				OC.filePath('core', 'ajax', 'share.php'),
42
				{
43
					fetch: 'getItemsSharedStatuses',
44
					itemType: itemType
45
				}, function(result) {
46
					if (result && result.status === 'success') {
47
						OC.Share.statuses = {};
48
						$.each(result.data, function(item, data) {
49
							OC.Share.statuses[item] = data;
50
						});
51
						if (_.isFunction(callback)) {
52
							callback(OC.Share.statuses);
53
						} else {
54
							OC.Share.updateIcons(itemType, fileList);
55
						}
56
					}
57
				}
58
			);
59
		},
60
		/**
61
		 * Updates the files' "Share" icons according to the known
62
		 * sharing states stored in OC.Share.statuses.
63
		 * (not reloaded from server)
64
		 *
65
		 * @param itemType item type
66
		 * @param fileList file list instance
67
		 * defaults to OCA.Files.App.fileList
68
		 */
69
		updateIcons:function(itemType, fileList){
70
			var item;
71
			var $fileList;
72
			var currentDir;
73
			if (!fileList && OCA.Files) {
74
				fileList = OCA.Files.App.fileList;
75
			}
76
			// fileList is usually only defined in the files app
77
			if (fileList) {
78
				$fileList = fileList.$fileList;
79
				currentDir = fileList.getCurrentDirectory();
80
			}
81
			// TODO: iterating over the files might be more efficient
82
			for (item in OC.Share.statuses){
83
				var image = OC.imagePath('core', 'actions/share');
84
				var data = OC.Share.statuses[item];
85
				var hasLink = data.link;
86
				// Links override shared in terms of icon display
87
				if (hasLink) {
88
					image = OC.imagePath('core', 'actions/public');
89
				}
90
				if (itemType !== 'file' && itemType !== 'folder') {
91
					$('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center');
92
				} else {
93
					// TODO: ultimately this part should be moved to files_sharing app
94
					var file = $fileList.find('tr[data-id="'+item+'"]');
95
					var shareFolder = OC.imagePath('core', 'filetypes/folder-shared');
96
					var img;
97
					if (file.length > 0) {
98
						this.markFileAsShared(file, true, hasLink);
99
					} else {
100
						var dir = currentDir;
101
						if (dir.length > 1) {
102
							var last = '';
103
							var path = dir;
104
							// Search for possible parent folders that are shared
105
							while (path != last) {
106
								if (path === data.path && !data.link) {
107
									var actions = $fileList.find('.fileactions .action[data-action="Share"]');
108
									var files = $fileList.find('.filename');
109
									var i;
110
									for (i = 0; i < actions.length; i++) {
111
										// TODO: use this.markFileAsShared()
112
										img = $(actions[i]).find('img');
113
										if (img.attr('src') !== OC.imagePath('core', 'actions/public')) {
114
											img.attr('src', image);
115
											$(actions[i]).addClass('permanent');
116
											$(actions[i]).html(' <span>'+t('core', 'Shared')+'</span>').prepend(img);
117
										}
118
									}
119
									for(i = 0; i < files.length; i++) {
120
										if ($(files[i]).closest('tr').data('type') === 'dir') {
121
											$(files[i]).find('.thumbnail').css('background-image', 'url('+shareFolder+')');
122
										}
123
									}
124
								}
125
								last = path;
126
								path = OC.Share.dirname(path);
127
							}
128
						}
129
					}
130
				}
131
			}
132
		},
133
		updateIcon:function(itemType, itemSource) {
134
			var shares = false;
135
			var link = false;
136
			var image = OC.imagePath('core', 'actions/share');
137
			$.each(OC.Share.itemShares, function(index) {
138
				if (OC.Share.itemShares[index]) {
139
					if (index == OC.Share.SHARE_TYPE_LINK) {
140
						if (OC.Share.itemShares[index] == true) {
141
							shares = true;
142
							image = OC.imagePath('core', 'actions/public');
143
							link = true;
144
							return;
145
						}
146
					} else if (OC.Share.itemShares[index].length > 0) {
147
						shares = true;
148
						image = OC.imagePath('core', 'actions/share');
149
					}
150
				}
151
			});
152
			if (itemType != 'file' && itemType != 'folder') {
153
				$('a.share[data-item="'+itemSource+'"]').css('background', 'url('+image+') no-repeat center');
154
			} else {
155
				var $tr = $('tr').filterAttr('data-id', String(itemSource));
156
				if ($tr.length > 0) {
157
					// it might happen that multiple lists exist in the DOM
158
					// with the same id
159
					$tr.each(function() {
160
						OC.Share.markFileAsShared($(this), shares, link);
161
					});
162
				}
163
			}
164
			if (shares) {
165
				OC.Share.statuses[itemSource] = OC.Share.statuses[itemSource] || {};
166
				OC.Share.statuses[itemSource]['link'] = link;
0 ignored issues
show
['link'] could be written in dot notation.

You can rewrite this statement in dot notation:

var obj = { };
obj['foo'] = 'bar'; // Bad
obj.foo = 'bar'; // Good
Loading history...
167
			} else {
168
				delete OC.Share.statuses[itemSource];
169
			}
170
		},
171
		/**
172
		 * Format a remote address
173
		 *
174
		 * @param {String} remoteAddress full remote share
175
		 * @return {String} HTML code to display
176
		 */
177
		_formatRemoteShare: function(remoteAddress) {
178
			var parts = this._REMOTE_OWNER_REGEXP.exec(remoteAddress);
179
			if (!parts) {
180
				// display as is, most likely to be a simple owner name
181
				return escapeHTML(remoteAddress);
182
			}
183
184
			var userName = parts[1];
185
			var userDomain = parts[3];
186
			var server = parts[4];
187
			var dir = parts[6];
188
			var tooltip = userName;
189
			if (userDomain) {
190
				tooltip += '@' + userDomain;
191
			}
192
			if (server) {
193
				if (!userDomain) {
194
					userDomain = '…';
195
				}
196
				tooltip += '@' + server;
197
			}
198
199
			var html = '<span class="remoteAddress" title="' + escapeHTML(tooltip) + '">';
200
			html += '<span class="username">' + escapeHTML(userName) + '</span>';
201
			if (userDomain) {
202
				html += '<span class="userDomain">@' + escapeHTML(userDomain) + '</span>';
203
			}
204
			html += '</span>';
205
			return html;
206
		},
207
		/**
208
		 * Marks/unmarks a given file as shared by changing its action icon
209
		 * and folder icon.
210
		 *
211
		 * @param $tr file element to mark as shared
212
		 * @param hasShares whether shares are available
213
		 * @param hasLink whether link share is available
214
		 */
215
		loadItem:function(itemType, itemSource) {
216
			var data = '';
217
			var checkReshare = true;
218
			if (typeof OC.Share.statuses[itemSource] === 'undefined') {
219
				// NOTE: Check does not always work and misses some shares, fix later
220
				var checkShares = true;
221
			} else {
222
				var checkShares = true;
223
			}
224
			$.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItem', itemType: itemType, itemSource: itemSource, checkReshare: checkReshare, checkShares: checkShares }, async: false, success: function(result) {
225
				if (result && result.status === 'success') {
226
					data = result.data;
227
				} else {
228
					data = false;
229
				}
230
			}});
231
232
			return data;
233
		},
234
		share:function(itemType, itemSource, shareType, shareWith, permissions, itemSourceName, expirationDate, callback, errorCallback) {
235
			// Add a fallback for old share() calls without expirationDate.
236
			// We should remove this in a later version,
237
			// after the Apps have been updated.
238
			if (typeof callback === 'undefined' &&
239
				typeof expirationDate === 'function') {
240
				callback = expirationDate;
241
				expirationDate = '';
242
				console.warn(
243
					"Call to 'OC.Share.share()' with too few arguments. " +
0 ignored issues
show
Strings must use singlequote.
Loading history...
244
					"'expirationDate' was assumed to be 'callback'. " +
0 ignored issues
show
Strings must use singlequote.
Loading history...
245
					"Please revisit the call and fix the list of arguments."
0 ignored issues
show
Strings must use singlequote.
Loading history...
246
				);
247
			}
248
249
			return $.post(OC.filePath('core', 'ajax', 'share.php'),
250
				{
251
					action: 'share',
252
					itemType: itemType,
253
					itemSource: itemSource,
254
					shareType: shareType,
255
					shareWith: shareWith,
256
					permissions: permissions,
257
					itemSourceName: itemSourceName,
258
					expirationDate: expirationDate
259
				}, function (result) {
260
					if (result && result.status === 'success') {
261
						if (callback) {
262
							callback(result.data);
263
						}
264
					} else {
265
						if (_.isUndefined(errorCallback)) {
266
							var msg = t('core', 'Error');
267
							if (result.data && result.data.message) {
268
								msg = result.data.message;
269
							}
270
							OC.dialogs.alert(msg, t('core', 'Error while sharing'));
271
						} else {
272
							errorCallback(result);
273
						}
274
					}
275
				}
276
			);
277
		},
278
		unshare:function(itemType, itemSource, shareType, shareWith, callback) {
279
			$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith }, function(result) {
280
				if (result && result.status === 'success') {
281
					if (callback) {
282
						callback();
283
					}
284
				} else {
285
					OC.dialogs.alert(t('core', 'Error while unsharing'), t('core', 'Error'));
286
				}
287
			});
288
		},
289
		setPermissions:function(itemType, itemSource, shareType, shareWith, permissions) {
290
			$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setPermissions', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
291
				if (!result || result.status !== 'success') {
292
					OC.dialogs.alert(t('core', 'Error while changing permissions'), t('core', 'Error'));
293
				}
294
			});
295
		},
296
		showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions, filename) {
297
			var data = OC.Share.loadItem(itemType, itemSource);
298
			var dropDownEl;
299
			var html = '<div id="dropdown" class="drop shareDropDown" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">';
300
			if (data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined && data.reshare.uid_owner !== OC.currentUser) {
301
				html += '<span class="reshare">';
302
				if (oc_config.enable_avatars === true) {
303
					html += '<div class="avatar"></div> ';
304
				}
305
306
				if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) {
307
					html += t('core', 'Shared with you and the group {group} by {owner}', {group: data.reshare.share_with, owner: data.reshare.displayname_owner});
308
				} else {
309
					html += t('core', 'Shared with you by {owner}', {owner: data.reshare.displayname_owner});
310
				}
311
				html += '</span><br />';
312
				// reduce possible permissions to what the original share allowed
313
				possiblePermissions = possiblePermissions & data.reshare.permissions;
314
			}
315
316
			if (possiblePermissions & OC.PERMISSION_SHARE) {
317
				// Determine the Allow Public Upload status.
318
				// Used later on to determine if the
319
				// respective checkbox should be checked or
320
				// not.
321
322
				var publicUploadEnabled = $('#filestable').data('allow-public-upload');
323
				if (typeof publicUploadEnabled == 'undefined') {
324
					publicUploadEnabled = 'no';
325
				}
326
				var allowPublicUploadStatus = false;
327
328
				$.each(data.shares, function(key, value) {
329
					if (value.share_type === OC.Share.SHARE_TYPE_LINK) {
330
						allowPublicUploadStatus = (value.permissions & OC.PERMISSION_CREATE) ? true : false;
331
						return true;
332
					}
333
				});
334
335
				var sharePlaceholder = t('core', 'Share with users or groups …');
336
				if(oc_appconfig.core.remoteShareAllowed) {
337
					sharePlaceholder = t('core', 'Share with users, groups or remote users …');
338
				}
339
340
				html += '<label for="shareWith" class="hidden-visually">'+t('core', 'Share')+'</label>';
341
				html += '<input id="shareWith" type="text" placeholder="' + sharePlaceholder + '" />';
342
				if(oc_appconfig.core.remoteShareAllowed) {
343
					var federatedCloudSharingDoc = '<a target="_blank" class="icon-info svg shareWithRemoteInfo" href="{docLink}" '
344
						+ 'title="' + t('core', 'Share with people on other ownClouds using the syntax [email protected]/owncloud') + '"></a>';
345
					html += federatedCloudSharingDoc.replace('{docLink}', oc_appconfig.core.federatedCloudShareDoc);
346
				}
347
				html += '<span class="shareWithLoading icon-loading-small hidden"></span>';
348
				html += '<ul id="shareWithList">';
349
				html += '</ul>';
350
				var linksAllowed = $('#allowShareWithLink').val() === 'yes';
351
				if (link && linksAllowed) {
352
					html += '<div id="link" class="linkShare">';
353
					html += '<span class="icon-loading-small hidden"></span>';
354
					html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">'+t('core', 'Share link')+'</label>';
355
					html += '<br />';
356
357
					var defaultExpireMessage = '';
358
					if ((itemType === 'folder' || itemType === 'file') && oc_appconfig.core.defaultExpireDateEnforced) {
359
						defaultExpireMessage = t('core', 'The public link will expire no later than {days} days after it is created',  {'days': oc_appconfig.core.defaultExpireDate}) + '<br/>';
360
					}
361
362
					html += '<label for="linkText" class="hidden-visually">'+t('core', 'Link')+'</label>';
363
					html += '<input id="linkText" type="text" readonly="readonly" />';
364
					html += '<input type="checkbox" name="showPassword" id="showPassword" value="1" style="display:none;" /><label for="showPassword" style="display:none;">'+t('core', 'Password protect')+'</label>';
365
					html += '<div id="linkPass">';
366
					html += '<label for="linkPassText" class="hidden-visually">'+t('core', 'Password')+'</label>';
367
					html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Choose a password for the public link')+'" />';
368
					html += '<span class="icon-loading-small hidden"></span>';
369
					html += '</div>';
370
371
					if (itemType === 'folder' && (possiblePermissions & OC.PERMISSION_CREATE) && publicUploadEnabled === 'yes') {
372
						html += '<div id="allowPublicUploadWrapper" style="display:none;">';
373
						html += '<span class="icon-loading-small hidden"></span>';
374
						html += '<input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload"' + ((allowPublicUploadStatus) ? 'checked="checked"' : '') + ' />';
375
						html += '<label for="sharingDialogAllowPublicUpload">' + t('core', 'Allow editing') + '</label>';
376
						html += '</div>';
377
					}
378
					html += '</div>';
379
					var mailPublicNotificationEnabled = $('input:hidden[name=mailPublicNotificationEnabled]').val();
380
					if (mailPublicNotificationEnabled === 'yes') {
381
						html += '<form id="emailPrivateLink">';
382
						html += '<input id="email" style="display:none; width:62%;" value="" placeholder="'+t('core', 'Email link to person')+'" type="text" />';
383
						html += '<input id="emailButton" style="display:none;" type="submit" value="'+t('core', 'Send')+'" />';
384
						html += '</form>';
385
					}
386
				}
387
388
				html += '<div id="expiration">';
389
				html += '<input type="checkbox" name="expirationCheckbox" id="expirationCheckbox" value="1" /><label for="expirationCheckbox">'+t('core', 'Set expiration date')+'</label>';
390
				html += '<label for="expirationDate" class="hidden-visually">'+t('core', 'Expiration')+'</label>';
391
				html += '<input id="expirationDate" type="text" placeholder="'+t('core', 'Expiration date')+'" style="display:none; width:90%;" />';
392
				html += '<em id="defaultExpireMessage">'+defaultExpireMessage+'</em>';
393
				html += '</div>';
394
				dropDownEl = $(html);
395
				dropDownEl = dropDownEl.appendTo(appendTo);
396
397
				// trigger remote share info tooltip
398
				if(oc_appconfig.core.remoteShareAllowed) {
399
					$('.shareWithRemoteInfo').tipsy({gravity: 'e'});
400
				}
401
402
				//Get owner avatars
403
				if (oc_config.enable_avatars === true && data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined) {
404
					dropDownEl.find(".avatar").avatar(data.reshare.uid_owner, 32);
0 ignored issues
show
Strings must use singlequote.
Loading history...
405
				}
406
407
				// Reset item shares
408
				OC.Share.itemShares = [];
409
				OC.Share.currentShares = {};
410
				if (data.shares) {
411
					$.each(data.shares, function(index, share) {
412
						if (share.share_type == OC.Share.SHARE_TYPE_LINK) {
413
							if (itemSource === share.file_source || itemSource === share.item_source) {
414
								OC.Share.showLink(share.token, share.share_with, itemSource);
415
							}
416
						} else {
417
							if (share.collection) {
418
								OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, share.collection);
419
							} else {
420
								if (share.share_type === OC.Share.SHARE_TYPE_REMOTE) {
421
									OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE, share.mail_send, false);
422
								} else {
423
									OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, false);
424
								}
425
							}
426
						}
427
						if (share.expiration != null) {
428
							OC.Share.showExpirationDate(share.expiration, share.stime);
429
						}
430
					});
431
				}
432
				$('#shareWith').autocomplete({minLength: 2, delay: 750, source: function(search, response) {
433
					var $loading = $('#dropdown .shareWithLoading');
434
					$loading.removeClass('hidden');
435
					$.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term.trim(), limit: 200, itemShares: OC.Share.itemShares, itemType: itemType }, function(result) {
436
						$loading.addClass('hidden');
437
						if (result.status == 'success' && result.data.length > 0) {
438
							$( "#shareWith" ).autocomplete( "option", "autoFocus", true );
0 ignored issues
show
Strings must use singlequote.
Loading history...
439
							response(result.data);
440
						} else {
441
							response();
442
						}
443
					}).fail(function(){
444
						$('#dropdown').find('.shareWithLoading').addClass('hidden');
445
						OC.Notification.show(t('core', 'An error occured. Please try again'));
446
						window.setTimeout(OC.Notification.hide, 5000);
447
					});
448
				},
449
				focus: function(event, focused) {
450
					event.preventDefault();
451
				},
452
				select: function(event, selected) {
453
					event.stopPropagation();
454
					var $dropDown = $('#dropdown');
455
					var itemType = $dropDown.data('item-type');
456
					var itemSource = $dropDown.data('item-source');
457
					var itemSourceName = $dropDown.data('item-source-name');
458
					var expirationDate = '';
459
					if ( $('#expirationCheckbox').is(':checked') === true ) {
460
						expirationDate = $( "#expirationDate" ).val();
0 ignored issues
show
Strings must use singlequote.
Loading history...
461
					}
462
					var shareType = selected.item.value.shareType;
463
					var shareWith = selected.item.value.shareWith;
464
					$(this).val(shareWith);
465
					// Default permissions are Edit (CRUD) and Share
466
					// Check if these permissions are possible
467
					var permissions = OC.PERMISSION_READ;
468
					if (shareType === OC.Share.SHARE_TYPE_REMOTE) {
469
						permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_READ;
470
					} else {
471
						if (possiblePermissions & OC.PERMISSION_UPDATE) {
472
							permissions = permissions | OC.PERMISSION_UPDATE;
473
						}
474
						if (possiblePermissions & OC.PERMISSION_CREATE) {
475
							permissions = permissions | OC.PERMISSION_CREATE;
476
						}
477
						if (possiblePermissions & OC.PERMISSION_DELETE) {
478
							permissions = permissions | OC.PERMISSION_DELETE;
479
						}
480
						if (oc_appconfig.core.resharingAllowed && (possiblePermissions & OC.PERMISSION_SHARE)) {
481
							permissions = permissions | OC.PERMISSION_SHARE;
482
						}
483
					}
484
485
					var $input = $(this);
486
					var $loading = $dropDown.find('.shareWithLoading');
487
					$loading.removeClass('hidden');
488
					$input.val(t('core', 'Adding user...'));
489
					$input.prop('disabled', true);
490
491
					OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, itemSourceName, expirationDate, function() {
492
						$input.prop('disabled', false);
493
						$loading.addClass('hidden');
494
						var posPermissions = possiblePermissions;
495
						if (shareType === OC.Share.SHARE_TYPE_REMOTE) {
496
							posPermissions = permissions;
497
						}
498
						OC.Share.addShareWith(shareType, shareWith, selected.item.label, permissions, posPermissions);
499
						$('#shareWith').val('');
500
						$('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares}));
501
						OC.Share.updateIcon(itemType, itemSource);
502
					});
503
					return false;
504
				}
505
				})
506
				// customize internal _renderItem function to display groups and users differently
507
				.data("ui-autocomplete")._renderItem = function( ul, item ) {
0 ignored issues
show
Strings must use singlequote.
Loading history...
508
					var insert = $( "<a>" );
0 ignored issues
show
Strings must use singlequote.
Loading history...
509
					var text = item.label;
510
					if (item.value.shareType === OC.Share.SHARE_TYPE_GROUP) {
511
						text = text +  ' ('+t('core', 'group')+')';
512
					} else if (item.value.shareType === OC.Share.SHARE_TYPE_REMOTE) {
513
						text = text +  ' ('+t('core', 'remote')+')';
514
					}
515
					insert.text( text );
516
					if(item.value.shareType === OC.Share.SHARE_TYPE_GROUP) {
517
						insert = insert.wrapInner('<strong></strong>');
518
					}
519
					return $( "<li>" )
0 ignored issues
show
Strings must use singlequote.
Loading history...
520
						.addClass((item.value.shareType === OC.Share.SHARE_TYPE_GROUP)?'group':'user')
521
						.append( insert )
522
						.appendTo( ul );
523
				};
524
				if (link && linksAllowed && $('#email').length != 0) {
525
					$('#email').autocomplete({
526
						minLength: 1,
527
						source: function (search, response) {
528
							$.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWithEmail', search: search.term }, function(result) {
529
								if (result.status == 'success' && result.data.length > 0) {
530
									response(result.data);
531
								}
532
							});
533
							},
534
						select: function( event, item ) {
535
							$('#email').val(item.item.email);
536
							return false;
537
						}
538
					})
539
					.data("ui-autocomplete")._renderItem = function( ul, item ) {
0 ignored issues
show
Strings must use singlequote.
Loading history...
540
						return $('<li>')
541
							.append('<a>' + escapeHTML(item.displayname) + "<br>" + escapeHTML(item.email) + '</a>' )
0 ignored issues
show
Strings must use singlequote.
Loading history...
542
							.appendTo( ul );
543
					};
544
				}
545
546
			} else {
547
				html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Resharing is not allowed')+'" style="width:90%;" disabled="disabled"/>';
548
				html += '</div>';
549
				dropDownEl = $(html);
550
				dropDownEl.appendTo(appendTo);
551
			}
552
			dropDownEl.attr('data-item-source-name', filename);
553
			$('#dropdown').slideDown(OC.menuSpeed, function() {
554
				OC.Share.droppedDown = true;
555
			});
556
			if ($('html').hasClass('lte9')){
557
				$('#dropdown input[placeholder]').placeholder();
558
			}
559
			$('#shareWith').focus();
560
		},
561
		hideDropDown:function(callback) {
562
			OC.Share.currentShares = null;
563
			$('#dropdown').slideUp(OC.menuSpeed, function() {
564
				OC.Share.droppedDown = false;
565
				$('#dropdown').remove();
566
				if (typeof FileActions !== 'undefined') {
567
					$('tr').removeClass('mouseOver');
568
				}
569
				if (callback) {
570
					callback.call();
571
				}
572
			});
573
		},
574
		addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, mailSend, collection) {
575
			var shareItem = {
576
				share_type: shareType,
577
				share_with: shareWith,
578
				share_with_displayname: shareWithDisplayName,
579
				permissions: permissions
580
			};
581
			if (shareType === OC.Share.SHARE_TYPE_GROUP) {
582
				shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'group') + ')';
0 ignored issues
show
Strings must use singlequote.
Loading history...
583
			}
584
			if (shareType === OC.Share.SHARE_TYPE_REMOTE) {
585
				shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'remote') + ')';
0 ignored issues
show
Strings must use singlequote.
Loading history...
586
			}
587
			if (!OC.Share.itemShares[shareType]) {
588
				OC.Share.itemShares[shareType] = [];
589
			}
590
			OC.Share.itemShares[shareType].push(shareWith);
591
			if (collection) {
592
				if (collection.item_type == 'file' || collection.item_type == 'folder') {
593
					var item = collection.path;
594
				} else {
595
					var item = collection.item_source;
596
				}
597
				var collectionList = $('#shareWithList li').filterAttr('data-collection', item);
598
				if (collectionList.length > 0) {
599
					$(collectionList).append(', '+shareWithDisplayName);
600
				} else {
601
					var html = '<li style="clear: both;" data-collection="'+item+'">'+t('core', 'Shared in {item} with {user}', {'item': item, user: shareWithDisplayName})+'</li>';
602
					$('#shareWithList').prepend(html);
603
				}
604
			} else {
605
				var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = '';
606
				if (permissions & OC.PERMISSION_CREATE) {
607
					createChecked = 'checked="checked"';
608
					editChecked = 'checked="checked"';
609
				}
610
				if (permissions & OC.PERMISSION_UPDATE) {
611
					updateChecked = 'checked="checked"';
612
					editChecked = 'checked="checked"';
613
				}
614
				if (permissions & OC.PERMISSION_DELETE) {
615
					deleteChecked = 'checked="checked"';
616
					editChecked = 'checked="checked"';
617
				}
618
				if (permissions & OC.PERMISSION_SHARE) {
619
					shareChecked = 'checked="checked"';
620
				}
621
				var html = '<li style="clear: both;" data-share-type="'+escapeHTML(shareType)+'" data-share-with="'+escapeHTML(shareWith)+'" title="' + escapeHTML(shareWith) + '">';
622
				var showCrudsButton;
623
				html += '<a href="#" class="unshare"><img class="svg" alt="'+t('core', 'Unshare')+'" title="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
624
				if (oc_config.enable_avatars === true) {
625
					html += '<div class="avatar"></div>';
626
				}
627
				html += '<span class="username">' + escapeHTML(shareWithDisplayName) + '</span>';
628
				var mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val();
629
				if (mailNotificationEnabled === 'yes' && shareType !== OC.Share.SHARE_TYPE_REMOTE) {
630
					var checked = '';
631
					if (mailSend === '1') {
632
						checked = 'checked';
633
					}
634
					html += '<label><input type="checkbox" name="mailNotification" class="mailNotification" ' + checked + ' />'+t('core', 'notify by email')+'</label> ';
635
				}
636
				if (oc_appconfig.core.resharingAllowed && (possiblePermissions & OC.PERMISSION_SHARE)) {
637
					html += '<label><input id="canShare-'+escapeHTML(shareWith)+'" type="checkbox" name="share" class="permissions" '+shareChecked+' data-permissions="'+OC.PERMISSION_SHARE+'" />'+t('core', 'can share')+'</label>';
638
				}
639
				if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) {
640
					html += '<label><input id="canEdit-'+escapeHTML(shareWith)+'" type="checkbox" name="edit" class="permissions" '+editChecked+' />'+t('core', 'can edit')+'</label>';
641
				}
642
				if (shareType !== OC.Share.SHARE_TYPE_REMOTE) {
643
					showCrudsButton = '<a href="#" class="showCruds"><img class="svg" alt="'+t('core', 'access control')+'" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>';
644
				}
645
				html += '<div class="cruds" style="display:none;">';
646
				if (possiblePermissions & OC.PERMISSION_CREATE) {
647
					html += '<label><input id="canCreate-' + escapeHTML(shareWith) + '" type="checkbox" name="create" class="permissions" ' + createChecked + ' data-permissions="' + OC.PERMISSION_CREATE + '"/>' + t('core', 'create') + '</label>';
648
				}
649
				if (possiblePermissions & OC.PERMISSION_UPDATE) {
650
					html += '<label><input id="canUpdate-' + escapeHTML(shareWith) + '" type="checkbox" name="update" class="permissions" ' + updateChecked + ' data-permissions="' + OC.PERMISSION_UPDATE + '"/>' + t('core', 'change') + '</label>';
651
				}
652
				if (possiblePermissions & OC.PERMISSION_DELETE) {
653
					html += '<label><input id="canDelete-' + escapeHTML(shareWith) + '" type="checkbox" name="delete" class="permissions" ' + deleteChecked + ' data-permissions="' + OC.PERMISSION_DELETE + '"/>' + t('core', 'delete') + '</label>';
654
				}
655
				html += '</div>';
656
				html += '</li>';
657
				html = $(html).appendTo('#shareWithList');
658
				if (oc_config.enable_avatars === true) {
659
					if (shareType === OC.Share.SHARE_TYPE_USER) {
660
						html.find('.avatar').avatar(escapeHTML(shareWith), 32);
661
					} else {
662
						//Add sharetype to generate different seed if there is a group and use with the same name
663
						html.find('.avatar').imageplaceholder(escapeHTML(shareWith) + ' ' + shareType);
664
					}
665
				}
666
				// insert cruds button into last label element
667
				var lastLabel = html.find('>label:last');
668
				if (lastLabel.exists()){
669
					lastLabel.append(showCrudsButton);
670
				}
671
				else{
672
					html.find('.cruds').before(showCrudsButton);
673
				}
674
				if (!OC.Share.currentShares[shareType]) {
675
					OC.Share.currentShares[shareType] = [];
676
				}
677
				OC.Share.currentShares[shareType].push(shareItem);
678
			}
679
		},
680
		showLink:function(token, password, itemSource) {
681
			OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = true;
682
			$('#linkCheckbox').attr('checked', true);
683
684
			//check itemType
685
			var linkSharetype=$('#dropdown').data('item-type');
686
687
			if (! token) {
688
				//fallback to pre token link
689
				var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file');
690
				var type = $('tr').filterAttr('data-id', String(itemSource)).data('type');
691
				if ($('#dir').val() == '/') {
692
					var file = $('#dir').val() + filename;
693
				} else {
694
					var file = $('#dir').val() + '/' + filename;
695
				}
696
				file = '/'+OC.currentUser+'/files'+file;
697
				// TODO: use oc webroot ?
698
				var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&'+type+'='+encodeURIComponent(file);
699
			} else {
700
				//TODO add path param when showing a link to file in a subfolder of a public link share
701
				var service='';
702
				if(linkSharetype === 'folder' || linkSharetype === 'file'){
703
					service='files';
704
				}else{
705
					service=linkSharetype;
706
				}
707
708
				// TODO: use oc webroot ?
709
				if (service !== 'files') {
710
					var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service='+service+'&t='+token;
711
				} else {
712
					var link = parent.location.protocol+'//'+location.host+OC.generateUrl('/s/')+token;
713
				}
714
			}
715
			$('#linkText').val(link);
716
			$('#linkText').slideDown(OC.menuSpeed);
717
			$('#linkText').css('display','block');
718
			if (oc_appconfig.core.enforcePasswordForPublicLink === false || password === null) {
719
				$('#showPassword').show();
720
				$('#showPassword+label').show();
721
			}
722
			if (password != null) {
723
				$('#linkPass').slideDown(OC.menuSpeed);
724
				$('#showPassword').attr('checked', true);
725
				$('#linkPassText').attr('placeholder', '**********');
726
			}
727
			$('#expiration').show();
728
			$('#emailPrivateLink #email').show();
729
			$('#emailPrivateLink #emailButton').show();
730
			$('#allowPublicUploadWrapper').show();
731
		},
732
		hideLink:function() {
733
			$('#linkText').slideUp(OC.menuSpeed);
734
			$('#defaultExpireMessage').hide();
735
			$('#showPassword').hide();
736
			$('#showPassword+label').hide();
737
			$('#linkPass').slideUp(OC.menuSpeed);
738
			$('#emailPrivateLink #email').hide();
739
			$('#emailPrivateLink #emailButton').hide();
740
			$('#allowPublicUploadWrapper').hide();
741
		},
742
		dirname:function(path) {
743
			return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
744
		},
745
		/**
746
		 * Parses a string to an valid integer (unix timestamp)
747
		 * @param time
748
		 * @returns {*}
749
		 * @internal Only used to work around a bug in the backend
750
		 */
751
		_parseTime: function(time) {
752
			if (_.isString(time)) {
753
				// skip empty strings and hex values
754
				if (time === '' || (time.length > 1 && time[0] === '0' && time[1] === 'x')) {
755
					return null;
756
				}
757
				time = parseInt(time, 10);
758
				if(isNaN(time)) {
759
					time = null;
760
				}
761
			}
762
			return time;
763
		},
764
		/**
765
		 * Displays the expiration date field
766
		 *
767
		 * @param {Date} date current expiration date
768
		 * @param {int} [shareTime] share timestamp in seconds, defaults to now
769
		 */
770
		showExpirationDate:function(date, shareTime) {
771
			var now = new Date();
772
			// min date should always be the next day
773
			var minDate = new Date();
774
			minDate.setDate(minDate.getDate()+1);
775
			var datePickerOptions = {
776
				minDate: minDate,
777
				maxDate: null
778
			};
779
			// TODO: hack: backend returns string instead of integer
780
			shareTime = OC.Share._parseTime(shareTime);
781
			if (_.isNumber(shareTime)) {
782
				shareTime = new Date(shareTime * 1000);
783
			}
784
			if (!shareTime) {
785
				shareTime = now;
786
			}
787
			$('#expirationCheckbox').attr('checked', true);
788
			$('#expirationDate').val(date);
789
			$('#expirationDate').slideDown(OC.menuSpeed);
790
			$('#expirationDate').css('display','block');
791
			$('#expirationDate').datepicker({
792
				dateFormat : 'dd-mm-yy'
793
			});
794
			if (oc_appconfig.core.defaultExpireDateEnforced) {
795
				$('#expirationCheckbox').attr('disabled', true);
796
				shareTime = OC.Util.stripTime(shareTime).getTime();
797
				// max date is share date + X days
798
				datePickerOptions.maxDate = new Date(shareTime + oc_appconfig.core.defaultExpireDate * 24 * 3600 * 1000);
799
			}
800
			if(oc_appconfig.core.defaultExpireDateEnabled) {
801
				$('#defaultExpireMessage').slideDown(OC.menuSpeed);
802
			}
803
			$.datepicker.setDefaults(datePickerOptions);
804
		},
805
		/**
806
		 * Get the default Expire date
807
		 *
808
		 * @return {String} The expire date
809
		 */
810
		getDefaultExpirationDate:function() {
811
			var expireDateString = '';
812
			if (oc_appconfig.core.defaultExpireDateEnabled) {
813
				var date = new Date().getTime();
814
				var expireAfterMs = oc_appconfig.core.defaultExpireDate * 24 * 60 * 60 * 1000;
815
				var expireDate = new Date(date + expireAfterMs);
816
				var month = expireDate.getMonth() + 1;
817
				var year = expireDate.getFullYear();
818
				var day = expireDate.getDate();
819
				expireDateString = year + "-" + month + '-' + day + ' 00:00:00';
0 ignored issues
show
Strings must use singlequote.
Loading history...
820
			}
821
			return expireDateString;
822
		}
823
	});
824
825
	$(document).ready(function() {
826
827
		if(typeof monthNames != 'undefined'){
828
			// min date should always be the next day
829
			var minDate = new Date();
830
			minDate.setDate(minDate.getDate()+1);
831
			$.datepicker.setDefaults({
832
				monthNames: monthNames,
833
				monthNamesShort: $.map(monthNames, function(v) { return v.slice(0,3)+'.'; }),
834
				dayNames: dayNames,
835
				dayNamesMin: $.map(dayNames, function(v) { return v.slice(0,2); }),
836
				dayNamesShort: $.map(dayNames, function(v) { return v.slice(0,3)+'.'; }),
837
				firstDay: firstDay,
838
				minDate : minDate
839
			});
840
		}
841
		$(document).on('click', 'a.share', function(event) {
842
			event.stopPropagation();
843
			if ($(this).data('item-type') !== undefined && $(this).data('item') !== undefined) {
844
				var itemType = $(this).data('item-type');
845
				var itemSource = $(this).data('item');
846
				var appendTo = $(this).parent().parent();
847
				var link = false;
848
				var possiblePermissions = $(this).data('possible-permissions');
849
				if ($(this).data('link') !== undefined && $(this).data('link') == true) {
850
					link = true;
851
				}
852
				if (OC.Share.droppedDown) {
853
					if (itemSource != $('#dropdown').data('item')) {
854
						OC.Share.hideDropDown(function () {
855
							OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions);
856
						});
857
					} else {
858
						OC.Share.hideDropDown();
859
					}
860
				} else {
861
					OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions);
862
				}
863
			}
864
		});
865
866
		$(this).click(function(event) {
867
			var target = $(event.target);
868
			var isMatched = !target.is('.drop, .ui-datepicker-next, .ui-datepicker-prev, .ui-icon')
869
				&& !target.closest('#ui-datepicker-div').length && !target.closest('.ui-autocomplete').length;
870
			if (OC.Share.droppedDown && isMatched && $('#dropdown').has(event.target).length === 0) {
871
				OC.Share.hideDropDown();
872
			}
873
		});
874
875
		$(document).on('click', '#dropdown .showCruds', function() {
876
			$(this).closest('li').find('.cruds').toggle();
877
			return false;
878
		});
879
880
		$(document).on('click', '#dropdown .unshare', function() {
881
			var $li = $(this).closest('li');
882
			var itemType = $('#dropdown').data('item-type');
883
			var itemSource = $('#dropdown').data('item-source');
884
			var shareType = $li.data('share-type');
885
			var shareWith = $li.attr('data-share-with');
886
			var $button = $(this);
887
888
			if (!$button.is('a')) {
889
				$button = $button.closest('a');
890
			}
891
892
			if ($button.hasClass('icon-loading-small')) {
893
				// deletion in progress
894
				return false;
895
			}
896
			$button.empty().addClass('icon-loading-small');
897
898
			OC.Share.unshare(itemType, itemSource, shareType, shareWith, function() {
899
				$li.remove();
900
				var index = OC.Share.itemShares[shareType].indexOf(shareWith);
901
				OC.Share.itemShares[shareType].splice(index, 1);
902
				// updated list of shares
903
				OC.Share.currentShares[shareType].splice(index, 1);
904
				$('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares}));
905
				OC.Share.updateIcon(itemType, itemSource);
906
				if (typeof OC.Share.statuses[itemSource] === 'undefined') {
907
					$('#expiration').slideUp(OC.menuSpeed);
908
				}
909
			});
910
911
			return false;
912
		});
913
914
		$(document).on('change', '#dropdown .permissions', function() {
915
			var li = $(this).closest('li');
916
			if ($(this).attr('name') == 'edit') {
917
				var checkboxes = $('.permissions', li);
918
				var checked = $(this).is(':checked');
919
				// Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck
920
				$(checkboxes).filter('input[name="create"]').attr('checked', checked);
921
				$(checkboxes).filter('input[name="update"]').attr('checked', checked);
922
				$(checkboxes).filter('input[name="delete"]').attr('checked', checked);
923
			} else {
924
				var checkboxes = $('.permissions', li);
925
				// Uncheck Edit if Create, Update, and Delete are not checked
926
				if (!$(this).is(':checked')
927
					&& !$(checkboxes).filter('input[name="create"]').is(':checked')
928
					&& !$(checkboxes).filter('input[name="update"]').is(':checked')
929
					&& !$(checkboxes).filter('input[name="delete"]').is(':checked'))
930
				{
931
					$(checkboxes).filter('input[name="edit"]').attr('checked', false);
932
				// Check Edit if Create, Update, or Delete is checked
933
				} else if (($(this).attr('name') == 'create'
934
					|| $(this).attr('name') == 'update'
935
					|| $(this).attr('name') == 'delete'))
936
				{
937
					$(checkboxes).filter('input[name="edit"]').attr('checked', true);
938
				}
939
			}
940
			var permissions = OC.PERMISSION_READ;
941
			$(checkboxes).filter(':not(input[name="edit"])').filter(':checked').each(function(index, checkbox) {
942
				permissions |= $(checkbox).data('permissions');
943
			});
944
			OC.Share.setPermissions($('#dropdown').data('item-type'),
945
				$('#dropdown').data('item-source'),
946
				li.data('share-type'),
947
				li.attr('data-share-with'),
948
				permissions);
949
		});
950
951
		$(document).on('change', '#dropdown #linkCheckbox', function() {
952
			var $dropDown = $('#dropdown');
953
			var itemType = $dropDown.data('item-type');
954
			var itemSource = $dropDown.data('item-source');
955
			var itemSourceName = $dropDown.data('item-source-name');
956
			var $loading = $dropDown.find('#link .icon-loading-small');
957
			var $button = $(this);
958
959
			if (!$loading.hasClass('hidden')) {
960
				// already in progress
961
				return false;
962
			}
963
964
			if (this.checked) {
965
				// Reset password placeholder
966
				$('#linkPassText').attr('placeholder', t('core', 'Choose a password for the public link'));
967
				// Reset link
968
				$('#linkText').val('');
969
				$('#showPassword').prop('checked', false);
970
				$('#linkPass').hide();
971
				$('#sharingDialogAllowPublicUpload').prop('checked', false);
972
				$('#expirationCheckbox').prop('checked', false);
973
				$('#expirationDate').hide();
974
				var expireDateString = '';
975
				// Create a link
976
				if (oc_appconfig.core.enforcePasswordForPublicLink === false) {
977
					expireDateString = OC.Share.getDefaultExpirationDate();
978
					$loading.removeClass('hidden');
979
					$button.addClass('hidden');
980
					$button.prop('disabled', true);
981
982
					OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, itemSourceName, expireDateString, function(data) {
983
						$loading.addClass('hidden');
984
						$button.removeClass('hidden');
985
						$button.prop('disabled', false);
986
						OC.Share.showLink(data.token, null, itemSource);
987
						$('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares}));
988
						OC.Share.updateIcon(itemType, itemSource);
989
					});
990
				} else {
991
					$('#linkPass').slideToggle(OC.menuSpeed);
992
					// TODO drop with IE8 drop
993
					if($('html').hasClass('ie8')) {
994
						$('#linkPassText').attr('placeholder', null);
995
						$('#linkPassText').val('');
996
					}
997
					$('#linkPassText').focus();
998
				}
999
				if (expireDateString !== '') {
1000
					OC.Share.showExpirationDate(expireDateString);
1001
				}
1002
			} else {
1003
				// Delete private link
1004
				OC.Share.hideLink();
1005
				$('#expiration').slideUp(OC.menuSpeed);
1006
				if ($('#linkText').val() !== '') {
1007
					$loading.removeClass('hidden');
1008
					$button.addClass('hidden');
1009
					$button.prop('disabled', true);
1010
					OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() {
1011
						$loading.addClass('hidden');
1012
						$button.removeClass('hidden');
1013
						$button.prop('disabled', false);
1014
						OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = false;
1015
						$('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares}));
1016
						OC.Share.updateIcon(itemType, itemSource);
1017
						if (typeof OC.Share.statuses[itemSource] === 'undefined') {
1018
							$('#expiration').slideUp(OC.menuSpeed);
1019
						}
1020
					});
1021
				}
1022
			}
1023
		});
1024
1025
		$(document).on('click', '#dropdown #linkText', function() {
1026
			$(this).focus();
1027
			$(this).select();
1028
		});
1029
1030
		// Handle the Allow Public Upload Checkbox
1031
		$(document).on('click', '#sharingDialogAllowPublicUpload', function() {
1032
1033
			// Gather data
1034
			var $dropDown = $('#dropdown');
1035
			var allowPublicUpload = $(this).is(':checked');
1036
			var itemType = $dropDown.data('item-type');
1037
			var itemSource = $dropDown.data('item-source');
1038
			var itemSourceName = $dropDown.data('item-source-name');
1039
			var expirationDate = '';
1040
			if ($('#expirationCheckbox').is(':checked') === true) {
1041
				expirationDate = $( "#expirationDate" ).val();
0 ignored issues
show
Strings must use singlequote.
Loading history...
1042
			}
1043
			var permissions = 0;
1044
			var $button = $(this);
1045
			var $loading = $dropDown.find('#allowPublicUploadWrapper .icon-loading-small');
1046
1047
			if (!$loading.hasClass('hidden')) {
1048
				// already in progress
1049
				return false;
1050
			}
1051
1052
			// Calculate permissions
1053
			if (allowPublicUpload) {
1054
				permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ;
1055
			} else {
1056
				permissions = OC.PERMISSION_READ;
1057
			}
1058
1059
			// Update the share information
1060
			$button.addClass('hidden');
1061
			$button.prop('disabled', true);
1062
			$loading.removeClass('hidden');
1063
			OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, itemSourceName, expirationDate, function(data) {
1064
				$loading.addClass('hidden');
1065
				$button.removeClass('hidden');
1066
				$button.prop('disabled', false);
1067
			});
1068
		});
1069
1070
		$(document).on('click', '#dropdown #showPassword', function() {
1071
			$('#linkPass').slideToggle(OC.menuSpeed);
1072
			if (!$('#showPassword').is(':checked') ) {
1073
				var itemType = $('#dropdown').data('item-type');
1074
				var itemSource = $('#dropdown').data('item-source');
1075
				var itemSourceName = $('#dropdown').data('item-source-name');
1076
				var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked');
1077
				var permissions = 0;
1078
				var $loading = $('#showPassword .icon-loading-small');
1079
1080
				// Calculate permissions
1081
				if (allowPublicUpload) {
1082
					permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ;
1083
				} else {
1084
					permissions = OC.PERMISSION_READ;
1085
				}
1086
1087
				$loading.removeClass('hidden');
1088
				OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, itemSourceName).then(function() {
1089
					$loading.addClass('hidden');
1090
					$('#linkPassText').attr('placeholder', t('core', 'Choose a password for the public link'));
1091
				});
1092
			} else {
1093
				$('#linkPassText').focus();
1094
			}
1095
		});
1096
1097
		$(document).on('focusout keyup', '#dropdown #linkPassText', function(event) {
1098
			var linkPassText = $('#linkPassText');
1099
			if ( linkPassText.val() != '' && (event.type == 'focusout' || event.keyCode == 13) ) {
1100
				var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked');
1101
				var dropDown = $('#dropdown');
1102
				var itemType = dropDown.data('item-type');
1103
				var itemSource = dropDown.data('item-source');
1104
				var itemSourceName = $('#dropdown').data('item-source-name');
1105
				var permissions = 0;
1106
				var $loading = dropDown.find('#linkPass .icon-loading-small');
1107
1108
				// Calculate permissions
1109
				if (allowPublicUpload) {
1110
					permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ;
1111
				} else {
1112
					permissions = OC.PERMISSION_READ;
1113
				}
1114
1115
				var expireDateString = OC.Share.getDefaultExpirationDate();
1116
1117
				$loading.removeClass('hidden');
1118
				OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), permissions, itemSourceName, expireDateString, function(data) {
1119
					$loading.addClass('hidden');
1120
					linkPassText.val('');
1121
					linkPassText.attr('placeholder', t('core', 'Password protected'));
1122
1123
					if (oc_appconfig.core.enforcePasswordForPublicLink) {
1124
						OC.Share.showLink(data.token, "password set", itemSource);
0 ignored issues
show
Strings must use singlequote.
Loading history...
1125
						OC.Share.updateIcon(itemType, itemSource);
1126
					}
1127
					$('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares}));
1128
				}, function(result) {
1129
					$loading.addClass('hidden');
1130
					linkPassText.val('');
1131
					linkPassText.attr('placeholder', result.data.message);
1132
				});
1133
1134
				if (expireDateString !== '') {
1135
					OC.Share.showExpirationDate(expireDateString);
1136
				}
1137
			}
1138
		});
1139
1140
		$(document).on('click', '#dropdown #expirationCheckbox', function() {
1141
			if (this.checked) {
1142
				OC.Share.showExpirationDate('');
1143
			} else {
1144
				var itemType = $('#dropdown').data('item-type');
1145
				var itemSource = $('#dropdown').data('item-source');
1146
				$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: '' }, function(result) {
1147
					if (!result || result.status !== 'success') {
1148
						OC.dialogs.alert(t('core', 'Error unsetting expiration date'), t('core', 'Error'));
1149
					}
1150
					$('#expirationDate').slideUp(OC.menuSpeed);
1151
					if (oc_appconfig.core.defaultExpireDateEnforced === false) {
1152
						$('#defaultExpireMessage').slideDown(OC.menuSpeed);
1153
					}
1154
				});
1155
			}
1156
		});
1157
1158
		$(document).on('change', '#dropdown #expirationDate', function() {
1159
			var itemType = $('#dropdown').data('item-type');
1160
			var itemSource = $('#dropdown').data('item-source');
1161
1162
			$(this).tipsy('hide');
1163
			$(this).removeClass('error');
1164
1165
			$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: $(this).val() }, function(result) {
1166
				if (!result || result.status !== 'success') {
1167
					var expirationDateField = $('#dropdown #expirationDate');
1168
					if (!result.data.message) {
1169
						expirationDateField.attr('original-title', t('core', 'Error setting expiration date'));
1170
					} else {
1171
						expirationDateField.attr('original-title', result.data.message);
1172
					}
1173
					expirationDateField.tipsy({gravity: 'n'});
1174
					expirationDateField.tipsy('show');
1175
					expirationDateField.addClass('error');
1176
				} else {
1177
					if (oc_appconfig.core.defaultExpireDateEnforced === 'no') {
1178
						$('#defaultExpireMessage').slideUp(OC.menuSpeed);
1179
					}
1180
				}
1181
			});
1182
		});
1183
1184
1185
		$(document).on('submit', '#dropdown #emailPrivateLink', function(event) {
1186
			event.preventDefault();
1187
			var link = $('#linkText').val();
1188
			var itemType = $('#dropdown').data('item-type');
1189
			var itemSource = $('#dropdown').data('item-source');
1190
			var file = $('tr').filterAttr('data-id', String(itemSource)).data('file');
1191
			var email = $('#email').val();
1192
			var expirationDate = '';
1193
			if ( $('#expirationCheckbox').is(':checked') === true ) {
1194
				expirationDate = $( "#expirationDate" ).val();
0 ignored issues
show
Strings must use singlequote.
Loading history...
1195
			}
1196
			if (email != '') {
1197
				$('#email').prop('disabled', true);
1198
				$('#email').val(t('core', 'Sending ...'));
1199
				$('#emailButton').prop('disabled', true);
1200
1201
				$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'email', toaddress: email, link: link, itemType: itemType, itemSource: itemSource, file: file, expiration: expirationDate},
1202
					function(result) {
1203
						$('#email').prop('disabled', false);
1204
						$('#emailButton').prop('disabled', false);
1205
					if (result && result.status == 'success') {
1206
						$('#email').css('font-weight', 'bold').val(t('core','Email sent'));
1207
						setTimeout(function() {
1208
							$('#email').css('font-weight', 'normal').val('');
1209
						}, 2000);
1210
					} else {
1211
						OC.dialogs.alert(result.data.message, t('core', 'Error while sharing'));
1212
					}
1213
				});
1214
			}
1215
		});
1216
1217
		$(document).on('click', '#dropdown input[name=mailNotification]', function() {
1218
			var $li = $(this).closest('li');
1219
			var itemType = $('#dropdown').data('item-type');
1220
			var itemSource = $('#dropdown').data('item-source');
1221
			var action = '';
1222
			if (this.checked) {
1223
				action = 'informRecipients';
1224
			} else {
1225
				action = 'informRecipientsDisabled';
1226
			}
1227
1228
			var shareType = $li.data('share-type');
1229
			var shareWith = $li.attr('data-share-with');
1230
1231
			$.post(OC.filePath('core', 'ajax', 'share.php'), {action: action, recipient: shareWith, shareType: shareType, itemSource: itemSource, itemType: itemType}, function(result) {
1232
				if (result.status !== 'success') {
1233
					OC.dialogs.alert(t('core', result.data.message), t('core', 'Warning'));
1234
				}
1235
			});
1236
1237
		});
1238
1239
	});
1240
1241
})(OC);
1242
1243