contextMenu.js 11 KB

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