From 96c4727be22bc014cd07ca231f88faff17af3d9e Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Mon, 6 Feb 2012 13:26:18 +0000 Subject: [PATCH] Added email validation in prechat survey. --- src/messenger/webim/js/164/survey.js | 8 +++++ src/messenger/webim/js/source/build.xml | 4 +++ src/messenger/webim/js/source/survey.js | 31 +++++++++++++++++++ src/messenger/webim/locales/en/properties | 1 + src/messenger/webim/locales/ru/properties | 1 + .../dialogs/default/templates/survey.tpl | 13 ++++++-- .../dialogs/original/templates/survey.tpl | 17 +++++++--- .../dialogs/silver/templates/survey.tpl | 13 ++++++-- .../dialogs/simplicity/templates/survey.tpl | 15 +++++++-- 9 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 src/messenger/webim/js/164/survey.js create mode 100644 src/messenger/webim/js/source/survey.js diff --git a/src/messenger/webim/js/164/survey.js b/src/messenger/webim/js/164/survey.js new file mode 100644 index 00000000..da2cdd8c --- /dev/null +++ b/src/messenger/webim/js/164/survey.js @@ -0,0 +1,8 @@ +/* + This file is part of Mibew Messenger project. + http://mibew.org + + Copyright (c) 2005-2011 Mibew Messenger Community + License: http://mibew.org/license.php +*/ +var Survey={checkFields:function(){var a=document.surveyForm.email,b=/^(([^<>()[\]\\.,;:\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 null!=a&&-1==a.value.search(b)?this.localizedStrings.wrongEmail:null},submit:function(){var a=this.checkFields();null==a?document.surveyForm.submit():alert(a)}};EventHelper.register(window,"onload",function(){Survey.localizedStrings=localizedStrings}); \ No newline at end of file diff --git a/src/messenger/webim/js/source/build.xml b/src/messenger/webim/js/source/build.xml index 623b68fb..6c604534 100644 --- a/src/messenger/webim/js/source/build.xml +++ b/src/messenger/webim/js/source/build.xml @@ -28,6 +28,10 @@ + + + + diff --git a/src/messenger/webim/js/source/survey.js b/src/messenger/webim/js/source/survey.js new file mode 100644 index 00000000..4f75c80f --- /dev/null +++ b/src/messenger/webim/js/source/survey.js @@ -0,0 +1,31 @@ +/** + * @preserve This file is part of Mibew Messenger project. + * http://mibew.org + * + * Copyright (c) 2005-2011 Mibew Messenger Community + * License: http://mibew.org/license.php + */ + +var Survey = { + checkFields: function(){ + var emailField = document.surveyForm.email; + var emailPattern = /^(([^<>()[\]\\.,;:\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,}))$/; + if( emailField != null && emailField.value.search(emailPattern) == -1 ){ + return this.localizedStrings.wrongEmail; + } + return null; + }, + + submit: function(){ + var error = this.checkFields(); + if(error == null){ + document.surveyForm.submit(); + }else{ + alert(error); + } + } +} + +EventHelper.register(window, 'onload', function(){ + Survey.localizedStrings = localizedStrings; +}); \ No newline at end of file diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index 04e5694c..8ca66249 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -407,6 +407,7 @@ permissions.intro=Change restrictions and available features for this operator. permissions.title=Permissions presurvey.department=Choose Department: presurvey.department.description=Department description: +presurvey.error.wrong_email=Wrong email address. presurvey.intro=Thank you for contacting us. Please fill out the form below and click the Start Chat button. presurvey.mail=Email: presurvey.name=Name: diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index a4b91e9d..2bbd019d 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -405,6 +405,7 @@ permissions.intro= permissions.title=Возможности оператора presurvey.department=Выберите отдел: presurvey.department.description=Описание отдела: +presurvey.error.wrong_email=Неверный адрес электронной почты. presurvey.intro=Спасибо, что связались с нами! Заполните, пожалуйста, небольшую форму и нажмите "Начать диалог". presurvey.mail=E-mail: presurvey.name=Ваше имя: diff --git a/src/messenger/webim/styles/dialogs/default/templates/survey.tpl b/src/messenger/webim/styles/dialogs/default/templates/survey.tpl index 816b0324..61b88386 100644 --- a/src/messenger/webim/styles/dialogs/default/templates/survey.tpl +++ b/src/messenger/webim/styles/dialogs/default/templates/survey.tpl @@ -34,9 +34,18 @@ text-decoration:none; } + + + + var groupDescriptions = ${page:group.descriptions}; ${endif:groups} + var localizedStrings = { +${if:showemail} + wrongEmail: '${msg:presurvey.error.wrong_email}', +${endif:showemail} + } + @@ -149,7 +158,7 @@ ${endif:showmessage} diff --git a/src/messenger/webim/styles/dialogs/original/templates/survey.tpl b/src/messenger/webim/styles/dialogs/original/templates/survey.tpl index 1c02f031..5821538f 100644 --- a/src/messenger/webim/styles/dialogs/original/templates/survey.tpl +++ b/src/messenger/webim/styles/dialogs/original/templates/survey.tpl @@ -20,9 +20,18 @@ .isubmit { background-position:0px -39px; width: 40px; height: 35px; } .isubmitrest { background-position:-31px -39px; width: 10px; height: 35px;} + + + + var groupDescriptions = ${page:group.descriptions}; ${endif:groups} + var localizedStrings = { +${if:showemail} + wrongEmail: '${msg:presurvey.error.wrong_email}', +${endif:showemail} + } +
- +
${msg:presurvey.submit}${msg:presurvey.submit}
@@ -132,12 +141,12 @@ ${endif:showmessage} diff --git a/src/messenger/webim/styles/dialogs/silver/templates/survey.tpl b/src/messenger/webim/styles/dialogs/silver/templates/survey.tpl index ac3ee6c8..e6eeaab8 100644 --- a/src/messenger/webim/styles/dialogs/silver/templates/survey.tpl +++ b/src/messenger/webim/styles/dialogs/silver/templates/survey.tpl @@ -4,9 +4,18 @@ ${msg:presurvey.title} + + + + var groupDescriptions = ${page:group.descriptions}; ${endif:groups} + var localizedStrings = { + ${if:showemail} + wrongEmail: '${msg:presurvey.error.wrong_email}', + ${endif:showemail} + } +
@@ -80,7 +89,7 @@
${endif:showmessage}
- + - +

- ${msg:presurvey.submit}
+ ${msg:presurvey.submit}
- ${msg:presurvey.submit} + ${msg:presurvey.submit}
 
diff --git a/src/messenger/webim/styles/dialogs/simplicity/templates/survey.tpl b/src/messenger/webim/styles/dialogs/simplicity/templates/survey.tpl index c3487485..e31b1026 100644 --- a/src/messenger/webim/styles/dialogs/simplicity/templates/survey.tpl +++ b/src/messenger/webim/styles/dialogs/simplicity/templates/survey.tpl @@ -4,9 +4,18 @@ ${msg:presurvey.title} + + + + var groupDescriptions = ${page:group.descriptions}; ${endif:groups} + var localizedStrings = { +${if:showemail} + wrongEmail: '${msg:presurvey.error.wrong_email}', +${endif:showemail} + } +
@@ -77,8 +86,8 @@ ${endif:groups} - - + +
${msg:presurvey.submit}${msg:presurvey.submit}${msg:presurvey.submit}${msg:presurvey.submit}