window.onbeforeunload = function (e) {
var message = "Document 'foo' is not saved. You will lost the changes if you leave the page.";
if (typeof e == "undefined") {
e = window.event;
}
if (e) {
e.returnValue = message;
}
return message;
};
const WHO = {
SYSTEM: {KEY: 0, PREFIX: 'system_', VALUE: "system"},
USER: {KEY: 1, PREFIX: 'user_', VALUE: "user"},
HOST: {KEY: 2, PREFIX: 'host_', VALUE: "host"},
WEB: {KEY: 4, PREFIX: 'web_', VALUE: "web"}
};
var isDebug = true;
var onLoadError = false;
//var config = [];
var url = location.href;
var currContent = '';
var currSide = '';
// data arrays
var console_, chat, lines, chanels, tarifs, devices, events, values, commands, calls, hosts, cancelCauses, penalties, penaltyCauses, uslugi;
var orders;
var selected_order = null;
// ws
var wait; // update interval. Wait ws connection.
// map
var layerCars;
var layerSectors;
var layerOrders;
// network
var wsClient;
var httpClient;
// components
var toolBarTop;
var toolBarSide;
var windowOrder;
var windowCar;
var windowConfig;
var windowChat;
var windowConsole;
var map;
var hostsTab;
var activeOrders;
//var historyOrders;
//var historyCalls;
var sideCars;
var sideCalls;
var sideChat;
//var phone;
//var orderMenu;
var deviceMenu;
//var locale = 'en-US';
var locale = 'ru-RU';
var phoneAnswer = 0;
webix.ready(function () {
if (isDebug) console.debug('application.js: require begin');
$('body').html('
');
webix.debug = true;
webix.require([
'i18n/ru.js',
'i18n/en.js',
'../objects/host.js',
'../objects/device.js',
'../objects/value.js',
'../objects/command.js',
'../objects/event.js',
'../objects/order.js',
//'../objects/call.js',
'../actions/side_chat.js',
'../actions/config.js',
//'../actions/phone.js',
'../actions/toolbar_top.js',
'../actions/toolbar_side.js',
'../actions/active_orders.js',
//'../actions/history_orders.js',
//'../actions/history_calls.js',
'../actions/map.js',
'../actions/hosts.js',
'../actions/create_order.js',
'../actions/device_menu.js',
//'../actions/car_window.js',
'../actions/chat_window.js',
'../actions/console_window.js',
//'../actions/order_menu.js',
'../actions/side_cars.js',
'../actions/side_calls.js',
'../views/side_chat.js',
'../views/config.js',
//'../views/phone.js',
'../views/toolbar_top.js',
'../views/toolbar_side.js',
'../views/active_orders.js',
//'../views/history_orders.js',
//'../views/history_calls.js',
'../views/layout.js',
'../views/map.js',
'../views/hosts.js',
'../views/create_order.js',
'../views/device_menu.js',
//'../views/car_window.js',
'../views/chat_window.js',
'../views/console_window.js',
//'../views/order_menu.js',
'../views/side_cars.js',
'../views/side_calls.js',
//'../websocket.js',
'../socket_io_client.js',
'../http_client.js'
], run);
function run() {
$('body').html('');
webix.i18n.setLocale(locale);
if (isDebug) console.debug('application.js:run');
CreateDataCollections();
CreateMapLayers();
//httpClient = new HttpClient({url: url});
// init layout
webix.ui(ui_layout);
// init header
toolBarTop = new ToolBarTop(ui_toolbar_top);
toolBarSide = new ToolBarSide(ui_toolbar_side);
//onLoadError = false;
if (!onLoadError) {
// init car context menu
deviceMenu = new DeviceMenu(ui_device_menu);
//windowCar = new WindowCar();
// init order context menu
//orderMenu = new OrderMenu(ui_order_menu);
// init chat window
windowChat = new WindowChat(ui_window_chat);
windowConsole = new WindowConsole(ui_window_console);
// init left side panel
//activeOrders = new ActiveOrders(ui_active_orders);
//activeOrders.Show();
sideCars = new SideCars(ui_side_cars);
sideCalls = new SideCalls(ui_side_calls);
sideChat = new SideChat(ui_side_chat);
//sideConsole = new SideConsole(ui_side_console);
// init history orders
//historyOrders = new HistoryOrders();
//historyCalls = new HistoryCalls();
// init map
map = new ViewMap(ui_map, {
lat: 48,//config.city_la,
lng: 38,//config.city_lo,
zoom: 14,//config.city_zoom,
arm_map: 1//config.arm_map
});
hostsTab = new Hosts(ui_host);
// init order window
windowOrder = new WindowOrder();
// окно настроек
windowConfig = new WindowConfig(ui_window_config);
// init phone
//if (config.default.internal_phone == 1) {
// phone = new Phone(ui_phone);
//}
// connect to server
/*wsClient = new WsClient(config.hostname, config.ws_port);
var reconnect = false;
if (config.default.ws_reconnect && config.default.ws_reconnect == '1') {
reconnect = true;
}
wsClient.Connect(reconnect);*/
wsClient = new SocketIoClient();
wsClient.init('myprog.com.ua', 5599);
//wsClient.init(config.hostname, config.ws_port);
if (isDebug) console.debug('application.js:init');
map.Show();
//hostsTab.Show();
$('body').append('');
} else {
webix.alert({
type: 'error',
text: 'Ошибка загрузки. Попробуйте обновить страницу'
})
}
}
function CreateDataCollections() {
// collections
hosts = new webix.DataCollection();
//orders = new webix.DataCollection();
events = new webix.DataCollection();
devices = new webix.DataCollection();
values = new webix.DataCollection();
commands = new webix.DataCollection();
//calls = new webix.DataCollection();
//cancelCauses = new webix.DataCollection();
chat = new webix.DataCollection();
console_ = new webix.DataCollection();
// events
/*orders.attachEvent("onAfterAdd", function (id) {
if (orders.data.count() > config.default.orders_history_count) {
var min = Number.MAX_VALUE;
orders.data.each(function (o) {
if (o.id < min) min = o.id
});
orders.remove(min);
console.debug('onAfterAdd:Remove:'+min);
}
});*/
/*calls.attachEvent("onAfterAdd", function (id) {
if (calls.data.count() > config.default.calls_history_count) {
var min = Number.MAX_VALUE;
calls.data.each(function (o) {
if (o.id < min) min = o.id
});
calls.remove(min);
}
});
*/
}
function CreateMapLayers() {
layerCars = L.featureGroup();
layerSectors = L.featureGroup();
layerOrders = L.featureGroup();
}
// hotkeys
webix.UIManager.addHotKey("pageup", function () {
phoneAnswer = 1;
if (phone) phone.Answer();
});
webix.UIManager.addHotKey("pagedown", function () {
if (phone) phone.Hungup();
});
webix.UIManager.addHotKey("ctrl+q", function () {
makeScreenshot();
});
webix.event(window, "resize", function () {
if ($$('toolbar_top').getNode().offsetHeight > 0) {
//alert ( getViewport().height - $$('toolbar_top').getNode().offsetHeight);
$$('content').define('height', getViewport().height - $$('toolbar_top').getNode().offsetHeight);
}
$$('layout').adjust();
$$('side').adjust();
$$('content').adjust();
});
});
function makeScreenshot() {
html2canvas(document.body).then(function (canvas) {
var data = canvas.toDataURL('image/png').replace(/data:image\/png;base64,/, '');
canvas.remove();
var post = {
action: 'screen',
data: data
};
$.ajax({
url: 'index.php',
method: 'POST',
data: post,
dataType: 'json',
success: function (data) {
}
});
});
}
function BuildApiUrl(method) {
var random = Math.random() * (2 - 1) + 1;
var ck = '/client_key/' + config.client_key;
var ck2 = 'client_key=' + config.client_key;
var sig = hex_md5(ck2 + 'method=' + method + 'random=' + random + config.api_key);
return '/api' + ck + '/method/' + method + '/random/' + random + '/sig/' + sig;
}
function sortNumber(a, b) {
return a - b;
}
function getViewport() {
var viewPortWidth;
var viewPortHeight;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined') {
viewPortWidth = window.innerWidth,
viewPortHeight = window.innerHeight
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0) {
viewPortWidth = document.documentElement.clientWidth,
viewPortHeight = document.documentElement.clientHeight
}
// older versions of IE
else {
viewPortWidth = document.getElementsByTagName('body')[0].clientWidth,
viewPortHeight = document.getElementsByTagName('body')[0].clientHeight
}
return {width: viewPortWidth, height: viewPortHeight};
}
function getStatusPic(status_id) {
if (status_id=='switch') {
return '/app/images/statuspic/switch_16.png';
}
if (status_id=='smart_led') {
return '/app/images/statuspic/rgb_16.png';
}
if (status_id=='relay') {
return '/app/images/statuspic/relay3_16.png';
}
if (status_id=='pwr') {
return '/app/images/statuspic/pwr_16.png';
}
if (status_id=='temp') {
return '/app/images/statuspic/temp_16.png';
}
if (status_id=='hum') {
return '/app/images/statuspic/hum2_16.png';
}
var status_idpic = [];
status_idpic[0] = 'white.png';
status_idpic[1] = 'green.png';
status_idpic[2] = 'yellow.png';
status_idpic[3] = 'white.png';
status_idpic[4] = 'red.png';
status_idpic[5] = 'red.png';
status_idpic[6] = 'green.png';
status_idpic[7] = 'green.png';
status_idpic[8] = 'red.png';
status_idpic[9] = 'green.png';
status_idpic[10] = 'red.png';
status_idpic[11] = 'blue.png';
status_idpic[12] = 'red.png';
status_idpic[13] = 'orange.png';
status_idpic[21] = 'yellow.png';
status_idpic[31] = 'red.png';
status_idpic[32] = 'red.png';
status_idpic[33] = 'red.png';
status_idpic[34] = 'red.png';
status_idpic[35] = 'white.png';
status_idpic[36] = 'red.png';
status_idpic[37] = 'red.png';
status_idpic[38] = 'white.png';
status_idpic[50] = 'yellow.png';
return '/app/images/statuspic/' + status_idpic[status_id];
}
function getParkStatusText(status) {
/*
define('PARK_READY',1);
define('PARK_COFFE',2);
define('PARK_HOME',3);
define('PARK_PENALTY',4);
define('PARK_BUSY',5);
define('PARK_UNCOFFE',6);
define('PARK_LOW_MONEY',7);
define('PARK_NEED_PHOTO',8);
define('PARK_GRAPHIC',9);
define('PARK_SET_FIRST',10);
*/
var text = '';
if (status) {
switch (status) {
case 1:
text = 'свободен';
break;
case 2:
text = 'кофе';
break;
case 3:
text = 'дом';
break;
case 4:
text = 'оштрафован';
break;
case 5:
text = 'занят';
break;
case 6:
text = 'свободен';
break;
case 7:
text = 'пополтите счет';
break;
case 8:
text = 'фото отчет';
break;
case 9:
text = 'по графику';
break;
case 10:
text = 'поставить первым';
break;
default:
text = '';
break;
}
}
return text;
}
function seconds_to_time(sec) {
var seconds = parseInt(sec, 10);
if (seconds > 0) {
var days = Math.floor(seconds / (3600 * 24));
seconds -= days * 3600 * 24;
var hours = Math.floor(seconds / 3600);
seconds -= hours * 3600;
var minutes = Math.floor(seconds / 60);
seconds -= minutes * 60;
if (days > 0) {
return days + webix.i18n.locales[locale].time.days;
} else if (hours > 0) {
return hours + webix.i18n.locales[locale].time.hours;
} else if (minutes > 0) {
return minutes + webix.i18n.locales[locale].time.minutes;
} else if (seconds > 0) {
return seconds + webix.i18n.locales[locale].time.seconds
}
}else{
return '0' + webix.i18n.locales[locale].time.minutes;
}
};
function minutes_to_time(min) {
var minutes = parseInt(min);
var days = Math.floor(minutes / (60 * 24));
minutes -= days *60* 24;
var hours = Math.floor(minutes / 60);
minutes -= hours * 60;
if(days > 0){
return days +webix.i18n.locales[locale].time.days;
}else if(hours > 0){
return hours +webix.i18n.locales[locale].time.hours;
}else{
return minutes +webix.i18n.locales[locale].time.minutes;
}
};
function remove_char(str, char_pos) {
part1 = str.substring(0, char_pos);
part2 = str.substring(char_pos + 1, str.length);
return (part1 + part2);
}
function normalize_phone(phone) {
if(phone) {
phone = phone.trim();
if (phone.substr(0, 1) == '+') {
phone = phone.substr(config.prefix.length);
}
phone = phone.length > 10 ? phone.substr(-10) : phone;
if (10 == phone.length) {
var f = false;
config.mobile_operators.forEach(function (i) {
if (i.line_type == 10 && i.code == phone.substr(0, i.code.length)) {
f = true;
}
});
if (f) {
return config.prefix + phone.substr(-config.asterisk_col_digits);
} else {
return false;
}
} else if (7 == phone.length || 6 == phone.length || 7 == phone.length) {
var p = '';
config.mobile_operators.forEach(function (i) {
if (7 == i.line_type && 7 == phone.length) {
p = i.code + phone;
}
if (6 == i.line_type || 6 == phone.length) {
p = i.code + phone;
}
if (5 == i.line_type || 5 == phone.length) {
p = i.code + phone;
}
});
if (p.length > 0) {
return p;
} else {
return false;
}
} else {
return false;
}
}else{
return false;
}
}
Array.prototype.in_array = function (p_val) {
for (var i = 0, l = this.length; i < l; i++) {
if (this[i] == p_val) {
return true;
}
}
return false;
};