function ModuleXXView(domId, model) {
    var _domId = '#' + domId;
    var _model = model;

    _model.dataChangeEvent(function(sender, data){
        _refresh(data);
    });

    function _refresh(data) {
        $(_domId + ' .liczba').html(data.liczba);
    }

    return {
        show: function() {
            $(_domId).html('<p>Jestem MODULEXX</p><p[>Wylosowalem liczbe: <span class="liczba">ciagle losuje ;)</span></p>');
        }
    }
}

function ModuleXXModel() {
    var dataChange = new Event(this);

    return {
        getNumber: function() {
            $.ajax({
                url: '/random.php',
                dataType: 'json',
                success: function(data) {
                    dataChange.notify(data);
                }
            });
        },

        dataChangeEvent: function(listener) {
            dataChange.attach(listener);
        }
    }
}

function ModuleXX(moduleId, domId, sandbox, cfg) {
    var _moduleId = moduleId;
    var isSleep = true;
    var _domId = domId;
    var _sandbox = sandbox;
    var _cfg = cfg;
    var _model = new ModuleXXModel();
    var _view = new ModuleXXView(_domId, _model);

    function _handleNotify(messageInfo) {
        console.log(messageInfo.msg);
    }
    return {
        init: function() {
            setTimeout(function() {_model.getNumber();}, 5000);

            _sandbox.listen('cos', _moduleId, _handleNotify);
        },

        activate: function() {
            isSleep = false;

            _view.show();
        },

        deactivate: function() {
            isSleep = true;
        },

        destroy: function() {

        },

        refresh: function() {
           // tu nic nie robimy :) poprostu niech modul sobie pracuje nadal
        }
    }
}
