From 3f63b8081c69974cfbc728a42795656db51897bb Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Fri, 29 Apr 2011 09:12:17 +0200 Subject: [PATCH] added api for repository information panels --- .../webapp/resources/js/sonia.repository.js | 64 +++++++++++++------ .../src/main/webapp/resources/js/sonia.scm.js | 21 +++++- .../main/webapp/resources/js/sonia.util.js | 12 ++++ 3 files changed, 76 insertions(+), 21 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.repository.js b/scm-webapp/src/main/webapp/resources/js/sonia.repository.js index 17d78549b5..7d6b89ef3d 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.repository.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.repository.js @@ -161,10 +161,10 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { console.debug( item.name + ' selected' ); } - var panels = [{ - item: item, - xtype: 'repositoryInfoPanel' - }]; + var infoPanel = main.getInfoPanel(item.type); + infoPanel.item = item; + + var panels = [infoPanel]; if ( Sonia.repository.isOwner(item) ){ Ext.getCmp('repoRmButton').setDisabled(false); @@ -211,6 +211,8 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { // register xtype Ext.reg('repositoryGrid', Sonia.repository.Grid); +// default repository information panel + Sonia.repository.InfoPanel = Ext.extend(Ext.Panel, { linkTemplate: '{0}', @@ -250,26 +252,20 @@ Sonia.repository.InfoPanel = Ext.extend(Ext.Panel, { },{ xtype: 'box', html: String.format(this.linkTemplate, this.item.url) - },{ - xtype: 'box', - height: 10, - colspan: 2 - },{ - xtype: 'link', - colspan: 2, - text: 'ChangesetViewer', - listeners: { - click: { - fn: this.openChangesetViewer, - scope: this - } - } }] } + console.debug(config); + this.modifyDefaultConfig(config); + console.debug(config); + Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.repository.InfoPanel.superclass.initComponent.apply(this, arguments); }, + + modifyDefaultConfig: function(config){ + + }, getRepositoryTypeText: function(t){ var text = null; @@ -282,15 +278,43 @@ Sonia.repository.InfoPanel = Ext.extend(Ext.Panel, { } return text; }, + + createSpacer: function(){ + return { + xtype: 'box', + height: 10, + colspan: 2 + }; + }, + + createChangesetViewerLink: function(){ + return { + xtype: 'link', + colspan: 2, + text: 'ChangesetViewer', + listeners: { + click: { + fn: this.openChangesetViewer, + scope: this + } + } + }; + }, - openChangesetViewer: function(){ - var changesetViewer = { + createChangesetViewer: function(){ + return { id: this.item.id + '-changesetViewer', title: 'ChangesetViewer ' + this.item.name, repository: this.item, xtype: 'repositoryChangesetViewerPanel', closable: true, autoScroll: true + }; + }, + + openChangesetViewer: function(changesetViewer){ + if ( changesetViewer == null ){ + changesetViewer = this.createChangesetViewer(); } main.addTab(changesetViewer); } diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.scm.js b/scm-webapp/src/main/webapp/resources/js/sonia.scm.js index 95d350d8fd..92822f48ac 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.scm.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.scm.js @@ -60,6 +60,8 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, { logoutFailedText: 'Logout Failed!', mainTabPanel: null, + + infoPanels: [], constructor : function(config) { this.addEvents('login', 'logout', 'init'); @@ -69,7 +71,24 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, { }, init: function(){ - this.fireEvent('load', this); + this.fireEvent('init', this); + }, + + registerInfoPanel: function(type, panel){ + this.infoPanels[type] = panel; + }, + + getInfoPanel: function(type){ + var rp = null; + var panel = this.infoPanels[type]; + if ( panel == null ){ + rp = { + xtype: 'repositoryInfoPanel' + }; + } else { + rp = Sonia.util.clone( panel ); + } + return rp; }, postLogin: function(){ diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.util.js b/scm-webapp/src/main/webapp/resources/js/sonia.util.js index 264ab510f7..70dc0475f4 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.util.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.util.js @@ -138,6 +138,18 @@ Ext.ns('Sonia.util'); +// clone method + +Sonia.util.clone = function(obj) { + var newObj = (this instanceof Array) ? [] : {}; + for (i in obj) { + if (i == 'clone') continue; + if (obj[i] && typeof obj[i] == "object") { + newObj[i] = Sonia.util.clone(obj[i]); + } else newObj[i] = obj[i] + } return newObj; +}; + // link Sonia.util.Link = Ext.extend(Ext.BoxComponent, {