added Sonia.History class to simplify handling of browser back and forward buttons

This commit is contained in:
Sebastian Sdorra
2011-08-15 11:02:57 +02:00
parent e8572f7b69
commit 1c4426d629
5 changed files with 59 additions and 21 deletions

View File

@@ -116,11 +116,7 @@ Sonia.group.Grid = Ext.extend(Sonia.rest.Grid, {
console.debug( group.name + ' selected' );
}
var token = Ext.History.getToken();
if ( token ){
var parts = token.split('|');
Ext.History.add(parts[0] + '|' + group.name);
}
Sonia.History.append(group.name);
Ext.getCmp('groupRmButton').setDisabled(false);
Sonia.group.setEditPanel([{

View File

@@ -103,11 +103,7 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
console.debug( item.name + ' selected' );
}
var token = Ext.History.getToken();
if ( token ){
var parts = token.split('|');
Ext.History.add(parts[0] + '|' + item.name);
}
Sonia.History.append(item.name);
var infoPanel = main.getInfoPanel(item.type);
infoPanel.item = item;

View File

@@ -29,14 +29,64 @@
*
*/
Ext.ns('Sonia');
Sonia.History = {
historyElements: [],
recentlyAdded: [],
add: function(token){
this.recentlyAdded.push(token);
Ext.History.add(token, true);
},
append: function(item){
var token = Ext.History.getToken();
if ( token ){
var parts = token.split('|');
this.add(parts[0] + '|' + item);
}
},
register: function(id, fn){
this.historyElements.push({
'id': id,
'fn': fn
});
},
handleChange: function(id, params){
if ( debug ){
console.debug( 'handle ' + id + ' with "' + params + '"' );
}
for (var i=0; i<this.historyElements.length; i++){
if (this.historyElements.id == id){
el.fn(params);
}
}
}
};
Ext.History.on('change', function(token){
if(token){
var parts = token.split('|');
var tab = parts[0];
if ( debug ){
console.debug( 'handle history event for ' + tab );
var found = false;
for ( var i=0; i<Sonia.History.recentlyAdded.length; i++ ){
if (Sonia.History.recentlyAdded[i] == token){
found = true;
Sonia.History.recentlyAdded.splice(i);
break;
}
}
if (!found){
var parts = token.split('|');
var id = parts[0];
Sonia.History.handleChange(id, parts.splice(1));
}
} else if (debug) {
console.debug('history token is empty');
}

View File

@@ -446,7 +446,7 @@ Ext.onReady(function(){
listeners: {
tabchange: function(tabPanel, tab){
if ( Ext.isDefined(tab) ){
Ext.History.add(tab.id);
Sonia.History.add(tab.id, true);
}
}
}

View File

@@ -103,11 +103,7 @@ Sonia.user.Grid = Ext.extend(Sonia.rest.Grid, {
console.debug( item.name + ' selected' );
}
var token = Ext.History.getToken();
if ( token ){
var parts = token.split('|');
Ext.History.add(parts[0] + '|' + item.name);
}
Sonia.History.append(item.name);
var panel = new Sonia.user.FormPanel({
item: item,