Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions modules/document_repository/jsx/categoryForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'jsx/Form';
import i18n from 'I18nSetup';
import {withTranslation} from 'react-i18next';
import translateKnownBackendError from './translateKnownBackendError';

import hiStrings from '../locale/hi/LC_MESSAGES/document_repository.json';
import jaStrings from '../locale/ja/LC_MESSAGES/document_repository.json';
Expand Down Expand Up @@ -154,6 +155,7 @@ class DocCategoryForm extends React.Component {
* Uploads the file to the server
*/
uploadFile() {
const {t} = this.props;
// Set form data and upload the media file
let formData = this.state.formData;
let formObj = new FormData();
Expand All @@ -178,19 +180,41 @@ class DocCategoryForm extends React.Component {
this.setState({
formData: {}, // reset form data after successful file upload
});
swal.fire('Category Successfully Added!',
'', 'success');
swal.fire({
title: t(
'Category added successfully!',
{ns: 'document_repository'}
),
text: '',
type: 'success',
confirmButtonText: t('OK', {ns: 'loris'}),
});
} else {
resp.json().then((data) => {
swal.fire('Could not add category!',
data.error, 'error');
const backendError = data && data.error ? data.error : '';
const errorMessage = backendError
? translateKnownBackendError(backendError, t)
: t(
'Please report the issue or contact your administrator',
{ns: 'document_repository'}
);
swal.fire({
title: t('Could not add category!', {ns: 'document_repository'}),
text: errorMessage,
type: 'error',
confirmButtonText: t('OK', {ns: 'loris'}),
});
}).catch((error) => {
console.error(error);
swal.fire(
'Unknown Error!',
'Please report the issue or contact your administrator.',
'error'
);
swal.fire({
title: t('Error', {ns: 'document_repository'}),
text: t(
'Please report the issue or contact your administrator',
{ns: 'document_repository'}
),
type: 'error',
confirmButtonText: t('OK', {ns: 'loris'}),
});
});
}
});
Expand Down
22 changes: 18 additions & 4 deletions modules/document_repository/jsx/deleteCategoryForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from 'jsx/Form';
import {withTranslation} from 'react-i18next';
import i18n from 'I18nSetup';
import translateKnownBackendError from './translateKnownBackendError';

import hiStrings from '../locale/hi/LC_MESSAGES/document_repository.json';
import jaStrings from '../locale/ja/LC_MESSAGES/document_repository.json';
Expand Down Expand Up @@ -159,28 +160,41 @@ class DeleteDocCategoryForm extends React.Component {
} else {
msg = t('Delete error!', {ns: 'document_repository'});
}
const translatedMsg = translateKnownBackendError(msg, t);
this.setState({
errorMessage: msg,
errorMessage: translatedMsg,
});
swal.fire({
title: translatedMsg,
text: '',
type: 'error',
confirmButtonText: t('OK', {ns: 'loris'}),
});
swal.fire(msg, '', 'error');
console.error(msg);
} else {
swal.fire({
text: t('Delete Successful!', {ns: 'document_repository'}),
title: '',
type: 'success',
confirmButtonText: t('OK', {ns: 'loris'}),
}).then(function() {
window.location.assign('/document_repository');
});
}
}).catch( (error) => {
let msg = error.message ? error.message : t('Delete error!',
{ns: 'document_repository'});
const translatedMsg = translateKnownBackendError(msg, t);
this.setState({
errorMessage: msg,
errorMessage: translatedMsg,
uploadProgress: -1,
});
swal.fire(msg, '', 'error');
swal.fire({
title: translatedMsg,
text: '',
type: 'error',
confirmButtonText: t('OK', {ns: 'loris'}),
});
console.error(error);
});
}
Expand Down
11 changes: 8 additions & 3 deletions modules/document_repository/jsx/docIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class DocIndex extends React.Component {
swal.fire({
title: t('Are you sure?', {ns: 'loris'}),
text: t('You won\'t be able to revert this!',
{ns: 'loris'}),
{ns: 'document_repository'}),
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
Expand All @@ -234,8 +234,13 @@ class DocIndex extends React.Component {
}).then((resp) => resp.json())
.then(()=>{
location.reload();
swal.fire(t('Delete Successful!',
{ns: 'document_repository'}), '', 'success');
swal.fire({
title: t('Delete Successful!',
{ns: 'document_repository'}),
text: '',
type: 'success',
confirmButtonText: t('OK', {ns: 'loris'}),
});
});
}
});
Expand Down
10 changes: 9 additions & 1 deletion modules/document_repository/jsx/editForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ class DocEditForm extends React.Component {
})
.then((resp) => resp.json())
.then(()=>{
swal.fire('Updated Successful!', '', 'success');
swal.fire({
title: this.props.t(
'File updated successfully!',
{ns: 'document_repository'}
),
text: '',
type: 'success',
confirmButtonText: this.props.t('OK', {ns: 'loris'}),
});
this.fetchData();
});
}
Expand Down
26 changes: 26 additions & 0 deletions modules/document_repository/jsx/translateKnownBackendError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const KNOWN_BACKEND_ERROR_MSGIDS = Object.freeze({
'Duplicate category name under same parent folder.':
'Duplicate category name under same parent folder.',
'Can not delete non-empty category':
'Can not delete non-empty category',
});

/**
* Translate known backend error bodies while preserving raw fallback text.
*
* @param {string} message - Backend-provided error body.
* @param {function} t - i18n translate function.
* @return {string} Translated text for known messages or raw fallback.
*/
const translateKnownBackendError = (message, t) => {
if (typeof message !== 'string' || message === '') {
return message;
}
const msgid = KNOWN_BACKEND_ERROR_MSGIDS[message];
if (!msgid || typeof t !== 'function') {
return message;
}
return t(msgid, {ns: 'document_repository', defaultValue: message});
};

export default translateKnownBackendError;
12 changes: 12 additions & 0 deletions modules/document_repository/locale/document_repository.pot
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ msgstr ""
msgid "Category added successfully!"
msgstr ""

msgid "Could not add category!"
msgstr ""

msgid "Duplicate category name under same parent folder."
msgstr ""

msgid "Error"
msgstr ""

Expand Down Expand Up @@ -138,6 +144,9 @@ msgstr ""
msgid "Delete error!"
msgstr ""

msgid "Can not delete non-empty category"
msgstr ""

msgid "Delete Successful!"
msgstr ""

Expand All @@ -162,6 +171,9 @@ msgstr ""
msgid "Edit"
msgstr ""

msgid "Delete"
msgstr ""

msgid "Delete File"
msgstr ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ msgstr "Parent"
msgid "Category added successfully!"
msgstr "Catégorie ajoutée avec succès !"

msgid "Could not add category!"
msgstr "Impossible d'ajouter la catégorie !"

msgid "Duplicate category name under same parent folder."
msgstr "Nom de catégorie en double sous le même dossier parent."

msgid "Error"
msgstr "Erreur"

Expand Down Expand Up @@ -154,6 +160,9 @@ msgstr "Supprimer une catégorie"
msgid "Delete error!"
msgstr "Supprimer l'erreur !"

msgid "Can not delete non-empty category"
msgstr "Impossible de supprimer une catégorie non vide"

#, fuzzy
msgid "Delete Successful!"
msgstr "Suppression réussie !"
Expand All @@ -180,6 +189,9 @@ msgstr "Date de téléversement"
msgid "Edit"
msgstr "Modifier"

msgid "Delete"
msgstr "Supprimer"

msgid "Delete File"
msgstr "Supprimer le fichier"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ msgstr "मूल"
msgid "Category added successfully!"
msgstr "श्रेणी सफलतापूर्वक जोड़ी गई!"

msgid "Could not add category!"
msgstr "श्रेणी नहीं जोड़ी जा सकी!"

msgid "Duplicate category name under same parent folder."
msgstr "एक ही मूल फ़ोल्डर के अंतर्गत श्रेणी का नाम डुप्लिकेट है।"

msgid "Error"
msgstr "त्रुटि"

Expand Down Expand Up @@ -140,6 +146,9 @@ msgstr "एक श्रेणी हटाएँ"
msgid "Delete error!"
msgstr "हटाने में त्रुटि!"

msgid "Can not delete non-empty category"
msgstr "रिक्त न होने वाली श्रेणी को हटाया नहीं जा सकता"

msgid "Delete Successful!"
msgstr "हटाना सफल रहा!"

Expand All @@ -161,6 +170,9 @@ msgstr "अपलोड की तारीख"
msgid "Edit"
msgstr "संपादित करें"

msgid "Delete"
msgstr "हटाएँ"

msgid "Delete File"
msgstr "फ़ाइल हटाएँ"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ msgstr "親"
msgid "Category added successfully!"
msgstr "カテゴリが正常に追加されました。"

msgid "Could not add category!"
msgstr "カテゴリを追加できませんでした!"

msgid "Duplicate category name under same parent folder."
msgstr "同じ親フォルダ内に同じカテゴリ名があります。"

msgid "Error"
msgstr "エラー"

Expand Down Expand Up @@ -138,6 +144,9 @@ msgstr "カテゴリを削除する"
msgid "Delete error!"
msgstr "削除エラー!"

msgid "Can not delete non-empty category"
msgstr "空でないカテゴリは削除できません"

msgid "Delete Successful!"
msgstr "削除に成功しました!"

Expand All @@ -162,6 +171,9 @@ msgstr "アップロード日"
msgid "Edit"
msgstr "編集"

msgid "Delete"
msgstr "削除"

msgid "Delete File"
msgstr "ファイルを削除"

Expand Down
Loading