forked from maccman/monocle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request maccman#1 from jclay/change_password
Adding in change password functionality
- Loading branch information
Showing
10 changed files
with
202 additions
and
42 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
app/assets/javascripts/app/controllers/alert.module.coffee
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
$ = jQuery | ||
Overlay = require('app/controllers/overlay') | ||
|
||
class Alert extends Overlay | ||
className: 'alert' | ||
|
||
constructor: (options = {}) -> | ||
super() | ||
@on('click', '#dismiss', @close) | ||
console.log(options.title) | ||
@title = options.title | ||
@message = options.message | ||
|
||
@render() | ||
@open() | ||
|
||
render: => | ||
@html(@view('alert')(this)) | ||
@$('[data-name=title]').html(@title) | ||
@$('[data-name=message]').html(@message) | ||
|
||
module.exports = Alert |
This file contains 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
58 changes: 58 additions & 0 deletions
58
app/assets/javascripts/app/controllers/users/change_password.module.coffee
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
$ = jQuery | ||
Overlay = require('app/controllers/overlay') | ||
User = require('app/models/user') | ||
State = require('app/state') | ||
Alert = require('app/controllers/alert') | ||
|
||
class ChangePassword extends Overlay | ||
className: 'users-change-password' | ||
|
||
constructor: (@user) -> | ||
super() | ||
@on 'submit', @submit | ||
@render() | ||
|
||
render: => | ||
# @user = State.get('user') | ||
|
||
@html(@view('users/change_password')(this)) | ||
@$form = @$('form') | ||
@$errors = @$('#errors') | ||
|
||
@$current_password = @$('input#current_password') | ||
@$new_password = @$('input#new_password') | ||
@$confirm_new_password = @$('input#confirm_new_password') | ||
|
||
clearErrors: => | ||
@$errors.children("ul").html("") | ||
|
||
addErrors: (errors) => | ||
@$errors.children("ul").html("") | ||
for error in errors | ||
@$errors.children("ul").append("<li>" + error + "</li>") | ||
|
||
clearValues: => | ||
@$current_password.val("") | ||
@$new_password.val("") | ||
@$confirm_new_password.val("") | ||
|
||
submit: (e) => | ||
e.preventDefault() | ||
|
||
response = @user.change_password(@$current_password.val(), | ||
@$new_password.val(), | ||
@$confirm_new_password.val()) | ||
|
||
|
||
response.done (data, textStatus, jqXHR) => | ||
@close() | ||
new Alert( title: "Success!", message: data) | ||
|
||
response.fail (jqXHR, textStatus, errorThrown) => | ||
@clearValues() | ||
errors = JSON.parse(jqXHR.responseText) | ||
@$errors.show() | ||
@clearErrors() | ||
@addErrors(errors) | ||
|
||
module.exports = ChangePassword |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<header> | ||
<h2 data-name="title"></h2> | ||
</header> | ||
|
||
<article> | ||
<p data-name="message"></p> | ||
</article> | ||
|
||
<footer> | ||
<button id="dismiss" class="btn">Ok</button> | ||
</footer> |
This file contains 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
35 changes: 35 additions & 0 deletions
35
app/assets/javascripts/app/views/users/change_password.jst.eco
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<header> | ||
<h2>Change Password</h2> | ||
</header> | ||
|
||
<div id="errors" class="hidden"> | ||
<h4>Uh-oh! Some errors occured</h4> | ||
<ul></ul> | ||
</div> | ||
|
||
<form> | ||
|
||
<article> | ||
<input id="current_password" | ||
type="password" | ||
name="current_password" | ||
placeholder="Current Password" | ||
autofocus> | ||
|
||
<input id="new_password" | ||
type="password" | ||
name="new_password" | ||
placeholder="New Password"> | ||
|
||
<input id="confirm_new_password" | ||
type="password" | ||
name="confirm_new_password" | ||
placeholder="Confirm New Password"> | ||
</article> | ||
|
||
<footer> | ||
<button type="submit" class="btn">Change</button> | ||
</footer> | ||
|
||
</form> | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.overlay .panel.users-change-password { | ||
width: 350px | ||
|
||
article { | ||
margin: 30px 30px 20px 30px | ||
} | ||
|
||
input { | ||
margin-bottom: 10px | ||
height: 38px | ||
padding: 0 10px | ||
|
||
&:last-child { | ||
margin-bottom: 0 | ||
} | ||
} | ||
|
||
footer { | ||
margin: 0 30px 25px 30px | ||
display: block; | ||
} | ||
|
||
.divider { | ||
text-align:center; | ||
font-weight: 200; | ||
} | ||
|
||
button { | ||
width: 100% | ||
height: 34px | ||
padding: 0 14px | ||
font-size: 14px | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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