Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

share.js 40KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. /* global escapeHTML */
  2. /**
  3. * @namespace
  4. */
  5. OC.Share={
  6. SHARE_TYPE_USER:0,
  7. SHARE_TYPE_GROUP:1,
  8. SHARE_TYPE_LINK:3,
  9. SHARE_TYPE_EMAIL:4,
  10. /**
  11. * Regular expression for splitting parts of remote share owners:
  12. * "user@example.com/path/to/owncloud"
  13. * "user@anotherexample.com@example.com/path/to/owncloud
  14. */
  15. _REMOTE_OWNER_REGEXP: new RegExp("^([^@]*)@(([^@]*)@)?([^/]*)(.*)?$"),
  16. /**
  17. * @deprecated use OC.Share.currentShares instead
  18. */
  19. itemShares:[],
  20. /**
  21. * Full list of all share statuses
  22. */
  23. statuses:{},
  24. /**
  25. * Shares for the currently selected file.
  26. * (for which the dropdown is open)
  27. *
  28. * Key is item type and value is an array or
  29. * shares of the given item type.
  30. */
  31. currentShares: {},
  32. /**
  33. * Whether the share dropdown is opened.
  34. */
  35. droppedDown:false,
  36. /**
  37. * Loads ALL share statuses from server, stores them in
  38. * OC.Share.statuses then calls OC.Share.updateIcons() to update the
  39. * files "Share" icon to "Shared" according to their share status and
  40. * share type.
  41. *
  42. * If a callback is specified, the update step is skipped.
  43. *
  44. * @param itemType item type
  45. * @param fileList file list instance, defaults to OCA.Files.App.fileList
  46. * @param callback function to call after the shares were loaded
  47. */
  48. loadIcons:function(itemType, fileList, callback) {
  49. // Load all share icons
  50. $.get(
  51. OC.filePath('core', 'ajax', 'share.php'),
  52. {
  53. fetch: 'getItemsSharedStatuses',
  54. itemType: itemType
  55. }, function(result) {
  56. if (result && result.status === 'success') {
  57. OC.Share.statuses = {};
  58. $.each(result.data, function(item, data) {
  59. OC.Share.statuses[item] = data;
  60. });
  61. if (_.isFunction(callback)) {
  62. callback(OC.Share.statuses);
  63. } else {
  64. OC.Share.updateIcons(itemType, fileList);
  65. }
  66. }
  67. }
  68. );
  69. },
  70. /**
  71. * Updates the files' "Share" icons according to the known
  72. * sharing states stored in OC.Share.statuses.
  73. * (not reloaded from server)
  74. *
  75. * @param itemType item type
  76. * @param fileList file list instance
  77. * defaults to OCA.Files.App.fileList
  78. */
  79. updateIcons:function(itemType, fileList){
  80. var item;
  81. var $fileList;
  82. var currentDir;
  83. if (!fileList && OCA.Files) {
  84. fileList = OCA.Files.App.fileList;
  85. }
  86. // fileList is usually only defined in the files app
  87. if (fileList) {
  88. $fileList = fileList.$fileList;
  89. currentDir = fileList.getCurrentDirectory();
  90. }
  91. // TODO: iterating over the files might be more efficient
  92. for (item in OC.Share.statuses){
  93. var image = OC.imagePath('core', 'actions/share');
  94. var data = OC.Share.statuses[item];
  95. var hasLink = data.link;
  96. // Links override shared in terms of icon display
  97. if (hasLink) {
  98. image = OC.imagePath('core', 'actions/public');
  99. }
  100. if (itemType !== 'file' && itemType !== 'folder') {
  101. $('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center');
  102. } else {
  103. // TODO: ultimately this part should be moved to files_sharing app
  104. var file = $fileList.find('tr[data-id="'+item+'"]');
  105. var shareFolder = OC.imagePath('core', 'filetypes/folder-shared');
  106. var img;
  107. if (file.length > 0) {
  108. this.markFileAsShared(file, true, hasLink);
  109. } else {
  110. var dir = currentDir;
  111. if (dir.length > 1) {
  112. var last = '';
  113. var path = dir;
  114. // Search for possible parent folders that are shared
  115. while (path != last) {
  116. if (path === data.path && !data.link) {
  117. var actions = $fileList.find('.fileactions .action[data-action="Share"]');
  118. var files = $fileList.find('.filename');
  119. var i;
  120. for (i = 0; i < actions.length; i++) {
  121. // TODO: use this.markFileAsShared()
  122. img = $(actions[i]).find('img');
  123. if (img.attr('src') !== OC.imagePath('core', 'actions/public')) {
  124. img.attr('src', image);
  125. $(actions[i]).addClass('permanent');
  126. $(actions[i]).html(' <span>'+t('core', 'Shared')+'</span>').prepend(img);
  127. }
  128. }
  129. for(i = 0; i < files.length; i++) {
  130. if ($(files[i]).closest('tr').data('type') === 'dir') {
  131. $(files[i]).css('background-image', 'url('+shareFolder+')');
  132. }
  133. }
  134. }
  135. last = path;
  136. path = OC.Share.dirname(path);
  137. }
  138. }
  139. }
  140. }
  141. }
  142. },
  143. updateIcon:function(itemType, itemSource) {
  144. var shares = false;
  145. var link = false;
  146. var image = OC.imagePath('core', 'actions/share');
  147. $.each(OC.Share.itemShares, function(index) {
  148. if (OC.Share.itemShares[index]) {
  149. if (index == OC.Share.SHARE_TYPE_LINK) {
  150. if (OC.Share.itemShares[index] == true) {
  151. shares = true;
  152. image = OC.imagePath('core', 'actions/public');
  153. link = true;
  154. return;
  155. }
  156. } else if (OC.Share.itemShares[index].length > 0) {
  157. shares = true;
  158. image = OC.imagePath('core', 'actions/share');
  159. }
  160. }
  161. });
  162. if (itemType != 'file' && itemType != 'folder') {
  163. $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+image+') no-repeat center');
  164. } else {
  165. var $tr = $('tr').filterAttr('data-id', String(itemSource));
  166. if ($tr.length > 0) {
  167. // it might happen that multiple lists exist in the DOM
  168. // with the same id
  169. $tr.each(function() {
  170. OC.Share.markFileAsShared($(this), shares, link);
  171. });
  172. }
  173. }
  174. if (shares) {
  175. OC.Share.statuses[itemSource] = OC.Share.statuses[itemSource] || {};
  176. OC.Share.statuses[itemSource]['link'] = link;
  177. } else {
  178. delete OC.Share.statuses[itemSource];
  179. }
  180. },
  181. /**
  182. * Format remote share owner to make it more readable
  183. *
  184. * @param {String} owner full remote share owner name
  185. * @return {String} HTML code for the owner display
  186. */
  187. _formatSharedByOwner: function(owner) {
  188. var parts = this._REMOTE_OWNER_REGEXP.exec(owner);
  189. if (!parts) {
  190. // display as is, most likely to be a simple owner name
  191. return escapeHTML(owner);
  192. }
  193. var userName = parts[1];
  194. var userDomain = parts[3];
  195. var server = parts[4];
  196. var tooltip = userName;
  197. if (userDomain) {
  198. tooltip += '@' + userDomain;
  199. }
  200. if (server) {
  201. tooltip += '@' + server;
  202. }
  203. var html = '<span class="remoteOwner" title="' + escapeHTML(tooltip) + '">';
  204. html += '<span class="username">' + escapeHTML(userName) + '</span>';
  205. if (userDomain) {
  206. html += '<span class="userDomain">@' + escapeHTML(userDomain) + '</span>';
  207. }
  208. html += '</span>';
  209. return html;
  210. },
  211. /**
  212. * Marks/unmarks a given file as shared by changing its action icon
  213. * and folder icon.
  214. *
  215. * @param $tr file element to mark as shared
  216. * @param hasShares whether shares are available
  217. * @param hasLink whether link share is available
  218. */
  219. markFileAsShared: function($tr, hasShares, hasLink) {
  220. var action = $tr.find('.fileactions .action[data-action="Share"]');
  221. var type = $tr.data('type');
  222. var img = action.find('img');
  223. var message;
  224. var recipients;
  225. var owner = $tr.attr('data-share-owner');
  226. var shareFolderIcon;
  227. var image = OC.imagePath('core', 'actions/share');
  228. // update folder icon
  229. if (type === 'dir' && (hasShares || hasLink || owner)) {
  230. if (hasLink) {
  231. shareFolderIcon = OC.imagePath('core', 'filetypes/folder-public');
  232. }
  233. else {
  234. shareFolderIcon = OC.imagePath('core', 'filetypes/folder-shared');
  235. }
  236. $tr.children('.filename').css('background-image', 'url(' + shareFolderIcon + ')');
  237. } else if (type === 'dir') {
  238. shareFolderIcon = OC.imagePath('core', 'filetypes/folder');
  239. $tr.children('.filename').css('background-image', 'url(' + shareFolderIcon + ')');
  240. }
  241. // update share action text / icon
  242. if (hasShares || owner) {
  243. recipients = $tr.attr('data-share-recipients');
  244. action.addClass('permanent');
  245. message = t('core', 'Shared');
  246. // even if reshared, only show "Shared by"
  247. if (owner) {
  248. message = this._formatSharedByOwner(owner);
  249. }
  250. else if (recipients) {
  251. message = t('core', 'Shared with {recipients}', {recipients: escapeHTML(recipients)});
  252. }
  253. action.html(' <span>' + message + '</span>').prepend(img);
  254. if (owner) {
  255. action.find('.remoteOwner').tipsy({gravity: 's'});
  256. }
  257. }
  258. else {
  259. action.removeClass('permanent');
  260. action.html(' <span>'+ escapeHTML(t('core', 'Share'))+'</span>').prepend(img);
  261. }
  262. if (hasLink) {
  263. image = OC.imagePath('core', 'actions/public');
  264. }
  265. img.attr('src', image);
  266. },
  267. loadItem:function(itemType, itemSource) {
  268. var data = '';
  269. var checkReshare = true;
  270. if (typeof OC.Share.statuses[itemSource] === 'undefined') {
  271. // NOTE: Check does not always work and misses some shares, fix later
  272. var checkShares = true;
  273. } else {
  274. var checkShares = true;
  275. }
  276. $.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) {
  277. if (result && result.status === 'success') {
  278. data = result.data;
  279. } else {
  280. data = false;
  281. }
  282. }});
  283. return data;
  284. },
  285. share:function(itemType, itemSource, shareType, shareWith, permissions, itemSourceName, expirationDate, callback) {
  286. // Add a fallback for old share() calls without expirationDate.
  287. // We should remove this in a later version,
  288. // after the Apps have been updated.
  289. if (typeof callback === 'undefined' &&
  290. typeof expirationDate === 'function') {
  291. callback = expirationDate;
  292. expirationDate = '';
  293. console.warn(
  294. "Call to 'OC.Share.share()' with too few arguments. " +
  295. "'expirationDate' was assumed to be 'callback'. " +
  296. "Please revisit the call and fix the list of arguments."
  297. );
  298. }
  299. $.post(OC.filePath('core', 'ajax', 'share.php'),
  300. {
  301. action: 'share',
  302. itemType: itemType,
  303. itemSource: itemSource,
  304. shareType: shareType,
  305. shareWith: shareWith,
  306. permissions: permissions,
  307. itemSourceName: itemSourceName,
  308. expirationDate: expirationDate
  309. }, function (result) {
  310. if (result && result.status === 'success') {
  311. if (callback) {
  312. callback(result.data);
  313. }
  314. } else {
  315. if (result.data && result.data.message) {
  316. var msg = result.data.message;
  317. } else {
  318. var msg = t('core', 'Error');
  319. }
  320. OC.dialogs.alert(msg, t('core', 'Error while sharing'));
  321. }
  322. }
  323. );
  324. },
  325. unshare:function(itemType, itemSource, shareType, shareWith, callback) {
  326. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith }, function(result) {
  327. if (result && result.status === 'success') {
  328. if (callback) {
  329. callback();
  330. }
  331. } else {
  332. OC.dialogs.alert(t('core', 'Error while unsharing'), t('core', 'Error'));
  333. }
  334. });
  335. },
  336. setPermissions:function(itemType, itemSource, shareType, shareWith, permissions) {
  337. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setPermissions', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
  338. if (!result || result.status !== 'success') {
  339. OC.dialogs.alert(t('core', 'Error while changing permissions'), t('core', 'Error'));
  340. }
  341. });
  342. },
  343. showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions, filename) {
  344. var data = OC.Share.loadItem(itemType, itemSource);
  345. var dropDownEl;
  346. var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">';
  347. if (data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined) {
  348. if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) {
  349. html += '<span class="reshare">'+t('core', 'Shared with you and the group {group} by {owner}', {group: escapeHTML(data.reshare.share_with), owner: escapeHTML(data.reshare.displayname_owner)})+'</span>';
  350. } else {
  351. html += '<span class="reshare">'+t('core', 'Shared with you by {owner}', {owner: escapeHTML(data.reshare.displayname_owner)})+'</span>';
  352. }
  353. html += '<br />';
  354. }
  355. if (possiblePermissions & OC.PERMISSION_SHARE) {
  356. // Determine the Allow Public Upload status.
  357. // Used later on to determine if the
  358. // respective checkbox should be checked or
  359. // not.
  360. var publicUploadEnabled = $('#filestable').data('allow-public-upload');
  361. if (typeof publicUploadEnabled == 'undefined') {
  362. publicUploadEnabled = 'no';
  363. }
  364. var allowPublicUploadStatus = false;
  365. $.each(data.shares, function(key, value) {
  366. if (value.share_type === OC.Share.SHARE_TYPE_LINK) {
  367. allowPublicUploadStatus = (value.permissions & OC.PERMISSION_CREATE) ? true : false;
  368. return true;
  369. }
  370. });
  371. html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Share with user or group …')+'" />';
  372. html += '<ul id="shareWithList">';
  373. html += '</ul>';
  374. var linksAllowed = $('#allowShareWithLink').val() === 'yes';
  375. if (link && linksAllowed) {
  376. html += '<div id="link">';
  377. html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">'+t('core', 'Share link')+'</label>';
  378. html += '<br />';
  379. var defaultExpireMessage = '';
  380. if ((itemType === 'folder' || itemType === 'file') && oc_appconfig.core.defaultExpireDateEnforced) {
  381. defaultExpireMessage = t('core', 'The public link will expire no later than {days} days after it is created', {'days': escapeHTML(oc_appconfig.core.defaultExpireDate)}) + '<br/>';
  382. }
  383. html += '<input id="linkText" type="text" readonly="readonly" />';
  384. html += '<input type="checkbox" name="showPassword" id="showPassword" value="1" style="display:none;" /><label for="showPassword" style="display:none;">'+t('core', 'Password protect')+'</label>';
  385. html += '<div id="linkPass">';
  386. html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Choose a password for the public link')+'" />';
  387. html += '</div>';
  388. if (itemType === 'folder' && (possiblePermissions & OC.PERMISSION_CREATE) && publicUploadEnabled === 'yes') {
  389. html += '<div id="allowPublicUploadWrapper" style="display:none;">';
  390. html += '<input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload"' + ((allowPublicUploadStatus) ? 'checked="checked"' : '') + ' />';
  391. html += '<label for="sharingDialogAllowPublicUpload">' + t('core', 'Allow Public Upload') + '</label>';
  392. html += '</div>';
  393. }
  394. html += '</div><form id="emailPrivateLink" >';
  395. html += '<input id="email" style="display:none; width:62%;" value="" placeholder="'+t('core', 'Email link to person')+'" type="text" />';
  396. html += '<input id="emailButton" style="display:none;" type="submit" value="'+t('core', 'Send')+'" />';
  397. html += '</form>';
  398. }
  399. html += '<div id="expiration">';
  400. html += '<input type="checkbox" name="expirationCheckbox" id="expirationCheckbox" value="1" /><label for="expirationCheckbox">'+t('core', 'Set expiration date')+'</label>';
  401. html += '<input id="expirationDate" type="text" placeholder="'+t('core', 'Expiration date')+'" style="display:none; width:90%;" />';
  402. html += '<em id="defaultExpireMessage">'+defaultExpireMessage+'</em>';
  403. html += '</div>';
  404. dropDownEl = $(html);
  405. dropDownEl = dropDownEl.appendTo(appendTo);
  406. // Reset item shares
  407. OC.Share.itemShares = [];
  408. OC.Share.currentShares = {};
  409. if (data.shares) {
  410. $.each(data.shares, function(index, share) {
  411. if (share.share_type == OC.Share.SHARE_TYPE_LINK) {
  412. if (itemSource === share.file_source || itemSource === share.item_source) {
  413. OC.Share.showLink(share.token, share.share_with, itemSource);
  414. }
  415. } else {
  416. if (share.collection) {
  417. OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, share.collection);
  418. } else {
  419. OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, false);
  420. }
  421. }
  422. if (share.expiration != null) {
  423. OC.Share.showExpirationDate(share.expiration, share.stime);
  424. }
  425. });
  426. }
  427. $('#shareWith').autocomplete({minLength: 1, source: function(search, response) {
  428. $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term, itemShares: OC.Share.itemShares }, function(result) {
  429. if (result.status == 'success' && result.data.length > 0) {
  430. $( "#shareWith" ).autocomplete( "option", "autoFocus", true );
  431. response(result.data);
  432. } else {
  433. response();
  434. }
  435. });
  436. },
  437. focus: function(event, focused) {
  438. event.preventDefault();
  439. },
  440. select: function(event, selected) {
  441. event.stopPropagation();
  442. var itemType = $('#dropdown').data('item-type');
  443. var itemSource = $('#dropdown').data('item-source');
  444. var itemSourceName = $('#dropdown').data('item-source-name');
  445. var expirationDate = '';
  446. if ( $('#expirationCheckbox').is(':checked') === true ) {
  447. expirationDate = $( "#expirationDate" ).val();
  448. }
  449. var shareType = selected.item.value.shareType;
  450. var shareWith = selected.item.value.shareWith;
  451. $(this).val(shareWith);
  452. // Default permissions are Edit (CRUD) and Share
  453. // Check if these permissions are possible
  454. var permissions = OC.PERMISSION_READ;
  455. if (possiblePermissions & OC.PERMISSION_UPDATE) {
  456. permissions = permissions | OC.PERMISSION_UPDATE;
  457. }
  458. if (possiblePermissions & OC.PERMISSION_CREATE) {
  459. permissions = permissions | OC.PERMISSION_CREATE;
  460. }
  461. if (possiblePermissions & OC.PERMISSION_DELETE) {
  462. permissions = permissions | OC.PERMISSION_DELETE;
  463. }
  464. if (oc_appconfig.core.resharingAllowed && (possiblePermissions & OC.PERMISSION_SHARE)) {
  465. permissions = permissions | OC.PERMISSION_SHARE;
  466. }
  467. OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, itemSourceName, expirationDate, function() {
  468. OC.Share.addShareWith(shareType, shareWith, selected.item.label, permissions, possiblePermissions);
  469. $('#shareWith').val('');
  470. $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares}));
  471. OC.Share.updateIcon(itemType, itemSource);
  472. });
  473. return false;
  474. }
  475. })
  476. // customize internal _renderItem function to display groups and users differently
  477. .data("ui-autocomplete")._renderItem = function( ul, item ) {
  478. var insert = $( "<a>" );
  479. var text = (item.value.shareType == 1)? item.label + ' ('+t('core', 'group')+')' : item.label;
  480. insert.text( text );
  481. if(item.value.shareType == 1) {
  482. insert = insert.wrapInner('<strong></strong>');
  483. }
  484. return $( "<li>" )
  485. .addClass((item.value.shareType == 1)?'group':'user')
  486. .append( insert )
  487. .appendTo( ul );
  488. };
  489. if (link && linksAllowed) {
  490. $('#email').autocomplete({
  491. minLength: 1,
  492. source: function (search, response) {
  493. $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWithEmail', search: search.term }, function(result) {
  494. if (result.status == 'success' && result.data.length > 0) {
  495. response(result.data);
  496. }
  497. });
  498. },
  499. select: function( event, item ) {
  500. $('#email').val(item.item.email);
  501. return false;
  502. }
  503. })
  504. .data("ui-autocomplete")._renderItem = function( ul, item ) {
  505. return $('<li>')
  506. .append('<a>' + escapeHTML(item.displayname) + "<br>" + escapeHTML(item.email) + '</a>' )
  507. .appendTo( ul );
  508. };
  509. }
  510. } else {
  511. html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Resharing is not allowed')+'" style="width:90%;" disabled="disabled"/>';
  512. html += '</div>';
  513. dropDownEl = $(html);
  514. dropDownEl.appendTo(appendTo);
  515. }
  516. dropDownEl.attr('data-item-source-name', filename);
  517. $('#dropdown').show('blind', function() {
  518. OC.Share.droppedDown = true;
  519. });
  520. if ($('html').hasClass('lte9')){
  521. $('#dropdown input[placeholder]').placeholder();
  522. }
  523. $('#shareWith').focus();
  524. },
  525. hideDropDown:function(callback) {
  526. OC.Share.currentShares = null;
  527. $('#dropdown').hide('blind', function() {
  528. OC.Share.droppedDown = false;
  529. $('#dropdown').remove();
  530. if (typeof FileActions !== 'undefined') {
  531. $('tr').removeClass('mouseOver');
  532. }
  533. if (callback) {
  534. callback.call();
  535. }
  536. });
  537. },
  538. addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, mailSend, collection) {
  539. var shareItem = {
  540. share_type: shareType,
  541. share_with: shareWith,
  542. share_with_displayname: shareWithDisplayName,
  543. permissions: permissions
  544. };
  545. if (shareType === 1) {
  546. shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'group') + ')';
  547. }
  548. if (!OC.Share.itemShares[shareType]) {
  549. OC.Share.itemShares[shareType] = [];
  550. }
  551. OC.Share.itemShares[shareType].push(shareWith);
  552. if (collection) {
  553. if (collection.item_type == 'file' || collection.item_type == 'folder') {
  554. var item = collection.path;
  555. } else {
  556. var item = collection.item_source;
  557. }
  558. var collectionList = $('#shareWithList li').filterAttr('data-collection', item);
  559. if (collectionList.length > 0) {
  560. $(collectionList).append(', '+shareWithDisplayName);
  561. } else {
  562. var html = '<li style="clear: both;" data-collection="'+item+'">'+t('core', 'Shared in {item} with {user}', {'item': escapeHTML(item), user: escapeHTML(shareWithDisplayName)})+'</li>';
  563. $('#shareWithList').prepend(html);
  564. }
  565. } else {
  566. var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = '';
  567. if (permissions & OC.PERMISSION_CREATE) {
  568. createChecked = 'checked="checked"';
  569. editChecked = 'checked="checked"';
  570. }
  571. if (permissions & OC.PERMISSION_UPDATE) {
  572. updateChecked = 'checked="checked"';
  573. editChecked = 'checked="checked"';
  574. }
  575. if (permissions & OC.PERMISSION_DELETE) {
  576. deleteChecked = 'checked="checked"';
  577. editChecked = 'checked="checked"';
  578. }
  579. if (permissions & OC.PERMISSION_SHARE) {
  580. shareChecked = 'checked="checked"';
  581. }
  582. var html = '<li style="clear: both;" data-share-type="'+escapeHTML(shareType)+'" data-share-with="'+escapeHTML(shareWith)+'" title="' + escapeHTML(shareWith) + '">';
  583. var showCrudsButton;
  584. html += '<a href="#" class="unshare"><img class="svg" alt="'+t('core', 'Unshare')+'" title="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
  585. html += '<span class="username">' + escapeHTML(shareWithDisplayName) + '</span>';
  586. var mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val();
  587. if (mailNotificationEnabled === 'yes') {
  588. var checked = '';
  589. if (mailSend === '1') {
  590. checked = 'checked';
  591. }
  592. html += '<label><input type="checkbox" name="mailNotification" class="mailNotification" ' + checked + ' />'+t('core', 'notify by email')+'</label> ';
  593. }
  594. if (oc_appconfig.core.resharingAllowed && (possiblePermissions & OC.PERMISSION_SHARE)) {
  595. html += '<label><input type="checkbox" name="share" class="permissions" '+shareChecked+' data-permissions="'+OC.PERMISSION_SHARE+'" />'+t('core', 'can share')+'</label>';
  596. }
  597. if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) {
  598. html += '<label><input type="checkbox" name="edit" class="permissions" '+editChecked+' />'+t('core', 'can edit')+'</label> ';
  599. }
  600. showCrudsButton = '<a href="#" class="showCruds"><img class="svg" alt="'+t('core', 'access control')+'" title="'+t('core', 'access control')+'" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>';
  601. html += '<div class="cruds" style="display:none;">';
  602. if (possiblePermissions & OC.PERMISSION_CREATE) {
  603. html += '<label><input type="checkbox" name="create" class="permissions" '+createChecked+' data-permissions="'+OC.PERMISSION_CREATE+'" />'+t('core', 'create')+'</label>';
  604. }
  605. if (possiblePermissions & OC.PERMISSION_UPDATE) {
  606. html += '<label><input type="checkbox" name="update" class="permissions" '+updateChecked+' data-permissions="'+OC.PERMISSION_UPDATE+'" />'+t('core', 'update')+'</label>';
  607. }
  608. if (possiblePermissions & OC.PERMISSION_DELETE) {
  609. html += '<label><input type="checkbox" name="delete" class="permissions" '+deleteChecked+' data-permissions="'+OC.PERMISSION_DELETE+'" />'+t('core', 'delete')+'</label>';
  610. }
  611. html += '</div>';
  612. html += '</li>';
  613. html = $(html).appendTo('#shareWithList');
  614. // insert cruds button into last label element
  615. var lastLabel = html.find('>label:last');
  616. if (lastLabel.exists()){
  617. lastLabel.append(showCrudsButton);
  618. }
  619. else{
  620. html.find('.cruds').before(showCrudsButton);
  621. }
  622. if (!OC.Share.currentShares[shareType]) {
  623. OC.Share.currentShares[shareType] = [];
  624. }
  625. OC.Share.currentShares[shareType].push(shareItem);
  626. }
  627. },
  628. showLink:function(token, password, itemSource) {
  629. OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = true;
  630. $('#linkCheckbox').attr('checked', true);
  631. //check itemType
  632. var linkSharetype=$('#dropdown').data('item-type');
  633. if (! token) {
  634. //fallback to pre token link
  635. var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file');
  636. var type = $('tr').filterAttr('data-id', String(itemSource)).data('type');
  637. if ($('#dir').val() == '/') {
  638. var file = $('#dir').val() + filename;
  639. } else {
  640. var file = $('#dir').val() + '/' + filename;
  641. }
  642. file = '/'+OC.currentUser+'/files'+file;
  643. // TODO: use oc webroot ?
  644. var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&'+type+'='+encodeURIComponent(file);
  645. } else {
  646. //TODO add path param when showing a link to file in a subfolder of a public link share
  647. var service='';
  648. if(linkSharetype === 'folder' || linkSharetype === 'file'){
  649. service='files';
  650. }else{
  651. service=linkSharetype;
  652. }
  653. // TODO: use oc webroot ?
  654. if (service !== 'files') {
  655. var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service='+service+'&t='+token;
  656. } else {
  657. var link = parent.location.protocol+'//'+location.host+OC.generateUrl('/s/')+token;
  658. }
  659. }
  660. $('#linkText').val(link);
  661. $('#linkText').show('blind');
  662. $('#linkText').css('display','block');
  663. if (oc_appconfig.core.enforcePasswordForPublicLink === false || password === null) {
  664. $('#showPassword').show();
  665. $('#showPassword+label').show();
  666. }
  667. if (password != null) {
  668. $('#linkPass').show('blind');
  669. $('#showPassword').attr('checked', true);
  670. $('#linkPassText').attr('placeholder', '**********');
  671. }
  672. $('#expiration').show();
  673. $('#emailPrivateLink #email').show();
  674. $('#emailPrivateLink #emailButton').show();
  675. $('#allowPublicUploadWrapper').show();
  676. },
  677. hideLink:function() {
  678. $('#linkText').hide('blind');
  679. $('#defaultExpireMessage').hide();
  680. $('#showPassword').hide();
  681. $('#showPassword+label').hide();
  682. $('#linkPass').hide('blind');
  683. $('#emailPrivateLink #email').hide();
  684. $('#emailPrivateLink #emailButton').hide();
  685. $('#allowPublicUploadWrapper').hide();
  686. },
  687. dirname:function(path) {
  688. return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
  689. },
  690. /**
  691. * Displays the expiration date field
  692. *
  693. * @param {Date} date current expiration date
  694. * @param {int} [shareTime] share timestamp in seconds, defaults to now
  695. */
  696. showExpirationDate:function(date, shareTime) {
  697. var now = new Date();
  698. // min date should always be the next day
  699. var minDate = new Date();
  700. minDate.setDate(minDate.getDate()+1);
  701. var datePickerOptions = {
  702. minDate: minDate,
  703. maxDate: null
  704. };
  705. if (_.isNumber(shareTime)) {
  706. shareTime = new Date(shareTime * 1000);
  707. }
  708. if (!shareTime) {
  709. shareTime = now;
  710. }
  711. $('#expirationCheckbox').attr('checked', true);
  712. $('#expirationDate').val(date);
  713. $('#expirationDate').show('blind');
  714. $('#expirationDate').css('display','block');
  715. $('#expirationDate').datepicker({
  716. dateFormat : 'dd-mm-yy'
  717. });
  718. if (oc_appconfig.core.defaultExpireDateEnforced) {
  719. $('#expirationCheckbox').attr('disabled', true);
  720. shareTime = OC.Util.stripTime(shareTime).getTime();
  721. // max date is share date + X days
  722. datePickerOptions.maxDate = new Date(shareTime + oc_appconfig.core.defaultExpireDate * 24 * 3600 * 1000);
  723. }
  724. if(oc_appconfig.core.defaultExpireDateEnabled) {
  725. $('#defaultExpireMessage').show('blind');
  726. }
  727. $.datepicker.setDefaults(datePickerOptions);
  728. }
  729. };
  730. $(document).ready(function() {
  731. if(typeof monthNames != 'undefined'){
  732. // min date should always be the next day
  733. var minDate = new Date();
  734. minDate.setDate(minDate.getDate()+1);
  735. $.datepicker.setDefaults({
  736. monthNames: monthNames,
  737. monthNamesShort: $.map(monthNames, function(v) { return v.slice(0,3)+'.'; }),
  738. dayNames: dayNames,
  739. dayNamesMin: $.map(dayNames, function(v) { return v.slice(0,2); }),
  740. dayNamesShort: $.map(dayNames, function(v) { return v.slice(0,3)+'.'; }),
  741. firstDay: firstDay,
  742. minDate : minDate
  743. });
  744. }
  745. $(document).on('click', 'a.share', function(event) {
  746. event.stopPropagation();
  747. if ($(this).data('item-type') !== undefined && $(this).data('item') !== undefined) {
  748. var itemType = $(this).data('item-type');
  749. var itemSource = $(this).data('item');
  750. var appendTo = $(this).parent().parent();
  751. var link = false;
  752. var possiblePermissions = $(this).data('possible-permissions');
  753. if ($(this).data('link') !== undefined && $(this).data('link') == true) {
  754. link = true;
  755. }
  756. if (OC.Share.droppedDown) {
  757. if (itemSource != $('#dropdown').data('item')) {
  758. OC.Share.hideDropDown(function () {
  759. OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions);
  760. });
  761. } else {
  762. OC.Share.hideDropDown();
  763. }
  764. } else {
  765. OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions);
  766. }
  767. }
  768. });
  769. $(this).click(function(event) {
  770. var target = $(event.target);
  771. var isMatched = !target.is('.drop, .ui-datepicker-next, .ui-datepicker-prev, .ui-icon')
  772. && !target.closest('#ui-datepicker-div').length && !target.closest('.ui-autocomplete').length;
  773. if (OC.Share.droppedDown && isMatched && $('#dropdown').has(event.target).length === 0) {
  774. OC.Share.hideDropDown();
  775. }
  776. });
  777. $(document).on('click', '#dropdown .showCruds', function() {
  778. $(this).closest('li').find('.cruds').toggle();
  779. return false;
  780. });
  781. $(document).on('click', '#dropdown .unshare', function() {
  782. var $li = $(this).closest('li');
  783. var itemType = $('#dropdown').data('item-type');
  784. var itemSource = $('#dropdown').data('item-source');
  785. var shareType = $li.data('share-type');
  786. var shareWith = $li.attr('data-share-with');
  787. OC.Share.unshare(itemType, itemSource, shareType, shareWith, function() {
  788. $li.remove();
  789. var index = OC.Share.itemShares[shareType].indexOf(shareWith);
  790. OC.Share.itemShares[shareType].splice(index, 1);
  791. // updated list of shares
  792. OC.Share.currentShares[shareType].splice(index, 1);
  793. $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares}));
  794. OC.Share.updateIcon(itemType, itemSource);
  795. if (typeof OC.Share.statuses[itemSource] === 'undefined') {
  796. $('#expiration').hide('blind');
  797. }
  798. });
  799. return false;
  800. });
  801. $(document).on('change', '#dropdown .permissions', function() {
  802. var li = $(this).closest('li');
  803. if ($(this).attr('name') == 'edit') {
  804. var checkboxes = $('.permissions', li);
  805. var checked = $(this).is(':checked');
  806. // Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck
  807. $(checkboxes).filter('input[name="create"]').attr('checked', checked);
  808. $(checkboxes).filter('input[name="update"]').attr('checked', checked);
  809. $(checkboxes).filter('input[name="delete"]').attr('checked', checked);
  810. } else {
  811. var checkboxes = $('.permissions', li);
  812. // Uncheck Edit if Create, Update, and Delete are not checked
  813. if (!$(this).is(':checked')
  814. && !$(checkboxes).filter('input[name="create"]').is(':checked')
  815. && !$(checkboxes).filter('input[name="update"]').is(':checked')
  816. && !$(checkboxes).filter('input[name="delete"]').is(':checked'))
  817. {
  818. $(checkboxes).filter('input[name="edit"]').attr('checked', false);
  819. // Check Edit if Create, Update, or Delete is checked
  820. } else if (($(this).attr('name') == 'create'
  821. || $(this).attr('name') == 'update'
  822. || $(this).attr('name') == 'delete'))
  823. {
  824. $(checkboxes).filter('input[name="edit"]').attr('checked', true);
  825. }
  826. }
  827. var permissions = OC.PERMISSION_READ;
  828. $(checkboxes).filter(':not(input[name="edit"])').filter(':checked').each(function(index, checkbox) {
  829. permissions |= $(checkbox).data('permissions');
  830. });
  831. OC.Share.setPermissions($('#dropdown').data('item-type'),
  832. $('#dropdown').data('item-source'),
  833. li.data('share-type'),
  834. li.attr('data-share-with'),
  835. permissions);
  836. });
  837. $(document).on('change', '#dropdown #linkCheckbox', function() {
  838. var itemType = $('#dropdown').data('item-type');
  839. var itemSource = $('#dropdown').data('item-source');
  840. var itemSourceName = $('#dropdown').data('item-source-name');
  841. if (this.checked) {
  842. var expireDateString = '';
  843. if (oc_appconfig.core.defaultExpireDateEnabled) {
  844. var date = new Date().getTime();
  845. var expireAfterMs = oc_appconfig.core.defaultExpireDate * 24 * 60 * 60 * 1000;
  846. var expireDate = new Date(date + expireAfterMs);
  847. var month = expireDate.getMonth() + 1;
  848. var year = expireDate.getFullYear();
  849. var day = expireDate.getDate();
  850. expireDateString = year + "-" + month + '-' + day + ' 00:00:00';
  851. }
  852. // Create a link
  853. if (oc_appconfig.core.enforcePasswordForPublicLink === false) {
  854. OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, itemSourceName, expireDateString, function(data) {
  855. OC.Share.showLink(data.token, null, itemSource);
  856. $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares}));
  857. OC.Share.updateIcon(itemType, itemSource);
  858. });
  859. } else {
  860. $('#linkPass').toggle('blind');
  861. $('#linkPassText').focus();
  862. }
  863. if (expireDateString !== '') {
  864. OC.Share.showExpirationDate(expireDateString);
  865. }
  866. } else {
  867. // Delete private link
  868. OC.Share.hideLink();
  869. $('#expiration').hide('blind');
  870. if ($('#linkText').val() !== '') {
  871. OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() {
  872. OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = false;
  873. $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares}));
  874. OC.Share.updateIcon(itemType, itemSource);
  875. if (typeof OC.Share.statuses[itemSource] === 'undefined') {
  876. $('#expiration').hide('blind');
  877. }
  878. });
  879. }
  880. }
  881. });
  882. $(document).on('click', '#dropdown #linkText', function() {
  883. $(this).focus();
  884. $(this).select();
  885. });
  886. // Handle the Allow Public Upload Checkbox
  887. $(document).on('click', '#sharingDialogAllowPublicUpload', function() {
  888. // Gather data
  889. var allowPublicUpload = $(this).is(':checked');
  890. var itemType = $('#dropdown').data('item-type');
  891. var itemSource = $('#dropdown').data('item-source');
  892. var itemSourceName = $('#dropdown').data('item-source-name');
  893. var expirationDate = '';
  894. if ($('#expirationCheckbox').is(':checked') === true) {
  895. expirationDate = $( "#expirationDate" ).val();
  896. }
  897. var permissions = 0;
  898. // Calculate permissions
  899. if (allowPublicUpload) {
  900. permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ;
  901. } else {
  902. permissions = OC.PERMISSION_READ;
  903. }
  904. // Update the share information
  905. OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, itemSourceName, expirationDate, function(data) {
  906. });
  907. });
  908. $(document).on('click', '#dropdown #showPassword', function() {
  909. $('#linkPass').toggle('blind');
  910. if (!$('#showPassword').is(':checked') ) {
  911. var itemType = $('#dropdown').data('item-type');
  912. var itemSource = $('#dropdown').data('item-source');
  913. var itemSourceName = $('#dropdown').data('item-source-name');
  914. var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked');
  915. var permissions = 0;
  916. // Calculate permissions
  917. if (allowPublicUpload) {
  918. permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ;
  919. } else {
  920. permissions = OC.PERMISSION_READ;
  921. }
  922. OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, itemSourceName);
  923. } else {
  924. $('#linkPassText').focus();
  925. }
  926. });
  927. $(document).on('focusout keyup', '#dropdown #linkPassText', function(event) {
  928. var linkPassText = $('#linkPassText');
  929. if ( linkPassText.val() != '' && (event.type == 'focusout' || event.keyCode == 13) ) {
  930. var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked');
  931. var dropDown = $('#dropdown');
  932. var itemType = dropDown.data('item-type');
  933. var itemSource = dropDown.data('item-source');
  934. var itemSourceName = $('#dropdown').data('item-source-name');
  935. var permissions = 0;
  936. // Calculate permissions
  937. if (allowPublicUpload) {
  938. permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ;
  939. } else {
  940. permissions = OC.PERMISSION_READ;
  941. }
  942. OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), permissions, itemSourceName, function(data) {
  943. linkPassText.val('');
  944. linkPassText.attr('placeholder', t('core', 'Password protected'));
  945. if (oc_appconfig.core.enforcePasswordForPublicLink) {
  946. OC.Share.showLink(data.token, "password set", itemSource);
  947. OC.Share.updateIcon(itemType, itemSource);
  948. }
  949. });
  950. }
  951. });
  952. $(document).on('click', '#dropdown #expirationCheckbox', function() {
  953. if (this.checked) {
  954. OC.Share.showExpirationDate('');
  955. } else {
  956. var itemType = $('#dropdown').data('item-type');
  957. var itemSource = $('#dropdown').data('item-source');
  958. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: '' }, function(result) {
  959. if (!result || result.status !== 'success') {
  960. OC.dialogs.alert(t('core', 'Error unsetting expiration date'), t('core', 'Error'));
  961. }
  962. $('#expirationDate').hide('blind');
  963. if (oc_appconfig.core.defaultExpireDateEnforced === false) {
  964. $('#defaultExpireMessage').show('blind');
  965. }
  966. });
  967. }
  968. });
  969. $(document).on('change', '#dropdown #expirationDate', function() {
  970. var itemType = $('#dropdown').data('item-type');
  971. var itemSource = $('#dropdown').data('item-source');
  972. $(this).tipsy('hide');
  973. $(this).removeClass('error');
  974. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: $(this).val() }, function(result) {
  975. if (!result || result.status !== 'success') {
  976. var expirationDateField = $('#dropdown #expirationDate');
  977. if (!result.data.message) {
  978. expirationDateField.attr('original-title', t('core', 'Error setting expiration date'));
  979. } else {
  980. expirationDateField.attr('original-title', result.data.message);
  981. }
  982. expirationDateField.tipsy({gravity: 'n', fade: true});
  983. expirationDateField.tipsy('show');
  984. expirationDateField.addClass('error');
  985. } else {
  986. if (oc_appconfig.core.defaultExpireDateEnforced === 'no') {
  987. $('#defaultExpireMessage'). hide('blind');
  988. }
  989. }
  990. });
  991. });
  992. $(document).on('submit', '#dropdown #emailPrivateLink', function(event) {
  993. event.preventDefault();
  994. var link = $('#linkText').val();
  995. var itemType = $('#dropdown').data('item-type');
  996. var itemSource = $('#dropdown').data('item-source');
  997. var file = $('tr').filterAttr('data-id', String(itemSource)).data('file');
  998. var email = $('#email').val();
  999. var expirationDate = '';
  1000. if ( $('#expirationCheckbox').is(':checked') === true ) {
  1001. expirationDate = $( "#expirationDate" ).val();
  1002. }
  1003. if (email != '') {
  1004. $('#email').prop('disabled', true);
  1005. $('#email').val(t('core', 'Sending ...'));
  1006. $('#emailButton').prop('disabled', true);
  1007. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'email', toaddress: email, link: link, itemType: itemType, itemSource: itemSource, file: file, expiration: expirationDate},
  1008. function(result) {
  1009. $('#email').prop('disabled', false);
  1010. $('#emailButton').prop('disabled', false);
  1011. if (result && result.status == 'success') {
  1012. $('#email').css('font-weight', 'bold');
  1013. $('#email').animate({ fontWeight: 'normal' }, 2000, function() {
  1014. $(this).val('');
  1015. }).val(t('core','Email sent'));
  1016. } else {
  1017. OC.dialogs.alert(result.data.message, t('core', 'Error while sharing'));
  1018. }
  1019. });
  1020. }
  1021. });
  1022. $(document).on('click', '#dropdown input[name=mailNotification]', function() {
  1023. var $li = $(this).closest('li');
  1024. var itemType = $('#dropdown').data('item-type');
  1025. var itemSource = $('#dropdown').data('item-source');
  1026. var action = '';
  1027. if (this.checked) {
  1028. action = 'informRecipients';
  1029. } else {
  1030. action = 'informRecipientsDisabled';
  1031. }
  1032. var shareType = $li.data('share-type');
  1033. var shareWith = $li.attr('data-share-with');
  1034. $.post(OC.filePath('core', 'ajax', 'share.php'), {action: action, recipient: shareWith, shareType: shareType, itemSource: itemSource, itemType: itemType}, function(result) {
  1035. if (result.status !== 'success') {
  1036. OC.dialogs.alert(t('core', result.data.message), t('core', 'Warning'));
  1037. }
  1038. });
  1039. });
  1040. });