ExtJS: Display image in window - extjs

Displaying image in a window sounds a simple task but i have problem with it.
I want to show my image (with variable size) to show in a window (or panel) with size 300*400. Then, by clicking on image or maximizing window, user sees image in its original size.
Following code works for stretching image to 300*400 thumbnail in initial view, but when maximizing it also stretches to full screen.
var myImage = Ext.create('Ext.Img', {
src: imgSrc,
});
picWin = Ext.create('Ext.window.Window', {
title: "My Picture",
width: 300,
height: 400,
maximizable: true,
maxWidth: myImage.getWidth(),
maxHeight: myImage.getHeight(),
layout: "fit",
items: [myImage]
})
picWin.show();

Take a look at my example: https://fiddle.sencha.com/#view/editor&fiddle/26eo
Seems to work. I removed the set max width and height.

Finally, i came to a solution like this. First we need to use card layout. Then we define two containers for specified image, one for initial view and one for maximized view. At last, we need to change these cards when window is maximized and when restored.
Code is as follows:
// Two image for when maximizing and when in initial view
var myImage = Ext.create('Ext.container.Container', {
layout: 'fit',
items: [{
xtype: 'image',
src: imgSrc
}]
});
var myImage2 = Ext.create('Ext.container.Container', {
scrollable: true,
items: [{
xtype: 'image',
src: imgSrc
}]
});
picWin = Ext.create('Ext.window.Window', {
title: "my title",
width: 300,
height: 400,
maximizable: true,
layout: "card",
activeItem: 0,
items: [myImage,myImage2],
listeners: {
maximize: function(){
this.setActiveItem(1);
},
restore: function(){
this.setActiveItem(0);
},
}
})
picWin.show();

What if we changed the layout from 'fit' to 'hbox' instead? This seems to give you what you want - when the window is maximised, the image does not stretch. Center and vbox also seemed to work, so there are probably a few layouts you could use to make it work. But since you only have an image in the window, it probably doesn't matter.
picWin = Ext.create('Ext.window.Window', {
title: "My Picture",
width: 300,
height: 400,
maximizable: true,
layout: "hbox",
items: [myImage]
})
picWin.show();
}

Related

ExtJS 4 display MS Word text

I have to display a MS World text (about 150 pages) in a ExtJS panel (in modal window I have two tabs, the first is a picture and the second should be the picture description).
I can prepare thix text olso in PDF format but stil have no idea how to do it good.
The iframe tag defines a rectangular region within the document in which the browser can display a separate document.
var panel = Ext.create('Ext.panel.Panel' {
width: 400,
height: 600,
modal : true,
items: [{
xtype: 'component',
html : '<iframe src="give path to your pdf here" width="100%" height="100%"></iframe>',
}]
});
Another solution is xtype: uxiframe. http://docs.sencha.com/extjs/4.1.0/#!/api/Ext.ux.IFrame
var panel = Ext.create('Ext.window.Window', {
width: 400,
height: 600,
modal : true,
layout:'fit',
items: [{
xtype: 'uxiframe',
title: 'myPDF title',
src: 'path to your pdf'
}]
}).show();
For see another way to use this component (with fiddle) take a look at this: https://www.sencha.com/forum/showthread.php?299797-Ext-ux-IFrame

Popup on a MapPanel is difficult to manually resize

I have a layout of type 'border' and in the 'center' panel I have a MapPanel.
I want to display a modeless popup with the code below.
It works fine, I can drag and resize.
But on resizing, if I drag with mouse outside the popup area (and inside MapPanel area) then I loose control of this action (the dotted line representing popup border disappear). But if I insist in dragging moving outside MapPanel area to 'west' or 'south' panel, then I will get again control of this action (dotted lines appear). I think that MapPanel will get mouse control when it is hovering on it. This behavior let resizing popup still possible but a bit tedious.
If I disable MapPanel on showing popup, resize works well, but that's not what I want. I want to display a modeless popup.
Any idea on any workaround?...
var mapPanel = Ext.ComponentQuery.query('viewMapPanel')[0];
Ext.create('GeoExt.window.Popup', {
map: mapPanel.map,
title: 'test',
frame: true,
border: false,
resizable: true,
draggable: true,
closable: true,
height: 400,
width: 200,
shadow: true,
shadowOffset: 20,
//modal:true
}).show();
Never used GeoExt. But I have used: http://code.betancourt.us/ext-map/ with the xtype: 'gmappanel' with success. You can just use a regular Ext.window and do layout: 'fit', items: {map} and it doesn't have these kinds of issues.
I think you could probably do the same thing instead of using GeoExt just use Ext.create('Ext.window.Window', { and have it pop up a regular window you can choose a layout for and then put your mapPanel in items.
var map = Ext.create('Ext.window.Window', {
title: 'I love Maps',
collapsible: true,
animCollapse: true,
maximizable: true,
width: 950,
height: 600,
minWidth: 200,
minHeight: 200,
layout: 'fit',
items: [{mapPanel}],
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
ui: 'footer',
layout: {
pack: 'center'
},
items: [{
minWidth: 80,
text: 'Close',
xtype: 'button'
}]
}]
});
map.show();
I assume you handed over a custom OpenLayers map to the GeoExt map panel instead of using the default. Set property "fallThrough" of that map to true, to allow bubbling up events.
var map = new OpenLayers.Map({
fallThrough: true
});

adding panel within panel dynamically with autoadjust

I want to add panels within a panel dynamically, since i dont know upfront the numbers of panels which i need to add.
This works fine if i do
panel.insert(<panel to be added>);
The parent panel is configured with the hbox layout.
But if the overall width of added panels goes beyond the parent panel width then there is a overflow and a horizontal scrollbar appears.
Rather what i am looking is it should add the panels to the next line automatically if it reaches the parent panels width.
Any solution to the above problem, might be i need to use some other layout here but not sure on that.
Thanks
I have one idea but you should try in your code then let me know the result. Basically, set layout type to auto.
var resultsPanel = Ext.create('Ext.panel.Panel', {
title: 'Results',
width: 600,
height: 400,
id: 'panel_one',
renderTo: Ext.getBody(),
layout: {
type: 'auto', // Arrange child items vertically
align: 'stretch', // Each takes up full width
padding: 5
}
});
var opanel = Ext.getCmp('panel_one');
console.log(opanel);
opanel.add([
{
xtype: 'panel',
title: 'Inner Panel',
width: Ext.getCmp('panel_one').getWidth(),
height: 100
}
]);
opanel.add([
{
xtype: 'panel',
title: 'Inner Panel',
width: Ext.getCmp('panel_one').getWidth()
height: 100
}
]);
Parent panel layout should be Table with number of columns specified.
See the following code for parent panel
{
xtype: 'panel',
itemId: 'productListPanel',
height: 500,
width: 600,
layout: {
type: 'table',
columns: 3
},
autoScroll: true
}
now i can add any number of child panels to it, see the following code.
for (var i = 0; i < 10; i++) {
var panel = Ext.create('Ext.panel.Panel', {
width: 190,
height: 150,
padding: 10,
cls: 'myPanel',
title: "Child Panle"+i
});
parentPanel.insert(panel);
}
This solved my problem, hope it helps somebody.
Thanks

Copy a container's item to a window Extjs 4

I have an item inside a container in my Viewport, I want to copy that item to a new window: What I've tried copies the item to the new window but unfortunately it destroys it in the container.
How can I keep it in both places ?
onOpenNewClick: function () {
var win;
var viewport = this.getMyViewport();
var chart = viewport.down('container #thechart');
win = Ext.create('widget.window', {
title: 'Layout Window',
width: 1000,
height: 600,
constrain: true,
constrainHeader: true,
hidden: false,
shadow: false,
maximizable: true,
autoScroll: true,
title: 'test',
layout: 'fit',
items: [{
region: 'center',
layout: 'fit',
title: 'chart',
xtype: chart
}]
});
win.show()
win.center();
},
My viewport :
items: [{
region : 'center',
height : '100%',
items : [{
xtype : 'container',
id : 'pan_chart',
border : false,
autoHeight : true,
hidden : true,
autoScroll : true,
items : [{
width : screen.width,
xtype: 'mychart',
id : 'thechart',
}]
}]
}
]
You need to clone the object instead of copying. Because when you copy you copy the reference and not creating a new instance of the object.
This thread discusses cloning of ExtJs objects.
Edit:
You are getting an extjs object and store it in the chart variable. In the second part you are trying to assign the object to the xtype property.
You should directly add it to the items property like so:
win = Ext.create('widget.window', {
title: 'Layout Window',
layout: 'fit',
items: [chart]
});
But this still "cut" your object and not "copy" it.
Edit2:
A good way for component copying is creating a function that return an instance of a chart. You can use the same store with the same data.
function createChart(store){
return Ext.create('Ext.chart.Chart', {
width: 400,
height: 300,
store: store
});
}
use it like so:
win = Ext.create('widget.window', {
title: 'Layout Window',
layout: 'fit',
items: [createChart(myStore)]//myStore must be defined
});

positioning of a container in extjs

In my project, I am trying to position a container as absolute. but if I do so, it is also effecting the neighbour items. I mean, after positioning the container, if I give some width and height to that particular container, it is effecting all the toolbar. (which I don't want to happen). This effect is happening even if I use layout: 'absolute or css position:absolute.
Here is my related code:
xtype: 'panel',
dockedItems: [{
dock: 'top',
xtype: 'toolbar',
height: 40,
items: [
{
//only this should be absolute positioned
xtype: 'container',
cls: 'logo', //tried with applying css styles !important
//even tried with layout: 'absolute'
},'-',
//the below elements should not move their position
//even if the above one has been applied positioning.
{
xtype: 'container'
},'->',
{
xtype: 'container'
}]
}],
Here my goal is to bring the container out of the toolbar because it should have greater height than the toolbar keeping other containers constant.
If the profile pic container has to be higher than the toolbar, it can't be a child of the toolbar container.
You could create a container with absolute layout below the toolbar, in that container you will have the profile pic and you can use a negative Y variable in order to move up the image, so it looks like is in the toolbar.
Just like this
var toolbar = Ext.create('Ext.toolbar.Toolbar', {
items: [
{},
{ xtype: 'tbspacer', width: 50 }, // Moving the button to the right
{ text: 'Fake Name Button' }
]
});
Ext.create('Ext.container.Container', {
layout: 'fit',
width : 700,
renderTo: Ext.getBody(),
items: [toolbar]
});
var image = Ext.create('Ext.Img', {
x: 0,
y: -25,
maxWidth: 70,
src: 'https://twimg0-a.akamaihd.net/profile_images/1471554494/swel.png'
});
Ext.create('Ext.container.Container', {
layout: {
type: 'absolute'
},
renderTo: Ext.getBody(),
items: [image]
});
http://jsfiddle.net/alexrom7/33cP8/1/
This solution is not so pretty, but it might work.

Resources