/** * Inizializza una seri e di variabile globali Javascript che * riportano le define PHP in Javascript */ var SCO_VERSION = '1.2.3'; var SCO_PATH_APPS = 'apps/'; var SCO_GATEWAY = 'index.php'; var SCO_OBJECTS = new Array(); /** * jQuery document ready */ $(document).ready( sco_init ); function sco_register( obj ) { SCO_OBJECTS.push( obj ); } /** * Funzione di inizializzazione del sistema */ function sco_init() { /** * jQuery UI patch (localizzazione) */ jQuery(function($){ $.datepicker.regional['it'] = { closeText: 'Chiudi', prevText: '<Prec', nextText: 'Succ>', currentText: 'Oggi', monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno', 'Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'], monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu', 'Lug','Ago','Set','Ott','Nov','Dic'], dayNames: ['Domenica','Lunedì','Martedì','Mercoledì','Giovedì','Venerdì','Sabato'], dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'], dayNamesMin: ['Do','Lu','Ma','Me','Gio','Ve','Sa'], dateFormat: 'dd/mm/yy', firstDay: 1, isRTL: false}; $.datepicker.setDefaults($.datepicker.regional['it']); }); /** * jQuery UI Dialog global options setting */ // $.ui.dialog.defaults.shadow = false; $.extend($.ui.dialog.defaults, { bgiframe : true, closeOnEscape : false, modal : false }); // Shadowbox.init(); // sco_initNavigation(); // for( var i = 0; i < SCO_OBJECTS.length; i++ ) SCO_OBJECTS[i].main(); } /** * Eventi sulla barra di navigazione principale */ function sco_initNavigation() { // $('div#sco_navigation ul li a img') // .hover( // function() { // $(this).stop().animate( {width: '128px', height: '128px', marginTop: '-64px' } ); // }, // function() { // $(this).stop().animate( {width: '64px', height: '64px', marginTop: '0' } ); // } // ); //$('div#sco_navigation ul li a img') $('img.sco_icon') .css( { opacity: '.5' } ) .hover( function() { $(this).stop().animate( { opacity: '1' } ); }, function() { $(this).stop().animate( { opacity: '.6' } ); } ); } /** * Carica una particolare applicazione in base all'id */ function sco_loadApplication( id ) { document.location = "/?SCO_APP_ID=" + id; } /** * Inizializza eventuali listview di sistema. Questa funzione * si preoccupa di generare le righe alternate nel background * associa l'effetto di mouseover e gestisce la selezione di * un elemento in lista. * * TODO:in futuro potrebbe gestire dei parametri * */ function scoLV_initListView() { $('table.sco_listview tbody tr:even') .css( 'background-color', '#eee' ) .data( 'bgcolor','#eee' ) .next() .css( 'background-color', '#fff' ) .data( 'bgcolor','#fff' ); $('table.sco_listview tbody tr') .data("selected", false) .click( function() { var num_sel = ( $('table.sco_listview').data('selectedRows') == undefined ) ? 0 : $('table.sco_listview').data('selectedRows'); if( !$(this).data("selected") ) { $(this).data( "selected", true); $(this).stop().animate( { backgroundColor: '#cdf' } ).css("fontWeight","bold"); num_sel++; } else { $(this).data( "selected", false); $(this).stop().animate( { backgroundColor: $(this).data('bgcolor') } ).css("fontWeight","normal"); num_sel--; } $('table.sco_listview').data('selectedRows', num_sel ); scoLV_updateRowsStatus(); } ) .hover( function() { if( !$(this).data("selected") ) $(this).stop().animate( { backgroundColor: '#cdf' } ); }, function() { if( !$(this).data("selected") ) $(this).stop().animate( { backgroundColor: $(this).data('bgcolor') } ); } ) .css( "cursor", "pointer"); scoLV_updateRowsStatus(); } /** * Seleziona tutti gli elementi di una lista * */ function scoLV_selectAllItems() { $('table.sco_listview tbody tr').data( "selected", true ).animate( { backgroundColor: '#cdf' } ).css("fontWeight","bold"); $('table.sco_listview').data('selectedRows', Number( $('table.sco_listview tbody tr').length ) ); scoLV_updateRowsStatus(); } /** * Aggiorna la "statusbar" di un ListView */ function scoLV_updateRowsStatus() { var tot = $('table.sco_listview tbody tr').length; var sel = ( $('table.sco_listview').data('selectedRows') > 0) ? ', Selezionati: ' + $('table.sco_listview').data('selectedRows') : ', Nessun elemento selezionato'; $('table.sco_listview tfoot th').eq(0).html( 'Totale: ' + tot + sel ); } /** * Rimuove dal List View le righe selezionate, cio� * che hanno data( "selected" ) = true */ function scoLV_removeSelectedItems() { $('table.sco_listview tbody tr').each( function(i,e) { if( $(e).data( "selected" ) ) { $(e).remove(); var tot = $('table.sco_listview').data('selectedRows') - 1; $('table.sco_listview').data('selectedRows', tot); } } ); scoLV_updateRowsStatus(); } /** * Mostra il box modale */ function sco_show_modal( v, cb ) { if( v ) $('div#sco_modal') .css( { height: $(document).height() + 'px' } ) .fadeIn( cb ); if( !v ) $('div#sco_modal').fadeOut(); } /** * Apre ua window modale */ function sco_open_modal_window( c ) { $('div#sco_modal') .css( { height: $(document).height() + 'px' } ) .fadeIn( function() { $('div#sco_extra') .html( '
'+c+'
' ) .fadeIn( 1000 ); } ); } /** * Visualizza o nasconde il gif di attesa Ajax e pone * il puntatore del mouse in modalit� clessidra */ function sco_showAjaxLoader( v ) { if( v ) { $('img#sco_ajax_wait').css({zIndex: '4000'}).fadeIn(); $('body').css('cursor','wait'); } if( !v ) { $('img#sco_ajax_wait').fadeOut(); $('body').css('cursor','default'); } } /** * Apre il dialog (jQuery UI) per l'aggiornamento dei dati personali * */ function sco_openEditUser() { sco_showAjaxLoader( true ); $.post( SCO_GATEWAY, { ajax_call : true, command : 'sco_get_user_form();' }, function( data ) { sco_showAjaxLoader( false ); $('body').append( data ); $('div#dialog_edit_user').dialog( { bgiframe : true, title : "Modifica i tuoi dati", modal : true, width : 700, height : 330, resizable : false, buttons : { 'Annulla' : function() { $(this).dialog('close').remove(); }, 'Modifica' : function() { sco_updateUser(); } }, open : function() { $('.ui-dialog-titlebar-close').css('display','none'); $('.ui-widget-shadow').css('display','none'); } } ); } ); } /** * Apre il dialog (jQuery UI) per l'informazioni sul sistema * */ function sco_openInformation() { sco_showAjaxLoader( true ); $.post( SCO_GATEWAY, { ajax_call : true, command : 'sco_get_information();' }, function( data ) { sco_showAjaxLoader( false ); $('body').append( data ); $('div#dialog_information').dialog( { bgiframe : true, title : "Informazioni", modal : true, width : 700, height : 500, resizable : false, buttons : { 'Chiudi' : function() { $(this).dialog('close').remove(); } }, open : function() { $('.ui-dialog-titlebar-close').css('display','none'); $('.ui-widget-shadow').css('display','none'); $('input#no-more-popup').change( function() { if( $(this).attr('checked') ) sco_setCookie('nomorepopup', "1", 10); else sco_deleteCookie('nomorepopup'); } ); } }); } ); } /** * Aggiorna un user tramite Ajax */ function sco_updateUser() { if( $( 'input#f_password' ).val() != $( 'input#s_password' ).val() ) { alert( 'ATTENZIONE!!\n\Le password inserito non coincidono!' ); $( 'input#s_password' ).val(''); $( 'input#f_password' ).val('').focus(); return; } var gateway = 'index.php'; sco_showAjaxLoader( true ); $.post( gateway, { ajax_call : true, command : 'sco_sco_updateUser_info();', name : $( 'input#name' ).val(), lastname : $( 'input#lastname' ).val(), email : $( 'input#email' ).val(), f_password : $( 'input#f_password' ).val() }, function( data ) { // sco_showAjaxLoader( false ); document.location = document.location.href; } ); } /** * Verifica che esista un cookie. In caso contrario ne restituisce * un valore di default * * @param {String} id Identificativo del cookie * @param {Any} d Valore di default * * @return Valore del cookie o valore di default * */ function sco_isset_cookie( id, d ) { return ( ( sco_getCookie( id ) == null ) ? d : sco_getCookie( id ) ); } /** * Queste tre funzioni non hanno bisogno di molte spiegazioni. Esse permettono di leggere * scrivere ed eliminare cookie. */ function sco_getCookie( name ) { var start = document.cookie.indexOf(name+"="); var len = start+name.length+1; if ((!start) && (name != document.cookie.substring(0,name.length))) return(null); if (start == -1) return(null); var end = document.cookie.indexOf(";",len); if (end == -1) end = document.cookie.length; return(unescape(document.cookie.substring(len,end)) ); } // set function sco_setCookie(name, value, expiredays, path, domain, secure) { var expires = new Date(); expires.setDate( expires.getDate() + expiredays ); var cookieString = name + "=" +escape(value) + ( (expires) ? ";expires=" + expires.toGMTString() : "") + ( (path) ? ";path=" + path : "") + ( (domain) ? ";domain=" + domain : "") + ( (secure) ? ";secure" : ""); document.cookie = cookieString; } // delete function sco_deleteCookie(name, path, domain) { if (sco_getCookie(name)) document.cookie = name + "=" + ( (path) ? ";path=" + path : "") + ( (domain) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-70 00:00:01 GMT"; }