define([ 'jquery', 'app/init', 'app/util', 'app/render', 'bootbox', 'app/ui/system_info', 'app/ui/system_graph', 'app/ui/system_signature', 'app/ui/system_route', 'app/ui/system_killboard', 'datatablesTableTools', 'xEditable', 'app/map/map' ], function($, Config, Util, Render, bootbox) { 'use strict'; var currentMapData = []; // current map data 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 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 * @param mapModule * @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; }; /** * get all TabElements in this map module * @returns {*} */ var getTabElements = function(){ return $('#' + config.mapTabBarId).find('a'); }; /** * 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:updateSystemData', function(e, mapData){ // collect all relevant data for SystemInfoElement var systemInfoData = { systemData: $( mapData.system).getSystemData(), mapId: parseInt( $( mapData.system).attr('data-mapid') ) }; drawSystemInfoElement($( e.target ), systemInfoData); }); $(this).on('pf:deleteSystemData', function(e, systemData){ console.log(systemData); }); }); }; /** * clears and updates the system info element (signature table, system info,...) * @param tabContentElement * @param systemInfoData */ var drawSystemInfoElement = function(tabContentElement, systemInfoData){ // get Table cell for system Info var firstCell = $(tabContentElement).find('.' + config.mapTabContentCellFirst); var secondCell = $(tabContentElement).find('.' + config.mapTabContentCellSecond); // draw system info module firstCell.drawSystemInfoModule(systemInfoData.systemData); // draw system graph module firstCell.drawSystemGraphModule(systemInfoData.systemData); // draw signature table module firstCell.drawSignatureTableModule(systemInfoData.systemData); // draw system routes module secondCell.drawSystemRouteModule(systemInfoData.systemData); // draw system killboard module secondCell.drawSystemKillboardModule(systemInfoData.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 <= 6 && clickY <= 6){ // 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: [ '40px', [ 400, 15 ] ] },{ duration: 400, easing: 'easeInSine', complete: function(){ moduleElement.addClass( config.moduleClosedClass ); } }); } } }); }; /** * updates only visible/active map module * @param userData * @returns {boolean} */ $.fn.updateMapModuleData = function(userData){ var mapModule = $(this); // get all active map elements for module var mapElement = mapModule.getActiveMap(); if(mapElement !== false){ var mapId = mapElement.data('id'); // get user data for each active map var mapUserData = null; for(var j = 0; j < userData.mapUserData.length; j++){ var tempMapUserData = userData.mapUserData[j]; if(tempMapUserData.config.id === mapId){ // map userData found mapUserData = tempMapUserData; break; } } // update map if(mapUserData){ mapElement.updateUserData(mapUserData); } } return true; }; /** * load all structure elements into a TabsContent div (tab body) */ $.fn.initContentStructure = function(){ return this.each(function(){ // init bootstrap Grid var contentStructure = $('