2021-02-02 13:00:38 +00:00
|
|
|
Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
|
2021-05-21 10:20:20 +00:00
|
|
|
extend: 'Ext.window.Window',
|
2021-03-25 10:04:40 +00:00
|
|
|
alias: 'widget.pbsTapeRestoreWindow',
|
2021-02-02 13:00:38 +00:00
|
|
|
mixins: ['Proxmox.Mixin.CBind'],
|
|
|
|
|
2021-05-21 13:53:50 +00:00
|
|
|
title: gettext('Restore Media-Set'),
|
|
|
|
|
2021-03-25 10:04:40 +00:00
|
|
|
width: 800,
|
2021-05-21 10:20:20 +00:00
|
|
|
height: 500,
|
2021-05-21 13:53:50 +00:00
|
|
|
|
2021-02-02 13:00:38 +00:00
|
|
|
url: '/api2/extjs/tape/restore',
|
|
|
|
method: 'POST',
|
2021-05-21 13:53:50 +00:00
|
|
|
|
2021-05-26 13:48:11 +00:00
|
|
|
modal: true,
|
2021-02-02 13:00:38 +00:00
|
|
|
|
2021-05-26 13:48:07 +00:00
|
|
|
mediaset: undefined,
|
|
|
|
prefilter: undefined,
|
|
|
|
uuid: undefined,
|
|
|
|
|
2021-05-11 10:50:07 +00:00
|
|
|
cbindData: function(config) {
|
|
|
|
let me = this;
|
2021-05-21 10:20:20 +00:00
|
|
|
if (me.prefilter !== undefined) {
|
|
|
|
me.title = gettext('Restore Snapshot(s)');
|
2021-05-11 10:50:07 +00:00
|
|
|
}
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
layout: 'fit',
|
|
|
|
bodyPadding: 0,
|
2021-02-02 13:00:38 +00:00
|
|
|
|
2021-05-21 13:24:52 +00:00
|
|
|
viewModel: {
|
|
|
|
data: {
|
2021-05-26 13:48:07 +00:00
|
|
|
uuid: "",
|
2021-05-21 13:24:52 +00:00
|
|
|
singleDatastore: true,
|
|
|
|
},
|
|
|
|
formulas: {
|
|
|
|
singleSelectorLabel: get =>
|
|
|
|
get('singleDatastore') ? gettext('Target Datastore') : gettext('Default Datastore'),
|
|
|
|
singleSelectorEmptyText: get => get('singleDatastore') ? '' : Proxmox.Utils.NoneText,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
controller: {
|
|
|
|
xclass: 'Ext.app.ViewController',
|
2021-03-25 10:04:40 +00:00
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
panelIsValid: function(panel) {
|
|
|
|
return panel.query('[isFormField]').every(field => field.isValid());
|
|
|
|
},
|
2021-03-25 10:04:40 +00:00
|
|
|
|
2021-05-26 13:48:07 +00:00
|
|
|
changeMediaSet: function(field, value) {
|
|
|
|
let me = this;
|
|
|
|
let vm = me.getViewModel();
|
|
|
|
vm.set('uuid', value);
|
|
|
|
me.updateSnapshots();
|
|
|
|
},
|
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
checkValidity: function() {
|
|
|
|
let me = this;
|
2021-05-21 13:24:52 +00:00
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
let tabpanel = me.lookup('tabpanel');
|
2021-05-21 13:24:52 +00:00
|
|
|
if (!tabpanel) {
|
|
|
|
return; // can get triggered early, when the tabpanel is not yet available
|
|
|
|
}
|
2021-05-21 10:20:20 +00:00
|
|
|
let items = tabpanel.items;
|
|
|
|
|
|
|
|
let indexOfActiveTab = items.indexOf(tabpanel.getActiveTab());
|
|
|
|
let indexOfLastValidTab = 0;
|
|
|
|
|
2021-05-21 13:18:54 +00:00
|
|
|
let checkValidity = true;
|
2021-05-21 10:20:20 +00:00
|
|
|
items.each((panel) => {
|
|
|
|
if (checkValidity) {
|
|
|
|
panel.setDisabled(false);
|
|
|
|
indexOfLastValidTab = items.indexOf(panel);
|
|
|
|
if (!me.panelIsValid(panel)) {
|
|
|
|
checkValidity = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
panel.setDisabled(true);
|
2021-05-11 10:50:07 +00:00
|
|
|
}
|
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
return true;
|
|
|
|
});
|
2021-03-25 10:04:40 +00:00
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
if (indexOfLastValidTab < indexOfActiveTab) {
|
|
|
|
tabpanel.setActiveTab(indexOfLastValidTab);
|
|
|
|
} else {
|
|
|
|
me.setButtonState(tabpanel.getActiveTab());
|
|
|
|
}
|
|
|
|
},
|
2021-03-25 10:04:40 +00:00
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
setButtonState: function(panel) {
|
|
|
|
let me = this;
|
|
|
|
let isValid = me.panelIsValid(panel);
|
|
|
|
let nextButton = me.lookup('nextButton');
|
|
|
|
let finishButton = me.lookup('finishButton');
|
|
|
|
nextButton.setDisabled(!isValid);
|
|
|
|
finishButton.setDisabled(!isValid);
|
|
|
|
},
|
2021-03-25 10:04:40 +00:00
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
changeButtonVisibility: function(tabpanel, newItem) {
|
|
|
|
let me = this;
|
|
|
|
let items = tabpanel.items;
|
|
|
|
|
|
|
|
let backButton = me.lookup('backButton');
|
|
|
|
let nextButton = me.lookup('nextButton');
|
|
|
|
let finishButton = me.lookup('finishButton');
|
|
|
|
|
|
|
|
let isLast = items.last() === newItem;
|
|
|
|
let isFirst = items.first() === newItem;
|
|
|
|
|
|
|
|
backButton.setVisible(!isFirst);
|
|
|
|
nextButton.setVisible(!isLast);
|
|
|
|
finishButton.setVisible(isLast);
|
|
|
|
|
|
|
|
me.setButtonState(newItem);
|
|
|
|
},
|
|
|
|
|
|
|
|
previousTab: function() {
|
|
|
|
let me = this;
|
|
|
|
let tabpanel = me.lookup('tabpanel');
|
|
|
|
let index = tabpanel.items.indexOf(tabpanel.getActiveTab());
|
|
|
|
tabpanel.setActiveTab(index - 1);
|
|
|
|
},
|
|
|
|
|
|
|
|
nextTab: function() {
|
|
|
|
let me = this;
|
|
|
|
let tabpanel = me.lookup('tabpanel');
|
|
|
|
let index = tabpanel.items.indexOf(tabpanel.getActiveTab());
|
|
|
|
tabpanel.setActiveTab(index + 1);
|
|
|
|
},
|
|
|
|
|
|
|
|
getValues: function() {
|
|
|
|
let me = this;
|
|
|
|
|
|
|
|
let values = {};
|
|
|
|
|
|
|
|
let tabpanel = me.lookup('tabpanel');
|
|
|
|
tabpanel
|
|
|
|
.query('inputpanel')
|
|
|
|
.forEach((panel) =>
|
|
|
|
Proxmox.Utils.assemble_field_data(values, panel.getValues()));
|
|
|
|
|
|
|
|
return values;
|
|
|
|
},
|
|
|
|
|
|
|
|
finish: function() {
|
|
|
|
let me = this;
|
|
|
|
let view = me.getView();
|
|
|
|
|
|
|
|
let values = me.getValues();
|
|
|
|
let url = view.url;
|
|
|
|
let method = view.method;
|
|
|
|
|
|
|
|
Proxmox.Utils.API2Request({
|
|
|
|
url,
|
|
|
|
waitMsgTarget: view,
|
|
|
|
method,
|
|
|
|
params: values,
|
|
|
|
failure: function(response, options) {
|
|
|
|
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
|
2021-03-25 10:04:40 +00:00
|
|
|
},
|
2021-05-21 10:20:20 +00:00
|
|
|
success: function(response, options) {
|
2021-05-26 17:00:12 +00:00
|
|
|
// keep around so we can trigger our close events when background action completes
|
2021-05-21 10:20:20 +00:00
|
|
|
view.hide();
|
|
|
|
|
|
|
|
Ext.create('Proxmox.window.TaskViewer', {
|
|
|
|
autoShow: true,
|
|
|
|
upid: response.result.data,
|
|
|
|
listeners: {
|
2021-05-26 17:00:12 +00:00
|
|
|
destroy: () => view.close(),
|
2021-05-21 10:20:20 +00:00
|
|
|
},
|
|
|
|
});
|
2021-03-25 10:04:40 +00:00
|
|
|
},
|
2021-05-21 10:20:20 +00:00
|
|
|
});
|
|
|
|
},
|
2021-03-25 10:04:40 +00:00
|
|
|
|
2021-05-21 13:44:16 +00:00
|
|
|
updateDatastores: function(grid, values) {
|
2021-05-21 10:20:20 +00:00
|
|
|
let me = this;
|
|
|
|
if (values === 'all') {
|
|
|
|
values = [];
|
|
|
|
}
|
|
|
|
let datastores = {};
|
2021-05-26 13:48:09 +00:00
|
|
|
values.forEach((snapshotOrDatastore) => {
|
|
|
|
let datastore = snapshotOrDatastore;
|
|
|
|
if (snapshotOrDatastore.indexOf(':') !== -1) {
|
|
|
|
let snapshot = snapshotOrDatastore;
|
|
|
|
let match = snapshot.split(':');
|
|
|
|
datastore = match[0];
|
|
|
|
} datastores[datastore] = true;
|
2021-05-21 10:20:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
me.setDataStores(Object.keys(datastores));
|
|
|
|
},
|
|
|
|
|
|
|
|
setDataStores: function(datastores, initial) {
|
|
|
|
let me = this;
|
|
|
|
|
2021-05-21 13:18:54 +00:00
|
|
|
// save all datastores on the first setting, and restore them if we selected all
|
2021-05-21 10:20:20 +00:00
|
|
|
if (initial) {
|
|
|
|
me.datastores = datastores;
|
|
|
|
} else if (datastores.length === 0) {
|
|
|
|
datastores = me.datastores;
|
|
|
|
}
|
|
|
|
|
2021-05-21 13:24:52 +00:00
|
|
|
const singleDatastore = !datastores || datastores.length <= 1;
|
|
|
|
me.getViewModel().set('singleDatastore', singleDatastore);
|
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
let grid = me.lookup('mappingGrid');
|
2021-05-21 13:24:52 +00:00
|
|
|
if (!singleDatastore && grid) {
|
|
|
|
grid.setDataStores(datastores);
|
2021-05-21 10:20:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
updateSnapshots: function() {
|
|
|
|
let me = this;
|
|
|
|
let view = me.getView();
|
|
|
|
let grid = me.lookup('snapshotGrid');
|
2021-05-26 13:48:07 +00:00
|
|
|
let vm = me.getViewModel();
|
|
|
|
let uuid = vm.get('uuid');
|
2021-05-21 10:20:20 +00:00
|
|
|
|
|
|
|
Proxmox.Utils.API2Request({
|
|
|
|
waitMsgTarget: view,
|
2021-05-26 13:48:07 +00:00
|
|
|
url: `/tape/media/content?media-set=${uuid}`,
|
2021-05-21 10:20:20 +00:00
|
|
|
success: function(response, opt) {
|
|
|
|
let datastores = {};
|
|
|
|
for (const content of response.result.data) {
|
|
|
|
datastores[content.store] = true;
|
|
|
|
}
|
|
|
|
me.setDataStores(Object.keys(datastores), true);
|
|
|
|
if (response.result.data.length > 0) {
|
|
|
|
grid.setDisabled(false);
|
2021-05-26 13:48:09 +00:00
|
|
|
grid.setData(response.result.data);
|
2021-05-21 10:20:20 +00:00
|
|
|
grid.getSelectionModel().selectAll();
|
|
|
|
// we've shown a big list, center the window again
|
|
|
|
view.center();
|
|
|
|
}
|
2021-03-25 10:04:40 +00:00
|
|
|
},
|
2021-05-21 10:20:20 +00:00
|
|
|
failure: function() {
|
|
|
|
// ignore failing api call, maybe catalog is missing
|
|
|
|
me.setDataStores([], true);
|
2021-03-25 10:04:40 +00:00
|
|
|
},
|
2021-05-21 10:20:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2021-05-26 13:48:07 +00:00
|
|
|
init: function(view) {
|
|
|
|
let me = this;
|
|
|
|
let vm = me.getViewModel();
|
|
|
|
|
|
|
|
vm.set('uuid', view.uuid);
|
|
|
|
},
|
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
control: {
|
|
|
|
'[isFormField]': {
|
|
|
|
change: 'checkValidity',
|
|
|
|
validitychange: 'checkValidity',
|
|
|
|
},
|
|
|
|
'tabpanel': {
|
|
|
|
tabchange: 'changeButtonVisibility',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
text: gettext('Back'),
|
|
|
|
reference: 'backButton',
|
|
|
|
handler: 'previousTab',
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: gettext('Next'),
|
|
|
|
reference: 'nextButton',
|
|
|
|
handler: 'nextTab',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: gettext('Restore'),
|
|
|
|
reference: 'finishButton',
|
|
|
|
handler: 'finish',
|
|
|
|
hidden: true,
|
2021-02-02 13:00:38 +00:00
|
|
|
},
|
2021-03-25 10:04:40 +00:00
|
|
|
],
|
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
items: [
|
|
|
|
{
|
|
|
|
xtype: 'tabpanel',
|
|
|
|
reference: 'tabpanel',
|
|
|
|
layout: 'fit',
|
|
|
|
bodyPadding: 10,
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
title: gettext('Snapshot Selection'),
|
|
|
|
xtype: 'inputpanel',
|
|
|
|
onGetValues: function(values) {
|
|
|
|
let me = this;
|
2021-03-25 10:04:40 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
if (values !== "all" &&
|
|
|
|
Ext.isString(values.snapshots) &&
|
|
|
|
values.snapshots &&
|
|
|
|
values.snapshots.indexOf(':') !== -1
|
|
|
|
) {
|
2021-05-21 10:20:20 +00:00
|
|
|
values.snapshots = values.snapshots.split(',');
|
2021-05-26 13:48:09 +00:00
|
|
|
} else {
|
|
|
|
delete values.snapshots;
|
2021-05-21 10:20:20 +00:00
|
|
|
}
|
2021-03-25 10:04:40 +00:00
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
return values;
|
|
|
|
},
|
2021-03-25 10:04:40 +00:00
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
column1: [
|
2021-05-26 13:48:07 +00:00
|
|
|
{
|
|
|
|
xtype: 'pbsMediaSetSelector',
|
|
|
|
fieldLabel: gettext('Media-Set'),
|
|
|
|
width: 350,
|
|
|
|
submitValue: false,
|
2021-05-26 17:10:16 +00:00
|
|
|
emptyText: gettext('Select Media-Set to restore'),
|
2021-05-26 13:48:07 +00:00
|
|
|
bind: {
|
|
|
|
value: '{uuid}',
|
|
|
|
},
|
|
|
|
cbind: {
|
|
|
|
hidden: '{uuid}',
|
|
|
|
disabled: '{uuid}',
|
|
|
|
},
|
|
|
|
listeners: {
|
|
|
|
change: 'changeMediaSet',
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 10:20:20 +00:00
|
|
|
{
|
|
|
|
xtype: 'displayfield',
|
2021-05-21 13:53:50 +00:00
|
|
|
fieldLabel: gettext('Media-Set'),
|
2021-05-21 10:20:20 +00:00
|
|
|
cbind: {
|
|
|
|
value: '{mediaset}',
|
2021-05-26 13:48:07 +00:00
|
|
|
hidden: '{!uuid}',
|
|
|
|
disabled: '{!uuid}',
|
2021-05-21 10:20:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2021-03-25 10:04:40 +00:00
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
column2: [
|
|
|
|
{
|
|
|
|
xtype: 'displayfield',
|
2021-05-21 13:53:50 +00:00
|
|
|
fieldLabel: gettext('Media-Set UUID'),
|
2021-05-21 10:20:20 +00:00
|
|
|
name: 'media-set',
|
|
|
|
submitValue: true,
|
2021-05-26 13:48:07 +00:00
|
|
|
bind: {
|
2021-05-21 10:20:20 +00:00
|
|
|
value: '{uuid}',
|
2021-05-26 13:48:07 +00:00
|
|
|
hidden: '{!uuid}',
|
|
|
|
disabled: '{!uuid}',
|
2021-05-21 10:20:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
columnB: [
|
|
|
|
{
|
|
|
|
xtype: 'pbsTapeSnapshotGrid',
|
|
|
|
reference: 'snapshotGrid',
|
|
|
|
name: 'snapshots',
|
|
|
|
height: 322,
|
2021-05-21 13:18:54 +00:00
|
|
|
disabled: true, // will be shown/enabled on successful load
|
2021-05-21 10:20:20 +00:00
|
|
|
listeners: {
|
|
|
|
change: 'updateDatastores',
|
|
|
|
},
|
|
|
|
cbind: {
|
|
|
|
prefilter: '{prefilter}',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: gettext('Target'),
|
|
|
|
xtype: 'inputpanel',
|
|
|
|
onGetValues: function(values) {
|
|
|
|
let me = this;
|
|
|
|
let datastores = [];
|
|
|
|
if (values.store.toString() !== "") {
|
|
|
|
datastores.push(values.store);
|
|
|
|
delete values.store;
|
|
|
|
}
|
2021-03-25 10:04:40 +00:00
|
|
|
|
2021-05-21 10:20:20 +00:00
|
|
|
if (values.mapping.toString() !== "") {
|
|
|
|
datastores.push(values.mapping);
|
2021-03-25 10:04:40 +00:00
|
|
|
}
|
2021-05-21 10:20:20 +00:00
|
|
|
delete values.mapping;
|
|
|
|
|
|
|
|
values.store = datastores.join(',');
|
|
|
|
|
|
|
|
return values;
|
2021-03-25 10:04:40 +00:00
|
|
|
},
|
2021-05-21 10:20:20 +00:00
|
|
|
column1: [
|
|
|
|
{
|
|
|
|
xtype: 'pbsUserSelector',
|
|
|
|
name: 'notify-user',
|
|
|
|
fieldLabel: gettext('Notify User'),
|
|
|
|
emptyText: gettext('Current User'),
|
|
|
|
value: null,
|
|
|
|
allowBlank: true,
|
|
|
|
skipEmptyText: true,
|
|
|
|
renderer: Ext.String.htmlEncode,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'pbsUserSelector',
|
|
|
|
name: 'owner',
|
|
|
|
fieldLabel: gettext('Owner'),
|
|
|
|
emptyText: gettext('Current User'),
|
|
|
|
value: null,
|
|
|
|
allowBlank: true,
|
|
|
|
skipEmptyText: true,
|
|
|
|
renderer: Ext.String.htmlEncode,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
column2: [
|
|
|
|
{
|
|
|
|
xtype: 'pbsDriveSelector',
|
2021-05-21 13:18:54 +00:00
|
|
|
name: 'drive',
|
2021-05-21 10:20:20 +00:00
|
|
|
fieldLabel: gettext('Drive'),
|
|
|
|
labelWidth: 120,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'pbsDataStoreSelector',
|
2021-05-21 13:24:52 +00:00
|
|
|
name: 'store',
|
2021-05-21 10:20:20 +00:00
|
|
|
labelWidth: 120,
|
2021-05-21 13:24:52 +00:00
|
|
|
bind: {
|
|
|
|
fieldLabel: '{singleSelectorLabel}',
|
|
|
|
emptyText: '{singleSelectorEmptyText}',
|
|
|
|
allowBlank: '{!singleDatastore}',
|
|
|
|
},
|
2021-05-21 10:20:20 +00:00
|
|
|
listeners: {
|
|
|
|
change: function(field, value) {
|
2021-05-21 13:18:54 +00:00
|
|
|
this.up('window').lookup('mappingGrid').setNeedStores(!value);
|
2021-05-21 10:20:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
columnB: [
|
|
|
|
{
|
2021-05-21 13:18:54 +00:00
|
|
|
xtype: 'displayfield',
|
2021-05-21 10:20:20 +00:00
|
|
|
fieldLabel: gettext('Datastore Mapping'),
|
|
|
|
labelWidth: 200,
|
2021-05-21 13:24:52 +00:00
|
|
|
bind: {
|
|
|
|
hidden: '{singleDatastore}',
|
|
|
|
},
|
2021-05-21 10:20:20 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'pbsDataStoreMappingField',
|
|
|
|
name: 'mapping',
|
2021-05-21 13:18:54 +00:00
|
|
|
reference: 'mappingGrid',
|
2021-05-21 10:20:20 +00:00
|
|
|
height: 260,
|
|
|
|
defaultBindProperty: 'value',
|
2021-05-21 13:24:52 +00:00
|
|
|
bind: {
|
|
|
|
hidden: '{singleDatastore}',
|
|
|
|
},
|
2021-05-21 10:20:20 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
listeners: {
|
|
|
|
afterrender: 'updateSnapshots',
|
2021-03-25 10:04:40 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Ext.define('PBS.TapeManagement.DataStoreMappingGrid', {
|
|
|
|
extend: 'Ext.grid.Panel',
|
|
|
|
alias: 'widget.pbsDataStoreMappingField',
|
|
|
|
mixins: ['Ext.form.field.Field'],
|
|
|
|
|
2021-05-21 10:20:18 +00:00
|
|
|
scrollable: true,
|
|
|
|
|
2021-03-25 10:04:40 +00:00
|
|
|
getValue: function() {
|
|
|
|
let me = this;
|
|
|
|
let datastores = [];
|
2021-05-21 13:18:54 +00:00
|
|
|
me.getStore().each(rec => {
|
|
|
|
let { source, target } = rec.data;
|
2021-03-25 10:04:40 +00:00
|
|
|
if (target && target !== "") {
|
|
|
|
datastores.push(`${source}=${target}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return datastores.join(',');
|
|
|
|
},
|
|
|
|
|
2021-05-21 12:31:05 +00:00
|
|
|
viewModel: {
|
|
|
|
data: {
|
|
|
|
needStores: false, // this determines if we need at least one valid mapping
|
|
|
|
},
|
|
|
|
formulas: {
|
|
|
|
emptyMeans: get => get('needStores') ? Proxmox.Utils.NoneText : Proxmox.Utils.defaultText,
|
|
|
|
},
|
|
|
|
},
|
2021-03-25 10:04:40 +00:00
|
|
|
|
|
|
|
setNeedStores: function(needStores) {
|
|
|
|
let me = this;
|
2021-05-21 12:31:05 +00:00
|
|
|
me.getViewModel().set('needStores', needStores);
|
2021-03-25 10:04:40 +00:00
|
|
|
me.checkChange();
|
|
|
|
me.validate();
|
|
|
|
},
|
|
|
|
|
|
|
|
setValue: function(value) {
|
|
|
|
let me = this;
|
|
|
|
me.setDataStores(value);
|
|
|
|
return me;
|
|
|
|
},
|
|
|
|
|
|
|
|
getErrors: function(value) {
|
|
|
|
let me = this;
|
|
|
|
let error = false;
|
|
|
|
|
2021-05-21 12:31:05 +00:00
|
|
|
if (me.getViewModel().get('needStores')) {
|
2021-03-25 10:04:40 +00:00
|
|
|
error = true;
|
2021-05-21 13:18:54 +00:00
|
|
|
me.getStore().each(rec => {
|
2021-03-25 10:04:40 +00:00
|
|
|
if (rec.data.target) {
|
|
|
|
error = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-21 10:20:18 +00:00
|
|
|
let el = me.getActionEl();
|
2021-03-25 10:04:40 +00:00
|
|
|
if (error) {
|
|
|
|
me.addCls(['x-form-trigger-wrap-default', 'x-form-trigger-wrap-invalid']);
|
|
|
|
let errorMsg = gettext("Need at least one mapping");
|
2021-05-21 10:20:18 +00:00
|
|
|
if (el) {
|
|
|
|
el.dom.setAttribute('data-errorqtip', errorMsg);
|
|
|
|
}
|
2021-03-25 10:04:40 +00:00
|
|
|
|
|
|
|
return [errorMsg];
|
|
|
|
}
|
|
|
|
me.removeCls(['x-form-trigger-wrap-default', 'x-form-trigger-wrap-invalid']);
|
2021-05-21 10:20:18 +00:00
|
|
|
if (el) {
|
|
|
|
el.dom.setAttribute('data-errorqtip', "");
|
|
|
|
}
|
2021-03-25 10:04:40 +00:00
|
|
|
return [];
|
|
|
|
},
|
|
|
|
|
|
|
|
setDataStores: function(datastores) {
|
|
|
|
let me = this;
|
|
|
|
|
2021-05-21 13:18:54 +00:00
|
|
|
let data = [];
|
2021-03-25 10:04:40 +00:00
|
|
|
for (const datastore of datastores) {
|
|
|
|
data.push({
|
|
|
|
source: datastore,
|
|
|
|
target: '',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-21 13:18:54 +00:00
|
|
|
me.getStore().setData(data);
|
2021-03-25 10:04:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
viewConfig: {
|
|
|
|
markDirty: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
store: { data: [] },
|
|
|
|
|
|
|
|
columns: [
|
2021-02-02 13:00:38 +00:00
|
|
|
{
|
2021-03-25 10:04:40 +00:00
|
|
|
text: gettext('Source Datastore'),
|
|
|
|
dataIndex: 'source',
|
|
|
|
flex: 1,
|
2021-03-05 08:45:32 +00:00
|
|
|
},
|
2021-03-12 10:28:41 +00:00
|
|
|
{
|
2021-03-25 10:04:40 +00:00
|
|
|
text: gettext('Target Datastore'),
|
|
|
|
xtype: 'widgetcolumn',
|
|
|
|
dataIndex: 'target',
|
|
|
|
flex: 1,
|
|
|
|
widget: {
|
|
|
|
xtype: 'pbsDataStoreSelector',
|
|
|
|
allowBlank: true,
|
2021-05-21 12:31:05 +00:00
|
|
|
bind: {
|
|
|
|
emptyText: '{emptyMeans}',
|
|
|
|
},
|
2021-03-25 10:04:40 +00:00
|
|
|
listeners: {
|
|
|
|
change: function(selector, value) {
|
|
|
|
let me = this;
|
|
|
|
let rec = me.getWidgetRecord();
|
|
|
|
if (!rec) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rec.set('target', value);
|
|
|
|
me.up('grid').checkChange();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-12 10:28:41 +00:00
|
|
|
},
|
2021-02-02 13:00:38 +00:00
|
|
|
],
|
|
|
|
});
|
2021-05-14 12:59:21 +00:00
|
|
|
|
|
|
|
Ext.define('PBS.TapeManagement.SnapshotGrid', {
|
|
|
|
extend: 'Ext.grid.Panel',
|
|
|
|
alias: 'widget.pbsTapeSnapshotGrid',
|
|
|
|
mixins: ['Ext.form.field.Field'],
|
|
|
|
|
|
|
|
getValue: function() {
|
|
|
|
let me = this;
|
|
|
|
let snapshots = [];
|
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
let storeCounts = {};
|
|
|
|
|
2021-05-14 12:59:21 +00:00
|
|
|
me.getSelection().forEach((rec) => {
|
|
|
|
let id = rec.get('id');
|
|
|
|
let store = rec.data.store;
|
|
|
|
let snap = rec.data.snapshot;
|
|
|
|
// only add if not filtered
|
|
|
|
if (me.store.findExact('id', id) !== -1) {
|
|
|
|
snapshots.push(`${store}:${snap}`);
|
2021-05-26 13:48:09 +00:00
|
|
|
if (storeCounts[store] === undefined) {
|
|
|
|
storeCounts[store] = 0;
|
|
|
|
}
|
|
|
|
storeCounts[store]++;
|
2021-05-14 12:59:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-05-21 10:20:19 +00:00
|
|
|
// getSource returns null if data is not filtered
|
|
|
|
let originalData = me.store.getData().getSource() || me.store.getData();
|
|
|
|
|
|
|
|
if (snapshots.length === originalData.length) {
|
|
|
|
return "all";
|
|
|
|
}
|
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
let wholeStores = [];
|
|
|
|
let wholeStoresSelected = true;
|
|
|
|
for (const [store, count] of Object.entries(storeCounts)) {
|
|
|
|
if (me.storeCounts[store] === count) {
|
|
|
|
wholeStores.push(store);
|
|
|
|
} else {
|
|
|
|
wholeStoresSelected = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wholeStoresSelected) {
|
|
|
|
return wholeStores;
|
|
|
|
}
|
|
|
|
|
2021-05-14 12:59:21 +00:00
|
|
|
return snapshots;
|
|
|
|
},
|
|
|
|
|
|
|
|
setValue: function(value) {
|
|
|
|
let me = this;
|
|
|
|
// not implemented
|
|
|
|
return me;
|
|
|
|
},
|
|
|
|
|
|
|
|
getErrors: function(value) {
|
|
|
|
let me = this;
|
2021-05-21 10:20:19 +00:00
|
|
|
if (me.getSelection().length < 1) {
|
2021-05-14 12:59:21 +00:00
|
|
|
me.addCls(['x-form-trigger-wrap-default', 'x-form-trigger-wrap-invalid']);
|
|
|
|
let errorMsg = gettext("Need at least one snapshot");
|
2021-05-21 10:20:19 +00:00
|
|
|
let el = me.getActionEl();
|
|
|
|
if (el) {
|
|
|
|
el.dom.setAttribute('data-errorqtip', errorMsg);
|
|
|
|
}
|
2021-05-14 12:59:21 +00:00
|
|
|
|
|
|
|
return [errorMsg];
|
|
|
|
}
|
|
|
|
me.removeCls(['x-form-trigger-wrap-default', 'x-form-trigger-wrap-invalid']);
|
2021-05-21 10:20:19 +00:00
|
|
|
let el = me.getActionEl();
|
|
|
|
if (el) {
|
|
|
|
el.dom.setAttribute('data-errorqtip', "");
|
|
|
|
}
|
2021-05-14 12:59:21 +00:00
|
|
|
return [];
|
|
|
|
},
|
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
setData: function(records) {
|
|
|
|
let me = this;
|
|
|
|
let storeCounts = {};
|
|
|
|
records.forEach((rec) => {
|
|
|
|
let store = rec.store;
|
|
|
|
if (storeCounts[store] === undefined) {
|
|
|
|
storeCounts[store] = 0;
|
|
|
|
}
|
|
|
|
storeCounts[store]++;
|
|
|
|
});
|
|
|
|
me.storeCounts = storeCounts;
|
|
|
|
me.getStore().setData(records);
|
|
|
|
},
|
|
|
|
|
2021-05-14 12:59:21 +00:00
|
|
|
scrollable: true,
|
|
|
|
plugins: 'gridfilters',
|
|
|
|
|
|
|
|
viewConfig: {
|
|
|
|
emptyText: gettext('No Snapshots'),
|
|
|
|
markDirty: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
selModel: 'checkboxmodel',
|
|
|
|
store: {
|
|
|
|
sorters: ['store', 'snapshot'],
|
|
|
|
data: [],
|
|
|
|
filters: [],
|
|
|
|
},
|
|
|
|
|
|
|
|
listeners: {
|
|
|
|
selectionchange: function() {
|
|
|
|
// to trigger validity and error checks
|
|
|
|
this.checkChange();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
checkChangeEvents: [
|
|
|
|
'selectionchange',
|
|
|
|
'change',
|
|
|
|
],
|
|
|
|
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
text: gettext('Source Datastore'),
|
|
|
|
dataIndex: 'store',
|
|
|
|
filter: {
|
|
|
|
type: 'list',
|
|
|
|
},
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: gettext('Snapshot'),
|
|
|
|
dataIndex: 'snapshot',
|
|
|
|
filter: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
flex: 2,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
initComponent: function() {
|
|
|
|
let me = this;
|
|
|
|
me.callParent();
|
|
|
|
if (me.prefilter !== undefined) {
|
2021-05-26 13:48:10 +00:00
|
|
|
if (me.prefilter.store !== undefined) {
|
|
|
|
me.store.filters.add(
|
|
|
|
{
|
|
|
|
id: 'x-gridfilter-store',
|
|
|
|
property: 'store',
|
|
|
|
operator: 'in',
|
|
|
|
value: [me.prefilter.store],
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (me.prefilter.snapshot !== undefined) {
|
|
|
|
me.store.filters.add(
|
|
|
|
{
|
|
|
|
id: 'x-gridfilter-snapshot',
|
|
|
|
property: 'snapshot',
|
|
|
|
value: me.prefilter.snapshot,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2021-05-14 12:59:21 +00:00
|
|
|
}
|
2021-05-21 10:20:19 +00:00
|
|
|
|
|
|
|
me.mon(me.store, 'filterchange', () => me.checkChange());
|
2021-05-14 12:59:21 +00:00
|
|
|
},
|
|
|
|
});
|
2021-05-26 13:48:06 +00:00
|
|
|
|
|
|
|
Ext.define('PBS.TapeManagement.MediaSetSelector', {
|
|
|
|
extend: 'Proxmox.form.ComboGrid',
|
|
|
|
alias: 'widget.pbsMediaSetSelector',
|
|
|
|
|
|
|
|
allowBlank: false,
|
|
|
|
displayField: 'media-set-name',
|
|
|
|
valueField: 'media-set-uuid',
|
|
|
|
autoSelect: false,
|
|
|
|
|
|
|
|
store: {
|
|
|
|
proxy: {
|
|
|
|
type: 'proxmox',
|
|
|
|
url: '/api2/json/tape/media/media-sets',
|
|
|
|
},
|
|
|
|
autoLoad: true,
|
|
|
|
idProperty: 'media-set-uuid',
|
|
|
|
sorters: ['pool', 'media-set-ctime'],
|
|
|
|
},
|
|
|
|
|
|
|
|
listConfig: {
|
|
|
|
width: 600,
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
text: gettext('Pool'),
|
|
|
|
dataIndex: 'pool',
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: gettext('Name'),
|
|
|
|
dataIndex: 'media-set-name',
|
|
|
|
width: 180,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: gettext('Media-Set UUID'),
|
|
|
|
dataIndex: 'media-set-uuid',
|
|
|
|
width: 280,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|