Skip to content

Commit

Permalink
Work on adapt-it#539
Browse files Browse the repository at this point in the history
Logic for multiple projects (ask the user if they want to switch projects at the end of the import)
  • Loading branch information
eb1 committed Dec 28, 2023
1 parent f41ef19 commit e3e1de7
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 3 deletions.
16 changes: 13 additions & 3 deletions www/js/views/DocumentViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -3925,7 +3925,11 @@ define(function (require) {
result = readLIFTDoc(contents);
} else if (contents.indexOf("\\lx") >= 0) {
// _probably_ \lx data for the KB
result = readSFMLexDoc(contents);
result = readSFMLexDoc(contents);
} else if (contents.indexOf("PunctuationTwoCharacterPairsSourceSet") >= 0) {
// project settings file reader is held in ProjectViews - call it
result = ProjectViews.importSettingsFile({model: proj});
return result; // in this case, we've already notified the user in ProjectViews::importFail();
} else {
// unknown -- try reading it as a text document
result = readTextDoc(contents);
Expand Down Expand Up @@ -6245,8 +6249,14 @@ define(function (require) {
$("#btnCancel").show();
$("#status").html(i18n.t("view.dscStatusReading", {document: fileName}));
$("#btnOK").hide();
// import the specified file
importFile(file, this.model);
// is this an .aic file?
if (fileName.toLowerCase().indexOf(".aic") > 0) {
// .aic project settings file reader is held in ProjectViews - call it
ProjectViews.importSettingsFile(file, this.model);
} else {
// import the specified file
importFile(file, this.model);
}
},
// Handler for when the user clicks the Select button (browser only) -
// (this is the html <input type=file> element displayed for the browser only) --
Expand Down
44 changes: 44 additions & 0 deletions www/js/views/ProjectViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,50 @@ define(function (require) {
$("#rowBookName").hide();
// tell the user the file was imported successfully
$("#lblDirections").html(i18n.t("view.dscStatusImportSuccess", {document: project.get("name")}));
// is there more than one project in our project list?
if (window.ProjectList) {
// YES -- ask if they want to switch
if (navigator.notification) {
// on mobile device -- use notification plugin API
navigator.notification.confirm(
i18n.t('view.msgUseProject'),
function (btnIndex) {
if (btnIndex === 1) {
// window.Application.currentProject = window.Application.ProjectList.at(index);
// localStorage.setItem("CurrentProjectID", window.Application.currentProject.get("projectid"));
// // Clear out any local chapter/book/sourcephrase/KB stuff so it loads
// // from our new project instead
// window.Application.BookList.length = 0;
// window.Application.ChapterList.length = 0;
// window.Application.spList.length = 0;
// window.Application.kbList.length = 0;
// // head back to the home page
// window.location.replace("");
} else {
// No -- just exit
}
},
i18n.t('view.ttlMain'),
[i18n.t('view.lblYes'), i18n.t('view.lblNo')]
);
} else {
// in browser -- use window.confirm / window.alert
if (window.confirm(i18n.t('view.msgUseProject'))) {
// window.Application.currentProject = window.Application.ProjectList.at(index);
// localStorage.setItem("CurrentProjectID", window.Application.currentProject.get("projectid"));
// // Clear out any local chapter/book/sourcephrase/KB stuff so it loads
// // from our new project instead
// window.Application.BookList.length = 0;
// window.Application.ChapterList.length = 0;
// window.Application.spList.length = 0;
// window.Application.kbList.length = 0;
// // head back to the home page
// window.location.replace("");
} else {
// No -- just exit
}
}
}
};
// Callback for when the file failed to import
var importFail = function (e) {
Expand Down
1 change: 1 addition & 0 deletions www/locales/dev/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
"ErrImportDoc": "Adapt It Mobile encountered a problem trying to open / import document: \"__error__\"",
"ErrImportNoProjectDefined": "Adapt It Mobile needs information about your translation project before you can import documents. Please create or copy a document, and then import documents into Adapt It Mobile.",
"ErrNoClipboard": "No text found on the clipboard. Please copy some text to the clipboard and try importing again.",
"msgUseProject": "Do you want to switch to this project?",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
1 change: 1 addition & 0 deletions www/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
"ErrImportDoc": "Adapt It Mobile encountered a problem trying to open / import document: \"__error__\"",
"ErrImportNoProjectDefined": "Adapt It Mobile needs information about your translation project before you can import documents. Please create or copy a document, and then import documents into Adapt It Mobile.",
"ErrNoClipboard": "No text found on the clipboard. Please copy some text to the clipboard and try importing again.",
"msgUseProject": "Do you want to switch to this project?",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
1 change: 1 addition & 0 deletions www/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
"ErrImportDoc": "Adapt It Mobile encontró un problema al intentar abrir/importar un documento: \"__error__\"",
"ErrImportNoProjectDefined": "Adapt It Mobile necesita información sobre su proyecto de traducción antes de poder importar documentos. Cree o copie un documento y luego podrá importar documentos a Adapt It Mobile.",
"ErrNoClipboard": "No se encontró texto en el portapapeles. Copie algo de texto en el portapapeles e intente importarlo nuevamente.",
"msgUseProject": "¿Quieres cambiar a este proyecto?",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
1 change: 1 addition & 0 deletions www/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
"ErrImportDoc": "Adapt It Mobile a rencontré un problème en essayant d'ouvrir/importer un document: \"__error__\"",
"ErrImportNoProjectDefined": "Adapt It Mobile a besoin d'informations sur votre projet de traduction avant de pouvoir importer des documents. Veuillez créer ou copier un document, puis vous pourrez importer des documents dans Adapt It Mobile.",
"ErrNoClipboard": "Aucun texte trouvé dans le presse-papiers. Veuillez copier du texte dans le presse-papiers et réessayer d'importer.",
"msgUseProject": "Voulez-vous changer pour ce projet?",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
1 change: 1 addition & 0 deletions www/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
"ErrImportDoc": "Adapt It Mobile encontrou um problema ao tentar abrir/importar documento: \"__error__\"",
"ErrImportNoProjectDefined": "O Adapt It Mobile precisa de informações sobre o seu projeto de tradução antes de importar documentos. Crie ou copie um documento e então você poderá importar documentos para o Adapt It Mobile.",
"ErrNoClipboard": "Nenhum texto encontrado na área de transferência. Copie algum texto para a área de transferência e tente importar novamente.",
"msgUseProject": "Você quer mudar para este projeto?",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
1 change: 1 addition & 0 deletions www/locales/tpi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
"ErrImportDoc": "Adapt It Mobile encountered a problem trying to open / import \"__document__\": \"__error__\"",
"ErrImportNoProjectDefined": "Adapt It Mobile needs information about your translation project before you can import documents. Please create or copy a document, and then import documents into Adapt It Mobile.",
"ErrNoClipboard": "Nogat klipbot teks.",
"msgUseProject": "Do you want to switch to this project?",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down

0 comments on commit e3e1de7

Please sign in to comment.