', {
class: [config.moduleClass, config.sigTableModuleClass].join(' ')
});
$(this).append(moduleElement);
// set default values for all signature "datatables"
$.extend( $.fn.dataTable.defaults, {
pageLength: -1,
lengthMenu: [[5, 10, 25, 50, -1], [5, 10, 25, 50, 'All']],
autoWidth: false,
language: {
zeroRecords: 'No signatures found',
lengthMenu: 'Show _MENU_ signatures',
info: 'Showing _START_ to _END_ of _TOTAL_ signatures'
},
columnDefs: [
{
targets: 0,
//"orderData": 0,
orderable: true,
title: 'sig',
width: '30px'
},{
targets: 1,
orderable: false,
title: 'type',
width: '50px'
},{
targets: 2,
orderable: false,
title: "name/description"
},{
targets: 3,
title: 'created',
width: '90px',
className: config.sigTableCounterClass
},{
targets: 4,
title: "updated",
width: '90px',
className: config.sigTableCounterClass
},{
targets: 5,
title: '',
orderable: false,
width: '10px',
class: 'text-center'
}
]
} );
// draw signature table
moduleElement.drawSignatureTable(signatureData, systemInfoData);
// draw toolbar for signature table
moduleElement.drawSignatureTableToolbar(emptySignatureData);
}
};
/**
* update systeminfo
*/
$.fn.updateSystemInfo = function(systemInfoData){
// TODO replace by AJAX
if(systemInfoData.systemId === 30002979){
var system = {
id: 30002979,
//name: 'J150020',
name: 'Tararan',
alias: '',
effect: '',
security: 'L',
trueSec: 0.3,
region: {
id: '10000036',
name: 'Devoid'
},
constellation: {
id: '20000436',
name: 'Jayai'
},
type: 'k-space'
};
}else{
var system = {
id: 2,
name: 'J150020',
alias: 'Polaris',
effect: 'magnetar',
security: 'C6',
trueSec: -1,
region: {
id: '12345',
name: 'F-R00030'
},
constellation: {
id: '678990',
name: 'F-C00298'
},
static: [{
security: 'C6',
name: ' W237',
lifetime: 24
}],
//type: 'wh'
type: 'wh'
};
}
// create new module container
var moduleElement = $('
', {
class: [config.moduleClass, config.systemInfoModuleClass].join(' ')
});
$(this).prepend(moduleElement);
// confirm dialog
var moduleConfig = {
name: 'modules/system_info',
position: moduleElement,
link: 'append',
functions: {
after: function(){
// init tooltips
var tooltipElements = $('.' + config.systemInfoModuleClass + ' [data-toggle="tooltip"]');
tooltipElements.tooltip();
// load trade routes
if(system.type !== 'wh'){
$(moduleElement).find('.' + config.systemInfoRoutesClass).updateSystemInfoRoutes(system.name, ['Jita', 'Amarr', 'Rens', 'Dodixie']);
}
}
}
};
// add security class for statics
if(system.static){
$.each(system.static, function(i, staticWH){
system['static'][i]['class'] = Util.getSecurityClassForSystem( staticWH.security );
});
}
var moduleData = {
system: system,
securityClass: Util.getSecurityClassForSystem( system.security ),
trueSecClass: Util.getTrueSecClassForSystem( system.trueSec ),
effectName: Util.getEffectInfoForSystem(system.effect, 'name'),
effectClass: Util.getEffectInfoForSystem(system.effect, 'class')
};
Render.showModule(moduleConfig, moduleData);
};
$.fn.updateSystemInfoRoutes = function(systemFrom, systemsTo){
// TODO get cached routes from backend
var baseUrl = 'http://api.eve-central.com/api/route/from/';
var wrapperElement = $(this);
// crate new route table
var table = $('
', {
class: ['compact', 'stripe', 'order-column', 'row-border', config.systemInfoRoutesTableClass].join(' ')
});
wrapperElement.append( $(table) );
// init empty table
var routesTable = table.DataTable( {
paging: false,
ordering: true,
info: false,
searching: false,
hover: false,
//autoWidth: false,
columnDefs: [
{
targets: 0,
//"orderData": 0,
orderable: true,
title: 'system'
},{
targets: 1,
orderable: true,
title: 'jumps  ',
width: '40px',
class: 'text-right'
},{
targets: 2,
orderable: false,
title: 'route'
}
],
data: [] // will be added dynamic
} );
$.each(systemsTo, function(i, systemTo){
if(systemFrom !== systemTo){
var url = baseUrl + systemFrom + '/to/' + systemTo;
$.getJSON(url, function(routeData){
// row class
var rowClass = config.systemInfoRoutesTableRowPrefix + i;
// add row Data
var rowData = [systemTo, routeData.length];
var jumpData = [];
// loop all systems on a rout
$.each(routeData, function(j, systemData){
var systemSecClass = config.systemSecurityClassPrefix;
var systemSec = systemData.to.security.toFixed(1).toString();
systemSecClass += systemSec.replace('.', '-');
var system = '';
jumpData.push( system );
});
rowData.push( jumpData.join(' ') );
// add new row
routesTable.row.add( rowData ).draw().nodes().to$().addClass( rowClass );
// init tooltips for each jump system
var tooltipElements = wrapperElement.find('.' + rowClass + ' [data-toggle="tooltip"]');
$(tooltipElements).tooltip();
});
}
});
};
/**
* update Progressbar for all scanned signatures in a system
*/
$.fn.updateScannedSignaturesBar = function(){
var systemCell = $(this);
// get progress bar
var progressBarWrapper = $(this).find('.' + config.systemInfoProgressScannedClass);
var progressBar = $(progressBarWrapper).find('.progress-bar');
var progressBarLabel = $(progressBarWrapper).find('.progress-label-right');
var tableData = systemCell.getSignatureTableData();
var percent = 0;
var progressBarType = 'progress-bar-danger';
if(tableData){
var sigCount = tableData.length;
var sigIncompleteCount = 0;
// check for signatures without "type" -> these are unscanned sigs
$.each(tableData, function(i, data){
var typeId = parseInt(data.typeId);
if(typeId === 0){
sigIncompleteCount++;
}
});
percent = 100 - Math.round( 100 / sigCount * sigIncompleteCount );
if(percent < 30){
progressBarType = 'progress-bar-danger' ;
}else if(percent < 100){
progressBarType = 'progress-bar-warning';
}else{
progressBarType = 'progress-bar-success';
}
}
setTimeout(
function() {
progressBarLabel.text(percent + '%');
progressBar.removeClass().addClass('progress-bar').addClass(progressBarType);
progressBar.attr('aria-valuenow', percent);
progressBar.css({width: percent + '%'});
}, 100);
};
/**
* make a table editable (in-line-editor)
* @param systemInfoData
*/
$.fn.makeEditable = function(systemInfoData){
var table = $(this);
// default x-editable options for each field
//$.fn.editable.defaults.url = '/post';
$.fn.editable.defaults.ajaxOptions = {
type: 'post',
dataType: 'json'
};
// find editable fields
var sigIdFields = table.find('.' + config.sigTableEditSigNameInput);
var sigTypeFields = table.find('.' + config.sigTableEditSigTypeSelect);
var sigNameFields = table.find('.' + config.sigTableEditSigNameSelect);
// jump to "next" editable field on save
var openNextEditDialogOnSave = function(fields, updateProgressBar){
fields.on('save', {test: 1}, function(e, data){
var that = this;
setTimeout(function() {
var nextField = getNextEditableField(that);
$(nextField).editable('show');
// update scanning progressbar if sig "type" has changed
if($(e.target).hasClass(config.sigTableEditSigTypeSelect)){
$(that).parents('.' + config.moduleClass).updateScannedSignaturesBar();
}
}, 200);
});
};
// get the next editable field
var getNextEditableField = function(field){
return $(field).closest('td').next().find('.editable');
};
/**
* add map/system specific data for each editable field in the sig-table
* @param params
* @returns {*}
*/
var modifyFieldParamsOnSend = function(params){
params.systemId = systemInfoData.systemId;
params.mapId = systemInfoData.mapId;
return params;
};
// sigTableEditSigNameInput
sigIdFields.editable({
mode: 'popup',
type: 'text',
title: 'signature id',
name: 'name',
emptytext: '? ? ?',
validate: function(value) {
if($.trim(value) === '') {
return 'Signature id cant be empty';
}
},
params: modifyFieldParamsOnSend
});
// cache sige types -----------------------------------------------------
var sigTypeCache = {};
// Select sig type (master)
sigTypeFields.editable({
mode: 'popup',
type: 'select',
title: 'signature type',
name: 'typeId',
emptytext: 'unknown',
params: modifyFieldParamsOnSend,
source: function(){
var systemType = $(this).attr('data-systemtype');
var areaId = $(this).attr('data-areaid');
var cacheKey = [systemType, areaId].join('_');
// check for cached signature names
if(sigTypeCache.hasOwnProperty( cacheKey )){
return sigTypeCache[cacheKey];
}
var availableTypes = {};
// get all available Signature Types
if(
config.signatureTypes[systemType] &&
config.signatureTypes[systemType][areaId]
){
// json object -> "translate" keys to names
var tempTypes = config.signatureTypes[systemType][areaId];
for (var prop in tempTypes) {
if(tempTypes.hasOwnProperty(prop)){
prop = parseInt(prop);
switch(prop){
case 1:
availableTypes[prop] = 'Combat';
break;
case 2:
availableTypes[prop] = 'Relict';
break;
case 3:
availableTypes[prop] = 'Data';
break;
case 4:
availableTypes[prop] = 'Gas';
break;
}
}
}
// add empty option
availableTypes[0] = '';
availableTypes = sigTypeCache[cacheKey] = availableTypes;
}
return availableTypes;
},
success: function(response, newValue){
// find related "name" select (same row) and change options
var nameSelect = getNextEditableField(this);
var systemType = $(this).attr('data-systemtype');
var areaId = $(this).attr('data-areaid');
// set new Options
var newSelectOptions = getSignatureNames(systemType, areaId, newValue);
$(nameSelect).editable('option', 'source', newSelectOptions);
$(nameSelect).editable('setValue', null);
if(newValue > 0){
$(nameSelect).editable('option', 'disabled', false);
}else{
$(nameSelect).editable('option', 'disabled', true);
}
}
});
// cache sig names -----------------------------------------------------------
var sigNameCache = {};
// Select sig name (slave: depends on sig type)
sigNameFields.editable({
mode: 'popup',
type: 'select',
title: 'signature name',
name: 'sigTypeId',
emptytext: 'unknown',
params: modifyFieldParamsOnSend,
source: function(){
var systemType = $(this).attr('data-systemtype');
var areaId = $(this).attr('data-areaid');
var typeId = $(this).attr('data-typeid');
var cacheKey = [systemType, areaId, typeId].join('_');
// check for cached signature names
if(sigNameCache.hasOwnProperty( cacheKey )){
return sigNameCache[cacheKey];
}
var signatureNames = getSignatureNames(systemType, areaId, typeId);
// add empty option
signatureNames[0] = '';
// get all available Signature Names
var availableSigs = sigNameCache[cacheKey] = signatureNames;
return availableSigs;
}
});
// open next field dialog
openNextEditDialogOnSave(sigIdFields, true);
openNextEditDialogOnSave(sigTypeFields, false);
// set button observer (delete sig)
$(this).find('.btn-danger').on('click', function(e){
e.preventDefault();
bootbox.confirm('Delete signature?', function(result) {
if(result){
// get module
var moduleElement = $(e.target).parents('.' + config.moduleClass);
// get clicked dataTable object
var currentTable = moduleElement.find('.' + config.sigTableMainClass);
currentTable = $(currentTable).dataTable();
// delete signature row
currentTable.fnDeleteRow($(e.target).parents('tr'));
// update signature bar
moduleElement.updateScannedSignaturesBar();
}
});
});
// init signature counter
$(this).find('.' + config.sigTableCounterClass).initSignatureCounter();
};
/**
* get Signature names out of global
* @param systemType
* @param areaId
* @param sigType
* @returns {{}}
*/
var getSignatureNames = function(systemType, areaId, sigType){
var signatureNames = {};
if(
config.signatureTypes[systemType] &&
config.signatureTypes[systemType][areaId] &&
config.signatureTypes[systemType][areaId][sigType]
){
signatureNames = config.signatureTypes[systemType][areaId][sigType];
}
return signatureNames;
};
/**
* get Area ID by security string
* k-space not implemented jet
* @param security
* @returns {*}
*/
var getAreaIdBySecurity = function(security){
var areaId = null;
switch(security){
case 'C1':
areaId = 1;
break;
case 'C2':
areaId = 2;
break;
case 'C3':
areaId = 3;
break;
case 'C4':
areaId = 4;
break;
case 'C5':
areaId = 5;
break;
case 'C6':
areaId = 6;
break;
}
return areaId;
};
/**
* formats all signature data for table
* @param systemData
* @returns {Array}
*/
var formatSignatureData = function(systemData, options){
var formattedData = [];
if(
systemData &&
systemData.config &&
systemData.config.id &&
systemData.config.type === 'wh'
){
// system data "should" be valid :)
var systemSecurity = systemData.config.security;
var systemType = systemData.config.type;
var areaId = getAreaIdBySecurity(systemSecurity);
// areaId is required as a key for signature names
if(areaId){
$.each(systemData.signatures, function(i, data){
var tempData = [];
// set signature name
var sigName = ' 0){
sigName += 'data-pk="' + data.id + '" ';
}
sigName += '>' + data.name + '';
tempData.push(sigName);
var sigType = ' 0){
sigType += 'data-pk="' + data.id + '" ';
}
sigType += 'data-systemType="' + systemType + '" ';
sigType += 'data-areaId="' + areaId + '" ';
sigType += 'data-value="' + data.typeId + '" ';
sigType += '>';
// set Sig Id
tempData.push( sigType );
var sigElement = ' 0){
sigElement += 'data-pk="' + data.id + '" ';
}
// set disabled if sig type is not selected
if(data.typeId < 1){
sigElement += 'data-disabled="1" ';
}
sigElement += 'data-systemType="' + systemType + '" ';
sigElement += 'data-areaId="' + areaId + '" ';
sigElement += 'data-typeId="' + data.typeId + '" ';
sigElement += 'data-value="' + data.sigTypeId + '" ';
sigElement += '>';
// set Sig Id
tempData.push( sigElement );
// set Sig created
tempData.push( data.created );
// set Sig updated
tempData.push( data.updated );
// action icon
var actionButtonClass = 'btn-danger';
var actionButtonIcon = 'fa-minus';
if(options.action){
actionButtonClass = options.action.buttonClass;
actionButtonIcon = options.action.buttonIcon;
}
var deleteButton = '';
deleteButton += '';
deleteButton += '';
tempData.push( deleteButton );
formattedData.push(tempData);
});
}
}
return formattedData;
};
/**
* TODO delete function !!!!!!!
*/
var tempFunctionGetSystemData = function(){
var data = {
config: {
id: 2,
name: 'J150020',
alias: 'Polaris',
effect: 'magnetar',
security: 'C6',
static: [{
lifetime: 24
}],
type: 'wh'
},
signatures: [
{
id: 2,
name: 'GDF',
typeId: 1,
sigTypeId: 2,
created: 1325376000,
updated: 1415215936
},{
id: 6,
name: 'HFS',
typeId: 0,
sigTypeId: 1,
created: 1415989953,
updated: 1415215936
},{
id: 8,
name: 'HFG',
typeId: 1,
sigTypeId: 1,
created: 1415215936,
updated: 1415215936
},{
id: 12,
name: 'LLD',
typeId: 1,
sigTypeId: 1,
created: 1415215936,
updated: 1415215936
},{
id: 13,
name: 'DGE',
typeId: 1,
sigTypeId: 1,
created: 1394613252,
updated: 1415215936
},{
id: 14,
name: 'EXS',
typeId: 1,
sigTypeId: 1,
created: 1415215936,
updated: 1415215936
},{
id: 15,
name: 'CVS',
typeId: 3,
sigTypeId: 1,
created: 1415215936,
updated: 1386934983
},{
id: 16,
name: 'GGD',
typeId: 0,
sigTypeId: 0,
created: 1415215936,
updated: 1415215936
},{
id: 18,
name: 'OKD',
typeId: 1,
sigTypeId: 1,
created: 1415215936,
updated: 1394613252
},{
id: 8,
name: 'DBE',
typeId: 3,
sigTypeId: 1,
created: 1415215936,
updated: 1415215936
},{
id: 20,
name: 'ASW',
typeId: 0,
sigTypeId: 3,
created: 1415215936,
updated: 1386934983
},{
id: 22,
name: 'NFG',
typeId: 2,
sigTypeId: 2,
created: 1415215936,
updated: 1415215936
}
]
};
return data;
};
/**
* updates complete map module (all maps)
* @param userData
*/
$.fn.updateMapModule = function(userData){
// get all active map elements for module
var mapElements = getMaps(this);
var currentUserData = null;
// current user data
if(userData.currentUserData){
currentUserData = userData.currentUserData;
}
// get map Data
$.each(mapElements, function(i, mapElement){
var mapId = parseInt( $(mapElement).attr('data-mapid') );
var mapUserData = null;
// get user data for each active map
$.each(userData.mapUserData, function(j, tempMapData){
if(tempMapData.config.id === mapId){
// map userdata found
mapUserData = tempMapData;
}
});
// update map
if(mapUserData){
$(mapElement).updateUserData(mapUserData, currentUserData);
}
});
};
/**
* load all structrure elements into a TabsContent div (tab body)
*/
$.fn.initContentStructure = function(){
return this.each(function(){
// init bootstrap Grid
var contentStructure = $('', {
class: ['row', config.mapTabContentRow].join(' ')
}).append(
$('
', {
class: ['col-xs-12', 'col-md-8', config.mapTabContentCellFirst, config.mapTabContentCell].join(' ')
})
).append(
$('
', {
class: ['col-xs-6', 'col-md-4', config.mapTabContentCellSecond, config.mapTabContentCell].join(' ')
})
);
// append grid structure
$(this).append(contentStructure);
});
};
/**
* load map module into element (all maps)
* @param mapData
*/
$.fn.loadMapModule = function(mapData){
var moduleConfig = {
name: 'modules/tabs',
position: $(this),
link: 'prepend',
functions: {
after: function(){
// this new created module
var mapContentModule = $("div[data-map-tabs='" + config.mapTabBarId + "']");
// load first map i in first tab content container
var tabContentElements = getTabContentElements(mapContentModule);
// set observer for manually triggered map events
tabContentElements.setTabContentObserver();
// load all the structure elements for ALL Tab Content Body
tabContentElements.initContentStructure();
// load first map i in first tab content container
$( tabContentElements[0] ).initMap(mapData[0]);
// check for "new map" action before tap-change
getTabElements().on('show.bs.tab', function (e) {
var mapIndex = parseInt( $(e.target).attr('data-map-index') );
if(mapIndex === -1){
// add new Tab selected
showNewMapDialog();
e.preventDefault();
}
});
// load new map right after tab-change
getTabElements().on('shown.bs.tab', function (e) {
var mapIndex = parseInt( $(e.target).attr('data-map-index') );
var mapId = mapData[mapIndex].config.id;
var currentTabContentElement = $('#' + config.mapTabIdPrefix + mapId);
$( currentTabContentElement).initMap( mapData[mapIndex]);
});
}
}
};
var moduleData = {
id: config.mapTabBarId,
tabs: []
};
// add new tab data for each map
$.each(mapData, function(i, data){
var active = false;
if(i === 0){
active = true;
}
moduleData.tabs.push({
id: data.config.id,
index: i,
name: data.config.name,
icon: data.config.icon,
tabClass: [config.mapTabClass, getMapTypeClassForType( data.config.type) ].join(' '),
contentClass: config.mapTabContentClass,
active: active
});
});
// add new tab
moduleData.tabs.push({
id: 0,
index: -1,
name: 'add',
icon: 'fa-plus',
tabClass: [config.mapTabClass, getMapTypeClassForType('default')].join(' '),
contentClass: config.mapTabContentClass,
pullRight: true
});
Render.showModule(moduleConfig, moduleData);
};
/**
* init map, load into a container and init custom scrollbar
* @param container
* @param mapData
*/
$.fn.initMap = function(mapData){
return this.each(function(){
$(this).loadMap(mapData);
// init custom scrollbars
$(this).initMapScrollbar();
});
};
/**
* init scrollbar for Map element
*/
$.fn.initMapScrollbar = function(){
// get Map Scrollbar
var scrollableElement = $(this).find('.' + config.mapWrapperClass);
initCutomScrollbar( scrollableElement );
};
/**
* init a custom scrollbar
* @param scrollableElement
*/
var initCutomScrollbar = function( scrollableElement ){
// init custom scrollbars
$(scrollableElement).mCustomScrollbar({
axis:"x",
theme:"light-thick",
scrollButtons:{
enable:true
}
});
};
/**
* scroll to a specific position in the map
* @returns {*} // string or id
*/
$.fn.scrollTo = function(position){
return this.each(function(){
// todo re-comment
//$(this).mCustomScrollbar('scrollTo', position);
});
};
});