added basic archive action to user interface

This commit is contained in:
Sebastian Sdorra
2012-03-30 10:16:42 +02:00
parent fccb7e023f
commit e79eeb9028

View File

@@ -34,6 +34,13 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, {
titleText: 'Repository Form',
emptyText: 'Add or select an Repository',
// TODO i18n
archiveText: 'Archive',
archiveTitleText: 'Archive Repository',
archiveMsgText: 'Archive Repository "{0}"?',
errorArchiveMsgText: 'Repository archival failed',
removeTitleText: 'Remove Repository',
removeMsgText: 'Remove Repository "{0}"?',
errorTitleText: 'Error',
@@ -70,6 +77,21 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, {
handler: this.showAddForm
});
}
// repository archive
if (state.clientConfig.enableRepositoryArchive){
toolbar.push({
xtype: 'tbbutton',
id: 'repoArchiveButton',
disabled: false,
text: this.archiveText,
// TODO find icon
icon: this.removeIcon,
scope: this,
handler: this.toggleArchive
});
}
toolbar.push({
xtype: 'tbbutton',
id: 'repoRmButton',
@@ -133,7 +155,7 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, {
id: 'displayArchived',
xtype: 'checkbox',
listeners: {
changed: {
check: {
fn: this.filterByArchived,
scope: this
}
@@ -205,50 +227,105 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, {
grid.getFilterRequest().query = field.getValue();
grid.filterByRequest();
},
removeRepository: function(){
getSelectedRepository: function(){
var repository = null;
var grid = this.getGrid();
var selected = grid.getSelectionModel().getSelected();
if ( selected ){
var item = selected.data;
var url = restUrl + 'repositories/' + item.id + '.json';
Ext.MessageBox.show({
title: this.removeTitleText,
msg: String.format(this.removeMsgText, item.name),
buttons: Ext.MessageBox.OKCANCEL,
icon: Ext.MessageBox.QUESTION,
fn: function(result){
if ( result == 'ok' ){
repository = selected.data;
} else if (debug) {
console.debug( 'no repository selected' );
}
return repository;
},
executeRemoteCall: function(title, message, method, url, data, failureCallback){
Ext.MessageBox.show({
title: title,
msg: message,
buttons: Ext.MessageBox.OKCANCEL,
icon: Ext.MessageBox.QUESTION,
fn: function(result){
if ( result == 'ok' ){
if ( debug ){
console.debug( 'remove repository ' + item.name );
}
if ( debug ){
console.debug('call repository repository action '+ method + ' on ' + url );
}
var el = this.el;
var tid = setTimeout( function(){el.mask('Loading ...');}, 100);
Ext.Ajax.request({
url: url,
method: 'DELETE',
scope: this,
success: function(){
this.reload();
this.resetPanel();
},
failure: function(result){
main.handleFailure(
result.status,
this.errorTitleText,
this.errorMsgText
);
}
});
if (data && data.group){
delete data.group;
}
},
scope: this
});
Ext.Ajax.request({
url: url,
method: method,
jsonData: data,
scope: this,
success: function(){
this.reload();
this.resetPanel();
clearTimeout(tid);
el.unmask();
},
failure: function(result){
clearTimeout(tid);
el.unmask();
failureCallback.call(this, result);
}
});
} // canceled
} else if ( debug ){
console.debug( 'no repository selected' );
},
scope: this
});
},
toggleArchive: function(){
var item = this.getSelectedRepository();
if ( item ){
console.debug(item);
item.archived = ! item.archived;
if (debug){
console.debug('toggle repository ' + item.name + ' archive to ' + item.archived);
}
var url = restUrl + 'repositories/' + item.id + '.json';
this.executeRemoteCall(this.archiveTitleText,
String.format(this.archiveMsgText, item.name),
'PUT', url, item, function(result){
main.handleFailure(
result.status,
this.errorTitleText,
this.errorArchiveMsgText
);
}
);
}
},
removeRepository: function(){
var item = this.getSelectedRepository();
if ( item ){
if ( debug ){
console.debug( 'remove repository ' + item.name );
}
var url = restUrl + 'repositories/' + item.id + '.json';
this.executeRemoteCall(this.archiveTitleText,
String.format(this.archiveMsgText, item.name),
'DELETE', url, null, function(result){
main.handleFailure(
result.status,
this.errorTitleText,
this.errorMsgText
);
}
);
}
},