context = window rest = context.JK.Rest() logger = context.JK.logger AppStore = context.AppStore SchoolActions = context.SchoolActions SchoolStore = context.SchoolStore UserStore = context.UserStore profileUtils = context.JK.ProfileUtils @AccountSchoolScreen = React.createClass({ mixins: [ ICheckMixin, Reflux.listenTo(AppStore, "onAppInit"), Reflux.listenTo(SchoolStore, "onSchoolChanged") Reflux.listenTo(UserStore, "onUserChanged") ] shownOnce: false screenVisible: false TILE_ACCOUNT: 'account' TILE_MEMBERS: 'members' TILE_EARNINGS: 'earnings' TILE_AGREEMENT: 'agreement' TILES: ['account', 'members', 'earnings', 'agreement'] onAppInit: (@app) -> @app.bindScreen('account/school', {beforeShow: @beforeShow, afterShow: @afterShow, beforeHide: @beforeHide}) onSchoolChanged: (schoolState) -> @setState(schoolState) onUserChanged: (userState) -> @noSchoolCheck(userState?.user) @setState({user: userState?.user}) componentDidMount: () -> @checkboxes = [{selector: 'input.slot-decision', stateKey: 'slot-decision'}] @root = $(@getDOMNode()) @iCheckify() componentDidUpdate: () -> @iCheckify() checkboxChanged: (e) -> checked = $(e.target).is(':checked') value = $(e.target).val() @setState({userSchedulingComm: value}) beforeHide: (e) -> #ProfileActions.viewTeacherProfileDone() @screenVisible = false return true beforeShow: (e) -> noSchoolCheck: (user) -> if user?.id? && @screenVisible if !user.owned_school_id? window.JK.Banner.showAlert("You are not the owner of a school in our systems. If you are, please contact support@jamkazam.com and we'll update your account.") return false else if !@shownOnce @shownOnce = true SchoolActions.refresh(user.owned_school_id) return true else return false afterShow: (e) -> @screenVisible = true logger.debug("AccountSchoolScreen: afterShow") logger.debug("after show", @state.user) @noSchoolCheck(@state.user) getInitialState: () -> { school: null, user: null, selected: 'account', userSchedulingComm: null, updateErrors: null, schoolName: null, studentInvitations: null, teacherInvitations: null, updating: false, distributions: [] } isSchoolManaged: () -> if this.state.userSchedulingComm? this.state.userSchedulingComm == 'school' else this.state.school.scheduling_communication == 'school' nameValue: () -> if this.state.schoolName? this.state.schoolName else this.state.school.name nameChanged: (e) -> $target = $(e.target) val = $target.val() @setState({schoolName: val}) onCancel: (e) -> e.preventDefault() context.location.href = '/client#/account' onUpdate: (e) -> e.preventDefault() if this.state.updating return name = @root.find('input[name="name"]').val() if @isSchoolManaged() scheduling_communication = 'school' else scheduling_communication = 'teacher' correspondence_email = @root.find('input[name="correspondence_email"]').val() @setState(updating: true) rest.updateSchool({ id: this.state.school.id, name: name, scheduling_communication: scheduling_communication, correspondence_email: correspondence_email }).done((response) => @onUpdateDone(response)).fail((jqXHR) => @onUpdateFail(jqXHR)) onUpdateDone: (response) -> @setState({school: response, userSchedulingComm: null, schoolName: null, updateErrors: null, updating: false}) @app.layout.notify({title: "update success", text: "Your school information has been successfully updated"}) onUpdateFail: (jqXHR) -> handled = false @setState({updating: false}) if jqXHR.status == 422 errors = JSON.parse(jqXHR.responseText) handled = true @setState({updateErrors: errors}) if !handled @app.ajaxError(jqXHR, null, null) inviteTeacher: () -> @app.layout.showDialog('invite-school-user', {d1: true}) inviteStudent: () -> @app.layout.showDialog('invite-school-user', {d1: false}) resendInvitation: (id, e) -> e.preventDefault() rest.resendSchoolInvitation({ id: this.state.school.id, invitation_id: id }).done((response) => @resendInvitationDone(response)).fail((jqXHR) => @resendInvitationFail(jqXHR)) resendInvitationDone: (response) -> @app.layout.notify({title: 'invitation resent', text: 'Invitation was resent to ' + response.email}) resendInvitationFail: (jqXHR) -> @app.ajaxError(jqXHR) deleteInvitation: (id, e) -> e.preventDefault() rest.deleteSchoolInvitation({ id: this.state.school.id, invitation_id: id }).done((response) => @deleteInvitationDone(id, response)).fail((jqXHR) => @deleteInvitationFail(jqXHR)) deleteInvitationDone: (id, response) -> context.SchoolActions.deleteInvitation(id) deleteInvitationFail: (jqXHR) -> @app.ajaxError(jqXHR) removeFromSchool: (id, isTeacher, e) -> if isTeacher rest.deleteSchoolTeacher({ id: this.state.school.id, teacher_id: id }).done((response) => @removeFromSchoolDone(response)).fail((jqXHR) => @removeFromSchoolFail(jqXHR)) else rest.deleteSchoolStudent({ id: this.state.school.id, student_id: id }).done((response) => @removeFromSchoolDone(response)).fail((jqXHR) => @removeFromSchoolFail(jqXHR)) removeFromSchoolDone: (school) -> context.JK.Banner.showNotice("User removed", "User was removed from your school.") context.SchoolActions.updateSchool(school) removeFromSchoolFail: (jqXHR) -> @app.ajaxError(jqXHR) renderUser: (user, isTeacher) -> photo_url = user.photo_url if !photo_url? photo_url = '/assets/shared/avatar_generic.png' mailto = "mailto:#{user.email}" `
{user.name} {user.email}
remove from school
` renderInvitation: (invitation) -> `
{invitation.first_name} {invitation.last_name}
has not yet accepted invitation
resend invitation delete
` renderTeachers: () -> teachers = [] if this.state.school.teachers? && this.state.school.teachers.length > 0 for teacher in this.state.school.teachers if teacher.user teachers.push(@renderUser(teacher.user, true)) else teachers = `

No teachers

` teachers renderStudents: () -> students = [] if this.state.school.students? && this.state.school.students.length > 0 for student in this.state.school.students students.push(@renderUser(student, false)) else students = `

No students

` students renderTeacherInvitations: () -> invitations = [] if this.state.teacherInvitations? && this.state.teacherInvitations.length > 0 for invitation in this.state.teacherInvitations invitations.push(@renderInvitation(invitation)) else invitations = `

No pending invitations

` invitations renderStudentInvitations: () -> invitations = [] if this.state.studentInvitations? && this.state.studentInvitations.length > 0 for invitation in this.state.studentInvitations invitations.push(@renderInvitation(invitation)) else invitations = `

No pending invitations

` invitations mainContent: () -> if !@state.user? || !@state.school? `
Loading...
` else if @state.selected == @TILE_ACCOUNT @account() else if @state.selected == @TILE_MEMBERS @members() else if @state.selected == @TILE_EARNINGS @earnings() else if @state.selected == @TILE_AGREEMENT @agreement() else @account() account: () -> ownerEmail = this.state.school.owner.email correspondenceEmail = this.state.school.correspondence_email correspondenceDisabled = !@isSchoolManaged() nameErrors = context.JK.reactSingleFieldErrors('name', @state.updateErrors) correspondenceEmailErrors = context.JK.reactSingleFieldErrors('correspondence_email', @state.updateErrors) nameClasses = classNames({name: true, error: nameErrors?, field: true}) correspondenceEmailClasses = classNames({ correspondence_email: true, error: correspondenceEmailErrors?, field: true }) cancelClasses = {"button-grey": true, "cancel": true, disabled: this.state.updating} updateClasses = {"button-orange": true, "update": true, disabled: this.state.updating} if this.state.school.education management = null else management = `

Management Preference

All emails relating to lesson scheduling will go to this email if school owner manages scheduling.
{correspondenceEmailErrors}
` `
{nameErrors}
{management}

Payments

CANCEL UPDATE
` members: () -> teachers = @renderTeachers() teacherInvitations = @renderTeacherInvitations() students = @renderStudents() studentInvitations = @renderStudentInvitations() `

teachers:

INVITE TEACHER
{teacherInvitations}
{teachers}

students:

INVITE STUDENT
{studentInvitations}
{students}
` earnings: () -> `

Coming soon

` paymentsToYou: () -> rows = [] for paymentHistory in this.state.distributions paymentMethod = 'Stripe' if paymentHistory.distributed date = paymentHistory.teacher_payment.teacher_payment_charge.last_billing_attempt_at status = 'Paid' else date = paymentHistory.created_at if paymentHistory.not_collectable status = 'Uncollectible' else if !paymentHistory.teacher?.teacher?.stripe_account_id? status = 'No Stripe Acct' else status = 'Collecting' date = context.JK.formatDate(date, true) description = paymentHistory.description if paymentHistory.teacher_payment? amt = paymentHistory.teacher_payment.real_distribution_in_cents else amt = paymentHistory.real_distribution_in_cents displayAmount = ' $' + (amt / 100).toFixed(2) amountClasses = {status: status} row = ` {date} {paymentMethod} {description} {status} {displayAmount} ` rows.push(row) `
{rows}
DATE METHOD DESCRIPTION STATUS AMOUNT
Next
No more payment history
BACK

` agreement: () -> `

The agreement between your music school and JamKazam is part of JamKazam's terms of service. You can find the complete terms of service here. And you can find the section that is most specific to the music school terms here.

` selectionMade: (selection, e) -> e.preventDefault() @setState({selected: selection}) createTileLink: (i, tile) -> active = this.state.selected == tile classes = classNames({last: i == @TILES.length - 1, activeTile: active}) return `
{tile}
` onCustomBack: (customBack, e) -> e.preventDefault() context.location = customBack render: () -> mainContent = @mainContent() profileSelections = [] for tile, i in @TILES profileSelections.push(@createTileLink(i, tile, profileSelections)) profileNav = `
{profileSelections}
` `
school:
{profileNav}
{mainContent}
` })