01/02/2011 Development / java script

        var profile = [{
            pagina: 'pagina1',
            thema: 'thema1',
            id: new Date().getDate(),
            perfil: 1,
            widgets: [{}],
            using: true
        }];
       
        function Controller() {
            this.oProfile = [];
        };

        Controller.prototype.loadprofile = function(p) {
            this.oProfile = p;
        };


    Controller.prototype.saveProfile = function() {

        var pagina = 'novapagina';

        /*if (pagina == getPage(pagina)) {
            alert('pagina jã existe');
            return false;
        }*/

        var o = {
            'pagina': pagina,
            'thema': 'thema2',
            'id': new Date().getDate(),
            'perfil': '2',
            'widgets': this.fullWidgets(),
            using: false

        }

        this.oProfile.push(o);
        var p = this.oProfile;
        alert(jQuery.toJSON(p));
    }
   
    /* retorna todos os wifgets da pagina atual */
    Controller.prototype.fullWidgets = function() {
        var widgets = [{ 'type': 'book' }, { 'type': 'book' }, { 'type': 'book' }, { 'type': 'book'}];
        return widgets;
    }

    var hb = new Controller();
    hb.loadprofile(profile);
    hb.saveProfile();