/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

orion_users_notify = {
    list : function(){
        var listado;
        $.getJSON('/NebulaTools/users_notify/list', {
            'cuack':1
        }, function(data){
            listado = data.prototype;
        });

        return listado;
    },

    close : function(nid){
        var url = '/NebulaTools/users_notify/close';
        $.post(url, {
            'nid':nid
        }, function(response){
            var errores = false;
            //return response;
            //form_processJson(response);
            var errors = 'errors' in response? response.errors : "";
            if(errors.length > 0){
                //form_messages_show(errors);
                errores = true;
            }

            return errores;

        }, "json");
    },

    /**
     * muestra en pantalla las notificaciones al usuario
     * y permite cerrarlas
     */
    writemessage : function(){
//        var listado = orion_users_notify.list();
//        $.each(listado, function(i,coso){
//                alert(coso.news);
//        });

        jQuery.getJSON('/NebulaTools/users_notify/list', {
            'cuack':1
        }, function(data){
            //alert(data[1].news);
            var msg = '';
            jQuery.each(data, function(i,coso){
                var boton_cerrar =  '<a href="javascript:;" onclick="orion_users_notify.close('+coso.NotifyID+');jQuery(\'#Dmsg'+coso.NotifyID+'\').remove();">';
                boton_cerrar += '<img title="close" border="0" src="/Orion/factory/NebulaTools/resources/icons/16/remove.png"/></a>';
                var Dmsg = '<div class="div_Dmsg" id="Dmsg'+coso.NotifyID+'"><div class="newsMsg">'+coso.news+'</div> <div class="btnClose">'+boton_cerrar+'</div></div>';

                msg += Dmsg;

            });
            //alert(msg);

           jQuery('div#writemessage').append(msg);

        });
    }
}


