share.js 24 KB

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