1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

implement submission for autofill firefox and chrome

This commit is contained in:
Tim Daubenschütz 2015-06-24 15:52:43 +02:00
parent ea88e87355
commit bf2a766e84
5 changed files with 47 additions and 29 deletions

View File

@ -69,7 +69,7 @@ gulp.task('js:build', function() {
bundle(false); bundle(false);
}); });
gulp.task('serve', ['browser-sync', 'run-server', 'lint:watch', 'sass:build', 'sass:watch', 'copy'], function() { gulp.task('serve', ['browser-sync', 'run-server', 'sass:build', 'sass:watch', 'copy'], function() {
bundle(true); bundle(true);
}); });

View File

@ -137,9 +137,12 @@ let Form = React.createClass({
}); });
}, },
render() { render() {
return ( return (
<form role="form" className="ascribe-form" onSubmit={this.submit} autoComplete="on"> <form
role="form"
className="ascribe-form"
onSubmit={this.submit}
autoComplete="on">
{this.getErrors()} {this.getErrors()}
{this.renderChildren()} {this.renderChildren()}
{this.getButtons()} {this.getButtons()}

View File

@ -118,7 +118,7 @@ var ReactS3FineUploader = React.createClass({
}, },
getCookie(name) { getCookie(name) {
console.log(document.cookie); //console.log(document);
let value = '; ' + document.cookie; let value = '; ' + document.cookie;
let parts = value.split('; ' + name + '='); let parts = value.split('; ' + name + '=');
if (parts.length === 2) { if (parts.length === 2) {
@ -126,31 +126,33 @@ var ReactS3FineUploader = React.createClass({
} }
}, },
requestKey(fileId) { requestKey(fileId) {
//console.log(this.getCookie('csrftoken'));
let filename = this.state.uploader.getName(fileId); let filename = this.state.uploader.getName(fileId);
let defer = new fineUploader.Promise(); return new Promise((resolve, reject) => {
fetch(this.props.keyRoutine.url, { fetch(this.props.keyRoutine.url, {
method: 'post', method: 'post',
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-CSRFToken': this.getCookie('csrftoken') 'X-CSRFToken': this.getCookie('csrftoken')
}, },
credentials: 'include', credentials: 'include',
body: JSON.stringify({ body: JSON.stringify({
'filename': filename, 'filename': filename,
'file_class': 'digitalwork' 'file_class': 'digitalwork'
})
}) })
}) .then((res) => {
.then((res) => { return res.json();
return res.json(); })
}) .then((res) =>{
.then((res) =>{ resolve(res.key);
defer.success(res.key); })
}) .catch((err) => {
.catch((err) => { console.error(err);
console.error(err); reject(err);
});
}); });
return defer;
}, },
/* FineUploader specific callback function handlers */ /* FineUploader specific callback function handlers */

View File

@ -37,16 +37,27 @@ let LoginForm = React.createClass({
handleSuccess(){ handleSuccess(){
let notification = new GlobalNotificationModel('Login successsful', 'success', 10000); let notification = new GlobalNotificationModel('Login successsful', 'success', 10000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
this.transitionTo('pieces');
/*Taken from http://stackoverflow.com/a/14916411 */
/*
We actually have to trick the Browser into showing the "save password" dialog
as Chrome expects the login page to be reloaded after the login.
Users on Stack Overflow claim this is a bug in chrome and should be fixed in the future.
Until then, we redirect the HARD way, but reloading the whole page using window.location
*/
window.location = '/collection';
}, },
render() { render() {
return ( return (
<Form <Form
ref="loginForm"
url={apiUrls.users_login} url={apiUrls.users_login}
handleSuccess={this.handleSuccess} handleSuccess={this.handleSuccess}
buttons={ buttons={
<button type="submit" className="btn ascribe-btn ascribe-btn-login"> <button
type="submit"
className="btn ascribe-btn ascribe-btn-login">
Log in to ascribe Log in to ascribe
</button>} </button>}
spinner={ spinner={
@ -61,6 +72,7 @@ let LoginForm = React.createClass({
type="email" type="email"
placeholder="Enter your email" placeholder="Enter your email"
autoComplete="on" autoComplete="on"
name="username"
required/> required/>
</Property> </Property>
<Property <Property
@ -70,6 +82,7 @@ let LoginForm = React.createClass({
type="password" type="password"
placeholder="Enter your password" placeholder="Enter your password"
autoComplete="on" autoComplete="on"
name="password"
required/> required/>
</Property> </Property>
<hr /> <hr />

View File

@ -40,7 +40,7 @@ let RegisterPiece = React.createClass( {
return data; return data;
}, },
handleChange(){ handleChange(){
this.setState({digital_work_key: this.refs.uploader.refs.fineuploader.state.filesToUpload[0].key}) this.setState({digital_work_key: this.refs.uploader.refs.fineuploader.state.filesToUpload[0].key});
}, },
render() { render() {