Files
crm.clientright.ru/layouts/v7/lib/nextcloud-editor.js

59 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Nextcloud Editor Integration
* Функция для редактирования документов в Nextcloud
*/
function editInNextcloud(recordId, fileName) {
console.log('Opening file in Nextcloud:', recordId, fileName);
// Проверяем расширение
const ext = fileName.split('.').pop().toLowerCase();
if (!['docx', 'xlsx', 'pptx'].includes(ext)) {
alert('Файл ' + fileName + ' не поддерживается для редактирования. Поддерживаются: docx, xlsx, pptx');
return;
}
// Отправляем запрос к нашему API
const apiUrl = `crm_extensions/nextcloud_api.php?record=${encodeURIComponent(recordId)}&fileName=${encodeURIComponent(fileName)}`;
fetch(apiUrl, {
method: 'GET'
})
.then(response => {
console.log('Response status:', response.status);
return response.json();
})
.then(json => {
console.log('JSON response:', json);
if (json.success && json.data && json.data.urls) {
// Сначала пробуем файловый менеджер, потом прямой редактор
const filesManagerUrl = json.data.urls.files_manager;
const collaboraUrl = json.data.urls.collabora_id;
const onlyofficeUrl = json.data.urls.onlyoffice_id;
if (filesManagerUrl) {
console.log('Opening files manager:', filesManagerUrl);
window.open(filesManagerUrl, '_blank');
} else if (collaboraUrl) {
console.log('Opening Collabora:', collaboraUrl);
window.open(collaboraUrl, '_blank');
} else if (onlyofficeUrl) {
console.log('Opening OnlyOffice:', onlyofficeUrl);
window.open(onlyofficeUrl, '_blank');
} else {
console.error('No valid URLs found');
alert('Ошибка: Не удалось получить URL для редактирования');
}
} else {
console.error('Invalid response structure:', json);
alert('Ошибка: ' + (json.error || 'Не удалось получить URL для редактирования. Проверьте консоль для деталей.'));
}
})
.catch(error => {
console.error('Error:', error);
alert('Ошибка: ' + error.message);
});
}
// Делаем функцию глобальной для доступа из шаблонов
window.editInNextcloud = editInNextcloud;