@slavmak2486/bx24ts
Version:
Library for bitrix24
132 lines (131 loc) • 4.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BX24Dev = void 0;
const BX24Server_1 = require("./BX24Server");
const lodash_1 = require("lodash");
class BX24Dev extends BX24Server_1.BX24Server {
constructor(param, cb) {
super(param);
this.appOption = {
get: (name) => {
return this.APP_OPTIONS[name];
},
set: (name, value, cb) => {
if (this.isAdmin()) {
const params = {};
params[name] = value;
this.callMethod('app.option.set', params, res => {
if (res.data() === true) {
this.APP_OPTIONS[name] = value;
}
if (cb) {
cb(res);
}
});
}
else {
console.error('Access denied!');
}
}
};
this.userOption = {
get: (name) => {
return this.USER_OPTIONS[name];
},
set: (name, value, cb) => {
const params = {};
params[name] = value;
this.callMethod('user.option.set', params, res => {
if (res.data() === true) {
this.USER_OPTIONS[name] = value;
}
if (cb) {
cb(res);
}
});
}
};
this.init(() => {
this.callBatch({
getAppOption: ['app.option.get', {}],
getUserOption: ['user.option.get', {}]
}, ress => {
let idx;
let textError = '';
for (idx in ress) {
const res = ress[idx];
if (res.error()) {
textError += `Init error. Check auth data. ${res.error()} for ${idx}\n`;
}
else {
if (idx == 'getAppOption') {
this.APP_OPTIONS = res.data();
}
else {
this.USER_OPTIONS = res.data();
}
}
}
if (textError)
console.error(textError);
if (cb) {
cb();
}
});
this.getPlacementOptions();
});
if (new Date().getTime() - 5 * 60 * 1000 > this.AUTH_EXPIRES && !param.noUpdateRefresh) {
this.refreshAuthAsync().then(() => {
this.doInit();
})
.catch((error) => {
this.logger.error(error);
});
}
else {
this.doInit();
}
}
getPlacementOptions() {
const result = {};
const url = typeof location !== 'undefined' ? new URL(location.href) : undefined;
const entrity = url ? url.searchParams.entries() : undefined;
const regexp = /\[([^\]]*)]/g;
let done = entrity ? false : true;
while (!done) {
const el = entrity.next();
done = el.done === true ? true : false;
if (el.value) {
let tempArrPath = Array.from(el.value[0].matchAll(regexp));
tempArrPath = tempArrPath.map(ell => { return ell[1]; });
const base = el.value[0].split('[')[0];
(0, lodash_1.set)(result, [base, ...tempArrPath], el.value[1]);
}
}
if (result.placement) {
this.PLACEMENT = result.placement;
delete (result.placement);
}
else {
this.PLACEMENT = 'DEFAULT';
}
this.PLACEMENT_OPTIONS = result;
}
openApplication(params, cb, settings) {
if (!params) {
params = {};
}
if (settings && typeof (settings) == 'object') {
for (const item in settings) {
params["bx24_" + item] = settings[item];
}
}
window.open(`?${this.getHttpString(params)}`);
console.log(`На проде по закрытии слайдера, я запущу функцию`, cb);
}
openPath(path, cb) {
window.open(`${this.PROTOCOL ? 'https:' : 'http'}${this.DOMAIN}${path}`);
console.log(`На проде по закрытии слайдера, я запущу функцию`, cb);
}
}
exports.BX24Dev = BX24Dev;