contextMenu.js 11 KB

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