Commit a276445e authored by Gabriel Monnerat's avatar Gabriel Monnerat

- refactor javascript code to display the form message.

- improve test

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43956 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8b702ce5
......@@ -55,6 +55,10 @@
form = context.REQUEST.form\n
portal = context.getPortalObject()\n
\n
if len(portal.portal_catalog(portal_type="Person",\n
reference=form.get("login_name"))):\n
return json.dumps(None)\n
\n
person = portal.person_module.newContent(portal_type="Person")\n
person.edit(first_name=form.get("firstname"),\n
last_name=form.get("lastname"),\n
......
......@@ -36,6 +36,9 @@
<key> <string>_text</string> </key>
<value> <unicode encoding="cdata"><![CDATA[
<div id="advertisement">\n
<h2>Welcome to UNG Web Office</h2>\n
</div>\n
<div id="login-box">\n
<table id="field_table">\n
<tbody>\n
......@@ -80,6 +83,8 @@
<td>\n
<form id="create-user" method="post">\n
<table width="100%">\n
<tr><td align="center" colspan="2"><b>Create an account</b></td></tr>\n
<tr><td id="form-message" align="center" colspan="2"></td></tr>\n
<tr><td>First name:</td><td><input type="text" name="firstname"/></td></tr>\n
<tr><td>Last name:</td><td><input type="text" name="lastname"/></td></tr>\n
<tr><td>Email:</td><td><input type="text" name="email"/></td></tr>\n
......
......@@ -109,7 +109,7 @@ function waitCreateUNGUser(paramStr){\n
data = jQuery.parseJSON(data);\n
if (data.response == true){\n
clearTimeout();\n
setTimeout(window.location.reload(), 2000);\n
window.location.reload();\n
}\n
else {\n
setTimeout(waitCreateUNGUser(paramStr), 2000);\n
......@@ -117,6 +117,11 @@ function waitCreateUNGUser(paramStr){\n
});\n
}\n
\n
function displayFormMessage(message){\n
$("td#form-message").text(message);\n
$("td#form-message").fadeIn(300).delay(800).fadeOut(3000);\n
}\n
\n
function displayLoginForm(){ \n
$("a.ung_docs, img[alt=\'calendar_logo_box\'], table#create-new-user, img[alt=\'mail_logo_box\']").hide();\n
$("div.header-left div.field input, div.main-right, div.main-left").hide();\n
......@@ -137,8 +142,7 @@ function displayLoginForm(){ \n
formHash[paramList[i].name] = paramList[i].value;\n
}\n
if (formHash.password != formHash.confirm){\n
$("td#form-message").text("Please confirm your password correctly..");\n
$("td#form-message").fadeIn(300).delay(800).fadeOut(1000);\n
displayFormMessage("Please confirm your password correctly..");\n
return false;\n
}\n
$.ajax({\n
......@@ -146,10 +150,18 @@ function displayLoginForm(){ \n
url: \'ERPSite_createUNGUser\',\n
data: $("form#create-user").serializeArray(),\n
dataType: "json",\n
});\n
var paramStr = "first_name=" + formHash.firstname +\n
success: function(data){\n
if (jQuery.parseJSON(data) == null){\n
displayFormMessage(formHash.login_name + " is not available, please try another...");\n
return false;\n
}\n
else {\n
var paramStr = "first_name=" + formHash.firstname +\n
"&" + "last_name=" + formHash.lastname;\n
setTimeout(waitCreateUNGUser(paramStr), 2000);\n
setTimeout(waitCreateUNGUser(paramStr), 2000); \n
}\n
},\n
});\n
});\n
});\n
});\n
......
......@@ -285,7 +285,8 @@ class TestUNG(ERP5TypeTestCase):
password="ung_password",
login_name="ung_user")
self.portal.REQUEST.form.update(form_dict)
self.portal.ERPSite_createUNGUser()
response = json.loads(self.portal.ERPSite_createUNGUser())
self.assertTrue(response)
self.stepTic()
person = self.portal.portal_catalog.getResultValue(portal_type="Person",
first_name="UNG")
......@@ -294,6 +295,8 @@ class TestUNG(ERP5TypeTestCase):
self.assertEquals(person.getEmail().getPortalType(), "Email")
self.assertEquals(person.getEmailText(), "g@g.com")
self.assertEquals(person.getReference(), "ung_user")
response = json.loads(self.portal.ERPSite_createUNGUser())
self.assertEquals(response, None)
def testERP5Site_getUserValidationState(self):
"""Test script ERP5Site_getUserValidationState"""
......@@ -320,4 +323,4 @@ class TestUNG(ERP5TypeTestCase):
self.assertEquals(response.get("response"), False)
self.login("ung_reference")
user = portal.ERP5Site_getAuthenticatedMemberPersonValue()
self.assertEquals(user.getFirstName(), "UNG")
\ No newline at end of file
self.assertEquals(user.getFirstName(), "UNG")
272
\ No newline at end of file
274
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment