jam-cloud/web/app/assets/javascripts/mods_utils.js.coffee

41 lines
984 B
CoffeeScript
Raw Permalink Normal View History

2014-11-11 22:21:29 +00:00
#
# Common utility functions.
#
$ = jQuery
context = window
context.JK ||= {};
class ModUtils
constructor: () ->
@logger = context.JK.logger
init: () =>
# creates a new show structure suitable for applying to a user update
noShow: (noShowName) =>
noShowValue = {}
noShowValue[noShowName] = true
{no_show: noShowValue}
updateNoShow: (noShowName) =>
context.JK.app.updateUserModel({mods: this.noShow(noShowName)})
# returns a deferred, so use .done
shouldShow: (noShowName) =>
deferred = new $.Deferred();
context.JK.app.user()
.done((user) => (
noShows = user.mods?.no_show
shouldShowForName = if noShows? then !noShows[noShowName] else true
deferred.resolve(shouldShowForName)
))
return deferred;
# returns a gear mod by name
getGear: (name) =>
gear = context.JK.app.currentUser().mods?.gear
if gear? then gear[name] else undefined
2014-11-11 22:21:29 +00:00
# global instance
context.JK.ModUtils = new ModUtils()