Skip to content

Commit

Permalink
Under the hood refactoring
Browse files Browse the repository at this point in the history
- Update to featherlight lib
- New / updates to model classes (not connected / json for web service proof of concept)
  • Loading branch information
eb1 committed Oct 31, 2024
1 parent cf51096 commit 152bc93
Show file tree
Hide file tree
Showing 12 changed files with 797 additions and 74 deletions.
8 changes: 7 additions & 1 deletion www/js/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ define(function (require) {
// new project wizard. These objects with no id defined are only in memory;
// once the source and target language are defined, an id is set and
// the project is saved in the device's localStorage.
// $.when(this.ProjectList.fetch()).done(function () {
$.when(this.ProjectList.fetch({reset: true, data: {name: ""}})).done(function () {
window.Application.ProjectList.each(function (model, index) {
if (model.get('projectid') === "") {
Expand All @@ -347,10 +348,15 @@ define(function (require) {
window.Application.ProjectList.remove(models);
}
if (window.Application.currentProject === null) {
console.log("Home() - No current project set");
// check to see if we saved a current project
if (localStorage.getItem("CurrentProjectID")) {
console.log("Attempting to use CurrentProjectID from local storage");
window.Application.currentProject = window.Application.ProjectList.where({projectid: localStorage.getItem("CurrentProjectID")})[0];
} else {
}
if (window.Application.currentProject === null) {
// project list was a dud. Set to the first item in the list if we can
console.log("No localStorage, or attempt to set failed. Trying the first item in the project list (if there is one)");
// pick the first project in the list, if there is one
if (window.Application.ProjectList.length > 0) {
window.Application.currentProject = window.Application.ProjectList.at(0);
Expand Down
9 changes: 5 additions & 4 deletions www/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require.config({
// backbone.babysitter 0.1.12
// backbone.wreqr 1.4.0
// circular-progress-bar 1.0.6
// featherlight 1.7.6
// featherlight.gallery 1.7.6
// featherlight 1.7.14
// featherlight.gallery 1.7.14
// hammer 2.0.8
// handlebars 4.7.8
// hopscotch 0.3.1+ ** NOTE: if upgrading, fold in the hack in hopscotch.js (search for EDB HACK) -
Expand Down Expand Up @@ -50,11 +50,12 @@ require.config({
map: {
'*': {
'app/models': 'app/models/sql' // Use sqlite model persistence
// 'app/models': 'app/models/json' // Use json model persistence
}
},
shim: {
'featherlightGallery': {
deps: ['featherlight', 'jquery'],
deps: ['jquery-hammerjs', 'featherlight', 'jquery'],
exports: 'featherlightGallery'
},
'handlebars': {
Expand All @@ -78,7 +79,7 @@ require.config({
},
'backbone': {
// deps: ['underscore', 'jquery'],
deps: ['jquery-hammerjs', 'underscore-min'],
deps: ['jquery-hammerjs', 'underscore-min', 'jquery'],
exports: 'Backbone'
},
'underscore': {
Expand Down
43 changes: 30 additions & 13 deletions www/js/models/json/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,36 @@ define(function (require) {

var Backbone = require('backbone'),

Book = Backbone.Model.extend({

urlRoot: "/book"

}),

BookCollection = Backbone.Collection.extend({

model: Book,

url: "/books"

});
Book = Backbone.Model.extend({
// default values
defaults: {
bookid: "",
projectid: "",
scrid: "",
name: "",
filename: "",
chapters: []
},

}),

BookCollection = Backbone.Collection.extend({
model: Book,
url: function() {
// TODO: global function to prepend server:port to url path
// return this.document.url() + '/books';
return "http://localhost:3042/books";
},
// sync: function (method, model, options) {
// if (method === "read") {
// // special case for sql - remove the blank name property for json
// if (options.data.hasOwnProperty('name') && options.data.name === "") {
// delete options.data.name;
// }
// }
// }

});

return {
Book: Book,
Expand Down
34 changes: 21 additions & 13 deletions www/js/models/json/chapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@ define(function (require) {

var Backbone = require('backbone'),

Chapter = Backbone.Model.extend({

urlRoot: "/chapter"

}),

ChapterCollection = Backbone.Collection.extend({

model: Chapter,

url: "/chapters"

});
Chapter = Backbone.Model.extend({
// default values
defaults: {
chapterid: "",
bookid: "",
projectid: "",
name: "",
lastadapted: 0,
versecount: 0
},

}),

ChapterCollection = Backbone.Collection.extend({
model: Chapter,
url: function() {
// TODO: global function to prepend server:port to url path
// return this.document.url() + '/chapters';
return "http://localhost:3042/chapters";
}
});

return {
Chapter: Chapter,
Expand Down
4 changes: 1 addition & 3 deletions www/js/models/json/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ define(function (require) {

Font = Backbone.Model.extend({

urlRoot: "http://localhost:3000/font"

}),

FontCollection = Backbone.Collection.extend({

model: Font,

url: "http://localhost:3000/fonts"
url: "/fonts"

});

Expand Down
Loading

0 comments on commit 152bc93

Please sign in to comment.