contextMenu.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. * @description This module is used for the context menu.
  3. * @copyright 2014 by Tobias Reich
  4. */
  5. contextMenu = {}
  6. contextMenu.add = function(e) {
  7. var items = [
  8. { type: 'item', title: 'Upload Photo', icon: 'icon-picture', fn: function() { $('#upload_files').click() } },
  9. { type: 'separator' },
  10. { type: 'item', title: 'Import from Link', icon: 'icon-link', fn: upload.start.url },
  11. { type: 'item', title: 'Import from Dropbox', icon: 'icon-folder-open', fn: upload.start.dropbox },
  12. { type: 'item', title: 'Import from Server', icon: 'icon-hdd', fn: upload.start.server },
  13. { type: 'separator' },
  14. { type: 'item', title: 'New Album', icon: 'icon-folder-close', fn: album.add }
  15. ];
  16. context.show(items, e);
  17. upload.notify();
  18. }
  19. contextMenu.settings = function(e) {
  20. var items = [
  21. { type: 'item', title: 'Change Login', icon: 'icon-user', fn: settings.setLogin },
  22. { type: 'item', title: 'Change Sorting', icon: 'icon-sort', fn: settings.setSorting },
  23. { type: 'item', title: 'Set Dropbox', icon: 'icon-folder-open', fn: settings.setDropboxKey },
  24. { type: 'separator' },
  25. { type: 'item', title: 'About Lychee', icon: 'icon-info-sign', fn: function() { window.open(lychee.website) } },
  26. { type: 'item', title: 'Diagnostics', icon: 'icon-dashboard', fn: function() { window.open('plugins/check/') } },
  27. { type: 'item', title: 'Show Log', icon: 'icon-list', fn: function() { window.open('plugins/displaylog/') } },
  28. { type: 'separator' },
  29. { type: 'item', title: 'Sign Out', icon: 'icon-signout', fn: lychee.logout }
  30. ];
  31. context.show(items, e);
  32. }
  33. contextMenu.album = function(albumID, e) {
  34. if (albumID==='0'||albumID==='f'||albumID==='s'||albumID==='r') return false;
  35. var items = [
  36. { type: 'item', title: 'Rename', icon: 'icon-edit', fn: function() { album.setTitle([albumID]) } },
  37. { type: 'item', title: 'Delete', icon: 'icon-trash', fn: function() { album.delete([albumID]) } }
  38. ];
  39. $('.album[data-id="' + albumID + '"]').addClass('active');
  40. context.show(items, e, function() {
  41. $('.photo.active, .album.active').removeClass('active');
  42. context.close();
  43. });
  44. }
  45. contextMenu.albumMulti = function(albumIDs, e) {
  46. multiselect.stopResize();
  47. var items = [
  48. { type: 'item', title: 'Rename All', icon: 'icon-edit', fn: function() { album.setTitle(albumIDs) } },
  49. { type: 'item', title: 'Delete All', icon: 'icon-trash', fn: function() { album.delete(albumIDs) } }
  50. ];
  51. context.show(items, e, function() {
  52. context.close();
  53. $('.photo.active, .album.active').removeClass('active');
  54. if (visible.multiselect()) multiselect.close();
  55. });
  56. }
  57. contextMenu.photo = function(photoID, e) {
  58. var items = [
  59. { type: 'item', title: 'Star', icon: 'icon-star', fn: function() { photo.setStar([photoID]) } },
  60. { type: 'item', title: 'Tags', icon: 'icon-tags', fn: function() { photo.editTags([photoID]) } },
  61. { type: 'separator' },
  62. { type: 'item', title: 'Rename', icon: 'icon-edit', fn: function() { photo.setTitle([photoID]) } },
  63. { type: 'item', title: 'Duplicate', icon: 'icon-copy', fn: function() { photo.duplicate([photoID]) } },
  64. { type: 'item', title: 'Move', icon: 'icon-folder-open', fn: function() { contextMenu.move([photoID], e) } },
  65. { type: 'item', title: 'Delete', icon: 'icon-trash', fn: function() { photo.delete([photoID]) } }
  66. ];
  67. $('.photo[data-id="' + photoID + '"]').addClass('active');
  68. context.show(items, e, function() {
  69. context.close();
  70. $('.photo.active, .album.active').removeClass('active');
  71. });
  72. }
  73. contextMenu.photoMulti = function(photoIDs, e) {
  74. multiselect.stopResize();
  75. var items = [
  76. { type: 'item', title: 'Star All', icon: 'icon-star', fn: function() { photo.setStar(photoIDs) } },
  77. { type: 'item', title: 'Tag All', icon: 'icon-tags', fn: function() { photo.editTags(photoIDs) } },
  78. { type: 'separator' },
  79. { type: 'item', title: 'Rename All', icon: 'icon-edit', fn: function() { photo.setTitle(photoIDs) } },
  80. { type: 'item', title: 'Duplicate All', icon: 'icon-copy', fn: function() { photo.duplicate(photoIDs) } },
  81. { type: 'item', title: 'Move All', icon: 'icon-folder-open', fn: function() { contextMenu.move(photoIDs, e) } },
  82. { type: 'item', title: 'Delete All', icon: 'icon-trash', fn: function() { photo.delete(photoIDs) } }
  83. ];
  84. context.show(items, e, function() {
  85. context.close();
  86. $('.photo.active, .album.active').removeClass('active');
  87. if (visible.multiselect()) multiselect.close();
  88. });
  89. }
  90. contextMenu.photoMore = function(photoID, e) {
  91. var items = [
  92. { type: 'item', title: 'Full Photo', icon: 'icon-resize-full', fn: function() { window.open(photo.getDirectLink()) } },
  93. { type: 'item', title: 'Download', icon: 'icon-circle-arrow-down', fn: function() { photo.getArchive(photoID) } }
  94. ];
  95. // Remove download-item when
  96. // 1) In public mode
  97. // 2) Downloadable not 1 or not found
  98. if (!(album.json&&album.json.downloadable&&album.json.downloadable==='1')&&
  99. lychee.publicMode===true) items.splice(1, 1);
  100. context.show(items, e);
  101. }
  102. contextMenu.move = function(photoIDs, e) {
  103. var items = [];
  104. // Show Unsorted when unsorted is not the current album
  105. if (album.getID()!=='0') {
  106. items = [
  107. { type: 'item', title: 'Unsorted', fn: function() { photo.setAlbum([photoIDs], 0) } },
  108. { type: 'separator' }
  109. ];
  110. }
  111. lychee.api('getAlbums', function(data) {
  112. if (data.num===0) {
  113. // Show 'Add album' when no album available
  114. items = [
  115. { type: 'item', title: 'New Album', fn: album.add }
  116. ];
  117. } else {
  118. // Generate list of albums
  119. $.each(data.content, function(index) {
  120. var that = this;
  121. if (that.id!=album.getID()) items.push({ type: 'item', title: that.title, fn: function() { photo.setAlbum([photoIDs], that.id) } });
  122. });
  123. }
  124. context.show(items, e);
  125. });
  126. }
  127. contextMenu.sharePhoto = function(photoID, e) {
  128. var link = photo.getViewLink(photoID);
  129. if (photo.json.public==='2') link = location.href;
  130. var items = [
  131. { type: 'item', title: '<input readonly id="link" value="' + link + '">', fn: function() {}, class: 'noHover' },
  132. { type: 'separator' },
  133. { type: 'item', title: 'Make Private', icon: 'icon-eye-close', fn: function() { photo.setPublic(photoID) } },
  134. { type: 'separator' },
  135. { type: 'item', title: 'Twitter', icon: 'icon-twitter', fn: function() { photo.share(photoID, 0) } },
  136. { type: 'item', title: 'Facebook', icon: 'icon-facebook', fn: function() { photo.share(photoID, 1) } },
  137. { type: 'item', title: 'Mail', icon: 'icon-envelope', fn: function() { photo.share(photoID, 2) } },
  138. { type: 'item', title: 'Dropbox', icon: 'icon-hdd', fn: function() { photo.share(photoID, 3) } },
  139. { type: 'item', title: 'Direct Link', icon: 'icon-link', fn: function() { window.open(photo.getDirectLink()) } }
  140. ];
  141. context.show(items, e);
  142. $('.context input#link').focus().select();
  143. }
  144. contextMenu.shareAlbum = function(albumID, e) {
  145. var items = [
  146. { type: 'item', title: '<input readonly id="link" value="' + location.href + '">', fn: function() {}, class: 'noHover' },
  147. { type: 'separator' },
  148. { type: 'item', title: 'Make Private', icon: 'icon-eye-close', fn: function() { album.setPublic(albumID) } },
  149. { type: 'separator' },
  150. { type: 'item', title: 'Twitter', icon: 'icon-twitter', fn: function() { album.share(0) } },
  151. { type: 'item', title: 'Facebook', icon: 'icon-facebook', fn: function() { album.share(1) } },
  152. { type: 'item', title: 'Mail', icon: 'icon-envelope', fn: function() { album.share(2) } }
  153. ];
  154. context.show(items, e);
  155. $('.context input#link').focus().select();
  156. }
  157. contextMenu.close = function(leaveSelection) {
  158. if (!visible.contextMenu()) return false;
  159. context.close();
  160. if (leaveSelection!==true) {
  161. $('.photo.active, .album.active').removeClass('active');
  162. if (visible.multiselect()) multiselect.close();
  163. }
  164. }