mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-02-10 18:05:06 +08:00
Add confirmation dialog for deleting custom assistants
This commit is contained in:
@ -31,6 +31,15 @@ ol {
|
||||
width: calc(100% - 24px);
|
||||
}
|
||||
|
||||
#deletion_text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
padding: 10px 0 0 0;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#custom_assistant {
|
||||
height: auto;
|
||||
padding: 10px 13px;
|
||||
|
||||
@ -961,7 +961,7 @@ function customAssistantWindowShow(assistantId, buttonAssistant)
|
||||
if (window.customAssistantWindow) {
|
||||
closeCustomAssistantWindow();
|
||||
}
|
||||
const actionButtonText = assistantId ? window.Asc.plugin.tr('Save') : window.Asc.plugin.tr('Add');
|
||||
const actionButtonText = assistantId ? 'Save' : 'Add';
|
||||
|
||||
let variation = {
|
||||
url : "customAssistant.html",
|
||||
@ -1014,7 +1014,7 @@ function customAssistantWindowShow(assistantId, buttonAssistant)
|
||||
{
|
||||
text: 'Delete',
|
||||
id: element.id + '-delete',
|
||||
onclick: () => deleteCustomAssistant(element.id, buttonAssistant)
|
||||
onclick: () => customAssistantWindowDeleteConfirm(element.id, buttonAssistant)
|
||||
}];
|
||||
buttonAssistant.attachOnClick(async function(){
|
||||
onStartCustomAssistant(element.id);
|
||||
@ -1042,16 +1042,52 @@ function closeCustomAssistantWindow() {
|
||||
window.pluginsButtonsCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} assistantId
|
||||
* @param {Asc.ButtonToolbar} buttonAssistant
|
||||
*/
|
||||
function deleteCustomAssistant(assistantId, buttonAssistant) {
|
||||
function customAssistantWindowDeleteConfirm(assistantId, buttonAssistant) {
|
||||
if (window.customAssistantWindow) {
|
||||
closeCustomAssistantWindow();
|
||||
}
|
||||
|
||||
const savedAssistants = JSON.parse(
|
||||
localStorage.getItem("onlyoffice_ai_saved_assistants") || "[]"
|
||||
);
|
||||
const index = savedAssistants.findIndex((item) => item.id === assistantId);
|
||||
const assistant = savedAssistants[index];
|
||||
|
||||
let variation = {
|
||||
url : "customAssistant.html",
|
||||
description : assistant.name,
|
||||
isVisual : true,
|
||||
buttons : [
|
||||
{ text: window.Asc.plugin.tr('Yes'), primary: true },
|
||||
{ text: window.Asc.plugin.tr('No'), primary: false },
|
||||
],
|
||||
icons: "resources/icons/%theme-name%(theme-default|theme-system|theme-classic-light)/%theme-type%(light|dark)/ask-ai%state%(normal|active)%scale%(default).png",
|
||||
isModal : false,
|
||||
isCanDocked: false,
|
||||
type: "window",
|
||||
EditorsSupport : ["word"],
|
||||
size : [ 400, 100 ]
|
||||
};
|
||||
|
||||
const customAssistantWindow = new window.Asc.PluginWindow();
|
||||
customAssistantWindow.attachEvent("onWindowReady", function() {
|
||||
Asc.Editor.callMethod("ResizeWindow", [customAssistantWindow.id, [400, 100], [400, 100], [0, 0]]);
|
||||
if (assistantId) {
|
||||
customAssistantWindow.command('onDeleteAssistant', assistant);
|
||||
}
|
||||
});
|
||||
|
||||
customAssistantWindow.show(variation);
|
||||
|
||||
window.pluginsButtonsCallback = window.Asc.plugin.button;
|
||||
window.Asc.plugin.button = async function(id, windowId, ...args) {
|
||||
if (customAssistantWindow && windowId === customAssistantWindow.id) {
|
||||
if (id === 0) {
|
||||
|
||||
if (index !== -1) {
|
||||
savedAssistants.splice(index, 1);
|
||||
localStorage.setItem(
|
||||
@ -1062,9 +1098,16 @@ function deleteCustomAssistant(assistantId, buttonAssistant) {
|
||||
buttonAssistant.removed = true;
|
||||
Asc.Buttons.updateToolbarMenu(window.buttonMainToolbar.id, window.buttonMainToolbar.name, [buttonAssistant]);
|
||||
}
|
||||
closeCustomAssistantWindow();
|
||||
}
|
||||
}
|
||||
closeCustomAssistantWindow();
|
||||
} else {
|
||||
await window.pluginsButtonsCallback(id, windowId, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
window.customAssistantWindow = customAssistantWindow;
|
||||
}
|
||||
|
||||
async function onStartCustomAssistant(assistantId)
|
||||
{
|
||||
|
||||
@ -99,6 +99,15 @@
|
||||
}
|
||||
);
|
||||
|
||||
window.Asc.plugin.attachEvent(
|
||||
"onDeleteAssistant",
|
||||
(/** @type {localStorageCustomAssistantItem} */ assistant) => {
|
||||
mainContainer.innerHTML = '<div id="deletion_text" class="noselect">' +
|
||||
window.Asc.plugin.tr("Do you really want to delete this custom assistant?") +
|
||||
'</div>';
|
||||
}
|
||||
);
|
||||
|
||||
function onThemeChanged(theme) {
|
||||
window.Asc.plugin.onThemeChangedBase(theme);
|
||||
updateBodyThemeClasses(theme.type, theme.name);
|
||||
|
||||
@ -688,7 +688,7 @@ async function registerButtons(window, undefined)
|
||||
{
|
||||
text: 'Delete',
|
||||
id: element.id + '-delete',
|
||||
onclick: () => deleteCustomAssistant(element.id, buttonAssistant)
|
||||
onclick: () => customAssistantWindowDeleteConfirm(element.id, buttonAssistant)
|
||||
}];
|
||||
buttonAssistant.attachOnClick(async function(){
|
||||
onStartCustomAssistant(element.id);
|
||||
|
||||
Reference in New Issue
Block a user