Created
January 18, 2013 19:45
-
-
Save dblandin/4567803 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.InvitesApp = { | |
Models: {} | |
Collections: {} | |
Views: {} | |
# Shared regular expressions, largely duplicates of ruby model validations | |
Regexes: | |
name: /^[a-z]+[-\w\s\.']*$/i | |
email: /[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/ | |
Options: | |
groupingWarning: 'Are you sure? All scouts in the group will lose their group' | |
initialize: (serialized) -> | |
mission_json = serialized.mission | |
grouping_json = serialized.scout_groups | |
invitation_json = serialized.assignments | |
previous_missions_json = serialized.previous_missions | |
# Mission Model - Gradually replacing the raw json | |
@mission = new InvitesApp.Models.Mission(mission_json) | |
@ratings = new ViewersApp.Collections.Ratings().preload() | |
InvitesApp.Collections.Groupings::psuedo.push( | |
id: 0 | |
mission_id: @mission.id | |
root: true | |
) | |
# Collections | |
@invitations = new InvitesApp.Collections.Assignments( | |
[], | |
mission: @mission | |
) | |
@groupings = new InvitesApp.Collections.Groupings | |
invitations: @invitations | |
mission: @mission | |
model: InvitesApp.Models.ScoutGroup | |
url: 'scout_groups' | |
# Grouping Views | |
@groupingsIndex = new InvitesApp.Views.GroupingsIndex | |
el: '#groupings-index' | |
collection: @groupings | |
showClass: InvitesApp.Views.GroupingShow | |
@groupingForm = new InvitesApp.Views.GroupingForm | |
el: '#grouping-form' | |
collection: @groupings | |
model_name: 'Group' | |
# Invitation Views | |
@invitesIndex = new InvitesApp.Views.InvitesIndex | |
el: '#invite-table' | |
collection: @invitations | |
allButton: 'Invite All' | |
columns: ['scout', 'rating', 'snippets', 'messages', 'group', 'status', 'action'] | |
mission: @mission | |
viewClass: InvitesApp.Views.AssignmentsShow | |
invitesClosed: true | |
@inviteModal = new InvitesApp.Models.Assignment | |
mission: @mission | |
customMessage: "Lucky you! You've been invited to participate in <%= name %>, a new mission on dScout." | |
tokensDeducted: true | |
@inviteSingle = new InvitesApp.Views.InviteSingle | |
collection: @groupings | |
instructions: 'Invite scouts to participate in the mission' | |
groupSelect: true | |
@inviteBatch = new InvitesApp.Views.InviteBatch | |
collection: @groupings | |
groupSelect: true | |
@invitePrevious = new InvitesApp.Views.InvitePrevious | |
collection: @groupings | |
mission: @mission | |
previous: previous_missions_json | |
displayScoutsCount: true | |
enableOnlySubmitted: true | |
enableIncludeGroups: true | |
@inviteModes = new InvitesApp.Views.InviteModes | |
style: 'scout' | |
modes: [{ name: 'single', view: @inviteSingle, title: 'Add a Scout' }, | |
{ name: 'batch', view: @inviteBatch, title: 'Batch Add Scouts' }, | |
{ name: 'previous', view: @invitePrevious, title: 'Add from Previous' }] | |
# Assignment totals | |
@inviteStatsPane = new InvitesApp.Views.InviteStats( | |
paneType: 'inviteStats' | |
collection: @invitations | |
) | |
# Blank Slate | |
@inviteBlankSlatePane = new InvitesApp.Views.InviteBlankSlate( | |
collection: @invitations | |
replaces: @invitesIndex | |
template: JST['invites_app/templates/invites/scouts_blank_slate'] | |
) | |
# Group Messaging | |
@groupMessagesPane = new InvitesApp.Views.GroupMessagesForm( | |
panetype: 'messages' | |
groupings: @groupings | |
invitations: @invitations | |
mission: @mission | |
) | |
# Scout Profile Modal | |
@inviteProfilePane = new InvitesApp.Views.InviteProfile( | |
mission_id: @mission.id | |
account_id: @mission.account_id | |
).render() | |
# Toolbar | |
@toolbar = new InvitesApp.Views.Toolbar( | |
el: '#toolbar' | |
collection: @groupings | |
invitations: @invitations | |
).render() | |
@toolbar.addPane 'group-message', @groupMessagesPane | |
@toolbar.addPane 'invite-stats', @inviteStatsPane | |
#@toolbar.addPane 'add-scouts', @inviteModes | |
# Bootstrap collections | |
@groupings.reset grouping_json | |
@invitations.reset invitation_json | |
@groupings.activate @groupings.at(0) | |
# Trigger table sorting | |
$('.invite-table').tablesorter() | |
@ | |
activeScoutIDs: -> | |
_.chain(@invitations.active()) | |
.map((assignment) -> assignment.get('user_id')) | |
.uniq() | |
.value() | |
.join(',') | |
} | |
#= require_tree . | |
#= require_tree ./models | |
#= require_tree ./collections | |
#= require_tree ./templates | |
#= require_tree ./views |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment