contextMenu.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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('dropbox', 'ionicons') + '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('dropbox', 'ionicons') + '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: 'Merge All', fn: function () { album.merge(albumIDs) } },
  46. { type: 'item', title: build.iconic('pencil') + 'Rename All', fn: function() { album.setTitle(albumIDs) } },
  47. { type: 'item', title: build.iconic('trash') + 'Delete All', fn: function() { album.delete(albumIDs) } }
  48. ];
  49. basicContext.show(items, e, contextMenu.close);
  50. }
  51. contextMenu.albumTitle = function(albumID, e) {
  52. var items = [];
  53. api.post('Album::getAll', {}, function(data) {
  54. if (data.num>1) {
  55. // Generate list of albums
  56. $.each(data.albums, function(index) {
  57. var that = this,
  58. title = '';
  59. if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg';
  60. title = "<img class='cover' width='16' height='16' src='" + that.thumbs[0] + "'><div class='title'>" + that.title + "</div>";
  61. if (that.id!=albumID) items.unshift({ type: 'item', title, fn: function() { lychee.goto(that.id) } });
  62. });
  63. items.unshift({ type: 'separator' });
  64. }
  65. items.unshift({ type: 'item', title: build.iconic('pencil') + 'Rename', fn: function() { album.setTitle([albumID]) } });
  66. basicContext.show(items, e, contextMenu.close);
  67. });
  68. }
  69. contextMenu.photo = function(photoID, e) {
  70. // Notice for 'Move':
  71. // fn must call basicContext.close() first,
  72. // in order to keep the selection
  73. var items = [
  74. { type: 'item', title: build.iconic('star') + 'Star', fn: function() { photo.setStar([photoID]) } },
  75. { type: 'item', title: build.iconic('tag') + 'Tags', fn: function() { photo.editTags([photoID]) } },
  76. { type: 'separator' },
  77. { type: 'item', title: build.iconic('pencil') + 'Rename', fn: function() { photo.setTitle([photoID]) } },
  78. { type: 'item', title: build.iconic('layers') + 'Duplicate', fn: function() { photo.duplicate([photoID]) } },
  79. { type: 'item', title: build.iconic('folder') + 'Move', fn: function() { basicContext.close(); contextMenu.move([photoID], e); } },
  80. { type: 'item', title: build.iconic('trash') + 'Delete', fn: function() { photo.delete([photoID]) } }
  81. ];
  82. $('.photo[data-id="' + photoID + '"]').addClass('active');
  83. basicContext.show(items, e, contextMenu.close);
  84. }
  85. contextMenu.photoMulti = function(photoIDs, e) {
  86. // Notice for 'Move All':
  87. // fn must call basicContext.close() first,
  88. // in order to keep the selection and multiselect
  89. multiselect.stopResize();
  90. var items = [
  91. { type: 'item', title: build.iconic('star') + 'Star All', fn: function() { photo.setStar(photoIDs) } },
  92. { type: 'item', title: build.iconic('tag') + 'Tag All', fn: function() { photo.editTags(photoIDs) } },
  93. { type: 'separator' },
  94. { type: 'item', title: build.iconic('pencil') + 'Rename All', fn: function() { photo.setTitle(photoIDs) } },
  95. { type: 'item', title: build.iconic('layers') + 'Duplicate All', fn: function() { photo.duplicate(photoIDs) } },
  96. { type: 'item', title: build.iconic('folder') + 'Move All', fn: function() { basicContext.close(); contextMenu.move(photoIDs, e); } },
  97. { type: 'item', title: build.iconic('trash') + 'Delete All', fn: function() { photo.delete(photoIDs) } }
  98. ];
  99. basicContext.show(items, e, contextMenu.close);
  100. }
  101. contextMenu.photoTitle = function(albumID, photoID, e) {
  102. var items = [
  103. { type: 'item', title: build.iconic('pencil') + 'Rename', fn: function() { photo.setTitle([photoID]) } }
  104. ];
  105. var data = album.json;
  106. if (data.num>1) {
  107. items.push({ type: 'separator' });
  108. // Generate list of albums
  109. $.each(data.content, function(index) {
  110. var that = this,
  111. title = '';
  112. title = "<img class='cover' width='16' height='16' src='" + that.thumbUrl + "'><div class='title'>" + that.title + "</div>";
  113. if (that.id!=photoID) items.push({ type: 'item', title, fn: function() { lychee.goto(albumID + '/' + that.id) } });
  114. });
  115. }
  116. basicContext.show(items, e, contextMenu.close);
  117. }
  118. contextMenu.photoMore = function(photoID, e) {
  119. var items = [
  120. { type: 'item', title: build.iconic('fullscreen-enter') + 'Full Photo', fn: function() { window.open(photo.getDirectLink()) } },
  121. { type: 'item', title: build.iconic('cloud-download') + 'Download', fn: function() { photo.getArchive(photoID) } }
  122. ];
  123. // Remove download-item when
  124. // 1) In public mode
  125. // 2) Downloadable not 1 or not found
  126. if (!(album.json&&album.json.downloadable&&album.json.downloadable==='1')&&
  127. lychee.publicMode===true) items.splice(1, 1);
  128. basicContext.show(items, e);
  129. }
  130. contextMenu.move = function(photoIDs, e) {
  131. var items = [];
  132. api.post('Album::getAll', {}, function(data) {
  133. if (data.num===0) {
  134. // Show only 'Add album' when no album available
  135. items = [
  136. { type: 'item', title: 'New Album', fn: album.add }
  137. ];
  138. } else {
  139. // Generate list of albums
  140. $.each(data.albums, function(index) {
  141. var that = this;
  142. if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg';
  143. that.title = "<img class='cover' width='16' height='16' src='" + that.thumbs[0] + "'><div class='title'>" + that.title + "</div>";
  144. if (that.id!=album.getID()) items.unshift({ type: 'item', title: that.title, fn: function() { photo.setAlbum(photoIDs, that.id) } });
  145. });
  146. // Show Unsorted when unsorted is not the current album
  147. if (album.getID()!=='0') {
  148. items.unshift({ type: 'separator' });
  149. items.unshift({ type: 'item', title: 'Unsorted', fn: function() { photo.setAlbum(photoIDs, 0) } });
  150. }
  151. }
  152. basicContext.show(items, e, contextMenu.close);
  153. });
  154. }
  155. contextMenu.sharePhoto = function(photoID, e) {
  156. var link = photo.getViewLink(photoID),
  157. iconClass = 'ionicons';
  158. if (photo.json.public==='2') link = location.href;
  159. var items = [
  160. { type: 'item', title: '<input readonly id="link" value="' + link + '">', fn: function() {}, class: 'noHover' },
  161. { type: 'separator' },
  162. { type: 'item', title: build.iconic('twitter', iconClass) + 'Twitter', fn: function() { photo.share(photoID, 0) } },
  163. { type: 'item', title: build.iconic('facebook', iconClass) + 'Facebook', fn: function() { photo.share(photoID, 1) } },
  164. { type: 'item', title: build.iconic('envelope-closed') + 'Mail', fn: function() { photo.share(photoID, 2) } },
  165. { type: 'item', title: build.iconic('dropbox', iconClass) + 'Dropbox', fn: function() { photo.share(photoID, 3) } },
  166. { type: 'item', title: build.iconic('link-intact') + 'Direct Link', fn: function() { window.open(photo.getDirectLink()) } },
  167. { type: 'separator' },
  168. { type: 'item', title: build.iconic('ban') + 'Make Private', fn: function() { photo.setPublic(photoID) } }
  169. ];
  170. basicContext.show(items, e);
  171. $('.basicContext input#link').focus().select();
  172. }
  173. contextMenu.shareAlbum = function(albumID, e) {
  174. var iconClass = 'ionicons';
  175. var items = [
  176. { type: 'item', title: '<input readonly id="link" value="' + location.href + '">', fn: function() {}, class: 'noHover' },
  177. { type: 'separator' },
  178. { type: 'item', title: build.iconic('twitter', iconClass) + 'Twitter', fn: function() { album.share(0) } },
  179. { type: 'item', title: build.iconic('facebook', iconClass) + 'Facebook', fn: function() { album.share(1) } },
  180. { type: 'item', title: build.iconic('envelope-closed') + 'Mail', fn: function() { album.share(2) } },
  181. { type: 'separator' },
  182. { type: 'item', title: build.iconic('pencil') + 'Edit Sharing', fn: function() { album.setPublic(albumID, true, e) } },
  183. { type: 'item', title: build.iconic('ban') + 'Make Private', fn: function() { album.setPublic(albumID, false) } }
  184. ];
  185. basicContext.show(items, e);
  186. $('.basicContext input#link').focus().select();
  187. }
  188. contextMenu.close = function() {
  189. if (!visible.contextMenu()) return false;
  190. basicContext.close();
  191. $('.photo.active, .album.active').removeClass('active');
  192. if (visible.multiselect()) multiselect.close();
  193. }