<commit_before>PhotoCollection = require 'collections/photo'
client = require "../lib/client"

# An album
# Properties :
# - photos : a PhotoCollection of the photo in this album
# maintains attribute

module.exports = class Album extends Backbone.Model

    urlRoot: 'albums'

    defaults: ->
        title: ''
        description: ''
        clearance: []
        thumbsrc: 'img/nophotos.gif'
        orientation: 1

    url: -> super + app.urlKey

    constructor: ->
        @photos = new PhotoCollection()
        return super

    # Build orientation and cover thumb src from photo attribute/
    parse: (attrs) ->

        if attrs.photos?.length > 0
            @photos.reset attrs.photos, parse: true
        delete attrs.photos


        if attrs.coverPicture and attrs.coverPicture isnt 'null'
            attrs.thumb = attrs.coverPicture
            attrs.thumbsrc = "photos/thumbs/#{attrs.coverPicture}.jpg"
            if @photos.get(attrs.coverPicture)?.attributes?.orientation?
                attrs.orientation =
                    @photos._byId[attrs.coverPicture].attributes.orientation

        if attrs.clearance is 'hidden'
            attrs.clearance = 'public'

        if attrs.clearance is 'private'
            attrs.clearance = []

        return attrs

    # Build cover thumb src from coverPicture field.
    getThumbSrc: ->
        "photos/thumbs/#{@get 'coverPicture'}.jpg" + app.urlKey

    getPublicURL: (key) ->
        urlKey = if key then "?key=#{key}" else ""
        "#{window.location.origin}/public/photos/#{urlKey}#albums/#{@id}"

    # Send sharing email for this album.
    sendMail: (url, mails, callback) ->
        data =
            url: url
            mails: mails
        client.post "albums/share", data, callback
<commit_msg>Use a default thumbnail when album is empty<commit_after>PhotoCollection = require 'collections/photo'
client = require "../lib/client"

# An album
# Properties :
# - photos : a PhotoCollection of the photo in this album
# maintains attribute

module.exports = class Album extends Backbone.Model

    urlRoot: 'albums'

    defaults: ->
        title: ''
        description: ''
        clearance: []
        thumbsrc: 'img/nophotos.gif'
        orientation: 1

    url: -> super + app.urlKey

    constructor: ->
        @photos = new PhotoCollection()
        return super

    # Build orientation and cover thumb src from photo attribute/
    parse: (attrs) ->

        if attrs.photos?.length > 0
            @photos.reset attrs.photos, parse: true
        delete attrs.photos


        if attrs.coverPicture and attrs.coverPicture isnt 'null'
            attrs.thumb = attrs.coverPicture
            attrs.thumbsrc = "photos/thumbs/#{attrs.coverPicture}.jpg"
            if @photos.get(attrs.coverPicture)?.attributes?.orientation?
                attrs.orientation =
                    @photos._byId[attrs.coverPicture].attributes.orientation

        if attrs.clearance is 'hidden'
            attrs.clearance = 'public'

        if attrs.clearance is 'private'
            attrs.clearance = []

        return attrs

    # Build cover thumb src from coverPicture field.
    getThumbSrc: ->
        coverPicture = @get 'coverPicture'
        if coverPicture?
            thumbSrc = "photos/thumbs/#{@get 'coverPicture'}.jpg"
        else
            thumbSrc = "img/nophotos.gif"
        return thumbSrc + app.urlKey

    getPublicURL: (key) ->
        urlKey = if key then "?key=#{key}" else ""
        "#{window.location.origin}/public/photos/#{urlKey}#albums/#{@id}"

    # Send sharing email for this album.
    sendMail: (url, mails, callback) ->
        data =
            url: url
            mails: mails
        client.post "albums/share", data, callback

{'fraction_non_alphanumeric': 0.10687633262260128, 'fraction_numerical': 0.0010660980810234541, 'mean_word_length': 2.137959866220736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3842210', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1031, 'n_words': 278}