Sha256: fec0788d6c6dc794200bdbe3e8bbeb89aa79ce1ba1996dd4de9697bc78062408

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

#
# This represents a collection of bookmarks that can be injected into controllers in order to
# keep track of the current user's bookmarks, which may be displayed at several places
# on the page.
#
# Please note, that file uses the extensions of make-js-more-like-ruby.js.coffee.
#

@app.factory( "current_user_bookmarks", [ "Bookmark", "$rootScope", (Bookmark, $rootScope)->

  bookmarks = []

  broadcastChange = ->
    $rootScope.$broadcast( "bookmarksChange" )

  bookmarks.add = (newBookmark)->
    bookmarks.push( newBookmark ) unless bookmarks.includes( newBookmark )
    broadcastChange()

  bookmarks.addArray = (newBookmarks)->
    bookmarks.pushArray newBookmarks

  bookmarks.fill = (newBookmarks)->
    bookmarks.clear()
    bookmarks.addArray newBookmarks

  bookmarks.remove = (starToRemove)->
    bookmarks.removeItem starToRemove
    broadcastChange()

  bookmarks.find_all_by_user_id = (user_id)->
    Bookmark.query( user_id: user_id, (fetchedBookmarks)->
      bookmarks.fill( fetchedBookmarks )
    )
    broadcastChange()

  return bookmarks

] )

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
your_platform-1.0.1 app/assets/javascripts/services-ng/current_user_bookmarks.js.coffee
your_platform-1.0.0 app/assets/javascripts/services-ng/current_user_bookmarks.js.coffee
your_platform-0.0.2 app/assets/javascripts/services-ng/current_user_bookmarks.js.coffee