Autohide a viewport's region in Extjs - extjs

Lets suppose i have the following code snippet:
Ext.create('Ext.container.Viewport', {
layout: 'border',
renderTo: Ext.getBody(),
items: [{
region: 'north',
html: '<h1 class="x-panel-header">Page Title</h1>',
autoHeight: true,
border: false,
margins: '0 0 5 0'
}, {
region: 'west',
collapsible: true,
title: 'Navigation',
width: 150
// could use a TreePanel or AccordionLayout for navigational items
}, {
region: 'south',
title: 'South Panel',
collapsible: true,
html: 'Information goes here',
split: true,
height: 100,
minHeight: 100
}, {
region: 'east',
title: 'East Panel',
collapsible: true,
split: true,
width: 150
}, {
region: 'center',
xtype: 'tabpanel', // TabPanel itself has no title
activeTab: 0, // First tab active by default
items: {
title: 'Default Tab',
html: 'The first tab\'s content. Others may be added dynamically'
}
}]
});
What i want to do is to have the north toolbar to be hidden automatically when the mouse is moved away from the north region and unhidden when the mouse is hovered on north region(exactly like autohide in windows start menu)

You could use the collapse functionality to achieve this. Create a placeholder that replaces the standard Header:
var placeHolder = Ext.create('Ext.panel.Panel', {
height: 5,
listeners: {
mouseover : {
element : 'el',
fn : function(){
//Expand the north region on mouseover
Ext.getCmp('region-north').expand();
}
}
}
});
Configure the north region to be collapsible and use the placeholder above as Collapsed-header-replacement:
...
items: [{
region: 'north',
html: '<h1 class="x-panel-header">Page Title</h1>',
autoHeight: true,
border: false,
id: 'region-north',
margins: '0 0 5 0',
collapsible: true,
collapsed: true,
placeholder: placeHolder,
preventHeader: true,
listeners: {
mouseleave: {
element: 'el',
fn: function() {
Ext.getCmp('region-north').collapse();
}
}
}
},
...
This way you can let Ext worry about the layout and keep the collapse functionality.

create a panel that sets its height to 1px when the mouse is not on it, and sets its height to 300px when the mouse is on it.
Ext.create('Ext.panel.Panel',{
renderTo : 'summary-div',
height : 300,
listeners : {
mouseover : {
element : 'el',
fn : function(){
this.setHeight(300);
}
},
mouseleave : {
element : 'el',
fn : function(){
this.setHeight(1);
}
}
}
});

Related

An accordion layout inside a tab, inside a border layout gives me slider bars when the region is resized. Only happens in Chrome.

I'm getting started on Ext using Ext JS 4 and I'm running with a strange behavior on Google Chrome.
I have a viewport with a fit layout. Inside it, I have a panel with a border layout.
It has a southern region, a western region, and a central region.
The western region has a tabpanel, and inside the first tab I have an accordion panel.
The problem is that when I collapse a panel, or reduce the size of the western region, in Chrome I get evil slider bars. On firefox it works just fine, it only happens in Chrome.
It doesn't happen when I'm on the tab 2 (the one that doesn't have the accordion panel).
Any idea of what could be the problem?
These are pictures depicting the problem: http://imgur.com/a/vgbcE
Here is the source code:
Ext.application({
name: 'HelloExt',
launch: function()
{
var viewPort = Ext.create('Ext.container.Viewport', {
layout: 'fit',
renderTo: 'layout'
});
var mainLayout = Ext.create('Ext.panel.Panel', {
width: 'auto',
layout: 'border',
title : 'Gis Web',
collapasible: true,
defaults: {
split: true,
border: false,
collapsible: true,
manageOverflow: 2
},
items: [
{
region: 'center',
collapsible: false,
id: 'center-panel',
border: true
},
{
id: 'south-panel',
region: 'south',
height: 100
},
{
id: 'west-panel',
region: 'west',
width: 200,
layout: 'fit'
}
]
});
var accordionPanel = Ext.create('Ext.panel.Panel', {
id: 'accordion-panel',
layout: 'accordion',
tabBar: {
plain: true
},
border: false,
items: [
{
id: 'accordion-1',
title: '1'
},
{
title: '2'
}
]
});
var tabPanel = Ext.createWidget('tabpanel', {
activeTab: 0,
defaults: {
autoScroll: true,
border: false
},
layout: 'fit',
items: [
{
id: 'tab-1',
title: 'Tab 1',
layout: 'fit'
},
{
layout: 'fit',
title: 'Tab 2'
}
]
});
Ext.getCmp('tab-1').add(accordionPanel);
var panel = Ext.getCmp('west-panel');
panel.add(tabPanel);
viewPort.add(mainLayout);
}
});
Try this for west panel :
{
id: 'west-panel',
region: 'west',
width: 200,
title: 'west panel',
xtype: 'tabpanel',
activeTab: 0,
defaults: {
//autoscroll removed !!!
//autoScroll: true,
border: false
},
items: [
{
id: 'tab-1',
title: 'Tab 1',
layout: 'fit'
},
{
layout: 'fit',
title: 'Tab 2'
}
]
}

How can I change percentage of the viewport in browser?

My viewport fits all browser but I want this to fit only 80% of browser's width. How can I do it?
This is my code below maybe you want to see it.
This is my viewport code:
var view = new Ext.Viewport({
layout: 'border',
autoScroll: true,
border: true,
items:[header,menuBar
,{
region: 'south',
collapsible: false,
padding: '25 25 25 25' ,
html:'Sanguis Team 2012',
border: true,
height: 100
},content
]
});
Ext.onReady(function(){
//var topHTML = '<img style="margin-left: 5px" src="Google_maps_logo.png" alt="logo" height="60" width="380">';
//Ext.BLANK_IMAGE_URL = 'extjs/resources/images/default/s.gif';
Ext.QuickTips.init();
var item1 = new Ext.Panel({
title: 'Kan Bağışı',
collapsible : true,
collapsed: true,
padding: '5 5 5 5' ,
html: 'Nerede Kan verebilirim?<br/>' +
'Kan Bağışlama Süreci'
});
var item2 = new Ext.Panel({
title: 'Kan Hakkında',
collapsed: true,
padding: '5 5 5 5' ,
collapsible : true,
html: 'Kanın Yapısı ve Görevleri Nelerdir?<br/>' +
'Kan Bağışlarım Nerede kullanılıyor<br/>'+
'Kan Grupları Hakkında Bilgiler<br/>'+
'Kana Yapılan Testler<br/>'+
'Dünya ve Türkiyede Kan Bağışı'
});
var item3 = new Ext.Panel({
title: '<a style="color: #FFFFFF;" href="#">Sıkça Sorulan Sorular</a>',
collapsible :false,
titleCollapse: false
});
var item4 = new Ext.Panel({
title: 'Site Kullanımı',
collapsed: true,
padding: '5 5 5 5' ,
collapsible : true,
html: 'Site Nasıl Çalışmaktadır<br/>' +
'Kan İsteğinde Nasıl Bulunabilirim?<br/>'
});
var item5 = new Ext.Panel({
padding: '5 5 5 5' ,
title: 'Kullanıcı Girişi',
bodyStyle : 'padding : 10px',
layout : 'form',
items: [
{
xtype: 'field',
fieldLabel: 'E-posta',
width: 100
},{
xtype: 'field',
fieldLabel: 'Şifre',
inputType:'password',
width: 100
},
{
xtype: 'button',
text: 'Giriş',
style: {
marginLeft: '170px'
},
align: 'right',
handler : function(btn){
Ext.MessageBox.alert('','kontrol yapılacak!!');
}
},
{
border : false,
html:'Şifremi Unuttum'
}
]
});
var item6 =new Ext.Panel({
border: false,
html: '<img src="../images/kaydol.jpg" />'
});
var menuBar = new Ext.Panel({
//layout: 'accordion',
autoScroll: true,
defaults: {autoScroll: true},
region: 'west',
width: 310,
defaults: {
hideCollapseTool : false,
//border: true
},
layoutConfig: {
// titleCollapse: false,
animate: true,
// activeOnTop: true,
autoScroll: true
},
margins:'5 0 5 5',
split:false,
items: [item1, item2, item4, item3, item5,item6]
});
var content = new Ext.Panel({
region: 'center',
autoScroll: true,
margins:'5 5 5 0',
layoutConfig : {
align : 'stretch'
},
html:'Ajax content will come here'
});
var header=new Ext.Panel({
renderTo: document.body,
layout: 'fit',
region: 'north',
html: '<p align="center"><img src="../images/banner.jpg" align="middle"/></p>',
height:150,
tbar: [
{
text: '<b>Ana Sayfa</b>',
iconCls: 'bmenu',
handler: function(){ alert('blah'); }
},
{
text: '<b>Hakkımızda</b>',
iconCls: 'bmenu',
handler: function(){ alert('blah'); }
},
{
text: '<b>Duyurular</b>',
iconCls: 'bmenu',
handler: function(){
}
},
{
text: '<b>İletişim</b>',
iconCls: 'bmenu', // <-- icon
handler: function(){ alert('blah'); }
}]
});
var view = new Ext.Viewport({
layout: 'border',
autoScroll: true,
border: true,
items:[header,menuBar
,{
region: 'south',
collapsible: false,
padding: '25 25 25 25' ,
html:'<br/><br/><p align="center"><b>Sanguis Team 2012</b></p>',
border: true,
height: 100
},content
]
});
/*var templates = new Ext.Window({
width:900,
height:700,
id:'Templates',
resizable:false,
//layout:'border',
//border:true,
closable:false,
title:'Plantillas',
items:view
});
templates.show();*/
// view.render('anasayfa');
});
There is no maxwidth property on viewport, as viewport is always the size of the window.
This works:
use a viewport, set its layout to anchor
add a container to viewport
set its anchor property to '80% 100%'
put whatever you want inside the container. you can give the container border layout if you want

How to drag panels in main Panel

How to allow drag & drop panels in a main panel ?
I have a panel which contains one panel ( for the moment ) or somes panels and i want allow drag and drop for organize panels.
like this examples : http://examples.extjs.eu/freedrag.html
but i don't understand how to adapte this with my application .
My code :
( Is the Sticky items into tabobj tab.Panel then i want drag & drop )
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.Action',
'Ext.tab.*',
'Ext.button.*',
'Ext.form.*',
'Ext.layout.*'
]);
Ext.onReady(function() {
Ext.tip.QuickTipManager.init();
Ext.define('Mesclasses.objet.sticky', {
alias: ['widget.stick'],
extend: 'Ext.panel.Panel',
bodyStyle: {
background: 'yellow',
},
height: 150,
width: 150,
margin: '10 0 0 10',
draggable: true,
items: [{
xtype: 'label',
text: 'Title',
listeners: {
move: function (me, x, y, opt) {
alert('move');
}
}
}],
});
var item2 = Ext.create('Ext.Panel', {
title: 'Accordion Item 2',
html: '<empty panel>',
cls: 'empty'
});
var item3 = Ext.create('Ext.Panel', {
title: 'Accordion Item 3',
html: '<empty panel>',
cls: 'empty'
});
var item4 = Ext.create('Ext.Panel', {
title: 'Accordion Item 4',
html: '<empty panel>',
cls: 'empty'
});
var item5 = Ext.create('Ext.Panel', {
title: 'Accordion Item 5',
html: '<empty panel>',
cls: 'empty'
});
var accordion = Ext.create('Ext.Panel', {
region: 'west',
margins: '5 0 5 5',
split: true,
width: 210,
layout: 'accordion',
items: [item2, item3, item4, item5]
});
var paneltitle = Ext.create('Ext.panel.Panel', {
region: 'north',
html: '<h1 class="x-panel-header" id="title">Your Sticky World</h1>',
height: 40
});
var montab = Ext.create('Ext.tab.Tab', {
title: 'lol',
});
var tabobj = Ext.create('Ext.tab.Panel', {
region: 'center',
//xtype: 'tabpanel', // TabPanel itself has no title
activeTab: 0, // First tab active by default
items: [{
title: 'My Stickys',
xtype: 'panel',
items: [{
xtype: 'stick',
}]
}]
});
Ext.create('Ext.container.Viewport', {
layout: 'border',
renderTo: Ext.getBody(),
items: [
paneltitle,
accordion, {
region: 'south',
title: 'South Panel',
collapsible: true,
html: 'Information goes here',
split: true,
height: 100,
minHeight: 100
}, {
region: 'east',
title: 'East Panel',
collapsible: true,
split: true,
width: 150
},
tabobj]
});
});
Reviewing the sources of the page could help.
The main idea is, generally, to create Ext.dd.DDProxy for each panel you are dragging.
So, the following snippet could help you get the basic functionality working:
{
title: 'My Stickys',
xtype: 'panel',
items : [{
xtype : 'stick',
listeners : {
afterrender : function(stick){
stick.dd = new Ext.dd.DDProxy(stick.el.dom.id, 'group');
}
}
}]
}
Or, to be more generic (check the afterrender listener):
Ext.define('Mesclasses.objet.sticky',{
alias : ['widget.stick'],
extend : 'Ext.panel.Panel',
bodyStyle: {
background: 'yellow',
},
height : 150,
width : 150,
margin : '10 0 0 10',
draggable : true,
items: [{
xtype: 'label',
text : 'Title',
listeners : {
move : function(me,x,y,opt){
alert('move');
}
}
}],
listeners : {
afterrender : function(stick){
stick.dd = new Ext.dd.DDProxy(stick.el.dom.id, 'group');
}
}
});
Here is the render part you are mostly interested in (original page using ExtJS 3 though):
// runs after the window is rendered
,afterRender:function() {
// create items using template
Ext.Window.prototype.afterRender.apply(this, arguments);
this.tpl.overwrite(this.body, this);
// setup D&D
var items = this.body.select('div.draggable');
// loop through draggable items
items.each(function(el, ce, index) {
// create DDProxy
el.dd = new Ext.dd.DDProxy(el.dom.id, 'group');
// configure the proxy
Ext.apply(el.dd, {
win:this
,itemIndex:index
// runs on drag start
// create nice proxy and constrain it to body
,startDrag:function(x, y) {
var dragEl = Ext.get(this.getDragEl());
var el = Ext.get(this.getEl());
dragEl.applyStyles({border:'','z-index':this.win.lastZIndex + 1});
dragEl.update(el.dom.innerHTML);
dragEl.addClass(el.dom.className + ' dd-proxy');
this.constrainTo(this.win.body);
} // eo function startDrag
// runs on drag end
// save new position of item and fire itemdrag event to save state
,afterDrag:function() {
var el = Ext.get(this.getEl());
var div = this.win.divs[this.itemIndex];
div.x = el.getLeft(true);
div.y = el.getTop(true);
this.win.fireEvent('itemdrag', this);
} // eo function afterDrag
}) // eo apply
}, this); // eo each
} // eo function afterRender

Extjs: two panel resize accordingly when window resizes

I have a panel containing two children panels.the parent panel uses "border" layout, while two children panels use "form" and "column" layouts respectively. now How can I make these two children panels resize accordingly when window resizes, i.e., make sure the size ratio of these two panels is constant.
thanks!
my codes are as follows:
itemRts = {
xtype: 'panel',
title: 'Route',
region: 'north',
autoHeight: true,
layout: 'form',
width: 294,
bodyStyle: 'padding:10px 12px 10px',
id: 'ROUTE_PANEL',
el: 'Route_Setup',
items: [
{
xtype: 'button',
text: 'Go',
anchor: '0',
id: 'GO_BTN'
}]
};
itemEvts = {
xtype: 'panel',
title: 'Events',
region: 'center',
layout: 'column',
tpl: 'Please put events here.',
//bodyStyle: 'padding:10px 12px 10px',
border: false,
hideBorders: true,
id: 'EVENT_PANEL',
el: 'Event_Legend',
autoScroll: true
};
newView = new Ext.Viewport({
layout: "border",
items: [
{
xtype: 'panel',
margins: '10 0 10 10',
region: 'center',
width: 200,
layout: 'border',
split: true,
boxMaxWidth: 280,
minWidth: 280,
id: 'RTS_EVTS_REGION',
collapseMode: 'mini',
items: [
itemRts,
itemEvts]
}]
});
how to modify above codes to make it work as what I want?
thanks again!
You can set a resize event for container panel and call "dolayout" method of their children in case of resize :
newView = new Ext.Viewport({
layout: "border",
items: [
{
xtype: 'panel',
margins: '10 0 10 10',
region: 'center',
width: 200,
layout: 'border',
split: true,
boxMaxWidth: 280,
minWidth: 280,
id: 'RTS_EVTS_REGION',
collapseMode: 'mini',
items: [itemRts, itemEvts],
listeners: {
'resize': function () {
itemRts.doLayout();
itemEvts.doLayout();
}
}
}]
});
for your main container, i suggest hbox and/or vbox layouts. those layouts are what you are looking for. here a sample:
var testPanel = new Ext.Viewport( {
id : 'vp_test',
layout : 'hbox',
align : 'stretch',
items : [
{
id : 'pnl_child_1',
title : 'Test 1',
flex : 2
},
{
id : 'pnl_child_2',
title : 'Test 2',
flex : 3,
layout : 'vbox',
align : 'stretch',
items : [
{
id : 'pnl_child_3',
title : 'Test 3',
flex : 1
},
{
id : 'pnl_child_4',
title : 'Test 4',
flex : 1
}
]
},
]
} );
you can refer to documentation, viewport, hbox, vbox
itemRts = {
xtype: 'panel',
title: 'Route',
// region: 'north', <<< we don't need this anymore
flex: 1, // this means that this container has 1 flexible share
// autoHeight: true, <<< this will ruin all layout
layout: 'form',
// width: 294, <<< we don't need this anymore
bodyStyle: 'padding:10px 12px 10px',
id: 'ROUTE_PANEL',
el:'Route_Setup',
items: [
{
xtype:'button',
text:'Go',
anchor:'0',
id:'GO_BTN'
}
]
};
itemEvts = {
xtype: 'panel',
title: 'Events',
// region: 'center', <<< we don't need this anymore
flex: 1, // this means that this container has 1 flexible share
layout: 'column',
tpl: 'Please put events here.', // <<<< if you're not going to use xTemplates you should use html property instead
//bodyStyle: 'padding:10px 12px 10px',
border: false,
hideBorders: true,
id: 'EVENT_PANEL',
el : 'Event_Legend',
autoScroll: true
};
newView = new Ext.Viewport({
//// if you have only one child component you can use fit layout for viewport.
//// and consider removing that only child. use viewport as main container.
layout : "border",
items: [
{
xtype: 'panel',
margins: '10 0 10 10',
region: 'center',
// width: 200, <<<< width has no effect on center region
/// we'll use hbox with align stretch
layout: 'hbox',
align: 'stretch',
// split: true, <<<< split has no effect on center region
// boxMaxWidth: 280, <<<< no effect
// minWidth: 280, <<<< no effect
id: 'RTS_EVTS_REGION',
// collapseMode: 'mini', <<<< collapse properties has no effect on center region
items: [
itemRts,
itemEvts
]
}
]
});

extjs xml tree example that I put into the layout-browser example provided by extjs

Below is a javascript variable that I'm using to load into the layout-browser...you will notice the listener section is commented out...when I uncomment this section the layout-browser and the tree do not show up. When I comment out the listener section, the layout-browser and the tree work fine with the exception of the listener populating the pool-details-panel.
Any ideas why the listener is blowing the render of the layout-browser and tree up?
var PoolStackTree = {
id: 'PoolStackTree-panel',
title: 'Pool List',
layout: 'border',
width: 500,
height: 500,
items: [{
xtype: 'treepanel',
id: 'pooltree-panel',
region: 'center',
margins: '2 2 0 2',
singleExpand: true,
animate: true,
useArrows: true,
autoScroll: true,
rootVisible: false,
root: new Ext.tree.AsyncTreeNode(),
loader: new Ext.app.PoolLoader({ dataUrl: 'calmonpool_views_xml.cgi' })
/*
listeners { 'render': function(tp) {
tp.getSelectionModel().on('selectionchange', function(tree-pool, node-pool) {
var el = Ext.getCmp('pool-details-panel').body;
if(node-pool && node-pool.leaf) {
tpl.overwrite(el, node-pool.attributes);
} else {
el.update(detailsText);
}
})
}}
*/
},{
id: 'pool-details-panel',
title: 'Pool Details',
region: 'south',
autoScroll: true,
collapsible: true,
split: true,
margins: '0 2 2 2',
cmargins: '2 2 2 2',
height: 220,
html: detailsText
}]
};
You're missing a comma before the "listeners" property name and a colon after the property name:
...,
listeners: { ...
Well just for starters you're missing a ":" after "listeners". That would certainly cause the Tree not to render.

Resources