Skip to content

Commit

Permalink
Merge pull request #594 from eb1/master
Browse files Browse the repository at this point in the history
Fix #591, 593
  • Loading branch information
eb1 authored Aug 26, 2024
2 parents c304427 + 36b1759 commit ff09512
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 3,078 deletions.
7 changes: 0 additions & 7 deletions www/js/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ define(function (require) {
spModel = require('app/models/sourcephrase'),
kbModels = require('app/models/targetunit'),
AppRouter = require('app/router'),
FastClick = require('fastclick'),
PageSlider = require('app/utils/pageslider'),
slider = new PageSlider($('body')),
lookupView = null,
Expand Down Expand Up @@ -307,12 +306,6 @@ define(function (require) {
// initialize the router
this.router = new AppRouter({controller: this});


// Attach touch screen function to avoid delay in double-click
$(function () {
FastClick.attach(document.body);
});

// Process back arrow button event
// (not the one in the browser, the one we render on our html page).
$("body").on("click", ".back-button", function (event) {
Expand Down
7 changes: 3 additions & 4 deletions www/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
require.config({

// 3rd party lib versions:
// backbone 1.5.0
// backbone 1.6.0
// backbone.babysitter 0.1.12
// backbone.wreqr 1.4.0
// circular-progress-bar 1.0.6
// fastclick 1.0.6
// featherlight 1.7.6
// featherlight.gallery 1.7.6
// hammer 2.0.8
Expand All @@ -19,11 +18,11 @@ require.config({
// jquery 3.6.0
// langtags 1.3.1 ** refactored and minimized (see before-build.js)
// marionette 2.4.2
// require 2.3.6
// require 2.3.7
// spectrum 1.8.1
// text 2.0.15
// typeahead 0.11.1
// underscore 1.9.1
// underscore 1.13.7

baseUrl: 'lib',

Expand Down
24 changes: 18 additions & 6 deletions www/js/models/sql/sourcephrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@ define(function (require) {
tx.executeSql(sql, [attributes.spid, attributes.norder, attributes.chapterid, attributes.vid, attributes.markers, attributes.orig, attributes.prepuncts, attributes.midpuncts, attributes.follpuncts, attributes.flags, attributes.texttype, attributes.gloss, attributes.freetrans, attributes.note, attributes.srcwordbreak, attributes.tgtwordbreak, attributes.source, attributes.target], function (tx, res) {
attributes.id = res.insertId;
console.log("sourcephrase INSERT ok.");
deferred.resolve();
}, function (tx, err) {
console.log("sourcephrase INSERT error: " + err.message);
deferred.reject(err);
});
}, function (e) {
console.log("sourcephrase create: transation error:" + e.message);
deferred.reject(e);
}, function () {
deferred.resolve();
console.log("sourcephrase create: transaction OK.");
});
return deferred.promise();

},
update: function () {
var deferred = $.Deferred();
Expand All @@ -92,7 +97,8 @@ define(function (require) {
deferred.reject(e);
}, function () {
deferred.resolve();
});
});
return deferred.promise();
},
destroy: function (options) {
var attributes = this.attributes;
Expand All @@ -113,8 +119,14 @@ define(function (require) {
}
switch (method) {
case 'create':
model.create();
// options.success(model);
// model.create();
$.when(model.create())
.done(function() {
options.success(model);
})
.fail(function() {
options.error;
});
break;

case 'read':
Expand All @@ -125,12 +137,12 @@ define(function (require) {

case 'update':
model.update();
// options.success(model);
// options.success(model);
break;

case 'delete':
model.destroy(options);
// options.success(model);
// options.success(model);
break;
}
}
Expand Down
162 changes: 91 additions & 71 deletions www/js/views/AdaptViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,22 +734,34 @@ define(function (require) {
exactMatch = pile,
thisObj = pile,
tmpStr = "",
done = false,
stopAtBoundaries = false,
nextObj = pile;
// find the source
console.log("findLargestPhrase: entry");
sourceText = $(pile).children('.source').html();
// initial values
idxStart = $(pile).index();
idxEnd = idxStart;
if ((!localStorage.getItem("StopAtBoundaries")) || (localStorage.getItem("StopAtBoundaries") === "true")) {
stopAtBoundaries = true;
}
// run until we hit the end of the strip OR we don't match anything
while (tu !== null && nextObj !== null) {
while (done === false && tu !== null && nextObj !== null) {
// move to the next pile and append the source
nextObj = thisObj.nextElementSibling;
if (nextObj !== null) {
if ($(nextObj).hasClass("strip")) {
// we went beyond the current strip -- exit the while loop
break;
}
if ($(nextObj).children(".target").html().length > 0) {
// exit -- we hit some target text in our processing
break;
}
if ((stopAtBoundaries === true) && ($(nextObj).children(".source").first().hasClass("fp"))) {
done = true; // current node is a boundary AND we want to stop there; we're done after this iteration
}
tmpStr = sourceText + ONE_SPACE + $(nextObj).children(".source").html();
sourceText = this.stripPunctuation(this.autoRemoveCaps(tmpStr, true), true);
// is there a match for this phrase?
Expand Down Expand Up @@ -3714,84 +3726,92 @@ define(function (require) {
follpuncts = selectedObj.get('follpuncts');
// now build the new sourcephrase from the string
// model object itself
console.log("togglePhrase - creating spid: phr-" + newID);
console.log("togglePhrase - creating spid: phr-" + newID + " for source: " + phraseSource);
phObj = new spModels.SourcePhrase({ spid: ("phr-" + newID), markers: phraseMarkers.trim(), source: phraseSource, target: phraseSource, orig: origTarget, prepuncts: prepuncts, follpuncts: follpuncts});
strID = $(selectedStart).attr('id');
strID = strID.substr(strID.indexOf("-") + 1); // remove "pile-"
selectedObj = this.collection.findWhere({spid: strID});
phObj.set('chapterid', selectedObj.get('chapterid'), {silent: true});
phObj.set('vid', selectedObj.get('vid'), {silent: true});
phObj.set('norder', selectedObj.get('norder'), {silent: true}); // phrase just takes same order # as first selected object
phObj.save();
this.collection.add(phObj);
// also save in KB
// saveInKB(this.stripPunctuation(this.autoRemoveCaps(phraseSource), true), phraseSource, "", project.get('projectid'), 0);
// UI representation
// marker, source divs
phraseHtml = PhraseLine0 + "phr-" + newID + PhraseLine1 + phraseMarkers + PhraseLine2 + phraseSource + PhraseLine3;
// if we're merging because of our lookahead KB parse, skip adding the target -- we want to
// populate the target from the KB instead
if (isMergingFromKB === false) {
// NOT merging from the KB (i.e., an automatic merge); so the user has merged this phrase --
// is there something in the KB that matches this phrase?
tu = this.findInKB(this.stripPunctuation(this.autoRemoveCaps(phraseSource, true), true), 0);
if (tu !== null) {
// found at least one match -- populate the target with the first match
refstrings = tu.get('refstring');
// first, make sure these refstrings are actually being used
options.length = 0; // clear out any old cruft
for (i = 0; i < refstrings.length; i++) {
if (refstrings[i].n > 0) {
options.push(Underscore.unescape(refstrings[i].target));
// save the model
// (further processing needs to wait on the async save / db INSERT)
var _this = this;
phObj.save(
{ 'chapterid': selectedObj.get('chapterid'),
'vid': selectedObj.get('vid'),
'norder': selectedObj.get('norder')},
{ silent: true,
success: function() {
// add to the collection
_this.collection.add(phObj);
// UI representation
// marker, source divs
phraseHtml = PhraseLine0 + "phr-" + newID + PhraseLine1 + phraseMarkers + PhraseLine2 + phraseSource + PhraseLine3;
// if we're merging because of our lookahead KB parse, skip adding the target -- we want to
// populate the target from the KB instead
if (isMergingFromKB === false) {
// NOT merging from the KB (i.e., an automatic merge); so the user has merged this phrase --
// is there something in the KB that matches this phrase?
tu = _this.findInKB(_this.stripPunctuation(_this.autoRemoveCaps(phraseSource, true), true), 0);
if (tu !== null) {
// found at least one match -- populate the target with the first match
refstrings = tu.get('refstring');
// first, make sure these refstrings are actually being used
options.length = 0; // clear out any old cruft
for (i = 0; i < refstrings.length; i++) {
if (refstrings[i].n > 0) {
options.push(Underscore.unescape(refstrings[i].target));
}
}
if (options.length === 1) {
// exactly one entry in KB -- populate the field
phraseHtml += _this.stripPunctuation(_this.autoAddCaps(phObj, refstrings[0].target), false);
isDirty = true;
}
}
}
phraseHtml += PhraseLine4;
console.log("phrase: " + phraseHtml);
isDirty = false;
$(selectedStart).before(phraseHtml);
// finally, remove the selected piles (they were merged into this one)
done = false;
tmpNode = selectedStart;
var coll = _this.collection;
while (!done) {
tmpNextNode = tmpNode.nextElementSibling;
// delete the current item
strID = $(tmpNode).attr('id');
// skip our phrase
if (strID.indexOf("phr") === -1) {
strID = strID.substr(strID.indexOf("-") + 1); // remove "pile-"
selectedObj = coll.findWhere({spid: strID});
coll.remove(selectedObj); // remove from collection
selectedObj.destroy(); // remove from database
$(tmpNode).remove(); // remove from the UI
}
if (options.length === 1) {
// exactly one entry in KB -- populate the field
phraseHtml += this.stripPunctuation(this.autoAddCaps(phObj, refstrings[0].target), false);
isDirty = true;
// are we done yet?
if (tmpNode === selectedEnd) {
done = true;
}
}
}
phraseHtml += PhraseLine4;
console.log("phrase: " + phraseHtml);
isDirty = false;
$(selectedStart).before(phraseHtml);
// finally, remove the selected piles (they were merged into this one)
done = false;
tmpNode = selectedStart;
while (!done) {
tmpNextNode = tmpNode.nextElementSibling;
// delete the current item
strID = $(tmpNode).attr('id');
// skip our phrase
if (strID.indexOf("phr") === -1) {
strID = strID.substr(strID.indexOf("-") + 1); // remove "pile-"
selectedObj = coll.findWhere({spid: strID});
coll.remove(selectedObj); // remove from collection
selectedObj.destroy(); // remove from database
$(tmpNode).remove(); // remove from the UI
}
// are we done yet?
if (tmpNode === selectedEnd) {
done = true;
// move to the next item
tmpNode = tmpNextNode;
}
// move to the next item
tmpNode = tmpNextNode;
}
// update the toolbar UI
$("div").removeClass("ui-selecting ui-selected");
$("#phBefore").prop('disabled', true);
$("#phAfter").prop('disabled', true);
$("#Retranslation").prop('disabled', true);
$("#Phrase").prop('disabled', true);
$("#mnuPHBefore").prop('disabled', true);
$("#mnuPHAfter").prop('disabled', true);
$("#mnuRetranslation").prop('disabled', true);
$("#mnuPhrase").prop('disabled', true);
// start adapting the new Phrase
next_edit = $('#pile-phr-' + newID);
selectedStart = next_edit;
$(next_edit).find('.target').mouseup();

// update the toolbar UI
$("div").removeClass("ui-selecting ui-selected");
$("#phBefore").prop('disabled', true);
$("#phAfter").prop('disabled', true);
$("#Retranslation").prop('disabled', true);
$("#Phrase").prop('disabled', true);
$("#mnuPHBefore").prop('disabled', true);
$("#mnuPHAfter").prop('disabled', true);
$("#mnuRetranslation").prop('disabled', true);
$("#mnuPhrase").prop('disabled', true);
// start adapting the new Phrase
next_edit = $('#pile-phr-' + newID);
selectedStart = next_edit;
$(next_edit).find('.target').mouseup();
}});
// end post async save() processing on sourcephrase
} else {
// selection is a phrase -- delete it from the model and the DOM
// first, re-create the original sourcephrase piles and add them to the collection and UI
Expand Down
2 changes: 1 addition & 1 deletion www/lib/backbone-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion www/lib/backbone-min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit ff09512

Please sign in to comment.