Commit 25e5aa75 authored by Samir Sadyhov's avatar Samir Sadyhov 🤔

update UTILS.js

parent 1ad54039
......@@ -365,30 +365,56 @@ UTILS.detectBrowser = () => {
}
}
const getDictValue = (item, id) => {
return item.values.find(x => x.columnID == id)?.value || null;
}
const getDictValue = (item, id) => item.values.find(x => x.columnID == id)?.value || null;
UTILS.parseDict = dict => {
const result = [];
try {
if(!dict) throw new Error('Не передан справочник');
dict.items.forEach(item => {
const tmp = {};
tmp.itemID = item.itemID;
dict.columns.forEach(col => {
tmp[col.code] = getDictValue(item, col.columnID);
});
dict.columns.forEach(col => tmp[col.code] = getDictValue(item, col.columnID));
result.push(tmp);
});
return result;
} catch (err) {
console.log(`ERROR [parseDict]: ${err.message}`);
return result;
}
}
UTILS.Cookie = {
get: function(name) {
let matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
},
set: function(name, value, options = {}) {
options = {path: '/', ...options};
if (options.expires instanceof Date) options.expires = options.expires.toUTCString();
let updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);
for (let optionKey in options) {
updatedCookie += "; " + optionKey;
let optionValue = options[optionKey];
if (optionValue !== true) updatedCookie += "=" + optionValue;
}
document.cookie = updatedCookie;
},
delete: function(){
UTILS.Cookie.set(name, "", {'max-age': -1});
}
}
//выпиливыние из массива повторяющихся елементов
Array.prototype.uniq = function() {
return this.filter(function(v, i, a){ return i == a.indexOf(v) });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment