Add support for per-page functions to be called before saving or
authorJoey Schulze <joey@infodrom.org>
Fri, 12 Mar 2010 14:05:34 +0000 (15:05 +0100)
committerJoey Schulze <joey@infodrom.org>
Fri, 12 Mar 2010 14:05:34 +0000 (15:05 +0100)
inserting new records

lib/functions.js

index b46c0b8..fd65cd4 100644 (file)
@@ -134,6 +134,8 @@ function select_update(id, options, empty)
       obj.options[empty+i] = new Option(options[i].text,options[i].id,false,false);
 }
 
+var pre_save = false;
+var pre_insert = false;
 var post_save = function() { grid_update(grid); }
 var post_delete = function() { grid_update(grid); }
 
@@ -161,6 +163,12 @@ function form_save(obj)
        return form_insert(obj);
 
     info('');
+
+    if (typeof pre_save == 'function')
+       if (!pre_save())
+           return false;
+
+
     ajax_request('save', Form.serialize(obj.form), save_callback);
     return false;
 }
@@ -168,6 +176,11 @@ function form_save(obj)
 function form_insert(obj)
 {
     info('');
+
+    if (typeof pre_insert == 'function')
+       if (!pre_insert())
+           return false;
+
     ajax_request('insert', Form.serialize(obj.form), save_callback);
     return false;
 }