In my sencha Touch application i am using the slidenavigation, when ever i click on the hamburger icon the menu slides out.
Now i want to mask the active view when menu slide is open.
My code for slidenavigation is as below
createMenu: function(){
var items = [
{
xtype:'button',
text:'Home',
ui: 'mainmenu',
listeners: {
tap: function(){
if(Ext.Viewport.getMenus().left.isHidden()){
Ext.Viewport.showMenu('left');
}
else
{
Ext.Viewport.hideMenu('left');
Ext.Viewport.setActiveItem({xtype: 'main'});
}
}
}
},
{
xtype:'button',
text:'Videos',
ui: 'mainmenu',
listeners: {
tap: function(){
Ext.Viewport.setActiveItem({xtype: 'videolist'});
if(Ext.Viewport.getMenus().left.isHidden()){
Ext.Viewport.showMenu('left');
}
else
{
Ext.Viewport.hideMenu('left');
}
}
}
}
];
return Ext.create('Ext.Menu', {
width: 200,
scrollable: 'vertical',
items: items,
id: 'mainmenu',
cls: 'mainmenu',
});
}
To show your mask, before "Ext.Viewport.showMenu()"
add this line :
Ext.Viewport.getActiveItem().setMasked(true);
To hide your mask, after "Ext.Viewport.hideMenu()"
add this line :
Ext.Viewport.getActiveItem().setMasked(false);
Related
My aim is simple, for some needs, I have to test the "pop-up function" in ExtJS via the widget.window.
I've created a button in HTML and a pop-u in a JS file, when I click it, everything works fine, the pop-up is well displayed.
The HTML button is coded this way :
<input type="button" id="popup-map" value="Pop Up"/>
And the JS refers to the button this way :
Ext.application({
name: 'popup',
launch: function() {
var popup,
button = Ext.get('popup-map');
button.on('click', function(){
if (!popup) {
popup = Ext.create('widget.window', {
title: 'Pop-Up',
header: {
titlePosition: 2,
titleAlign: 'center'
},
border: false,
closable: true,
closeAction: 'hide',
width: 800,
minWidth: 400,
maxWidth: 1200,
height: 500,
minHeight: 550,
maxHeight: 800,
tools: [{type: 'help'}],
layout: {
type: 'border',
padding: 2
},
items: [
{
region: 'center',
xtype: 'tabpanel',
items: [
mappanel,
{
title: 'Description',
html: 'Attributs de l\'objet sous forme de tableau'
}
]
}
]
});
}
button.dom.disabled = true;
if (popup.isVisible()) {
popup.hide(this, function() {
button.dom.disabled = false;
});
} else {
popup.show(this, function() {
button.dom.disabled = false;
});
}
});
Problem, if I have two buttons that contains the id "popup-map", only the first one declared is working. I guess it's pretty normal the way I've coded it.
How can I call the popup contains in the JS file by clicking several buttons in HTML ?
Thanks :-)
Use a CSS class instead of a duplicated id. Duplicated ids are bad, you know that... Then use Ext.query instead of Ext.get. Your code should look something like this:
Ext.onReady(function() {
var popup;
function handler(button) {
if (!popup) {
// ...
}
// you've got button and popup, do your things
}
// adds the handler to every button with class 'popup-map' on the page
Ext.query('button.popup-map', function(button) {
button.on('click', handler);
});
});
I'm using Ext.onReady to wait for the DOM to be ready before searching for buttons on the page. That also gives us a closure for our local variables popup and handler.
Thanks to #rixo, here's the code working.
I've created a empty css class called customizer.
Ext.onReady(function() {
var popup, popup_visible;
function popup_constructor() {
//alert(this.getAttribute('pwet'));
if (!popup) {
popup = Ext.create('widget.window', {
title: 'Pop-Up',
id: 'popup',
header: {
titlePosition: 2,
titleAlign: 'center',
height: 30
},
border: false,
closable: true,
closeAction: 'hide',
width: 800,
minWidth: 400,
maxWidth: 1200,
height: 500,
minHeight: 550,
maxHeight: 800,
tools: [{type: 'help'}],
layout: {
type: 'border',
padding: 10
},
items: [
{
region: 'center',
xtype: 'tabpanel',
plain: true,
items: [
{
title: 'Carte',
html: 'On mettra la carte ici',
border: false,
},
{
title: 'Description',
html: 'Attributs de l\'objet sous forme de tableau',
border: false,
}
]
}
]
});
}
popup_visible = true;
if (popup.isVisible())
{
popup.hide(this, function() {
popup_visible = false;
});
}
else
{
popup.show(this, function() {
popup_visible = false;
});
}
}
var popup_show = Ext.query('.customizer');
Ext.each(popup_show, function (item) {
item = Ext.get(item);
item.on('click', popup_constructor);
}, this);
});
I have added an input field to Window's title bar (header). On Chrome selecting and editing the input field works, and I can still drag the window around. On Firefox I can drag the window around the viewport, but I am unable to select the input field and edit it. How should I correct this code so that it would work on both browsers?
Quick'n'dirty demonstration of the problem:
Ext.define('Demo.DemoWindow', {
extend: 'Ext.window.Window',
xtype: 'demowindow',
height: 300,
width: 400,
title: 'Window',
autoShow: true,
items: [{
xtype: 'button',
text : 'Press!',
listeners: {
click: function() {
var win = this.up('window');
var header = win.getHeader();
header.setTitle('');
var killDrag = false;
var dragEvent = win.dd.on({
beforedragstart: function(dd, e) {
if (killDrag) {
return false;
}
}
});
var field = Ext.create('Ext.form.field.Text', {
name: 'Title',
allowBlank: false,
value: 'Type here something!',
listeners: {
el: {
delegate: 'input',
mouseout: function() {
killDrag = false;
},
mouseenter: function() {
killDrag = true;
}
}
}
});
header.insert(0, field);
}
}
}]
});
Ext.application({
name: 'Demo',
launch: function() {
Ext.create('Ext.container.Viewport', {
layout: 'absolute',
items: [
{
xtype: 'demowindow',
x: 20,
y: 20,
}
]
});
}
});
Using the mouseover event instead of mouseenter seems to work well with both.
I'm attempting to render a simple carousel in Sencha Touch, however, it's not showing up. The only thing I see are the indicator dots for the items. Inspecting in Chrome shows that the tags are being added, but I can't see them.
Carousel View:
Ext.define('Project.view.ChartCarousel', {
extend : 'Ext.Carousel',
xtype : 'chartCarousel',
config : {
title : 'Title',
fullscreen: 'true',
width: '100',
height: '100',
jumpToIndex: 0,
defaults : {
padding: '10 10 10 10'
},
items : [{
html:'<div style="text-align:center">test 1</div>'
}, {
html:'<div style="text-align:center">test 2</div>'
}, {
html:'<div style="text-align:center">test 3</div>'
}]
}
});
Containing View:
Ext.define('Project.view.SummaryChart',{
extend: 'Ext.form.Panel',
xtype: 'summaryChart',
requires: [
'Ext.Toolbar'
],
config: {
items: [
{
xtype: 'chartCarousel'
}
]
},
initialize: function() {
this.callParent(arguments);
}
});
I found the answer. I needed to add flex: '1' to the carousel's config.
I have made this application in sencha touch 2
Ext.application({
name: "SOMENAME",
launch: function () {
//Ext.Viewport.setLayout({type:'fit',align:'stretch'});
var mainPanel = Ext.create('Ext.Container', {
layout: 'vbox',
items: [
{
xtype: 'panel',
layout: {
type: 'card',
animation: 'slide'
},
height: 300,
id: 'nooPanel',
items: [
{
html: 'Page 1'
},
{
html: 'Page 2 asdasdasd'
},
{
html: 'Page 3 asdq323434'
}
]
},
{
xtype: 'button',
text: 'Next',
handler: function (button, e, eOpts) {
var panel = Ext.getCmp('nooPanel');
var totalItems = panel.getInnerItems().length;
var index = panel.getInnerItems().indexOf(panel.getActiveItem());
panel.setActiveItem((index + 1) % totalItems);
}
}
]
});
Ext.Viewport.add(mainPanel);
mainPanel.down('panel').setActiveItem(0);
},
init: function () {
}
})
but the problem is that if i dont put the height to 300 on the panel of which the layout is card its height becomes 0 and nothing is displayed
even after setting layout to fit on the viewport what should i do?
When you put items into a container with layout: 'vbox', Sencha Touch 2 needs to know what is the height ratio between these child items.
If you want to has a full-height items inside a vbox, add this config to that item, instead of height: 300, use flex:1
well digging into the configs i found out flex as a part of config..
through this property i can define the ratios of all the elements inside a container having vbox layout
so if i set the flex to 3 different items as 10,1,1 then the first one will take up (10/(10+1+1))*100 % of the space..
kind of worked for me..
but still looking for the final ans
You can only have one item in a container when you use 'fit'. I added a couple of 'flex:' values to give what I think you want. Here is the code and it's on SenchaFiddle for testing.
Ext.Loader.setConfig({
enabled: true
});
Ext.application({
name: "SOMENAME",
launch: function () {
//Ext.Viewport.setLayout({type:'fit',align:'stretch'});
var mainPanel = Ext.create('Ext.Container', {
layout: 'vbox',
items: [
{
xtype: 'panel',
flex: 20,
layout: {
type: 'card',
animation: 'slide'
},
//height:300,
id: 'nooPanel',
items: [
{
html: 'Page 1',
flex:1
},
{
html: 'Page 2 asdasdasd'
},
{
html: 'Page 3 asdq323434'
}
]
},
{
xtype: 'button',
text: 'Next',
flex: 1,
handler: function (button, e, eOpts) {
var panel = Ext.getCmp('nooPanel');
var totalItems = panel.getInnerItems().length;
var index = panel.getInnerItems().indexOf(panel.getActiveItem());
panel.setActiveItem((index + 1) % totalItems);
}
}
]
});
Ext.Viewport.add(mainPanel);
mainPanel.down('panel').setActiveItem(0);
},
init: function () {
}
})
I'm able to hide items among the dockedItems of a TabPanel, but am wanting to temporarily hide the entire dock, because the toolbar itself still takes up space and the rest of the content does not fill the screen.
So far, I do like so:
myApp.views.productList.dockedItems.items[0].removeAll(true);
myApp.views.productList.doComponentLayout();
Alternatively:
myApp.views.productList.getComponent('search').removeAll(true);
myApp.views.productList.doComponentLayout();
But neither removes the dockedItems toolbar itself.
I've even tried to give the dockedItems individually and collectively an id: to remove the whole component, but without luck. I've also tried moving the toolbar in question out from the docked items and into the items: property of the containing panel, but this breaks other things in my app that I'd rather not change at present.
Any clues on how to do this?
If I understand you correctly you want to temporally remove tabBar from a tabPanel. I was able to accomplish this through giving and id to my tabBar and then using removeDocked and addDocked methods. I'm new to sencha-touch so most likely there is a better way of doing this
The code below removes tabBar from tabPanel and then adds it back again.
Ext.setup({
onReady: function() {
var tabpanel = new Ext.TabPanel({
ui : 'dark',
sortable : true,
tabBar:{
id: 'tabPanelTabBar'
},
items: [
{title: 'Tab 1',html : '1',cls : 'card1'},
{title: 'Tab 2',html : '2',cls : 'card2'},
{title: 'Tab 3',html : '3',cls : 'card3'}
]
});
var paneltest = new Ext.Panel({
fullscreen: true,
dockedItems:[
{
xtype: 'button',
text: 'Disable TabBar',
scope: this,
hasDisabled: false,
handler: function(btn) {
console.log(btn);
if (btn.hasDisabled) {
tabpanel.addDocked(Ext.getCmp('tabPanelTabBar'), 0);
btn.hasDisabled = false;
btn.setText('Disable TabBar');
} else {
tabpanel.removeDocked(Ext.getCmp('tabPanelTabBar'), false)
btn.hasDisabled = true;
btn.setText('Enable TabBar');
}
}}
],
items:[tabpanel]
});
paneltest.show()
}
})
в dockedItems добавить button, которая будет обращаться к элементу panel.dockedItems и изменять/скрывать сам dockedItems
function f_create_accord(P_el_id, P_el_params) {
P_el = Ext.create
(
'Ext.panel.Panel',
{
id: P_el_id
, border: false
, x: P_el_params.left
, y: P_el_params.top
, id_el: P_el_params.id_el
, layout: 'accordion'
, dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
items: [{
P_el_id: P_el_id,
xtype: 'button',
text: 'добавить',
}, {
id_el: P_el_id,
xtype: 'button',
text: 'скрыть',
vision: true,
listeners: {
click: function (el, v2, v3) {
if (el.vision) {
Ext.getCmp(el.id_el).dockedItems.items[0].setHeight(5);
Ext.getCmp(el.id_el).dockedItems.items[0].items.items[0].hide();
Ext.getCmp(el.id_el).dockedItems.items[0].items.items[1].setWidth(Ext.getCmp(el.id_el).getWidth());
el.vision = false
}
else {
Ext.getCmp(el.id_el).dockedItems.items[0].setHeight('15px');
Ext.getCmp(el.id_el).dockedItems.items[0].items.items[0].show();
Ext.getCmp(el.id_el).dockedItems.items[0].items.items[1].setWidth(60);
el.vision = true
}
// Ext.getCmp(el.id_el).dockedItems.items[i].hide();
}
}
}]
}]
}
);
P_el.setStyle('position', 'absolute');
P_el.setStyle('box-shadow', ' 0px 0px 0px 1px green');
P_el.setStyle('background', 'border-box');
return P_el;
}