summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Luka Šijanec <sijanecantonluka@gmail.com>2020-03-01 19:17:08 +0100
committerAnton Luka Šijanec <sijanecantonluka@gmail.com>2020-03-01 19:17:08 +0100
commitf4c07c8baee5d9bb0c89610425d92c66314c63b2 (patch)
treeab9fe2193d01085522b187b9805a8a66736f2cec
parentmeals fix and 1.0.11 version bump (diff)
downloadbeziapp-f4c07c8baee5d9bb0c89610425d92c66314c63b2.tar
beziapp-f4c07c8baee5d9bb0c89610425d92c66314c63b2.tar.gz
beziapp-f4c07c8baee5d9bb0c89610425d92c66314c63b2.tar.bz2
beziapp-f4c07c8baee5d9bb0c89610425d92c66314c63b2.tar.lz
beziapp-f4c07c8baee5d9bb0c89610425d92c66314c63b2.tar.xz
beziapp-f4c07c8baee5d9bb0c89610425d92c66314c63b2.tar.zst
beziapp-f4c07c8baee5d9bb0c89610425d92c66314c63b2.zip
-rw-r--r--js/meals.js106
-rw-r--r--sw.js2
2 files changed, 76 insertions, 32 deletions
diff --git a/js/meals.js b/js/meals.js
index d04bb6c..e2d4024 100644
--- a/js/meals.js
+++ b/js/meals.js
@@ -278,41 +278,85 @@ async function setMenu(date, menu) {
setLoading(false);
localforage.settItem("logged_in_lopolis", false).then(()=>{checkLogin();})
} else {
- $.ajax({
- url: API_ENDPOINT+"setmenus",
- crossDomain: true,
- contentType: "application/json",
- headers: {
- "Authorization": "Bearer "+dataauth.data
- },
- data: JSON.stringify({"choices": {[date]: menu}}),
- dataType: "json",
- cache: false,
- type: "POST",
- success: (data) => {
- if(data == null) {
- M.toast({ html: "Request for Setting the menu failed!" });
- setLoading(false);
- } else if(data.error == true) {
- M.toast({html:"Setting the menu errored out"});
- setLoading(false);
- } else {
- M.toast({html:"Success? It looks like one. Refresh the menus to be sure."});
- setLoading(false);
+ d = new Date();
+ $.ajax({
+ url: API_ENDPOINT+"getmenus",
+ crossDomain: true,
+ contentType: "application/json",
+ data: JSON.stringify({"month": d.getMonth()+1, "year": d.getFullYear()}),
+ headers: {
+ "Authorization": "Bearer "+dataauth.data
+ },
+ dataType: "json",
+ cache: false,
+ type: "POST",
+ success: (data) => {
+ if(data == null) {
+ M.toast({ html: "Request to get menus failed!" });
+ setLoading(false);
+ } else if(data.error == true) {
+ M.toast({html:"Lopolis refused to serve menus"});
+ setLoading(false);
+ } else {
+ localforage.setItem("meals", data).then((value) => {
+ othermeals = value;
+ var choices = new Object();
+ // tale for loop je zelo C-jevski approach ...
+ for(const [mealzzdate, mealzz] of Object.entries(othermeals.data)) {
+ if (mealzzdate == date) {
+ choices[mealzzdate] = menu;
+ } else {
+ for (const [mealid, mealdata] of Object.entries(mealzz.menu_options)) {
+ if(mealdata.selected == true) {
+ choices[mealzzdate] = mealdata.value;
+ break;
+ }
+ }
+ }
}
- },
- error: () => {
- M.toast({html:"No internet connection! Are you fucking kidding me??!?!?!"});
- setLoading(false);
+ // console.log(choices); // debug
+ $.ajax({
+ url: API_ENDPOINT+"setmenus",
+ crossDomain: true,
+ contentType: "application/json",
+ headers: {
+ "Authorization": "Bearer "+dataauth.data
+ },
+ data: JSON.stringify({"choices": choices}),
+ dataType: "json",
+ cache: false,
+ type: "POST",
+ success: (data) => {
+ if(data == null) {
+ M.toast({ html: "Request for Setting the menu failed!" });
+ setLoading(false);
+ } else if(data.error == true) {
+ M.toast({html:"Setting the menu errored out"});
+ setLoading(false);
+ } else {
+ M.toast({html:"Success? It looks like one. Refresh the menus to be sure."});
+ setLoading(false);
+ }
+ },
+ error: () => {
+ M.toast({html:"No internet connection! Are you fucking kidding me??!?!?!"});
+ setLoading(false);
+ }
+ });
+ });
}
- });
-
- }
- },
- error: () => {
+ },
+ error: () => {
+ M.toast({html:"No internet connection! (-:"});
+ setLoading(false);
+ }
+ });
+ }
+ },
+ error: () => {
M.toast({html:"No internet connection!"});
setLoading(false);
- }
+ }
});
}
diff --git a/sw.js b/sw.js
index 62142f8..7373a91 100644
--- a/sw.js
+++ b/sw.js
@@ -1,5 +1,5 @@
// Change version to cause cache refresh
-const static_cache_name = "site-static-v1.0.11";
+const static_cache_name = "site-static-v1.0.11.1";
// Tukej ne met notr directory namov, samo imena fajlov,
// ker v primeru index.html to prpele do double-cachinga, oz. do velik 404