Merge pull request #24011 from demeritcowboy/composerlock
[civicrm-core.git] / js / crm.ajax.js
index 4cb20cd03ee7b65c3fea57749294e07d8577166a..82a8025a7942191cb0e322a29c506bb4eaf51bc9 100644 (file)
     options: {
       url: null,
       block: true,
+      post: null,
       crmForm: null
     },
     _originalContent: null,
         } else {
           url = url.replace(/snippet=[^&]*/, 'snippet=' + snippetType);
         }
+        // See Civi\Angular\AngularLoader
+        if (snippetType === 'json' && CRM.angular) {
+          url += '&crmAngularModules=' + CRM.angular.modules.join();
+        }
       }
       return url;
     },
         return false;
       });
     },
+    _ajax: function(url) {
+      if (!this.options.post || !this.isOriginalUrl()) {
+        return $.getJSON(url);
+      }
+      return $.post({
+        url: url,
+        dataType: 'json',
+        data: this.options.post
+      });
+    },
     refresh: function() {
-      var that = this;
-      var url = this._formatUrl(this.options.url, 'json');
+      var that = this,
+        hash = this.options.url.split('#')[1];
+        url = this._formatUrl(this.options.url, 'json');
+      $(this.element).data('urlHash', hash);
       if (this.options.crmForm) $('form', this.element).ajaxFormUnbind();
       if (this.options.block) this.element.block();
-      $.getJSON(url, function(data) {
+      this._ajax(url).then(function(data) {
         if (data.status === 'redirect') {
           that.options.url = data.userContext;
           return that.refresh();
             $('[name="'+formElement+'"]', that.element).crmError(msg);
           });
         }
-      }).fail(function(data, msg, status) {
+      }function(data, msg, status) {
         that._onFailure(data, status);
       });
     },