in patron editor, prevent Save and Save & Clone from working with an invalid form...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 15 Jun 2010 04:01:23 +0000 (04:01 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 15 Jun 2010 04:01:23 +0000 (04:01 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@16719 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/ui/default/actor/user/register.js
Open-ILS/web/templates/default/actor/user/register.tt2

index 1979f91..4f5593e 100644 (file)
@@ -44,6 +44,8 @@ var stageUser;
 var optInSettings;
 var allCardsTemplate;
 
+var dupeUsrname = false;
+var dupeBarcode = false;
 
 if(!window.xulG) var xulG = null;
 
@@ -602,6 +604,7 @@ function attachWidgetEvents(fmcls, fmfield, widget) {
             dojo.connect(widget.widget, 'onChange',
                 function() {
                     var barcode = this.attr('value');
+                    dupeBarcode = false;
                     dojo.addClass(dojo.byId('uedit-dupe-barcode-warning'), 'hidden');
                     fieldmapper.standardRequest(
                         ['open-ils.actor', 'open-ils.actor.barcode.exists'],
@@ -610,8 +613,10 @@ function attachWidgetEvents(fmcls, fmfield, widget) {
                             oncomplete : function(r) {
                                 var res = openils.Util.readResponse(r);
                                 if(res == '1') {
+                                    dupeBarcode = true;
                                     dojo.removeClass(dojo.byId('uedit-dupe-barcode-warning'), 'hidden');
                                 } else {
+                                    dupeBarcode = false;
                                     dojo.addClass(dojo.byId('uedit-dupe-barcode-warning'), 'hidden');
                                     var un = findWidget('au', 'usrname');
                                     if(!un.widget.attr('value'))
@@ -636,6 +641,7 @@ function attachWidgetEvents(fmcls, fmfield, widget) {
                         var usrname = input.widget.attr('value');
 
                         if(!usrname) {
+                            dupeUsrname = false;
                             dojo.addClass(dojo.byId('uedit-dupe-username-warning'), 'hidden');
                             return;
                         }
@@ -647,8 +653,10 @@ function attachWidgetEvents(fmcls, fmfield, widget) {
                                 oncomplete : function(r) {
                                     var res = openils.Util.readResponse(r);
                                     if(res) {
+                                        dupeUsrname = true;
                                         dojo.removeClass(dojo.byId('uedit-dupe-username-warning'), 'hidden');
                                     } else {
+                                        dupeUsrname = false;
                                         dojo.addClass(dojo.byId('uedit-dupe-username-warning'), 'hidden');
                                     }
                                 }
@@ -953,6 +961,11 @@ function uEditSaveClone() { _uEditSave(true); }
 
 function _uEditSave(doClone) {
 
+    if ( (! myForm.isValid()) || dupeUsrname || dupeBarcode ) {
+        alert('Form is invalid.  Please edit and try again.');
+        return;
+    }
+
     for(var idx in widgetPile) {
         var w = widgetPile[idx];
         var val = uEditWidgetVal(w);
index 431cdea..2300b13 100644 (file)
 
 </style>
 
-<table>
-    [% INCLUDE default/actor/user/register_table.tt2 %]
-</table>
+<div dojoType="dijit.form.Form" id="myForm" jsId="myForm" encType="multipart/form-data" action="" method="">
+    <script type="dojo/method" event="onSubmit">
+        /* we don't want to use the form action, but uEditSave and UEditSaveClone from the Save buttons.  We
+            do want to use the Form's validation features, which we do from within UEditSave, etc. */
+        return false;
+    </script>
+    <table>
+        [% INCLUDE default/actor/user/register_table.tt2 %]
+    </table>
+</div>
 
 <div id='uedit-save-div'>
     <button dojoType='dijit.form.Button' jsId='saveButton' onClick='uEditSave'>Save</button>