Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions client/app/settings/pages/accountInfo/accountInfo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,13 @@ Template['settings_page_accountInfo'].events
'submit form': (event) ->
event.preventDefault()

firstName = Helpers.nameCap $('#firstNameInput').val()
lastName = Helpers.nameCap $('#lastNameInput').val()

oldPass = $('#currentPassInput').val()

mail = $('#mailInput').val().toLowerCase()

newPass = $('#newPassInput').val()
newPassRepeat = $('#newPassRepeatInput').val()

nameChanged = (
profile = getUserField Meteor.userId(), 'profile'
profile.firstName isnt firstName or profile.lastName isnt lastName
)

mailChanged = mail isnt getUserField Meteor.userId(), 'emails[0].address'
passChanged = newPass isnt '' or newPassRepeat isnt ''
needsPass = mailChanged or passChanged
Expand Down Expand Up @@ -61,9 +53,6 @@ Template['settings_page_accountInfo'].events
else
callback not e?

if nameChanged
Meteor.call 'changeName', firstName, lastName, (e) -> callback not e?

if passChanged
unless newPass is newPassRepeat
setFieldError (
Expand Down
8 changes: 0 additions & 8 deletions client/app/settings/pages/accountInfo/accountInfo.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<template name="settings_page_accountInfo">
<div id="accountInfoSettings">
<form class="vertical full-width">
<div id="firstNameGroup" class="group">
<label for="firstNameInput">Voornaam</label>
<input type="text" id="firstNameInput" placeholder="Henk" value="{{currentUser.profile.firstName}}">
</div>
<div id="lastNameGroup" class="group">
<label for="lastNameInput">Achternaam</label>
<input type="text" id="lastNameInput" placeholder="Jansen" value="{{currentUser.profile.lastName}}">
</div>
<div id="currentPassGroup" class="group">
<label for="currentPassInput">Huidig wachtwoord</label>
<input type="password" id="currentPassInput" placeholder="●●●●●●●●●●">
Expand Down
72 changes: 34 additions & 38 deletions client/app/setup/setup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SReactiveVar = require('meteor/simply:strict-reactive-var').default

currentSelectedImage = new SReactiveVar Number, 0
currentSelectedCourseInfo = new SReactiveVar Number, 0
currentSelectedName = new SReactiveVar Number, 0

weekdays = new SReactiveVar [Object]

Expand All @@ -15,6 +16,10 @@ schoolEngineSub = null

setup = undefined

anyServiceLoggedIn = ->
services = externalServices.get()
_.some services, (s) -> s.loginNeeded and s.profileData()?

# TODO: These methods are not really DRY, even overall ugly.
pictures = ->
current = currentSelectedImage.get()
Expand Down Expand Up @@ -50,10 +55,21 @@ courseInfos = ->
.value()

names = ->
for service in externalServices.get()
val = service.profileData()?.nameInfo
return val if val?
undefined
current = currentSelectedName.get()

_(externalServices.get())
.map (s) -> s.profileData()?.nameInfo
.reject _.isEmpty
.uniq (info) -> "#{info.firstName} #{info.lastName}"
.map (c, i) ->
isSelected: ->
if current is i
'selected'
else
''
value: c
index: i
.value()

addProgress = (item, cb) ->
ga 'send', 'event', 'setup', 'progress', item
Expand Down Expand Up @@ -84,32 +100,7 @@ class @Setup
.map (s) -> s.profileData()?.schoolId
.find _.negate _.isUndefined

done = (success) ->
if success?
addProgress 'externalServices', -> cb yes
else
cb no

loginServices = _.filter externalServices.get(), 'loginNeeded'
data = _.filter loginServices, (s) -> s.profileData()?
if loginServices.length > 0 and data.length is 0
alertModal(
'Hé!'
'''
Je hebt je op geen enkele site ingelogd!
Hierdoor zal simplyHomework niet automagisch data van sites voor je kunnen ophalen.
Als je later toch een site wilt toevoegen kan dat altijd in je instellingen.

Weet je zeker dat je door wilt gaan?
'''
DialogButtons.OkCancel
{ main: 'doorgaan', second: 'woops' }
{ main: 'btn-danger' }
main: -> done yes
second: -> done no
)
else
done yes
addProgress 'externalServices', -> cb yes
}

{
Expand All @@ -118,11 +109,9 @@ class @Setup
onDone: (cb) ->
schoolQuery = $('#setup #schoolInput').val()

$firstNameInput = $ '#setup #firstNameInput'
$lastNameInput = $ '#setup #lastNameInput'
any = no
any = yes if empty($firstNameInput, '#firstNameGroup', 'Voornaam is leeg')
any = yes if empty($lastNameInput, '#lastNameGroup', 'Achternaam is leeg')

name = names()[currentSelectedName.get()]?.value

courseInfo = courseInfos()[currentSelectedCourseInfo.get()]?.value
unless courseInfo?
Expand Down Expand Up @@ -159,8 +148,8 @@ class @Setup
fetchedBy: val.fetchedBy
)
'profile.courseInfo': courseInfo
'profile.firstName': Helpers.nameCap $firstNameInput.val()
'profile.lastName': Helpers.nameCap $lastNameInput.val()
'profile.firstName': name.firstName
'profile.lastName': name.lastName
'profile.birthDate':
# Picks the date from the first externalService that has one.
# REVIEW: Maybe we should ask the user too?
Expand Down Expand Up @@ -340,16 +329,20 @@ Template.setup.onRendered ->

Template.setupFooter.helpers
isLast: -> _.every setup?.running, 'done'
showButton: ->
current = setup?.current()
current?.name isnt 'externalServices' or anyServiceLoggedIn()

Template.setupFooter.events
'click button': -> setup.finishStep()

# === step template stuff

Template['setup-extractInfo'].helpers
pictures: pictures
hasSchool: -> schoolId?
courseInfos: courseInfos
firstName: -> names()?.firstName
lastName: -> names()?.lastName
names: names

Template['setup-extractInfo'].events
'click #pictureSelector > img': (event) ->
Expand All @@ -358,6 +351,9 @@ Template['setup-extractInfo'].events
'click #courseInfoSelector > div': (event) ->
currentSelectedCourseInfo.set @index

'click #nameSelector > div': (event) ->
currentSelectedName.set @index

Template['setup-extractInfo'].onRendered ->
unless schoolId?
engine = new Bloodhound
Expand Down
36 changes: 19 additions & 17 deletions client/app/setup/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@

<template name="setupFooter">
<div class="footer">
<button class="btn btn-primary">
{{#if isLast}}
afronden
{{else}}
verder
{{/if}}
</button>
{{! TODO: back button}}

{{#if showButton}}
<button class="btn btn-primary">
{{#if isLast}}
afronden
{{else}}
verder
{{/if}}
</button>
{{/if}}
</div>
</template>

Expand Down Expand Up @@ -118,17 +122,15 @@ <h2>Profielinfo</h2>
<hr>

<h2>Naam</h2>
<form class="vertical full-width">
<div id="firstNameGroup" class="group">
<label for="firstNameInput">Voornaam</label>
<input type="text" id="firstNameInput" value="{{firstName}}"/>
</div>
<div id="lastNameGroup" class="group">
<label for="lastNameInput">Achternaam</label>
<input type="text" id="lastNameInput" value="{{lastName}}"/>
{{#with names}}
<div id="nameSelector" class="selector">
{{#each this}}
<div class="{{isSelected}}">
{{value.firstName}} {{value.lastName}}
</div>
{{/each}}
</div>
</form>

{{/with}}
</div>
</template>

Expand Down
20 changes: 0 additions & 20 deletions lib/methods.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,6 @@ Meteor.methods
$set: isRead: yes
}

###*
# @method changeName
# @param {String} firstName non empty string.
# @param {String} lastName non empty string.
###
changeName: (firstName, lastName) ->
check firstName, String
check lastName, String

firstName = Helpers.nameCap firstName.trim()
lastName = Helpers.nameCap lastName.trim()

if firstName.length is 0 or lastName.length is 0
throw new Meteor.Error 'name-empty'

Meteor.users.update @userId,
$set:
'profile.firstName': firstName
'profile.lastName': lastName

###*
# @method saveMessageDraft
# @param {Draft} draft
Expand Down