create repository url from repository type and name

This commit is contained in:
Sebastian Sdorra
2012-06-15 18:58:26 +02:00
parent b95a275cb8
commit 48eaca73ef
4 changed files with 37 additions and 6 deletions

View File

@@ -86,8 +86,6 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
name: 'description'
},{
name: 'creationDate'
},{
name:'url'
},{
name: 'public'
},{
@@ -150,8 +148,9 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
},{
id: 'Url',
header: this.colUrlText,
dataIndex: 'url',
renderer: this.renderUrl,
dataIndex: 'name',
renderer: this.renderRepositoryUrl,
scope: this,
width: 250
},{
id: 'Archive',
@@ -219,6 +218,13 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
}
},
renderRepositoryUrl: function(name, meta, record){
var type = record.get('type');
return this.renderUrl(
Sonia.repository.createUrl(type, name)
);
},
renderArchive: function(v){
return v ? '<img src=' + this.archiveIcon + ' alt=' + v + '>' : '';
},

View File

@@ -74,7 +74,7 @@ Sonia.repository.InfoPanel = Ext.extend(Ext.Panel, {
text: this.urlText
},{
xtype: 'box',
html: String.format(this.linkTemplate, this.item.url)
html: String.format(this.linkTemplate, Sonia.repository.createUrlFromObject(this.item))
}];
var config = {
@@ -105,7 +105,7 @@ Sonia.repository.InfoPanel = Ext.extend(Ext.Panel, {
},
getRepositoryUrlWithUsername: function(){
var uri = this.item.url;
var uri = Sonia.repository.createUrlFromObject(this.item);
if ( state.user.name != 'anonymous' ){
var index = uri.indexOf("://");
if ( index > 0 ){

View File

@@ -78,6 +78,16 @@ Sonia.repository.setEditPanel = function(panels){
editPanel.doLayout();
}
Sonia.repository.createUrl = function(type, name){
return Sonia.util.getBaseUrl() + '/' + type + '/' + name
}
Sonia.repository.createUrlFromObject = function(repository){
var url = Sonia.repository.createUrl(repository.type, repository.name);
console.debug(url);
return url;
}
/**
* default panel
*/

View File

@@ -59,6 +59,21 @@ Sonia.util.getContextPath = function(){
return path;
}
Sonia.util.getBaseUrl = function(){
var url = location.href;
var i = url.indexOf('#');
if ( i > 0 ){
url = url.substring(0, i);
}
if ( url.endsWith('/index.html') ){
url = url.substring(0, url.length - '/index.html'.length);
} else if ( url.endsWith('/') ){
url = url.substring(0, url.length -1);
}
return url;
}
Sonia.util.getName = function(path){
var name = path;
var index = path.lastIndexOf('/');