﻿Ext.namespace('Mapping.Ext.Esri');

///
/// Basic error manager can be called from anywhere in the application to notify the user of an error
///
Mapping.Ext.Esri.ErrorManager = function() {
  
  var initialized = false;
  var callbackFunctions = new Array();
  
  return {
    
    esriError : function(err) {
      if ( err.dojoType ) {
        if (err.dojoType == "timeout") {
          Ext.Msg.alert('Timeout Error', 'A timout error ocurred. This is usually the result of a network connection issue. Please check your network connection and try your operation again.');
        } else {
          Ext.Msg.alert('Server Error', 'An unknown mapping server error has occurred. Please try your operation again or close your browser and open a new session.');
        }
      } else if (err.code){
        Ext.Msg.alert('Server Error ' + err.code, 'A mapping server error has occurred. Please try your operation again. If the error persists, please contact your administrator.');      
      }
      else if (Ext.isString(err)) {
        Ext.Msg.alert(err);
      } else {
        Ext.Msg.alert('Unknown Error','An unknown error has occured with the map. Please try your operation again. If the error persists, please contact your administrator.');
      }
      if(Mapping.Ext.Esri.CursorManager){
        Mapping.Ext.Esri.CursorManager.resetCursor();
      }
    },
    
    generalError: function(err) {
      Ext.Msg.alert('General Application Error',err);
    },
    
    /// Initialize this object and set the esri timeout to the configured value
    init: function() {
      if (!initialized) {
        initialized = true;
        esri.config.defaults.io.timeout = ajaxTimeout;
      }
    }
  };

}();

Mapping.Ext.Esri.ErrorManager.init();
