Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
gwagner57 committed Sep 6, 2023
1 parent a846a71 commit f5bed3c
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 202 deletions.
2 changes: 1 addition & 1 deletion apps/minimal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8"/>
<title>OEMjs Simple Web App Example</title>
<title>OEMjs Minimal App Example</title>
<meta name="description" content="A minimal app made with OEMjs."/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>

Expand Down
360 changes: 184 additions & 176 deletions apps/public-library/img/CityLibrary_IDM2_simplified.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion apps/public-library/js/Book.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {dt} from "../../../src/datatypes.mjs";
* @class
*/
class Book extends bUSINESSoBJECT {
constructor ({isbn, title, year, publisher, authors, reserved=false}) {
constructor ({isbn, title, year, publisher, authors, reserved=false, bookCopies}) {
super( isbn);
this.title = title;
this.year = year;
this.authors = authors;
if (publisher) this.publisher = publisher;
this.reserved = reserved;
if (bookCopies) this.publisher = bookCopies;
}
}
Book.properties = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import bUSINESSaCTIVITY from "../../../src/bUSINESSaCTIVITY.mjs";
import {BookCopyStatusEL} from "./BookCopy.mjs";
import {BookCopy, BookCopyStatusEL} from "./BookCopy.mjs";
import app from "./app.mjs";

/**
* Business activity type BookLending
* @class
*/
class BookReturn extends bUSINESSaCTIVITY {
class BookTakeBack extends bUSINESSaCTIVITY {
constructor ({returner, bookCopies}) {
super();
this.returner = returner;
Expand All @@ -14,18 +15,19 @@ class BookReturn extends bUSINESSaCTIVITY {
onActivityEnd() {
for (const bc of this.bookCopies) {
bc.status = BookCopyStatusEL.AVAILABLE;
app.storageManager.update( BookCopy, bc.id, {status: bc.status});
}
}
}
BookReturn.properties = {
BookTakeBack.properties = {
"returner": {range:"Person", label:"Returner"},
"bookCopies": {range:"BookCopy", label:"Returned book copies", minCard: 1, maxCard: Infinity,
selectionRangeFilter: bc => bc.status === BookCopyStatusEL.LENDED}
}
// menu item text and UI title
BookReturn.activityPhrase = "Take back books";
BookTakeBack.activityPhrase = "Take back books";

// collect classes in a map
bUSINESSaCTIVITY.classes["BookReturn"] = BookReturn;
bUSINESSaCTIVITY.classes["BookTakeBack"] = BookTakeBack;

export default BookReturn;
export default BookTakeBack;
2 changes: 1 addition & 1 deletion apps/public-library/js/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Book from "./Book.mjs";
import {BookCopy, BookCopyStatusEL} from "./BookCopy.mjs";
import BookReturnReminder from "./BookReturnReminder.mjs";
import BookLending from "./BookLending.mjs";
import BookReturn from "./BookReturn.mjs";
import BookTakeBack from "./BookTakeBack.mjs";

// import framework code files
import sTORAGEmANAGER from "../../../src/storage/sTORAGEmANAGER.mjs";
Expand Down
4 changes: 4 additions & 0 deletions src/ui/SelectMultipleItemsWidget.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ class SelectMultipleItemsWidget extends HTMLElement {
this.fillSelectedItemsList();
this.fillSelectionListWithOptions();
}
reset() {
this.selection = [];
this.refresh();
}
static createDeleteButton() {
const el = document.createElement("button");
el.type = "button";
Expand Down
47 changes: 30 additions & 17 deletions src/ui/vIEW.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ class vIEW {
}));
break;
case "C": //================ CREATE ============================
this.resetViewFields();
// create form fields for all view fields
createUiElemsForViewFields();
// create save and back buttons
Expand Down Expand Up @@ -586,8 +585,8 @@ class vIEW {
}
if (formEl.checkValidity()) {
view.userActions["createRecord"]( slots);
// clear view fields, otherwise they are sent again even if the form is empty!
view.resetViewFields();
formEl.reset();
view.reset();
}
});
break;
Expand All @@ -604,14 +603,7 @@ class vIEW {
selectEl = formEl[slots.name];
// when an entity is selected, populate the form with its data
selectEl.addEventListener("change", async function () {
const formFields = formEl.elements;
var id = selectEl.value;
// reset form fields
formEl.reset();
// reset custom validity
for (let i=0; i < formFields.length; i++) {
formFields[i].setCustomValidity("");
}
if (id) { // parse id if integer value
if (dt.isIntegerType( stdIdRange)) id = parseInt( id);
const obj = await vIEW.app.storageManager.retrieve( mc, id);
Expand Down Expand Up @@ -662,7 +654,8 @@ class vIEW {
if (dt.isIntegerType( stdIdRange)) id = parseInt( id);
// map UI event to a user action defined by the view
view.userActions["updateRecord"]( id, slots);
view.resetViewFields();
formEl.reset();
view.reset();
}
});
break;
Expand Down Expand Up @@ -707,10 +700,11 @@ class vIEW {
if (selectEl && id) {
selectEl.remove( selectEl.selectedIndex);
}
formEl.reset();
view.reset();
});
break;
default: // activity UI
this.resetViewFields();
// create form fields for all view fields
createUiElemsForViewFields();
// create delete and back buttons
Expand Down Expand Up @@ -766,8 +760,8 @@ class vIEW {
if (formEl.checkValidity()) {
// map UI event to a user action defined by the view
await view.userActions["performActivity"]( slots);
// clear view fields, otherwise they are sent again even if the form is empty!
view.resetViewFields();
formEl.reset();
view.reset();
}
});
}
Expand All @@ -783,9 +777,7 @@ class vIEW {
*/
}
/**
* Generic setter for view fields, takes also care of bottom-up data-binding
* (from view field to corresponding UI widget)
* this = view object
* Reset view fields
* @method
* @author Gerd Wagner
* TODO: support derived and dependent view fields
Expand All @@ -802,6 +794,27 @@ class vIEW {
}
}
}
/**
* Reset view
* @method
* @author Gerd Wagner
* TODO: support derived and dependent view fields
*/
reset() {
for (const f of Object.keys( this.fields)) {
const fldDef = this.fields[f],
uiEl = this.dataBinding[f];
if ("setCustomValidity" in uiEl) uiEl.setCustomValidity("");
else uiEl.reset();
if (fldDef.maxCard > 1) {
this.fldValues[f] = [];
} else if (fldDef.range in dt.classes) {
this.fldValues[f] = undefined; // view field holds ID strings
} else {
this.fldValues[f] = dt.getDefaultValue( fldDef.range);
}
}
}
/**
* Generic setter for view fields, takes also care of bottom-up data-binding
* (from view field to corresponding UI widget)
Expand Down

0 comments on commit f5bed3c

Please sign in to comment.