First stab at handling multi-step forms in a popup
authorColeman Watts <coleman@civicrm.org>
Thu, 12 Jun 2014 20:10:41 +0000 (21:10 +0100)
committerColeman Watts <coleman@civicrm.org>
Thu, 12 Jun 2014 21:25:02 +0000 (22:25 +0100)
js/crm.ajax.js

index e018472b6b7f179130377ab664945fbe2359a66f..2f2496f9bd2b07f92e0d96c0c78ef2b4e8cff95a 100644 (file)
@@ -3,7 +3,7 @@
  * @see https://wiki.civicrm.org/confluence/display/CRMDOC/AJAX+Interface
  * @see https://wiki.civicrm.org/confluence/display/CRMDOC/Ajax+Pages+and+Forms
  */
-(function($, CRM) {
+(function($, CRM, undefined) {
   /**
    * Almost like {crmURL} but on the client side
    * eg: var url = CRM.url('civicrm/contact/view', {reset:1,cid:42});
         refreshAction: ['next_new', 'submit_savenext', 'upload_new'],
         cancelButton: '.cancel',
         openInline: 'a.open-inline, a.button, a.action-item',
-        onCancel: function(event) {},
-        onError: function(data) {
-          var $el = $(this);
-          $el.html(data.content).trigger('crmLoad', data).trigger('crmFormLoad', data).trigger('crmFormError', data);
-          if (typeof(data.errors) == 'object') {
-            $.each(data.errors, function(formElement, msg) {
-              $('[name="'+formElement+'"]', $el).crmError(msg);
-            });
-          }
-        }
+        onCancel: function(event) {}
       }
     };
     // Move options that belong to crmForm. Others will be passed through to crmSnippet
         url: data.url.replace(/reset=1[&]?/, ''),
         dataType: 'json',
         success: function(response) {
-          if (response.status !== 'form_error') {
+          if (response.content === undefined) {
             $el.crmSnippet('option', 'block') && $el.unblock();
             $el.trigger('crmFormSuccess', response);
             // Reset form for e.g. "save and new"
           }
           else {
             response.url = data.url;
-            settings.onError.call($el, response);
+            $el.html(response.content).trigger('crmLoad', response).trigger('crmFormLoad', response);
+            if (response.status === 'form_error') {
+              $el.trigger('crmFormError', response);
+              $.each(response.errors || [], function(formElement, msg) {
+                $('[name="'+formElement+'"]', $el).crmError(msg);
+              });
+            }
           }
         },
         beforeSerialize: function(form, options) {