Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
* New searchbox (fixes #2353)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxhash committed Feb 24, 2012
1 parent 33f2f60 commit 15954b3
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 271 deletions.
239 changes: 117 additions & 122 deletions app/modules/AppKit/lib/js/AppKitNavBar.js
@@ -1,28 +1,28 @@
Ext.ns("AppKit.util");

AppKit.util.AppKitNavBar = Ext.extend(Ext.Container,{
layout: null,
layout: null,
menuData: {},
preferenceURL: AppKit.util.Config.get('path') + '/modules/my/preferences',
logoutURL: null,
username: null,
hasAuth: false,
navBar: null,
iconField: null,


defaultCfg: {
layout: 'column',
id: 'menu',
border: false,
defaults: {style: {borderLeft: '1px #d0d0d0 solid'}, border: false, height: 40}
id: 'menu',
border: false,
defaults: {style: {borderLeft: '1px #d0d0d0 solid'}, border: false, height: 40}
},

// default config for the menubar field
tbarCfg: {
id: 'menu-navigation',
defaults: {border: false, style: 'margin:2px'},
style: 'border: none',
id: 'menu-navigation',
defaults: {border: false, style: 'margin:2px'},
style: 'border: none',
height: 35,
items: {},
columnWidth: 1
Expand All @@ -31,119 +31,114 @@ AppKit.util.AppKitNavBar = Ext.extend(Ext.Container,{
// default config for the icon field
iconFieldCfg: {
id: 'menu-logo',
width: 60,
height: 30,
border: false,
cls: 'icinga-link',
items: {
width: 61,
border: false,
autoEl: 'div',
frame: false,
cls: 'menu-logo-icon'
width: 60,
height: 30,
border: false,
cls: 'icinga-link',
items: {
width: 61,
border: false,
autoEl: 'div',
frame: false,
cls: 'menu-logo-icon'
}
},

constructor: function(cfg) {
if(Ext.getCmp(this.defaultCfg.id))
throw("Menubar is already loaded");
Ext.apply(this,cfg);

this.buildNavBar();
this.buildIconField();
Ext.apply(cfg,this.defaultCfg);
cfg.items = [
this.navBar,
this.iconField
];
this.navBar,
this.iconField
];

Ext.Container.prototype.constructor.call(this,cfg);
},


buildNavBar:function() {
var cfg = {};
var cfg = Ext.apply(cfg,this.tbarCfg);
cfg = Ext.apply(cfg,this.tbarCfg);
this.initMenuItems(cfg);
this.navBar = new Ext.Toolbar(cfg);
},

buildIconField : function() {
this.iconField = new Ext.Container(this.iconFieldCfg);
// Make the icon funky when loading
Ext.Ajax.on("beforerequest",function() {
try {
var icon = Ext.DomQuery.selectNode('.menu-logo-icon');
if(!icon)
return true;
Ext.get(icon).setStyle('background-image','url('+AppKit.c.path+'/images/ajax/icinga-throbber.gif)');
} catch(e) {
// ignore any errors
}
});
Ext.Ajax.on("requestcomplete",function() {
try {
var icon = Ext.DomQuery.selectNode('.menu-logo-icon');
if(!icon)
return true;
Ext.get(icon).setStyle('background-image','url('+AppKit.c.path+'/images/icinga/idot-small.png)');
} catch(e) {
// ignore any errors
}
});


this.iconField.on('render', function(c) {
c.getEl().on('click', function() {
AppKit.changeLocation('http://www.icinga.org');
});
});
try {
var icon = Ext.DomQuery.selectNode('.menu-logo-icon');
if(!icon)
return true;
Ext.get(icon).setStyle('background-image','url('+AppKit.c.path+'/images/ajax/icinga-throbber.gif)');
} catch(e) {
// ignore any errors
}
});
Ext.Ajax.on("requestcomplete",function() {
try {
var icon = Ext.DomQuery.selectNode('.menu-logo-icon');
if(!icon)
return true;
Ext.get(icon).setStyle('background-image','url('+AppKit.c.path+'/images/icinga/idot-small.png)');
} catch(e) {
// ignore any errors
}
});


this.iconField.on('render', function(c) {
c.getEl().on('click', function() {
AppKit.changeLocation('http://www.icinga.org');
});
});
},

initMenuItems : function(cfg) {
cfg.items = [];
this.addMenuFields(cfg.items,this.menuData);
cfg.items.push({xtype : 'tbfill'});
this.addClock(cfg.items);

if (AppKit.search.SearchHandler.isReady() === true) {
this.addSearchBox(cfg.items);
}

this.addUserFields(cfg.items);
},

addClock : function(itemsCfg) {
var item = new AppKit.util.Servertime();
itemsCfg.push({xtype: 'container',items:item});
},

addSearchBox : function(itemsCfg) {
var item = new AppKit.search.Searchbox();

AppKit.search.SearchHandler.setSearchbox(item);

itemsCfg.push({
xtype : 'container',
items : item
});
var item = new AppKit.search.Searchbox();
AppKit.search.SearchHandler.setSearchbox(item);
itemsCfg.push(item);
},

addMenuFields : function(itemsCfg,menuData) {

for(var i=0;i<menuData.length;i++) {
var menuPoint = menuData[i];
var p = {
text: _(menuPoint.caption),
iconCls: menuPoint.icon || null,
id: menuPoint.id || Ext.id()
text: _(menuPoint.caption),
iconCls: menuPoint.icon || null,
id: menuPoint.id || Ext.id()
};
if(menuPoint.target) {
p.handler = this.createHandlerForTarget(menuPoint.target);

// To allow native browser actions e.g. 'open in new tab', ...
if (menuPoint.target.target == 'new' && "url" in menuPoint.target) {
p.href = menuPoint.target.url;
p.href = menuPoint.target.url;
}
}
if(menuPoint.items) {
Expand All @@ -157,71 +152,71 @@ AppKit.util.AppKitNavBar = Ext.extend(Ext.Container,{

createHandlerForTarget: function(target) {
switch(target.target) {
case 'new':
return Ext.createDelegate(AppKit.changeLocation,window,[target.url]);
case 'container':
return function() {
var el = Ext.get(target.id);
if(!el) {
AppKit.log("Error: id "+target.id+" not found");
} else {
var updater = el.getUpdater();
updater.update({
url:target.url,
params: target.params || null
});
}
};

case 'window':
target.bodyStyle = target.style || "background-color: #ffffff";
return Ext.createDelegate(AppKit.util.contentWindow, this, [{
url: target.url
}, target]);
case 'new':
return Ext.createDelegate(AppKit.changeLocation,window,[target.url]);
case 'container':
return function() {
var el = Ext.get(target.id);
if(!el) {
AppKit.log("Error: id "+target.id+" not found");

} else {
var updater = el.getUpdater();
updater.update({
url:target.url,
params: target.params || null
});
}
};

case 'window':
target.bodyStyle = target.style || "background-color: #ffffff";
return Ext.createDelegate(AppKit.util.contentWindow, this, [{
url: target.url
}, target]);
}
},

addUserFields : function(itemsCfg) {

var userField = {
iconCls: this.hasAuth ? 'icinga-icon-user' : 'icinga-icon-user-delete',
text: this.username
iconCls: this.hasAuth ? 'icinga-icon-user' : 'icinga-icon-user-delete',
text: this.username
};
if(this.hasAuth) {

userField.menu = {};
userField.menu.items = {
xtype: 'buttongroup',
columns: 2,
autoWidth: true,
defaults: {
scale: 'large',
iconAlign: 'left',
width: '100%'

},
items: [{
tooltip: _('Preferences'),
iconCls: 'icinga-icon-user-edit',
text: _('Preferences'),
handler: function() {
AppKit.util.doPreferences(this.preferenceURL);
},
scope: this
}, {
tooltip: _('Logout'),
iconCls: 'icinga-icon-user-go',
width: 'auto',
handler: function() {
AppKit.util.doLogout(this.logoutURL);
xtype: 'buttongroup',
columns: 2,
autoWidth: true,
defaults: {
scale: 'large',
iconAlign: 'left',
width: '100%'

},
scope:this
}]
items: [{
tooltip: _('Preferences'),
iconCls: 'icinga-icon-user-edit',
text: _('Preferences'),
handler: function() {
AppKit.util.doPreferences(this.preferenceURL);
},
scope: this
}, {
tooltip: _('Logout'),
iconCls: 'icinga-icon-user-go',
width: 'auto',
handler: function() {
AppKit.util.doLogout(this.logoutURL);
},
scope:this
}]
};
}
itemsCfg.push(userField);
}
});


2 changes: 1 addition & 1 deletion app/modules/AppKit/lib/js/Layout.js
Expand Up @@ -16,7 +16,7 @@ Ext.onReady(function() {
layout: 'border',
defaults: { border: false },
items: [
{ layout: 'fit', region: 'north', id: 'viewport-north', border: false, height: 30 },
{ layout: 'fit', region: 'north', id: 'viewport-north', border: false, height: 27 },
{ layout: 'fit',region: 'center', id: 'viewport-center', border: false, contentEl: 'content' }
]
});
Expand Down

0 comments on commit 15954b3

Please sign in to comment.