-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
123 lines (108 loc) · 2.87 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// File for all used functions and objects
// set Toaster options for warning messages
function toasterOptions() {
toastr.options = {
closeButton: true,
debug: false,
newestOnTop: true,
progressBar: true,
positionClass: "toast-top-right",
preventDuplicates: true,
onclick: null,
showDuration: "3000",
hideDuration: "1000",
timeOut: "2000",
extendedTimeOut: "1000",
showEasing: "swing",
hideEasing: "linear",
showMethod: "show",
hideMethod: "hide",
};
}
toasterOptions();
//set an element class function
function setClass(elem, clas) {
elem.className = clas;
}
// define object class registered user
class regUser {
constructor(fnam, lnam, em, ag, usr, psw) {
this.fnam = fnam;
this.lnam = lnam;
this.em = em;
this.ag = ag;
this.usr = usr;
this.psw = psw;
}
}
// define object logged user
class loggedUser {
constructor(user, loginTime) {
this.user = user;
this.loginTime = loginTime;
}
}
function delay(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
// function to read data from local storage
function getItemsFromLS(storObj,key, objArr){
storObj = localStorage.getItem(key);
if (storObj) {
objArr=JSON.parse(storObj);
return objArr;
}
}
// function to set data to Local storage
function setItemToLS(key, obj){
localStorage.setItem(key, JSON.stringify(obj));
}
// create new shift ID
function createId(shAr){
let id;
let foundId = false;
do {id = Math.random().toString(36).substring(2,13);
// check if the new created id is already used
for (let item of shAr){
if (item.shiftId == id){
foundId = true;
break;
}
}
} while (foundId);
// add newly created id to ids array and store ids array to localstorage
return id;
}
// define Shift object
class Shift{
constructor (addDate, startTime, endTime, hourlyWage, place, shiftId, profit, comment){
this.addDate = addDate;
this.startTime = startTime;
this.endTime = endTime;
this.hourlyWage = hourlyWage;
this.place = place;
this.shiftId = shiftId;
this.profit = profit;
this.comment = comment;
}
}
//function to test against regEx
function testInput(exp, elem) {
if (exp.test(elem)) {
return true;
}
return false;
}
//change HTML element class for focusout event
function focusOut(elem,clas){
elem.addEventListener("focusout", (ev)=>{
setClass(elem, clas);
});
}
// function to extract month-year string from shifts array
function monYearStr(shift_date){
let actDate = new Date(shift_date);
let actYear = actDate.getFullYear();
let actMonth = actDate.toLocaleString("default", {month: 'long'});
return `${actMonth}-${actYear}`;
}