contextMenu.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /**
  2. * @description This module is used for the context menu.
  3. * @copyright 2015 by Tobias Reich
  4. */
  5. contextMenu = {}
  6. contextMenu.add = function(e) {
  7. var items = [
  8. { type: 'item', title: build.iconic('image') + 'Upload Photo', fn: function() { $('#upload_files').click() } },
  9. { type: 'separator' },
  10. { type: 'item', title: build.iconic('link-intact') + 'Import from Link', fn: upload.start.url },
  11. { type: 'item', title: build.iconic('box') + 'Import from Dropbox', fn: upload.start.dropbox },
  12. { type: 'item', title: build.iconic('terminal') + 'Import from Server', fn: upload.start.server },
  13. { type: 'separator' },
  14. { type: 'item', title: build.iconic('folder') + 'New Album', fn: album.add }
  15. ];
  16. basicContext.show(items, e);
  17. upload.notify();
  18. }
  19. contextMenu.settings = function(e) {
  20. var items = [
  21. { type: 'item', title: build.iconic('person') + 'Change Login', fn: settings.setLogin },
  22. { type: 'item', title: build.iconic('sort-ascending') + 'Change Sorting', fn: settings.setSorting },
  23. { type: 'item', title: build.iconic('box') + 'Set Dropbox', fn: settings.setDropboxKey },
  24. { type: 'separator' },
  25. { type: 'item', title: build.iconic('info') + 'About Lychee', fn: function() { window.open(lychee.website) } },
  26. { type: 'item', title: build.iconic('wrench') + 'Diagnostics', fn: function() { window.open('plugins/check/') } },
  27. { type: 'item', title: build.iconic('align-left') + 'Show Log', fn: function() { window.open('plugins/displaylog/') } },
  28. { type: 'separator' },
  29. { type: 'item', title: build.iconic('account-logout') + 'Sign Out', fn: lychee.logout }
  30. ];
  31. basicContext.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: build.iconic('pencil') + 'Rename', fn: function() { album.setTitle([albumID]) } },
  37. { type: 'item', title: build.iconic('trash') + 'Delete', fn: function() { album.delete([albumID]) } }
  38. ];
  39. $('.album[data-id="' + albumID + '"]').addClass('active');
  40. basicContext.show(items, e, contextMenu.close);
  41. }
  42. contextMenu.albumMulti = function(albumIDs, e) {
  43. multiselect.stopResize();
  44. var items = [
  45. { type: 'item', title: build.iconic('pencil') + 'Rename All', fn: function() { album.setTitle(albumIDs) } },
  46. { type: 'item', title: build.iconic('trash') + 'Delete All', fn: function() { album.delete(albumIDs) } }
  47. ];
  48. basicContext.show(items, e, contextMenu.close);
  49. }
  50. contextMenu.albumTitle = function(albumID, e) {
  51. var items = [
  52. { type: 'item', title: build.iconic('pencil') + 'Rename', fn: function() { album.setTitle([albumID]) } }
  53. ];
  54. api.post('Album::getAll', {}, function(data) {
  55. if (data.num!==0) {
  56. items.push({ type: 'separator' });
  57. // Generate list of albums
  58. $.each(data.content, function(index) {
  59. var that = this;
  60. if (!that.thumb0) that.thumb0 = 'src/images/no_cover.svg';
  61. that.title = "<img class='albumCover' width='16' height='16' src='" + that.thumb0 + "'><div class='albumTitle'>" + that.title + "</div>";
  62. if (that.id!=album.getID()) items.push({ type: 'item', title: that.title, fn: function() { lychee.goto(that.id) } });
  63. });
  64. }
  65. basicContext.show(items, e, contextMenu.close);
  66. });
  67. }
  68. contextMenu.photo = function(photoID, e) {
  69. // Notice for 'Move':
  70. // fn must call basicContext.close() first,
  71. // in order to keep the selection
  72. var items = [
  73. { type: 'item', title: build.iconic('star') + 'Star', fn: function() { photo.setStar([photoID]) } },
  74. { type: 'item', title: build.iconic('tag') + 'Tags', fn: function() { photo.editTags([photoID]) } },
  75. { type: 'separator' },
  76. { type: 'item', title: build.iconic('pencil') + 'Rename', fn: function() { photo.setTitle([photoID]) } },
  77. { type: 'item', title: build.iconic('layers') + 'Duplicate', fn: function() { photo.duplicate([photoID]) } },
  78. { type: 'item', title: build.iconic('folder') + 'Move', fn: function() { basicContext.close(); contextMenu.move([photoID], e); } },
  79. { type: 'item', title: build.iconic('trash') + 'Delete', fn: function() { photo.delete([photoID]) } }
  80. ];
  81. $('.photo[data-id="' + photoID + '"]').addClass('active');
  82. basicContext.show(items, e, contextMenu.close);
  83. }
  84. contextMenu.photoMulti = function(photoIDs, e) {
  85. // Notice for 'Move All':
  86. // fn must call basicContext.close() first,
  87. // in order to keep the selection and multiselect
  88. multiselect.stopResize();
  89. var items = [
  90. { type: 'item', title: build.iconic('star') + 'Star All', fn: function() { photo.setStar(photoIDs) } },
  91. { type: 'item', title: build.iconic('tag') + 'Tag All', fn: function() { photo.editTags(photoIDs) } },
  92. { type: 'separator' },
  93. { type: 'item', title: build.iconic('pencil') + 'Rename All', fn: function() { photo.setTitle(photoIDs) } },
  94. { type: 'item', title: build.iconic('layers') + 'Duplicate All', fn: function() { photo.duplicate(photoIDs) } },
  95. { type: 'item', title: build.iconic('folder') + 'Move All', fn: function() { basicContext.close(); contextMenu.move(photoIDs, e); } },
  96. { type: 'item', title: build.iconic('trash') + 'Delete All', fn: function() { photo.delete(photoIDs) } }
  97. ];
  98. basicContext.show(items, e, contextMenu.close);
  99. }
  100. contextMenu.photoMore = function(photoID, e) {
  101. var items = [
  102. { type: 'item', title: build.iconic('fullscreen-enter') + 'Full Photo', fn: function() { window.open(photo.getDirectLink()) } },
  103. { type: 'item', title: build.iconic('cloud-download') + 'Download', fn: function() { photo.getArchive(photoID) } }
  104. ];
  105. // Remove download-item when
  106. // 1) In public mode
  107. // 2) Downloadable not 1 or not found
  108. if (!(album.json&&album.json.downloadable&&album.json.downloadable==='1')&&
  109. lychee.publicMode===true) items.splice(1, 1);
  110. basicContext.show(items, e);
  111. }
  112. contextMenu.move = function(photoIDs, e) {
  113. var items = [];
  114. // Show Unsorted when unsorted is not the current album
  115. if (album.getID()!=='0') {
  116. items = [
  117. { type: 'item', title: 'Unsorted', fn: function() { photo.setAlbum(photoIDs, 0) } },
  118. { type: 'separator' }
  119. ];
  120. }
  121. api.post('Album::getAll', {}, function(data) {
  122. if (data.num===0) {
  123. // Show only 'Add album' when no album available
  124. items = [
  125. { type: 'item', title: 'New Album', fn: album.add }
  126. ];
  127. } else {
  128. // Generate list of albums
  129. $.each(data.content, function(index) {
  130. var that = this;
  131. if (!that.thumb0) that.thumb0 = 'src/images/no_cover.svg';
  132. that.title = "<img class='albumCover' width='16' height='16' src='" + that.thumb0 + "'><div class='albumTitle'>" + that.title + "</div>";
  133. if (that.id!=album.getID()) items.push({ type: 'item', title: that.title, fn: function() { photo.setAlbum(photoIDs, that.id) } });
  134. });
  135. }
  136. basicContext.show(items, e, contextMenu.close);
  137. });
  138. }
  139. contextMenu.sharePhoto = function(photoID, e) {
  140. var link = photo.getViewLink(photoID),
  141. file = 'ionicons';
  142. if (photo.json.public==='2') link = location.href;
  143. var items = [
  144. { type: 'item', title: '<input readonly id="link" value="' + link + '">', fn: function() {}, class: 'noHover' },
  145. { type: 'separator' },
  146. { type: 'item', title: build.iconic('twitter', file, file) + 'Twitter', fn: function() { photo.share(photoID, 0) } },
  147. { type: 'item', title: build.iconic('facebook', file, file) + 'Facebook', fn: function() { photo.share(photoID, 1) } },
  148. { type: 'item', title: build.iconic('envelope-closed') + 'Mail', fn: function() { photo.share(photoID, 2) } },
  149. { type: 'item', title: build.iconic('dropbox', file, file) + 'Dropbox', fn: function() { photo.share(photoID, 3) } },
  150. { type: 'item', title: build.iconic('link-intact') + 'Direct Link', fn: function() { window.open(photo.getDirectLink()) } },
  151. { type: 'separator' },
  152. { type: 'item', title: build.iconic('ban') + 'Make Private', fn: function() { photo.setPublic(photoID) } }
  153. ];
  154. basicContext.show(items, e);
  155. $('.basicContext input#link').focus().select();
  156. }
  157. contextMenu.shareAlbum = function(albumID, e) {
  158. var file = 'ionicons';
  159. var items = [
  160. { type: 'item', title: '<input readonly id="link" value="' + location.href + '">', fn: function() {}, class: 'noHover' },
  161. { type: 'separator' },
  162. { type: 'item', title: build.iconic('twitter', file, file) + 'Twitter', fn: function() { album.share(0) } },
  163. { type: 'item', title: build.iconic('facebook', file, file) + 'Facebook', fn: function() { album.share(1) } },
  164. { type: 'item', title: build.iconic('envelope-closed') + 'Mail', fn: function() { album.share(2) } },
  165. { type: 'separator' },
  166. { type: 'item', title: build.iconic('ban') + 'Make Private', fn: function() { album.setPublic(albumID) } }
  167. ];
  168. basicContext.show(items, e);
  169. $('.basicContext input#link').focus().select();
  170. }
  171. contextMenu.close = function() {
  172. if (!visible.contextMenu()) return false;
  173. basicContext.close();
  174. $('.photo.active, .album.active').removeClass('active');
  175. if (visible.multiselect()) multiselect.close();
  176. }