diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 18563ca0b..089003518 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -7,6 +7,7 @@ use App; use File; use View; use Lang; +use Flash; use Event; use Config; use Session; @@ -645,6 +646,12 @@ class Controller $responseContents['X_OCTOBER_REDIRECT'] = $result->getTargetUrl(); $result = null; } + /* + * No redirect is used, look for any flash messages + */ + elseif (Request::header('X_OCTOBER_REQUEST_FLASH') && Flash::check()) { + $responseContents['X_OCTOBER_FLASH_MESSAGES'] = Flash::all(); + } /* * If the handler returned an array, we should add it to output for rendering. diff --git a/modules/system/assets/js/framework.js b/modules/system/assets/js/framework.js index 62065e8ef..9b35005e0 100644 --- a/modules/system/assets/js/framework.js +++ b/modules/system/assets/js/framework.js @@ -80,13 +80,19 @@ if (window.jQuery === undefined) if (options.data !== undefined && !$.isEmptyObject(options.data)) data.push($.param(options.data)) + var requestHeaders = { + 'X-OCTOBER-REQUEST-HANDLER': handler, + 'X-OCTOBER-REQUEST-PARTIALS': this.extractPartials(options.update) + } + + if (options.flash !== undefined) { + requestHeaders['X-OCTOBER-REQUEST-FLASH'] = 1 + } + var requestOptions = { url: window.location.href, context: context, - headers: { - 'X-OCTOBER-REQUEST-HANDLER': handler, - 'X-OCTOBER-REQUEST-PARTIALS': this.extractPartials(options.update) - }, + headers: requestHeaders, success: function(data, textStatus, jqXHR) { /* * Halt here if beforeUpdate() or data-request-before-update returns false @@ -149,13 +155,13 @@ if (window.jQuery === undefined) * Trigger 'ajaxError' on the form, halt if event.preventDefault() is called */ var _event = jQuery.Event('ajaxError') - $triggerEl.trigger(_event, [context, textStatus, jqXHR]) + $triggerEl.trigger(_event, [context, errorMsg, textStatus, jqXHR]) if (_event.isDefaultPrevented()) return /* * Halt here if the data-request-error attribute returns false */ - if (options.evalError && eval('(function($el, context, textStatus, jqXHR) {'+options.evalError+'}.call($el.get(0), $el, context, textStatus, jqXHR))') === false) + if (options.evalError && eval('(function($el, context, errorMsg, textStatus, jqXHR) {'+options.evalError+'}.call($el.get(0), $el, context, errorMsg, textStatus, jqXHR))') === false) return requestOptions.handleErrorMessage(errorMsg) @@ -229,6 +235,8 @@ if (window.jQuery === undefined) * Focus fields with errors */ if (data['X_OCTOBER_ERROR_FIELDS']) { + $triggerEl.trigger('ajaxValidation', [context, data['X_OCTOBER_ERROR_MESSAGE'], data['X_OCTOBER_ERROR_FIELDS']]) + var isFirstInvalidField = true $.each(data['X_OCTOBER_ERROR_FIELDS'], function focusErrorField(fieldName, fieldMessages) { var fieldElement = $form.find('[name="'+fieldName+'"], [name="'+fieldName+'[]"], [name$="['+fieldName+']"], [name$="['+fieldName+'][]"]').filter(':enabled').first() @@ -251,8 +259,9 @@ if (window.jQuery === undefined) if (data['X_OCTOBER_ASSETS']) { assetManager.load(data['X_OCTOBER_ASSETS'], $.proxy(updatePromise.resolve, updatePromise)) } - else + else { updatePromise.resolve() + } return updatePromise } @@ -329,6 +338,7 @@ if (window.jQuery === undefined) confirm: $this.data('request-confirm'), redirect: $this.data('request-redirect'), loading: $this.data('request-loading'), + flash: $this.data('request-flash'), update: paramToObj('data-request-update', $this.data('request-update')), data: paramToObj('data-request-data', $this.data('request-data')) }