contextMenu.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. let items = [
  8. { title: build.iconic('image') + 'Upload Photo', fn: () => $('#upload_files').click() },
  9. { },
  10. { title: build.iconic('link-intact') + 'Import from Link', fn: upload.start.url },
  11. { title: build.iconic('dropbox', 'ionicons') + 'Import from Dropbox', fn: upload.start.dropbox },
  12. { title: build.iconic('terminal') + 'Import from Server', fn: upload.start.server },
  13. { },
  14. { 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. let items = [
  21. { title: build.iconic('person') + 'Change Login', fn: settings.setLogin },
  22. { title: build.iconic('sort-ascending') + 'Change Sorting', fn: settings.setSorting },
  23. { title: build.iconic('dropbox', 'ionicons') + 'Set Dropbox', fn: settings.setDropboxKey },
  24. { },
  25. { title: build.iconic('info') + 'About Lychee', fn: () => window.open(lychee.website) },
  26. { title: build.iconic('wrench') + 'Diagnostics', fn: () => window.open('plugins/Diagnostics/') },
  27. { title: build.iconic('align-left') + 'Show Log', fn: () => window.open('plugins/Log/') },
  28. { },
  29. { 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. // Show merge-item when there's more than one album
  39. let showMerge = (albums.json && albums.json.albums && Object.keys(albums.json.albums).length>1)
  40. let items = [
  41. { title: build.iconic('pencil') + 'Rename', fn: () => album.setTitle([ albumID ]) },
  42. { title: build.iconic('collapse-left') + 'Merge', visible: showMerge, fn: () => { basicContext.close(); contextMenu.mergeAlbum(albumID, e) } },
  43. { title: build.iconic('trash') + 'Delete', fn: () => album.delete([ albumID ]) }
  44. ]
  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. // Automatically merge selected albums when albumIDs contains more than one album
  51. // Show list of albums otherwise
  52. let autoMerge = (albumIDs.length>1 ? true : false)
  53. // Show merge-item when there's more than one album
  54. let showMerge = (albums.json && albums.json.albums && Object.keys(albums.json.albums).length>1)
  55. let items = [
  56. { title: build.iconic('pencil') + 'Rename All', fn: () => album.setTitle(albumIDs) },
  57. { title: build.iconic('collapse-left') + 'Merge All', visible: showMerge && autoMerge, fn: () => album.merge(albumIDs) },
  58. { title: build.iconic('collapse-left') + 'Merge', visible: showMerge && !autoMerge, fn: () => { basicContext.close(); contextMenu.mergeAlbum(albumIDs[0], e) } },
  59. { title: build.iconic('trash') + 'Delete All', fn: () => album.delete(albumIDs) }
  60. ]
  61. items.push()
  62. basicContext.show(items, e.originalEvent, contextMenu.close)
  63. }
  64. contextMenu.albumTitle = function(albumID, e) {
  65. api.post('Album::getAll', {}, function(data) {
  66. let items = []
  67. if (data.albums && data.num>1) {
  68. // Generate list of albums
  69. $.each(data.albums, function() {
  70. if (!this.thumbs[0]) this.thumbs[0] = 'src/images/no_cover.svg'
  71. let title = lychee.html`<img class='cover' width='16' height='16' src='$${ this.thumbs[0] }'><div class='title'>$${ this.title }</div>`
  72. if (this.id!=albumID) items.push({ title, fn: () => lychee.goto(this.id) })
  73. })
  74. items.unshift({ })
  75. }
  76. items.unshift({ title: build.iconic('pencil') + 'Rename', fn: () => album.setTitle([ albumID ]) })
  77. basicContext.show(items, e.originalEvent, contextMenu.close)
  78. })
  79. }
  80. contextMenu.mergeAlbum = function(albumID, e) {
  81. api.post('Album::getAll', {}, function(data) {
  82. let items = []
  83. if (data.albums && data.num>1) {
  84. $.each(data.albums, function() {
  85. if (!this.thumbs[0]) this.thumbs[0] = 'src/images/no_cover.svg'
  86. let title = lychee.html`<img class='cover' width='16' height='16' src='$${ this.thumbs[0] }'><div class='title'>$${ this.title }</div>`
  87. if (this.id!=albumID) items.push({ title, fn: () => album.merge([ albumID, this.id ]) })
  88. })
  89. }
  90. if (items.length===0) return false
  91. basicContext.show(items, e.originalEvent, contextMenu.close)
  92. })
  93. }
  94. contextMenu.photo = function(photoID, e) {
  95. // Notice for 'Move':
  96. // fn must call basicContext.close() first,
  97. // in order to keep the selection
  98. let items = [
  99. { title: build.iconic('star') + 'Star', fn: () => photo.setStar([ photoID ]) },
  100. { title: build.iconic('tag') + 'Tags', fn: () => photo.editTags([ photoID ]) },
  101. { },
  102. { title: build.iconic('pencil') + 'Rename', fn: () => photo.setTitle([ photoID ]) },
  103. { title: build.iconic('layers') + 'Duplicate', fn: () => photo.duplicate([ photoID ]) },
  104. { title: build.iconic('folder') + 'Move', fn: () => { basicContext.close(); contextMenu.move([ photoID ], e) } },
  105. { title: build.iconic('trash') + 'Delete', fn: () => photo.delete([ photoID ]) }
  106. ]
  107. $('.photo[data-id="' + photoID + '"]').addClass('active')
  108. basicContext.show(items, e.originalEvent, contextMenu.close)
  109. }
  110. contextMenu.photoMulti = function(photoIDs, e) {
  111. // Notice for 'Move All':
  112. // fn must call basicContext.close() first,
  113. // in order to keep the selection and multiselect
  114. multiselect.stopResize()
  115. let items = [
  116. { title: build.iconic('star') + 'Star All', fn: () => photo.setStar(photoIDs) },
  117. { title: build.iconic('tag') + 'Tag All', fn: () => photo.editTags(photoIDs) },
  118. { },
  119. { title: build.iconic('pencil') + 'Rename All', fn: () => photo.setTitle(photoIDs) },
  120. { title: build.iconic('layers') + 'Duplicate All', fn: () => photo.duplicate(photoIDs) },
  121. { title: build.iconic('folder') + 'Move All', fn: () => { basicContext.close(); contextMenu.move(photoIDs, e) } },
  122. { title: build.iconic('trash') + 'Delete All', fn: () => photo.delete(photoIDs) }
  123. ]
  124. basicContext.show(items, e.originalEvent, contextMenu.close)
  125. }
  126. contextMenu.photoTitle = function(albumID, photoID, e) {
  127. let items = [
  128. { title: build.iconic('pencil') + 'Rename', fn: () => photo.setTitle([ photoID ]) }
  129. ]
  130. let data = album.json
  131. if (data.content!==false && data.num>1) {
  132. items.push({ })
  133. // Generate list of albums
  134. $.each(data.content, function(index) {
  135. let title = lychee.html`<img class='cover' width='16' height='16' src='$${ this.thumbUrl }'><div class='title'>$${ this.title }</div>`
  136. if (this.id!=photoID) items.push({ title, fn: () => lychee.goto(albumID + '/' + this.id) })
  137. })
  138. }
  139. basicContext.show(items, e.originalEvent, contextMenu.close)
  140. }
  141. contextMenu.photoMore = function(photoID, e) {
  142. // Show download-item when
  143. // a) Public mode is off
  144. // b) Downloadable is 1 and public mode is on
  145. let showDownload = lychee.publicMode===false || ((album.json && album.json.downloadable && album.json.downloadable==='1') && lychee.publicMode===true)
  146. let items = [
  147. { title: build.iconic('fullscreen-enter') + 'Full Photo', fn: () => window.open(photo.getDirectLink()) },
  148. { title: build.iconic('cloud-download') + 'Download', visible: showDownload, fn: () => photo.getArchive(photoID) }
  149. ]
  150. basicContext.show(items, e.originalEvent)
  151. }
  152. contextMenu.move = function(photoIDs, e) {
  153. let items = []
  154. api.post('Album::getAll', {}, function(data) {
  155. if (data.num===0) {
  156. // Show only 'Add album' when no album available
  157. items = [
  158. { title: 'New Album', fn: album.add }
  159. ]
  160. } else {
  161. // Generate list of albums
  162. $.each(data.albums, function() {
  163. if (!this.thumbs[0]) this.thumbs[0] = 'src/images/no_cover.svg'
  164. let title = lychee.html`<img class='cover' width='16' height='16' src='$${ this.thumbs[0] }'><div class='title'>$${ this.title }</div>`
  165. if (this.id!=album.getID()) items.push({ title, fn: () => photo.setAlbum(photoIDs, this.id) })
  166. })
  167. // Show Unsorted when unsorted is not the current album
  168. if (album.getID()!=='0') {
  169. items.unshift({ })
  170. items.unshift({ title: 'Unsorted', fn: () => photo.setAlbum(photoIDs, 0) })
  171. }
  172. }
  173. basicContext.show(items, e.originalEvent, contextMenu.close)
  174. })
  175. }
  176. contextMenu.sharePhoto = function(photoID, e) {
  177. let link = photo.getViewLink(photoID)
  178. let iconClass = 'ionicons'
  179. let items = [
  180. { title: `<input readonly id="link" value="${ link }">`, fn: () => {}, class: 'basicContext__item--noHover' },
  181. { },
  182. { title: build.iconic('twitter', iconClass) + 'Twitter', fn: () => photo.share(photoID, 'twitter') },
  183. { title: build.iconic('facebook', iconClass) + 'Facebook', fn: () => photo.share(photoID, 'facebook') },
  184. { title: build.iconic('envelope-closed') + 'Mail', fn: () => photo.share(photoID, 'mail') },
  185. { title: build.iconic('dropbox', iconClass) + 'Dropbox', fn: () => photo.share(photoID, 'dropbox') },
  186. { title: build.iconic('link-intact') + 'Direct Link', fn: () => window.open(photo.getDirectLink()) },
  187. { },
  188. { title: build.iconic('ban') + 'Make Private', fn: () => photo.setPublic(photoID) }
  189. ]
  190. basicContext.show(items, e.originalEvent)
  191. $('.basicContext input#link').focus().select()
  192. }
  193. contextMenu.shareAlbum = function(albumID, e) {
  194. let iconClass = 'ionicons'
  195. let items = [
  196. { title: `<input readonly id="link" value="${ location.href }">`, fn: () => {}, class: 'basicContext__item--noHover' },
  197. { },
  198. { title: build.iconic('twitter', iconClass) + 'Twitter', fn: () => album.share('twitter') },
  199. { title: build.iconic('facebook', iconClass) + 'Facebook', fn: () => album.share('facebook') },
  200. { title: build.iconic('envelope-closed') + 'Mail', fn: () => album.share('mail') },
  201. { },
  202. { title: build.iconic('pencil') + 'Edit Sharing', fn: () => album.setPublic(albumID, true, e) },
  203. { title: build.iconic('ban') + 'Make Private', fn: () => album.setPublic(albumID, false) }
  204. ]
  205. basicContext.show(items, e.originalEvent)
  206. $('.basicContext input#link').focus().select()
  207. }
  208. contextMenu.close = function() {
  209. if (!visible.contextMenu()) return false
  210. basicContext.close()
  211. $('.photo.active, .album.active').removeClass('active')
  212. if (visible.multiselect()) multiselect.close()
  213. }