I want to open a new window on click of button. On cclick on button window is opening and closing fine but second time it is not closing properly.
Here is my code
var formPanel = new Ext.FormPanel({
height: 125,
autoScroll: true,
id: 'formpanel',
defaultType: 'field',
frame: true,
title: 'CheckOut from SVN',
items: [{
fieldLabel: 'SVN Path'
}],
buttons: [{
text: 'Submit',
minWidth: 75,
handler: function() {
var urlTemp = './Export?' + '&' + fp.getForm().getValues(true);
formPanel.getForm().submit({
url: urlTemp,
method: 'Post',
success: successFn1,
timeout: 18000000,
failure: otherFn
});
}
}, {
text: 'Reset',
minWidth: 75,
handler: function() {
formPanel.getForm().reset();
}
}]
});
function buildWindow() {
var win = new Ext.Window({
id: 'newWindow',
layout: 'fit',
width: 300,
height: 200,
closeAction: 'hide',
plain: true,
stateful: false,
items: [formPanel]
});
win.show();
}
var extSVN = new Ext.Button({
text: 'Checkout from SVN',
minWidth: 75,
handler: function() {
buildWindow();
}
});
Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
width: 400,
height: 300,
items: [extSVN]
});
you are using closeAction: 'hide' on your window which mean that when you close it it will not be destroyed but hidden.
The problem is that when you reopen the window you create a new one so your formPanel ends up in 2 different windows which causes the error.
You can :
remove the closeAction: 'hide', but your formPanel will also be
destroy when you close the window, so you'll have to recreate
another too
or keep the closeAction: 'hide' and only create the
windows one time
You have provided id to your form and window. And inside window you have set config closeAction: 'hide' that means whenever your press close button window is hiding.
And on again on-click of Checkout from SVN button you creating a same window and form with same id's so instead of creating of new window you can use previous window and show again.
In this FIDDLE, I have created a demo using your code and put some modifications.
CODE SNIPPET
Ext.onReady(function () {
var formPanel = new Ext.FormPanel({
height: 125,
autoScroll: true,
id: 'formpanel',
defaultType: 'field',
frame: true,
title: 'CheckOut from SVN',
items: [{
fieldLabel: 'SVN Path'
}],
buttons: [{
text: 'Submit',
minWidth: 75,
handler: function () {
var urlTemp = './Export?' + '&' + fp.getForm().getValues(true);
formPanel.getForm().submit({
url: urlTemp,
method: 'Post',
success: successFn1,
timeout: 18000000,
failure: otherFn
});
}
}, {
text: 'Reset',
minWidth: 75,
handler: function () {
formPanel.getForm().reset();
}
}]
});
function buildWindow(btn) {
if (!btn.win) {
btn.win = new Ext.Window({
layout: 'fit',
id: 'newWindow',
modal: true,
width: 300,
height: 200,
closeAction: 'hide',
plain: true,
stateful: false,
items: [formPanel]
});
}
btn.win.show();
}
var extSVN = new Ext.Button({
text: 'Checkout from SVN',
minWidth: 75,
handler: buildWindow
});
new Ext.Panel({
title: 'SVN Chekcout',
renderTo: Ext.getBody(),
width: 200,
height: 130,
items: [extSVN],
renderTo: Ext.getBody()
});
});
Related
I want to open a panel window under the button i click which is located in the header. The panel should be displayed under the button (aligned with the header) : i try :
{
xtype:'button',
height: '100%',
text: Strings.Notifications,
glyph: 'xf142#FontAwesome',
reference: 'settingsNotificationsButton',
cls :'headerButtonsCls',
listeners: {
click: function () {
new Ext.form.Panel({
width: 200,
height: 200,
title: 'Foo',
floating: true,
closable: false
}).show();
}
}
}
But the above code displays the panel in middle of the screen as a modal which i don't want (as i said i want it right under the header)
So how to achieve that ?
Thanks .
I took Muzaffers answer as base and added the feature to use the event coordinates here:
var windowPanel = Ext.create('Ext.Panel', {
bodyStyle: 'background: #ffff00;',
border: true,
height: 200,
width: 200,
floating:true
});
Ext.create('Ext.Container', {
renderTo: Ext.getBody(),
items: [{
xtype: 'button',
text: 'Show/Hide Panel',
handler: function (btn, event) {
windowPanel.showAt(event.getXY())
}
}
]
});
Here is the fiddle: https://fiddle.sencha.com/#fiddle/3a8j&view/editor
Is that useful for you?
var windowPanel = Ext.create('Ext.Panel', {
bodyStyle: 'background: #ffff00;',
border: true,
height: 200,
width: 200,
hidden: true
});
Ext.create('Ext.Container', {
renderTo: Ext.getBody(),
items: [{
xtype: 'button',
text: 'Show/Hide Panel',
handler: function () {
if (windowPanel.isHidden()) {
windowPanel.show();
} else {
windowPanel.hide();
}
}
},
windowPanel
]
});
https://fiddle.sencha.com/#fiddle/3a8c
I have an iframe (fit in a window) to load before showing it.
When I do :
window.show();
window.hide();
The window is not hidden. "window.show()" is used to render the iframe.
The loading of the iframe is about 10 sec.
How can I render the iframe without display the window?
My window :
var win = Ext.create('Ext.window.Window', {
height: '95%',
width: '95%',
modal: true,
header: false,
hideMode:'visibility',
constrain: true,
resizable:false,
itemId:'winIframeItemId....',
id:'winIframeId....',
baseCls: 'x-window-....',
layout: {
type: 'vbox',
align: 'stretch',
pack: 'start'
},
items: [{
xtype: 'container',
layout: {
type: 'hbox',
align: 'middle',
pack: 'end'
},
items: [{
xtype: 'button',
cls: 'x-button-close-window...',
height: 34,
width: 34
...
}]
}, {
xtype: 'container',
itemId:'conIframeWindow',
layout:"fit",
flex: 1,
items: [{
xtype: 'component',
autoScroll: true,
itemId:'IframeTest',
baseCls: 'x-component-w....',
autoEl: {
tag: "iframe",
domain: '....',
frameborder: 0,
src: url
}
}]
}]
});
Windows and menus are typically rendered to the document body. I was able to use the Ext.Component.renderTo configuration to render windows and menus without displaying them.
https://fiddle.sencha.com/#view/editor&fiddle/2f5h
// Render a hidden window.
var window = Ext.create('Ext.window.Window', {
renderTo: Ext.getBody(),
title: 'Window'
});
// Render a hidden menu.
var menu = Ext.create('Ext.button.Button', {
menu: {
items: [{
text: 'Item'
}],
renderTo: Ext.getBody()
},
text: 'Button'
});
I have a tab panel.I open a tab and a grid is shown. Then i double click a row and a window is opened. In this window i have a panel and in this panel i have 4 textfields.
Then i close window, and double click another row, window is opened and fields that in panel shown correctly like below.
label label label label
|_______| |______| |______| |______|
When i close tab and opened it again and click row to open window, window is opened but in my panel's items shown three times. I mean it looks like below :
label label label label
label label label label
label label label label
And every click rows it is increasing...
My window is ;
var win = new Ext.Window({
width: 680,
height: 250,
title: 'Details',
layout: 'border',
modal: true,
closeAction:'hide',
items: [top,grid]
});
and my panel (name is top)
var top = new Ext.FormPanel({
labelAlign: 'top',
region : 'north',
frame:true,
bodyStyle:'padding:5px 5px 0',
width: 680,
height:75,
items: [{
layout:'column',
items:[{
columnWidth:.25,
layout: 'form',
items: [{
xtype:'textfield',
id : 'date',
fieldLabel: '<font color="red" style="margin-left: 25px" ><b>date</b></font>',
labelSeparator: '',
style: 'text-align: center;',
width:120
}]
},{
columnWidth:.25,
layout: 'form',
items: [{
id : 'xxx',
xtype:'textfield',
fieldLabel: '<font color="red"style="margin-left: 25px" ><b>xxxx</b></font>',
labelSeparator: '',
style: 'text-align: center;',
width:120
}]
},{
columnWidth:.25,
layout: 'form',
items: [{
id : 'cost',
xtype:'textfield',
fieldLabel: '<font color="red"style="margin-left: 4px" ><b>cost</b></font>',
labelSeparator: '',
style: 'text-align: right;',
width:120
}]
},{
columnWidth:.25,
layout: 'form',
items: [{
id : 'price',
xtype:'textfield',
fieldLabel: '<font color="red"style="margin-left: 15px" ><b>price</b></font>',
labelSeparator: '',
style: 'text-align: right;',
width:120
}]
}]
}]
});
I try to change window's closeAction config 'hide' to 'destroy', but this time i can not open window second time if i don't close the tab.
How can i fix this problem.
Thank you very much.
var grid = new Ext.grid.GridPanel({
stripeRows: true,
frame: false,
border:false,
autoScroll: true,
loadMask: {msg : 'loading...'},
trackMouseOver:false,
store: store,
bbar: paging,
region:'center',
cm: cm,
sm: sm,
viewConfig: {enableRowBody:true,emptyText: 'empty...'},
listeners: {
celldblclick: function(){
showDetail();
}
}
});
and showDetail function is ;
var showDetail = function(){
store.baseParams = {
Id : sm.getSelected().data['ID']
};
store.load();
win.show();
var d =sm.getSelected().data['date'];
Ext.getCmp("xxx").setValue(sm.getSelected().data['xxx']);
Ext.getCmp("date").setValue(d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear());
Ext.getCmp("cost").setValue((sm.getSelected().data['cost']));
Ext.getCmp("price").setValue((sm.getSelected().data['price']));
};
You need to create the window on every call and destroy when close
function createWindow(){
return new Ext.Window({
width: 680,
height: 250,
title: 'Details',
layout: 'border',
modal: true,
closeAction:'destroy',
items: [top,grid]
});
}
And then call the createWindow
var showDetail = function(){
store.baseParams = {
Id : sm.getSelected().data['ID']
};
store.load();
var win = createWindow();
win.show();
var d =sm.getSelected().data['date'];
Ext.getCmp("xxx").setValue(sm.getSelected().data['xxx']);
Ext.getCmp("date").setValue(d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear());
Ext.getCmp("cost").setValue((sm.getSelected().data['cost']));
Ext.getCmp("price").setValue((sm.getSelected().data['price']));
};
In the before render event of the window. i have this code
Ext.define('Ext.view.ReaderWindow', {
extend: 'Ext.window.Window',
alias: 'widget.reader',
id1: 0,
file_path: '',
id: 'reader',
itemId: 'reader',
maxHeight: 800,
maxWidth: 900,
minHeight: 300,
minWidth: 500,
layout: {
type: 'anchor'
},
title: 'File Reader',
modal: true,
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [{
xtype: 'form',
anchor: '100% 100%',
itemId: 'reader_form',
maxHeight: 800,
maxWidth: 900,
minHeight: 300,
minWidth: 500,
autoScroll: true,
bodyPadding: 10,
items: [{
xtype: 'displayfield',
anchor: '100%',
itemId: 'file_contents',
maxWidth: 900,
minWidth: 50,
hideLabel: true,
name: 'file_contents'
}]
}],
listeners: {
beforerender: {
fn: me.reader_windowBeforeRender,
scope: me
}
}
});
me.callParent(arguments);
},
reader_windowBeforeRender: function(component, eOpts) {
Ext.model.FileReaderModel.load(this.id1, {
params: {
'file': this.file_path
},
success: function(file_reader) {
var form_panel = current.query('#reader_form');
var contents_field = form_panel[0].getComponent('file_contents');
var contents = file_reader.get('file_contents');
var pattern = /(\/.*?\.\S*)/gi;
contents = contents.replace(pattern, "<a href='#' class='sample'>$1</a>");
contents_field.setValue('<pre>' + contents + '</pre>');
Ext.select('.sample').on('click', function() {
var path = this.innerHTML;
var Id1 = this.id1;
var reader = Ext.create('Ext.view.ReaderWindow', {
id1: Id1,
file_path: path
});
reader.show();
});
},
failure: function(file_reader, response) {
}
});
},
});
for "a tag" i have assigned "sample" class. When a link is clicked, it opens a new window (but the same window is used to show the content).
The problem is if i click the a tag first time, then on click is called once. Then after i close the window and click a tag again..this time it fires twice. So depending on number of times i open and close..the click event is called so many times.
It looks like every time i open the window same event is registered multiple times. But i want to register the event only once.Any time i click a link, only once it should call the click event.
I want to popup a window to interact with people who want to upload a file to server. I want to render a file input form in the new window, but I can't make it run by doing follows:
var win = new Ext.Window();
var fp = new Ext.FormPanel({
renderTo: win,//I just guess that I can render this to the window I created...
fileUpload: true,
width: 500,
frame: true,
title: 'File Upload Form',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
xtype: 'textfield',
fieldLabel: 'Name'
},{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: 'Select an image',
fieldLabel: 'Photo',
name: 'photo-path',
buttonText: '',
buttonCfg: {
iconCls: 'upload-icon'
}
}],
buttons: [{
text: 'Save',
handler: function(){
if(fp.getForm().isValid()){
fp.getForm().submit({
url: 'file-upload.php',
waitMsg: 'Uploading your photo...',
success: function(fp, o){
msg('Success', 'Processed file "'+o.result.file+'" on the server');
}
});
}
}
},{
text: 'Reset',
handler: function(){
fp.getForm().reset();
}
}]
});
win.show();
As per the Ext JS documentation about the renderTo() method:
"Do not use this option if the Component is to be a child item of a Container. It is the responsibility of the Container's layout manager to render and manage its child items."
So what you need to do is:
Create the formPanel without the renderTo option
Create your window and specify the formPanel as an item of the window.
var win = new Ext.Window({
//You can specify other properties like height, width etc here as well
items: [fp]
});
You can refer to a working fiddle on this link:
http://jsfiddle.net/prashant_11235/2tgAQ/