﻿Ext.BLANK_IMAGE_URL = 'Scripts/extjs/resources/images/default/s.gif';
Ext.Ajax.on("requestexception", function(conn, response, options) {
    var showMessaje = true;
    var jsonData = null;
    try {
        jsonData = Ext.util.JSON.decode(response.responseText);
    } catch (e) { }

    if (jsonData && jsonData.Error) {
        showMessaje = false;
        Ext.MessageBox.show({
            title: 'Error : ' + jsonData.Metodo,
            msg: jsonData.Error + '<br/><hr/>StackTrace : ' + jsonData.StackTrace,
            buttons: Ext.MessageBox.OK
        });
    }

    if (showMessaje && jsonData && jsonData.Message) {
        showMessaje = false;
        Ext.MessageBox.show({
            title: 'Error'
            , msg:jsonData.Message
            , buttons: Ext.MessageBox.OK
        });
    }
    if (showMessaje) {
      verError(response.responseText)
    }

    this.progressCount = 0;
    Ext.get(document.body).unmask()
}, this);
////////////////////////
// Componentes
////////////////////////
ConcolTree = Ext.extend(Ext.tree.TreePanel, {
  loadMask: true
, initComponent:function() {
    ConcolTree.superclass.initComponent.apply(this, arguments);
    if (this.loadMask) { this.on('render', this.createMask, this); }
  }
  , createMask: function() {
    var mask = new Ext.LoadMask(this.getEl(), this.maskConfig);
    this.on('beforeload', mask.show, mask);
    this.on('load', mask.hide, mask);
  }
});

////////////////////////
// Funciones
////////////////////////
function verError(error) {
  Ext.MessageBox.show({
    title: 'Error'
            , msg: error
            , buttons: Ext.MessageBox.OK
  });
}

function rendererWrap(value, metaData, record, rowIndex, colIndex, store) {
  return '<p style="white-space:normal;">' + value + '</p>';
}

function rendererWithTitle(value, metaData, record, rowIndex, colIndex, store) {
    metaData.attr = 'ext:qtitle="" ext:qtip="' + Ext.util.Format.htmlEncode(value) + '"';
    return value;
}
