Accessing the TitleBar close event from a grid button - javascript

I am launching a shieldwindow from shield Tree View.
The shieldwindow has a single ‘close’ button on the TitleBar as per code below:
var dbwindow = $("#mapworkpanel").shieldWindow({
width: "60%",
height: "100%",
appendToBody:false,
draggable: false,
position: { left: 700, top: 0 },
title: "Dictionary Definitions",
titleBarButtons: [ 'close' ],
events: {
close: function(e) {
//
}
},
content: {
remote: {
url:thisurl,
iframe: true,
}
},
modal: false,
}).swidget();
The URL launches a shield UI grid with a few buttons including a Close Button.
When I click the “x” button on the Titlebar the form closes with no issues.
How can I access the TitleBar close button from the Close Button on the grid?
I appreciate any suggestions.
Thanks,
Mario

Hopefully I'm understanding your question correctly, but I'm not sure why you need access to the actual title bar's close button. In the case you're just looking to close the window an additional way, there's an API function in the Shield Window widget for that. Assuming your dbwindow reference is available, you should just be able to call dbwindow.close() in the event handler for your grid's close button.

Related

ExtJS 5.0 - adding button as overlay to component

We are working with software supplied by a third party, and we are not allowed to modify it, can use only overrides.
I would like to create a new button and overlay it on top of a text input so that they are close together.
I'm having trouble getting the overlay to align, instead it appears top left on the screen. So of course it doesn't align to the text input. Sample code is below, in this case implemented in the view initComponent override after this.callParent([]); is called.
var viewport = Ext.ComponentQuery.query('viewport')[0];
var overlay = viewport.add({
xtype: 'panel',
fullscreen: true,
left: 0,
top: 0,
width: 120,
height: 40,
items:[{
xtype: 'button',
text: 'Find Address',
handler: function() {
alert('Got it!');
}
}],
styleHtmlContent: true
});
var textField = this.query('*[itemId=textField]')[0];
overlay.showBy(textField, 'c-c?');
I've tried using floating: true and lots of other approaches.
Once I get it to position properly, is there a way to have the button respond to tab order correctly? That is, tab out of the text field, then have the button get focus?
As I understand from your question, you have trouble with setting position to a component. If it is the problem, you can set xy coordinate. Look at this fiddle:
https://fiddle.sencha.com/#fiddle/tpl
viewport.down('#idOverlay').setXY([150, 140]);
Edit:
Ext.define('OverriddenViewport', {
override: 'ExampleViewPort',
initComponent: function() {
// Set up first
this.callParent([]);
this.add(overlay);
this.addListener('afterrender', function(viewport) {
viewport.down('#idOverlay').setXY([220,50]);
viewport.down('#idButton').addListener('blur', function(button) {
viewport.down('#idTextfield').focus();
console.log('textfield is focussed');
});
viewport.down('#idTextfield').addListener('blur', function(button) {
viewport.down('#idButton').focus();
console.log('button is focussed');
});
});
}
});
If you can access the source (just to look around) you maybe can create an override of the corresponding class. Create a override, and copy all of the code of the class (form?) into your override.
Here some additional info about creating overrides in ExtJs:
http://moduscreate.com/writing-ext-js-overrides/
https://sencha.guru/2014/12/04/abstract-vs-override/
In your override create a trigger (on the field you want to expand) with your functionality:
{
fieldLabel: 'My Custom Field',
triggers: {
foo: {
cls: 'my-foo-trigger',
handler: function() {
console.log('foo trigger clicked');
}
}
}
}

jQuery ui dialog box always positioned to top left

My jquery UI dialog box always gets positioned to top left no matter what I specify in the position attribute. I tried adding a css position to the div too. But it was of no use.
Can someone help me with this? Thanks.
$("<div>----Play again?---</div>").dialog({
title: 'Game Over!',
height: 'auto',
width: 'auto',
autoOpen: false,
draggable: true,
modal: false,
position: 'center',
buttons:{
"Yes": function() {
startGame();
$(this).dialog('close');
},
"No": function() {
alert('\nYour Score is: '+score+'\nGood Bye '+playerName+'!');
$(this).dialog('close');
}
}
});
I'm pretty sure you shouldnt need to set a position:
$("#dialog").dialog();
should centre by default.
I did have a look at the article, and also checked what it says on the official jquery-ui site about positioning a dialog : and in it were discussed 2 states of: initialise and after initialise.
Code examples - (taken from jQuery UI 2009-12-03)
Initialize a dialog with the position option specified.
$('.selector').dialog({ position: 'top' });
Get or set the position option, after init.
//getter
var position = $('.selector').dialog('option', 'position');
//setter
$('.selector').dialog('option', 'position', 'top');
I think that if you were to remove the position attribute you would find it centres by itself else try the second setter option where you define 3 elements of "option" "position" and "center".

Right Click Menu Event using Javascript

I'm working on a new project and I need to create an event where a menu list will show up once I right click on a label. Any idea how to do this?
When you click on a list from the menu box, a dialog box will appear. I do know how to create a dialog box but my problem is the right click event.
var createDialog = function(){
dialog = new Ext.LayoutDialog(id+'container', {
title: "DXFエクスポート",
width: 350,
height: 400,
shadow: true,
proxyDrag: false,
resizable: true,
modal: false,
autoScroll:true,
center: {
autoScroll:true
},
south: {
height: 60
}
});
I hope someone can give me an idea how to do mouse events.

Jquery dialog resizing only happens the first time it's opened

I have this code for a JQuery a dialog for a div containing a gridview that loads with a lists of tasks. The dialog fits to the contents OK, but if hundreds of tasks are loaded the dialog gets too big and can't be resized by hand, so I needed to code a way for it to open with a manageable size.
Before anyone suggests it, I tried setting the max-height property on my div to 500px and that worked fine except the div wouldn't fill the whole dialog if the dialog got higher than 500px, which we want it to. I also tried setting the maxHeight property on the dialog directly but that only takes effect when you resize the dialog by hand, not when the dialog opens. And when the dialog opens bigger than the screen that can't be done.
So instead I wrote this code which declares the dialog, then if more than 20 tasks are loaded the dialog is supposed to be resized to 500px high. That way the div inside fills the dialog completely at all times and the dialog size stays managable.
function ShowReferedTasks(title, s, taskCount) {
//On crée le dialog à partir de la même div
$('#litReferedTasks').dialog({
autoOpen: true,
modal: true,
resizable: true,
show: 'drop',
hide: 'drop',
width: 800,
minHeight: 0,
title: 'Tâche' + s + ' référée' + s + ' de ' + title
});
//if more than 20 refered tasks are found
if (taskCount > 20) {
$('#litReferedTasks').dialog('option', 'height', 500);
$('#litReferedTasks').dialog('option', 'position', 'center');
}
}
This code is called from a button in each line of a parent gridview, loading each line's tasks.
Here is what happens when I refresh my page and flush the cache (ctrl+F5), then open some task lists.
If I open one list of tasks containing more than 20 tasks (a dialog that will need to be refreshed), it works fine.
If I open any list of tasks, even one with less than 20 tasks that doesn't need resizing, then close it, and open one with more than 20 tasks, the dialog opens and the gridview is filled perfectly but the resizing doesn't work, the dialog is too big to fit on the screen, and can't be resized by hand.
Basically the resize part of my code only works on the first dialog I open after refreshing my page and flushing the cache. I think something must be kept in memory after the first time a dialog is opened, but I'm a newbie with JQuery and JS in general and I can't find the answer.
<div id="litReferedTasks" style="background-color: White; display: none; overflow:auto; height:95%;">
<asp:GridView ID="gvReferedTasks" runat="server" OnRowDataBound="gvReferedTasks_RowDataBound" Width="97.5%" Visible="false">
</asp:GridView>
<asp:Label ID="lblNoReferedTasks" runat="server" Visible="false" Width="100%"></asp:Label>
</div>
Any help?
Okay, so if you set the option after the dialog has been opened, height may not have an effect, but if you put height into the initial dialog creation code, it should have a set height just fine:
function ShowReferedTasks(title, s, taskCount) {
var dialogOptions = {
autoOpen: true,
modal: true,
resizable: true,
show: 'drop',
hide: 'drop',
width: 800,
minHeight: 0,
title: 'Tâche' + s + ' référée' + s + ' de ' + title
};
//if more than 20 refered tasks are found
if (taskCount > 20) {
dialogOptions.height = 500
}
//On crée le dialog à partir de la même div
$('#litReferedTasks').dialog(dialogOptions);
}
I think you are over-complicating the .dialog function. The easiest thing to do is create the dialog once with autoOpen set to false, rather than trying to re-initialize it every time. I think you'd have better luck with something like this:
// Do this once when the document is ready
$(function() {
$('#litReferedTasks').dialog({
autoOpen: false,
modal: true,
resizable: true,
show: 'drop',
hide: 'drop',
width: 800,
minHeight: 0
});
});
function ShowReferedTasks(title, s, taskCount) {
$('#litReferedTasks').dialog('option', 'title', 'Tâche' + s + ' référée' + s + ' de ' + title);
if (taskCount > 20) {
$('#litReferedTasks').dialog('option', {
height: 500,
position: 'center'
});
}
$('#litReferedTasks').dialog('open');
}

Jqueryui dialog "resizeable: false" not working?

Below is my code. When it opens the modal, it IS resizeable even though it's set to false. This is not expected. All other parameters work as expected (height, width, position, draggable, modal).
//MODAL IFRAME POPUP FOR EDITS/adds
$("#modalDiv").dialog({
modal: true,
autoOpen: false,
height: '400',
width: '400',
position: ['150','200'],
draggable: true,
resizeable: false,
title: ''
});
//catch a click on an item with the class "add" open modal div.
$('.add').live('click', function () {
var thing = $(this).attr('add')
url = 'add/' + thing + '.aspx?appid=' + $('.lblAppID').html();
$('#modalIFrame').attr('src', url);
$('#modalDiv').dialog('open');
return false;
});
However, if I call the following code from within the modal iframe, it makes it unresizeable (as expected).
window.parent.$("#modalDiv").dialog("option", "resizable", false);
This works, but preferably I'd like to know what I'm missing... I'm sure it's something stupid. Help?
It's resizable, not resizeable.
You're spelling the word two different ways :-)

Categories