Skip to content

Commit

Permalink
Work on adapt-it#507
Browse files Browse the repository at this point in the history
Code checkpoint. Updated language strings, and moved the New TU functionality to a wizard page. Work still in progress.
  • Loading branch information
eb1 committed Oct 24, 2023
1 parent a58ada8 commit 1df075a
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 139 deletions.
66 changes: 35 additions & 31 deletions www/js/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ define(function (require) {
importDocView = null,
exportDocView = null,
showTransView = null,
newTransView = null,
editTUView = null,
i18n = require('i18n'),
lang = "",
Expand Down Expand Up @@ -442,42 +443,45 @@ define(function (require) {
});
},

showTU: function (id) {
newTU: function() {
console.log("newTU");
// update the KB list, then show the view
$.when(window.Application.kbList.fetch({reset: true, data: {projectid: window.Application.currentProject.get("projectid")}})).done(function () {
// create a new / temporary TU to pass in to the TUView
// (this object isn't saved or added to the collection yet)
var newID = window.Application.generateUUID(),
curDate = new Date(),
timestamp = (curDate.getFullYear() + "-" + (curDate.getMonth() + 1) + "-" + curDate.getDay() + "T" + curDate.getUTCHours() + ":" + curDate.getUTCMinutes() + ":" + curDate.getUTCSeconds() + "z"),
theTU = new kbModels.TargetUnit({
tuid: newID,
projectid: window.Application.currentProject.get("projectid"),
source: "",
refstring: [],
timestamp: timestamp,
user: "",
isGloss: 0
});
newTransView = new SearchViews.NewTUView({model: theTU});
newTransView.delegateEvents();
window.Application.main.show(newTransView);
});
},

editTU: function (id) {
console.log("editTU");
// update the KB list, then show the view
$.when(window.Application.kbList.fetch({reset: true, data: {projectid: id}})).done(function () {
var theTU = null,
bNewTU = false;
// are we creating a new TU?
if (id === "000") {
// create a new / temporary TU to pass in to the TUView
// (this object isn't saved or added to the collection yet)
var newID = window.Application.generateUUID(),
curDate = new Date(),
timestamp = (curDate.getFullYear() + "-" + (curDate.getMonth() + 1) + "-" + curDate.getDay() + "T" + curDate.getUTCHours() + ":" + curDate.getUTCMinutes() + ":" + curDate.getUTCSeconds() + "z"),
theTU = new kbModels.TargetUnit({
tuid: newID,
projectid: id,
source: "",
refstring: [],
timestamp: timestamp,
user: "",
isGloss: 0
});
bNewTU = true;
} else {
// show the selected TU
var tu = window.Application.kbList.where({tuid: id});
if (tu === null) {
console.log("KB Entry not found:" + id);
return; // don't do anything -- this TU is supposed to exist
}
theTU = tu[0];
bNewTU = false;
$.when(window.Application.kbList.fetch({reset: true, data: {projectid: window.Application.currentProject.get("projectid")}})).done(function () {
var theTU = null;
// show the selected TU
var tu = window.Application.kbList.where({tuid: id});
if (tu === null) {
console.log("KB Entry not found:" + id);
return; // don't do anything -- this TU is supposed to exist
}
theTU = tu[0];
showTransView = new SearchViews.TUView({model: theTU});
showTransView.spObj = null; // NO current sourcephrase (this is coming from the KB editor)
showTransView.bNewTU = bNewTU; // set the bNewTU flag as appropriate
showTransView.bNewTU = false;
showTransView.delegateEvents();
window.Application.main.show(showTransView);
});
Expand Down
3 changes: 2 additions & 1 deletion www/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ define(function (require) {
"project/:id": "editProject", // #project/projectID
"search/:id": "lookupChapter", // #search/projectID
"kb/:id": "editKB", // #kb/projectID (KB editor)
"tu/:tuid": "showTU", // #tu/target unit ID (TU editor - ID will be "000" for a new TU)
"tu": "newTU", // #tu (create a new TU)
"tu/:tuid": "editTU", // #tu/target unit ID (TU editor)
"sp/:spid": "showTranslations", // #sp/source phrase ID (show translations for SP)
"import/:id": "importBooks", // #import/projectID (import books into projectID)
"export/:id": "exportBooks", // #export/projectID (export books from projectID)
Expand Down
192 changes: 107 additions & 85 deletions www/js/views/SearchViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ define(function (require) {
tuModels = require('app/models/targetunit'),
tplChapterList = require('text!tpl/ChapterList.html'),
tplLookup = require('text!tpl/Lookup.html'),
tplNewTU = require('text!tpl/NewTU.html'),
tplTargetUnit = require('text!tpl/TargetUnit.html'),
tplTUList = require('text!tpl/TargetUnitList.html'),
tplRSList = require('text!tpl/RefStringList.html'),
Expand Down Expand Up @@ -201,7 +202,7 @@ define(function (require) {
// User clicked on the New TU button. Show the TUView for a _new_ item, with an empty/null TU
onClickNewTU: function () {
console.log("onClickNewTU - entry");
window.Application.router.navigate("tu/000", {trigger: true});
window.Application.router.navigate("tu", {trigger: true});
},
onShow: function () {
var lstTU = "";
Expand Down Expand Up @@ -239,6 +240,109 @@ define(function (require) {
}
}),

NewTUView = Marionette.ItemView.extend({
nStep: 0, // step 0 (source) and 1 (target) in this wizard
bDirty: false,
template: Handlebars.compile(tplNewTU),
initialize: function () {
// spList is used for the "find in documents"
this.spList = new spModels.SourcePhraseCollection();
this.spList.clearLocal();
this.render();
},
events: {
"click #Done": "onDone",
"click #Cancel": "onCancel",
"click #Next": "onNext",
"input #txtField": "onInputEditField"
},
// user clicked the Done button. Save the TU and return to the TU List page.
onDone: function () {
var value = $("#txtField").val(),
trimmedValue = value.trim(),
refstrings = [],
curDate = new Date(),
timestamp = (curDate.getFullYear() + "-" + (curDate.getMonth() + 1) + "-" + curDate.getDay() + "T" + curDate.getUTCHours() + ":" + curDate.getUTCMinutes() + ":" + curDate.getUTCSeconds() + "z"),
newRS = {
'target': Underscore.unescape(trimmedValue), //klb
'n': '1', // there's no real instance, but we need a valid # for it to show up in the list
'cDT': timestamp,
'df': '0',
'wC': ""
};
refstrings.push(newRS);
this.model.set('refstring', refstrings, {silent: true});
this.model.save();
window.Application.kbList.add(this.model);
window.history.go(-1);
},
// User clicked the Cancel button (new TU). Delete the TU and return to the TU List page.
onCancel: function () {
this.model = null;
window.history.go(-1);
},
// User clicked the Next button. Move to the "enter Target text" step.
onNext: function () {
// pull out the source value from the text field
var value = $("#txtField").val(),
trimmedValue = value.trim();
this.model.set('source', trimmedValue, {silent: true});
this.model.update();
// set the step
this.nStep = 1;
// update the UI
$("#lblPrompt").html(i18next.t("view.dscNewRS", {source: trimmedValue}));
$("#txtField").val(""); // clear out the edit field
$("#Next").addClass('hide');
$("#Done").removeClass('hide');
$("#Done").prop('disabled', true); // enabled once the user types in some target text
},
// User typed something in the source text (new TU)
onInputEditField: function (event) {
// pull out the text
var value = $("#txtField").val(),
trimmedValue = value.trim();
if (trimmedValue.length > 0) {
// there's some text in the txtField edit box -- enable the UI as appropriate
if (this.nStep === 0) {
$("#Next").prop('disabled', false);
} else {
$("#Done").prop('disabled', false);
}
} else {
// no "real" text - disable the UI as appropriate
if (this.nStep === 0) {
$("#Next").prop('disabled', true);
} else {
$("#Done").prop('disabled', true);
}
}
if ((event.keyCode === 9) || (event.keyCode === 13)) {
// tab or enter key -- blur focus
$("#txtField").blur();
}
},
onShow: function () {
// load the source / target punctuation pairs
window.Application.currentProject.get('PunctPairs').forEach(function (elt, idx, array) {
punctsSource.push(elt.s);
punctsTarget.push(elt.t);
});
// load the source / target case pairs
window.Application.currentProject.get('CasePairs').forEach(function (elt, idx, array) {
caseSource.push(elt.s);
caseTarget.push(elt.t);
});
// First step: enter a source word or phrase
this.step = 0; // first step
var srcLang = window.Application.currentProject.get('SourceLanguageName');
$("#lblPrompt").html(i18next.t("view.dscNewSP", {lang: srcLang}));
// disable the Next button until the user adds a source
$("#Next").prop('disabled', true);
$("#Done").addClass('hide');
}
}),

TUView = Marionette.LayoutView.extend({
spObj: null,
bNewTU: false,
Expand Down Expand Up @@ -372,11 +476,6 @@ define(function (require) {
}
},
events: {
"click #OK": "onOK",
"click #Cancel": "onCancel",
"focus #srcPhrase": "onFocusSource",
"keydown #srcPhrase": "onEditSource",
"blur #srcPhrase": "onBlurSource",
"click #btnNewRS": "onNewRS",
"click .topcoat-list__item": "onClickRefString",
"keydown .refstring-list__item": "onEditRefString",
Expand All @@ -388,63 +487,6 @@ define(function (require) {
"click .btnSearch": "onClickSearch",
"click .btnSearchItem": "onClickSearchItem"
},
// User clicked the OK button (new TU). Save the TU and add it to our TUList
onOK: function () {
this.model.save();
window.Application.kbList.add(this.model);
window.history.go(-1);
// window.Application.editKB(window.Application.currentProject.get("projectid"));
},
// User clicked the Cancel button (new TU). Delete the TU and return to the TU List page.
onCancel: function () {
this.model = null;
window.history.go(-1);
},
// Focus set to the source edit field
onFocusSource: function () {
// reset the dirty bit -- that's all
this.bDirty = false;
},
// User typed something in the source text (new TU)
onEditSource: function (event) {
// pull out the text
var value = $("#srcPhrase").text(),
trimmedValue = value.trim();
if (trimmedValue.length > 0) {
// there's something here -- enable the "add translation" button if needed
if ($("#btnNewRS").hasClass("filter-gray")) {
$("#btnNewRS").removeClass("filter-gray");
$("#btnNewRS").addClass("filter-burnt-orange");
}
} else {
// no "real" text - disable the "add translation" button if needed
if ($("#btnNewRS").hasClass("filter-burnt-orange")) {
$("#btnNewRS").removeClass("filter-burnt-orange");
$("#btnNewRS").addClass("filter-gray");
}
}
if ((event.keyCode === 9) || (event.keyCode === 13)) {
// tab or enter key -- blur focus
$("#srcPhrase").blur();
} else {
// any other key -- set the dirty bit
this.bDirty = true;
}
},
// Focus moved from the srcPhrase edit field (probably new TU). If the trimmed text is non-empty, set the
// source for the current TU
onBlurSource: function () {
if (this.bDirty === true) {
// text changed in the source edit field -- if it's non-empty, update the source for the current TU
var value = $("#srcPhrase").text(),
trimmedValue = value.trim();
if (trimmedValue.length > 0) {
this.model.set('source', trimmedValue, {silent: true});
}
}
// reset the dirty bit
this.bDirty = false;
},
// user clicked on the "new translation" button - prompt the user for a new translation string,
// and then update the refstrings list if the user clicks OK
onNewRS: function (event) {
Expand Down Expand Up @@ -822,28 +864,7 @@ define(function (require) {
var tgtLang = window.Application.currentProject.get('TargetLanguageName');
$("#lblSourceLang").html(srcLang);
$("#lbltargetLang").html(tgtLang);
// is this a new TU?
if (this.bNewTU === true) {
var range = null,
selection = null;
// creating a new TU
$("#tbBottom").removeClass("hide"); // show the OK/Cancel button
// disable the OK button until the user adds a source AND target
$("#OK").prop('disabled', true);
// disable the "Add Translation" button until they type in a source
$("#btnNewRS").removeClass("filter-burnt-orange");
$("#btnNewRS").addClass("filter-gray");
// hide the current translation / target UI
$("#lblCurrentTrans").hide();
$(".tgtbox").hide();
// first item of business is adding the source phrase -- nudge the user there
$("#srcPhrase").prop('contenteditable', true);
$("#srcBox").attr("style", "background: #eee;"); //
$("#srcPhrase").attr("style", "display:block;")
$("#srcPhrase").focus();
$("#srcPhrase").mouseup();
return; // no further processing
}

// do a fuzzy search on the TargetUnit's source (i.e., no punctuation)
this.spList.fetch({reset: true, data: {source: this.model.get("source")}});
// source we're looking at
Expand Down Expand Up @@ -1049,6 +1070,7 @@ define(function (require) {
return {
TUListView: TUListView,
TUView: TUView,
NewTUView: NewTUView,
LookupView: LookupView,
ChapterResultsView: ChapterResultsView
};
Expand Down
4 changes: 2 additions & 2 deletions www/locales/dev/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@
"ttlTotalEntries": "Total Entries: __total__",
"lblNewTU": "Add Entry...",
"lblNewRS": "Add Translation...",
"dscNewSP": "Enter a new source phrase in language \"__lang__\": ",
"dscNewRS": "Enter a new translation for \"__source__\": ",
"dscNewSP": "Enter a word or phrase in language \"__lang__\".",
"dscNewRS": "Enter a translation for \"__source__\".",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
4 changes: 2 additions & 2 deletions www/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@
"ttlTotalEntries": "Total Entries: __total__",
"lblNewTU": "Add Entry...",
"lblNewRS": "Add Translation...",
"dscNewSP": "Enter a new source phrase in language \"__lang__\".",
"dscNewRS": "Enter a translation for \"__source__\" in language __lang__.",
"dscNewSP": "Enter a word or phrase in language \"__lang__\".",
"dscNewRS": "Enter a translation for \"__source__\".",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
4 changes: 2 additions & 2 deletions www/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@
"ttlTotalEntries": "Recuento de elementos: __total__",
"lblNewTU": "Nuevo elemento...",
"lblNewRS": "Nueva Traducción...",
"dscNewSP": "Escriba una palabra o frase en el idioma \"__lang__\": ",
"dscNewRS": "Escriba una nueva traducción para \"__source__\": ",
"dscNewSP": "Escriba una palabra o frase en el idioma \"__lang__\".",
"dscNewRS": "Escriba una traducción para \"__source__\".",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
4 changes: 2 additions & 2 deletions www/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@
"ttlTotalEntries": "Nombre d'entrées: __total__",
"lblNewTU": "Nouvelle entrée...",
"lblNewRS": "Nouvelle traduction...",
"dscNewSP": "Entrez un mot ou une phrase dans la langue \"__lang__\": ",
"dscNewRS": "Entrez une nouvelle traduction pour \"__source__\": ",
"dscNewSP": "Entrez un mot ou une phrase dans la langue \"__lang__\".",
"dscNewRS": "Entrez une traduction pour \"__source__\".",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
Loading

0 comments on commit 1df075a

Please sign in to comment.