From: Coleman Watts Date: Thu, 12 Dec 2013 22:13:29 +0000 (-0800) Subject: CRM-13863 - Allow sorting to happen through ajax X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4a140040d9ad04c67ac8bedfa7ea175836ef690b;p=civicrm-core.git CRM-13863 - Allow sorting to happen through ajax --- diff --git a/CRM/Utils/Weight.php b/CRM/Utils/Weight.php index a5b2402166..f68a6bd1f8 100644 --- a/CRM/Utils/Weight.php +++ b/CRM/Utils/Weight.php @@ -368,10 +368,10 @@ class CRM_Utils_Weight { if ($prevID != 0) { $alt = ts('Move to top'); - $links[] = "\"$alt\""; + $links[] = "\"$alt\""; $alt = ts('Move up one row'); - $links[] = "\"$alt\""; + $links[] = "\"$alt\""; } else { $links[] = ""; @@ -380,10 +380,10 @@ class CRM_Utils_Weight { if ($nextID != 0) { $alt = ts('Move down one row'); - $links[] = "\"$alt\""; + $links[] = "\"$alt\""; $alt = ts('Move to bottom'); - $links[] = "\"$alt\""; + $links[] = "\"$alt\""; } else { $links[] = ""; @@ -415,7 +415,7 @@ class CRM_Utils_Weight { $srcWeight = CRM_Core_DAO::getFieldValue($daoName, $src, 'weight', $idName); $dstWeight = CRM_Core_DAO::getFieldValue($daoName, $dst, 'weight', $idName); if ($srcWeight == $dstWeight) { - CRM_Utils_System::redirect($url); + self::fixOrderOutput($url); } $tableName = $object->tableName(); @@ -455,7 +455,17 @@ class CRM_Utils_Weight { CRM_Core_DAO::executeQuery($query, $params); } - CRM_Utils_System::redirect($url); + self::fixOrderOutput($url); + } + + static function fixOrderOutput($url) { + if (empty($_GET['snippet']) || $_GET['snippet'] !== 'json') { + CRM_Utils_System::redirect($url); + } + + CRM_Core_Page_AJAX::returnJsonResponse(array( + 'userContext' => $url, + )); } } diff --git a/js/Common.js b/js/Common.js index 27aa8aab0f..68c8190af2 100644 --- a/js/Common.js +++ b/js/Common.js @@ -854,6 +854,7 @@ CRM.validate = CRM.validate || { if (!this.element.is('.crm-container *')) { this.element.addClass('crm-container'); } + this._handleOrderLinks(); this.options.url ? this.refresh() : this.options.url = document.location.href; this._originalUrl = this.options.url; }, @@ -869,17 +870,30 @@ CRM.validate = CRM.validate || { } return url; }, + _handleOrderLinks: function() { + var that = this; + $('a.crm-weight-arrow', that.element).click(function(e) { + that.options.block && that.element.block(); + $.getJSON(that._formatUrl(this.href)).done(function() { + that.refresh(); + }); + e.stopImmediatePropagation(); + return false; + }); + }, refresh: function() { var that = this; var url = this._formatUrl(this.options.url); - this.options.block && this.element.block(); + this.options.block && $('.blockOverlay', this.element).length < 1 && this.element.block(); $.getJSON(url, function(data) { if (typeof(data) != 'object' || typeof(data.content) != 'string') { that._onFailure(data); return; } data.url = url; - that.element.html(data.content).trigger('crmLoad', data); + that.element.html(data.content); + that._handleOrderLinks(); + that.element.trigger('crmLoad', data); that.options.crmForm && that.element.trigger('crmFormLoad', data); }).fail(function() { that._onFailure();