﻿function eCrmAction(action, args) {
    this.action = '';
    this.args = {};
    this.estConnecte = $('#eCrmConnecte').val() == 'True';

    if (action)
        this.action = action;

    if (args)
        this.args = args;

    this.affecter();
};

eCrmAction.prototype = {

    affecter: function () {
        $('#eCrmAction').val(this.action);
        $('#eCrmArguments').val($.toJSON(this.args));
    }
};

Entities.prototype.deconnexion = function () {
    var url = document.location.href;

    var idxQs = url.indexOf('?');

    //Supprime le paramètre de connexion automatique
    if (idxQs != -1 && url.indexOf('_al', idxQs) > -1)
        url = url.substring(0, url.indexOf('_al', idxQs) - 1);

    //Supprime l'ancre présente dans l'url
    if (url.indexOf('#') > -1)
        url = url.substring(0, url.indexOf('#'));

    if (url.indexOf('?') > -1)
        url += "&";
    else
        url += "?";

    url += '_ecc=deconnexion';

    document.location.href = url;
};

Entities.prototype.eCrmAction = function () {
    return $('#eCrmAction').val();
};

Entities.prototype.eCrmArguments = function () {
    var args = $('#eCrmArguments').val();

    if (!args || args == '')
        return '';
    else
        return $.evalJSON(args);
};
