Ext.ux.Workbench = function(security) {
this.map = {};
this.security = security;
};
Ext.ux.Workbench.prototype = {
init: function() {
this.initView();
this.initLoginWindow();
},
initView: function() {
this.north = this.createNorthPanel();
this.south = this.createSouthPanel();
this.west = this.createWestPanel();
this.center = this.createCenterPanel();
var viewport = new Ext.Viewport({
layout: 'border',
items: [
this.north,
this.south,
this.west,
this.center
]
});
setTimeout(function(){
Ext.get('loading').remove();
Ext.get('loading-mask').fadeOut({remove:true});
}, 500);
},
initLoginWindow: function() {
if (this.security.loginUrl) {
this.loginWindow = new Ext.ux.LoginWindow({
url: this.security.loginUrl,
callback: function(result) {
this.rebuildMenu(result.info.menus);
this.loginWindow.hide();
}.createDelegate(this)
});
Ext.Ajax.request({
url: this.security.checkUrl,
success: function(response) {
var result = Ext.decode(response.responseText);
if (result.success) {
this.rebuildMenu(result.info.menus);
} else {
this.loginWindow.show();
}
},
failure: function(response) {
Ext.Msg.alert('错误', '无法访问服务器。');
},
scope: this
});
} else {
this.loginWindow = new Ext.ux.LoginWindow({
url: (typeof WEB_ROOT == 'undefined' ? '.' : WEB_ROOT) + '/scripts/ux/window/login.jsp',
callback: function(result) {
this.rebuildMenu(this.security);
this.loginWindow.hide();
}.createDelegate(this)
});
Ext.Ajax.request({
url: (typeof WEB_ROOT == 'undefined' ? '.' : WEB_ROOT) + '/scripts/ux/window/login.jsp',
success: function(response) {
var result = Ext.decode(response.responseText);
if (result.success) {
this.rebuildMenu(this.security);
} else {
this.loginWindow.show();
}
},
failure: function(response) {
Ext.Msg.alert('错误', '无法访问服务器。');
},
scope: this
});
}
},
logout: function() {
if (this.security.logoutUrl) {
Ext.Ajax.request({
url: this.security.logoutUrl,
success: function(response) {
this.clean();
this.loginWindow.formPanel.getForm().reset();
this.loginWindow.show();
},
failure: function(response) {
Ext.Msg.alert('错误', '无法访问服务器。');
},
scope: this
});
} else {
Ext.Ajax.request({
url: (typeof WEB_ROOT == 'undefined' ? '.' : WEB_ROOT) + '/scripts/ux/window/logout.jsp',
success: function(response) {
this.clean();
this.loginWindow.formPanel.getForm().reset();
this.loginWindow.show();
},
failure: function(response) {
Ext.Msg.alert('错误', '无法访问服务器。');
},
scope: this
});
}
},
createNorthPanel: function() {
return {
region: 'north',
height: 80,
margins: '5 5 5 5',
html: '
',
bbar: new Ext.Toolbar(['->', {
text: 'Logout',
iconCls: 'logout-btn',
handler: function() {
this.logout();
},
scope: this
}])
};
},
createSouthPanel: function() {
return {
region: 'south',
height: 18,
margins: '5 0 0 0',
border: false,
frame: false,
bodyStyle: 'background-color:#99BBEE;color:white;font-size:12px;font-weight:bold;',
html: new Date().toString()
};
},
createWestPanel: function() {
var westPanel = new Ext.Panel({
id: 'mainAccordion',
region: 'west',
title: '功能菜单',
layout: 'accordion',
cls: 'west-menu',
width: 150,
minSize: 120,
maxSize: 200,
split: true,
collapsible: true,
margins: '0 0 0 5',
cmargins: '0 5 0 5',
frame: true,
border: true,
defaults: {
border: false,
lines: false,
autoScroll: true,
bodyStyle: 'background: #fff;',
collapseFirst: true
}
});
return westPanel;
},
createCenterPanel: function() {
var tabPanel = new Ext.TabPanel({
region: 'center',
layoutOnTabChange: true,
enableTabScroll: true,
monitorResize: true,
activeTab: 0,
margins: '0 5 0 0',
plain: true,
frame: true,
hideMode: 'offsets',
deferredRender: false,
deferredLayout: false,
defaults: {
closable: true,
viewConfig: {
forceFit: true
},
margins: '5 5 5 5',
bodyBorder: true
},
items: [{
id: 'Home',
title: '欢迎您',
closable: false,
autoScroll: true,
iconCls: 'welcome',
html: '
'
+ ''
+ ' '
+ ' |