Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
584c89a3
Commit
584c89a3
authored
Nov 16, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
many small corrections to the validation + deactivate doors ajax temporarily
parent
711c1cab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
78 deletions
+96
-78
base_form.html
base_form.html
+4
-4
comex_merci_pour_les_infos.py.cgi
cgi-bin/comex_merci_pour_les_infos.py.cgi
+1
-1
table_specifications.md
doc/table_specifications.md
+2
-1
comex_reg_form_controllers.js
static/js/comex_reg_form_controllers.js
+89
-72
No files found.
base_form.html
View file @
584c89a3
...
@@ -83,7 +83,7 @@
...
@@ -83,7 +83,7 @@
<!-- ########################### ( FORM ) ########################## -->
<!-- ########################### ( FORM ) ########################## -->
<form
id=
"comex_reg_form"
enctype=
"multipart/form-data"
<form
id=
"comex_reg_form"
enctype=
"multipart/form-data"
method=
"post"
onsubmit=
"validateSubmit(
this,
event, 'from form', 'register')"
method=
"post"
onsubmit=
"validateSubmit(event, 'from form', 'register')"
action=
"cgi-bin/comex_merci_pour_les_infos.py.cgi"
>
action=
"cgi-bin/comex_merci_pour_les_infos.py.cgi"
>
<!-- todo onsubmit also save to cache -->
<!-- todo onsubmit also save to cache -->
...
@@ -374,7 +374,7 @@
...
@@ -374,7 +374,7 @@
<!-- button instead of input.submit to validate before real submit action -->
<!-- button instead of input.submit to validate before real submit action -->
<button
class=
"btn btn-lg btn-success"
style=
"float:right"
<button
class=
"btn btn-lg btn-success"
style=
"float:right"
id=
"formsubmit"
id=
"formsubmit"
onclick=
"validateSubmit(
this.parent,
event, 'from main submit button', 'register')"
>
onclick=
"validateSubmit(event, 'from main submit button', 'register')"
>
Submit your form
Submit your form
</button>
</button>
...
@@ -385,10 +385,10 @@
...
@@ -385,10 +385,10 @@
<!-- FOR DEBUG: test go-between with Doors -->
<!-- FOR DEBUG: test go-between with Doors -->
<!-- <p>
<!-- <p>
<button onclick='validateSubmit(
this,
event, "from button", "login")'>
<button onclick='validateSubmit(event, "from button", "login")'>
test doors login
test doors login
</button>
</button>
<button onclick='validateSubmit(
this,
event, "from button", "register")'>
<button onclick='validateSubmit(event, "from button", "register")'>
test doors register
test doors register
</button>
</button>
</p> -->
</p> -->
...
...
cgi-bin/comex_merci_pour_les_infos.py.cgi
View file @
584c89a3
...
@@ -42,7 +42,7 @@ templating_env = Environment(loader = FileSystemLoader('../templates'),
...
@@ -42,7 +42,7 @@ templating_env = Environment(loader = FileSystemLoader('../templates'),
# all columns as they are declared in form & DB as tuple:
# all columns as they are declared in form & DB as tuple:
# NAME, NOT NULL, N or MAXCHARS (if applicable)
# NAME, NOT NULL, N or MAXCHARS (if applicable)
COLS
=
[
(
"doors_uid"
,
True
,
36
),
COLS
=
[
(
"doors_uid"
,
True
,
36
),
(
"last_modified_date"
,
True
,
10
),
# 2016-11-16
(
"last_modified_date"
,
True
,
24
),
# ex 2016-11-16T17:47:07.308Z
(
"email"
,
True
,
255
),
(
"email"
,
True
,
255
),
(
"initials"
,
True
,
7
),
(
"initials"
,
True
,
7
),
(
"country"
,
True
,
60
),
(
"country"
,
True
,
60
),
...
...
doc/table_specifications.md
View file @
584c89a3
...
@@ -17,7 +17,8 @@ create table test_table (
...
@@ -17,7 +17,8 @@ create table test_table (
-- ########################
-- ########################
create table comex_registrations (
create table comex_registrations (
doors_uid char(36) not null unique,
doors_uid char(36) not null unique,
last_modified_date char(10) not null,
-- ISO stamp like 2016-11-16T17:47:07.308Z
last_modified_date char(24) not null,
email varchar(255) not null unique primary key,
email varchar(255) not null unique primary key,
initials varchar(7) not null,
initials varchar(7) not null,
country varchar(60) not null,
country varchar(60) not null,
...
...
static/js/comex_reg_form_controllers.js
View file @
584c89a3
// the target columns in DB: tuple (name, mandatoryBool, maxChars (or nChars))
// the target columns in DB: tuple (name, mandatoryBool, maxChars (or nChars))
var
COLS
=
[
[
"doors_uid"
,
tru
e
,
36
,
'exact'
],
var
COLS
=
[
[
"doors_uid"
,
fals
e
,
36
,
'exact'
],
[
"last_modified_date"
,
true
,
10
,
'exact'
],
[
"last_modified_date"
,
true
,
24
,
'exact'
],
[
"email"
,
true
,
255
],
[
"email"
,
true
,
255
],
[
"initials"
,
true
,
7
],
[
"initials"
,
true
,
7
],
[
"country"
,
true
,
60
],
[
"country"
,
true
,
60
],
...
@@ -21,6 +21,7 @@ var COLS = [ ["doors_uid", true, 36, 'exact'],
...
@@ -21,6 +21,7 @@ var COLS = [ ["doors_uid", true, 36, 'exact'],
// vars that will be used during the interaction
// vars that will be used during the interaction
// NB other vars defined in main scope but just before their respective funs
// NB other vars defined in main scope but just before their respective funs
var
wholeFormData
var
theForm
=
document
.
getElementById
(
'comex_reg_form'
)
var
theForm
=
document
.
getElementById
(
'comex_reg_form'
)
var
regTimestamp
=
document
.
getElementById
(
'last_modified_date'
)
var
regTimestamp
=
document
.
getElementById
(
'last_modified_date'
)
...
@@ -54,21 +55,36 @@ var passStatus = false
...
@@ -54,21 +55,36 @@ var passStatus = false
var
emailStatus
=
false
var
emailStatus
=
false
var
captchaStatus
=
false
var
captchaStatus
=
false
submitButton
.
disabled
=
true
submitButton
.
disabled
=
true
theForm
.
onkeyup
=
function
()
{
theForm
.
onkeyup
=
beTestedAsYouGo
// done when anything in the form changes
function
beTestedAsYouGo
()
{
if
(
passStatus
&&
emailStatus
&&
captchaStatus
)
{
if
(
passStatus
&&
emailStatus
&&
captchaStatus
)
{
submitButton
.
disabled
=
false
submitButton
.
disabled
=
false
}
}
else
{
else
{
submitButton
.
disabled
=
true
submitButton
.
disabled
=
true
}
}
var
now
=
new
Date
()
regTimestamp
.
value
=
now
.
toISOString
()
}
function
makePseudoDoorsUid
()
{
var
rando
=
""
var
possible
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
;
for
(
var
i
=
0
;
i
<
36
;
i
++
)
rando
+=
possible
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
possible
.
length
));
return
rando
}
}
// validate more precisely at the end
// validate more precisely at the end
function
validateSubmit
(
form
,
e
,
orignStr
,
loginOrRegister
)
{
function
validateSubmit
(
e
,
orignStr
,
loginOrRegister
)
{
e
.
preventDefault
()
e
.
preventDefault
()
var
valid
=
fals
e
var
valid
=
tru
e
var
doorsUid
=
null
var
doorsUid
=
null
var
doorsErr
=
null
var
doorsErr
=
null
...
@@ -77,7 +93,8 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
...
@@ -77,7 +93,8 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
mainMessage
.
style
.
display
=
'block'
mainMessage
.
style
.
display
=
'block'
mainMessage
.
innerHTML
=
"Validating the form..."
mainMessage
.
innerHTML
=
"Validating the form..."
console
.
log
(
"form"
,
form
)
console
.
log
(
"form"
,
theForm
)
console
.
log
(
"event"
,
e
)
// 2) transmit registration to doors
// 2) transmit registration to doors
console
.
warn
(
"=====> CORS <====="
)
console
.
warn
(
"=====> CORS <====="
)
...
@@ -91,57 +108,62 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
...
@@ -91,57 +108,62 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
}
}
// objectify
// objectify
wholeFormData
=
new
FormData
(
form
);
wholeFormData
=
new
FormData
(
theForm
);
//
$
.
ajax
({
// $.ajax({
contentType
:
"application/json"
,
// contentType: "application/json",
dataType
:
'json'
,
// dataType: 'json',
url
:
"http://localhost:8989/api/"
+
action
,
// url: "http://localhost:8989/api/" + action,
data
:
JSON
.
stringify
({
// data: JSON.stringify({
// TODO pass the real values
// // these values from the form have been checked by beTestedAsYouGo
"login"
:
"jpp@om.fr"
,
// "login": wholeFormData.get("email"),
"password"
:
"droitaubut"
,
// "password": wholeFormData.get("password"),
"name"
:
"JPP"
// "name": wholeFormData.get("initials")
}),
// }),
type
:
'POST'
,
// type: 'POST',
success
:
function
(
data
)
{
// success: function(data) {
console
.
log
(
"doors ajax success"
)
// // console.log("doors ajax success")
console
.
log
(
"response data"
,
data
)
// // console.log("response data", data)
//
// EXPECTED DOORS ANSWER
// // EXPECTED DOORS ANSWER
// {
// // {
// "status": "login ok",
// // "status": "login ok",
// "userInfo": {
// // "userInfo": {
// "id": {
// // "id": {
// "id": "78407900-6f48-44b8-ab37-503901f85458"
// // "id": "78407900-6f48-44b8-ab37-503901f85458"
// },
// // },
// "password": "68d23eab21abab38542184e8fca2199d",
// // "password": "68d23eab21abab38542184e8fca2199d",
// "name": "JPP",
// // "name": "JPP",
// "hashAlgorithm": "PBKDF2",
// // "hashAlgorithm": "PBKDF2",
// "hashParameters": {"iterations" : 1000, "keyLength" : 128}
// // "hashParameters": {"iterations" : 1000, "keyLength" : 128}
// }
// // }
// }
// // }
//
doorsUid
=
data
.
userInfo
.
id
.
id
// doorsUid = data.userInfo.id.id
setTimeout
(
// setTimeout(
function
()
{
// function() {
location
.
reload
();
// location.reload();
},
5000
);
// }, 5000);
},
// },
error
:
function
(
result
)
{
// error: function(result) {
console
.
log
(
"doors ajax err"
,
result
);
// // console.log("doors ajax err", result);
doorsErr
=
result
.
statusText
// doorsErr = result.statusText
//
// TESTS: no need to invalidate the form until doors server ready
// // TESTS: no need to invalidate the form until doors server ready
// valid = false
// // valid = false
}
// }
});
// });
// here entire validation
doorsUid
=
makePseudoDoorsUid
()
// 3) fill in the answer we got
wholeFormData
.
set
(
"doors_uid"
,
doorsUid
)
// 4) here entire validation
var
missingFields
=
[]
var
missingFields
=
[]
var
toolongFields
=
[]
var
toolongFields
=
[]
for
(
var
i
in
COLS
)
{
for
(
var
i
in
COLS
)
{
console
.
warn
(
"checking COLS["
+
i
+
"]"
,
COLS
[
i
])
//
console.warn("checking COLS["+i+"]", COLS[i])
var
fieldName
=
COLS
[
i
][
0
]
var
fieldName
=
COLS
[
i
][
0
]
var
mandatory
=
COLS
[
i
][
1
]
var
mandatory
=
COLS
[
i
][
1
]
var
nChars
=
COLS
[
i
][
2
]
var
nChars
=
COLS
[
i
][
2
]
...
@@ -153,11 +175,14 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
...
@@ -153,11 +175,14 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
var
actualValue
=
wholeFormData
.
get
(
fieldName
)
var
actualValue
=
wholeFormData
.
get
(
fieldName
)
// console.log("actualValue", actualValue)
// test mandatory -----------------
// test mandatory -----------------
if
(
mandatory
&&
actualValue
==
null
)
{
if
(
mandatory
&&
actualValue
==
null
&&
actualValue
!=
""
)
{
// todo human-readable fieldName here
// todo human-readable fieldName here
missingFields
.
push
(
fieldName
)
missingFields
.
push
(
fieldName
)
valid
=
false
valid
=
false
console
.
log
(
"missingField"
,
fieldName
)
}
}
// test length --------------------
// test length --------------------
...
@@ -170,22 +195,28 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
...
@@ -170,22 +195,28 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
+
"("
+
actualValue
+
")"
+
"("
+
actualValue
+
")"
+
"should have exactly "
+
nChars
+
" chars"
)
+
"should have exactly "
+
nChars
+
" chars"
)
valid
=
false
valid
=
false
console
.
log
(
"wrong value"
)
}
}
}
}
else
{
else
{
if
(
actualValue
.
length
>
nChars
)
{
if
(
actualValue
.
length
>
nChars
)
{
toolongFields
.
push
([
fieldName
,
nChars
])
toolongFields
.
push
([
fieldName
,
nChars
])
valid
=
false
valid
=
false
console
.
log
(
"tooShort"
)
}
}
}
}
}
}
// --------------------------------
// --------------------------------
}
// end for val in COLS
}
// end for val in COLS
// 5) RESULTS
if
(
valid
)
{
if
(
valid
)
{
mainMessage
.
innerHTML
=
"Form is valid... Submitting..."
mainMessage
.
innerHTML
=
"Form is valid... Submitting..."
mainMessage
.
style
.
display
=
'block'
mainMessage
.
style
.
display
=
'block'
// f
orm.submit()
theF
orm
.
submit
()
return
true
return
true
}
}
else
{
else
{
...
@@ -198,16 +229,7 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
...
@@ -198,16 +229,7 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
var
errorMessage
=
""
var
errorMessage
=
""
// TESTS: restore after we get doors server ================================
// TESTS: restore after we get doors server ================================
// generate a pseudo doors ID during the tests
// for now we generated a pseudo doors ID above
if
(
!
doorsUid
)
{
var
doorsUid
=
""
;
var
possible
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ
\
abcdefghijklmnopqrstuvwxyz
\
0123456789"
;
for
(
var
i
=
0
;
i
<
36
;
i
++
)
text
+=
possible
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
possible
.
length
));
}
// if (!doorsUid) {
// if (!doorsUid) {
// // todo retrieve more info than statusText
// // todo retrieve more info than statusText
// errorMessage += "<br/>The email/password registration had an error ("+doorsErr+"), "
// errorMessage += "<br/>The email/password registration had an error ("+doorsErr+"), "
...
@@ -232,11 +254,6 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
...
@@ -232,11 +254,6 @@ function validateSubmit(form, e, orignStr, loginOrRegister) {
}
}
// done when anything in the form changes
function
testYourself
()
{
var
now
=
new
Date
()
regTimestamp
.
value
=
now
.
toISOString
()
}
var
picMsg
=
document
.
getElementById
(
'picture_message'
)
var
picMsg
=
document
.
getElementById
(
'picture_message'
)
function
testPictureBlob
(
fileInput
)
{
function
testPictureBlob
(
fileInput
)
{
...
@@ -415,7 +432,7 @@ $(function() {
...
@@ -415,7 +432,7 @@ $(function() {
// autocomplete position
// autocomplete position
$
(
function
()
{
$
(
function
()
{
var
$jobtitlesInput
=
$
(
'#
hon_
title'
)
var
$jobtitlesInput
=
$
(
'#
job
title'
)
var
jobtitlesList
=
[
"Student"
,
"Engineer"
,
"capetown"
,
var
jobtitlesList
=
[
"Student"
,
"Engineer"
,
"capetown"
,
"PhD Student"
,
"Dr"
,
"Post-Doc"
,
"PhD Student"
,
"Dr"
,
"Post-Doc"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment