全碼:
Ext.application({
name: '',
launch: function() {
var previews = Ext.create('Ext.Panel',{
layout: 'column',
height: 500
});
var albumPhotos = Ext.create('Ext.Panel', {
layout: 'column',
border: 0
});
var itemModelStore = Ext.create('ItemModelStore');
itemModelStore.load(function() {
itemModelStore.each(function(record){
previews.add({
'id': record.get('id'),
'xtype': 'image',
'src': record.get('src'),
'style' : 'width:171px;height:196px;padding-left:5px;padding-top:5px;cursor:pointer;',
listeners: {
el: {
click: function() {
albumId = record.get('id');
fillAlbum(albumId);
var tabs = Ext.getCmp('tabs');
var albumTab = {
id: 'albumTab',
title: 'New album',
items: [
{
xtype: 'panel',
layout: {
type: 'vbox',
align: 'stretch'
},
items: [
uploadForm,
albumPhotos
]
}
]
};
tabs.add(albumTab);
var albumTabPanel = tabs.items.findBy(function (i) {
return i.id === 'albumTab';
});
tabs.setActiveTab(albumTabPanel);
tabs.down('#albumsTab').setDisabled(true);
tabs.down('#photosTab').setDisabled(true);
}
}
}
});
});
previews.doLayout();
albumPhotos.doLayout();
});
Ext.create('Ext.container.Viewport', {
layout: {
type: 'vbox',
align: 'stretch'
},
items: [
{
title: '',
items: [
{
xtype: 'tabpanel',
id: 'tabs'
}
]
}
]
});
var albumsTab = {
title: 'Album',
id: 'albumsTab',
items: [
{
xtype: 'panel',
layout: {
type: 'vbox',
align: 'stretch'
},
items: [
{
html: '<b><a onclick="return newAlbumWindowShow()" href="">Create album</a></b>'
+ '<br/><br/>'
}, previews
]
}
]
};
var photosTab = {
title: 'Photos',
id: 'photosTab',
html: 'blabla 2<br/><b><a onclick="newAlbumWindowShow()" href="#">Create album</a></b>'
};
displayStartPage = function() {
var tabs = Ext.getCmp('tabs');
tabs.add(albumsTab);
tabs.add(photosTab);
}();
onStartPage = function() {
var tabs = Ext.getCmp('tabs');
var albumsTabPanel = tabs.items.findBy(function (i) {
return i.id === 'albumsTab';
});
tabs.down('#albumsTab').setDisabled(false);
tabs.down('#photosTab').setDisabled(false);
tabs.setActiveTab(albumsTabPanel);
tabs.remove('albumTab', true);
}
var fillAlbum = function(albumId) {
Ext.define('AlbumStore', {
extend: 'Ext.data.Store',
model: 'ItemModel',
proxy: {
type: 'ajax',
url: 'php/readAlbum.php',
method: 'POST',
reader:{
type:'json',
root: 'objs'
}
}
});
var albumStore = Ext.create('AlbumStore');
albumStore.load({
params:{
id: albumId
},
callback: function() {
albumStore.each(function(record) {
albumPhotos.add({
'xtype': 'image',
'src': record.get('src'),
'style': 'width:200px;height:200px;padding-left:5px;padding-top:5px;' +
'padding-bottom:15px;cursor:pointer;'
});
});
}
});
}
}
});