Commit 7a1f0f98 authored by Ivan Tyagov's avatar Ivan Tyagov

Show message from server side user credential request creation script.

parent e88809ef
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
......
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.54147.54917.10649</string> </value>
<value> <string>976.54150.62060.20974</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1562150816.8</float>
<float>1563275707.24</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, UriTemplate */
/*global window, rJS, RSVP, jIO, UriTemplate, document, console */
/*jslint indent: 2, maxerr: 3, nomen: true */
(function (window, rJS, UriTemplate, document) {
(function (window, rJS, RSVP, jIO, UriTemplate, document, console) {
"use strict";
function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
rJS(window)
/////////////////////////////////////////////////////////////////
// handle acquisition
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("updateHeader", "updateHeader")
......@@ -18,8 +21,12 @@
// declared methods
/////////////////////////////////////////////////////////////////
//.declareMethod("render", function (options) {
//})
.onEvent('submit', function (evt) {
var first_name = document.getElementById("first_name").value,
var gadget = this,
first_name = document.getElementById("first_name").value,
last_name = document.getElementById("last_name").value,
email = document.getElementById("email").value;
......@@ -27,24 +34,43 @@
document.getElementById("status-message").innerHTML = msg;
}
function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
if ((validateEmail(email)) && (first_name) && (last_name)) {
/* send to server */
var url = "ERP5Site_newCredentialRequest?batch_mode=1&reference=" + email + "&default_email_text=" + email + "&first_name=" + first_name + "&last_name=" + last_name;
jIO.util.ajax({"type": "POST",
"url": url,
"xhrFields": {withCredentials: true}})
// XXX: check server response code!
showMessage("Request was created and will be reviewed shortly. It might take some time to be approved. You will be notified by email.");
var url = "ERP5Site_newCredentialRequest?batch_mode=1&reference=" + email + "&default_email_text=" + email + "&first_name=" + first_name + "&last_name=" + last_name;
return RSVP.Queue()
.push(function () {
return jIO.util.ajax({"type": "POST",
"url": url,
"xhrFields": {withCredentials: true}});
})
.push(function (server_response) {
var response = server_response.target.response;
var r = JSON.parse(response),
msg = r.msg,
code = r.code;
if (code === 0) {
return gadget.notifySubmitted({message: msg, status: 'success'});
}
else {
return gadget.notifySubmitted({message: msg, status: 'error'});
}
}, function (error) {
return gadget.notifySubmitted({message: 'HTTP ERROR. Registration NOT done.', status: 'error'});
})
//if you want to redirect to a specific page after registration:
/*.push(function () {
return gadget.redirect({
command: 'display',
options: {
page: "home"
}
});
})*/;
} else {
showMessage("Invalid first or last name or invalid email address!");
return gadget.notifySubmitted({message: 'bad fields', status: 'error'});
}
return evt;
});
}(window, rJS, UriTemplate, document));
\ No newline at end of file
}(window, rJS, RSVP, jIO, UriTemplate, document, console));
\ No newline at end of file
......@@ -69,7 +69,7 @@
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/javascript</string> </value>
<value> <string>text/x-rst</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.54162.42888.10752</string> </value>
<value> <string>977.8898.22031.4078</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1562151577.76</float>
<float>1563367884.02</float>
<string>UTC</string>
</tuple>
</state>
......
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