 
Ext.BLANK_IMAGE_URL = './ext/resources/images/default/s.gif';
Ext.ns('GeoPrisma');
 
GeoPrisma.app = new Ext.App({});
 
// application main entry point
Ext.onReady(function() {
 
    Ext.QuickTips.init();
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
    
    var tools = [{
        id:'gear',
        handler: function(){
            Ext.Msg.alert('Message', 'The Settings tool was clicked.');
        }
    }];
   
    var snifferGrid = new GeoPrisma.Test.Sniffer.Grid();
    var snifferStateView = new GeoPrisma.Test.Sniffer.DataView();
    var homeSnifferStateView = new GeoPrisma.Test.Sniffer.DataView();
  
    var phpUnitGrid = new GeoPrisma.Test.PHPUnit.Grid();
    var phpUnitStateView = new GeoPrisma.Test.PHPUnit.DataView(); 
    var homePhpUnitStateView = new GeoPrisma.Test.PHPUnit.DataView();
    
    var viewport = new Ext.Viewport(   
    {
        layout: 'fit',
        items: [    
        {
            layout: 'border',
            items: [{
                region: 'north',
                height: 50,
                xtype: 'container',
                border: false,
                items : [{      
                    xtype : 'box',
                    autoEl: {tag: 'img', src: 'img/geoprisma.png'}
                }]              
            },{
                region: 'center',
                xtype: 'tabpanel', // TabPanel itself has no title
                activeTab: g_activeTab,

                items: [{
                    title: 'Home', 
                    
                    xtype:'portal',
                    region:'center',
                    margins:'35 5 5 0',
                    items:[{
                        columnWidth:.66,
                        style:'padding:10px 0 10px 10px',
                        items:[{
                            xtype: 'container',
                            title: 'Welcome',
                            height: 200,
                            cls : 'welcome-panel'                        
                        },{
                            title: 'Samples list',
                            layout:'fit',
                            tools: tools,
                            items: { 
                                xtype      : 'panel',
                                height     : 300,
                                autoScroll : true,
                                cls        : 'all-demos',
                                items : new GeoPrisma.Sample.DataView({autoHeight: false, height:400})
                            }
                        }]
                    },{
                        columnWidth: .33,
                        style:'padding:10px 0 10px 10px',
                        items:[{
                            title: 'Collaboration',
                            layout:'fit',
                            items: { 
                                xtype: 'panel',
                                html:
                                     '<a href="http://trac.osgeo.org/geoprisma/" target="_blank">Trac url</a><br/>'+
                                     '<a href="https://svn.osgeo.org/geoprisma/projects/geoprisma/trunk" target="_blank">SVN url</a><br/>'+
                                     '<a href="http://lists.osgeo.org/mailman/listinfo/geoprisma-dev" target="_blank">GeoPrisma-dev mailing list</a><br/>'+
                                     '<a href="http://n3.nabble.com/GeoPrisma-dev-f25947.html" target="_blank">GeoPrisma-dev on Nabble</a><br/>'+
                                     '<a href="http://lists.osgeo.org/mailman/listinfo/geoprisma-users" target="_blank">GeoPrisma-users mailing list</a><br/>'+
                                     '<a href="http://n3.nabble.com/GeoPrisma-users-f26231.html" target="_blank">GeoPrisma-users on Nabble</a>'                
                            }
                        },{
                            title: 'Traffic stats',
                            layout:'fit',
                            items: { 
                                xtype: 'panel',
                                html:'<a href="http://geoprisma.org/awstats/awstats.pl?config=geoprisma.org" target="_blank">AWStats report</a><br/>'+
                                     '<a href="http://geoprisma.org/betterawstats/index.php" target="_blank">BetterAWStats report</a>'                
                            }
                        },{
                            title: 'Documentation',
                            layout:'fit',
                            items: { 
                                xtype: 'panel',
                                html:'<a href="../dist/build/html/index.html" target="_blank">General Documentation</a> <br/>'+
                                     '<a href="../dist/doc/index.html" target="_blank">PHP API Documentation</a> <br/>'+
                                     '<a href="../dist/naturaldoc/index.html" target="_blank">JS API Documentation</a><br/>'+
                                     '<a href="../docs/presentations/geoprisma-presentation-2009-Sept-EN.pdf" target="_blank">FOSS4G Presentation (pdf)</a> - <font color="red"><b>(new)</b></font>'                                     
                            }
                        },{
                            title: 'Hudson',
                            layout:'fit',
                            items: { 
                                xtype: 'panel',
                                html:'Continuous integration engine : <a href="http://osm.vm.boreal-is.com:8080/" target="_blank">go</a>'                
                            }
                        },{
                            title: 'Download',
                            layout:'fit',
                            items: new GeoPrisma.Release.Panel()
                        },{
                            title: 'Trunk state',
                            layout: {
                                    type:'vbox',                                    
                                    align:'stretch'
                                },
                            height: 300,                
                            padding:'10',                                      
                            items: [{ 
                                xtype:'fieldset', 
                                title: 'Code sniffer state',
                                height:120,
                                items : [homeSnifferStateView]
                            },{ 
                                xtype:'fieldset', 
                                title: 'PHP unit state',
                                height:120,
                                items : [homePhpUnitStateView]
                            }                            
                            ]
                        }                                       
                        ] 
                    }]           
                },{
                    title: 'Download',
                    layout:'fit',
                    items: new GeoPrisma.Release.Panel()
                },{
                    title: 'Documentation',
                    
                    xtype: 'tabpanel', 
                    activeTab: 0,

                    items: [{
                        title: 'General',   
                        xtype: 'panel',
                        layout : 'fit',
                        
                        tbar : [ {
                            text: 'Build',
                            handler: function(button){
                                button.disable();
                                button.setText('Build in progress...');
                                Ext.Ajax.request({
                                   url: 'php/service/doc/build_gen_doc.php',
                                   success: function(response, opts) {                                      
                                                                            
                                        this.enable();
                                        this.setText('Build');
                                        var iframe = Ext.get('php_gen_iframe');

                                        var dt = new Date();
                                        iframe.dom.src = iframe.dom.src + '?force=' + dt.format('U');        

                                        Ext.Msg.show({
                                            title:'General DOC Build end',
                                            msg: '<div class="build-result"><pre>' + response.responseText + '</pre></div>',
                                            buttons: Ext.Msg.OK,                                        
                                            icon: Ext.MessageBox.QUESTION
                                        });
                                      
                                   },
                                   failure: function(response, opts) {
                                       Ext.Msg.alert('Error', 'server-side failure with status code ' + response.status);
                                       this.enable();
                                       this.setText('Build');
                                   },
                                   scope : button                                 
                                });
                            }
                        }],
                                                
                        items: {                        
                            xtype : 'box',
                            autoEl: {id : 'php_gen_iframe', tag: 'iframe', src: '../dist/build/html/index.html'}
                        } 

                    },{
                        title: 'PHP',
                        xtype: 'panel',
                        layout : 'fit',
                        
                        tbar : [ {
                            text: 'Build',
                            handler: function(button){
                                button.disable();
                                button.setText('Build in progress...');
                                Ext.Ajax.request({
                                   url: 'php/service/doc/build_php_doc.php',
                                   success: function(response, opts) {                                      
                                                                         
                                      this.enable();
                                      this.setText('Build');
                                      var iframe = Ext.get('php_doc_iframe');
                                      
                                      var dt = new Date();
                                      iframe.dom.src = iframe.dom.src + '?force=' + dt.format('U');  
                                      
                                      Ext.Msg.show({
                                            title:'PHP DOC Build end',
                                            msg: '<div class="build-result"><pre>' + response.responseText + '</pre></div>',
                                            buttons: Ext.Msg.OK,                                        
                                            icon: Ext.MessageBox.QUESTION
                                        });      
                                   },
                                   failure: function(response, opts) {
                                       Ext.Msg.alert('Error', 'server-side failure with status code ' + response.status);
                                       this.enable();
                                       this.setText('Build');
                                   },
                                   scope : button                                 
                                });
                            }
                        }],
                                                
                        items: {                        
                            xtype : 'box',
                            autoEl: {id : 'php_doc_iframe', tag: 'iframe', src: '../dist/doc/index.html'}
                        } 
                    },{
                        title: 'JS',
                        
                        xtype: 'panel',
                        layout : 'fit',
                        
                        tbar : [ {
                            text: 'Build',
                            handler: function(button){
                                button.disable();
                                button.setText('Build in progress...');
                                Ext.Ajax.request({
                                   url: 'php/service/doc/build_js_doc.php',
                                   success: function(response, opts) {                                      

                                      this.enable();
                                      this.setText('Build');
                                      var iframe = Ext.get('php_js_iframe');
                                      
                                      var dt = new Date();
                                      iframe.dom.src = iframe.dom.src + '?force=' + dt.format('U');   
                                      
                                      Ext.Msg.show({
                                            title:'JS DOC Build end',
                                            msg: '<div class="build-result"><pre>' + response.responseText + '</pre></div>',
                                            buttons: Ext.Msg.OK,                                        
                                            icon: Ext.MessageBox.QUESTION
                                        });     
                                   },
                                   failure: function(response, opts) {
                                       Ext.Msg.alert('Error', 'server-side failure with status code ' + response.status);
                                       this.enable();
                                       this.setText('Build');
                                   },
                                   scope : button                                 
                                });
                            }
                        }],
                                                
                        items: {                        
                            xtype : 'box',
                            autoEl: {id : 'php_js_iframe', tag: 'iframe', src: '../dist/naturaldoc/index.html'}
                        }  
                    }]
                },{
                    title: 'Samples',
                    xtype:'panel',
                    autoScroll : true,
                    layout:'anchor',
                    items:[ 
                        { 
                            border: false,
                            xtype:'panel',                                
                            autoHeight:true,
                            cls: 'all-demos',
                            items : new GeoPrisma.Sample.DataView()
                        }
                        
                    ]                    
                    
                },{
                    title: 'Developer tools',
                    xtype: 'tabpanel', 
                    activeTab: 0,
                    
                    
                    items: [{
                        title: 'Code sniffer',   
                        xtype: 'panel',
                        padding:'10',
                        layout: {
                                    type:'vbox',                                    
                                    align:'stretch'
                                },                
                        tbar : [ {
                            text: 'Test',
                            handler: function(button){
                                button.disable();
                                button.setText('Test in progress...');
                                Ext.Ajax.request({
                                   url: 'php/service/test/test_sniffer.php',
                                   success: function(response, opts) {                                      
                                                                            
                                        this.enable();
                                        this.setText('Test');
                                        

                                        snifferGrid.store.load({force:true});
                                        snifferStateView.store.load({force:true});
                                        homeSnifferStateView.store.load({force:true});
                                        
                                        Ext.Msg.show({
                                            title:'Code sniffer test end',
                                            msg: '<div class="test-result"><pre>' + response.responseText + '</pre></div>',
                                            buttons: Ext.Msg.OK,                                        
                                            icon: Ext.MessageBox.QUESTION
                                        });
                                      
                                   },
                                   failure: function(response, opts) {
                                       Ext.Msg.alert('Error', 'server-side failure with status code ' + response.status);
                                       this.enable();
                                       this.setText('Test');
                                   },
                                   scope : button                                 
                                });
                            }
                        }],
                                                
                        items: [{

                            height:20,                            
                            layout: 'fit',
                            
                            xtype : 'box',
                            autoEl: {tag: 'div', html: 'Code sniffer checks programming rules in php files and lists all errors and warnings'}
                            
                        },{
                            
                            height:120,                            
                            layout: 'fit',
                            title:'State',
                            xtype : 'panel',
                            frame : true,
                            margins:'0 0 5 0',
                            items: [snifferStateView] 
                        },{  
                            flex:1,
                            layout: 'fit',
                            title:'Error & Warning list',
                            xtype : 'panel', 
                            items: [snifferGrid]
                        }] 
                             
                    },{
                        title: 'PHP Unit',   
                        xtype: 'panel',
                        padding:'10',
                        layout: {
                                    type:'vbox',                                    
                                    align:'stretch'
                                },                
                        tbar : [ {
                            text: 'Test',
                            handler: function(button){
                                button.disable();
                                button.setText('Test in progress...');
                                Ext.Ajax.request({
                                   url: 'php/service/test/test_phpunit.php',
                                   success: function(response, opts) {                                      
                                                                            
                                        this.enable();
                                        this.setText('Test');
                                        
                                        
                                        phpUnitGrid.store.load({force:true});
                                        phpUnitStateView.store.load({force:true});
                                        homePhpUnitStateView.store.load({force:true}); 
                                        
                                        var iframe = Ext.get('code_coverage_iframe');                                   
                                        var dt = new Date();
                                        iframe.dom.src = iframe.dom.src + '?force=' + dt.format('U');
                                        
                                        Ext.Msg.show({
                                            title:'PHP Unit test end',
                                            msg: '<div class="build-result"><pre>' + response.responseText + '</pre></div>',
                                            buttons: Ext.Msg.OK,                                        
                                            icon: Ext.MessageBox.QUESTION
                                        });
                                      
                                   },
                                   failure: function(response, opts) {
                                       Ext.Msg.alert('Error', 'server-side failure with status code ' + response.status);
                                       this.enable();
                                       this.setText('Test');
                                   },
                                   scope : button                                 
                                });
                            }
                        }],
                                                
                        items: [{

                            height:20,                            
                            layout: 'fit',
                            
                            xtype : 'box',
                            autoEl: {tag: 'div', html: 'PHP Unit test the geoprisma core its work normally'}
                            
                        },{
                            
                            height:120,                            
                            layout: 'fit',
                            title:'State',
                            xtype : 'panel',
                            frame : true,
                            margins:'0 0 5 0',
                            items: [phpUnitStateView] 
                        },{  
                            flex:1,
                            layout: 'fit',
                            title:'Error & Failure list',
                            xtype : 'panel', 
                            items: [phpUnitGrid]
                        }] 
                             
                    },{
                        title: 'Code coverage',
                        xtype: 'panel',
                        layout : 'fit',                    
                                                
                        items: {                        
                            xtype : 'box',
                            autoEl: {id : 'code_coverage_iframe', tag: 'iframe', src: '../dist/coverage/index.html'}
                        } 
                    }]
                },{
                    title: 'Contributors',
                    autoLoad:'contributors.html'
                },{
                    title: 'License',
                    autoLoad:'../license/index.html'
                } ]
            }]
        }]
    });   

}); // eo function onReady
 
// eof
