これは Ext JS での最初の大きなプロジェクトなので、理解してください :) ポータルの例に基づいてアプリケーションを構築しています。私が作成する必要があるのは、上部にツールバー、下部にステータスバー、画面全体を占めるタブパネルを備えた単純なレイアウトです。そのようです:
基本的な考え方は、アプリケーションの一部を簡単に変更できるように、すべての大きなコントロールを個別のファイルに入れることです。
私のディレクトリ構造は次のようになります。
root
--layout.html
--js
----App.js
----Components
------StatusBar.js
------UserInfo.js
------MenuBar
--------UserMenuBar.js
------Dashboard
--------UserDashboard.js
私の App.js は次のようになります。
Ext.ns('Holidays');
Ext.Loader.setConfig({
enabled: true,
disableCaching: true
});
Ext.Loader.setPath('Holidays', 'js');
Ext.Loader.setPath('Holidays.Components', 'js/Components');
Ext.Loader.setPath('Ext.ux', 'js/ux');
Holidays.application = null;
Ext.application({
name: "Holidays",
launch: function () {
Holidays.application = this;
this.createLayout();
Holidays.application = this;
Ext.fly(document.body).on('contextmenu', this.onContextMenu, this);
},
onContextMenu: function (e, target) {
if (!e.ctrlKey) {
e.preventDefault();
}
},
createLayout: function () {
this.menuBar = Ext.create("Holidays.Components.MenuBar.UserMenuBar");
this.statusBar = Ext.create("Holidays.Components.StatusBar");
this.centerView = Ext.create("Holidays.Components.Dashboard.UserDashboard");
this.centerPanel = Ext.create("Ext.tab.Panel", {
xtype: 'tabpanel',
border: false,
region: 'center',
bodyStyle: 'background:#DBDBDB',
plugins: Ext.create('Ext.ux.TabCloseMenu')
});
Ext.create('Ext.container.Viewport', {
layout: 'fit',
items: [{
xtype: 'panel',
border: false,
layout: 'border',
items: [
this.centerPanel],
bbar: this.statusBar,
tbar: this.menuBar
}]
});
this.addItem(this.centerView);
},
addItem: function (item) {
this.centerPanel.add(item);
item.show();
},
getStatusbar: function () {
return this.statusBar;
},
getCenterView: function () {
return this.centerView;
}
});
Holidays.getApplication = function () {
return Holidays.application;
};
Dashboard.js は次のようになります。
Ext.define('Holidays.Components.Dashboard.UserDashboard', {
extend: 'Ext.panel.Panel',
alias: 'widget.UserDashboard',
layout: 'border',
padding: 5,
closable: false,
title: 'Holiday planner',
initComponent: function () {
this.tree = Ext.create("Ext.panel.Panel", {
region: 'west',
split: true,
title: 'Categories',
width: 300,
collapsible: true,
animCollapse: false
});
//this.tree = Ext.create("Holidays.Components.UserInfo");THIS WON'T WORK :(
this.grid = Ext.create("Ext.panel.Panel", {
title: 'Plan urlopu',
region: 'center',
split: true,
});
this.history = Ext.create("Ext.panel.Panel", {
collapsed: true,
collapsible: true,
region: 'east',
split: true,
width: 300,
animCollapse: false,
title: 'test'
});
this.items = [this.tree, this.grid, this.history];
this.callParent();
},
getScheduler: function () {
return this.grid;
}
});
左のパネルを外部ファイルに移動すると、レイアウトがクラッシュします。パネルを折りたたむとき、および折りたたんでツールバーとステータスバーを復元しようとすると、パネルにアニメーションが表示されなくなり、ステータスバーが消えます:/
これが私のコードです:http://dl.dropbox.com/u/1206389/layout.zip
私の質問は次のとおりです。
- レイアウトを作成し、パーツを外部ファイルに分割する方法は?
- すべてのコントロールにエイリアスを作成する必要がありますか? 利点は何ですか?
- Ext.Loader を使用してロード コンポーネントをオンデマンドで修正する方法 (私の場合はインターフェイスの一部)
- ビューポートにステータスバーとツールバーを追加するには? 私はそれを正しくやっていますか?
そして最後に私のレイアウトは正しいですか?どんなアドバイスも大歓迎です:)