ExtJs: update() & autoScroll not working - extjs4

I'm trying to update the html of a tabPanel. The scrollbar is there on the initial load, but then on update the scroll bar disappears.
This is my code:
var text = "a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>";
years = [];
items = [];
for(i=this_year; i>2002; i--) {
years.push(i);
}
for(i=0; i<parents.length; i++) {
items.push({
xtype: 'tabpanel',
title: years[i],
id: 'tabs' + years[i],
activeTab: 0,
autoScroll: true,
html: text, // this works just fine
});
}
var tp = new Ext.TabPanel({
renderTo: div,
id: 'tabs',
activeTab: 0,
items: items,
autoFit: true,
height: 500,
width: 500,
listeners: {
'tabchange': function(tabPanel, tab){
// dynamically update the html
}
}
});
// but if i instead use this the scrollbar disappears
Ext.get('tabs' + 2014).update(text);
Is there some other way to update the HTML?

Got it working with contentEl and jQuery's appendTo:
years = [];
items = [];
for(i=this_year; i>2002; i--) {
years.push(i);
}
for(i=0; i<parents.length; i++) {
$('<div id="tabs' + years[i] + '"></div>').appendTo("#some_div");
items.push({
xtype: 'tabpanel',
title: years[i],
id: 'foo-tabs' + years[i],
activeTab: 0,
autoScroll: true,
contentEl: 'tabs' + years[i],
});
}
var tp = new Ext.TabPanel({
renderTo: div,
id: 'foo-tabs',
activeTab: 0,
items: items,
autoFit: true,
height: 500,
width: 500,
listeners: {
'tabchange': function(tabPanel, tab){
}
}
});
$('some html').appendTo('#tabs' + year);

Related

ExtJS 4 and display PDF from BLOB

I try to display PDF stream in separate window and this stream is from database BLOB field. My code is the following:
Ext.define('MyApp.view.ViewPDF', {
extend: 'Ext.window.Window',
alias: 'widget.mywindow',
requires: [
'Ext.toolbar.Toolbar',
'Ext.button.Button'
],
config: {
title: '',
source: ''
},
itemId: 'SHOW_PDF',
closable: false,
resizable: true,
modal: true,
onClose: function (clsbtn) {
clsbtn.up('window').destroy();
},
initComponent: function () {
var my = this;
Ext.apply(my, {
items: [
{
xtype: 'panel',
layout: 'fit',
width: 640,
height: 780,
items: [
{
items: {
xtype: 'component',
align: 'stretch',
autoEl: {
tag: 'iframe',
loadMask: 'Creating report...please wait!',
style: 'height: 100%; width: 100%; border: none',
src: 'data:application/pdf;base64,' + tutaj.getSource()
}
}
}
]
}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
height: 30,
items: [
'->',
{
xtype: 'button',
baseCls: 'x-btn-default-large',
cls: 'cap-btn',
handler: my.onClose,
width: 55,
margin: '0, 10, 0, 0',
style: 'text-align: center',
text: 'Close'
}
]
}
]
});
my.callParent();
my.title = my.getTitle();
}
});
and it's working only via FireFox browser. In Chrome I can see empty window. So two questions (can't answer myself):
how to correct above to display this PDF stream in other browsers
how to display text in mask because loadMask in code above can't
work; just display text starting with window open and finishing when PDF is displayed
Be so kind as to prompt me what's wrong in this code.
I have created a FIDDLE using filefield, BLOB and FileReader. I have tested in chrome and Fire Fox. I hope this FIDDLE will help you or guid you to solve your problem.
CODE SNIPPET
Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
height: window.innerHeight,
title: 'Iframe Example for PDF',
bodyPadding: 10,
items: [{
xtype: 'fileuploadfield',
buttonOnly: true,
buttonText: 'Choose PDF and show via BLOB',
listeners: {
afterrender: function (cmp) {
cmp.fileInputEl.set({
accept: '.pdf'
});
},
change: function (f) {
var file = document.getElementById(f.fileInputEl.id).files[0];
this.up('form').doSetPDF(file);
}
}
}, {
xtype: 'fileuploadfield',
buttonOnly: true,
buttonText: 'Choose PDF and show via BASE64 ',
listeners: {
afterrender: function (cmp) {
cmp.fileInputEl.set({
accept: '.pdf'
});
},
change: function (f) {
var file = document.getElementById(f.fileInputEl.id).files[0];
this.up('form').doSetViaBase64(file);
}
}
}, {
xtype: 'box',
autoEl: {
tag: 'iframe',
loadMask: 'Creating report...please wait!',
width: '100%',
height: '100%'
}
}],
//Show pdf file using BLOB and createObjectURL
doSetPDF: function (file) {
if (file) {
var form = this,
blob, file;
if (Ext.isIE) {
this.doSetViaBase64(file)
} else {
blob = new Blob([file], {
type: 'application/pdf'
}),
file = window.URL.createObjectURL(blob);
form.getEl().query('iframe')[0].src = file;
}
}
},
//Show pdf file using BASE64
doSetViaBase64: function (file) {
var form = this,
reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
form.getEl().query('iframe')[0].src = this.result;
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
}
});

Sencha Touch 2.2.1 Carousel not inizialized

I'm back on the project of catalogue viewer app, and after updating to the last sencha release, I have the same problem I had a couple of month ago...the carousel don't recognize the onTap event or, it won't load correctly.
The app is quite simple, the structure is the following:
company name
list of catalogues
detailcard with the catalogue pages (3 per row)
carousel starting from the page tapped
The fact that when I use the app NOT compiled with sencha cmd, it work very smoothly, and problemless, but when I build the app (also production and packaging) with sencha cmd, it won't work.
The dataview show all the image, and when I click one of them, it pop-up the carousel, but empty. I tried to debug, and it won't do the initialize, but why only in the build version?
The code that I use is the following:
Ext.define('CIAM_app.view.Cataloghi', {
extend: 'Ext.NestedList',
xtype: 'cataloghi',
requires: ['Ext.data.TreeStore', 'Ext.carousel.Carousel'],
fullscreen: true,
config: {
iconCls: 'doc',
iconMask: true,
title: 'Cataloghi',
styleHtmlContent: true,
store: 'lista_cataloghiStore',
variableHeights: true,
listConfig: {
itemTpl: '<tpl if="leaf == false"><img src="{icon}" alt="{text}" class="cataloghi_img" /></tpl><tpl if="leaf == true"><p class="cataloghi_p">{text}</p></tpl>',
},
listeners: {
leafitemtap: function(nestedList, list, index, target, record) {
var detailCard = nestedList.getDetailCard();
var pagina = record.get('immagini_catalogo');
var n = record.get('pagine_catalogo');
items = [];
if (detailCard.getData() != null) {
detailCard.getStore().removeAll(true, true);
}
for (i = 1; i <= n; i++) {
items.push({
src: 'gallery/' + pagina + '/' + i + '.jpg',
});
}
detailCard.setData(items);
detailCard.refresh();
},
},
detailCard: {
xtype: 'dataview',
itemTpl: '<img src="{src}">',
cls: 'immagine_catalogo',
listeners: {
itemtap: function(dataView, index, target, record, e, eOpts) {
Ext.Viewport.add({
xtype: 'carousel',
extend: 'Ext.Carousel',
defaultType: 'image',
initialize: function() {
this.setItems(dataView.getData());
this.setActiveItem(index);
this.callParent();
this.element.on('tap', this.onTap, this);
},
onTap: function(e, t) {
this.fireEvent('tap', this, e, t);
this.hide();
},
style: {
'background': 'rgba(206,203,203,0.87)'
},
indicator: false,
width: '100%',
height: '100%',
centered: true,
fullscreen: true,
modal: true,
hideOnMaskTap: true,
showAnimation: {
type: 'popIn',
duration: 250,
easing: 'ease-out'
},
hideAnimation: {
type: 'popOut',
duration: 250,
easing: 'ease-out'
},
}).show();
}
}
}
}
});
If you want to see the webapp, here's the link: http://www.ciamcostruzioni.it/CIAM_app/not_compiled/
Thanks in advance.
I have made some changes in your code. Check it:
http://jsfiddle.net/JCarlesVilaseca/NZj3N/
Ext.define('CIAM_app.view.Cataloghi', {
extend: 'Ext.NestedList',
xtype: 'cataloghi',
requires: ['Ext.data.TreeStore', 'Ext.carousel.Carousel'],
fullscreen: true,
config: {
iconCls: 'books',
iconMask: true,
title: 'Cataloghi',
styleHtmlContent: true,
store: Ext.create('CIAM_app.store.lista_cataloghiStore'),
variableHeights: true,
listConfig: {
itemTpl: '<tpl if="leaf == false"><img src="http://www.ciamcostruzioni.it/CIAM_app/not_compiled/{icon}" alt="{text}" class="cataloghi_img" /></tpl><tpl if="leaf == true"><p class="cataloghi_p">{text}</p></tpl>'
},
listeners: {
leafitemtap: function(nestedList, list, index, target, record) {
var detailCard = nestedList.getDetailCard();
var pagina = record.get('immagini_catalogo');
var n = record.get('pagine_catalogo');
items = [];
if (detailCard.getData() !== null) {
detailCard.getStore().removeAll(true, true);
}
for (i = 1; i <= n; i++) {
items.push({
src: 'http://www.ciamcostruzioni.it/CIAM_app/not_compiled/gallery/' + pagina + '/' + i + '.jpg'
});
}
detailCard.setData(items);
detailCard.refresh();
}
},
detailCard: {
xtype: 'dataview',
itemTpl: '<img src="{src}">',
cls: 'immagine_catalogo',
listeners: {
itemtap: function(dataView, index, target, record, e, eOpts) {
Ext.Viewport.add({
xtype: 'catalogues_carousel',
listeners: {
initialize: function() {
this.setItems(dataView.getData());
this.setActiveItem(index);
}
}
}).show()
}
}
}
}
});
Ext.define('CIAM_app.view.Cataloghi_carousel', {
extend: 'Ext.Carousel',
xtype: 'catalogues_carousel',
requires: ['Ext.carousel.Carousel'],
config: {
fullscreen: true,
defaultType: 'image',
style: {
'background': 'rgba(206,203,203,0.87)',
'z-index':10
},
indicator: false,
modal: true,
showAnimation: {
type: 'popIn',
duration: 250,
easing: 'ease-out'
},
hideAnimation: {
type: 'popOut',
duration: 250,
easing: 'ease-out'
}
},
initialize: function() {
this.element.on('tap',function() {
this.hide();
});
}
});

Ext Editor position issue

I am using an editor for inline edit tree node value, when lage text comes its position changing? following is the code i made for test this scenario.
var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [
{ text: "ong label for testing long options test field.50", leaf: true },
{ text: "long label for testing long options test field.50 long label for testing log option test field. 100", leaf: true },
{ text: "option4", leaf: true }
]
}
});
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 300,
height: 250,
store: store,
rootVisible: false,
defaultRootId: 0,
renderTo: Ext.getBody(),
listeners: {
itemdblclick: function (View, record, item, index, e, eOpts) {
var editor = new Ext.Editor({
ignoreNoChange: true,
revertInvalid: true,
width: 235,
shadow: false,
//offsets: [-150, 0],
hideEl: false,
field: {
xtype: 'textfield',
maxLength: 500,
enforceMaxLength: true,
allowBlank: false
}
});
editor.startEdit(item, record.get('text'));
editor.on('complete', function (me, value) {
if (value.replace(/^[\s]+/, '').replace(/[\s]+$/, '').replace(/[\s]{2,}/, ' ') != "") {
record.set('text', value);
}
}, item, { single: true });
}
}
});
I am using Extjs4.1 version
First you should change alingment of editor to tl (top-left). It should be then always aligned to the left side of node. If you want to align editor to text in node, then you should also adjust offset.
Example:
itemdblclick: function (View, record, item, index, e, eOpts) {
var item = Ext.get(item);
var images = item.down('td').query('.x-tree-elbow, .x-tree-elbow-empty, .x-tree-elbow-end, .x-tree-elbow-line');
var x = 0;
for (var i = 0, ilen = images.length; i < ilen; ++i) {
x += Ext.get(images[i]).getWidth();
}
var editor = new Ext.Editor({
alignment: 'tl',
ignoreNoChange: true,
revertInvalid: true,
width: 235 - x,
shadow: false,
offsets: [x, 0],
hideEl: false,
field: {
xtype: 'textfield',
maxLength: 500,
enforceMaxLength: true,
allowBlank: false
}
});
editor.startEdit(item, record.get('text'));
editor.on('complete', function (me, value) {
if (value.replace(/^[\s]+/, '').replace(/[\s]+$/, '').replace(/[\s]{2,}/, ' ') != "") {
record.set('text', value);
}
}, item, { single: true });
}

sencha touch repeated task

I want to move a panel from bottom to up. smoothly. for this i try this code.
Ext.define("mathmania.view.Main", {
extend: 'Ext.Panel',
requries: [
'Ext.util.DelayedTask'
],
xtype: 'panel',
config: {
autodestory: true,
border: 1,
html: 'test panel',
bottom: 0,
centered: true,
padding: 10,
margin: '2%',
width: '95%',
listeners: {
painted: 'countdown'
}
},
countdown: function()
{
var task = Ext.create('Ext.util.DelayedTask', function() {
this.setBottom(this.getBottom + 5);
task.delay(100);
});
task.delay(0);
}
but each time it works only once not for multiple time as a repeating task?. for moving this float panel smoothly is there any better way or what i missing in this code?
I have tried using do-while loop, Panel is moving two times now but still the objective is unachieved. I think i am lacking somewhere in loop.
Hope this helps a little bit.
Ext.define("mathmania.view.Main", {
extend: 'Ext.Panel',
requries: [
'Ext.util.DelayedTask'
],
xtype: 'panel',
config: {
id: 'main1',
autodestory: true,
border: 1,
html: 'test panel',
bottom: 0,
centered: true,
padding: 10,
margin: '2%',
width: '95%',
listeners: {
painted: 'countdown'
}
},
countdown: function()
{
var a=Ext.getCmp('main1');
var i=0;
var j=20;
do{
var task = Ext.create('Ext.util.DelayedTask', function() {
a.setBottom(a.getBottom() + 10);
task.delay(500);
});
task.delay(1000);
i++;
}while(i<j)
}
});

Extjs 4 MVC custom parameter to store load listener

Inside my Controller i have function that runs after user clicks on item, which loads a store and creates/populates TabPanel with DataView (it works). When user clicks on only one specified item (if clause) i want to split store and create 2 panels with 2 DataViews. How can i pass custom parameter (record.data.name) to store listener so i could check which item was clicked? Or maybe there is different method to achieve what i want? Here is code of my Controller:
init: function() {
this.control({
'gallery_menu': {
itemclick: this.show_gallery
}
});
},
imageStoreLoaded: function(ImageStore, store1, store2) {
},
show_gallery: function(view, record, item, index, e, opts) {
Ext.getCmp('hania-viewport').setLoading('Loading data...');
var tabb = Ext.ComponentQuery.query('.gallery_panel');
var ImageStore = Ext.create('Gallery.store.Images');
ImageStore.load({url: 'myphoto/index.php/api/feed/json/' + record.data.uuid});
var gallery_view;
if (record.data.name == 'Specified_item1') {
var store1 = Ext.create('Gallery.store.Images');
var store2 = Ext.create('Gallery.store.Images');
//THIS WONT WORK - STORE IS NOT LOADED YET;
ImageStore.each(function(r) {
if (r.data.name.substring(0, 2) == 'PS') {
console.log('PS');
store1.add(r.copy());
}else{
console.log('NOT PS');
store2.add(r.copy());
}
});
//IF I ADD LISTENER HOW CAN I RETURN/REFERENCE store1, store2 ???
//OR how can i pass record.data.name so i could check which item was clicked?
ImageStore.addListener('load',this.imageStoreLoaded, this);
var panel1 = Ext.widget('gallery_view', {
title: 'xxx',
autoScroll: true,
store: store1,
flex: 1
});
var panel2 = Ext.widget('gallery_view', {
title: 'yyy',
autoScroll: true,
store: store2,
flex: 2
});
gallery_view = Ext.create('Ext.panel.Panel',{
id: record.data.uuid,
title: 'abc',
layout: {
type: 'hbox',
pack: 'start',
align: 'stretch'
},
closable: true,
autoScroll: true,
items: [panel1, panel2]
});
}else{
gallery_view = Ext.widget('gallery_view', {
title: record.data.name + ' - Photo Gallery',
id: record.data.uuid,
closable:true,
scrollable:true,
autoScroll: true,
store: ImageStore
});
}
if (tabb[0].down('#' + record.data.uuid)) {
tabb[0].setActiveTab(record.data.uuid);
}else{
tabb[0].add(gallery_view);
tabb[0].setActiveTab(gallery_view);
};
}
And the code:
show_gallery: function(view, record, item, index, e, opts) {
Ext.getCmp('hania-viewport').setLoading('Loading data...');
var tabb = Ext.ComponentQuery.query('.gallery_panel');
var ImageStore = Ext.create('Gallery.store.Images');
ImageStore.load({url: 'myphoto/index.php/api/feed/json/' + record.data.uuid});
var gallery_view;
if (record.data.name == 'Do kogo jestem podobna?') {
var store1 = Ext.create('Gallery.store.Images');
var store2 = Ext.create('Gallery.store.Images');
function doStuff() {
console.log(ImageStore);
ImageStore.each(function(r) {
if (r.data.raw_name.substring(0, 2) == 'PS') {
console.log('PS');
store1.add(r.copy());
}else{
console.log('NOT PS');
store2.add(r.copy());
}
});
console.log(store1);
console.log(store2);
}
ImageStore.addListener('load',doStuff, this);
var view1 = Ext.widget('gallery_view', {
title: 'xxx',
store: store1,
flex: 1
});
var panel1 = Ext.create('Ext.panel.Panel',{
title: 'Tata',
items: view1,
flex: 1
});
var view2 = Ext.widget('gallery_view', {
//autoScroll: true,
store: store2,
flex: 1
});
var panel2 = Ext.create('Ext.panel.Panel',{
title: 'Mama',
items: view2,
flex: 1
});
gallery_view = Ext.create('Ext.panel.Panel',{
id: record.data.uuid,
title: 'Do kogo jestem podobna?',
width: 800,
bodyStyle: 'padding: 25px;',
layout: {
type: 'hbox',
pack: 'start',
align: 'stretch'
},
closable: true,
autoScroll: true,
items: [panel1, panel2]
});
}else{
gallery_view = Ext.widget('gallery_view', {
title: record.data.name + ' - Photo Gallery',
id: record.data.uuid,
closable:true,
scrollable:true,
autoScroll: true,
store: ImageStore
});
}
if (tabb[0].down('#' + record.data.uuid)) {
tabb[0].setActiveTab(record.data.uuid);
}else{
tabb[0].add(gallery_view);
tabb[0].setActiveTab(gallery_view);
};
}