How do I lock a carousel in Sencha Touch - scroll

I am using a carousel and would like to lock the carousel until a button is clicked. Is there an easy way to do this? Thanks!
My code so far:
Ext.define('BabyBen.view.MainCarousel', {
extend: 'Ext.carousel.Carousel',
xtype: 'maincarousel',
config: {
fullscreen: true,
activeItem: 1,
indicator: false,
scrollable: {
direction: 'vertical',
directionLock: true
},
items: [{
xtype: 'whatscreen'
}, {
xtype: 'startscreen'
}, {
xtype: 'whenscreen'
}]
}
});

You need to write a custom view for lockable carousel:
Ext.define("myApp.view.LockableCarousel",{
extend: 'Ext.Carousel',
initialize: function () {
this.onDragOrig = this.onDrag;
this.onDrag = function (e) { if(!this.locked){this.onDragOrig(e);} }
},
locked: false,
lock: function () { this.locked = true; },
unlock: function () { this.locked = false; }
});
Then you can extend this custom carousel anywhere using extend as well as you need to apply custom lock and unlock function for your desired lockable carousel through button handler:
Ext.define("myApp.view.CustomCarousel",{
xtype: 'CustomCarousel',
extend: 'myApp.view.LockableCarousel',
config: {
id: 'LockableCarousel',
title: 'Example4',
iconCls: 'cloud',
indicator: false,
items: [
{
html : 'Item 1',
style: 'background-color: #5E99CC'
},
{
items: [
{
xtype : 'button',
text: 'Lock',
handler:function() {
Ext.getCmp('LockableCarousel').lock();
}
},
{
xtype : 'button',
text: 'Unlock',
handler:function() {
Ext.getCmp('LockableCarousel').unlock();
}
}
]
}
]
}
});
Working Demo

Related

eventlisters not working in controller

I'm working on my very first Sencha Touch 2 project, so I'm not very familiar with it yet. I'm using the Sencha documentation and have been Googling and Stackoverflowing a lot, but can't seem to find the answer to this problem.
I'm working in MVC and want to add some eventlisteners (in the controller) to controls in my view. Whatever I try, they don't seem to work, although they work when I add them in the view itself. Ofcourse that's not best practice at all, so I'm wondering what I'm doing wrong?
This is how my controller looks:
Ext.define("workingTime.controller.MainController", {
extend: "Ext.app.Controller",
views: ['Main'],
refs: [
{
sl_break: '#sl_break'
},
{
sl_work: '#sl_work'
}
],
init: function() {
this.control({
'sl_break': {
change: 'setBreakTime'
}
});
},
setBreakTime: function(newValue) {
console.log('set');
}
});
And this is how my view looks (with the listener still added):
Ext.define("workingTime.view.Main", {
extend: 'Ext.form.Panel',
controllers: ['MainController'],
requires: [
'Ext.field.Slider'
],
config: {
fullscreen: true,
items: [
{
xtype: 'label',
html: '<p class="label_field">Take a <span>five</span> minute break<p>'
},
{
xtype: 'sliderfield',
name: 'sl_break',
value: 5,
minValue: 1,
maxValue: 30,
style: {
'background-color' : '#FFecc0'
},
listeners: {
change: function() {
alert('changed');
}
}
},
{
]
}
});
Tell me if you need more info.
I would try: (without init function)
config: {
refs: {
sl_break: '#sl_break',
sl_work: '#sl_work'
},
control: {
sl_break: {
change: 'setBreakTime'
}
}
},
in your controller add sl_break: 'main sliderfield[itemId=sl_break]' in refs
Ext.define("workingTime.controller.MainController", {
extend: "Ext.app.Controller",
views: ['Main'],
refs: [
{
sl_break: 'main sliderfield[itemId=sl_break]'
}
],
init: function() {
this.control({
'sl_break': {
change: 'setBreakTime'
}
});
},
setBreakTime: function(newValue) {
console.log('set');
}
});
in view add alias to main and itemId to sliderfield
Ext.define("workingTime.view.Main", {
extend: 'Ext.form.Panel',
controllers: ['MainController'],
alias: 'widget.main',
requires: [
'Ext.field.Slider'
],
config: {
fullscreen: true,
items: [
{
xtype: 'label',
html: '<p class="label_field">Take a <span>five</span> minute break<p>'
},
{
xtype: 'sliderfield',
name: 'sl_break',
itemId:'sl_break',
value: 5,
minValue: 1,
maxValue: 30,
style: {
'background-color' : '#FFecc0'
},
listeners: {
change: function() {
alert('changed');
}
}
},
{
]
}
});
i hope it will work

Image form field Sencha Touch 2

I'm trying to create a Sencha Touch 2 form panel for a model in which one of the fields contains the URL to an image file. If I include a textfield, it'll display the text of the URL correctly, but what I really want is to display the image found at that URL, and I'm not sure how to do that. If I use xtype: image, I think I need a src config, and I'm not sure how to specify that the desired value is in one of the form fields. My view looks like this:
Ext.define("CatalogApp.view.ItemDetailView", {
extend: "Ext.form.Panel",
requires: "Ext.form.FieldSet",
alias: "widget.itemdetailview",
config:{
scrollable:'vertical'
},
initialize: function ()
{
this.callParent(arguments);
var backButton = {
xtype: "button",
ui: "back",
text: "Home",
handler: this.onBackButtonTap,
scope: this
};
var topToolbar = {
xtype: "toolbar",
docked: "top",
title: "Item Detail",
items: [
backButton
]
};
var mainLayout = {
xtype: "container",
layout: 'hbox',
items: [
{
xtype: 'textfield',
width: 200,
name: 'thumbUrl'
},
{
xtype: "fieldset",
flex: 1,
items : [
{
xtype: 'textfield',
name: 'itemNbr',
label: 'Item Nbr',
disabled: true
},
{
xtype: 'textfield',
name: 'itemDesc',
label: 'Item Desc',
disabled: true
}
]
}
]
};
this.add([
topToolbar,
mainLayout
]);
},
onBackButtonTap: function ()
{
console.log("backToHomeCommand");
this.fireEvent("backToHomeCommand", this);
}
});
How can I set up this view to display the image correctly?
You have to define new Sencha component: ImageField
Ext.define('Ext.ux.field.ImageField', {
extend: 'Ext.field.Field',
requires: [
'Ext.Img'
],
xtype: 'imagefield',
config: {
component: {
xtype: 'image'
}
},
updateValue: function(value, oldValue) {
var me = this,
component = me.getComponent();
component.setSrc(value);
},
proxyConfig: {
width: '100%',
height: '100%'
}
});
Than in form:
Ext.define("CatalogApp.view.ItemDetailView", {
extend: "Ext.form.Panel",
requires: "Ext.form.FieldSet",
alias: "widget.itemdetailview",
config:{
scrollable:'vertical'
},
initialize: function ()
{
this.callParent(arguments);
var backButton = {
xtype: "button",
ui: "back",
text: "Home",
handler: this.onBackButtonTap,
scope: this
};
var topToolbar = {
xtype: "toolbar",
docked: "top",
title: "Item Detail",
items: [
backButton
]
};
var mainLayout = {
xtype: "container",
layout: 'hbox',
items: [
{
xtype: 'imagefield', // only this change
width: 200,
height: 150,
name: 'thumbUrl'
},
{
xtype: "fieldset",
flex: 1,
items : [
{
xtype: 'textfield',
name: 'itemNbr',
label: 'Item Nbr',
disabled: true
},
{
xtype: 'textfield',
name: 'itemDesc',
label: 'Item Desc',
disabled: true
}
]
}
]
};
this.add([
topToolbar,
mainLayout
]);
},
onBackButtonTap: function ()
{
console.log("backToHomeCommand");
this.fireEvent("backToHomeCommand", this);
}
});
Cheers, Oleg

Load another view after login with sencha touch 2.0

I'm having a dumb problem and I would like you to give me a hand.Thanks in advance.
The situatios is as follows: I have 2 wiews (both created with sencha architect 2.0), one for login, and another for general purposes. And I would like to load the second view on successful response when trying to log in, this is, after any successful login. The main problem is that I've tried with Ex.create, Ext.Viewport.add, Ext.Viewport.setActiveItem, but I can't manage to make the second view to appear on screen, the login screen just keeps there and the app does not load the other view. Another thing, I don't have to use a navigation view for this.
Here is the code of my controller, from which I want to load my second view. And as you'll see, I even created a reference of the view, which has autoCreate enabled and has that ID "mainTabPanel":
Ext.define('MyApp.controller.Login', {
extend: 'Ext.app.Controller',
config: {
refs: {
loginButton: {
selector: '#login',
xtype: 'button'
},
username: {
selector: '#user',
xtype: 'textfield'
},
password: {
selector: '#pass',
xtype: 'passwordfield'
},
mainTabPanel: {
selector: '#mainTabPanel',
xtype: 'tabpanel',
autoCreate: true
}
},
control: {
"loginButton": {
tap: 'onLoginButtonTap'
}
}
},
onLoginButtonTap: function(button, e, options) {
Ext.Ajax.request({
url: '../../backend/auth.php',
method: 'POST',
params: {
user: this.getUsername().getValue(),
pass: this.getPassword().getValue()
},
success: function(response) {
var json = Ext.decode(response.responseText);
if (json.type == 'success') {
// LOAD THE DAMN SECOND VIEW HERE!
//var paneltab = Ext.create('MyApp.view.MainTabPanel');
//Ext.Viewport.add(paneltab);
//Ext.Viewport.setActiveItem(this.getMainTabPanel());
} else {
alert(json.value);
}
},
failure: function(response) {
alert('The request failed!');
}
});
}
});
And here is the code of my login view:
Ext.define('MyApp.view.LoginForm', {
extend: 'Ext.form.Panel',
config: {
id: 'loginForm',
ui: 'light',
items: [
{
xtype: 'fieldset',
ui: 'light',
title: 'Log into the system',
items: [
{
xtype: 'textfield',
id: 'user',
label: 'User',
name: 'user'
},
{
xtype: 'passwordfield',
id: 'pass',
label: 'Pass',
name: 'pass'
}
]
},
{
xtype: 'button',
id: 'login',
ui: 'confirm',
text: 'Login'
}
]
}
});
And finally, the code of the view I want to load. This view loads normally if I set it as the Initial View, but does not load when a successful login occurs:
Ext.define('MyApp.view.MainTabPanel', {
extend: 'Ext.tab.Panel',
config: {
id: 'mainTabPanel',
layout: {
animation: 'slide',
type: 'card'
},
items: [
{
xtype: 'container',
layout: {
type: 'vbox'
},
title: 'Tab 1',
iconCls: 'time',
items: [
{
xtype: 'titlebar',
docked: 'top',
title: 'General Report',
items: [
{
xtype: 'button',
iconCls: 'refresh',
iconMask: true,
text: '',
align: 'right'
}
]
},
{
xtype: 'container',
height: 138,
flex: 1,
items: [
{
xtype: 'datepickerfield',
label: 'From',
placeHolder: 'mm/dd/yyyy'
},
{
xtype: 'datepickerfield',
label: 'To',
placeHolder: 'mm/dd/yyyy'
},
{
xtype: 'numberfield',
label: 'Hours'
}
]
},
{
xtype: 'dataview',
ui: 'dark',
itemTpl: [
'<div style="height:50px; background-color: white; margin-bottom: 1px;">',
' <span style="color: #0000FF">{user}</span>',
' <span>{description}</span>',
'</div>'
],
store: 'hoursStore',
flex: 1
}
]
},
{
xtype: 'container',
title: 'Tab 2',
iconCls: 'maps'
},
{
xtype: 'container',
title: 'Tab 3',
iconCls: 'favorites'
}
],
tabBar: {
docked: 'bottom'
}
}
});
Please, I need help... :)
I'm stuck here for like 3 days now and can't figure out what the problem is. Thank you.
Could you post your app.js too?
I'm trying your code here and it load the view as expected. Here is my app.js:
Ext.application({
name: 'MyApp',
requires: [
'Ext.MessageBox'
],
controllers: ['Login'],
views: ['LoginForm','MainTabPanel'],
icon: {
'57': 'resources/icons/Icon.png',
'72': 'resources/icons/Icon~ipad.png',
'114': 'resources/icons/Icon#2x.png',
'144': 'resources/icons/Icon~ipad#2x.png'
},
isIconPrecomposed: true,
startupImage: {
'320x460': 'resources/startup/320x460.jpg',
'640x920': 'resources/startup/640x920.png',
'768x1004': 'resources/startup/768x1004.png',
'748x1024': 'resources/startup/748x1024.png',
'1536x2008': 'resources/startup/1536x2008.png',
'1496x2048': 'resources/startup/1496x2048.png'
},
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
// Initialize the main view
//Ext.Viewport.add(Ext.create('MyApp.view.Main'));
Ext.Viewport.add(Ext.create('MyApp.view.LoginForm'));
},
onUpdated: function() {
Ext.Msg.confirm(
"Application Update",
"This application has just successfully been updated to the latest version. Reload now?",
function(buttonId) {
if (buttonId === 'yes') {
window.location.reload();
}
}
);
}
});
Destroy the login panel, You don't really need it anymore...
success: function(response) {
var json = Ext.decode(response.responseText);
if (json.type == 'success') {
// LOAD THE DAMN SECOND VIEW HERE!
var paneltab = Ext.create('MyApp.view.MainTabPanel');
Ext.getCmp('loginForm').destroy();
Ext.Viewport.add(paneltab);
} else {
alert(json.value);
}
},
There are several problems here:
Your autoCreate rule uses an xtype: 'tabpanel' which will only ever create a vanilla Ext.TabPanel with no items in it. You'd need to assign an xtype attribute to your MyApp.view.MainTabPanel like xtype: 'mainTabPanel' and then use that xtype value in your autoCreate rule.
This then explains why this code won't work since this.getMainTabPanel() will return the wrong object. Simpler would be to just use Ext.Viewport.setActiveItem(paneltab).
In general, you usually don't want assign an id to a view (id: 'mainTabPanel'). Safer to just use an xtype to fetch it. Although you don't need it in this case, avoiding global id's allows you to create multiple instances of a view (or any other class type).

Sencha Touch 2 DataView itemtaphold not firing

For the life of me I'm unable to get my dataview to fire an itemtaphold event no matter how I attach the event handler. The itemtap event fires just fine. The closest i've been able to come is to use the longpress on the dom elements but that doesn't give me a reference to my control, just the dom element. Is the itemtaphold event broken for dataview on sencha touch 2 commercial?
BrowserGrid.js:
Ext.define('MyApp.view.BrowserGrid', {
extend: 'Ext.dataview.DataView',
xtype: 'browsergrid',
requires: [
'MyApp.view.BrowserGridItem',
'Ext.dataview.*',
'Ext.plugin.*'
],
config: {
useComponents: true,
cls: 'browser-grid',
defaultType: 'browsergriditem',
scrollable:{
direction: 'vertical',
directionLock: true
},
plugins :[{xclass:'Ext.plugin.ListPaging',autoPaging: true}],
listeners:
{
itemtaphold: function() { console.log('tapped'); }
}
}
});
BrowserGridItem.js
Ext.define('MyApp.view.BrowserGridItem', {
extend: 'Ext.dataview.component.DataItem',
xtype : 'browsergriditem',
config: {
cls: 'browser-grid-item',
dataMap: {
getName: {
setHtml: 'FILE_NAME'
},
getImage: {
setSrc: 'IMG_URL'
}
},
name: {
cls: 'x-name'
},
image: {
height:150,
width: 150,
flex:1
},
layout: {
type: 'vbox',
align: 'center'
}
},
applyImage: function(config) {
return Ext.factory(config, Ext.Img, this.getImage());
},
updateImage: function(newImage, oldImage) {
if (newImage) {
this.add(newImage);
}
if (oldImage) {
this.remove(oldImage);
}
},
applyName: function(config) {
return Ext.factory(config, Ext.Component, this.getName());
},
updateName: function(newName, oldName) {
if (newName) {
this.add(newName);
}
if (oldName) {
this.remove(oldName);
}
}
});

Extjs 4.0 MVC - how to close a view from within the controller?

I have a simple example here with a modal window that is a 'view'. I want to have a button within the window that does a window close, so the lazy user doesn't need to click the 'X' in top right.
My problem is I don't know how to reference the view from within the controller. In the non-MVC world I would just do a 'window.close()' in the button handler. Any ideas? Thanks!
View
Ext.define('AM.view.testwindow.window', {
extend: 'Ext.window.Window',
alias: 'widget.TESTwindow',
title: 'TEST Window',
layout: 'border',
width: 1000, height: 400,
minimizable: true,
maximizable: true,
closeAction: 'destroy',
initComponent: function () {
this.items = [
{xtype: 'gridpanel', region: 'center', // grid in the window
store: 'Equipments',
columns: [
{ text: 'Equip ID', dataIndex: 'EquipmentID' }
, { text: 'StationID', dataIndex: 'StationID' }
],
dockedItems: [{
xtype: 'toolbar', // Grid's toolbar
items: [
{
xtype: 'button', /* Close button to close the window */
text: 'Close Window',
itemId: 'btnTestClose'
}
]
}
]
}
];
this.callParent(arguments);
}
});
Controller
Ext.define('AM.controller.testwindow', {
extend: 'Ext.app.Controller',
stores: ['Equipments', 'Stations'],
models: ['Equipment'],
views: ['testwindow.window', 'testwindow.Grid'],
refs: [
{ ref: 'TESTgrid', selector: 'TESTgrid' },
{ ref: 'testwindow', selector: 'testwindow' }
],
init: function () {
this.control(
{
'#btnTestClose': {
click: function (butt, e, options) {
alert('close handler!');
this.getTestwindowWindowView().close(); // this fails. What should I do? ComponentQuery ?
}
}
}
)
}
}
);
Scope of 'this' from within Button handler
Your ref to the test window should match the alias TESTwindow (without the widget part), or maybe the long name testwindow.window:
refs: [
{ ref: 'TESTgrid', selector: 'TESTgrid' },
{ ref: 'TESTwindow', selector: 'testwindow' }
],
This will give you the autogenerated getter you need:
this.getTestwindow().close();
Getters are composed of get plus the reference selector with uppercase first letter.
refs: [
{ ref: 'TESTgrid', selector: 'TESTgrid' },
{ ref: 'win', selector: 'testwindow' }
],
Try this
this.getWin().close();
ready ok

Resources