contextMenu.js 11 KB

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