Skip to content

Commit

Permalink
Work on adapt-it#539
Browse files Browse the repository at this point in the history
Sanity import checks for .aic files:
(1) test for existence of source/target language names (is it a valid .aic file?), return false if not found so file import can fall back on text import
(2) if source/target language exist AND there is a project list, check each project to make sure we aren't importing a duplicate project (error out if we are).
  • Loading branch information
eb1 committed Dec 27, 2023
1 parent 20ffca7 commit f41ef19
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions www/js/views/ProjectViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,29 @@ define(function (require) {
lines = evt.target.result.split("\n");
// first off, a couple of sanity checks:
// 1. Is this .aic file an Adapt It project file?
var srcLangName = getSettingValue(55, "SourceLanguageName");
var tgtLangName = getSettingValue(56, "TargetLanguageName");
if ((srcLangName.length === 0) || (tgtLangName.length === 0)) {
// source or target language name not found -- we can't parse this as a project file
return false; // no message, as this might be parsed as just regular text later
}
// 2. Is this for a file we've already configured or imported (i.e., do the source and target languages
// match a project in our project list)?

// We've successfully opened an Adapt It project file (.aic) -
// populate our AIM model object with values
// from the .aic file
project.set("SourceLanguageName", getSettingValue(55, "SourceLanguageName"), {silent: true});
project.set("TargetLanguageName", getSettingValue(56, "TargetLanguageName"), {silent: true});
if (window.ProjectList) {
// we've got some projects -- see if our source and target match one of them
window.Application.ProjectList.each(function (model, index) {
if (model.get('SourceLanguageName') === srcLangName && model.get('TargetLanguageName') === tgtLangName) {
// stop import -- this file matches an existing project in our list
errMsg = i18n.t("view.dscErrDuplicateFile");
importFail(new Error(errMsg)); // tell the user -- this can't be imported, period.
return false;
}
});
}
// We've successfully opened an Adapt It project file (.aic), and it's not a duplicate -
// populate our AIM model object with values from the file
project.set("SourceLanguageName", srcLangName, {silent: true});
project.set("TargetLanguageName", tgtLangName, {silent: true});
project.set("SourceLanguageCode", getSettingValue(59, "SourceLanguageCode"), {silent: true});
project.set("TargetLanguageCode", getSettingValue(60, "TargetLanguageCode"), {silent: true});
project.set("SourceDir", (getSettingValue(115, "SourceIsRTL") === "1") ? "rtl" : "ltr", {silent: true});
Expand Down

0 comments on commit f41ef19

Please sign in to comment.