Sha256: 0c0fe48e154f951b7a1a6302b40a441d1170627f9f979b0c4989a2e35201072d

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

(function(){
var notifiers, showErrorsInResponse, showFlashMessages;

notifiers = {
  notice: 'success',
  alert: 'error',
  info: 'info'
};

showFlashMessages = function(jqXHR) {
  var flash;
  if (!jqXHR || !jqXHR.getResponseHeader) return;
  flash = jqXHR.getResponseHeader('X-Flash');
  flash = JSON.parse(flash);
  return _.each(flash, function(message, key) {
    return toastr[notifiers[key]](message);
  });
};

showErrorsInResponse = function(jqXHR) {
  var error, response;
  (jqXHR.responseJSON)
  if (!jqXHR || !jqXHR.responseJSON || !jqXHR.responseJSON.errors) return;
  response = jqXHR.responseJSON;
  error = _.map(response.errors, function(messages, property) {
    return _.map(messages, function(x) {
      return "" + property + " " + x;
    }).join("<br />");
  });
  return toastr.error(error, "ERROR");
};

$(function() {
  toastr.options.positionClass = 'toast-top-right';
  return $(document).ajaxComplete(function(event, xhr, settings) {
    showFlashMessages(xhr);
    showErrorsInResponse(xhr);
  });
});
})(this)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aflash-0.1.1 vendor/assets/javascripts/ajax_flash.js