[feature] Add reset settings buttons

This commit is contained in:
PauI Ostrovckij
2025-06-10 19:51:00 +03:00
parent 98d5933e94
commit 27fa860f2f
3 changed files with 120 additions and 1 deletions

View File

@ -25,6 +25,9 @@ window.Asc.plugin.init = function() {
updatedComboBoxes();
});
window.Asc.plugin.attachEvent("onThemeChanged", onThemeChanged);
window.Asc.plugin.attachEvent("onResetSelectors", function() {
$('.ai-model-select').val('').trigger('change');
});
$('#edit-ai-models label').click(function(e) {
window.Asc.plugin.sendToPlugin("onOpenAiModelsModal");

View File

@ -13,6 +13,8 @@ const AIIntegration = {
// Callback functions
onSave: null,
onOk: null,
onResetActions: null,
onResetAllSettings: null,
// Initialize the AI integration
init() {
@ -44,6 +46,8 @@ const AIIntegration = {
<div class="ai-controls" id="ai-controls">
<button class="ai-btn" id="ai-btn-back" style="display: none;">Back</button>
<button class="ai-btn" id="ai-btn-cancel" style="display: none;">Cancel</button>
<button class="ai-btn" id="ai-btn-reset-all-settings" style="display: none;">Reset All Settings</button>
<button class="ai-btn" id="ai-btn-reset-actions" style="display: none;">Reset</button>
<button class="ai-btn primary" id="ai-btn-save" style="display: none;">Save</button>
<button class="ai-btn primary" id="ai-btn-ok" style="display: none;">OK</button>
</div>
@ -60,6 +64,8 @@ const AIIntegration = {
const btnCancel = document.getElementById('ai-btn-cancel');
const btnSave = document.getElementById('ai-btn-save');
const btnOk = document.getElementById('ai-btn-ok');
const btnResetActions = document.getElementById('ai-btn-reset-actions');
const btnResetAllSettings = document.getElementById('ai-btn-reset-all-settings');
const iframeSettings = document.getElementById('ai-iframe-settings');
const iframeEdit = document.getElementById('ai-iframe-edit');
const iframeList = document.getElementById('ai-iframe-list');
@ -83,6 +89,14 @@ const AIIntegration = {
if (btnOk) {
btnOk.addEventListener('click', () => this.ok());
}
if (btnResetActions) {
btnResetActions.addEventListener('click', () => this.resetActions());
}
if (btnResetAllSettings) {
btnResetAllSettings.addEventListener('click', () => this.resetAllSettings());
}
if (iframeSettings) {
iframeSettings.addEventListener('load', () => this.onIframeLoad());
@ -164,9 +178,11 @@ const AIIntegration = {
const btnCancel = document.getElementById('ai-btn-cancel');
const btnSave = document.getElementById('ai-btn-save');
const btnOk = document.getElementById('ai-btn-ok');
const btnResetActions = document.getElementById('ai-btn-reset-actions');
const btnResetAllSettings = document.getElementById('ai-btn-reset-all-settings');
// Hide all buttons first
[btnBack, btnCancel, btnSave, btnOk].forEach(btn => {
[btnBack, btnCancel, btnSave, btnOk, btnResetActions, btnResetAllSettings].forEach(btn => {
if (btn) btn.style.display = 'none';
});
@ -174,6 +190,8 @@ const AIIntegration = {
switch (this.currentView) {
case 'settings':
if (btnSave) btnSave.style.display = 'inline-block';
if (btnResetActions) btnResetActions.style.display = 'inline-block';
if (btnResetAllSettings) btnResetAllSettings.style.display = 'inline-block';
break;
case 'aiModelEdit':
if (btnOk) btnOk.style.display = 'inline-block';
@ -245,6 +263,40 @@ const AIIntegration = {
cancel() {
this.navigateToView('aiModelsList');
},
resetActions() {
if (this.onResetActions) {
this.onResetActions().then((res) => {
const btnResetActions = document.getElementById('ai-btn-reset-actions');
if (btnResetActions) {
const originalText = btnResetActions.textContent;
btnResetActions.textContent = res ? 'Actions Reset!' : 'Reset Failed!';
btnResetActions.disabled = true;
setTimeout(() => {
btnResetActions.textContent = originalText;
btnResetActions.disabled = false;
}, 2000);
}
});
}
},
resetAllSettings() {
if (this.onResetAllSettings) {
this.onResetAllSettings().then((res) => {
const btnResetAllSettings = document.getElementById('ai-btn-reset-all-settings');
if (btnResetAllSettings) {
const originalText = btnResetAllSettings.textContent;
btnResetAllSettings.textContent = res ? 'Settings Reset!' : 'Reset Failed!';
btnResetAllSettings.disabled = true;
setTimeout(() => {
btnResetAllSettings.textContent = originalText;
btnResetAllSettings.disabled = false;
}, 2000);
}
});
}
}
};

View File

@ -61,6 +61,70 @@
return false;
});
};
AIIntegration.onResetActions = function() {
try {
var settingsWindow = findIframeBySrcPart('settings');
if (settingsWindow && settingsWindow.contentWindow) {
if (settings && settings.actions) {
for (let id in settings.actions) {
if (settings.actions[id]) {
settings.actions[id].model = "";
}
}
}
sendMessageToSettings({
name: 'onResetSelectors'
}, settingsWindow.contentWindow);
return Promise.resolve(true);
}
} catch (error) {
console.error('Reset actions error:', error);
}
return Promise.resolve(false);
};
AIIntegration.onResetAllSettings = function() {
try {
if (settings) {
// Reset actions models
if (settings.actions) {
for (let id in settings.actions) {
if (settings.actions[id]) {
settings.actions[id].model = "";
}
}
}
// Reset models array
settings.models = [];
// Reset custom providers
settings.customProviders = {};
// Reset providers
if (settings.providers) {
for (let id in settings.providers) {
if (settings.providers[id]) {
settings.providers[id].key = "";
settings.providers[id].models = [];
}
}
}
// Update UI
var settingsWindow = findIframeBySrcPart('settings');
if (settingsWindow && settingsWindow.contentWindow) {
sendMessageToSettings({
name: 'onResetSelectors'
}, settingsWindow.contentWindow);
}
return Promise.resolve(true);
}
} catch (error) {
console.error('Reset all settings error:', error);
}
return Promise.resolve(false);
};
AIIntegration.onOk = function() {
var aiModelEditWindow = findIframeBySrcPart('aiModelEdit');
if(aiModelEditWindow) {