', {
id: config.mapModuleId
});
}
return mapModule;
};
/**
* get Area ID by security string
* @param security
* @returns {number}
*/
let getAreaIdBySecurity = function(security){
let areaId = 0;
switch(security){
case 'H':
areaId = 10;
break;
case 'L':
areaId = 11;
break;
case '0.0':
areaId = 12;
break;
case 'SH':
areaId = 13;
break;
default:
// w-space
for(let i = 1; i <= 6; i++){
if(security === 'C' + i){
areaId = i;
break;
}
}
break;
}
return areaId;
};
/**
* get system effect data by system security and system class
* if no search parameters given -> get all effect data
* @param security
* @param effect
* @returns {boolean}
*/
let getSystemEffectData = function(security, effect){
let data = SystemEffect;
if(security){
// look for specific data
data = false;
let areaId = getAreaIdBySecurity(security);
if(
areaId > 0 &&
SystemEffect.wh[effect] &&
SystemEffect.wh[effect][areaId]
){
data = SystemEffect.wh[effect][areaId];
}
}
return data;
};
/**
* get status info for a character for a given status
* @param characterData
* @param option
* @returns {string}
*/
let getStatusInfoForCharacter = function(characterData, option){
let statusInfo = '';
// character status can not be checked if there are no reference data
// e.g. during registration process (login page)
if(Init.characterStatus){
// get info for current "main" character
let corporationId = getCurrentUserInfo('corporationId');
let allianceId = getCurrentUserInfo('allianceId');
// get all user characters
let userData = getCurrentUserData();
if(userData){
// check if character is one of his own characters
let userCharactersData = userData.characters;
for(let i = 0; i < userCharactersData.length; i++){
if(userCharactersData[i].id === characterData.id){
statusInfo = Init.characterStatus.own[option];
break;
}
}
}
if(statusInfo === ''){
// compare current user data with given user data
if(
characterData.corporation &&
characterData.corporation.id === corporationId
){
statusInfo = Init.characterStatus.corporation[option];
}else if(
characterData.alliance &&
characterData.alliance.id === allianceId
){
statusInfo = Init.characterStatus.alliance[option];
}
}
}
return statusInfo;
};
/**
* get a HTML table with system effect information
* e.g. for popover
* @param data
* @returns {string}
*/
let getSystemEffectTable = function(data){
let table = '';
if(data.length > 0){
table += '
';
for(let i = 0; i < data.length; i++){
table += '';
table += '| ';
table += data[i].effect;
table += ' | ';
table += '';
table += data[i].value;
table += ' | ';
table += '
';
}
table += '
';
}
return table;
};
/**
* get a HTML table with information for multiple systems
* e.g. for popover
* @param data
* @returns {string}
*/
let getSystemsInfoTable = function(data){
let table = '';
if(data.length > 0){
table += '
';
for(let i = 0; i < data.length; i++){
let trueSecClass = getTrueSecClassForSystem( data[i].trueSec );
let securityClass = getSecurityClassForSystem( data[i].security );
table += '';
table += '| ';
table += data[i].name;
table += ' | ';
table += '';
table += data[i].security;
table += ' | ';
table += '';
table += parseFloat( data[i].trueSec ).toFixed(1);
table += ' | ';
table += '
';
}
table += '
';
}
return table;
};
/**
* get a css class for the security level of a system
* @param sec
* @returns {string}
*/
let getSecurityClassForSystem = function(sec){
let secClass = '';
if( Init.classes.systemSecurity.hasOwnProperty(sec) ){
secClass = Init.classes.systemSecurity[sec]['class'];
}
return secClass;
};
/**
* get a css class for the trueSec level of a system
* @param trueSec
* @returns {string}
*/
let getTrueSecClassForSystem = function(trueSec){
let trueSecClass = '';
trueSec = parseFloat(trueSec);
// check for valid decimal number
if(
!isNaN( trueSec ) &&
isFinite( trueSec )
){
if(trueSec < 0){
trueSec = 0;
}
trueSec = trueSec.toFixed(1).toString();
if( Init.classes.trueSec.hasOwnProperty(trueSec) ){
trueSecClass = Init.classes.trueSec[trueSec]['class'];
}
}
return trueSecClass;
};
/**
* get status info
* @param status
* @param option
* @returns {string}
*/
let getStatusInfoForSystem = function(status, option){
let statusInfo = '';
if( Init.systemStatus.hasOwnProperty(status) ){
// search by status string
statusInfo = Init.systemStatus[status][option];
}else{
// saarch by statusID
$.each(Init.systemStatus, function(prop, data){
if(status === data.id){
statusInfo = data[option];
return;
}
});
}
return statusInfo;
};
/**
* get signature group information
* @param option
* @returns {{}}
*/
let getSignatureGroupInfo = function(option){
let groupInfo = {};
for (let prop in Init.signatureGroups) {
if(Init.signatureGroups.hasOwnProperty(prop)){
prop = parseInt(prop);
groupInfo[prop] = Init.signatureGroups[prop][option];
}
}
return groupInfo;
};
/**
* get Signature names out of global
* @param systemTypeId
* @param areaId
* @param sigGroupId
* @returns {{}}
*/
let getAllSignatureNames = function(systemTypeId, areaId, sigGroupId){
let signatureNames = {};
if(
SignatureType[systemTypeId] &&
SignatureType[systemTypeId][areaId] &&
SignatureType[systemTypeId][areaId][sigGroupId]
){
signatureNames = SignatureType[systemTypeId][areaId][sigGroupId];
}
return signatureNames;
};
/**
* get the typeID of a signature name
* @param systemData
* @param sigGroupId
* @param name
* @returns {number}
*/
let getSignatureTypeIdByName = function(systemData, sigGroupId, name){
let signatureTypeId = 0;
let areaId = getAreaIdBySecurity(systemData.security);
if(areaId > 0){
let signatureNames = getAllSignatureNames(systemData.type.id, areaId, sigGroupId );
name = name.toLowerCase();
for(let prop in signatureNames) {
if(
signatureNames.hasOwnProperty(prop) &&
signatureNames[prop].toLowerCase() === name
){
signatureTypeId = parseInt( prop );
break;
}
}
}
return signatureTypeId;
};
/**
* set currentMapUserData as "global" variable (count of active pilots)
* this function should be called continuously after data change
* to keep the data always up2data
* @param mapUserData
*/
let setCurrentMapUserData = function(mapUserData){
Init.currentMapUserData = mapUserData;
return getCurrentMapUserData();
};
/**
* get currentMapUserData from "global" variable for specific map or all maps
* @param mapId
* @returns {boolean}
*/
let getCurrentMapUserData = function(mapId){
let currentMapUserData = false;
if(
mapId === parseInt(mapId, 10) &&
Init.currentMapUserData
){
// search for a specific map
for(let i = 0; i < Init.currentMapUserData.length; i++){
if(Init.currentMapUserData[i].config.id === mapId){
currentMapUserData = Init.currentMapUserData[i];
break;
}
}
}else{
// get data for all maps
currentMapUserData = Init.currentMapUserData;
}
if(currentMapUserData !== false){
// return a fresh (deep) copy of that, in case of further modifications
currentMapUserData = $.extend(true, {}, currentMapUserData);
}
return currentMapUserData;
};
/**
* set currentMapData as "global" variable
* this function should be called continuously after data change
* to keep the data always up2data
* @param mapData
*/
let setCurrentMapData = function(mapData){
Init.currentMapData = mapData;
return getCurrentMapData();
};
/**
* get mapData array index by mapId
* @param mapId
* @returns {boolean|int}
*/
let getCurrentMapDataIndex = function(mapId){
let mapDataIndex = false;
if( mapId === parseInt(mapId, 10) ){
for(let i = 0; i < Init.currentMapData.length; i++){
if(Init.currentMapData[i].config.id === mapId){
mapDataIndex = i;
break;
}
}
}
return mapDataIndex;
};
/**
* update cached mapData for a single map
* @param mapData
*/
let updateCurrentMapData = function(mapData){
let mapDataIndex = getCurrentMapDataIndex( mapData.config.id );
if(mapDataIndex !== false){
Init.currentMapData[mapDataIndex].config = mapData.config;
Init.currentMapData[mapDataIndex].data = mapData.data;
}else{
// new map data
Init.currentMapData.push(mapData);
}
};
/**
* get currentMapData from "global" variable for a specific map or all maps
* @param mapId
* @returns {boolean}
*/
let getCurrentMapData = function(mapId){
let currentMapData = false;
if( mapId === parseInt(mapId, 10) ){
// search for a specific map
for(let i = 0; i < Init.currentMapData.length; i++){
if(Init.currentMapData[i].config.id === mapId){
currentMapData = Init.currentMapData[i];
break;
}
}
}else{
// get data for all maps
currentMapData = Init.currentMapData;
}
return currentMapData;
};
/**
* delete map data by mapId from currentMapData
* @param mapId
*/
let deleteCurrentMapData = (mapId) => {
Init.currentMapData = Init.currentMapData.filter((mapData) => {
return (mapData.config.id !== mapId);
});
};
/**
* set currentUserData as "global" variable
* this function should be called continuously after data change
* to keep the data always up2data
* @param userData
*/
let setCurrentUserData = function(userData){
Init.currentUserData = userData;
// check if function is available
// this is not the case in "login" page
if( $.fn.updateHeaderUserData ){
$.fn.updateHeaderUserData();
}
return getCurrentUserData();
};
/**
* get the current log data for the current user character
* @returns {boolean}
*/
let getCurrentCharacterLog = function(){
let characterLog = false;
let currentUserData = getCurrentUserData();
if(
currentUserData &&
currentUserData.character &&
currentUserData.character.log
){
characterLog = currentUserData.character.log;
}
return characterLog;
};
/**
* get information for the current mail user
* @param option
* @returns {boolean}
*/
let getCurrentUserInfo = function(option){
let currentUserData = getCurrentUserData();
let userInfo = false;
if(currentUserData){
// user data is set -> user data will be set AFTER the main init request!
let characterData = currentUserData.character;
if(characterData){
if(
option === 'allianceId' &&
characterData.alliance
){
userInfo = characterData.alliance.id;
}
if(
option === 'corporationId' &&
characterData.corporation
){
userInfo = characterData.corporation.id;
}
}
}
return userInfo;
};
/**
* set new destination for a system
* -> CREST request
* @param systemData
* @param type
*/
let setDestination = function(systemData, type){
let description = '';
switch(type){
case 'set_destination':
description = 'Set destination';
break;
case 'add_first_waypoint':
description = 'Set first waypoint';
break;
case 'add_last_waypoint':
description = 'Set new waypoint';
break;
}
$.ajax({
type: 'POST',
url: Init.path.setDestination,
data: {
clearOtherWaypoints: (type === 'set_destination') ? 1 : 0,
first: (type === 'add_last_waypoint') ? 0 : 1,
systemData: [{
systemId: systemData.systemId,
name: systemData.name
}]
},
context: {
description: description
},
dataType: 'json'
}).done(function(responseData){
if(
responseData.systemData &&
responseData.systemData.length > 0
){
for (let j = 0; j < responseData.systemData.length; j++) {
showNotify({title: this.description, text: 'System: ' + responseData.systemData[j].name, type: 'success'});
}
}
if(
responseData.error &&
responseData.error.length > 0
){
for(let i = 0; i < responseData.error.length; i++){
showNotify({title: this.description + ' error', text: 'System: ' + responseData.error[i].message, type: 'error'});
}
}
}).fail(function( jqXHR, status, error) {
let reason = status + ' ' + error;
showNotify({title: jqXHR.status + ': ' + this.description, text: reason, type: 'warning'});
});
};
/**
* set currentSystemData as "global" variable
* @param systemData
*/
let setCurrentSystemData = function(systemData){
Init.currentSystemData = systemData;
};
/**
* get currentSystemData from "global" variables
* @returns {*}
*/
let getCurrentSystemData = function(){
return Init.currentSystemData;
};
/**
* get current location data
* -> system data where current user is located
* @returns {{id: *, name: *}}
*/
let getCurrentLocationData = function(){
let currentLocationLink = $('#' + config.headCurrentLocationId).find('a');
return {
id: currentLocationLink.data('systemId'),
name: currentLocationLink.data('systemName')
};
};
/**
* get all "open" dialog elements
* @returns {*|jQuery}
*/
let getOpenDialogs = function(){
return $('.' + config.dialogClass).filter(':visible');
};
/**
* send Ajax request that remote opens an ingame Window
* @param targetId
*/
let openIngameWindow = (targetId) => {
targetId = parseInt(targetId);
if(targetId > 0){
$.ajax({
type: 'POST',
url: Init.path.openIngameWindow,
data: {
targetId: targetId
},
dataType: 'json'
}).done(function(data){
if(data.error.length > 0){
showNotify({title: 'Open window in client', text: 'Remote window open failed', type: 'error'});
}else{
showNotify({title: 'Open window in client', text: 'Check your EVE client', type: 'success'});
}
}).fail(function( jqXHR, status, error) {
let reason = status + ' ' + error;
showNotify({title: jqXHR.status + ': openWindow', text: reason, type: 'error'});
});
}
};
/**
* formats a price string into an ISK Price
* @param price
* @returns {string}
*/
let formatPrice = function(price){
price = Number( price ).toFixed(2);
let parts = price.toString().split('.');
price = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',') + (parts[1] ? '.' + parts[1] : '');
return price + ' ISK';
};
/**
* get localForage instance (singleton) for offline client site storage
* @returns {localforage}
*/
let getLocalStorage = function(){
if(localStorage === undefined){
localStorage = localforage.createInstance({
driver: [localforage.INDEXEDDB, localforage.WEBSQL, localforage.LOCALSTORAGE],
name: 'Pathfinder local storage'
});
}
return localStorage;
};
/**
* Create Date as UTC
* @param date
* @returns {Date}
*/
let createDateAsUTC = function(date) {
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
};
/**
* Convert Date to UTC (!important function!)
* @param date
* @returns {Date}
*/
let convertDateToUTC = function(date) {
return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
};
/**
* Convert Date to Time String
* @param date
* @returns {string}
*/
let convertDateToString = function(date){
let dateString = ('0'+ (date.getMonth() + 1 )).slice(-2) + '/' + ('0'+date.getDate()).slice(-2) + '/' + date.getFullYear();
let timeString = ('0' + date.getHours()).slice(-2) + ':' + ('0'+date.getMinutes()).slice(-2);
return dateString + ' ' + timeString;
};
/**
* get document path
* -> www.pathfinder.com/pathfinder/ -> /pathfinder
* @returns {string|string}
*/
let getDocumentPath = function(){
let pathname = window.location.pathname;
// replace file endings
let r = /[^\/]*$/;
let path = pathname.replace(r, '');
return path || '/';
};
/**
* redirect
* @param url
* @param params
*/
let redirect = function(url, params){
let currentUrl = document.URL;
if(url !== currentUrl){
if(
params &&
params.length > 0
){
url += '?' + params.join('&');
}
window.location = url;
}
};
/**
* send logout request
* @param params
*/
let logout = function(params){
let data = {};
if(
params &&
params.ajaxData
){
data = params.ajaxData;
}
$.ajax({
type: 'POST',
url: Init.path.logout,
data: data,
dataType: 'json'
}).done(function(data){
if(data.reroute){
redirect(data.reroute, ['logout']);
}
}).fail(function( jqXHR, status, error) {
let reason = status + ' ' + error;
showNotify({title: jqXHR.status + ': logout', text: reason, type: 'error'});
});
};
return {
config: config,
getVersion: getVersion,
showVersionInfo: showVersionInfo,
initPrototypes: initPrototypes,
initDefaultBootboxConfig: initDefaultBootboxConfig,
getCurrentTriggerDelay: getCurrentTriggerDelay,
getServerTime: getServerTime,
convertTimestampToServerTime: convertTimestampToServerTime,
getTimeDiffParts: getTimeDiffParts,
timeStart: timeStart,
timeStop: timeStop,
log: log,
showNotify: showNotify,
stopTabBlink: stopTabBlink,
getLogInfo: getLogInfo,
ajaxSetup: ajaxSetup,
setSyncStatus: setSyncStatus,
getSyncType: getSyncType,
isXHRAborted: isXHRAborted,
getMapModule: getMapModule,
getSystemEffectData: getSystemEffectData,
getSystemEffectTable: getSystemEffectTable,
getSystemsInfoTable: getSystemsInfoTable,
getStatusInfoForCharacter: getStatusInfoForCharacter,
getSecurityClassForSystem: getSecurityClassForSystem,
getTrueSecClassForSystem: getTrueSecClassForSystem,
getStatusInfoForSystem: getStatusInfoForSystem,
getSignatureGroupInfo: getSignatureGroupInfo,
getAllSignatureNames: getAllSignatureNames,
getSignatureTypeIdByName: getSignatureTypeIdByName,
getAreaIdBySecurity: getAreaIdBySecurity,
setCurrentMapUserData: setCurrentMapUserData,
getCurrentMapUserData: getCurrentMapUserData,
setCurrentMapData: setCurrentMapData,
getCurrentMapData: getCurrentMapData,
getCurrentMapDataIndex: getCurrentMapDataIndex,
updateCurrentMapData: updateCurrentMapData,
deleteCurrentMapData: deleteCurrentMapData,
setCurrentUserData: setCurrentUserData,
getCurrentUserData: getCurrentUserData,
setCurrentSystemData: setCurrentSystemData,
getCurrentSystemData: getCurrentSystemData,
getCurrentLocationData: getCurrentLocationData,
getCurrentUserInfo: getCurrentUserInfo,
getCurrentCharacterLog: getCurrentCharacterLog,
flattenXEditableSelectArray: flattenXEditableSelectArray,
setDestination: setDestination,
convertDateToString: convertDateToString,
getOpenDialogs: getOpenDialogs,
openIngameWindow: openIngameWindow,
formatPrice: formatPrice,
getLocalStorage: getLocalStorage,
getDocumentPath: getDocumentPath,
redirect: redirect,
logout: logout
};
});