﻿if (Ext.ux.FileUploader) {
    Ext.apply(Ext.ux.FileUploader.prototype, {
        jsonErrorText: 'L\'objet JSON ne peut pas être décodé'
        ,unknownErrorText: 'Erreur inconnue'
    });
}
if (Ext.ux.UploadPanel) {
    Ext.apply(Ext.ux.UploadPanel.prototype, {
        fileQueuedText: 'Fichier en attente d\'envoi.' 
        ,fileDoneText: 'Fichier envoyé.' 
        ,fileFailedText: 'Echec de l\'envoi du fichier.' 
        ,fileStoppedText: 'Envoi du fichier interrompu par l\'utilisateur.' 
        ,fileUploadingText: 'Envoi du fichier en cours...' 
        ,fileProcessingText: 'Traitement du fichier en cours...' 
        ,fileStopFailedText: 'L\'envoi du fichier ne peut plus être interrompu.' 
        
        ,fileNameHeader: 'Nom de fichier local'
        ,progressHeader: 'Progression'
        ,stateHeader: 'Statut'
        
        ,addText: 'Ajouter'
        ,addTip: 'Ajouter un fichier à la file d\'attente'
        ,removeText: 'Supprimer'
        ,removeTip: 'Supprimer la sélection'
        ,stopAllText: 'Arrêter'
        ,stopAllTip: 'Arrêter tous les envois'
        ,uploadText: 'Envoyer'
        ,uploadTip: 'Traiter la file d\'attente'
        
        ,forbiddenExtensionTitle: 'Extension interdite'
        ,forbiddenExtensionMessage: 'Les fichiers portant l\'extension {0} ne peuvent pas être envoyés.'
    });
}

Ext.grid.PropertyColumnModel = function(grid, store) {
    this.grid = grid;
    var g = Ext.grid;
    g.PropertyColumnModel.superclass.constructor.call(this, [
        { header: this.nameText, width: 50, sortable: true, dataIndex: 'name', id: 'name', menuDisabled: true },
        { header: this.valueText, width: 50, resizable: false, dataIndex: 'value', id: 'value', menuDisabled: true }
    ]);
    this.store = store;
    this.bselect = Ext.DomHelper.append(document.body, {
        tag: 'select', cls: 'x-grid-editor x-hide-display', children: [
            { tag: 'option', value: 'true', html: 'vrai' },
            { tag: 'option', value: 'false', html: 'faux' }
        ]
    });
    var f = Ext.form;

    var bfield = new f.Field({
        el: this.bselect,
        bselect: this.bselect,
        autoShow: true,
        getValue: function() {
            return this.bselect.value == 'true';
        }
    });
    this.editors = {
        'date': new g.GridEditor(new f.DateField({ selectOnFocus: true })),
        'string': new g.GridEditor(new f.TextField({ selectOnFocus: true })),
        'number': new g.GridEditor(new f.NumberField({ selectOnFocus: true, style: 'text-align:left;' })),
        'boolean': new g.GridEditor(bfield)
    };
    this.renderCellDelegate = this.renderCell.createDelegate(this);
    this.renderPropDelegate = this.renderProp.createDelegate(this);
};

Ext.extend(Ext.grid.PropertyColumnModel, Ext.grid.ColumnModel, {
    // private - strings used for locale support
    nameText: 'Nom',
    valueText: 'Valeur',
    dateFormat: 'm/j/Y',

    // private
    renderDate: function(dateVal) {
        return dateVal.dateFormat(this.dateFormat);
    },

    // private
    renderBool: function(bVal) {
        return bVal ? 'vrai' : 'faux';
    },

    // private
    isCellEditable: function(colIndex, rowIndex) {
        return colIndex == 1;
    },

    // private
    getRenderer: function(col) {
        return col == 1 ?
            this.renderCellDelegate : this.renderPropDelegate;
    },

    // private
    renderProp: function(v) {
        return this.getPropertyName(v);
    },

    // private
    renderCell: function(val) {
        var rv = val;
        if (Ext.isDate(val)) {
            rv = this.renderDate(val);
        } else if (typeof val == 'boolean') {
            rv = this.renderBool(val);
        }
        return Ext.util.Format.htmlEncode(rv);
    },

    // private
    getPropertyName: function(name) {
        var pn = this.grid.propertyNames;
        return pn && pn[name] ? pn[name] : name;
    },

    // private
    getCellEditor: function(colIndex, rowIndex) {
        var p = this.store.getProperty(rowIndex);
        var n = p.data['name'], val = p.data['value'];
        if (this.grid.customEditors[n]) {
            return this.grid.customEditors[n];
        }
        if (Ext.isDate(val)) {
            return this.editors['date'];
        } else if (typeof val == 'number') {
            return this.editors['number'];
        } else if (typeof val == 'boolean') {
            return this.editors['boolean'];
        } else {
            return this.editors['string'];
        }
    }
});

Ext.apply(ui, {
    errorTitle: 'Erreur',
    errorInfosTitle: 'Informations complémentaires',
    errorMessage : 'Une erreur est survenue',
    quitConfirmationTitle: 'Enregistrer les changements ?',
    quitConfirmationMsg: 'Voulez-vous enregistrer vos modifications ?',
    deleteConfirmationTitle: 'Supprimer',
    deleteConfirmationMsg: 'Voulez-vous vraiment supprimer {0} ?',
    onBeforeUnloadMessage: 'Les modifications seront perdues.',
    timeoutMessage: 'La requête n\'a pas abouti. Veuillez réessayer.'
});

Ext.apply(ui.gridRenderers, {
    yesText : 'Oui',
    noText : 'Non'
});

Ext.ux.form.clearable.clearTip = 'Effacer';

Ext.apply(Ext.ux.form.XDateField.prototype, {
    format: 'd/m/Y'
});

Ext.apply(Ext.ux.form.ReadOnlyField.prototype, {
    trueText: 'Vrai',
    falseText: 'Faux',
    dateDisplayFormat: 'd/m/Y'
});

Ext.form.VTypes.passwordText = 'Les mots de passe sont différents';
Ext.form.VTypes.ipText = "L'ip saisie est incorrecte";

Ext.apply(Ext.ux.form.HrefField.prototype, {
    triggerTip: 'Visiter le site web'
});

Ext.apply(Ext.plugins.grid.GridCellCopy.prototype, {
    menuItemText: 'Copier le contenu de la cellule',
    dialogTitle: 'Copier',
    dialogMessage: 'Appuyer sur Ctrl+C pour copier le texte.'
});

Ext.apply(Ext.ux.form.LovCombo.prototype, {
    selectAllTextField : 'Tous'
});

Ext.apply(Ext.ux.form.PhoneField.prototype, {
    triggerTip : 'Appeler'
});
Ext.apply(Ext.ux.form.clearable.PhoneField.prototype, {
    triggerTip : 'Appeler'
});

Ext.apply(Ext.ux.form.MailField.prototype, {
    triggerTip : 'Envoyer un message électronique'
});

Ext.apply(Ext.ux.form.XPathField.prototype, {
    triggerTip : 'Copier le champ sélectionné',
    invalidXPathMsg : 'Le champ sélectionné est invalide'
});

Ext.apply(Ext.ux.form.clearable.MailField.prototype, {
    triggerTip : 'Envoyer un message électronique'
});

Ext.apply(Ext.ux.form.UpdatableDateField.prototype, {
    updateTip : 'Met à jour la valeur du champ'
});

Ext.apply(Ext.ux.grid.livegrid.ExpandableGridView.prototype, {
    browserWarningTitle: 'Avertissement',
    browserWarningMessage: 'Votre navigateur ne permet pas d\'afficher plus de {0} résultats. Veuillez affiner votre recherche.'
});

Ext.apply(Ext.ux.form.RegExpField.prototype, {
    triggerTip      : 'Aide',
    valueText       : 'Symbole',
    descriptionText : 'Correspondance',
    sampleText      : 'Exemple/Equivalence',
    closeText       : 'Fermer',
    htmlText        : '<p>Une expression régulière est en informatique une chaîne de caractères que l’on appelle parfois un motif et qui décrit un ensemble  de chaînes de caractères possibles selon une syntaxe précise (<a target="_blank" href="http://fr.wikipedia.org/wiki/Expression_r%C3%A9guli%C3%A8re">wikipedia</a>).</p>',
    windowTitle     : 'Aide pour la saisie d\'expression régulière',
    data : [        
        ['\\',      'Caractère d\'échappement',             '[\\.] contient un "."'],
        ['^',       'Début de ligne',                       '^b$ contient uniquement b'],
        ['.',       'N\'importe quel caractère',            '^.$ contient un seul caractère'],
        ['$',       'Fin de ligne',                         'er$ finit par "er"'],
        ['|',       'Alternative',                          '^(a|A) commence par a ou A'],
        ['( )',     'Groupement',                           '^((a)|(er)) commence par a ou er'],
        ['-',       'Intervalle de caractères',             '^[a-d] commence par a,b,c ou d'],
        ['[ ]',     'Ensemble de caractères',               '[0-9] contient un chiffre'],
        ['[^]',     'Tout sauf un ensemble de caractères',  '^[^a] ne commence pas par a'],
        ['+',       '1 fois ou plus',                       '^(a)+ commence par un ou plusieurs a'],
        ['?	',      '0 ou 1 fois',                          '^(a)? commence ou non par un a'],
        ['*	',      '0 fois ou plus',                       '^(a)* peut ou non commencer par a'],
        ['{x}',     'x fois exactement',                    'a{2} deux fois "a"'],
        ['{x,}' ,   'x fois au moins',                      'a{2,} deux fois "a" au moins'],
        ['{x, y}',  'x fois minimum, y maximum',            'a{2,4} deux, trois ou quatre fois "a"'],
        ['n',       'Caractère de nouvelle ligne',          ''],
        ['\\r',     'Caractère de retour à la ligne',       ''],
        ['\\t',     'Caractère de tabulation',              ''],
        ['\\s',     'Caractère d\'espacement (espace, tabulation, saut de page, etc)','[\\f\\n\\r\\t\\v]'],
        ['\\S',     'Tout ce qui n\'est pas un espacement', '[^\\f\\n\\r\\t\\v]'],
        ['\\d',     'Un chiffre',                           '[0-9]'],
        ['\\D',     'Tout sauf un chiffre',                 '[^0-9]'],
        ['\\w',     'Un caractère alphanumérique',          '[a-zA-Z0-9_]'],
        ['\\W',     'Tout sauf un caractère alphanumérique','[^a-zA-Z0-9_]'],
        ['\\n',     'Caractère en octal',                   'ex:\\001 ==> " 1 "'],
        ['\\xn',    'Caractère en hexadécimal',             'ex: \\x41 ==>" A "'] 	 
    ]
});
Ext.override(Ext.grid.CheckboxSelectionModel, {    
    header: '<div class="x-grid3-hd-checker" ext:qtip="Tous/aucun">&#160;</div>'
});

Ext.override(Ext.ux.form.HtmlField, {
    closeText : 'Fermer',
    validateText : 'OK',
    htmlText : '',
    triggerTip : 'Editer',
    windowTitle : 'Editeur Html'
});
