mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-04-07 14:04:30 +08:00
Add confirmation dialog for deleting custom assistants
This commit is contained in:
@ -31,6 +31,15 @@ ol {
|
|||||||
width: calc(100% - 24px);
|
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 {
|
#custom_assistant {
|
||||||
height: auto;
|
height: auto;
|
||||||
padding: 10px 13px;
|
padding: 10px 13px;
|
||||||
|
|||||||
@ -961,7 +961,7 @@ function customAssistantWindowShow(assistantId, buttonAssistant)
|
|||||||
if (window.customAssistantWindow) {
|
if (window.customAssistantWindow) {
|
||||||
closeCustomAssistantWindow();
|
closeCustomAssistantWindow();
|
||||||
}
|
}
|
||||||
const actionButtonText = assistantId ? window.Asc.plugin.tr('Save') : window.Asc.plugin.tr('Add');
|
const actionButtonText = assistantId ? 'Save' : 'Add';
|
||||||
|
|
||||||
let variation = {
|
let variation = {
|
||||||
url : "customAssistant.html",
|
url : "customAssistant.html",
|
||||||
@ -1014,7 +1014,7 @@ function customAssistantWindowShow(assistantId, buttonAssistant)
|
|||||||
{
|
{
|
||||||
text: 'Delete',
|
text: 'Delete',
|
||||||
id: element.id + '-delete',
|
id: element.id + '-delete',
|
||||||
onclick: () => deleteCustomAssistant(element.id, buttonAssistant)
|
onclick: () => customAssistantWindowDeleteConfirm(element.id, buttonAssistant)
|
||||||
}];
|
}];
|
||||||
buttonAssistant.attachOnClick(async function(){
|
buttonAssistant.attachOnClick(async function(){
|
||||||
onStartCustomAssistant(element.id);
|
onStartCustomAssistant(element.id);
|
||||||
@ -1042,28 +1042,71 @@ function closeCustomAssistantWindow() {
|
|||||||
window.pluginsButtonsCallback = null;
|
window.pluginsButtonsCallback = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} assistantId
|
* @param {string} assistantId
|
||||||
* @param {Asc.ButtonToolbar} buttonAssistant
|
* @param {Asc.ButtonToolbar} buttonAssistant
|
||||||
*/
|
*/
|
||||||
function deleteCustomAssistant(assistantId, buttonAssistant) {
|
function customAssistantWindowDeleteConfirm(assistantId, buttonAssistant) {
|
||||||
|
if (window.customAssistantWindow) {
|
||||||
|
closeCustomAssistantWindow();
|
||||||
|
}
|
||||||
|
|
||||||
const savedAssistants = JSON.parse(
|
const savedAssistants = JSON.parse(
|
||||||
localStorage.getItem("onlyoffice_ai_saved_assistants") || "[]"
|
localStorage.getItem("onlyoffice_ai_saved_assistants") || "[]"
|
||||||
);
|
);
|
||||||
const index = savedAssistants.findIndex((item) => item.id === assistantId);
|
const index = savedAssistants.findIndex((item) => item.id === assistantId);
|
||||||
if (index !== -1) {
|
const assistant = savedAssistants[index];
|
||||||
savedAssistants.splice(index, 1);
|
|
||||||
localStorage.setItem(
|
let variation = {
|
||||||
"onlyoffice_ai_saved_assistants",
|
url : "customAssistant.html",
|
||||||
JSON.stringify(savedAssistants)
|
description : assistant.name,
|
||||||
);
|
isVisual : true,
|
||||||
if (buttonAssistant) {
|
buttons : [
|
||||||
buttonAssistant.removed = true;
|
{ text: window.Asc.plugin.tr('Yes'), primary: true },
|
||||||
Asc.Buttons.updateToolbarMenu(window.buttonMainToolbar.id, window.buttonMainToolbar.name, [buttonAssistant]);
|
{ 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(
|
||||||
|
"onlyoffice_ai_saved_assistants",
|
||||||
|
JSON.stringify(savedAssistants)
|
||||||
|
);
|
||||||
|
if (buttonAssistant) {
|
||||||
|
buttonAssistant.removed = true;
|
||||||
|
Asc.Buttons.updateToolbarMenu(window.buttonMainToolbar.id, window.buttonMainToolbar.name, [buttonAssistant]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closeCustomAssistantWindow();
|
||||||
|
} else {
|
||||||
|
await window.pluginsButtonsCallback(id, windowId, ...args);
|
||||||
}
|
}
|
||||||
closeCustomAssistantWindow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.customAssistantWindow = customAssistantWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onStartCustomAssistant(assistantId)
|
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) {
|
function onThemeChanged(theme) {
|
||||||
window.Asc.plugin.onThemeChangedBase(theme);
|
window.Asc.plugin.onThemeChangedBase(theme);
|
||||||
updateBodyThemeClasses(theme.type, theme.name);
|
updateBodyThemeClasses(theme.type, theme.name);
|
||||||
|
|||||||
@ -688,7 +688,7 @@ async function registerButtons(window, undefined)
|
|||||||
{
|
{
|
||||||
text: 'Delete',
|
text: 'Delete',
|
||||||
id: element.id + '-delete',
|
id: element.id + '-delete',
|
||||||
onclick: () => deleteCustomAssistant(element.id, buttonAssistant)
|
onclick: () => customAssistantWindowDeleteConfirm(element.id, buttonAssistant)
|
||||||
}];
|
}];
|
||||||
buttonAssistant.attachOnClick(async function(){
|
buttonAssistant.attachOnClick(async function(){
|
||||||
onStartCustomAssistant(element.id);
|
onStartCustomAssistant(element.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user