Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for candidates #121

Merged
merged 1 commit into from
Oct 21, 2015
Merged
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
91 changes: 55 additions & 36 deletions app/elements/candidates/invite-candidate-input.html
Original file line number Diff line number Diff line change
@@ -1,68 +1,82 @@
<link rel="import" href="/bower_components/paper-input/all-imports.html">
<link rel="import" href="/bower_components/paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="/bower_components/paper-menu/paper-menu.html">
<link rel="import" href="/bower_components/paper-item/paper-item.html">

<dom-module id="invite-candidate-input">
<style>
:host {
display: block;
}

#inputContainer {
display: table;
#address {
width: 325px;
}

#inputContainer paper-input {
display: table-cell;
width: 300px;
#challenges {
width: 200px;
margin-left: 15px;
}

#inputContainer select {
display: table-cell;
position: relative;
bottom: -27px;
margin-left: 20px;
option {
width: 200px;
}

#inputContainer p {
display: table-cell;
paper-menu {
background-color: white;
}
#challenge {
max-width: 200px;
overflow: hidden;
position: relative;
bottom: -29px;
padding-left: 10px;
padding-right: 10px;
bottom: -25px;
margin-left: 15px;
}

#inputContainer iron-icon {
display: table-cell;
iron-icon {
position: relative;
bottom: -15px;
margin-left: 25px;
bottom: -5px;
margin-left: 15px;
cursor: pointer;
}
</style>
<template>
<div id="inputContainer">
<paper-input id="address" label="Address" value="{{candidate.Address}}"></paper-input>
<div class="horizontal layout">
<paper-input
class="self-center"
id="address"
label="Firstname Lastname <person@example.com>"
value="{{candidate.Address}}"
pattern="^.*<[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])?>$"
error-message="Address should match the example above"
required></paper-input>
<template is="dom-if" if="{{isSingleChallenge}}">
<p>{{challenges.0.Name}}</p>
<p id="challenge">{{challenges.0.Name}}</p>
</template>
<template is="dom-if" if="{{!isSingleChallenge}}">
<select id="challenges" on-change="_setChallenge">
<option selected disabled>Please select a challenge</option>
<template is="dom-repeat" items="{{challenges}}">
<option value="{{item.Key}}">{{item.Name}}</option>
</template>
</select>
<paper-dropdown-menu class="self-center" id="challenges" label="Challenge" selected-item="{{selectedChallenge}}" required>
<paper-menu class="dropdown-content">
<template is="dom-repeat" items="{{challenges}}">
<option value="{{item.Key}}">{{item.Name}}</option><br>
</template>
</paper-menu>
</paper-dropdown-menu>
</template>
<iron-icon icon="remove" on-click="_removeItem"></iron-icon>
<iron-icon class="self-center" icon="remove" on-click="_removeItem"></iron-icon>
</div>
<br>
</template>
<script>
Polymer({
is: 'invite-candidate-input',
behaviors: [
Polymer.IronFormElementBehavior,
Polymer.IronValidatableBehavior
],
properties: {
challenges: {
type: Array
},
selectedChallenge: {
type: Object,
notify: true,
observer: '_selectedChallengeChanged'
},
candidate: {
type: Object,
reflectToAttribute: true,
Expand All @@ -73,11 +87,16 @@
computed: '_isSingleChallenge(challenges)'
}
},
validate: function(){
return this.$.address.validate() && this.$$('#challenges').validate();
},
_isSingleChallenge: function(challenges){
return challenges.length === 1;
},
_setChallenge: function () {
this.candidate.Challenge = this.$$('#challenges').options[this.$$('#challenges').selectedIndex].value;
_selectedChallengeChanged: function () {
if (!!this.selectedChallenge){
this.candidate.Challenge = this.selectedChallenge.value;
}
},
_removeItem: function () {
this.fire('candidate-removed', this.candidate);
Expand Down
22 changes: 11 additions & 11 deletions app/elements/candidates/invite-candidates.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}

#addCandidate {
margin-top: 10px;
cursor: pointer;
}

Expand All @@ -33,15 +34,15 @@ <h2>Invite candidates</h2>

<form is="iron-form" id="form">
<template is="dom-repeat" items="{{candidates}}">
<invite-candidate-input challenges="{{challenges}}" candidate="{{item}}"></invite-candidate-input>
<invite-candidate-input name="inviteCandidateInput" challenges="{{challenges}}" candidate="{{item}}" required></invite-candidate-input>
</template>
<div id="addCandidate" on-click="_addCandidate">
<iron-icon icon="add"></iron-icon>
<span>Add another candidate</span>
</div>
<div class="buttonGroup">
<paper-button class="primary" dialog-dismiss>Cancel</paper-button>
<paper-button class="primary" raised on-click="inviteCandidates" dialog-confirm>Invite
<paper-button class="primary" raised on-click="inviteCandidates">Invite
</paper-button>
</div>
</form>
Expand Down Expand Up @@ -72,17 +73,16 @@ <h2>Invite candidates</h2>
this.$.dialog.toggle();
},
inviteCandidates: function () {
if (!this.$.form.validate()){
return;
}
for (var i = 0; i < this.candidates.length; i++) {
var candidate = this.candidates[i];
if (candidate.Address === '' || candidate.Challenge === undefined) {
return;
}
var toInvite = {
'Address': candidate.Address,
'Challenge': candidate.Challenge
};
this.$.userService.invite(toInvite);
this.$.userService.invite({
'Address': this.candidates[i].Address,
'Challenge': this.candidates[i].Challenge
});
}
this.$.dialog.close();
},
_addCandidate: function () {
if (this.challenges.length === 1) {
Expand Down