
// Necessità del Web Service ~/WS/NewsWS.asmx
// Register the namespace for the control.
Type.registerNamespace('Ribo.Cms.JS');
Ribo.Cms.JS.CustomerSelector = function(_entityName) {
    if (_entityName == null) { _entityName = "Customer" };
    Ribo.Cms.JS.EntitySelector._initializeBase(this, _entityName);
};
Ribo.Cms.JS.CustomerSelector.prototype = Ribo.Cms.JS.EntitySelector.prototype;
//estensione della funzione initializeCommand
//l'estensione deve ritornare i comandi che si devono eseguire ancora
Ribo.Cms.JS.CustomerSelector.prototype.initializeCommand_extender = function(element, cmds) {
    var all = (cmds == '*');
    cmds += '[setcurrentcustomer]';
    var _os = 'javascript:iObject[\'' + this.uid + '\']';
    _ename = this._entityName;

    if (all || cmds.indexOf('[setcurrentcustomer]', 0) >= 0) {
        var arr = getElementsByKey(element, _ename + '.SetCurrentCustomer', 'a');
        for (var i = 0; i < arr.length; i++) {
            obj = arr[i];
            obj.customerUid = obj.getAttribute("_customerUid");
            obj.href = _os + '.SetCurrentCustomer(\'' + obj.customerUid + '\',\'' + this.getFilter("AccountUid") + '\');';
        }
    }

    //considero eseguito il l'inizializzazione del comando detail per il detail
    cmds = cmds.replace('[setcurrentcustomer]', '');
    // ritorno la string modificata eventualmente per togliere dei comandi
    return cmds
};
Ribo.Cms.JS.CustomerSelector.prototype.SetCurrentCustomer = function(customerUid, accountUid) {

    if (customerUid == null || customerUid == '') { alert('CustomerUid non valido.') }
    filter = '{"CustomerUid":"' + customerUid + '","AccountUid":"' + accountUid + '"}';

    iWS[this.uid].SetCurrentCustomer(filter, this.onSuccessSetCurrentCustomer, this.onFailedCallback, this.uid);

};
Ribo.Cms.JS.CustomerSelector.prototype.onSuccessSetCurrentCustomer = function(result, context) {
    iobj = iObject[context];
    iobj.hidePanel();
    if (result != '') {
        iobj.showEntity(result);

        for (var k = 0; k < iObject.count; k++) {
            if (iObject['Product_' + k] != null) { iObject['Product_' + k].Refresh(); }
            if (iObject['Cart_' + k] != null) { iObject['Cart_' + k].Refresh(); }
            if (iObject['Document_' + k] != null) { iObject['Document_' + k].Refresh(); }
            if (iObject['Soldier_' + k] != null) { iObject['Soldier_' + k].Refresh(); }
            if (iObject['Equipment_' + k] != null) { iObject['Equipment_' + k].Refresh(); }
            if (iObject['EquipmentItem_' + k] != null) { iObject['EquipmentItem_' + k].Refresh(); }
        }

    }
};
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
