share.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. OC.Share={
  2. SHARE_TYPE_USER:0,
  3. SHARE_TYPE_GROUP:1,
  4. SHARE_TYPE_LINK:3,
  5. SHARE_TYPE_EMAIL:4,
  6. itemShares:[],
  7. statuses:[],
  8. droppedDown:false,
  9. loadIcons:function(itemType) {
  10. // Load all share icons
  11. $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getItemsSharedStatuses', itemType: itemType }, function(result) {
  12. if (result && result.status === 'success') {
  13. $.each(result.data, function(item, data) {
  14. OC.Share.statuses[item] = data;
  15. var hasLink = data['link'];
  16. // Links override shared in terms of icon display
  17. if (hasLink) {
  18. var image = OC.imagePath('core', 'actions/public');
  19. } else {
  20. var image = OC.imagePath('core', 'actions/shared');
  21. }
  22. if (itemType != 'file' && itemType != 'folder') {
  23. $('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center');
  24. } else {
  25. var file = $('tr').filterAttr('data-id', item);
  26. if (file.length > 0) {
  27. var action = $(file).find('.fileactions .action').filterAttr('data-action', 'Share');
  28. var img = action.find('img').attr('src', image);
  29. action.addClass('permanent');
  30. action.html(' '+t('core', 'Shared')).prepend(img);
  31. } else {
  32. var dir = $('#dir').val();
  33. if (dir.length > 1) {
  34. var last = '';
  35. var path = dir;
  36. // Search for possible parent folders that are shared
  37. while (path != last) {
  38. if (path == data['path']) {
  39. var actions = $('.fileactions .action').filterAttr('data-action', 'Share');
  40. $.each(actions, function(index, action) {
  41. var img = $(action).find('img');
  42. if (img.attr('src') != OC.imagePath('core', 'actions/public')) {
  43. img.attr('src', image);
  44. $(action).addClass('permanent');
  45. $(action).html(' '+t('core', 'Shared')).prepend(img);
  46. }
  47. });
  48. }
  49. last = path;
  50. path = OC.Share.dirname(path);
  51. }
  52. }
  53. }
  54. }
  55. });
  56. }
  57. });
  58. },
  59. updateIcon:function(itemType, itemSource) {
  60. var shares = false;
  61. var link = false;
  62. var image = OC.imagePath('core', 'actions/share');
  63. $.each(OC.Share.itemShares, function(index) {
  64. if (OC.Share.itemShares[index]) {
  65. if (index == OC.Share.SHARE_TYPE_LINK) {
  66. if (OC.Share.itemShares[index] == true) {
  67. shares = true;
  68. image = OC.imagePath('core', 'actions/public');
  69. link = true;
  70. return;
  71. }
  72. } else if (OC.Share.itemShares[index].length > 0) {
  73. shares = true;
  74. image = OC.imagePath('core', 'actions/shared');
  75. }
  76. }
  77. });
  78. if (itemType != 'file' && itemType != 'folder') {
  79. $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+image+') no-repeat center');
  80. } else {
  81. var file = $('tr').filterAttr('data-id', String(itemSource));
  82. if (file.length > 0) {
  83. var action = $(file).find('.fileactions .action').filterAttr('data-action', 'Share');
  84. var img = action.find('img').attr('src', image);
  85. if (shares) {
  86. action.addClass('permanent');
  87. action.html(' '+ escapeHTML(t('core', 'Shared'))).prepend(img);
  88. } else {
  89. action.removeClass('permanent');
  90. action.html(' '+ escapeHTML(t('core', 'Share'))).prepend(img);
  91. }
  92. }
  93. }
  94. if (shares) {
  95. OC.Share.statuses[itemSource]['link'] = link;
  96. } else {
  97. delete OC.Share.statuses[itemSource];
  98. }
  99. },
  100. loadItem:function(itemType, itemSource) {
  101. var data = '';
  102. var checkReshare = true;
  103. if (typeof OC.Share.statuses[itemSource] === 'undefined') {
  104. // NOTE: Check does not always work and misses some shares, fix later
  105. checkShares = true;
  106. } else {
  107. checkShares = true;
  108. }
  109. $.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) {
  110. if (result && result.status === 'success') {
  111. data = result.data;
  112. } else {
  113. data = false;
  114. }
  115. }});
  116. return data;
  117. },
  118. share:function(itemType, itemSource, shareType, shareWith, permissions, callback) {
  119. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'share', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
  120. if (result && result.status === 'success') {
  121. if (callback) {
  122. callback(result.data);
  123. }
  124. } else {
  125. OC.dialogs.alert(result.data.message, t('core', 'Error while sharing'));
  126. }
  127. });
  128. },
  129. unshare:function(itemType, itemSource, shareType, shareWith, callback) {
  130. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith }, function(result) {
  131. if (result && result.status === 'success') {
  132. if (callback) {
  133. callback();
  134. }
  135. } else {
  136. OC.dialogs.alert(t('core', 'Error'), t('core', 'Error while unsharing'));
  137. }
  138. });
  139. },
  140. setPermissions:function(itemType, itemSource, shareType, shareWith, permissions) {
  141. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setPermissions', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
  142. if (!result || result.status !== 'success') {
  143. OC.dialogs.alert(t('core', 'Error'), t('core', 'Error while changing permissions'));
  144. }
  145. });
  146. },
  147. showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions) {
  148. var data = OC.Share.loadItem(itemType, itemSource);
  149. var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">';
  150. if (data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined) {
  151. if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) {
  152. html += '<span class="reshare">'+t('core', 'Shared with you and the group {group} by {owner}', {group: data.reshare.share_with, owner: data.reshare.displayname_owner})+'</span>';
  153. } else {
  154. html += '<span class="reshare">'+t('core', 'Shared with you by {owner}', {owner: data.reshare.displayname_owner})+'</span>';
  155. }
  156. html += '<br />';
  157. }
  158. if (possiblePermissions & OC.PERMISSION_SHARE) {
  159. html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Share with')+'" />';
  160. html += '<ul id="shareWithList">';
  161. html += '</ul>';
  162. if (link) {
  163. html += '<div id="link">';
  164. html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">'+t('core', 'Share with link')+'</label>';
  165. html += '<br />';
  166. html += '<input id="linkText" type="text" readonly="readonly" />';
  167. html += '<input type="checkbox" name="showPassword" id="showPassword" value="1" style="display:none;" /><label for="showPassword" style="display:none;">'+t('core', 'Password protect')+'</label>';
  168. html += '<div id="linkPass">';
  169. html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Password')+'" />';
  170. html += '</div>';
  171. html += '</div>';
  172. html += '<form id="emailPrivateLink" >';
  173. html += '<input id="email" style="display:none; width:62%;" value="" placeholder="'+t('core', 'Email link to person')+'" type="text" />';
  174. html += '<input id="emailButton" style="display:none;" type="submit" value="'+t('core', 'Send')+'" />';
  175. html += '</form>';
  176. }
  177. html += '<div id="expiration">';
  178. html += '<input type="checkbox" name="expirationCheckbox" id="expirationCheckbox" value="1" /><label for="expirationCheckbox">'+t('core', 'Set expiration date')+'</label>';
  179. html += '<input id="expirationDate" type="text" placeholder="'+t('core', 'Expiration date')+'" style="display:none; width:90%;" />';
  180. html += '</div>';
  181. $(html).appendTo(appendTo);
  182. // Reset item shares
  183. OC.Share.itemShares = [];
  184. if (data.shares) {
  185. $.each(data.shares, function(index, share) {
  186. if (share.share_type == OC.Share.SHARE_TYPE_LINK) {
  187. OC.Share.showLink(share.token, share.share_with, itemSource);
  188. } else {
  189. if (share.collection) {
  190. OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.collection);
  191. } else {
  192. OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, false);
  193. }
  194. }
  195. if (share.expiration != null) {
  196. OC.Share.showExpirationDate(share.expiration);
  197. }
  198. });
  199. }
  200. $('#shareWith').autocomplete({minLength: 1, source: function(search, response) {
  201. // if (cache[search.term]) {
  202. // response(cache[search.term]);
  203. // } else {
  204. $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term, itemShares: OC.Share.itemShares }, function(result) {
  205. if (result.status == 'success' && result.data.length > 0) {
  206. response(result.data);
  207. } else {
  208. // Suggest sharing via email if valid email address
  209. // var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
  210. // if (pattern.test(search.term)) {
  211. // response([{label: t('core', 'Share via email:')+' '+search.term, value: {shareType: OC.Share.SHARE_TYPE_EMAIL, shareWith: search.term}}]);
  212. // } else {
  213. response([t('core', 'No people found')]);
  214. // }
  215. }
  216. });
  217. // }
  218. },
  219. focus: function(event, focused) {
  220. event.preventDefault();
  221. },
  222. select: function(event, selected) {
  223. event.stopPropagation();
  224. var itemType = $('#dropdown').data('item-type');
  225. var itemSource = $('#dropdown').data('item-source');
  226. var shareType = selected.item.value.shareType;
  227. var shareWith = selected.item.value.shareWith;
  228. $(this).val(shareWith);
  229. // Default permissions are Read and Share
  230. var permissions = OC.PERMISSION_READ | OC.PERMISSION_SHARE;
  231. OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, function() {
  232. OC.Share.addShareWith(shareType, shareWith, selected.item.label, permissions, possiblePermissions);
  233. $('#shareWith').val('');
  234. OC.Share.updateIcon(itemType, itemSource);
  235. });
  236. return false;
  237. }
  238. });
  239. } else {
  240. html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Resharing is not allowed')+'" style="width:90%;" disabled="disabled"/>';
  241. html += '</div>';
  242. $(html).appendTo(appendTo);
  243. }
  244. $('#dropdown').show('blind', function() {
  245. OC.Share.droppedDown = true;
  246. });
  247. $('#shareWith').focus();
  248. },
  249. hideDropDown:function(callback) {
  250. $('#dropdown').hide('blind', function() {
  251. OC.Share.droppedDown = false;
  252. $('#dropdown').remove();
  253. if (typeof FileActions !== 'undefined') {
  254. $('tr').removeClass('mouseOver');
  255. }
  256. if (callback) {
  257. callback.call();
  258. }
  259. });
  260. },
  261. addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, collection) {
  262. if (!OC.Share.itemShares[shareType]) {
  263. OC.Share.itemShares[shareType] = [];
  264. }
  265. OC.Share.itemShares[shareType].push(shareWith);
  266. if (collection) {
  267. if (collection.item_type == 'file' || collection.item_type == 'folder') {
  268. var item = collection.path;
  269. } else {
  270. var item = collection.item_source;
  271. }
  272. var collectionList = $('#shareWithList li').filterAttr('data-collection', item);
  273. if (collectionList.length > 0) {
  274. $(collectionList).append(', '+shareWith);
  275. } else {
  276. var html = '<li style="clear: both;" data-collection="'+item+'">'+t('core', 'Shared in {item} with {user}', {'item': item, user: shareWithDisplayName})+'</li>';
  277. $('#shareWithList').prepend(html);
  278. }
  279. } else {
  280. var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = '';
  281. if (permissions & OC.PERMISSION_CREATE) {
  282. createChecked = 'checked="checked"';
  283. editChecked = 'checked="checked"';
  284. }
  285. if (permissions & OC.PERMISSION_UPDATE) {
  286. updateChecked = 'checked="checked"';
  287. editChecked = 'checked="checked"';
  288. }
  289. if (permissions & OC.PERMISSION_DELETE) {
  290. deleteChecked = 'checked="checked"';
  291. editChecked = 'checked="checked"';
  292. }
  293. if (permissions & OC.PERMISSION_SHARE) {
  294. shareChecked = 'checked="checked"';
  295. }
  296. var html = '<li style="clear: both;" data-share-type="'+escapeHTML(shareType)+'" data-share-with="'+escapeHTML(shareWith)+'" title="' + escapeHTML(shareWith) + '">';
  297. html += '<a href="#" class="unshare" style="display:none;"><img class="svg" alt="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
  298. if(shareWith.length > 14){
  299. html += escapeHTML(shareWithDisplayName.substr(0,11) + '...');
  300. }else{
  301. html += escapeHTML(shareWithDisplayName);
  302. }
  303. if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) {
  304. if (editChecked == '') {
  305. html += '<label style="display:none;">';
  306. } else {
  307. html += '<label>';
  308. }
  309. html += '<input type="checkbox" name="edit" class="permissions" '+editChecked+' />'+t('core', 'can edit')+'</label>';
  310. }
  311. html += '<a href="#" class="showCruds" style="display:none;"><img class="svg" alt="'+t('core', 'access control')+'" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>';
  312. html += '<div class="cruds" style="display:none;">';
  313. if (possiblePermissions & OC.PERMISSION_CREATE) {
  314. html += '<label><input type="checkbox" name="create" class="permissions" '+createChecked+' data-permissions="'+OC.PERMISSION_CREATE+'" />'+t('core', 'create')+'</label>';
  315. }
  316. if (possiblePermissions & OC.PERMISSION_UPDATE) {
  317. html += '<label><input type="checkbox" name="update" class="permissions" '+updateChecked+' data-permissions="'+OC.PERMISSION_UPDATE+'" />'+t('core', 'update')+'</label>';
  318. }
  319. if (possiblePermissions & OC.PERMISSION_DELETE) {
  320. html += '<label><input type="checkbox" name="delete" class="permissions" '+deleteChecked+' data-permissions="'+OC.PERMISSION_DELETE+'" />'+t('core', 'delete')+'</label>';
  321. }
  322. if (possiblePermissions & OC.PERMISSION_SHARE) {
  323. html += '<label><input type="checkbox" name="share" class="permissions" '+shareChecked+' data-permissions="'+OC.PERMISSION_SHARE+'" />'+t('core', 'share')+'</label>';
  324. }
  325. html += '</div>';
  326. html += '</li>';
  327. $(html).appendTo('#shareWithList');
  328. $('#expiration').show();
  329. }
  330. },
  331. showLink:function(token, password, itemSource) {
  332. OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = true;
  333. $('#linkCheckbox').attr('checked', true);
  334. if (! token) {
  335. //fallback to pre token link
  336. var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file');
  337. var type = $('tr').filterAttr('data-id', String(itemSource)).data('type');
  338. if ($('#dir').val() == '/') {
  339. var file = $('#dir').val() + filename;
  340. } else {
  341. var file = $('#dir').val() + '/' + filename;
  342. }
  343. file = '/'+OC.currentUser+'/files'+file;
  344. var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&'+type+'='+encodeURIComponent(file);
  345. } else {
  346. //TODO add path param when showing a link to file in a subfolder of a public link share
  347. var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&t='+token;
  348. }
  349. $('#linkText').val(link);
  350. $('#linkText').show('blind');
  351. $('#linkText').css('display','block');
  352. $('#showPassword').show();
  353. $('#showPassword+label').show();
  354. if (password != null) {
  355. $('#linkPass').show('blind');
  356. $('#showPassword').attr('checked', true);
  357. $('#linkPassText').attr('placeholder', t('core', 'Password protected'));
  358. }
  359. $('#expiration').show();
  360. $('#emailPrivateLink #email').show();
  361. $('#emailPrivateLink #emailButton').show();
  362. },
  363. hideLink:function() {
  364. $('#linkText').hide('blind');
  365. $('#showPassword').hide();
  366. $('#showPassword+label').hide();
  367. $('#linkPass').hide();
  368. $('#emailPrivateLink #email').hide();
  369. $('#emailPrivateLink #emailButton').hide();
  370. },
  371. dirname:function(path) {
  372. return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
  373. },
  374. showExpirationDate:function(date) {
  375. $('#expirationCheckbox').attr('checked', true);
  376. $('#expirationDate').before('<br />');
  377. $('#expirationDate').val(date);
  378. $('#expirationDate').show();
  379. $('#expirationDate').datepicker({
  380. dateFormat : 'dd-mm-yy'
  381. });
  382. }
  383. }
  384. $(document).ready(function() {
  385. if(typeof monthNames != 'undefined'){
  386. $.datepicker.setDefaults({
  387. monthNames: monthNames,
  388. monthNamesShort: $.map(monthNames, function(v) { return v.slice(0,3)+'.'; }),
  389. dayNames: dayNames,
  390. dayNamesMin: $.map(dayNames, function(v) { return v.slice(0,2); }),
  391. dayNamesShort: $.map(dayNames, function(v) { return v.slice(0,3)+'.'; }),
  392. firstDay: firstDay
  393. });
  394. }
  395. $(document).on('click', 'a.share', function(event) {
  396. event.stopPropagation();
  397. if ($(this).data('item-type') !== undefined && $(this).data('item') !== undefined) {
  398. var itemType = $(this).data('item-type');
  399. var itemSource = $(this).data('item');
  400. var appendTo = $(this).parent().parent();
  401. var link = false;
  402. var possiblePermissions = $(this).data('possible-permissions');
  403. if ($(this).data('link') !== undefined && $(this).data('link') == true) {
  404. link = true;
  405. }
  406. if (OC.Share.droppedDown) {
  407. if (itemSource != $('#dropdown').data('item')) {
  408. OC.Share.hideDropDown(function () {
  409. OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions);
  410. });
  411. } else {
  412. OC.Share.hideDropDown();
  413. }
  414. } else {
  415. OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions);
  416. }
  417. }
  418. });
  419. $(this).click(function(event) {
  420. var target = $(event.target);
  421. var isMatched = !target.is('.drop, .ui-datepicker-next, .ui-datepicker-prev, .ui-icon')
  422. && !target.closest('#ui-datepicker-div').length;
  423. if (OC.Share.droppedDown && isMatched && $('#dropdown').has(event.target).length === 0) {
  424. OC.Share.hideDropDown();
  425. }
  426. });
  427. $(document).on('mouseenter', '#dropdown #shareWithList li', function(event) {
  428. // Show permissions and unshare button
  429. $(':hidden', this).filter(':not(.cruds)').show();
  430. });
  431. $(document).on('mouseleave', '#dropdown #shareWithList li', function(event) {
  432. // Hide permissions and unshare button
  433. if (!$('.cruds', this).is(':visible')) {
  434. $('a', this).hide();
  435. if (!$('input[name="edit"]', this).is(':checked')) {
  436. $('input:[type=checkbox]', this).hide();
  437. $('label', this).hide();
  438. }
  439. } else {
  440. $('a.unshare', this).hide();
  441. }
  442. });
  443. $(document).on('click', '#dropdown .showCruds', function() {
  444. $(this).parent().find('.cruds').toggle();
  445. });
  446. $(document).on('click', '#dropdown .unshare', function() {
  447. var li = $(this).parent();
  448. var itemType = $('#dropdown').data('item-type');
  449. var itemSource = $('#dropdown').data('item-source');
  450. var shareType = $(li).data('share-type');
  451. var shareWith = $(li).data('share-with');
  452. OC.Share.unshare(itemType, itemSource, shareType, shareWith, function() {
  453. $(li).remove();
  454. var index = OC.Share.itemShares[shareType].indexOf(shareWith);
  455. OC.Share.itemShares[shareType].splice(index, 1);
  456. OC.Share.updateIcon(itemType, itemSource);
  457. if (typeof OC.Share.statuses[itemSource] === 'undefined') {
  458. $('#expiration').hide();
  459. }
  460. });
  461. });
  462. $(document).on('change', '#dropdown .permissions', function() {
  463. if ($(this).attr('name') == 'edit') {
  464. var li = $(this).parent().parent()
  465. var checkboxes = $('.permissions', li);
  466. var checked = $(this).is(':checked');
  467. // Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck
  468. $(checkboxes).filter('input[name="create"]').attr('checked', checked);
  469. $(checkboxes).filter('input[name="update"]').attr('checked', checked);
  470. $(checkboxes).filter('input[name="delete"]').attr('checked', checked);
  471. } else {
  472. var li = $(this).parent().parent().parent();
  473. var checkboxes = $('.permissions', li);
  474. // Uncheck Edit if Create, Update, and Delete are not checked
  475. if (!$(this).is(':checked')
  476. && !$(checkboxes).filter('input[name="create"]').is(':checked')
  477. && !$(checkboxes).filter('input[name="update"]').is(':checked')
  478. && !$(checkboxes).filter('input[name="delete"]').is(':checked'))
  479. {
  480. $(checkboxes).filter('input[name="edit"]').attr('checked', false);
  481. // Check Edit if Create, Update, or Delete is checked
  482. } else if (($(this).attr('name') == 'create'
  483. || $(this).attr('name') == 'update'
  484. || $(this).attr('name') == 'delete'))
  485. {
  486. $(checkboxes).filter('input[name="edit"]').attr('checked', true);
  487. }
  488. }
  489. var permissions = OC.PERMISSION_READ;
  490. $(checkboxes).filter(':not(input[name="edit"])').filter(':checked').each(function(index, checkbox) {
  491. permissions |= $(checkbox).data('permissions');
  492. });
  493. OC.Share.setPermissions($('#dropdown').data('item-type'),
  494. $('#dropdown').data('item-source'),
  495. $(li).data('share-type'),
  496. $(li).data('share-with'),
  497. permissions);
  498. });
  499. $(document).on('change', '#dropdown #linkCheckbox', function() {
  500. var itemType = $('#dropdown').data('item-type');
  501. var itemSource = $('#dropdown').data('item-source');
  502. if (this.checked) {
  503. // Create a link
  504. OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, function(data) {
  505. OC.Share.showLink(data.token, null, itemSource);
  506. OC.Share.updateIcon(itemType, itemSource);
  507. });
  508. } else {
  509. // Delete private link
  510. OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() {
  511. OC.Share.hideLink();
  512. OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = false;
  513. OC.Share.updateIcon(itemType, itemSource);
  514. if (typeof OC.Share.statuses[itemSource] === 'undefined') {
  515. $('#expiration').hide();
  516. }
  517. });
  518. }
  519. });
  520. $(document).on('click', '#dropdown #linkText', function() {
  521. $(this).focus();
  522. $(this).select();
  523. });
  524. $(document).on('click', '#dropdown #showPassword', function() {
  525. $('#linkPass').toggle('blind');
  526. if (!$('#showPassword').is(':checked') ) {
  527. var itemType = $('#dropdown').data('item-type');
  528. var itemSource = $('#dropdown').data('item-source');
  529. OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ);
  530. } else {
  531. $('#linkPassText').focus();
  532. }
  533. });
  534. $(document).on('focusout keyup', '#dropdown #linkPassText', function(event) {
  535. if ( $('#linkPassText').val() != '' && (event.type == 'focusout' || event.keyCode == 13) ) {
  536. var itemType = $('#dropdown').data('item-type');
  537. var itemSource = $('#dropdown').data('item-source');
  538. OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), OC.PERMISSION_READ, function() {
  539. console.log("password set to: '" + $('#linkPassText').val() +"' by event: " + event.type);
  540. $('#linkPassText').val('');
  541. $('#linkPassText').attr('placeholder', t('core', 'Password protected'));
  542. });
  543. }
  544. });
  545. $(document).on('click', '#dropdown #expirationCheckbox', function() {
  546. if (this.checked) {
  547. OC.Share.showExpirationDate('');
  548. } else {
  549. var itemType = $('#dropdown').data('item-type');
  550. var itemSource = $('#dropdown').data('item-source');
  551. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: '' }, function(result) {
  552. if (!result || result.status !== 'success') {
  553. OC.dialogs.alert(t('core', 'Error'), t('core', 'Error unsetting expiration date'));
  554. }
  555. $('#expirationDate').hide();
  556. });
  557. }
  558. });
  559. $(document).on('change', '#dropdown #expirationDate', function() {
  560. var itemType = $('#dropdown').data('item-type');
  561. var itemSource = $('#dropdown').data('item-source');
  562. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: $(this).val() }, function(result) {
  563. if (!result || result.status !== 'success') {
  564. OC.dialogs.alert(t('core', 'Error'), t('core', 'Error setting expiration date'));
  565. }
  566. });
  567. });
  568. $(document).on('submit', '#dropdown #emailPrivateLink', function(event) {
  569. event.preventDefault();
  570. var link = $('#linkText').val();
  571. var itemType = $('#dropdown').data('item-type');
  572. var itemSource = $('#dropdown').data('item-source');
  573. var file = $('tr').filterAttr('data-id', String(itemSource)).data('file');
  574. var email = $('#email').val();
  575. if (email != '') {
  576. $('#email').attr('disabled', "disabled");
  577. $('#email').val(t('core', 'Sending ...'));
  578. $('#emailButton').attr('disabled', "disabled");
  579. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'email', toaddress: email, link: link, itemType: itemType, itemSource: itemSource, file: file},
  580. function(result) {
  581. $('#email').attr('disabled', "false");
  582. $('#emailButton').attr('disabled', "false");
  583. if (result && result.status == 'success') {
  584. $('#email').css('font-weight', 'bold');
  585. $('#email').animate({ fontWeight: 'normal' }, 2000, function() {
  586. $(this).val('');
  587. }).val(t('core','Email sent'));
  588. } else {
  589. OC.dialogs.alert(result.data.message, t('core', 'Error while sharing'));
  590. }
  591. });
  592. }
  593. });
  594. });