build.coffee 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. ###
  2. # @description This module is used to generate HTML-Code.
  3. # @copyright 2014 by Tobias Reich
  4. ###
  5. window.build = {}
  6. build.iconic = (icon, classes, path) ->
  7. path = path || 'src/images/iconic.svg'
  8. classes = classes || ''
  9. "<svg viewBox='0 0 8 8' class='iconic #{ classes }'><use xlink:href='#{ path }##{ icon }'></use></svg>"
  10. build.divider = (title) ->
  11. "<div class='divider fadeIn'><h1>#{ title }</h1></div>"
  12. build.editIcon = (id) ->
  13. "<div id='#{ id }' class='edit'>#{ build.iconic('pencil') }</div>"
  14. build.multiselect = (top, left) ->
  15. "<div id='multiselect' style='top: #{ top }px; left: #{ left }px;'></div>"
  16. build.album = (data) ->
  17. return '' if not data?
  18. title = data.title
  19. longTitle = ''
  20. typeThumb = ''
  21. if title? and title.length > 18
  22. title = data.title.substr(0, 18) + '...'
  23. longTitle = data.title
  24. if data.thumb0.split('.').pop() is 'svg' then typeThumb = 'nonretina'
  25. html = """
  26. <div class='album' data-id='#{ data.id }' data-password='#{ data.password }'>
  27. <img src='#{ data.thumb2 }' width='200' height='200' alt='thumb' data-type='nonretina'>
  28. <img src='#{ data.thumb1 }' width='200' height='200' alt='thumb' data-type='nonretina'>
  29. <img src='#{ data.thumb0 }' width='200' height='200' alt='thumb' data-type='#{ typeThumb }'>
  30. <div class='overlay'>
  31. """
  32. if data.password and lychee.publicMode is false
  33. html += "<h1 title='#{ longTitle }'><span class='icon-lock'></span> #{ title }</h1>";
  34. else
  35. html += "<h1 title='#{ longTitle }'>#{ title }</h1>"
  36. html += """
  37. <a>#{ data.sysdate }</a>
  38. </div>
  39. """
  40. if lychee.publicMode is false
  41. if data.star is '1' then html += "<a class='badge'>#{ build.iconic('star') }</a>"
  42. if data.public is '1' then html += "<a class='badge'>#{ build.iconic('eye') }</a>"
  43. if data.unsorted is '1' then html += "<a class='badge'>#{ build.iconic('list') }</a>"
  44. if data.recent is '1' then html += "<a class='badge'>#{ build.iconic('clock') }</a>"
  45. html += "</div>"
  46. return html
  47. build.photo = (data) ->
  48. return '' if not data?
  49. title = data.title
  50. longTitle = ''
  51. if title? and title.length > 18
  52. title = data.title.substr(0, 18) + '...'
  53. longTitle = data.title
  54. html = """
  55. <div class='photo' data-album-id='#{ data.album }' data-id='#{ data.id }'>
  56. <img src='#{ data.thumbUrl }' width='200' height='200' alt='thumb'>
  57. <div class='overlay'>
  58. <h1 title='#{ longTitle }'>#{ title }</h1>
  59. """
  60. if data.cameraDate is 1
  61. html += "<a><span class='icon-camera' title='Photo Date'></span>#{ data.sysdate }</a>"
  62. else
  63. html += "<a>#{ data.sysdate }</a>"
  64. html += "</div>"
  65. if data.star is '1' then html += "<a class='badge'>#{ build.iconic('star') }</a>"
  66. if lychee.publicMode is false and data.public is '1' and album.json.public isnt '1' then html += "<a class='badge'>#{ build.iconic('eye') }</a>"
  67. html += "</div>"
  68. return html
  69. build.imageview = (data, size, visibleControls) ->
  70. return '' if not data?
  71. html = """
  72. <div class='arrow_wrapper arrow_wrapper--previous'><a id='previous'>#{ build.iconic('caret-left') }</a></div>
  73. <div class='arrow_wrapper arrow_wrapper--next'><a id='next'>#{ build.iconic('caret-right') }</a></div>
  74. """
  75. if size is 'big'
  76. if visibleControls is true
  77. html += "<div id='image' style='background-image: url(#{ data.url })'></div>"
  78. else
  79. html += "<div id='image' style='background-image: url(#{ data.url });' class='full'></div>"
  80. else if size is 'medium'
  81. if visibleControls is true
  82. html += "<div id='image' style='background-image: url(#{ data.medium })'></div>"
  83. else
  84. html += "<div id='image' style='background-image: url(#{ data.medium });' class='full'></div>"
  85. else if size is 'small'
  86. if visibleControls is true
  87. html += "<div id='image' class='small' style='background-image: url(#{ data.url }); width: #{ data.width }px; height: #{ data.height }px; margin-top: -#{ parseInt(data.height/2-20) }px; margin-left: -#{ data.width/2 }px;'></div>"
  88. else
  89. html += "<div id='image' class='small' style='background-image: url(#{ data.url }); width: #{ data.width }px; height: #{ data.height }px; margin-top: -#{ parseInt(data.height/2) }px; margin-left: -#{ data.width/2 }px;'></div>"
  90. return html
  91. build.no_content = (typ) ->
  92. html = """
  93. <div class='no_content fadeIn'>
  94. <a class='icon icon-#{ typ }'></a>
  95. """
  96. switch typ
  97. when 'search' then html += "<p>No results</p>"
  98. when 'share' then html += "<p>No public albums</p>"
  99. when 'cog' then html += "<p>No configuration</p>"
  100. html += "</div>"
  101. return html
  102. build.modal = (title, text, button, marginTop, closeButton) ->
  103. if marginTop? then custom_style = "style='margin-top: #{ marginTop }px;'"
  104. else custom_style = ''
  105. html = """
  106. <div class='message_overlay fadeIn'>
  107. <div class='message center' #{ custom_style }>
  108. <h1>#{ title }</h1>
  109. """
  110. if closeButton isnt false then html += "<a class='close icon-remove-sign'></a>"
  111. html += "<p>#{ text }</p>"
  112. $.each button, (index) ->
  113. if this[0] isnt ''
  114. if index is 0 then html += "<a class='button active'>#{ this[0] }</a>"
  115. else html += "<a class='button'>#{ this[0] }</a>"
  116. html += """
  117. </div>
  118. </div>
  119. """
  120. return html
  121. build.uploadModal = (title, files) ->
  122. html = """
  123. <div class='upload_overlay fadeIn'>
  124. <div class='upload_message center'>
  125. <h1>#{ title }</h1>
  126. <a class='close icon-remove-sign'></a>
  127. <div class='rows'>
  128. """
  129. i = 0
  130. file = null
  131. while i < files.length
  132. file = files[i]
  133. if file.name.length > 40
  134. file.name = file.name.substr(0, 17) + '...' + file.name.substr(file.name.length-20, 20)
  135. html += """
  136. <div class='row'>
  137. <a class='name'>#{ lychee.escapeHTML(file.name) }</a>
  138. """
  139. if file.supported is true then html += "<a class='status'></a>"
  140. else html += "<a class='status error'>Not supported</a>"
  141. html += """
  142. <p class='notice'></p>
  143. </div>
  144. """
  145. i++
  146. html += """
  147. </div>
  148. </div>
  149. </div>
  150. """
  151. return html
  152. build.tags = (tags, forView) ->
  153. html = ''
  154. if forView is true or lychee.publicMode is true then editTagsHTML = ''
  155. else editTagsHTML = ' ' + build.editIcon('edit_tags')
  156. if tags isnt ''
  157. tags = tags.split ','
  158. tags.forEach (tag, index, array) ->
  159. html += "<a class='tag'>#{ tag }<span class='icon-remove' data-index='#{ index }'></span></a>"
  160. html += editTagsHTML
  161. else
  162. html = "<div class='empty'>No Tags#{ editTagsHTML }</div>"
  163. return html
  164. build.infoboxPhoto = (data, forView) ->
  165. html = ""
  166. switch data.public
  167. when '0' then visible = 'No'
  168. when '1' then visible = 'Yes'
  169. when '2' then visible = 'Yes (Album)'
  170. else visible = '-'
  171. if forView is true or lychee.publicMode is true then editTitleHTML = ''
  172. else editTitleHTML = ' ' + build.editIcon('edit_title')
  173. if forView is true or lychee.publicMode is true then editDescriptionHTML = ''
  174. else editDescriptionHTML = ' ' + build.editIcon('edit_description')
  175. infos = [
  176. ['', 'Basics']
  177. ['Title', data.title + editTitleHTML]
  178. ['Uploaded', data.sysdate]
  179. ['Description', data.description + editDescriptionHTML]
  180. ['', 'Image']
  181. ['Size', data.size]
  182. ['Format', data.type]
  183. ['Resolution', data.width + ' x ' + data.height]
  184. ['Tags', build.tags(data.tags, forView)]
  185. ]
  186. exifHash = data.takestamp+data.make+data.model+data.shutter+data.aperture+data.focal+data.iso
  187. if exifHash isnt '0' or exifHash isnt '0'
  188. infos = infos.concat [
  189. ['', 'Camera']
  190. ['Captured', data.takedate]
  191. ['Make', data.make]
  192. ['Type/Model', data.model]
  193. ['Shutter Speed', data.shutter]
  194. ['Aperture', data.aperture]
  195. ['Focal Length', data.focal]
  196. ['ISO', data.iso]
  197. ]
  198. infos = infos.concat [
  199. ['', 'Share']
  200. ['Public', visible]
  201. ]
  202. infos.forEach (info, i, items) ->
  203. if info[1] is '' or
  204. not info[1]?
  205. info[1] = '-'
  206. switch info[0]
  207. when ''
  208. # Divider
  209. html += """
  210. </table>
  211. <div class='divider'><h1>#{ info[1] }</h1></div>
  212. <table>
  213. """
  214. when 'Tags'
  215. # Tags
  216. if forView isnt true and lychee.publicMode is false
  217. html += """
  218. </table>
  219. <div class='divider'><h1>#{ info[0] }</h1></div>
  220. <div id='tags'>#{ info[1] }</div>
  221. """
  222. else
  223. # Item
  224. html += """
  225. <tr>
  226. <td>#{ info[0] }</td>
  227. <td class='attr_#{ info[0].toLowerCase() }'>#{ info[1] }</td>
  228. </tr>
  229. """
  230. html += """
  231. </table>
  232. <div class='bumper'></div>
  233. """
  234. return html
  235. build.infoboxAlbum = (data, forView) ->
  236. html = ""
  237. switch data.public
  238. when '0' then visible = 'No'
  239. when '1' then visible = 'Yes'
  240. else visible = '-'
  241. switch data.password
  242. when false then password = 'No'
  243. when true then password = 'Yes'
  244. else password = '-'
  245. switch data.downloadable
  246. when '0' then downloadable = 'No'
  247. when '1' then downloadable = 'Yes'
  248. else downloadable = '-'
  249. if forView is true or lychee.publicMode is true then editTitleHTML = ''
  250. else editTitleHTML = ' ' + build.editIcon('edit_title_album')
  251. if forView is true or lychee.publicMode is true then editDescriptionHTML = ''
  252. else editDescriptionHTML = ' ' + build.editIcon('edit_description_album')
  253. infos = [
  254. ['', 'Basics']
  255. ['Title', data.title + editTitleHTML]
  256. ['Description', data.description + editDescriptionHTML]
  257. ['', 'Album']
  258. ['Created', data.sysdate]
  259. ['Images', data.num]
  260. ['', 'Share']
  261. ['Public', visible]
  262. ['Downloadable', downloadable]
  263. ['Password', password]
  264. ]
  265. infos.forEach (info, i, items) ->
  266. if info[0] is ''
  267. # Divider
  268. html += """
  269. </table>
  270. <div class='divider'><h1>#{ info[1] }</h1></div>
  271. <table id='infos'>
  272. """
  273. else
  274. # Item
  275. html += """
  276. <tr>
  277. <td>#{ info[0] }</td>
  278. <td class='attr_#{ info[0].toLowerCase() }'>#{ info[1] }</td>
  279. </tr>
  280. """
  281. html += """
  282. </table>
  283. <div class='bumper'></div>
  284. """
  285. return html