tags:

views:

1290

answers:

3

I have a border layout in ExtJS,

The north region contains some HTML, but also needs to contain a toolbar like this...

So i've managed to get the border layout set up, added the html to the North Region of the layout, but I can't find any workable examples of how to implement a tool bar.

I have found lot's of examples of toolbars on their own, but I've not got the luxury or learning ExtJs thoroughly so it's all greek to me.

I suspect there's a way to define a tool bar outside of the cumbersome JSON style flow of creating a layout and somehow attaching it to the region, and I'm hoping it's relativley simple to do. If someone can explain how I'd do this, it would really help.

Here's the code so far...

//make sure YOUR path is correct to this image!!
Ext.BLANK_IMAGE_URL = '../../ext-2.0.2/resources/images/default/s.gif';


//this runs on DOM load - you can access all the good stuff now.

Ext.onReady(function(){
    var viewport = new Ext.Viewport({
        layout: "border",
        border: false,
        renderTo: Ext.getBody(),
        items: [


        // ------------------------------------------------------------------
        {
            region: "north",
            id : "toolbar-area",
            xtype: 'panel',
            html: [ "<div id=\"html-header\">",
                    "<div id=\"council-logo\"></div>",
                    "<ul id=\"ancillary-menu\">",
                        "<li><a href=\"#\">Logout</a></li>",
                        "<li><a href=\"#\">Gazeteer Home</a></li>",
                        "<li>Hello Rachel</li>",
                    "</ul>",
                    "<img id=\"inteligent-logo\" src=\"applied-images/logos/inteligent.gif\">",
                    "</div>" ],

            /* ++++++++++++++++++++++++++++++++++++++++++++ */
            /* The toolbar needs to go around here....      */
            /* ++++++++++++++++++++++++++++++++++++++++++++ */

            height: 100
        },

        // ------------------------------------------------------------------
        // WEST
        // ------------------------------------------------------------------
        {
            region: 'west',
            xtype: 'panel',
            split: true,
            resizeable: false,
            maxWidth : 350,
            minWidth : 349,
            collapsible: true,
            title: 'Gazetteer Explorer',
            width: 350,
            minSize: 150,

            // --------------------------------------------------------------

            title: 'Nested Layout',
            layout: 'border',
            border: false,
            id: "west",
            items: [

                {
                    // ***********************************************
                    // Search Form
                    // ***********************************************

                    region : "north",
                    height: 300,
                    split : true,
                    id : "left-form-panel",
                    items : [{

                        xtype : "form",
                        id : "search-form",
                        items : [

                            // Authority combo box
                            // ===============================
                            {
                                xtype : "combo",
                                fieldLabel : "Authority",
                                name : "authority",
                                hiddenName : "authority",
                                id : "authority-combo"
                            },
                            // ===============================

                            // Search Fieldset
                            // ===============================
                            {
                                xtype : "fieldset",
                                autoHeight : true,
                                title : "Search by...",
                                id : "search-fieldset",
                                items : [

                                    // Ref Number text Box
                                    // %%%%%%%%%%%%%%%%
                                    {

                                        xtype : "textfield",
                                        name : "ref-number",
                                        fieldLabel : "Ref. Number",
                                        id : "ref-number-textfield"

                                    },
                                    // %%%%%%%%%%%%%%%%
                                    // Streetname Combo
                                    // %%%%%%%%%%%%%%%
                                    {

                                        xtype : "combo",
                                        name : "street-name",
                                        hiddenName : "street-name",
                                        fieldLabel : "Street Name",
                                        id : "street-name-combo"

                                    },
                                    // %%%%%%%%%%%%%%%%
                                    // Postcode Combo
                                    // %%%%%%%%%%%%%%%%
                                    {

                                        xtype : "combo",
                                        name : "postcode",
                                        hiddenName : "postcode",
                                        fieldLabel : "Postcode",
                                        id : "postcode-combo"

                                    },
                                    // %%%%%%%%%%%%%%%%

                                    // Postcode Combo
                                    // %%%%%%%%%%%%%%%%
                                    {

                                        xtype : "combo",
                                        name : "town",
                                        hiddenName : "town",
                                        fieldLabel : "Town",
                                        id : "towm-combo"

                                    },
                                    // %%%%%%%%%%%%%%%%

                                    // Postcode Combo
                                    // %%%%%%%%%%%%%%%%
                                    {

                                        xtype : "combo",
                                        name : "locality",
                                        hiddenName : "locality",
                                        fieldLabel : "Locality",
                                        id : "locality-combo"

                                    },
                                    // %%%%%%%%%%%%%%%

                                     // Search Button
                                    // %%%%%%%%%%%%%%%%

                                    {
                                        xtype : "button",
                                        text : "Search",
                                        id : "search-button"
                                    },  

                                    // Reset Button
                                    // %%%%%%%%%%%%%%%

                                    {
                                        xtype : "button",
                                        text : "Reset",
                                        id : "reset-button"
                                    } 


                                ]
                            },
                            // =======================


                        ]

                    }]

                    // *********************************************

                },

                {
                    region: 'center',
                    html: 'Tree view goes here'
                }

            ]



        },

        // ------------------------------------------------------------------
        {
            region: 'center',
            xtype: 'panel',


            // --------------------------------------------------------------
              layout: 'border',
              border: false,
              items: [

                  {
                    region: 'center',
                    height: 200,
                    split: true,
                    html: 'Map goes here'
                  },

                  {
                    region: 'south',
                    title: "Selection", 
                    split: true,
                    height: 200,
                    collapsible: true,
                    html: 'Nested Center'
                  }

              ]
        },

        // ------------------------------------------------------------------
        {
            region: 'east',

        },

        // ------------------------------------------------------------------

        {
            region: 'south',
        }]


    }); 
});

Sorry there's so much code, but ExtJS makes me scared to touch anything that's working.

A: 

ExtJS has a built-in toolbar.

You can see an example here:

mojbro
i've found all the examples like this, but for a novice, it's of no use. I should point out, I've not opted to use ExtJS, it's been forced upon me. I have no experience with it at all. I did point this out to the client before I started and was assured of technical assistance which hasn't manifested itself. What I need to know is how this toolbar code relates to regions in a border layout.
gargantaun
+1  A: 

just add

bbar: [
   // YOUR ITEMS HERE EXAMPLE FOLLOWING
   {
       xtype: 'button',
       text: 'test Button',
       handler: function(btn){
           alert('Button Click');
       }
   }
]

to your config (where xtype === panel)

it would look like something like this :

    {
        region: "north",
        id : "toolbar-area",
        xtype: 'panel',
        html: [ "<div id=\"html-header\">",
                "<div id=\"council-logo\"></div>",
                "<ul id=\"ancillary-menu\">",
                    "<li><a href=\"#\">Logout</a></li>",
                    "<li><a href=\"#\">Gazeteer Home</a></li>",
                    "<li>Hello Rachel</li>",
                "</ul>",
                "<img id=\"inteligent-logo\" src=\"applied-images/logos/inteligent.gif\">",
                "</div>" 
              ],
        bbar: [
           {
               xtype: 'button',
               text: 'test Button',
               handler: function(btn){
               alert('Button Click');
           }
        ],
        height: 100
    }
Nexum
+2  A: 

@Nexum's answer is correct, but to add a little more context, every region of a BorderLayout is actually an Ext.Panel, so any config that you can use for panels can be applied to a region. For toolbars, look at the Ext.Panel docs for tbar (top toolbar) and bbar (bottom toolbar).

On an unrelated note, I see that you are manually creating a bunch of HTML in code for the north panel contents. This is a recipe for pain. It's much easier for nontrivial markup to add it in the page as standard HTML with a surrounding div. Give the div an id and a class of x-hidden, then pull it in using the contentEl Panel config.

bmoeskau
hm i want to add that a region in an ext vieport can be everything extended from Ext.Component, so a region could as well directly a toolbar or a well a formpanel or dataview. just in cae someone gets confused :-) vote up for you here :)
Nexum
Actually, when I say "region" I mean an Ext.BorderLayout.Region. Some other component like a DataView could be added to a container as you say, but it would not technically be a "region" in that case.
bmoeskau