From 4d32e46388c89343e065a757232c94ced5e12439 Mon Sep 17 00:00:00 2001
From: "@alexbuckley" <@alexbuckley>
Date: Thu, 12 Jan 2017 21:24:00 +0000
Subject: [PATCH] Bug 17855 -Fifth update following tester feedback.
Implemented Javascript password check to determine if the values in the
'password' and 'confirm password' fields are consistent.
If passwords are not consistent a message informing the user is displayed and they only have
to change the password values rather than re-fill out the whole form.
Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
---
installer/onboarding.pl | 30 ++++++++--
.../prog/en/modules/onboarding/onboardingstep3.tt | 68 ++++++++++------------
2 files changed, 57 insertions(+), 41 deletions(-)
diff --git a/installer/onboarding.pl b/installer/onboarding.pl
index 85d2afa..eb20b44 100755
--- a/installer/onboarding.pl
+++ b/installer/onboarding.pl
@@ -143,8 +143,10 @@ elsif ( $start && $start eq 'Minimal item type setup' ) {
$template->param( itemtypes => $itemtypes, );
}
elsif ( $step && $step == 1 ) {
- my $createlibrary = $input->param('createlibrary'); #Store the inputted library branch code and name in $createlibrary variable
- $template->param( 'createlibrary' => $createlibrary ); # Hand the library values back to the template in the createlibrary variable
+ my $createlibrary = $input->param('createlibrary')
+ ; #Store the inputted library branch code and name in $createlibrary variable
+ $template->param( 'createlibrary' => $createlibrary )
+ ; # Hand the library values back to the template in the createlibrary variable
#store inputted parameters in variables
my $branchcode = $input->param('branchcode');
@@ -160,7 +162,8 @@ elsif ( $step && $step == 1 ) {
);
$template->param( 'branchcode' => $branchcode );
- $branchcode =~ s|\s||g; # Use a regular expression to check the value of the inputted branchcode
+ $branchcode =~ s|\s||g
+ ; # Use a regular expression to check the value of the inputted branchcode
#Create a new library object and store the branchcode and @fields array values in this new library object
my $library = Koha::Library->new(
@@ -182,7 +185,8 @@ elsif ( $step && $step == 1 ) {
#Check if the $step variable equals 2 i.e. the user has clicked to create a patron category in the create patron category screen 1
}
elsif ( $step && $step == 2 ) {
- my $createcat = $input->param('createcat'); #Store the inputted category code and name in $createcat
+ my $createcat = $input->param('createcat')
+ ; #Store the inputted category code and name in $createcat
$template->param( 'createcat' => $createcat );
#Initialising values
@@ -306,6 +310,19 @@ elsif ( $step && $step == 3 ) {
my $borrowernumber = $input->param('borrowernumber');
my $userid = $input->param('userid');
+ # function to designate mandatory fields (visually with css)
+ my $check_BorrowerMandatoryField =
+ C4::Context->preference("BorrowerMandatoryField");
+ my @field_check = split( /\|/, $check_BorrowerMandatoryField );
+ foreach (@field_check) {
+ $template->param( "mandatory$_" => 1 );
+ $template->param(
+ BorrowerMandatoryField =>
+ C4::Context->preference("BorrowerMandatoryField")
+ , #field to test with javascript
+ );
+ }
+
#If the entered cardnumber causes an error hand this error to the @errors array
if ( my $error_code = checkcardnumber( $cardnumber, $borrowernumber ) ) {
push @errors,
@@ -649,6 +666,7 @@ elsif ( $step && $step == 5 ) {
);
$sth_search->execute($branch);
my $res = $sth_search->fetchrow_hashref();
+
if ( $res->{total} ) {
$sth_update->execute( $onshelfholds, $branch );
}
@@ -665,7 +683,9 @@ elsif ( $step && $step == 5 ) {
if ($issuingrule) {
$issuingrule->set($params)->store();
push @messages,
- { type => 'error', code => 'error_on_insert'
+ {
+ type => 'error',
+ code => 'error_on_insert'
}; #Stops crash of the onboarding tool if someone makes a circulation rule with the same item type, library and patron categroy as an exisiting circulation rule.
}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep3.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep3.tt
index f901707..171601a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep3.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep3.tt
@@ -13,53 +13,48 @@
<!--jQuery scripts for creating patron-->
<script type-"text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.fixFloat.js"></script>
-<script type="text/javascipt">
- var MSG_DUPLICATE_PATRON = _("Warning: Duplicate patron");
- var MSG_PASSWORD_MISMATCH = _("The passwords entered do not match");
- var MSG_PASSWORD_CONTAINS_TRAILING_SPACES = _("Password contains leading and/or trailing spaces.");
-function check_password(password){
- if(password.match(/^\s/) || password.match(/\s$/)){
- return false;
- }return true;
-}
+
+<script type="text/javascript">
+ var MSG_CATEGORYCODE_CHARS=(_("Please only enter letters into this field."));
+ var MSG_PASSWORD_MISMATCH=(_("The entered passwords do not match, please rewrite them"));
+ </script>
+
+<script type="text/javascript">
+jQuery.validator.addMethod( "password_match", function(value,element){
+ var MSG_PASSWORD_MISMATCH = (_("The passwords entered do not match"));
+ var password = document.getElementById('password').value
+ var confirmpassword = document.getElementById('password2').value
+
+ if ( password != confirmpassword ){
+ return false;
+ }
+ else{
+ return true
+ }
+ }, MSG_PASSWORD_MISMATCH
+);
+
+
$(document).ready(function(){
- $("#createpatron").validate({
+
+ $("#Submit").click(function(){
+ $("#createpatron").validate({
rules: {
- borrowernumber: {
- required: true,
- digits: true
- },
- surname:{
- required: true,
- letters: true
- },
- firstname:{
- required:true,
- letters:true
- },
- userid: {
- required: true;
- letters_numbers: true
- },
password: {
- letters_numbers: true
- },
+ password_match:true
+ }
},
messages: {
password: {
required: MSG_PASSWORD_MISMATCH
},
- userid: {
- required: MSG_DUPLICATE_PATRON
- }
}
});
-
-})
+});
+});
</script>
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/members.js"></script>
</head>
<div>
@@ -118,7 +113,7 @@ $(document).ready(function(){
<p>
Now we will create a patron with superlibrarian permissions. Login with this to access Koha as a staff member will all permissions.
</p>
- <form name="createpatron" method="post" action="onboarding.pl">
+ <form name="createpatron" id="createpatron" method="post" action="onboarding.pl">
<fieldset class="rows">
<input type="hidden" name="step" value="3"/>
<input type="hidden" name="op" value="add_validate" />
@@ -179,6 +174,7 @@ $(document).ready(function(){
<ol>
<h3>OPAC/Staff Login</h3>
<li>
+ <input type="hidden" name="BorrowerMandatoryField" value = [% BorrowerMandatoryField %] />
<label for="userid" class="required">Username: </label>
<input type="text" name="userid" id ="userid" pattern="[A-Za-z1-9 ]+" title="Please only enter letters or numbers into this username field" size="20" value="[% userid %]" class="required" required="required" />
<span class="required">Required</span>
@@ -195,6 +191,6 @@ $(document).ready(function(){
</li>
</ol>
</fieldset><br>
- <input type="submit" class="action" value="Submit"/>
+ <input type="submit" id="Submit" class="action" value="Submit"/>
</form>
[% END %]
--
2.1.4