Skip to content

Commit

Permalink
Work on adapt-it#539
Browse files Browse the repository at this point in the history
Pretty close -- just need to get switching project from project mgt / copy new project working properly
  • Loading branch information
eb1 committed Jan 4, 2024
1 parent 4e864e5 commit 5aca5be
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 64 deletions.
43 changes: 31 additions & 12 deletions www/js/views/DocumentViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ define(function (require) {
isClipboard = false,
isKB = false,
isGlossKB = false,
isProjectFile = false,
fileList = [],
fileCount = 0,
batchesSent = 0,
Expand Down Expand Up @@ -258,10 +259,22 @@ define(function (require) {
// Did we just import the KB?
if (isKB === true) {
// KB file -- only display success status
$("#verifyNameControls").show();
$("#lblVerify").hide();
$("#rowBookName").hide();
$("#lblDirections").html(i18n.t("view.dscStatusKBImportSuccess"));
} else if (isGlossKB === true) {
// Gloss KB file -- only display success status
$("#verifyNameControls").show();
$("#lblVerify").hide();
$("#rowBookName").hide();
$("#lblDirections").html(i18n.t("view.dscStatusGlossKBImportSuccess"));
} else if (isProjectFile === true) {
// project file -- only display success status
$("#verifyNameControls").show();
$("#lblVerify").hide();
$("#rowBookName").hide();
$("#lblDirections").html(i18n.t("view.dscStatusImportSuccess", {document: fileName}));
} else {
// not a KB file:
// for regular document files, we did our best to guess a book name --
Expand Down Expand Up @@ -3862,11 +3875,13 @@ define(function (require) {
}
} else if (fileName.toLowerCase().indexOf(".aic") > 0) {
// create a new project object and populate it from the file contents
isProjectFile = true;
var newProj = new projModel.Project();
newProj.fromString(contents).done(function() {
// success -- save the object and add to the collection
newProj.save();
window.Application.ProjectList.add(newProj);
fileName = newProj.get('name');
importSuccess();
}).fail(function (err) {
importFail(err);
Expand Down Expand Up @@ -3917,6 +3932,20 @@ define(function (require) {
}
}
result = readUSXDoc(contents);
} else if (contents.indexOf("PunctuationTwoCharacterPairsSourceSet") >= 0) {
// _probably adapt it configuration (aic) file contents
// create a new project object and populate it from the clipboard contents
isProjectFile = true;
var newProj = new projModel.Project();
newProj.fromString(contents).done(function() {
// success -- save the object and add to the collection
newProj.save();
window.Application.ProjectList.add(newProj);
fileName = newProj.get('name');
importSuccess();
}).fail(function (err) {
importFail(err);
});
} else if (contents.indexOf("\\id") >= 0) {
// _probably_ USFM under the hood
index = contents.indexOf("\\h ");
Expand All @@ -3934,17 +3963,6 @@ define(function (require) {
} else if (contents.indexOf("\\lx") >= 0) {
// _probably_ \lx data for the KB
result = readSFMLexDoc(contents);
} else if (contents.indexOf("PunctuationTwoCharacterPairsSourceSet") >= 0) {
// create a new project object and populate it from the clipboard contents
var newProj = new projModel.Project();
newProj.fromString(contents).done(function() {
// success -- save the object and add to the collection
newProj.save();
window.Application.ProjectList.add(newProj);
importSuccess();
}).fail(function (err) {
importFail(err);
});
} else {
// unknown -- try reading it as a text document
result = readTextDoc(contents);
Expand Down Expand Up @@ -6553,9 +6571,10 @@ define(function (require) {
window.Application.kbList.clearLocal(); // clear out the kbList so it gets rebuilt
kblist = window.Application.kbList;
kblist.fetch({reset: true, data: {projectid: window.Application.currentProject.get("projectid")}});
// reset the isKB flag
// reset the file type flags
isKB = false;
isGlossKB = false;
isProjectFile = false;
// show either the browser or mobile selection buttons
if (this.isLoadingFromURL === false) {
if (device && (device.platform !== "browser")) {
Expand Down
94 changes: 42 additions & 52 deletions www/js/views/ProjectViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,46 +120,6 @@ 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 = project;
localStorage.setItem("CurrentProjectID", project.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;
} 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 = project;
localStorage.setItem("CurrentProjectID", project.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;
} else {
// No -- just exit
}
}
}
};
// Callback for when the file failed to import
var importFail = function (e) {
Expand Down Expand Up @@ -244,20 +204,50 @@ define(function (require) {
onOK: function () {
// save the model
this.model.save();
// is there already a current project?
if (window.Application.currentProject !== null) {
// There's already a project defined, so there might be some local
// chapter/book/sourcephrase/KB stuff -- clear it out so it reloads info 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;
// 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 = this.model;
localStorage.setItem("CurrentProjectID", this.model.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;
} else {
// No -- just exit
}
// head back to the home page
window.location.replace("");
},
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 = project;
localStorage.setItem("CurrentProjectID", project.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;
} else {
// No -- just exit
}
// head back to the home page
window.location.replace("");
}
}
// Set the current project to our new one
window.Application.currentProject = this.model;
localStorage.setItem("CurrentProjectID", window.Application.currentProject.get("projectid"));
// head back to the home page
window.location.replace("");
},
// User clicked on the (mobile) Select file button --
// call getFile() on the chooser plugin, and if we get a file back, import it
Expand Down

0 comments on commit 5aca5be

Please sign in to comment.