share.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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.reshare) {
  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 += '<a href="#" id="showPassword" style="display:none;"><img class="svg" alt="'+t('core', 'Password protect')+'" src="'+OC.imagePath('core', 'actions/lock')+'"/></a>';
  165. html += '<br />';
  166. html += '<input id="linkText" type="text" readonly="readonly" />';
  167. html += '<div id="linkPass">';
  168. html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Password')+'" />';
  169. html += '</div>';
  170. html += '</div>';
  171. }
  172. html += '<div id="expiration">';
  173. html += '<input type="checkbox" name="expirationCheckbox" id="expirationCheckbox" value="1" /><label for="expirationCheckbox">'+t('core', 'Set expiration date')+'</label>';
  174. html += '<input id="expirationDate" type="text" placeholder="'+t('core', 'Expiration date')+'" style="display:none; width:90%;" />';
  175. html += '</div>';
  176. $(html).appendTo(appendTo);
  177. // Reset item shares
  178. OC.Share.itemShares = [];
  179. if (data.shares) {
  180. $.each(data.shares, function(index, share) {
  181. if (share.share_type == OC.Share.SHARE_TYPE_LINK) {
  182. OC.Share.showLink(itemSource, share.share_with);
  183. } else {
  184. if (share.collection) {
  185. OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions, share.collection);
  186. } else {
  187. OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions, false);
  188. }
  189. }
  190. if (share.expiration != null) {
  191. OC.Share.showExpirationDate(share.expiration);
  192. }
  193. });
  194. }
  195. $('#shareWith').autocomplete({minLength: 2, source: function(search, response) {
  196. // if (cache[search.term]) {
  197. // response(cache[search.term]);
  198. // } else {
  199. $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term, itemShares: OC.Share.itemShares }, function(result) {
  200. if (result.status == 'success' && result.data.length > 0) {
  201. response(result.data);
  202. } else {
  203. // Suggest sharing via email if valid email address
  204. // var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
  205. // if (pattern.test(search.term)) {
  206. // response([{label: t('core', 'Share via email:')+' '+search.term, value: {shareType: OC.Share.SHARE_TYPE_EMAIL, shareWith: search.term}}]);
  207. // } else {
  208. response([t('core', 'No people found')]);
  209. // }
  210. }
  211. });
  212. // }
  213. },
  214. focus: function(event, focused) {
  215. event.preventDefault();
  216. },
  217. select: function(event, selected) {
  218. event.stopPropagation();
  219. var itemType = $('#dropdown').data('item-type');
  220. var itemSource = $('#dropdown').data('item-source');
  221. var shareType = selected.item.value.shareType;
  222. var shareWith = selected.item.value.shareWith;
  223. $(this).val(shareWith);
  224. // Default permissions are Read and Share
  225. var permissions = OC.PERMISSION_READ | OC.PERMISSION_SHARE;
  226. OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, function() {
  227. OC.Share.addShareWith(shareType, shareWith, permissions, possiblePermissions);
  228. $('#shareWith').val('');
  229. OC.Share.updateIcon(itemType, itemSource);
  230. });
  231. return false;
  232. }
  233. });
  234. } else {
  235. html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Resharing is not allowed')+'" style="width:90%;" disabled="disabled"/>';
  236. html += '</div>';
  237. $(html).appendTo(appendTo);
  238. }
  239. $('#dropdown').show('blind', function() {
  240. OC.Share.droppedDown = true;
  241. });
  242. $('#shareWith').focus();
  243. },
  244. hideDropDown:function(callback) {
  245. $('#dropdown').hide('blind', function() {
  246. OC.Share.droppedDown = false;
  247. $('#dropdown').remove();
  248. if (typeof FileActions !== 'undefined') {
  249. $('tr').removeClass('mouseOver');
  250. }
  251. if (callback) {
  252. callback.call();
  253. }
  254. });
  255. },
  256. addShareWith:function(shareType, shareWith, permissions, possiblePermissions, collection) {
  257. if (!OC.Share.itemShares[shareType]) {
  258. OC.Share.itemShares[shareType] = [];
  259. }
  260. OC.Share.itemShares[shareType].push(shareWith);
  261. if (collection) {
  262. if (collection.item_type == 'file' || collection.item_type == 'folder') {
  263. var item = collection.path;
  264. } else {
  265. var item = collection.item_source;
  266. }
  267. var collectionList = $('#shareWithList li').filterAttr('data-collection', item);
  268. if (collectionList.length > 0) {
  269. $(collectionList).append(', '+shareWith);
  270. } else {
  271. var html = '<li style="clear: both;" data-collection="'+item+'">'+t('core', 'Shared in {item} with {user}', {'item': item, user: shareWith})+'</li>';
  272. $('#shareWithList').prepend(html);
  273. }
  274. } else {
  275. var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = '';
  276. if (permissions & OC.PERMISSION_CREATE) {
  277. createChecked = 'checked="checked"';
  278. editChecked = 'checked="checked"';
  279. }
  280. if (permissions & OC.PERMISSION_UPDATE) {
  281. updateChecked = 'checked="checked"';
  282. editChecked = 'checked="checked"';
  283. }
  284. if (permissions & OC.PERMISSION_DELETE) {
  285. deleteChecked = 'checked="checked"';
  286. editChecked = 'checked="checked"';
  287. }
  288. if (permissions & OC.PERMISSION_SHARE) {
  289. shareChecked = 'checked="checked"';
  290. }
  291. var html = '<li style="clear: both;" data-share-type="'+shareType+'" data-share-with="'+shareWith+'" title="' + shareWith + '">';
  292. html += '<a href="#" class="unshare" style="display:none;"><img class="svg" alt="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
  293. if(shareWith.length > 14){
  294. html += shareWith.substr(0,11) + '...';
  295. }else{
  296. html += shareWith;
  297. }
  298. if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) {
  299. if (editChecked == '') {
  300. html += '<label style="display:none;">';
  301. } else {
  302. html += '<label>';
  303. }
  304. html += '<input type="checkbox" name="edit" class="permissions" '+editChecked+' />'+t('core', 'can edit')+'</label>';
  305. }
  306. html += '<a href="#" class="showCruds" style="display:none;"><img class="svg" alt="'+t('core', 'access control')+'" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>';
  307. html += '<div class="cruds" style="display:none;">';
  308. if (possiblePermissions & OC.PERMISSION_CREATE) {
  309. html += '<label><input type="checkbox" name="create" class="permissions" '+createChecked+' data-permissions="'+OC.PERMISSION_CREATE+'" />'+t('core', 'create')+'</label>';
  310. }
  311. if (possiblePermissions & OC.PERMISSION_UPDATE) {
  312. html += '<label><input type="checkbox" name="update" class="permissions" '+updateChecked+' data-permissions="'+OC.PERMISSION_UPDATE+'" />'+t('core', 'update')+'</label>';
  313. }
  314. if (possiblePermissions & OC.PERMISSION_DELETE) {
  315. html += '<label><input type="checkbox" name="delete" class="permissions" '+deleteChecked+' data-permissions="'+OC.PERMISSION_DELETE+'" />'+t('core', 'delete')+'</label>';
  316. }
  317. if (possiblePermissions & OC.PERMISSION_SHARE) {
  318. html += '<label><input type="checkbox" name="share" class="permissions" '+shareChecked+' data-permissions="'+OC.PERMISSION_SHARE+'" />'+t('core', 'share')+'</label>';
  319. }
  320. html += '</div>';
  321. html += '</li>';
  322. $(html).appendTo('#shareWithList');
  323. $('#expiration').show();
  324. }
  325. },
  326. showLink:function(itemSource, password) {
  327. OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = true;
  328. $('#linkCheckbox').attr('checked', true);
  329. var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file');
  330. var type = $('tr').filterAttr('data-id', String(itemSource)).data('type');
  331. if ($('#dir').val() == '/') {
  332. var file = $('#dir').val() + filename;
  333. } else {
  334. var file = $('#dir').val() + '/' + filename;
  335. }
  336. file = '/'+OC.currentUser+'/files'+file;
  337. var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&'+type+'='+encodeURIComponent(file);
  338. $('#linkText').val(link);
  339. $('#linkText').show('blind');
  340. $('#showPassword').show();
  341. if (password != null) {
  342. $('#linkPass').show('blind');
  343. $('#linkPassText').attr('placeholder', t('core', 'Password protected'));
  344. }
  345. $('#expiration').show();
  346. },
  347. hideLink:function() {
  348. $('#linkText').hide('blind');
  349. $('#showPassword').hide();
  350. $('#linkPass').hide();
  351. },
  352. dirname:function(path) {
  353. return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
  354. },
  355. showExpirationDate:function(date) {
  356. $('#expirationCheckbox').attr('checked', true);
  357. $('#expirationDate').before('<br />');
  358. $('#expirationDate').val(date);
  359. $('#expirationDate').show();
  360. $('#expirationDate').datepicker({
  361. dateFormat : 'dd-mm-yy'
  362. });
  363. }
  364. }
  365. $(document).ready(function() {
  366. if(typeof monthNames != 'undefined'){
  367. $.datepicker.setDefaults({
  368. monthNames: monthNames,
  369. monthNamesShort: $.map(monthNames, function(v) { return v.slice(0,3)+'.'; }),
  370. dayNames: dayNames,
  371. dayNamesMin: $.map(dayNames, function(v) { return v.slice(0,2); }),
  372. dayNamesShort: $.map(dayNames, function(v) { return v.slice(0,3)+'.'; }),
  373. firstDay: firstDay
  374. });
  375. }
  376. $('a.share').live('click', function(event) {
  377. event.stopPropagation();
  378. if ($(this).data('item-type') !== undefined && $(this).data('item') !== undefined) {
  379. var itemType = $(this).data('item-type');
  380. var itemSource = $(this).data('item');
  381. var appendTo = $(this).parent().parent();
  382. var link = false;
  383. var possiblePermissions = $(this).data('possible-permissions');
  384. if ($(this).data('link') !== undefined && $(this).data('link') == true) {
  385. link = true;
  386. }
  387. if (OC.Share.droppedDown) {
  388. if (itemSource != $('#dropdown').data('item')) {
  389. OC.Share.hideDropDown(function () {
  390. OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions);
  391. });
  392. } else {
  393. OC.Share.hideDropDown();
  394. }
  395. } else {
  396. OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions);
  397. }
  398. }
  399. });
  400. $(this).click(function(event) {
  401. var target = $(event.target);
  402. var isMatched = !target.is('.drop, .ui-datepicker-next, .ui-datepicker-prev, .ui-icon')
  403. && !target.closest('#ui-datepicker-div').length;
  404. if (OC.Share.droppedDown && isMatched && $('#dropdown').has(event.target).length === 0) {
  405. OC.Share.hideDropDown();
  406. }
  407. });
  408. $('#shareWithList li').live('mouseenter', function(event) {
  409. // Show permissions and unshare button
  410. $(':hidden', this).filter(':not(.cruds)').show();
  411. });
  412. $('#shareWithList li').live('mouseleave', function(event) {
  413. // Hide permissions and unshare button
  414. if (!$('.cruds', this).is(':visible')) {
  415. $('a', this).hide();
  416. if (!$('input[name="edit"]', this).is(':checked')) {
  417. $('input:[type=checkbox]', this).hide();
  418. $('label', this).hide();
  419. }
  420. } else {
  421. $('a.unshare', this).hide();
  422. }
  423. });
  424. $('.showCruds').live('click', function() {
  425. $(this).parent().find('.cruds').toggle();
  426. });
  427. $('.unshare').live('click', function() {
  428. var li = $(this).parent();
  429. var itemType = $('#dropdown').data('item-type');
  430. var itemSource = $('#dropdown').data('item-source');
  431. var shareType = $(li).data('share-type');
  432. var shareWith = $(li).data('share-with');
  433. OC.Share.unshare(itemType, itemSource, shareType, shareWith, function() {
  434. $(li).remove();
  435. var index = OC.Share.itemShares[shareType].indexOf(shareWith);
  436. OC.Share.itemShares[shareType].splice(index, 1);
  437. OC.Share.updateIcon(itemType, itemSource);
  438. if (typeof OC.Share.statuses[itemSource] === 'undefined') {
  439. $('#expiration').hide();
  440. }
  441. });
  442. });
  443. $('.permissions').live('change', function() {
  444. if ($(this).attr('name') == 'edit') {
  445. var li = $(this).parent().parent()
  446. var checkboxes = $('.permissions', li);
  447. var checked = $(this).is(':checked');
  448. // Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck
  449. $(checkboxes).filter('input[name="create"]').attr('checked', checked);
  450. $(checkboxes).filter('input[name="update"]').attr('checked', checked);
  451. $(checkboxes).filter('input[name="delete"]').attr('checked', checked);
  452. } else {
  453. var li = $(this).parent().parent().parent();
  454. var checkboxes = $('.permissions', li);
  455. // Uncheck Edit if Create, Update, and Delete are not checked
  456. 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')) {
  457. $(checkboxes).filter('input[name="edit"]').attr('checked', false);
  458. // Check Edit if Create, Update, or Delete is checked
  459. } else if (($(this).attr('name') == 'create' || $(this).attr('name') == 'update' || $(this).attr('name') == 'delete')) {
  460. $(checkboxes).filter('input[name="edit"]').attr('checked', true);
  461. }
  462. }
  463. var permissions = OC.PERMISSION_READ;
  464. $(checkboxes).filter(':not(input[name="edit"])').filter(':checked').each(function(index, checkbox) {
  465. permissions |= $(checkbox).data('permissions');
  466. });
  467. OC.Share.setPermissions($('#dropdown').data('item-type'), $('#dropdown').data('item-source'), $(li).data('share-type'), $(li).data('share-with'), permissions);
  468. });
  469. $('#linkCheckbox').live('change', function() {
  470. var itemType = $('#dropdown').data('item-type');
  471. var itemSource = $('#dropdown').data('item-source');
  472. if (this.checked) {
  473. // Create a link
  474. OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, function() {
  475. OC.Share.showLink(itemSource);
  476. OC.Share.updateIcon(itemType, itemSource);
  477. });
  478. } else {
  479. // Delete private link
  480. OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() {
  481. OC.Share.hideLink();
  482. OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = false;
  483. OC.Share.updateIcon(itemType, itemSource);
  484. if (typeof OC.Share.statuses[itemSource] === 'undefined') {
  485. $('#expiration').hide();
  486. }
  487. });
  488. }
  489. });
  490. $('#linkText').live('click', function() {
  491. $(this).focus();
  492. $(this).select();
  493. });
  494. $('#showPassword').live('click', function() {
  495. $('#linkPass').toggle('blind');
  496. });
  497. $('#linkPassText').live('focusout', function(event) {
  498. var itemType = $('#dropdown').data('item-type');
  499. var itemSource = $('#dropdown').data('item-source');
  500. OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $(this).val(), OC.PERMISSION_READ, function() {
  501. $('#linkPassText').val('');
  502. $('#linkPassText').attr('placeholder', t('core', 'Password protected'));
  503. });
  504. $('#linkPassText').attr('placeholder', t('core', 'Password protected'));
  505. });
  506. $('#expirationCheckbox').live('click', function() {
  507. if (this.checked) {
  508. OC.Share.showExpirationDate('');
  509. } else {
  510. var itemType = $('#dropdown').data('item-type');
  511. var itemSource = $('#dropdown').data('item-source');
  512. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: '' }, function(result) {
  513. if (!result || result.status !== 'success') {
  514. OC.dialogs.alert(t('core', 'Error'), t('core', 'Error unsetting expiration date'));
  515. }
  516. $('#expirationDate').hide();
  517. });
  518. }
  519. });
  520. $('#expirationDate').live('change', function() {
  521. var itemType = $('#dropdown').data('item-type');
  522. var itemSource = $('#dropdown').data('item-source');
  523. $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: $(this).val() }, function(result) {
  524. if (!result || result.status !== 'success') {
  525. OC.dialogs.alert(t('core', 'Error'), t('core', 'Error setting expiration date'));
  526. }
  527. });
  528. });
  529. });