Skip to content

Commit 1c27ecd

Browse files
1 parent 1674993 commit 1c27ecd

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

app/webapp/controller/App.controller.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,74 @@ sap.ui.define("z2ui5/Geolocation", ["sap/ui/core/Control"], (Control) => {
458458
}
459459
);
460460

461+
sap.ui.define("z2ui5/Storage", ["sap/ui/core/Control", "sap/ui/util/Storage"], (Control, Storage) => {
462+
"use strict";
463+
464+
return Control.extend("z2ui5.Storage", {
465+
metadata: {
466+
properties: {
467+
type: {
468+
type: "string",
469+
defaultValue: "session"
470+
},
471+
prefix: {
472+
type: "string",
473+
defaultValue: ""
474+
},
475+
key: {
476+
type: "string",
477+
defaultValue: ""
478+
},
479+
value: {
480+
type: "any",
481+
defaultValue: ""
482+
}
483+
},
484+
events: {
485+
"finished": {
486+
parameters: {
487+
type: {
488+
type: "string",
489+
},
490+
prefix: {
491+
type: "string",
492+
},
493+
key: {
494+
type: "string",
495+
},
496+
value: {
497+
type: "any",
498+
}
499+
}
500+
}
501+
}
502+
},
503+
504+
async renderer(_, oControl) {
505+
let storageType = oControl.getProperty("type");
506+
let storageKeyPrefix = oControl.getProperty("prefix");
507+
let storageKey = oControl.getProperty("key");
508+
let storageValue = oControl.getProperty("value");
509+
let oStorage = new Storage(storageType, storageKeyPrefix);
510+
let storedValue = oStorage.get(storageKey);
511+
if (storedValue == null) {
512+
storedValue = "";
513+
}
514+
if (storedValue !== storageValue) {
515+
oControl.setProperty("value", storedValue);
516+
oControl.fireFinished({
517+
"type": storageType,
518+
"prefix": storageKeyPrefix,
519+
"key": storageKey,
520+
"value": storedValue
521+
});
522+
}
523+
},
524+
onAfterRendering() { },
525+
init() { }
526+
});
527+
});
528+
461529
sap.ui.define("z2ui5/FileUploader", ["sap/ui/core/Control", "sap/m/Button", "sap/ui/unified/FileUploader", "sap/m/HBox"], function (Control, Button, FileUploader, HBox) {
462530
"use strict";
463531

app/webapp/controller/View1.controller.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
sap.ui.define(["sap/ui/core/mvc/Controller", "sap/ui/core/mvc/XMLView", "sap/ui/model/json/JSONModel",
22
"sap/ui/core/BusyIndicator", "sap/m/MessageBox", "sap/m/MessageToast", "sap/ui/core/Fragment", "sap/m/BusyDialog",
3-
"sap/ui/VersionInfo", "z2ui5/cc/Server", "sap/ui/model/odata/v2/ODataModel", "sap/m/library", "sap/ui/core/routing/HashChanger"
3+
"sap/ui/VersionInfo", "z2ui5/cc/Server", "sap/ui/model/odata/v2/ODataModel", "sap/m/library", "sap/ui/core/routing/HashChanger", "sap/ui/util/Storage"
44
],
55
function (Controller, XMLView, JSONModel, BusyIndicator, MessageBox, MessageToast, Fragment, mBusyDialog, VersionInfo,
6-
Server, ODataModel, mobileLibrary, HashChanger) {
6+
Server, ODataModel, mobileLibrary, HashChanger, Storage) {
77
"use strict";
88
return Controller.extend("z2ui5.controller.View1", {
99

@@ -313,6 +313,24 @@ sap.ui.define(["sap/ui/core/mvc/Controller", "sap/ui/core/mvc/XMLView", "sap/ui/
313313
var oModel = new ODataModel({ serviceUrl: args[1], annotationURI: (args.length > 3 ? args[3] : '') });
314314
z2ui5.oView.setModel(oModel, args[2] ? args[2] : undefined);
315315
break;
316+
case 'STORE_DATA':
317+
let storageParams = args[1];
318+
let storageType = Storage.Type.session;
319+
switch (storageParams.TYPE) {
320+
case 'session':
321+
storageType = Storage.Type.session;
322+
break;
323+
case 'local':
324+
storageType = Storage.Type.local;
325+
break;
326+
}
327+
let oStorage = new Storage(storageType, storageParams.PREFIX);
328+
if (storageParams.VALUE == "" || storageParams.VALUE == null) {
329+
oStorage.remove(storageParams.KEY);
330+
} else {
331+
oStorage.put(storageParams.KEY, storageParams.VALUE);
332+
}
333+
break;
316334
case 'DOWNLOAD_B64_FILE':
317335
var a = document.createElement("a");
318336
a.href = args[1];

0 commit comments

Comments
 (0)