define([ 'jquery', 'app/init', 'app/util', 'app/map/map', 'app/map/util', 'app/counter', 'app/ui/system_info', 'app/ui/system_graph', 'app/ui/system_signature', 'app/ui/system_route', 'app/ui/system_killboard', 'datatables.net', 'datatables.net-buttons', 'datatables.net-buttons-html', 'datatables.net-responsive', 'datatables.net-select' ], function($, Init, Util, Map, MapUtil) { 'use strict'; var config = { dynamicElementWrapperId: 'pf-dialog-wrapper', // parent Element for dynamic content (dialogs,..) mapTabElementId: 'pf-map-tab-element', // id for map tab element (tabs + content) mapTabBarId: 'pf-map-tabs', // id for map tab bar mapTabIdPrefix: 'pf-map-tab-', // id prefix for a map tab mapTabClass: 'pf-map-tab', // class for a map tab mapTabLinkTextClass: 'nav-tabs-link', // class for span elements in a tab mapTabIconClass: 'pf-map-tab-icon', // class for map icon mapTabSharedIconClass: 'pf-map-tab-shared-icon', // class for map shared icon mapTabContentClass: 'pf-map-tab-content', // class for tab content container mapTabContentSystemInfoClass: 'pf-map-tab-content-system', mapWrapperClass: 'pf-map-wrapper', // scrollable mapClass: 'pf-map', // class for each map // 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 // module moduleClass: 'pf-module', // class for a module moduleClosedClass: 'pf-module-closed' // class for a closed module }; var mapTabChangeBlocked = false; // flag for preventing map tab switch /** * get all maps for a maps module * @returns {*} */ $.fn.getMaps = function(){ var maps = $(this).find('.' + config.mapClass); return maps; }; /** * get the current active map for * @returns {*} */ $.fn.getActiveMap = function(){ var map = $(this).find('.active.' + config.mapTabContentClass + ' .' + config.mapClass); if(map.length === 0){ map = false; } return map; }; /** * set Tab Observer, events are triggered within map.js * @param mapContentModule */ $.fn.setTabContentObserver = function(){ return this.each(function(){ // update Tab Content with system data information $(this).on('pf:drawSystemModules', function(e){ drawSystemModules($( e.target )); }); $(this).on('pf:removeSystemModules', function(e){ removeSystemModules($( e.target )); }); }); }; /** * clear all system info modules and remove them * @param tabContentElement */ var removeSystemModules = function(tabContentElement, callback){ tabContentElement.find('.' + config.moduleClass).velocity('transition.slideDownOut', { duration: Init.animationSpeed.mapModule, complete: function(tempElement){ $(tempElement).remove(); if(callback){ callback(); } } }); }; /** * clears and updates the system info element (signature table, system info,...) * @param tabContentElement */ var drawSystemModules = function(tabContentElement){ var currentSystemData = Util.getCurrentSystemData(); // get Table cell for system Info var firstCell = $(tabContentElement).find('.' + config.mapTabContentCellFirst); var secondCell = $(tabContentElement).find('.' + config.mapTabContentCellSecond); // draw system info module firstCell.drawSystemInfoModule(currentSystemData.mapId, currentSystemData.systemData); // draw system graph module firstCell.drawSystemGraphModule(currentSystemData.systemData); // draw signature table module firstCell.drawSignatureTableModule(currentSystemData.systemData); // draw system routes module secondCell.drawSystemRouteModule(currentSystemData.mapId, currentSystemData.systemData); // draw system killboard module secondCell.drawSystemKillboardModule(currentSystemData.systemData); // set Module Observer setModuleObserver(); }; /** * set observer for each module */ var setModuleObserver = function(){ // toggle height for a module $(document).off('click.toggleModuleHeight').on('click.toggleModuleHeight', '.' + config.moduleClass, function(e){ var moduleElement = $(this); // get click position var posX = moduleElement.offset().left; var posY = moduleElement.offset().top; var clickX = e.pageX - posX; var clickY = e.pageY - posY; // check for top-left click if(clickX <= 8 && clickY <= 8){ // remember height if(! moduleElement.data('origHeight')){ moduleElement.data('origHeight', moduleElement.outerHeight()); } if(moduleElement.hasClass( config.moduleClosedClass )){ var moduleHeight = moduleElement.data('origHeight'); moduleElement.velocity('finish').velocity({ height: [ moduleHeight + 'px', [ 400, 15 ] ] },{ duration: 400, easing: 'easeInSine', complete: function(){ moduleElement.removeClass( config.moduleClosedClass ); moduleElement.removeData(); } }); }else{ moduleElement.velocity('finish').velocity({ height: [ '36px', [ 400, 15 ] ] },{ duration: 400, easing: 'easeInSine', complete: function(){ moduleElement.addClass( config.moduleClosedClass ); } }); } } }); }; /** * updates only visible/active map module * @returns {boolean} */ $.fn.updateMapModuleData = function(){ var mapModule = $(this); // get all active map elements for module var mapElement = mapModule.getActiveMap(); if(mapElement !== false){ var mapId = mapElement.data('id'); var currentMapUserData = Util.getCurrentMapUserData(mapId); // update map with current user data if(currentMapUserData){ mapElement.updateUserData(currentMapUserData); } } return true; }; /** * update system info panels (below map) * @param systemData */ $.fn.updateSystemModuleData = function(systemData){ var mapModule = $(this); if(systemData){ // check if current open system is still the requested info system var currentSystemData = Util.getCurrentSystemData(); if(currentSystemData){ if(systemData.id === currentSystemData.systemData.id){ // trigger system update event $(document).trigger('pf:updateSystemModules', [systemData]); } } } }; /** * load all structure 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-12', 'col-md-4', config.mapTabContentCellSecond, config.mapTabContentCell].join(' ') }) ); // append grid structure $(this).append(contentStructure); }); }; /** * get a fresh tab element * @param options * @returns {*|jQuery|HTMLElement} */ var getTabElement = function(options){ var tabElement = $('
', { id: config.mapTabElementId }); var tabBar = $('