rowElement
+ * @param rowElement
*/
- let unlockSignatureTable = instant =>{
- if(disableTableUpdate === true){
- if(instant === true){
- disableTableUpdate = false;
+ let toggleTableRow = rowElement => {
+
+ let toggleTableRowExecutor = (resolve, reject) => {
+ let cellElements = rowElement.children('td');
+ let duration = 350;
+ // wrap each into a container (for better animation performance)
+ // slideUp new wrapper divs
+ if(rowElement.is(':visible')){
+ // hide row
+
+ // stop sig counter by adding a stopClass to each | , remove padding
+ cellElements.addClass('stopCounter')
+ .velocity({
+ paddingTop: [0, '4px'],
+ paddingBottom: [0, '4px'],
+ opacity: [0, 1]
+ },{
+ duration: duration,
+ easing: 'linear'
+ }).wrapInner('')
+ .children()
+ .css({
+ 'willChange': 'height'
+ }).velocity('slideUp', {
+ duration: duration,
+ easing: 'linear',
+ complete: function(animationElements){
+ // remove wrapper
+ $(animationElements).children().unwrap();
+
+ resolve({
+ action: 'rowHidden',
+ row: rowElement
+ });
+ }
+ });
}else{
- // wait until add/remove animations are finished before enable table for auto update again
- setTimeout(function(){ disableTableUpdate = false; }, 2000);
+ // show row
+
+ // remove padding on "hidden" cells for smother animation
+ cellElements.css({
+ 'padding-top': 0,
+ 'padding-bottom': 0,
+ 'willChange': 'padding-top, padding-top, height'
+ });
+
+ // add hidden wrapper for ea
+ cellElements.wrapInner($(' ').hide());
+
+ // show row for padding animation
+ rowElement.show();
+
+ cellElements.velocity({
+ paddingTop: ['4px', 0],
+ paddingBottom: ['4px', 0]
+ },{
+ duration: duration,
+ queue: false,
+ complete: function(){
+ // animate wrapper
+ cellElements.children()
+ .css({
+ 'willChange': 'height'
+ }).velocity('slideDown', {
+ duration: duration,
+ complete: function(animationElements){
+ // remove wrapper
+ for(let i = 0; i < animationElements.length; i++){
+ let currentWrapper = $(animationElements[i]);
+ if(currentWrapper.children().length > 0){
+ currentWrapper.children().unwrap();
+ }else{
+ currentWrapper.parent().html( currentWrapper.html() );
+ }
+ }
+
+ resolve({
+ action: 'rowShown',
+ row: rowElement
+ });
+ }
+ });
+ }
+ });
}
- }
+ };
+
+ return new Promise(toggleTableRowExecutor);
};
/**
- * update Progressbar for all scanned signatures in a system
+ * update scanned signatures progress bar
+ * @param tableApi
* @param options
*/
- $.fn.updateScannedSignaturesBar = function(options){
- let moduleElement = $(this);
- let signatureTableApi = getDataTableInstanceByModuleElement(moduleElement, 'primary');
-
- // get progress bar
- let progressBarWrapper = moduleElement.find('.' + config.signatureScannedProgressBarClass);
- let progressBar = $(progressBarWrapper).find('.progress-bar');
+ let updateScannedSignaturesBar = (tableApi, options) => {
+ let tableElement = tableApi.table().node();
+ let moduleElement = $(tableElement).parents('.' + config.moduleTypeClass);
+ let progressBar = moduleElement.find('.progress-bar');
let progressBarLabel = moduleElement.find('.progress-label-right');
- let tableData = getTableData(signatureTableApi);
-
- let sigCount = 0;
let percent = 0;
- let sigIncompleteCount = 0;
- let progressBarType = 'progress-bar-danger';
+ let progressBarType = '';
+ let columnGroupData = tableApi.column('group:name').data();
+ let sigCount = columnGroupData.length;
+ let sigIncompleteCount = columnGroupData.filter((value, index) => !value).length;
- if(tableData){
- sigCount = tableData.length;
+ if(sigCount){
+ percent = 100 - Math.round( 100 / sigCount * sigIncompleteCount );
+ }
- // check for signatures without "groupId" -> these are un scanned signatures
+ if(percent < 30){
+ progressBarType = 'progress-bar-danger' ;
+ }else if(percent < 100){
+ progressBarType = 'progress-bar-warning';
+ }else{
+ progressBarType = 'progress-bar-success';
+ }
- for(let i = 0; i < tableData.length; i++){
- let groupId = parseInt(tableData[i].groupId);
- if(groupId === 0){
- sigIncompleteCount++;
- }
- }
+ progressBarLabel.text(percent + '%');
+ progressBar.removeClass().addClass('progress-bar').addClass(progressBarType);
+ progressBar.attr('aria-valuenow', percent);
+ progressBar.css({width: percent + '%'});
- if(sigCount > 0){
- percent = 100 - Math.round( 100 / sigCount * sigIncompleteCount );
- }
+ // show notifications
+ if(options.showNotice !== false){
+ let notification = (sigCount - sigIncompleteCount) + ' / ' + sigCount + ' (' + percent + '%) signatures scanned';
- if(percent < 30){
- progressBarType = 'progress-bar-danger' ;
- }else if(percent < 100){
- progressBarType = 'progress-bar-warning';
+ if(percent < 100){
+ Util.showNotify({title: 'Unscanned signatures', text: notification, type: 'info'});
}else{
- progressBarType = 'progress-bar-success';
+ Util.showNotify({title: 'System is scanned', text: notification, type: 'success'});
}
}
-
- setTimeout(
- function() {
- progressBarLabel.text(percent + '%');
- progressBar.removeClass().addClass('progress-bar').addClass(progressBarType);
- progressBar.attr('aria-valuenow', percent);
- progressBar.css({width: percent + '%'});
-
- let notification = (sigCount - sigIncompleteCount) + ' / ' + sigCount + ' (' + percent + '%) signatures scanned';
-
- // show notifications
- if(options.showNotice !== false){
- if(percent < 100){
- Util.showNotify({title: 'Unscanned signatures', text: notification, type: 'info'});
- }else{
- Util.showNotify({title: 'System is scanned', text: notification, type: 'success'});
- }
- }
- }, 100);
};
/**
@@ -573,20 +607,20 @@ define([
success: {
label: ' update signatures',
className: 'btn-success',
- callback: function () {
+ callback: function (){
let form = this.find('form');
let formData = form.getFormValues();
let signatureOptions = {
deleteOld: (formData.deleteOld) ? 1 : 0
};
- moduleElement.updateSignatureTableByClipboard(systemData, formData.clipboard, signatureOptions);
+ updateSignatureTableByClipboard(moduleElement, systemData, formData.clipboard, signatureOptions);
}
}
}
});
// dialog shown event
- signatureReaderDialog.on('shown.bs.modal', function(e) {
+ signatureReaderDialog.on('shown.bs.modal', function(e){
signatureReaderDialog.initTooltips();
// set focus on sig-input textarea
@@ -595,85 +629,6 @@ define([
});
};
- /**
- * updates the signature table with all signatures pasted into the "signature reader" dialog
- * -> Hint: copy&paste signature data (without any open dialog) will add signatures as well
- * @param systemData
- * @param clipboard data stream
- * @param options
- */
- $.fn.updateSignatureTableByClipboard = function(systemData, clipboard, options){
- let moduleElement = $(this);
-
- let saveSignatureData = function(signatureData){
- // lock update function until request is finished
- lockSignatureTable();
-
- // lock copy during request (prevent spamming (ctrl + c )
- disableCopyFromClipboard = true;
-
- let requestData = {
- signatures: signatureData,
- deleteOld: (options.deleteOld) ? 1 : 0,
- systemId: parseInt(systemData.id)
- };
-
- $.ajax({
- type: 'POST',
- url: Init.path.saveSignatureData,
- data: requestData,
- dataType: 'json',
- context: {
- moduleElement: moduleElement
- }
- }).done(function(responseData){
- // unlock table for update
- unlockSignatureTable(true);
- // updates table with new/updated signature information
- updateSignatureTable(this.moduleElement, responseData.signatures, false);
- }).fail(function( jqXHR, status, error) {
- let reason = status + ' ' + error;
- Util.showNotify({title: jqXHR.status + ': Update signatures', text: reason, type: 'warning'});
- $(document).setProgramStatus('problem');
- }).always(function() {
- unlockSignatureTable(true);
- disableCopyFromClipboard = false;
- });
- };
-
- // check if copy&paste is enabled
- if( !disableCopyFromClipboard ){
- // parse input stream
- let signatureData = parseSignatureString(systemData, clipboard);
- if(signatureData.length > 0){
- // valid signature data parsed
-
- // check if signatures will be added to a system where character is currently in
- // if user is not in any system -> id === undefined -> no "confirmation required
- let currentLocationData = Util.getCurrentLocationData();
- if(
- currentLocationData.id &&
- currentLocationData.id !== systemData.id
- ){
-
- let systemNameStr = (systemData.name === systemData.alias) ? '"' + systemData.name + '"' : '"' + systemData.alias + '" (' + systemData.name + ')';
- systemNameStr = '' + systemNameStr + '';
-
- let msg = '';
- msg += 'Update signatures in ' + systemNameStr + ' ? This not your current location, "' + currentLocationData.name + '" !';
- bootbox.confirm(msg, function(result) {
- if(result){
- saveSignatureData(signatureData);
- }
- });
- }else{
- // current system selected -> no "confirmation" required
- saveSignatureData(signatureData);
- }
- }
- }
- };
-
/**
* parses a copy&paste string from ingame scanning window
* @param systemData
@@ -700,20 +655,18 @@ define([
let typeId = 0;
// get groupId by groupName
- for (let prop in signatureGroupOptions) {
- if(signatureGroupOptions.hasOwnProperty(prop)){
- let reg = new RegExp(signatureGroupOptions[prop], 'i');
- if (reg.test(sigGroup)) {
- sigGroupId = parseInt( prop );
- break;
- }
+ for(let groupOption of signatureGroupOptions){
+ let reg = new RegExp(groupOption.text, 'i');
+ if(reg.test(sigGroup)){
+ sigGroupId = groupOption.value;
+ break;
}
}
// wormhole type cant be extracted from signature string -> skip function call
if(sigGroupId !== 5){
// try to get "typeId" by description string
- typeId = Util.getSignatureTypeIdByName( systemData, sigGroupId, sigDescription );
+ typeId = Util.getSignatureTypeIdByName(systemData, sigGroupId, sigDescription);
// set signature name as "description" if signature matching failed
sigDescription = (typeId === 0) ? sigDescription : '';
@@ -747,1123 +700,1176 @@ define([
};
/**
- * format signature data array into dataTable structure
+ * updates the signature table with all signatures pasted into the "signature reader" dialog
+ * -> Hint: copy&paste signature data (without any open dialog) will add signatures as well
+ * @param tableApi
* @param systemData
- * @param signatureData
+ * @param clipboard data stream
* @param options
- * @returns {Array}
*/
- let formatSignatureData = (systemData, signatureData, options) => {
- let formattedData = [];
-
- // security check
- if(
- systemData &&
- systemData.id &&
- systemData.id > 0
- ){
- let systemTypeId = systemData.type.id;
-
- // areaId is required as a key for signature names
- // if areaId is 0, no signature data is available for this system
- let areaId = Util.getAreaIdBySecurity(systemData.security);
-
- for(let i = 0; i < signatureData.length; i++){
- let data = signatureData[i];
-
- let tempData = {};
-
- // set id ---------------------------------------------------------------------------------------------
- let sigId = 0;
- if(data.id > 0){
- sigId = data.id;
- }
- tempData.id = sigId;
-
- // set status -----------------------------------------------------------------------------------------
- let statusClass = '';
- if(data.updated.character !== undefined){
- statusClass = Util.getStatusInfoForCharacter(data.updated.character, 'class');
- }
- let status = '';
-
- tempData.status = {
- status: status,
- status_sort: statusClass
- };
-
- // set name -------------------------------------------------------------------------------------------
- let sigName = ' 0){
- sigName += 'data-pk="' + data.id + '" ';
- }
- sigName += '>' + data.name + '';
+ let updateSignatureTableByClipboard = (tableApi, systemData, clipboard, options) => {
+ if(isLockedTable(tableApi, 'clipboard')) return;
- tempData.name = {
- render: sigName,
- name: data.name
- };
+ let saveSignatureData = signatureData => {
+ // lock update function until request is finished
+ lockTable(tableApi);
- // set group id ---------------------------------------------------------------------------------------
- let sigGroup = ' 0){
- sigGroup += 'data-pk="' + data.id + '" ';
- }
- sigGroup += 'data-systemTypeId="' + systemTypeId + '" ';
- sigGroup += 'data-areaId="' + areaId + '" ';
- sigGroup += 'data-value="' + data.groupId + '" ';
- sigGroup += '>';
-
- tempData.group = {
- group: sigGroup,
- sort: config.signatureGroupsLabels[data.groupId] || '',
- filter: config.signatureGroupsLabels[data.groupId] ||''
- };
+ // lock copy during request (prevent spamming (ctrl + c )
+ lockTable(tableApi, 'clipboard');
- // set type id ----------------------------------------------------------------------------------------
- let sigType = ' 0){
- sigType += 'data-pk="' + data.id + '" ';
- }
+ let requestData = {
+ signatures: signatureData,
+ deleteOld: (options.deleteOld) ? 1 : 0,
+ systemId: parseInt(systemData.id)
+ };
- // set disabled if sig type is not selected
- if(data.groupId < 1){
- sigType += 'data-disabled="1" ';
+ $.ajax({
+ type: 'POST',
+ url: Init.path.saveSignatureData,
+ data: requestData,
+ dataType: 'json',
+ context: {
+ tableApi: tableApi
}
+ }).done(function(responseData){
+ // unlock table for update
+ unlockTable(this.tableApi);
+ // updates table with new/updated signature information
+ updateSignatureTable(this.tableApi, responseData.signatures, false);
+ }).fail(function( jqXHR, status, error){
+ let reason = status + ' ' + error;
+ Util.showNotify({title: jqXHR.status + ': Update signatures', text: reason, type: 'warning'});
+ $(document).setProgramStatus('problem');
+ }).always(function(){
+ unlockTable(this.tableApi);
+ unlockTable(this.tableApi, 'clipboard');
+ });
+ };
- sigType += 'data-systemTypeId="' + systemTypeId + '" ';
- sigType += 'data-areaId="' + areaId + '" ';
- sigType += 'data-groupId="' + data.groupId + '" ';
- sigType += 'data-value="' + data.typeId + '" ';
- sigType += '>';
-
- tempData.type = sigType;
+ // parse input stream
+ let signatureData = parseSignatureString(systemData, clipboard);
+ if(signatureData.length > 0){
+ // valid signature data parsed
+
+ // check if signatures will be added to a system where character is currently in
+ // if user is not in any system -> id === undefined -> no "confirmation required
+ let currentLocationData = Util.getCurrentLocationData();
+ if(
+ currentLocationData.id &&
+ currentLocationData.id !== systemData.id
+ ){
+
+ let systemNameStr = (systemData.name === systemData.alias) ? '"' + systemData.name + '"' : '"' + systemData.alias + '" (' + systemData.name + ')';
+ systemNameStr = '' + systemNameStr + '';
+
+ let msg = 'Update signatures in ' + systemNameStr + ' ? This not your current location, "' + currentLocationData.name + '" !';
+ bootbox.confirm(msg, function(result){
+ if(result){
+ saveSignatureData(signatureData);
+ }
+ });
+ }else{
+ // current system selected -> no "confirmation" required
+ saveSignatureData(signatureData);
+ }
+ }
+ };
- // set connection (to target system) ------------------------------------------------------------------
- let sigConnection = ' 0){
- sigConnection += 'data-pk="' + data.id + '" ';
- }
+ /**
+ * deletes signature rows from signature table
+ * @param tableApi
+ * @param rows
+ */
+ let deleteSignatures = (tableApi, rows) => {
+ // get unique id array from rows -> in case there are 2 rows with same id -> you never know
+ let signatureIds = [...new Set(rows.data().toArray().map(rowData => rowData.id))];
- // set disabled if group is not wormhole
- if(data.groupId !== 5){
- sigConnection += 'data-disabled="1" ';
- }
+ let requestData = {
+ signatureIds: signatureIds
+ };
- if(data.connection){
- sigConnection += 'data-value="' + data.connection.id + '" ';
- }
- sigConnection += '>';
+ $.ajax({
+ type: 'POST',
+ url: Init.path.deleteSignatureData,
+ data: requestData,
+ dataType: 'json',
+ context: {
+ tableApi: tableApi
+ }
+ }).done(function(responseData){
+ // promises for all delete rows
+ let promisesToggleRow = [];
+ // get deleted rows -> match with response data
+ let rows = this.tableApi.rows((idx, rowData, node) => responseData.deletedSignatureIds.includes(rowData.id));
+ // toggle hide animation for rows one by one...
+ rows.every(function(rowIdx, tableLoop, rowLoop){
+ let row = this;
+ let rowElement = row.nodes().to$();
- tempData.connection = {
- render: sigConnection,
- connection: data.connection
- };
+ rowElement.pulseBackgroundColor('deleted');
- // set description ------------------------------------------------------------------------------------
- let sigDescription = ' 0){
- sigDescription += 'data-pk="' + data.id + '" ';
- }
- sigDescription += '>' + data.description + '';
+ promisesToggleRow.push(toggleTableRow(rowElement));
+ });
- tempData.description = sigDescription;
+ // ... all hide animations done ...
+ Promise.all(promisesToggleRow).then(payloads => {
+ // ... get deleted (hide animation done) and delete them
+ this.tableApi.rows(payloads.map(payload => payload.row)).remove().draw();
- // set created ----------------------------------------------------------------------------------------
- tempData.created = data.created;
+ // update signature bar
+ updateScannedSignaturesBar(this.tableApi, {showNotice: false});
- // set updated ----------------------------------------------------------------------------------------
- tempData.updated = data.updated;
+ // update connection conflicts
+ checkConnectionConflicts();
- // info icon ------------------------------------------------------------------------------------------
- let infoButton = '';
- if(data.id > 0){
- infoButton = '';
+ let notificationOptions = {
+ type: 'success'
+ };
+ if(payloads.length === 1){
+ notificationOptions.title = 'Signature deleted';
+ }else{
+ notificationOptions.title = payloads.length + ' Signatures deleted ';
}
- tempData.info = infoButton;
+ Util.showNotify(notificationOptions);
+ });
+ }).fail(function( jqXHR, status, error){
+ let reason = status + ' ' + error;
+ Util.showNotify({title: jqXHR.status + ': Delete signature', text: reason, type: 'warning'});
+ $(document).setProgramStatus('problem');
+ });
+ };
- // action icon ----------------------------------------------------------------------------------------
+ /**
+ * updates a single cell with new data (e.g. "updated" cell)
+ * @param tableApi
+ * @param rowIndex
+ * @param columnSelector
+ * @param data
+ */
+ let updateSignatureCell = (tableApi, rowIndex, columnSelector, data) => {
+ tableApi.cell(rowIndex, columnSelector).data(data);
+ };
- let actionButton = '';
- tempData.action = {
- action: options.action,
- button: actionButton
- };
+ /**
+ * check connectionIds for conflicts (multiple signatures -> same connection)
+ * -> show "conflict" icon next to select
+ */
+ let checkConnectionConflicts = () => {
+ setTimeout(() => {
+ let connectionSelects = $('.' + config.tableCellConnectionClass + '.editable');
+ let connectionIds = [];
+ let duplicateConnectionIds = [];
+ let groupedSelects = [];
- formattedData.push(tempData);
+ connectionSelects.each(function(){
+ let select = $(this);
+ let value = parseInt(select.editable('getValue', true) )|| 0;
- }
+ if(
+ connectionIds.indexOf(value) > -1 &&
+ duplicateConnectionIds.indexOf(value) === -1
+ ){
+ // duplicate found
+ duplicateConnectionIds.push(value);
+ }
- }
+ if(groupedSelects[value] !== undefined){
+ groupedSelects[value].push(select[0]);
+ }else{
+ groupedSelects[value] = [select[0]];
+ }
+
+ connectionIds.push(value);
+ });
- return formattedData;
+ // update "conflict" icon next to select label for connectionIds
+ connectionSelects.each(function(){
+ let select = $(this);
+ let value = parseInt(select.editable('getValue', true) )|| 0;
+ let conflictIcon = select.find('.fa-exclamation-triangle');
+ if(
+ duplicateConnectionIds.indexOf(value) > -1 &&
+ groupedSelects[value].indexOf(select[0]) > -1
+ ){
+ conflictIcon.removeClass('hide');
+ }else{
+ conflictIcon.addClass('hide');
+ }
+ });
+ }, 200);
};
/**
- * get all rows of a table
- * @param tableApi
- * @returns {*}
+ * get group label by groupId
+ * @param groupId
+ * @returns {string}
*/
- let getRows = tableApi => {
- let rows = tableApi.rows();
- return rows;
+ let getGroupLabelById = (groupId) => {
+ let options = config.signatureGroupsLabels.filter(option => option.value === groupId);
+ return options.length ? options[0].text : '';
};
/**
- * get all selected rows of a table
+ * helper function - get cell by columnSelector from same row as cell
* @param tableApi
+ * @param cell
+ * @param columnSelector
* @returns {*}
*/
- let getSelectedRows = tableApi => {
- let selectedRows = tableApi.rows('.selected');
- return selectedRows;
+ let getNeighboringCell = (tableApi, cell, columnSelector) => {
+ return tableApi.cell(tableApi.row(cell).index(), columnSelector);
};
/**
- * check the "delete signature" button. show/hide the button if a signature is selected
+ * get next cell by columnSelector
* @param tableApi
+ * @param cell
+ * @param columnSelectors
+ * @returns {*}
*/
- let checkDeleteSignaturesButton = tableApi => {
- let selectedRows = getSelectedRows(tableApi);
- let selectedRowCount = selectedRows.data().length;
- let clearButton = tableApi.button('tableTools', 'delete:name').node();
-
- if(selectedRowCount > 0){
- let allRows = getRows(tableApi);
- let rowCount = allRows.data().length;
-
- let countText = selectedRowCount;
- if(selectedRowCount >= rowCount){
- countText = 'all';
- }
- clearButton.find('i+span').text(countText);
-
- // update clear signatures button text
- clearButton.velocity('stop');
-
- if( clearButton.is(':hidden') ){
- // show button
- clearButton.velocity('transition.expandIn', {
- duration: 100
- });
+ let searchNextCell = (tableApi, cell, columnSelectors) => {
+ if(columnSelectors.length){
+ // copy selectors -> .shift() modifies the orig array, important!
+ columnSelectors = columnSelectors.slice(0);
+ let nextCell = getNeighboringCell(tableApi, cell, columnSelectors.shift());
+ let nextCellElement = nextCell.nodes().to$();
+ if( nextCellElement.data('editable') ){
+ // cell is xEditable field -> skip "disabled" OR check value
+ let nextCellValue = nextCellElement.editable('getValue', true);
+ if(
+ [0, null].includes(nextCellValue) &&
+ !nextCellElement.data('editable').options.disabled
+ ){
+ // xEditable value is empty
+ return nextCell;
+ }else{
+ // search next cell
+ return searchNextCell(tableApi, cell, columnSelectors);
+ }
+ }else if( nextCell.index().column === tableApi.column(-1).index() ){
+ // NO xEditable cell BUT last column (=> action cell) -> OK
+ return nextCell;
}else{
- // highlight button
- clearButton.velocity('callout.pulse', {
- duration: 200
- });
+ console.error('No cell found for activation!');
}
}else{
- // hide button
- clearButton.velocity('transition.expandOut', {
- duration: 100
- });
+ // return origin cell
+ return tableApi.cell(cell);
}
};
/**
- * draw signature table toolbar (add signature button, scan progress bar
- * @param moduleElement
- * @param mapId
- * @param systemData
+ * make cell active -> focus() + show xEditable
+ * @param cell
*/
- let drawSignatureTableNew = (moduleElement, mapId, systemData) => {
- // add toolbar action for table -------------------------------------------------------------------------------
- let tableToolbarAction = $('', {
- class: config.tableToolsActionClass
- });
-
- // create "empty table for new signature
- let table = $(' ', {
- class: ['stripe', 'row-border', 'compact', 'nowrap', config.sigTableClass, config.sigTableSecondaryClass].join(' ')
- });
-
- tableToolbarAction.append(table);
-
- moduleElement.find('.' + config.moduleHeadClass).after(tableToolbarAction);
-
- let signatureData = formatSignatureData(systemData, [emptySignatureData], emptySignatureOptions);
- let signatureTable = table.dataTable( {
- data: signatureData,
- paging: false,
- info: false,
- searching: false,
- tabIndex: -1
- } );
- let signatureTableApi = signatureTable.api();
-
- setDataTableInstance(mapId, systemData.id, 'secondary', signatureTableApi);
-
- table.makeEditable(signatureTableApi, systemData);
+ let activateCell = (cell) => {
+ let cellElement = cell.nodes().to$();
+ // NO xEditable
+ cellElement.focus();
+
+ if( cellElement.data('editable') ){
+ // cell is xEditable field -> show xEditable form
+ cellElement.editable('show');
+ }
};
/**
- * Update/set tooltip for an element
- * @param element
- * @param title
+ * search neighboring cell (same row) and set "active" -> show editable
+ * @param tableApi
+ * @param cell
+ * @param columnSelectors
*/
- let updateTooltip = (element, title) => {
- $(element).attr('data-container', 'body').attr('title', title.toUpperCase()).tooltip('fixTitle')
- .tooltip('setContent');
+ let activateNextCell = (tableApi, cell, columnSelectors) => {
+ let nextCell = searchNextCell(tableApi, cell, columnSelectors);
+ activateCell(nextCell);
+ let test;
};
/**
- * helper function - jump to "next" editable field on save
- * @param field
- * @param selector
- * @returns {*|jQuery|HTMLElement}
+ * helper function - set 'save' observer for xEditable cell
+ * -> show "neighboring" xEditable field
+ * @param tableApi
+ * @param cell
+ * @param columnSelectorsAjax - used for Ajax save (edit signature)
+ * @param columnSelectorsDry - used for dry save (new signature)
*/
- let getNextEditableField = (field, selector) => {
- let nextEditableField = null;
- if(selector){
- // search specific sibling
- nextEditableField = $(field).closest('td').nextAll(selector).find('.editable');
- }else{
- // get next sibling
- nextEditableField = $(field).closest('td').next().find('.editable');
- }
-
- return $(nextEditableField);
+ let editableOnSave = (tableApi, cell, columnSelectorsAjax = [], columnSelectorsDry = []) => {
+ $(cell).on('save', function(e, params){
+ if(params.response){
+ // send by Ajax
+ activateNextCell(tableApi, cell, columnSelectorsAjax);
+ }else{
+ // dry save - no request
+ activateNextCell(tableApi, cell, columnSelectorsDry);
+ }
+ });
};
/**
- * helper function - get the next editable field in next table column
- * @param fields
+ * helper function - set 'hidden' observer for xEditable cell
+ * -> set focus() on xEditable field
+ * @param tableApi
+ * @param cell
*/
- let openNextEditDialogOnSave = fields => {
- fields.on('save', function(e, params){
- let currentField = $(this);
- let nextField = getNextEditableField(currentField);
- nextField.editable('show');
-
- setTimeout(() => {
- // update scanning progressbar if sig "type" has changed AND
- // the current field is in the "primary" table (not the "add" new sig row)
- if(
- $(e.target).hasClass(config.sigTableEditSigGroupSelect) &&
- $(e.target).parents('.' + config.sigTableClass).hasClass(config.sigTablePrimaryClass)
- ){
- currentField.parents('.' + config.moduleClass).updateScannedSignaturesBar({showNotice: true});
- }
- }, 200);
+ let editableOnHidden = (tableApi, cell) => {
+ $(cell).on('hidden', function(e, reason){
+ // re-focus element on close (keyboard navigation)
+ // 'save' event handles default focus (e.g. open new xEditable)
+ // 'hide' handles all the rest (experimental)
+ if(reason !== 'save'){
+ this.focus();
+ }
});
};
/**
- * make a table or row editable
- * @param tableApi
- * @param systemData
+ * helper function - set 'shown' observer for xEditable type cell
+ * -> enable Select2 for xEditable form
+ * @param cell
*/
- $.fn.makeEditable = function(tableApi, systemData){
- // table element OR row element
- let tableElement = $(this);
-
- // find editable fields
- let sigNameFields = tableElement.find('.' + config.sigTableEditSigNameInput);
- let sigGroupFields = tableElement.find('.' + config.sigTableEditSigGroupSelect);
- let sigTypeFields = tableElement.find('.' + config.sigTableEditSigTypeSelect);
- let sigDescriptionFields = tableElement.find('.' + config.sigTableEditSigDescriptionTextarea);
- let sigConnectionFields = tableElement.find('.' + config.sigTableEditSigConnectionSelect);
-
- /**
- * add map/system specific data for each editable field in the sig-table
- * @param params
- * @returns {*}
- */
- let modifyFieldParamsOnSend = params => {
- params.systemId = systemData.id;
- return params;
- };
-
- // set global xEditable options for all table fields
- $.extend($.fn.editable.defaults, {
- url: Init.path.saveSignatureData,
- dataType: 'json',
- mode: 'popup',
- container: 'body',
- error: function(jqXHR, newValue){
- let reason = '';
- let status = '';
- if(jqXHR.name){
- // save error new sig (mass save)
- reason = jqXHR.name;
- status = 'Error';
- }else{
- reason = jqXHR.responseJSON.text;
- status = jqXHR.status;
- }
-
- Util.showNotify({title: status + ': save signature', text: reason, type: 'error'});
- $(document).setProgramStatus('problem');
- return reason;
- }
+ let editableGroupOnShown = cell => {
+ $(cell).on('shown', function(e, editable){
+ let inputField = editable.input.$input;
+ inputField.addClass('pf-select2').initSignatureGroupSelect();
});
+ };
-
- // Input sig name ---------------------------------------------------------------------------------------------
- sigNameFields.editable({
- type: 'text',
- title: 'signature id',
- name: 'name',
- emptytext: '? ? ?',
- display: function(value) {
- // change display value to first 3 letters
- $(this).text($.trim( value.substr(0, 3) ).toLowerCase());
- },
- validate: function(value) {
- if($.trim(value).length < 3) {
- return 'Id is less than min of "3"';
- }else if($.trim(value).length > 10){
- return 'Id is more than max of "10"';
- }
- },
- params: modifyFieldParamsOnSend,
- success: function(response, newValue){
- if(response){
- let signatureNameField = $(this);
- let columnElement = signatureNameField.parents('td');
- let rowElement = signatureNameField.parents('tr');
- let newRowData = response.signatures[0];
-
- // update column tooltip
- updateTooltip(columnElement, newValue);
-
- // update "updated" cell
- updateSignatureCell(tableApi, rowElement, 7, newRowData.updated);
- }
+ /**
+ * helper function - set 'save' observer for xEditable group cell
+ * -> update scanned signature bar
+ * @param tableApi
+ * @param cell
+ */
+ let editableGroupOnSave = (tableApi, cell) => {
+ $(cell).on('save', function(e, params){
+ if(params.response){
+ // send by Ajax
+ updateScannedSignaturesBar(tableApi, {showNotice: true});
}
});
+ };
-
- // Select sig group (master) ----------------------------------------------------------------------------------
- sigGroupFields.editable({
- type: 'select',
- title: 'group',
- name: 'groupId',
- emptytext: 'unknown',
- onblur: 'submit',
- showbuttons: false,
- prepend: [{value: '0', text: ''}],
- params: modifyFieldParamsOnSend,
- source: function(){
- let signatureGroupField = $(this);
- let systemTypeId = parseInt( signatureGroupField.attr('data-systemTypeId') );
-
- // get all available Signature Types
- let availableTypes = config.signatureGroupsLabels;
-
- return availableTypes;
- },
- success: function(response, newValue){
- let signatureGroupField = $(this);
- let rowElement = signatureGroupField.parents('tr');
- newValue = parseInt(newValue);
-
- if(response){
- let newRowData = response.signatures[0];
-
- // update "updated" cell
- updateSignatureCell(tableApi, rowElement, 7, newRowData.updated);
- }
-
- // find related "type" select (same row) and change options
- let signatureTypeField = getNextEditableField(signatureGroupField);
-
- let systemTypeId = parseInt( signatureGroupField.attr('data-systemTypeId') );
- let areaId = parseInt( signatureGroupField.attr('data-areaid') );
-
- let newSelectOptions = getAllSignatureNames(systemData, systemTypeId, areaId, newValue);
- signatureTypeField.editable('option', 'source', newSelectOptions);
-
- if(
- newValue > 0 &&
- newSelectOptions.length > 0
- ){
- signatureTypeField.editable('enable');
- }else{
- signatureTypeField.editable('disable');
- }
-
- signatureTypeField.editable('setValue', null);
-
- // find "connection" select (same row) and change "enabled" flag
- let signatureConnectionField = getNextEditableField(signatureGroupField, '.' + config.sigTableConnectionClass);
- if(newValue === 5){
- // wormhole
- signatureConnectionField.editable('enable');
- }else{
- checkConnectionConflicts();
- signatureConnectionField.editable('disable');
- }
-
- signatureConnectionField.editable('setValue', null);
+ /**
+ * helper function - set 'init' observer for xEditable type cell
+ * -> disable xEditable field if no options available
+ * @param cell
+ */
+ let editableTypeOnInit = cell => {
+ $(cell).on('init', function(e, editable){
+ if(!editable.options.source().length){
+ editableDisable($(this));
}
});
+ };
+ /**
+ * helper function - set 'shown' observer for xEditable type cell
+ * -> enable Select2 for xEditable form
+ * @param cell
+ */
+ let editableTypeOnShown = cell => {
+ $(cell).on('shown', function(e, editable){
+ // destroy possible open popovers (e.g. wormhole types)
+ $(this).destroyPopover(true);
- // Select sig type (slave: depends on sig type) ---------------------------------------------------------------
- sigTypeFields.on('init', function(e, editable) {
- // check if there are initial options available
- let options = editable.input.options.source.bind(e.target)();
- if(options.length <= 0){
- editable.disable();
- }
+ let inputField = editable.input.$input;
+ let hasOptGroups = inputField.has('optgroup').length > 0;
+ inputField.addClass('pf-select2').initSignatureTypeSelect({}, hasOptGroups);
});
+ };
- sigTypeFields.editable({
- type: 'select',
- title: 'type',
- name: 'typeId',
- emptytext: 'unknown',
- onblur: 'submit',
- showbuttons: false,
- params: modifyFieldParamsOnSend,
- display: function(value, sourceData){
- let selected = $.fn.editableutils.itemsByValue(value, sourceData);
- if(selected.length && selected[0].text.length){
- $(this).html(FormElement.formatSignatureTypeSelectionData({text: selected[0].text}));
- }else{
- $(this).empty();
- }
- },
- source: function(){
- let signatureTypeField = $(this);
-
- let systemTypeId = parseInt( signatureTypeField.attr('data-systemTypeId') );
- let areaId = parseInt( signatureTypeField.attr('data-areaid') );
- let groupId = parseInt( signatureTypeField.attr('data-groupId') );
- let availableSigs = getAllSignatureNames(systemData, systemTypeId, areaId, groupId);
-
- return availableSigs;
- },
- success: function(response, newValue){
- let signatureTypeField = $(this);
- let rowElement = signatureTypeField.parents('tr');
-
- if(response){
- let newRowData = response.signatures[0];
- // update "updated" cell
- updateSignatureCell(tableApi, rowElement, 7, newRowData.updated);
- }else{
- // "add new" signature -> set "+" focus for keyboard control
- setTimeout(() => {
- rowElement.find('.pf-table-action-cell')[0].focus();
- }, 50);
- }
- }
+ /**
+ * helper function - set 'shown' observer for xEditable description cell
+ * -> change height for "new signature" table wrapper
+ * @param cell
+ */
+ let editableDescriptionOnShown = cell => {
+ $(cell).on('shown', function(e, editable){
+ $(this).parents('.' + config.tableToolsActionClass).css( 'height', '+=35px' );
});
+ };
- // Textarea sig description -----------------------------------------------------------------------------------
- sigDescriptionFields.editable({
- type: 'textarea',
- title: 'description',
- name: 'description',
- emptytext: '',
- onblur: 'submit',
- mode: 'inline',
- showbuttons: false,
- inputclass: config.editableDescriptionInputClass,
- params: modifyFieldParamsOnSend,
- success: function(response, newValue){
- if(response){
- let signatureDescriptionField = $(this);
- let rowElement = signatureDescriptionField.parents('tr');
- let newRowData = response.signatures[0];
-
- // update "updated" cell
- updateSignatureCell(tableApi, rowElement, 7, newRowData.updated);
- }
- }
+ /**
+ * helper function - set 'hidden' observer for xEditable description cell
+ * -> change height for "new signature" table wrapper
+ * @param cell
+ */
+ let editableDescriptionOnHidden = cell => {
+ $(cell).on('hidden', function(e, editable){
+ $(this).parents('.' + config.tableToolsActionClass).css( 'height', '-=35px' );
});
+ };
- // Select connection (target system) --------------------------------------------------------------------------
- let initCount = 0;
- sigConnectionFields.on('init', function(e, editable) {
- if(++initCount >= sigConnectionFields.length){
+ /**
+ * helper function - set 'init' observer for xEditable connection cell
+ * -> set focus() on xEditable field
+ * @param cell
+ */
+ let editableConnectionOnInit = cell => {
+ $(cell).on('init', function(e, editable){
+ if(editable.value > 0){
+ // empty connection selects ON INIT don´t make a difference for conflicts
checkConnectionConflicts();
}
});
+ };
- sigConnectionFields.editable({
- type: 'select',
- title: 'system',
- name: 'connectionId',
- emptytext: 'unknown',
- onblur: 'submit',
- showbuttons: false,
- prepend: [{value: '0', text: ''}],
- params: modifyFieldParamsOnSend,
- display: function(value, sourceData) {
- let selected = $.fn.editableutils.itemsByValue(value, sourceData);
- if(selected.length && selected[0].text.length){
- let errorIcon = ' ';
- $(this).html(FormElement.formatSignatureConnectionSelectionData({text: selected[0].text})).prepend(errorIcon);
- }else{
- $(this).empty() ;
- }
- },
- source: function(a,b){
- let activeMap = Util.getMapModule().getActiveMap();
- let mapId = activeMap.data('id');
-
- let availableConnections = getSignatureConnectionOptions(mapId, systemData);
-
- return availableConnections;
- },
- success: function(response, newValue){
- let signatureConnectionField = $(this);
- let rowElement = signatureConnectionField.parents('tr');
-
- if(response){
- let newRowData = response.signatures[0];
-
- // update "updated" cell
- updateSignatureCell(tableApi, rowElement, 7, newRowData.updated);
- }else{
- // "add new" signature -> set "+" focus for keyboard control
- setTimeout(() => {
- rowElement.find('.pf-table-action-cell')[0].focus();
- }, 50);
- }
- }
- });
-
- sigGroupFields.on('shown', function(e, editable){
- let inputField = editable.input.$input;
- inputField.addClass('pf-select2').initSignatureGroupSelect();
- });
-
- sigTypeFields.on('shown', function(e, editable){
- // destroy possible open popovers (e.g. wormhole types)
- $(this).destroyPopover(true);
-
- let inputField = editable.input.$input;
- let hasOptGroups = inputField.has('optgroup').length > 0;
- inputField.addClass('pf-select2').initSignatureTypeSelect({}, hasOptGroups);
- });
-
- sigConnectionFields.on('shown', function(e, editable){
+ /**
+ * helper function - set 'shown' observer for xEditable connection cell
+ * -> enable Select2 for xEditable form
+ * @param cell
+ */
+ let editableConnectionOnShown = cell => {
+ $(cell).on('shown', function(e, editable){
let inputField = editable.input.$input;
inputField.addClass('pf-select2').initSignatureConnectionSelect();
});
+ };
- sigDescriptionFields.on('shown', function(e, editable){
- // enlarge the tools-action container because the tables gets bigger
- tableElement.parents('.' + config.tableToolsActionClass).css( 'height', '+=35px' );
- });
-
- sigDescriptionFields.on('hidden', function(e, editable){
- // enlarge the tools-action container because the tables gets bigger
- tableElement.parents('.' + config.tableToolsActionClass).css( 'height', '-=35px' );
- });
-
- sigConnectionFields.on('save', function(e, editable){
+ /**
+ * helper function - set 'save' observer for xEditable connection cell
+ * -> check connection conflicts
+ * @param cell
+ */
+ let editableConnectionOnSave = cell => {
+ $(cell).on('save', function(e, params){
checkConnectionConflicts();
});
+ };
- $().add(sigNameFields).add(sigGroupFields).add(sigTypeFields)
- .add(sigDescriptionFields).add(sigConnectionFields).on('hidden', function(e, editable) {
- // re-focus element on close (keyboard navigation)
- this.focus();
- });
+ /**
+ * enable xEditable element
+ * @param element
+ */
+ let editableEnable = element => {
+ element.editable('enable');
+ // (re)-enable focus on element by tabbing, xEditable removes "tabindex" on 'disable'
+ element.attr('tabindex', 0);
+ };
- // open next field dialog -------------------------------------------------------------------------------------
- openNextEditDialogOnSave(sigNameFields);
- openNextEditDialogOnSave(sigGroupFields);
+ /**
+ * disable xEditable element
+ * @param element
+ */
+ let editableDisable = element => {
+ element.editable('disable');
+ // xEditable sets 'tabindex = -1'
};
/**
- * get all connection select options
+ * get dataTables default options for signature tables
* @param mapId
* @param systemData
- * @returns {Array}
+ * @returns {{}}
*/
- let getSignatureConnectionOptions = (mapId, systemData) => {
- let map = Map.getMapInstance( mapId );
- let systemId = MapUtil.getSystemId(mapId, systemData.id);
- let systemConnections = MapUtil.searchConnectionsBySystems(map, [systemId], 'wh');
- let newSelectOptions = [];
- let connectionOptions = [];
-
- for(let i = 0; i < systemConnections.length; i++){
- let connectionData = MapUtil.getDataByConnection(systemConnections[i]);
-
- // connectionId is required (must be stored)
- if(connectionData.id){
- // check whether "source" or "target" system is relevant for this connection
- // -> hint "source" === 'target' --> loop
- if(systemData.id !== connectionData.target){
- let targetSystemData = MapUtil.getSystemData(mapId, connectionData.target);
- if(targetSystemData){
- // take target...
- connectionOptions.push({
- value: connectionData.id,
- text: connectionData.targetAlias + ' - ' + targetSystemData.security
- });
- }
- }else if(systemData.id !== connectionData.source){
- let sourceSystemData = MapUtil.getSystemData(mapId, connectionData.source);
- if(sourceSystemData){
- // take source...
- connectionOptions.push({
- value: connectionData.id,
- text: connectionData.sourceAlias + ' - ' + sourceSystemData.security
- });
- }
- }
- }
- }
+ let getSignatureDataTableDefaults = (mapId, systemData) => {
- if(connectionOptions.length > 0){
- newSelectOptions.push({ text: 'System', children: connectionOptions});
- }
+ /**
+ * add map/system specific data for each editable field in the sig-table
+ * @param params
+ * @returns {*}
+ */
+ let modifyFieldParamsOnSend = params => {
+ params.systemId = systemData.id;
+ return params;
+ };
- return newSelectOptions;
- };
+ let dataTableDefaults = {
+ pfMeta: {
+ 'mapId': mapId,
+ 'systemId': systemData.id
+ },
+ order: [1, 'asc'],
+ rowId: rowData => config.sigTableRowIdPrefix + rowData.id,
+ language: {
+ emptyTable: 'No signatures added',
+ info: 'Showing _START_ to _END_ of _TOTAL_ signatures',
+ infoEmpty: 'Showing 0 to 0 of 0 signatures',
+ infoFiltered: '( from _MAX_ total)',
+ lengthMenu: 'Show _MENU_',
+ zeroRecords: 'No signatures recorded'
+ },
+ columnDefs: [
+ {
+ targets: 0,
+ name: 'status',
+ orderable: true,
+ searchable: false,
+ title: '',
+ width: 2,
+ class: ['text-center'].join(' '),
+ data: 'updated',
+ type: 'html',
+ render: {
+ _: (cellData, type, rowData, meta) => {
+ let value = '';
+ if(cellData && cellData.character){
+ value = Util.getStatusInfoForCharacter(cellData.character, 'class');
+ }
- /**
- * check connectionIds for conflicts (multiple signatures -> same connection)
- * -> show "conflict" icon next to select
- */
- let checkConnectionConflicts = () => {
- setTimeout(() => {
- let connectionSelects = $('.' + config.sigTableConnectionClass + ' .editable');
- let connectionIds = [];
- let duplicateConnectionIds = [];
- let groupedSelects = [];
+ if(type === 'display'){
+ value = '';
+ }
+ return value;
+ }
+ }
+ },{
+ targets: 1,
+ name: 'id',
+ orderable: true,
+ searchable: true,
+ title: 'id',
+ type: 'string',
+ width: 15,
+ class: [config.tableCellFocusClass, config.sigTableEditSigNameInput].join(' '),
+ data: 'name',
+ createdCell: function(cell, cellData, rowData, rowIndex, colIndex){
+ let tableApi = this.api();
+
+ updateTooltip(cell, cellData);
+
+ editableOnSave(tableApi, cell, [], ['group:name', 'type:name', 'action:name']);
+ editableOnHidden(tableApi, cell);
+
+ $(cell).editable($.extend({
+ mode: 'popup',
+ type: 'text',
+ title: 'signature id',
+ name: 'name',
+ pk: rowData.id || null,
+ emptytext: '? ? ?',
+ value: cellData,
+ inputclass: config.editableNameInputClass,
+ display: function(value){
+ // change display value to first 3 letters
+ $(this).text($.trim( value.substr(0, 3) ).toLowerCase());
+ },
+ validate: function(value){
+ let msg = false;
+ if($.trim(value).length < 3){
+ msg = 'Id is less than min of "3"';
+ }else if($.trim(value).length > 10){
+ msg = 'Id is more than max of "10"';
+ }
- connectionSelects.each(function(){
- let select = $(this);
- let value = parseInt(select.editable('getValue', true) )|| 0;
+ if(msg){
+ return {newValue: value, msg: msg, field: this};
+ }
+ },
+ params: modifyFieldParamsOnSend,
+ success: function(response, newValue){
+ tableApi.cell(cell).data(newValue);
+
+ $(this).pulseBackgroundColor('changed');
+ updateTooltip(cell, newValue);
+
+ if(response){
+ let newRowData = response.signatures[0];
+ updateSignatureCell(tableApi, rowIndex, 'status:name', newRowData.updated);
+ updateSignatureCell(tableApi, rowIndex, 'updated:name', newRowData.updated.updated);
+ }
+ tableApi.draw();
+ }
+ }, editableDefaults));
+ }
+ },{
+ targets: 2,
+ name: 'group',
+ orderable: true,
+ searchable: true,
+ title: 'group',
+ type: 'string', // required for sort/filter because initial data type is numeric
+ width: 40,
+ class: [config.tableCellFocusClass].join(' '),
+ data: 'groupId',
+ render: {
+ sort: getGroupLabelById,
+ filter: getGroupLabelById
+ },
+ createdCell: function(cell, cellData, rowData, rowIndex, colIndex){
+ let tableApi = this.api();
+
+ editableOnSave(tableApi, cell, ['type:name'], ['type:name', 'action:name']);
+ editableOnHidden(tableApi, cell);
+ editableGroupOnShown(cell);
+ editableGroupOnSave(tableApi, cell);
+
+ $(cell).editable($.extend({
+ mode: 'popup',
+ type: 'select',
+ title: 'group',
+ name: 'groupId',
+ pk: rowData.id || null,
+ emptytext: 'unknown',
+ onblur: 'submit',
+ showbuttons: false,
+ value: cellData,
+ prepend: [{value: 0, text: ''}],
+ params: modifyFieldParamsOnSend,
+ source: config.signatureGroupsLabels,
+ display: function(value, sourceData){
+ let selected = $.fn.editableutils.itemsByValue(value, sourceData);
+ if(selected.length && selected[0].value > 0){
+ $(this).html(selected[0].text);
+ }else{
+ $(this).empty();
+ }
+ },
+ validate: function(value){
+ // convert string to int -> important for further processing
+ // -> on submit record (new signature) validate() is called and no error should be returned
+ // value should already be integer
+ if( !Number.isInteger(value) ){
+ return {newValue: parseInt(value) || 0, msg: null};
+ }
+ },
+ success: function(response, newValue){
+ tableApi.cell(cell).data(newValue);
- if(
- connectionIds.indexOf(value) > -1 &&
- duplicateConnectionIds.indexOf(value) === -1
- ){
- // duplicate found
- duplicateConnectionIds.push(value);
- }
+ $(this).pulseBackgroundColor('changed');
- if(groupedSelects[value] !== undefined){
- groupedSelects[value].push(select[0]);
- }else{
- groupedSelects[value] = [select[0]];
- }
+ if(response){
+ let newRowData = response.signatures[0];
+ updateSignatureCell(tableApi, rowIndex, 'status:name', newRowData.updated);
+ updateSignatureCell(tableApi, rowIndex, 'updated:name', newRowData.updated.updated);
+ }
+ tableApi.draw();
+
+ // find related "type" select (same row) and change options
+ let signatureTypeCell = getNeighboringCell(tableApi, cell, 'type:name');
+ let signatureTypeField = signatureTypeCell.nodes().to$();
+
+ let typeOptions = getAllSignatureNames(
+ systemData,
+ systemData.type.id,
+ Util.getAreaIdBySecurity(systemData.security),
+ newValue
+ );
+ signatureTypeField.editable('option', 'source', typeOptions);
+
+ if(
+ newValue > 0 &&
+ typeOptions.length > 0
+ ){
+ editableEnable(signatureTypeField);
+ }else{
+ editableDisable(signatureTypeField);
+ }
+ signatureTypeCell.data(0);
+ signatureTypeField.editable('setValue', 0);
- connectionIds.push(value);
- });
- // update "conflict" icon next to select label for connectionIds
- connectionSelects.each(function(){
- let select = $(this);
- let value = parseInt(select.editable('getValue', true) )|| 0;
- let conflictIcon = select.find('.fa-exclamation-triangle');
- if(
- duplicateConnectionIds.indexOf(value) > -1 &&
- groupedSelects[value].indexOf(select[0]) > -1
- ){
- conflictIcon.removeClass('hide');
- }else{
- conflictIcon.addClass('hide');
- }
- });
- }, 200);
- };
+ // find "connection" select (same row) and change "enabled" flag
+ let signatureConnectionCell = getNeighboringCell(tableApi, cell, 'connection:name');
+ let signatureConnectionField = signatureConnectionCell.nodes().to$();
- /**
- * get all signature types that can exist for a given system
- * -> result is partially cached
- * @param systemData
- * @param systemTypeId
- * @param areaId
- * @param groupId
- * @returns {Array}
- */
- let getAllSignatureNames = (systemData, systemTypeId, areaId, groupId) => {
- let newSelectOptions = [];
- let cacheKey = [systemTypeId, areaId, groupId].join('_');
- let newSelectOptionsCount = 0;
+ if(newValue === 5){
+ // wormhole
+ editableEnable(signatureConnectionField);
+ }else{
+ checkConnectionConflicts();
+ editableDisable(signatureConnectionField);
+ }
+ signatureConnectionCell.data(0);
+ signatureConnectionField.editable('setValue', 0);
+ }
+ }, editableDefaults));
+ }
+ },{
+ targets: 3,
+ name: 'type',
+ orderable: false,
+ searchable: false,
+ title: 'type',
+ type: 'string', // required for sort/filter because initial data type is numeric
+ width: 180,
+ class: [config.tableCellFocusClass].join(' '),
+ data: 'typeId',
+ createdCell: function(cell, cellData, rowData, rowIndex, colIndex){
+ let tableApi = this.api();
+
+ editableOnSave(tableApi, cell, ['connection:name'], ['action:name']);
+ editableOnHidden(tableApi, cell);
+ editableTypeOnInit(cell);
+ editableTypeOnShown(cell);
+
+ $(cell).editable($.extend({
+ mode: 'popup',
+ type: 'select',
+ title: 'type',
+ name: 'typeId',
+ pk: rowData.id || null,
+ emptytext: 'unknown',
+ onblur: 'submit',
+ showbuttons: false,
+ disabled: rowData.groupId <= 0, // initial disabled if groupId not set
+ value: cellData,
+ prepend: [{value: 0, text: ''}],
+ params: modifyFieldParamsOnSend,
+ source: function(){
+ // get current row data (important!)
+ // -> "rowData" param is not current state, values are "on createCell()" state
+ let rowData = tableApi.row($(cell).parents('tr')).data();
+
+ let typeOptions = getAllSignatureNames(
+ systemData,
+ systemData.type.id,
+ Util.getAreaIdBySecurity(systemData.security),
+ rowData.groupId
+ );
+ return typeOptions;
+ },
+ display: function(value, sourceData){
+ let selected = $.fn.editableutils.itemsByValue(value, sourceData);
+ if(selected.length && selected[0].value > 0){
+ $(this).html(FormElement.formatSignatureTypeSelectionData({text: selected[0].text}));
+ }else{
+ $(this).empty();
+ }
+ },
+ validate: function(value){
+ // convert string to int -> important for further processing
+ // -> on submit record (new signature) validate() is called and no error should be returned
+ // value should already be integer
+ if( !Number.isInteger(value) ){
+ return {newValue: parseInt(value) || 0, msg: null};
+ }
+ },
+ success: function(response, newValue){
+ tableApi.cell(cell).data(newValue);
- // check for cached signature names
- if(sigNameCache.hasOwnProperty( cacheKey )){
- // cached signatures do not include static WHs!
- // -> ".slice(0)" creates copy
- newSelectOptions = sigNameCache[cacheKey].slice(0);
- newSelectOptionsCount = getOptionsCount('children', newSelectOptions);
- }else{
- // get new Options ----------
- // get all possible "static" signature names by the selected groupId
- let tempSelectOptions = Util.getAllSignatureNames(systemTypeId, areaId, groupId);
+ $(this).pulseBackgroundColor('changed');
- // format options into array with objects advantages: keep order, add more options (whs), use optgroup
- if(tempSelectOptions){
- let fixSelectOptions = [];
- for (let key in tempSelectOptions) {
- if (
- key > 0 &&
- tempSelectOptions.hasOwnProperty(key)
- ) {
- newSelectOptionsCount++;
- fixSelectOptions.push({value: parseInt(key), text: tempSelectOptions[key]});
+ if(response){
+ let newRowData = response.signatures[0];
+ updateSignatureCell(tableApi, rowIndex, 'status:name', newRowData.updated);
+ updateSignatureCell(tableApi, rowIndex, 'updated:name', newRowData.updated.updated);
+ }
+ tableApi.draw();
+ }
+ }, editableDefaults));
}
- }
-
- if(newSelectOptionsCount > 0){
- if(groupId === 5){
- // "wormhole" selected => multiple | |