define(['jquery', 'app/render', 'datatables', 'xEditable', 'app/map/map', 'customScrollbar', 'app/counter'], function($, Render) { "use strict"; var config = { dynamicElementWrapperId: 'pf-dialog-wrapper', // parent Element for dynamic content (dialoges,..) mapTabBarId: 'pf-map-tabs', mapTabIdPrefix: 'pf-map-tab-', mapTabClass: 'pf-map-tab', mapTabContentClass: 'pf-map-tab-content', mapTabContentSystemInfoClass: 'pf-map-tab-content-system', mapWrapperClass: 'pf-map-wrapper', // scrollable mapClass: 'pf-map', // class for each map newMapDialogId: 'pf-map-new-dialog', // TabContentStructure mapTabContentRow: 'pf-map-content-row', // main row for Tab content (grid) mapTabContentCell: 'pf-map-content-col', // column mapTabContentCellFirst: 'pf-map-content-col-first', // first column mapTabContentCellSecond: 'pf-map-content-col-second', // second column // system info systemInfoElementWrapperClass: 'pf-system-info-wrapper', // class for systeminfo Wrapper systemInfoProgressScannedClass: 'pf-system-progress-scanned', // progress bar scanned signatures // sig table sigTableToolsClass: 'pf-sig-table-tools', // table toolbar sigTableToolsActionClass: 'pf-sig-table-tools-action', // table toolbar action sigTableClass: 'pf-sig-table', // Table class for all Signature Tables sigTableEditText: 'pf-sig-table-edit-text', // class for editable fields (text) sigTableEditSigNameInput: 'pf-sig-table-edit-name-input', // class for editable fields (input) sigTableEditSigTypeSelect: 'pf-sig-table-edit-type-select', // class for editable fields (select) sigTableEditSigNameSelect: 'pf-sig-table-edit-name-select', // class for editable fields (select) sigTableCounterClass: 'pf-sig-table-counter', // class for signature table counter // map types mapTypes: [ {type: 'default', label: 'default', class: 'pf-map-type-default'}, {type: 'global', label: 'global', class: 'pf-map-type-global'}, {type: 'alliance', label: 'alliance', class: 'pf-map-type-alliance'}, {type: 'private', label: 'private', class: 'pf-map-type-private'} ], // map scopes mapScopes: [ {scope: 'wormhole', label: 'W-Space'} ], mapIcons: [ {class: 'fa-desktop', label: 'desktop'}, {class: 'fa-bookmark', label: 'bookmark'}, {class: 'fa-cube', label: 'cube'}, {class: 'fa-warning', label: 'warning'}, {class: 'fa-plane', label: 'plane'}, {class: 'fa-rocket', label: 'rocket'} ], // Signature Type signatureTypes: { wh: { // system type 1: { // C1 (area id) 1: { // Combat 1: 'Perimeter Ambush Point', 2: 'Perimeter Camp', 3: 'Phase Catalyst Node', 4: 'The Line' }, 2: { // Relict 1: 'Forgotten Perimeter Coronation Platform' }, 3: { // Data 1: 'Unsecured Perimeter Amplifier ', 2: 'Unsecured Perimeter Information Center ' } }, 2: { // C2 1: { // Combat 1: 'Perimeter Checkpoint', 2: 'Perimeter Hangar', 3: 'The Ruins of Enclave Cohort 27', 4: 'Sleeper Data Sanctuary' }, 2: { // Relict 1: 'Forgotten Perimeter Gateway', 2: 'Forgotten Perimeter Habitation Coils' }, 3: { // Data 1: 'Unsecured Perimeter Comms Relay', 2: 'Unsecured Perimeter Transponder Farm ' } }, 3: { // C3 1: { // Combat 1: 'Fortification Frontier Stronghold', 2: 'Outpost Frontier Stronghold', 3: 'Solar Cell', 4: 'The Oruze Construct' }, 2: { // Relict 1: 'Forgotten Frontier Quarantine Outpost', 2: 'Forgotten Frontier Recursive Depot' }, 3: { // Data 1: 'Unsecured Frontier Database', 2: 'Unsecured Frontier Receiver' } }, 4: { // C4 1: { // Combat 1: 'Frontier Barracks', 2: 'Frontier Command Post', 3: 'Integrated Terminus', 4: 'Sleeper Information Sanctum' }, 2: { // Relict 1: 'Forgotten Frontier Conversion Module', 2: 'Forgotten Frontier Evacuation Center' }, 3: { // Data 1: 'Unsecured Frontier Digital Nexus', 2: 'Unsecured Frontier Trinary Hub' } }, 5: { // C5 1: { // Combat 1: 'Core Garrison', 2: 'Core Stronghold', 3: 'Oruze Osobnyk', 4: 'Quarantine Area' }, 2: { // Relict 1: 'Forgotten Core Data Field', 2: 'Forgotten Core Information Pen' }, 3: { // Data 1: 'Unsecured Frontier Enclave Relay', 2: 'Unsecured Frontier Server Bank' } }, 6: { // C6 1: { // Combat 1: 'Core Citadel', 2: 'Core Bastion', 3: 'Strange Energy Readings', 4: 'The Mirror' }, 2: { // Relict 1: 'Forgotten Core Assembly Hall', 2: 'Forgotten Core Circuitry Disassembler' }, 3: { // Data 1: 'Unsecured Core Backup Array', 2: 'Unsecured Core Emergence ' } } } } }; /** * get map type class for a type * @param type * @returns {string} */ var getMapTypeClassForType = function(type){ var typeClass= ''; $.each(config.mapTypes, function(i, typeData){ if(typeData.type === type){ typeClass = typeData.class; } }); return typeClass; }; /** * shows the add new map dialog */ var showNewMapDialog = function(){ // confirm dialog var moduleConfig = { name: 'modules/map_dialog', position: $('#' + config.dynamicElementWrapperId), link: 'after', functions: { after: function(){ $( "#" + config.newMapDialogId).dialog({ modal: true, resizable: false, buttons: { 'Cancel': function(){ $(this).dialog('close'); }, 'Add map': function(){ // get form Values var form = $('#' + config.newMapDialogId).find('form'); var newMapData = {}; $.each(form.serializeArray(), function(i, field) { newMapData[field.name] = field.value; }); saveMapData(newMapData); $(this).dialog('close'); } } }); } } }; var moduleData = { id: config.newMapDialogId, title: 'Add new map', scope: config.mapScopes, type: config.mapTypes, icon: config.mapIcons }; Render.showModule(moduleConfig, moduleData); }; var saveMapData = function(mapData){ // TODO: save map console.log(mapData); }; /** * get all maps for a maps module * @param mapModule * @returns {*} */ var getMaps = function(mapModule){ var maps = $(mapModule).find('.' + config.mapClass); return maps; }; /** * get all TabElements in this map module * @returns {*} */ var getTabElements = function(){ return $('#' + config.mapTabBarId).find('a[data-toggle="tab"]'); }; /** * get all Tabs for a maps module * @param mapModule * @returns {*} */ var getTabContentElements = function(mapContentModule){ var tabs = $(mapContentModule).find('.' + config.mapTabContentClass ); return tabs; }; /** * set Tab Observer, events are triggered within map.js * @param mapContentModule */ $.fn.setTabContenteObserver = function(){ return this.each(function(){ // update Tab Content with system data information $(this).on('pf:updateSystemData', function(e, data){ updateSystemInfoElement($( e.target )); }); // highlite a mapTab $(this).on('pf:highlightTab', function(e, data){ // update Tab Content with system data information highliteTab(e.target, data); }); }); }; /** * highlite a Tab in this module e.g. when user has an active pilot in this map * @param contentElement * @param data */ var highliteTab = function(contentElement, data){ var tabElements = getTabElements(); contentElement = $(contentElement); // look for related tab element $.each(tabElements, function(i, tabElement){ tabElement = $(tabElement); if(tabElement.attr('data-map-index') === contentElement.attr('data-map-index')){ tabElement.tooltip({placement: 'top', trigger: 'manual'}); tabElement.attr('title', ''); tabElement.tooltip('hide'); // check if this tab needs to be highlighted if(data.system){ // destroy empty tooltip end create new tabElement.tooltip('destroy'); tabElement.attr('title', $(data.system).data('name')); tabElement.tooltip('show'); // scroll to system contentElement.find('.' + config.mapWrapperClass).scrollTo( '#' + data.system.id ); } return false; } }); }; $.fn.drawSignatureTableToolbar = function(emptySignatureData){ // add toolbar buttons for table ------------------------------------- var tableToolbar = $('