2020-06-03 23:19:14 +02:00
/* Codacy comment to notify that baseurl is a read-only global variable. */
/* global baseurl */
2017-04-13 16:31:48 +02:00
String . prototype . ucfirst = function ( ) {
2019-02-13 08:46:18 +01:00
return this . charAt ( 0 ) . toUpperCase ( ) + this . slice ( 1 ) ;
2017-04-13 16:31:48 +02:00
}
2017-04-13 11:59:17 +02:00
2018-12-13 10:17:29 +01:00
if ( ! String . prototype . startsWith ) {
String . prototype . startsWith = function ( searchString , position ) {
position = position || 0 ;
return this . indexOf ( searchString , position ) === position ;
} ;
}
2022-05-05 22:02:39 +02:00
function escapeHtml ( unsafe ) {
2022-09-23 14:48:25 +02:00
if ( typeof unsafe === "boolean" || typeof unsafe === "number" ) {
return unsafe ;
}
2022-05-05 22:02:39 +02:00
return unsafe
. replace ( /&/g , "&" )
. replace ( /</g , "<" )
. replace ( />/g , ">" )
. replace ( /"/g , """ )
. replace ( /'/g , "'" ) ;
}
2021-09-02 10:19:06 +02:00
function copyToClipboard ( element ) {
var $temp = $ ( "<input>" ) ;
$ ( "body" ) . append ( $temp ) ;
$temp . val ( $ ( element ) . val ( ) ) . select ( ) ;
document . execCommand ( "copy" ) ;
$temp . remove ( ) ;
}
2019-05-06 15:19:22 +02:00
function stringToRGB ( str ) {
var hash = 0 ;
if ( str . length == 0 ) return hash ;
for ( i = 0 ; i < str . length ; i ++ ) {
hash = ( ( hash << 5 ) - hash ) + str . charCodeAt ( i ) ;
hash = hash & hash ; // Convert to 32bit integer
}
var c = ( hash & 0x00FFFFFF )
. toString ( 16 )
. toUpperCase ( ) ;
return "#" + "00000" . substring ( 0 , 6 - c . length ) + c ;
}
2020-08-10 10:38:28 +02:00
function rgb2hex ( rgb ) {
rgb = rgb . match ( /^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/ ) ;
function hex ( x ) {
return ( "0" + parseInt ( x ) . toString ( 16 ) ) . slice ( - 2 ) ;
}
return "#" + hex ( rgb [ 1 ] ) + hex ( rgb [ 2 ] ) + hex ( rgb [ 3 ] ) ;
}
2020-07-14 12:34:29 +02:00
function xhrFailCallback ( xhr ) {
2022-09-23 11:00:31 +02:00
if ( xhr . status === 0 ) {
showMessage ( 'fail' , 'Something went wrong – server is not responding.' ) ;
2022-09-30 13:04:13 +02:00
} else if ( xhr . status === 401 ) {
2021-02-19 15:16:56 +01:00
showMessage ( 'fail' , 'Unauthorized. Please reload page to log again.' ) ;
} else if ( xhr . status === 403 || xhr . status === 405 ) {
2020-07-14 12:34:29 +02:00
showMessage ( 'fail' , 'Not allowed.' ) ;
} else if ( xhr . status === 404 ) {
showMessage ( 'fail' , 'Resource not found.' ) ;
} else {
showMessage ( 'fail' , 'Something went wrong - the queried function returned an exception. Contact your administrator for further details.' ) ;
}
}
2021-02-19 15:38:03 +01:00
function xhr ( options ) {
options . beforeSend = options . beforeSend || function ( ) {
$ ( ".loading" ) . show ( ) ;
} ;
options . complete = options . complete || function ( ) {
$ ( ".loading" ) . hide ( ) ;
}
options . error = options . error || xhrFailCallback ;
options . cache = options . cache || false ;
if ( ! options . url . startsWith ( 'http://' ) && ! options . url . startsWith ( 'https://' ) ) {
options . url = baseurl + options . url ;
}
return $ . ajax ( options ) ;
}
2020-07-14 12:34:29 +02:00
function deleteObject ( type , action , id ) {
2020-08-16 13:31:31 +02:00
var url = baseurl + "/" + type + "/" + action + "/" + id ;
2022-03-29 12:30:36 +02:00
$ . get ( url , openConfirmation ) . fail ( xhrFailCallback )
2017-04-13 16:31:48 +02:00
}
2014-05-09 23:12:51 +02:00
2017-04-13 16:31:48 +02:00
function quickDeleteSighting ( id , rawId , context ) {
2022-10-24 15:22:56 +02:00
var url = baseurl + "/sightings/quickDelete/" + id + "/" + rawId + "/" + context ;
2022-04-21 17:39:07 +02:00
$ . get ( url , openConfirmation ) . fail ( xhrFailCallback )
2017-04-13 16:31:48 +02:00
}
2017-02-16 22:41:22 +01:00
2020-10-05 20:38:58 +02:00
function fetchAddSightingForm ( type , attribute _id , onvalue ) {
2020-08-16 13:31:31 +02:00
var url = baseurl + "/sightings/quickAdd/" + attribute _id + "/" + type ;
2018-10-30 17:14:42 +01:00
if ( onvalue ) {
url = url + "/1" ;
} else {
url = url + "/0" ;
}
2022-04-21 17:39:07 +02:00
$ . get ( url , openConfirmation ) . fail ( xhrFailCallback ) ;
2018-10-30 17:14:42 +01:00
}
2022-04-17 17:03:41 +02:00
function flexibleAddSighting ( clicked , type , attribute _id , placement ) {
2019-10-08 11:46:22 +02:00
var $clicked = $ ( clicked ) ;
var hoverbroken = false ;
$clicked . off ( 'mouseleave.temp' ) . on ( 'mouseleave.temp' , function ( ) {
hoverbroken = true ;
} ) ;
setTimeout ( function ( ) {
$clicked . off ( 'mouseleave.temp' ) ;
if ( $clicked . is ( ":hover" ) && ! hoverbroken ) {
var html = '<div>'
2022-04-17 17:03:41 +02:00
+ '<button class="btn btn-primary" onclick="addSighting(\'' + type + '\', \'' + attribute _id + '\')">This attribute</button>'
2020-10-05 20:38:58 +02:00
+ '<button class="btn btn-primary" style="margin-left:5px;" onclick="fetchAddSightingForm(\'' + type + '\', \'' + attribute _id + '\', true)">Global value</button>'
2019-10-08 11:46:22 +02:00
+ '</div>' ;
openPopover ( clicked , html , true , placement ) ;
}
} , 1000 ) ;
2019-01-29 16:07:03 +01:00
}
2020-06-16 16:36:49 +02:00
function publishPopup ( id , type , scope ) {
scope = scope === undefined ? 'events' : scope ;
2019-02-13 08:46:18 +01:00
var action = "alert" ;
2022-03-28 12:10:34 +02:00
if ( type === "publish" ) action = "publish" ;
if ( type === "unpublish" ) action = "unpublish" ;
if ( type === "sighting" ) action = "publishSightings" ;
2022-03-27 22:22:29 +02:00
$ . get ( baseurl + "/" + scope + "/" + action + "/" + id , openConfirmation ) . fail ( xhrFailCallback ) ;
2017-04-13 16:31:48 +02:00
}
2014-08-18 15:05:56 +02:00
2017-04-13 16:31:48 +02:00
function delegatePopup ( id ) {
2020-08-16 13:31:31 +02:00
simplePopup ( baseurl + "/event_delegations/delegateEvent/" + id ) ;
2017-04-13 16:31:48 +02:00
}
2016-02-12 05:47:06 +01:00
2018-03-19 10:36:09 +01:00
function genericPopup ( url , popupTarget , callback ) {
2020-10-14 09:15:25 +02:00
var $popupTarget = $ ( popupTarget ) ;
2019-02-13 08:46:18 +01:00
$ . get ( url , function ( data ) {
2020-10-14 09:15:25 +02:00
$popupTarget . html ( data ) ;
$popupTarget . fadeIn ( ) ;
var left = ( $ ( window ) . width ( ) / 2 ) - ( $ ( popupTarget ) . width ( ) / 2 ) ;
$popupTarget . css ( { 'left' : left + 'px' } ) ;
2019-02-13 08:46:18 +01:00
$ ( "#gray_out" ) . fadeIn ( ) ;
if ( callback !== undefined ) {
callback ( ) ;
}
2020-10-29 12:57:26 +01:00
} ) . fail ( xhrFailCallback )
2017-04-13 16:31:48 +02:00
}
2014-08-18 15:05:56 +02:00
2019-03-13 15:57:52 +01:00
function screenshotPopup ( url , title ) {
2019-03-28 16:13:30 +01:00
if ( ! url . startsWith ( 'data:image/' ) ) {
url = url . slice ( 0 , - 1 ) ;
}
2019-05-07 09:01:05 +02:00
url = $ ( '<div>' ) . text ( url ) . html ( ) ;
2022-04-22 10:29:31 +02:00
var img = document . createElement ( 'img' ) ;
img . classList . add ( 'hidden' , 'screenshot_box-content' ) ;
img . src = url ;
img . title = title ;
img . alt = title ;
img . onload = function ( ) {
$ ( this ) . show ( ) ;
$ ( this ) . parent ( ) . parent ( ) . find ( '.fa-spinner' ) . remove ( ) ;
}
img . onerror = function ( ) {
showMessage ( 'fail' , 'Something went wrong - could not load attachment' ) ;
closeScreenshot ( ) ;
}
var popupHtml = '<it class="fa fa-spin fa-spinner" style="font-size: xx-large; color: white; position: fixed; left: 50%; top: 50%;"></it>' ;
popupHtml += '<div class="screenshot-img-box"></div>' ;
2022-04-21 16:20:25 +02:00
popupHtml += '<div class="close-icon useCursorPointer" onclick="closeScreenshot()"></div>' ;
2019-03-28 15:35:10 +01:00
if ( ! url . startsWith ( 'data:image/' ) ) {
2022-04-21 16:20:25 +02:00
popupHtml += '<a class="close-icon useCursorPointer fa fa-expand" style="right: 20px; background: black; color: white; text-decoration: none;" target="_blank" href="' + url + '"></a>' ;
2019-03-28 15:35:10 +01:00
}
2019-03-13 15:57:52 +01:00
popupHtml += '<div style="height: 20px;"></div>' ; // see bottom of image for large one
2022-04-21 16:20:25 +02:00
var $screenshotBox = $ ( "<div id=\"screenshot_box\"></div>" ) . appendTo ( "body" ) ;
$screenshotBox . html ( popupHtml ) ;
$screenshotBox . css ( {
2019-03-13 15:57:52 +01:00
display : 'block' ,
top : ( document . documentElement . scrollTop + 100 ) + 'px'
} ) ;
2022-04-22 10:29:31 +02:00
$screenshotBox . find ( ".screenshot-img-box" ) . append ( img ) ;
2019-02-13 08:46:18 +01:00
$ ( "#gray_out" ) . fadeIn ( ) ;
2017-04-13 16:31:48 +02:00
}
2017-01-19 10:18:29 +01:00
2017-04-13 16:31:48 +02:00
function editTemplateElement ( type , id ) {
2020-08-16 13:31:31 +02:00
simplePopup ( baseurl + "/template_elements/edit/" + type + "/" + id ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-19 08:44:35 +02:00
2017-04-13 16:31:48 +02:00
function cancelPrompt ( isolated ) {
2019-02-13 08:46:18 +01:00
if ( isolated == undefined ) {
$ ( "#gray_out" ) . fadeOut ( ) ;
}
2020-07-13 12:34:58 +02:00
$ ( "#popover_form" ) . fadeOut ( ) ;
2021-11-14 12:11:20 +01:00
$ ( "#confirmation_box" ) . fadeOut ( ) . empty ( ) ;
2019-02-13 08:46:18 +01:00
$ ( '.have-a-popover' ) . popover ( 'destroy' ) ;
2017-04-13 16:31:48 +02:00
}
2014-05-09 23:12:51 +02:00
2017-04-13 16:31:48 +02:00
function submitDeletion ( context _id , action , type , id ) {
2019-02-13 08:46:18 +01:00
var context = 'event' ;
if ( type == 'template_elements' ) context = 'template' ;
var formData = $ ( '#PromptForm' ) . serialize ( ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
data : formData ,
2021-02-19 15:38:03 +01:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
if ( type == 'eventGraph' ) {
showMessage ( 'success' , 'Network has been deleted' ) ;
reset _graph _history ( ) ;
} else {
updateIndex ( context _id , context ) ;
handleGenericAjaxResponse ( data ) ;
}
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
} ,
2021-02-19 15:38:03 +01:00
type : "post" ,
url : "/" + type + "/" + action + "/" + id ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-05-09 23:12:51 +02:00
2017-10-09 15:40:40 +02:00
function removeSighting ( caller ) {
2019-02-13 08:46:18 +01:00
var id = $ ( caller ) . data ( 'id' ) ;
var rawid = $ ( caller ) . data ( 'rawid' ) ;
var context = $ ( caller ) . data ( 'context' ) ;
if ( context != 'attribute' ) {
context = 'event' ;
}
var formData = $ ( '#PromptForm' ) . serialize ( ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
data : formData ,
success : function ( data , textStatus ) {
handleGenericAjaxResponse ( data ) ;
var org = "/" + $ ( '#org_id' ) . text ( ) ;
updateIndex ( id , 'event' ) ;
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/sightings/listSightings/" + rawid + "/" + context + org , function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#sightingsData" ) . html ( data ) ;
2021-02-19 15:38:03 +01:00
} ) . fail ( xhrFailCallback ) ;
2019-02-13 08:46:18 +01:00
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#confirmation_box" ) . fadeOut ( ) ;
} ,
type : "post" ,
2021-02-19 15:38:03 +01:00
url : "/sightings/quickDelete/" + id + "/" + rawid + "/" + context ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2017-02-16 22:41:22 +01:00
2017-04-13 16:31:48 +02:00
function toggleSetting ( e , setting , id ) {
2019-02-13 08:46:18 +01:00
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
switch ( setting ) {
2020-11-02 13:54:20 +01:00
case 'warninglist_enable' :
formID = '#WarninglistIndexForm' ;
dataDiv = '#WarninglistData' ;
replacementForm = baseurl + '/warninglists/getToggleField/' ;
searchString = 'enabled' ;
2020-11-10 13:30:32 +01:00
var successCallback = function ( setting ) {
var icon = $ ( e . target ) . closest ( 'tr' ) . find ( '[data-path="Warninglist.enabled"] .fa' )
if ( setting ) {
icon . removeClass ( 'fa-times' ) . addClass ( 'fa-check' )
$ ( e . target ) . removeClass ( 'fa-play' ) . addClass ( 'fa-stop' )
} else {
icon . removeClass ( 'fa-check' ) . addClass ( 'fa-times' )
$ ( e . target ) . removeClass ( 'fa-stop' ) . addClass ( 'fa-play' )
}
}
2020-11-02 13:54:20 +01:00
break ;
case 'favourite_tag' :
formID = '#FavouriteTagIndexForm' ;
dataDiv = '#FavouriteTagData' ;
replacementForm = baseurl + '/favourite_tags/getToggleField/' ;
searchString = 'Adding' ;
break ;
case 'activate_object_template' :
formID = '#ObjectTemplateIndexForm' ;
dataDiv = '#ObjectTemplateData' ;
replacementForm = baseurl + '/ObjectTemplates/getToggleField/' ;
searchString = 'activated' ;
break ;
case 'noticelist_enable' :
formID = '#NoticelistIndexForm' ;
dataDiv = '#NoticelistData' ;
replacementForm = baseurl + '/noticelists/getToggleField/' ;
searchString = 'enabled' ;
break ;
2019-02-13 08:46:18 +01:00
}
$ ( dataDiv ) . val ( id ) ;
var formData = $ ( formID ) . serialize ( ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
data : formData ,
2021-02-19 15:38:03 +01:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
var result = data ;
if ( result . success ) {
var setting = false ;
if ( result . success . indexOf ( searchString ) > - 1 ) setting = true ;
2020-11-10 13:30:32 +01:00
if ( typeof successCallback === 'function' ) {
successCallback ( setting )
} else {
$ ( '#' + e . target . id ) . prop ( 'checked' , setting ) ;
}
2019-02-13 08:46:18 +01:00
}
handleGenericAjaxResponse ( data ) ;
} ,
complete : function ( ) {
2020-11-02 13:54:20 +01:00
$ . get ( replacementForm , function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( '#hiddenFormDiv' ) . html ( data ) ;
2021-02-19 15:38:03 +01:00
} ) . fail ( xhrFailCallback ) ;
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . hide ( ) ;
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
} ,
error : function ( ) {
handleGenericAjaxResponse ( { 'saved' : false , 'errors' : [ 'Request failed due to an unexpected error.' ] } ) ;
} ,
2021-02-19 15:38:03 +01:00
type : "post" ,
2019-02-13 08:46:18 +01:00
url : $ ( formID ) . attr ( 'action' ) ,
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-04-21 22:58:49 +02:00
2017-04-13 16:31:48 +02:00
function initiatePasswordReset ( id ) {
2022-04-21 17:39:07 +02:00
$ . get ( baseurl + "/users/initiatePasswordReset/" + id , openConfirmation ) . fail ( xhrFailCallback )
2017-04-13 16:31:48 +02:00
}
2015-05-27 17:46:01 +02:00
2017-04-13 16:31:48 +02:00
function submitPasswordReset ( id ) {
2019-02-13 08:46:18 +01:00
var formData = $ ( '#PromptForm' ) . serialize ( ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
data : formData ,
2020-10-31 13:37:38 +01:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
handleGenericAjaxResponse ( data ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
} ,
2020-10-31 13:37:38 +01:00
type : "post" ,
2021-02-19 15:38:03 +01:00
url : "/users/initiatePasswordReset/" + id ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-05-27 17:46:01 +02:00
2023-04-13 15:45:47 +02:00
function submitMessageForm ( url ) {
2019-02-13 08:46:18 +01:00
if ( ! $ ( '#PostMessage' ) . val ( ) ) {
showMessage ( "fail" , "Cannot submit empty message." ) ;
} else {
2023-04-13 15:45:47 +02:00
var message = $ ( '#PostMessage' ) . val ( )
fetchFormDataAjax ( url , function ( formData ) {
var $formData = $ ( formData ) ;
$formData . find ( '#PostMessage' ) . val ( message ) ;
$ . ajax ( {
data : $formData . find ( 'form' ) . serialize ( ) ,
beforeSend : function ( ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data ) {
showMessage ( "success" , "Message added." ) ;
$ ( '#top' ) . html ( data ) ;
} ,
error : function ( ) {
showMessage ( 'fail' , 'Could not add message.' ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
type : "post" ,
url : $formData . find ( 'form' ) . attr ( 'action' )
} ) ;
} ) ;
2019-02-13 08:46:18 +01:00
}
2017-04-13 16:31:48 +02:00
}
2016-06-20 19:11:39 +02:00
2022-04-17 19:43:39 +02:00
function acceptObject ( type , id ) {
2020-08-14 13:40:05 +02:00
var name = '#ShadowAttribute_' + id + '_accept' ;
2019-02-13 08:46:18 +01:00
var formData = $ ( name ) . serialize ( ) ;
$ . ajax ( {
data : formData ,
2022-04-17 19:43:39 +02:00
success : function ( data ) {
updateIndex ( null , 'event' ) ;
2019-02-13 08:46:18 +01:00
eventUnpublish ( ) ;
handleGenericAjaxResponse ( data ) ;
} ,
2020-08-14 13:40:05 +02:00
error : xhrFailCallback ,
type : "post" ,
2019-02-13 08:46:18 +01:00
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/shadow_attributes/accept/" + id ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-05-02 14:29:15 +02:00
2018-12-12 17:53:10 +01:00
function toggleCorrelation ( id , skip _reload ) {
if ( typeof skip _reload === "undefined" ) {
skip _reload = false ;
}
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
data : $ ( '#PromptForm' ) . serialize ( ) ,
2021-02-19 15:38:03 +01:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
handleGenericAjaxResponse ( data , skip _reload ) ;
$ ( "#correlation_toggle_" + id ) . prop ( 'checked' , ! $ ( "#correlation_toggle_" + id ) . is ( ':checked' ) ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
} ,
type : "post" ,
2021-02-19 15:38:03 +01:00
url : '/attributes/toggleCorrelation/' + id ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-14 15:54:17 +02:00
}
2019-02-26 16:24:01 +01:00
function toggleToIDS ( id , skip _reload ) {
if ( typeof skip _reload === "undefined" ) {
skip _reload = false ;
}
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-26 16:24:01 +01:00
data : $ ( '#PromptForm' ) . serialize ( ) ,
success : function ( data , textStatus ) {
handleGenericAjaxResponse ( data , skip _reload ) ;
$ ( "#toids_toggle_" + id ) . prop ( 'checked' , ! $ ( "#toids_toggle_" + id ) . is ( ':checked' ) ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
} ,
type : "post" ,
2021-02-19 15:38:03 +01:00
url : '/attributes/editField/' + id ,
2019-02-26 16:24:01 +01:00
} ) ;
}
2017-04-13 16:31:48 +02:00
function eventUnpublish ( ) {
2019-02-13 08:46:18 +01:00
$ ( '.publishButtons' ) . show ( ) ;
$ ( '.exportButtons' ) . hide ( ) ;
$ ( '.published' ) . hide ( ) ;
$ ( '.notPublished' ) . show ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-08-14 14:08:55 +02:00
2022-09-23 12:04:55 +02:00
function updateIndex ( id , context , callback ) {
2019-02-13 08:46:18 +01:00
var url , div ;
2022-04-17 17:03:41 +02:00
if ( context === 'event' ) {
2019-02-13 08:46:18 +01:00
if ( typeof currentUri == 'undefined' ) {
location . reload ( ) ;
return true ;
}
url = currentUri ;
div = "#attributes_div" ;
2022-04-17 17:03:41 +02:00
} else if ( context === 'template' ) {
2021-02-19 15:38:03 +01:00
url = "/template_elements/index/" + id ;
2019-02-13 08:46:18 +01:00
div = "#templateElements" ;
}
2021-02-19 15:38:03 +01:00
xhr ( {
dataType : "html" ,
2022-09-23 12:04:55 +02:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( div ) . html ( data ) ;
2022-09-23 12:04:55 +02:00
if ( typeof callback !== "undefined" ) {
callback ( "success" ) ;
}
2019-02-13 08:46:18 +01:00
if ( typeof genericPopupCallback !== "undefined" ) {
genericPopupCallback ( "success" ) ;
} else {
console . log ( "genericPopupCallback function not defined" ) ;
}
2019-06-13 09:16:34 +02:00
if ( typeof timelinePopupCallback !== "undefined" ) {
timelinePopupCallback ( "success" ) ;
} else {
console . log ( "timelinepopupcallback function not defined" ) ;
}
2019-02-13 08:46:18 +01:00
} ,
url : url ,
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-14 15:13:01 +02:00
2022-04-17 09:39:47 +02:00
function updateFieldOnSuccess ( $td , type , id , field ) {
var objectType = type === 'Object' ? 'objects' : 'attributes' ;
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2020-10-15 20:20:44 +02:00
beforeSend : function ( ) {
if ( field !== 'timestamp' ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . show ( ) ;
}
} ,
2022-09-27 12:25:53 +02:00
dataType : "html" ,
2019-02-13 08:46:18 +01:00
cache : false ,
2022-04-16 21:33:38 +02:00
success : function ( data ) {
2020-10-15 20:20:44 +02:00
if ( field !== 'timestamp' ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . hide ( ) ;
2022-04-17 09:39:47 +02:00
$td . find ( '.inline-field-placeholder' ) . remove ( ) ;
$td . find ( '.inline-field-solid' ) . html ( data ) . show ( ) ;
2019-02-13 08:46:18 +01:00
} else {
2022-04-17 09:39:47 +02:00
$td . parent ( ) . find ( 'td.timestamp' ) . html ( data ) ;
2019-02-13 08:46:18 +01:00
}
2020-10-15 20:20:44 +02:00
popoverStartup ( ) ; // reactive popovers
2019-02-13 08:46:18 +01:00
} ,
2021-02-19 15:38:03 +01:00
error : xhrFailCallback ,
2022-04-17 09:39:47 +02:00
url : baseurl + "/" + objectType + "/fetchViewValue/" + id + "/" + field ,
2019-06-13 09:16:34 +02:00
} ) ;
}
2022-04-17 17:03:41 +02:00
function activateField ( $td , type , id , field ) {
2022-04-16 21:33:38 +02:00
resetEditHoverForms ( ) ;
2020-10-15 09:48:45 +02:00
if ( type === 'denyForm' ) {
return ;
}
2022-04-16 21:33:38 +02:00
var objectType = type === 'Object' ? 'objects' : 'attributes' ;
2019-02-13 08:46:18 +01:00
var name = '#' + type + '_' + id + '_' + field ;
2022-04-16 21:33:38 +02:00
2021-02-19 15:38:03 +01:00
xhr ( {
2020-10-15 09:48:45 +02:00
dataType : "html" ,
success : function ( data ) {
2022-04-16 21:33:38 +02:00
var $placeholder = $ ( '<div class="inline-field-placeholder"></div>' ) . html ( data ) ;
$td . find ( ".inline-field-solid" ) . before ( $placeholder ) ;
2022-04-17 17:03:41 +02:00
postActivationScripts ( $td , name , type , id , field ) ;
2022-04-16 21:33:38 +02:00
$td . find ( ".inline-field-solid" ) . hide ( ) ;
2019-02-13 08:46:18 +01:00
} ,
2021-02-19 15:38:03 +01:00
url : "/" + objectType + "/fetchEditForm/" + id + "/" + field ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-17 11:44:40 +02:00
2014-04-24 15:10:08 +02:00
//if someone clicks an inactive field, replace it with the hidden form field. Also, focus it and bind a focusout event, so that it gets saved if the user clicks away.
//If a user presses enter, submit the form
2022-04-17 17:03:41 +02:00
function postActivationScripts ( $td , name , type , id , field ) {
2022-04-16 21:33:38 +02:00
var $field = $ ( name + '_field' ) ;
$field . focus ( ) ;
inputFieldButtonActive ( $field ) ;
if ( field === 'value' || field === 'comment' ) {
autoresize ( $field [ 0 ] ) ;
$field . on ( 'keyup' , function ( ) {
2019-02-13 08:46:18 +01:00
autoresize ( this ) ;
} ) ;
}
2022-04-16 21:33:38 +02:00
2019-02-13 08:46:18 +01:00
$ ( name + '_form' ) . submit ( function ( e ) {
e . preventDefault ( ) ;
2022-04-17 17:03:41 +02:00
submitForm ( $td , type , id , field ) ;
2019-02-13 08:46:18 +01:00
return false ;
2022-04-16 21:33:38 +02:00
} ) . bind ( "focusout" , function ( ) {
inputFieldButtonPassive ( $field ) ;
} ) . bind ( "focusin" , function ( ) {
inputFieldButtonActive ( $field ) ;
2019-02-13 08:46:18 +01:00
} ) ;
2022-04-16 21:33:38 +02:00
var $inlineInputContainer = $field . closest ( '.inline-input-container' ) ;
2019-02-13 08:46:18 +01:00
2022-04-16 21:33:38 +02:00
$inlineInputContainer . children ( '.inline-input-accept' ) . bind ( 'click' , function ( ) {
2022-04-17 17:03:41 +02:00
submitForm ( $td , type , id , field ) ;
2019-02-13 08:46:18 +01:00
} ) ;
2022-04-16 21:33:38 +02:00
$inlineInputContainer . children ( '.inline-input-decline' ) . bind ( 'click' , function ( ) {
resetEditHoverForms ( ) ;
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-17 11:44:40 +02:00
2022-04-17 17:03:41 +02:00
function quickEditHover ( td , type , id , field ) {
2018-12-12 15:16:01 +01:00
var $td = $ ( td ) ;
2018-12-12 14:45:18 +01:00
$td . find ( '#quickEditButton' ) . remove ( ) ; // clean all similar if exist
2018-12-12 15:16:01 +01:00
var $div = $ ( '<div id="quickEditButton"></div>' ) ;
2018-12-12 14:45:18 +01:00
$div . addClass ( 'quick-edit-row-div' ) ;
2018-12-12 15:16:01 +01:00
var $span = $ ( '<span></span>' ) ;
2018-12-12 14:45:18 +01:00
$span . addClass ( 'fa-as-icon fa fa-edit' ) ;
$span . css ( 'font-size' , '12px' ) ;
$div . append ( $span ) ;
2022-04-16 21:33:38 +02:00
$td . find ( ".inline-field-solid" ) . append ( $div ) ;
2018-12-12 14:45:18 +01:00
$span . click ( function ( ) {
2022-04-17 17:03:41 +02:00
activateField ( $td , type , id , field ) ;
2018-12-12 14:45:18 +01:00
} ) ;
2018-12-12 15:16:01 +01:00
$td . off ( 'mouseleave' ) . on ( 'mouseleave' , function ( ) {
2018-12-12 14:45:18 +01:00
$div . remove ( ) ;
} ) ;
}
2022-04-17 17:03:41 +02:00
function addSighting ( type , attribute _id ) {
2021-01-09 13:48:41 +01:00
var $sightingForm = $ ( '#SightingForm' ) ;
$ ( 'input[name="data[Sighting][type]"]' , $sightingForm ) . val ( type ) ;
$ ( 'input[name="data[Sighting][id]"]' , $sightingForm ) . val ( attribute _id ) ;
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2021-01-09 13:48:41 +01:00
data : $sightingForm . serialize ( ) ,
2019-02-13 08:46:18 +01:00
cache : false ,
2021-01-09 13:48:41 +01:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
handleGenericAjaxResponse ( data ) ;
var result = data ;
if ( result . saved == true ) {
2021-01-09 13:48:41 +01:00
// Update global sighting counter
$ ( '.sightingsCounter' ) . each ( function ( ) {
2019-02-13 08:46:18 +01:00
$ ( this ) . html ( parseInt ( $ ( this ) . html ( ) ) + 1 ) ;
} ) ;
2022-04-17 17:03:41 +02:00
updateIndex ( null , 'event' ) ;
2019-02-13 08:46:18 +01:00
}
} ,
2021-02-19 15:38:03 +01:00
error : function ( xhr ) {
xhrFailCallback ( xhr ) ;
2022-04-17 17:03:41 +02:00
updateIndex ( null , 'event' ) ;
2019-02-13 08:46:18 +01:00
} ,
2020-10-05 20:38:58 +02:00
type : "post" ,
2021-01-09 13:48:41 +01:00
url : baseurl + "/sightings/add/" ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-12-20 13:41:52 +01:00
2022-04-16 21:33:38 +02:00
function resetEditHoverForms ( ) {
$ ( '.inline-field-solid' ) . show ( ) ;
$ ( '.inline-field-placeholder' ) . remove ( ) ;
}
2017-04-13 16:31:48 +02:00
function resetForms ( ) {
2019-02-13 08:46:18 +01:00
$ ( '.inline-field-solid' ) . show ( ) ;
2022-04-16 21:33:38 +02:00
$ ( '.inline-field-placeholder' ) . hide ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-14 15:13:01 +02:00
2017-04-13 16:31:48 +02:00
function inputFieldButtonActive ( selector ) {
2019-02-13 08:46:18 +01:00
$ ( selector ) . closest ( '.inline-input-container' ) . children ( '.inline-input-accept' ) . removeClass ( 'inline-input-passive' ) . addClass ( 'inline-input-active' ) ;
$ ( selector ) . closest ( '.inline-input-container' ) . children ( '.inline-input-decline' ) . removeClass ( 'inline-input-passive' ) . addClass ( 'inline-input-active' ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-14 15:13:01 +02:00
2017-04-13 16:31:48 +02:00
function inputFieldButtonPassive ( selector ) {
2019-02-13 08:46:18 +01:00
$ ( selector ) . closest ( '.inline-input-container' ) . children ( '.inline-input-accept' ) . addClass ( 'inline-input-passive' ) . removeClass ( 'inline-input-active' ) ;
$ ( selector ) . closest ( '.inline-input-container' ) . children ( '.inline-input-daecline' ) . addClass ( 'inline-input-passive' ) . removeClass ( 'inline-input-active' ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-14 15:13:01 +02:00
2017-04-13 16:31:48 +02:00
function autoresize ( textarea ) {
textarea . style . height = '20px' ;
textarea . style . height = ( textarea . scrollHeight ) + 'px' ;
}
2014-04-14 15:13:01 +02:00
// submit the form - this can be triggered by unfocusing the activated form field or by submitting the form (hitting enter)
2016-06-04 01:10:45 +02:00
// after the form is submitted, intercept the response and act on it
2022-04-17 17:03:41 +02:00
function submitForm ( $td , type , id , field ) {
2019-02-13 08:46:18 +01:00
var object _type = 'attributes' ;
var name = '#' + type + '_' + id + '_' + field ;
2022-04-17 09:39:47 +02:00
if ( type === 'Object' ) {
2019-06-13 09:16:34 +02:00
object _type = 'objects' ;
2019-02-13 08:46:18 +01:00
}
$ . ajax ( {
data : $ ( name + '_field' ) . closest ( "form" ) . serialize ( ) ,
cache : false ,
2022-04-17 09:39:47 +02:00
success : function ( data ) {
2022-04-17 17:03:41 +02:00
handleAjaxEditResponse ( $td , data , type , id , field ) ;
2019-02-13 08:46:18 +01:00
} ,
2022-04-17 09:39:47 +02:00
error : function ( xhr ) {
2021-02-19 15:38:03 +01:00
xhrFailCallback ( xhr ) ;
2022-04-17 17:03:41 +02:00
updateIndex ( null , 'event' ) ;
2019-02-13 08:46:18 +01:00
} ,
2022-04-17 09:39:47 +02:00
type : "post" ,
url : baseurl + "/" + object _type + "/editField/" + id
2019-02-13 08:46:18 +01:00
} ) ;
$ ( name + '_field' ) . unbind ( "keyup" ) ;
$ ( name + '_form' ) . unbind ( "focusout" ) ;
return false ;
2021-02-19 15:38:03 +01:00
}
2014-04-14 15:13:01 +02:00
2022-04-17 14:47:23 +02:00
// Event attributes and attributes index and search
( function ( ) {
$ ( document . body ) . on ( 'click' , '.correlation-toggle' , function ( ) {
var attribute _id = $ ( this ) . parents ( 'tr' ) . data ( 'primary-id' ) ;
getPopup ( attribute _id , 'attributes' , 'toggleCorrelation' , '' , '#confirmation_box' ) ;
return false ;
} ) ;
$ ( document . body ) . on ( 'click' , '.toids-toggle' , function ( ) {
var attribute _id = $ ( this ) . parents ( 'tr' ) . data ( 'primary-id' ) ;
getPopup ( attribute _id , 'attributes' , 'toggleToIDS' , '' , '#confirmation_box' ) ;
return false ;
} ) ;
2022-04-21 16:20:25 +02:00
$ ( document . body ) . on ( 'click' , '.screenshot' , function ( ) {
screenshotPopup ( $ ( this ) . attr ( 'src' ) , $ ( this ) . attr ( 'title' ) ) ;
} ) ;
2022-04-17 17:12:10 +02:00
// Show quick edit hover icon for attributes and objects
$ ( document . body ) . on ( 'mouseenter' , '[data-edit-field]' , function ( ) {
var $tr = $ ( this ) . parents ( 'tr' ) ;
var objectId = $tr . data ( 'primary-id' ) ;
var type = $tr . attr ( 'id' ) . startsWith ( 'Object' ) ? 'Object' : 'Attribute' ;
var field = $ ( this ) . data ( 'edit-field' ) ;
quickEditHover ( this , type , objectId , field ) ;
} ) ;
2022-10-12 20:03:10 +02:00
// Show popover with advanced sightings information about given or selected attributes
$ ( document . body ) . on ( 'click' , '.sightings_advanced_add' , function ( e ) {
e . preventDefault ( ) ;
2022-05-05 17:14:26 +02:00
var object _context = $ ( this ) . data ( 'object-context' ) ;
var object _id = $ ( this ) . data ( 'object-id' ) ;
if ( object _id === 'selected' ) {
var selected = [ ] ;
$ ( ".select_attribute:checked" ) . each ( function ( ) {
selected . push ( $ ( this ) . data ( "id" ) ) ;
} ) ;
object _id = selected . join ( '|' ) ;
}
var url = baseurl + "/sightings/advanced/" + object _id + "/" + object _context ;
genericPopup ( url , '#popover_box' ) ;
} ) ;
2022-04-17 14:47:23 +02:00
} ) ( ) ;
2019-01-09 16:09:05 +01:00
function quickSubmitTagForm ( selected _tag _ids , addData ) {
2019-02-13 08:46:18 +01:00
var event _id = addData . id ;
2019-07-08 11:39:41 +02:00
var localFlag = '' ;
if ( undefined != addData [ 'local' ] && addData [ 'local' ] ) {
localFlag = '/local:1' ;
}
2021-02-19 15:38:03 +01:00
var url = baseurl + "/events/addTag/" + event _id + localFlag ;
2019-07-08 11:39:41 +02:00
fetchFormDataAjax ( url , function ( formData ) {
2022-04-24 14:53:43 +02:00
var $formData = $ ( formData ) ;
$formData . find ( '#EventTag' ) . val ( JSON . stringify ( selected _tag _ids ) ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2022-04-24 14:53:43 +02:00
data : $formData . serialize ( ) ,
2021-02-19 15:38:03 +01:00
success : function ( data ) {
2019-06-07 14:44:39 +02:00
handleGenericAjaxResponse ( data ) ;
} ,
2021-02-19 15:38:03 +01:00
error : function ( ) {
2019-06-07 14:44:39 +02:00
showMessage ( 'fail' , 'Could not add tag.' ) ;
} ,
2021-02-19 15:38:03 +01:00
complete : function ( ) {
2022-04-24 14:53:43 +02:00
loadEventTags ( event _id ) ;
loadGalaxies ( event _id , 'event' ) ;
2019-06-07 14:44:39 +02:00
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( ".loading" ) . hide ( ) ;
} ,
2021-02-19 15:38:03 +01:00
type : "post" ,
url : url
2019-06-07 14:44:39 +02:00
} ) ;
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-11-27 17:41:41 +01:00
2019-01-09 14:19:14 +01:00
function quickSubmitAttributeTagForm ( selected _tag _ids , addData ) {
2019-02-13 08:46:18 +01:00
var attribute _id = addData . id ;
2019-07-08 11:39:41 +02:00
var localFlag = '' ;
if ( undefined != addData [ 'local' ] && addData [ 'local' ] ) {
localFlag = '/local:1' ;
}
2021-02-19 15:38:03 +01:00
var url = baseurl + "/attributes/addTag/" + attribute _id + localFlag ;
2019-07-08 11:39:41 +02:00
fetchFormDataAjax ( url , function ( formData ) {
2022-04-24 14:53:43 +02:00
var $formData = $ ( formData ) ;
$formData . find ( '#AttributeTag' ) . val ( JSON . stringify ( selected _tag _ids ) ) ;
if ( attribute _id === 'selected' ) {
$formData . find ( '#AttributeAttributeIds' ) . val ( getSelected ( ) ) ;
2019-06-07 14:44:39 +02:00
}
2021-02-19 15:38:03 +01:00
xhr ( {
2022-04-24 14:53:43 +02:00
data : $formData . serialize ( ) ,
2021-02-19 15:38:03 +01:00
success : function ( data ) {
2019-06-07 14:44:39 +02:00
if ( attribute _id == 'selected' ) {
updateIndex ( 0 , 'event' ) ;
} else {
loadAttributeTags ( attribute _id ) ;
loadGalaxies ( attribute _id , 'attribute' ) ;
}
handleGenericAjaxResponse ( data ) ;
} ,
error : function ( ) {
showMessage ( 'fail' , 'Could not add tag.' ) ;
2019-02-13 08:46:18 +01:00
loadAttributeTags ( attribute _id ) ;
2019-01-06 21:22:01 +01:00
loadGalaxies ( attribute _id , 'attribute' ) ;
2019-06-07 14:44:39 +02:00
} ,
complete : function ( ) {
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( ".loading" ) . hide ( ) ;
} ,
type : "post" ,
2019-07-08 11:39:41 +02:00
url : url
2019-06-07 14:44:39 +02:00
} ) ;
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-09-29 16:52:47 +02:00
2019-01-09 16:09:05 +01:00
function quickSubmitTagCollectionTagForm ( selected _tag _ids , addData ) {
2019-02-13 08:46:18 +01:00
var tag _collection _id = addData . id ;
2019-07-08 11:39:41 +02:00
var localFlag = '' ;
if ( undefined != addData [ 'local' ] && addData [ 'local' ] ) {
localFlag = '/local:1' ;
}
2022-05-22 11:33:57 +02:00
var url = baseurl + "/tag_collections/addTag/" + tag _collection _id + localFlag ;
2019-07-08 11:39:41 +02:00
fetchFormDataAjax ( url , function ( formData ) {
2022-05-22 11:33:57 +02:00
var $formData = $ ( formData ) ;
$formData . find ( '#TagCollectionTag' ) . val ( JSON . stringify ( selected _tag _ids ) ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2022-05-22 11:33:57 +02:00
data : $formData . serialize ( ) ,
success : function ( data ) {
2019-06-07 14:44:39 +02:00
handleGenericAjaxResponse ( data ) ;
refreshTagCollectionRow ( tag _collection _id ) ;
} ,
error : function ( ) {
showMessage ( 'fail' , 'Could not add tag.' ) ;
2022-05-22 15:26:58 +02:00
refreshTagCollectionRow ( tag _collection _id ) ;
2019-06-07 14:44:39 +02:00
} ,
complete : function ( ) {
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( ".loading" ) . hide ( ) ;
} ,
type : "post" ,
2019-07-08 11:39:41 +02:00
url : url
2019-06-07 14:44:39 +02:00
} ) ;
2019-02-13 08:46:18 +01:00
} ) ;
2018-12-20 21:48:04 +01:00
}
2018-12-25 14:04:01 +01:00
function refreshTagCollectionRow ( tag _collection _id ) {
$ . ajax ( {
type : "get" ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/tag_collections/getRow/" + tag _collection _id ,
2018-12-25 14:04:01 +01:00
error : function ( ) {
showMessage ( 'fail' , 'Could not fetch updates to the modified row.' ) ;
} ,
2022-05-22 15:26:58 +02:00
success : function ( data ) {
2018-12-25 14:04:01 +01:00
$ ( '[data-row-id="' + tag _collection _id + '"]' ) . replaceWith ( data ) ;
}
} ) ;
}
2022-10-14 15:49:24 +02:00
function modifyTagRelationship ( ) {
2022-10-14 16:08:50 +02:00
event . preventDefault ( ) ;
var $form = $ ( event . target ) ;
2022-10-14 15:49:24 +02:00
var action = $form . attr ( "action" ) ;
$ . ajax ( {
type : "post" ,
url : action ,
data : $form . serialize ( ) ,
error : xhrFailCallback ,
2022-10-14 16:08:50 +02:00
success : function ( data ) {
if ( data . saved ) {
$ ( '#genericModal' ) . modal ( 'hide' ) ;
if ( "attribute_id" in data . data ) {
var attribute _id = data . data . attribute _id ;
loadAttributeTags ( attribute _id ) ;
loadGalaxies ( attribute _id , 'attribute' ) ;
} else {
var event _id = data . data . event _id ;
loadEventTags ( event _id ) ;
loadGalaxies ( event _id , 'event' ) ;
}
2022-10-14 15:49:24 +02:00
}
}
} ) ;
2022-10-14 16:08:50 +02:00
return false ;
2022-10-14 15:49:24 +02:00
}
2022-04-17 17:03:41 +02:00
function handleAjaxEditResponse ( $td , data , type , id , field ) {
2022-04-16 21:33:38 +02:00
var responseArray = data ;
2020-10-18 13:35:16 +02:00
if ( type === 'Attribute' ) {
2019-02-13 08:46:18 +01:00
if ( responseArray . saved ) {
2019-06-13 09:16:34 +02:00
var msg = responseArray . success !== undefined ? responseArray . success : responseArray . message ;
showMessage ( 'success' , msg ) ;
2022-04-17 09:39:47 +02:00
updateFieldOnSuccess ( $td , type , id , field ) ;
updateFieldOnSuccess ( $td , type , id , 'timestamp' ) ;
2019-02-13 08:46:18 +01:00
eventUnpublish ( ) ;
} else {
showMessage ( 'fail' , 'Validation failed: ' + responseArray . errors . value ) ;
2022-04-17 09:39:47 +02:00
updateFieldOnSuccess ( $td , type , id , field ) ;
2019-02-13 08:46:18 +01:00
}
2020-10-18 13:35:16 +02:00
} else if ( type === 'ShadowAttribute' ) {
2022-04-17 17:03:41 +02:00
updateIndex ( null , 'event' ) ;
2020-10-18 13:35:16 +02:00
} else if ( type === 'Object' ) {
2019-06-13 09:16:34 +02:00
if ( responseArray . saved ) {
2020-10-18 13:35:16 +02:00
showMessage ( 'success' , responseArray . message ) ;
2022-04-17 09:39:47 +02:00
updateFieldOnSuccess ( $td , type , id , field ) ;
updateFieldOnSuccess ( $td , type , id , 'timestamp' ) ;
2019-06-13 09:16:34 +02:00
eventUnpublish ( ) ;
} else {
showMessage ( 'fail' , 'Validation failed: ' + responseArray . errors . value ) ;
2022-04-17 09:39:47 +02:00
updateFieldOnSuccess ( $td , type , id , field ) ;
2019-06-13 09:16:34 +02:00
}
2019-02-13 08:46:18 +01:00
}
if ( responseArray . hasOwnProperty ( 'check_publish' ) ) {
checkAndSetPublishedInfo ( ) ;
}
2017-04-13 16:31:48 +02:00
}
2014-04-14 15:13:01 +02:00
2018-12-13 10:07:35 +01:00
function handleGenericAjaxResponse ( data , skip _reload ) {
2019-02-13 08:46:18 +01:00
if ( typeof skip _reload === "undefined" ) {
2018-12-13 10:07:35 +01:00
skip _reload = false ;
}
2019-02-13 08:46:18 +01:00
if ( typeof data == 'string' ) {
responseArray = JSON . parse ( data ) ;
} else {
responseArray = data ;
}
// remove remaining popovers
cancelPrompt ( ) ;
// in case the origin node has been deleted (e.g. tags)
$ ( '.popover' ) . remove ( ) ;
if ( responseArray . saved ) {
showMessage ( 'success' , responseArray . success ) ;
if ( responseArray . hasOwnProperty ( 'check_publish' ) ) {
checkAndSetPublishedInfo ( skip _reload ) ;
}
return true ;
} else {
showMessage ( 'fail' , responseArray . errors ) ;
return false ;
}
2017-04-13 16:31:48 +02:00
}
2014-04-16 15:52:25 +02:00
2017-04-13 16:31:48 +02:00
function toggleAllAttributeCheckboxes ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( ".select_all" ) . is ( ":checked" ) ) {
2022-04-18 11:21:30 +02:00
$ ( ".select_attribute, .select_proposal" ) . prop ( "checked" , true ) ;
2019-02-13 08:46:18 +01:00
} else {
2022-04-18 11:21:30 +02:00
$ ( ".select_attribute, .select_proposal" ) . prop ( "checked" , false ) ;
2019-02-13 08:46:18 +01:00
}
2017-04-13 16:31:48 +02:00
}
2014-04-16 15:52:25 +02:00
2017-06-01 09:45:10 +02:00
function toggleAllCheckboxes ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( ".select_all" ) . is ( ":checked" ) ) {
$ ( ".select" ) . prop ( "checked" , true ) ;
} else {
$ ( ".select" ) . prop ( "checked" , false ) ;
}
2017-06-01 09:45:10 +02:00
}
2017-04-13 16:31:48 +02:00
function toggleAllTaxonomyCheckboxes ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( ".select_all" ) . is ( ":checked" ) ) {
$ ( ".select_taxonomy" ) . prop ( "checked" , true ) ;
} else {
$ ( ".select_taxonomy" ) . prop ( "checked" , false ) ;
}
2017-04-13 16:31:48 +02:00
}
2015-11-26 04:31:24 +01:00
2017-04-13 16:31:48 +02:00
function attributeListAnyAttributeCheckBoxesChecked ( ) {
2021-02-02 12:22:26 +01:00
if ( $ ( '.select_attribute:checked' ) . length > 0 ) {
$ ( '.mass-select' ) . removeClass ( 'hidden' ) ;
2022-09-26 19:50:58 +02:00
if ( $ ( "#object-button" ) . length ) {
$ ( "#object-button" ) . removeClass ( 'last' ) ;
} else {
$ ( '#create-button' ) . removeClass ( 'last' ) ;
}
2021-02-02 12:22:26 +01:00
} else {
$ ( '.mass-select' ) . addClass ( 'hidden' ) ;
2022-09-26 19:50:58 +02:00
if ( $ ( "#object-button" ) . length ) {
$ ( "#object-button" ) . addClass ( 'last' ) ;
} else {
$ ( '#create-button' ) . addClass ( 'last' ) ;
}
2021-02-02 12:22:26 +01:00
}
2017-04-13 16:31:48 +02:00
}
2014-04-16 15:52:25 +02:00
2018-01-15 17:25:11 +01:00
function listCheckboxesChecked ( ) {
2022-10-24 15:41:21 +02:00
if ( $ ( '.select:checked' ) . length > 0 ) {
$ ( '.mass-select' ) . removeClass ( 'hidden' ) ;
} else {
$ ( '.mass-select' ) . addClass ( 'hidden' )
}
2017-06-01 09:45:10 +02:00
}
2022-10-26 16:50:21 +02:00
function listCheckboxesCheckedEventIndex ( ) {
// Show mass delete just when user has permission to delete at least one of selected event
if ( $ ( '.select:checked[data-can-modify="1"]' ) . length > 0 ) {
$ ( '.mass-delete' ) . removeClass ( 'hidden' ) ;
} else {
$ ( '.mass-delete' ) . addClass ( 'hidden' ) ;
}
if ( $ ( '.select:checked' ) . length > 0 ) {
$ ( '.mass-export' ) . removeClass ( 'hidden' ) ;
} else {
$ ( '.mass-export' ) . addClass ( 'hidden' ) ;
}
2017-06-01 09:45:10 +02:00
}
2017-04-13 16:31:48 +02:00
function attributeListAnyProposalCheckBoxesChecked ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '.select_proposal:checked' ) . length > 0 ) $ ( '.mass-proposal-select' ) . removeClass ( 'hidden' ) ;
else $ ( '.mass-proposal-select' ) . addClass ( 'hidden' ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-16 15:52:25 +02:00
2017-04-13 16:31:48 +02:00
function taxonomyListAnyCheckBoxesChecked ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '.select_taxonomy:checked' ) . length > 0 ) $ ( '.mass-select' ) . show ( ) ;
else $ ( '.mass-select' ) . hide ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-11-26 04:31:24 +01:00
2017-06-01 09:45:10 +02:00
function multiSelectDeleteEvents ( ) {
2019-02-13 08:46:18 +01:00
var selected = [ ] ;
2022-10-26 16:50:21 +02:00
$ ( ".select:checked" ) . each ( function ( ) {
if ( $ ( this ) . data ( 'can-modify' ) ) {
2019-02-13 08:46:18 +01:00
var temp = $ ( this ) . data ( "id" ) ;
if ( temp != null ) {
selected . push ( temp ) ;
}
}
} ) ;
2022-03-27 22:07:36 +02:00
deleteEventPopup ( JSON . stringify ( selected ) ) ;
}
function deleteEventPopup ( eventId ) {
$ . get ( baseurl + "/events/delete/" + eventId , openConfirmation ) . fail ( xhrFailCallback ) ;
2017-06-01 09:45:10 +02:00
}
2022-03-10 10:18:39 +01:00
function multiSelectExportEvents ( ) {
var selected = [ ] ;
2022-10-26 16:50:21 +02:00
$ ( ".select:checked" ) . each ( function ( ) {
var temp = $ ( this ) . data ( "id" ) ;
if ( temp != null ) {
selected . push ( temp ) ;
2022-03-10 10:18:39 +01:00
}
} ) ;
openGenericModal ( baseurl + "/events/restSearchExport/" + JSON . stringify ( selected ) )
}
2018-03-30 23:30:54 +02:00
function multiSelectToggleFeeds ( on , cache ) {
2019-02-13 08:46:18 +01:00
var selected = [ ] ;
$ ( ".select" ) . each ( function ( ) {
if ( $ ( this ) . is ( ":checked" ) ) {
var temp = $ ( this ) . data ( "id" ) ;
if ( temp != null ) {
selected . push ( temp ) ;
}
}
} ) ;
2022-04-21 17:39:07 +02:00
$ . get ( baseurl + "/feeds/toggleSelected/" + on + "/" + cache + "/" + JSON . stringify ( selected ) , openConfirmation ) . fail ( xhrFailCallback ) ;
2018-01-15 17:25:11 +01:00
}
2022-07-26 11:07:52 +02:00
function multiSelectToggleField ( scope , action , fieldName , enabled , inputID ) {
2021-05-03 16:11:18 +02:00
var selected = [ ] ;
2022-05-22 11:33:57 +02:00
$ ( ".select:checked" ) . each ( function ( ) {
var temp = $ ( this ) . data ( "id" ) ;
if ( temp != null ) {
selected . push ( temp ) ;
2021-05-03 16:11:18 +02:00
}
} ) ;
$ . get ( baseurl + "/" + scope + "/" + action + "/" + fieldName + "/" + enabled , function ( data ) {
2022-05-22 11:33:57 +02:00
var $formData = $ ( data ) ;
2022-07-26 11:07:52 +02:00
$ ( 'body' ) . append ( $formData )
$formData . find ( inputID ) . val ( JSON . stringify ( selected ) ) ;
2022-05-22 11:33:57 +02:00
$formData . find ( "form" ) [ 0 ] . submit ( ) ;
2021-05-03 16:11:18 +02:00
} ) . fail ( xhrFailCallback ) ;
}
2020-09-07 18:14:01 +02:00
function multiSelectDeleteEventBlocklist ( on , cache ) {
2019-06-12 15:27:39 +02:00
var selected = [ ] ;
$ ( ".select" ) . each ( function ( ) {
if ( $ ( this ) . is ( ":checked" ) ) {
var temp = $ ( this ) . data ( "id" ) ;
if ( temp != null ) {
selected . push ( temp ) ;
}
}
} ) ;
2022-04-21 17:39:07 +02:00
$ . get ( baseurl + "/eventBlocklists/massDelete?ids=" + JSON . stringify ( selected ) , openConfirmation ) . fail ( xhrFailCallback ) ;
2019-06-12 15:27:39 +02:00
}
2022-04-18 11:21:30 +02:00
function multiSelectAction ( event _id , context ) {
2019-02-13 08:46:18 +01:00
var settings = {
2020-10-15 19:20:43 +02:00
deleteAttributes : {
confirmation : "Are you sure you want to delete all selected attributes?" ,
controller : "attributes" ,
camelCase : "Attribute" ,
alias : "attribute" ,
action : "delete"
} ,
acceptProposals : {
confirmation : "Are you sure you want to accept all selected proposals?" ,
controller : "shadow_attributes" ,
camelCase : "ShadowAttribute" ,
alias : "proposal" ,
action : "accept"
} ,
discardProposals : {
confirmation : "Are you sure you want to discard all selected proposals?" ,
controller : "shadow_attributes" ,
camelCase : "ShadowAttribute" ,
alias : "proposal" ,
action : "discard"
} ,
2019-02-13 08:46:18 +01:00
} ;
var answer = confirm ( "Are you sure you want to " + settings [ context ] [ "action" ] + " all selected " + settings [ context ] [ "alias" ] + "s?" ) ;
if ( answer ) {
var selected = [ ] ;
2022-04-18 11:21:30 +02:00
$ ( ".select_" + settings [ context ] [ "alias" ] + ":checked" ) . each ( function ( ) {
selected . push ( $ ( this ) . data ( "id" ) ) ;
2019-02-13 08:46:18 +01:00
} ) ;
$ ( '#' + settings [ context ] [ "camelCase" ] + 'Ids' + settings [ context ] [ "action" ] . ucfirst ( ) ) . attr ( 'value' , JSON . stringify ( selected ) ) ;
var formData = $ ( '#' + settings [ context ] [ "action" ] + '_selected' ) . serialize ( ) ;
if ( context == 'deleteAttributes' ) {
var url = $ ( '#delete_selected' ) . attr ( 'action' ) ;
} else {
2022-04-18 11:21:30 +02:00
var url = baseurl + "/" + settings [ context ] [ "controller" ] + "/" + settings [ context ] [ "action" ] + "Selected/" + event _id ;
2019-02-13 08:46:18 +01:00
}
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
data : formData ,
type : "POST" ,
url : url ,
2020-10-15 19:20:43 +02:00
success : function ( data ) {
2022-04-18 11:21:30 +02:00
updateIndex ( null , 'event' ) ;
2019-02-13 08:46:18 +01:00
var result = handleGenericAjaxResponse ( data ) ;
2020-10-15 19:20:43 +02:00
if ( settings [ context ] [ "action" ] != "discard" && result == true ) {
eventUnpublish ( ) ;
}
} ,
2019-02-13 08:46:18 +01:00
} ) ;
}
return false ;
2017-04-13 16:31:48 +02:00
}
2014-04-24 15:10:08 +02:00
2017-04-13 16:31:48 +02:00
function editSelectedAttributes ( event ) {
2019-02-13 08:46:18 +01:00
var selectedAttributeIds = getSelected ( ) ;
2020-07-27 12:10:53 +02:00
var data = { selected _ids : selectedAttributeIds }
2020-08-16 13:31:31 +02:00
simplePopup ( baseurl + "/attributes/getMassEditForm/" + event , 'POST' , data ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-24 15:10:08 +02:00
2017-04-13 16:31:48 +02:00
function addSelectedTaxonomies ( taxonomy ) {
2022-04-21 17:39:07 +02:00
$ . get ( baseurl + "/taxonomies/taxonomyMassConfirmation/" + taxonomy , openConfirmation ) . fail ( xhrFailCallback ) ;
2017-04-13 16:31:48 +02:00
}
2015-11-26 04:31:24 +01:00
2019-05-08 16:56:19 +02:00
function proposeObjectsFromSelectedAttributes ( clicked , event _id ) {
var selectedAttributeIds = getSelected ( ) ;
popoverPopup ( clicked , event _id + '/' + selectedAttributeIds , 'objects' , 'proposeObjectsFromAttributes' ) ;
}
2022-10-11 08:01:49 +02:00
function bulkAddRelationshipToSelectedAttributes ( clicked , event _id ) {
var selectedAttributeIds = getSelected ( ) ;
var url = baseurl + '/objectReferences/bulkAdd/' + event _id + '/' + selectedAttributeIds
openGenericModal ( url )
}
2018-09-10 12:53:33 +02:00
function hideSelectedTags ( taxonomy ) {
2022-04-21 17:39:07 +02:00
$ . get ( baseurl + "/taxonomies/taxonomyMassHide/" + taxonomy , openConfirmation ) . fail ( xhrFailCallback ) ;
2018-09-10 12:53:33 +02:00
}
function unhideSelectedTags ( taxonomy ) {
2022-04-21 17:39:07 +02:00
$ . get ( baseurl + "/taxonomies/taxonomyMassUnhide/" + taxonomy , openConfirmation ) . fail ( xhrFailCallback ) ;
2018-09-10 12:53:33 +02:00
}
2017-04-13 16:31:48 +02:00
function getSelected ( ) {
2019-02-13 08:46:18 +01:00
var selected = [ ] ;
2022-04-18 11:21:30 +02:00
$ ( ".select_attribute:checked" ) . each ( function ( ) {
var test = $ ( this ) . data ( "id" ) ;
selected . push ( test ) ;
2019-02-13 08:46:18 +01:00
} ) ;
return JSON . stringify ( selected ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-24 15:10:08 +02:00
2017-04-13 16:31:48 +02:00
function getSelectedTaxonomyNames ( ) {
2019-02-13 08:46:18 +01:00
var selected = [ ] ;
$ ( ".select_taxonomy" ) . each ( function ( ) {
if ( $ ( this ) . is ( ":checked" ) ) {
var row = $ ( this ) . data ( "id" ) ;
var temp = $ ( '#tag_' + row ) . html ( ) ;
temp = $ ( "<div/>" ) . html ( temp ) . text ( ) ;
selected . push ( temp ) ;
}
} ) ;
$ ( '#TaxonomyNameList' ) . val ( JSON . stringify ( selected ) ) ;
2017-04-13 16:31:48 +02:00
}
2015-11-26 04:31:24 +01:00
2017-04-13 16:31:48 +02:00
function loadEventTags ( id ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2022-10-14 15:49:24 +02:00
dataType : "html" ,
2019-02-13 08:46:18 +01:00
cache : false ,
2022-10-14 15:49:24 +02:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( ".eventTagContainer" ) . html ( data ) ;
} ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/tags/showEventTag/" + id ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-24 15:10:08 +02:00
2019-01-05 05:03:04 +01:00
function loadGalaxies ( id , scope ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
dataType : "html" ,
cache : false ,
2022-04-24 18:29:32 +02:00
success : function ( data ) {
if ( scope === 'event' ) {
2019-02-13 08:46:18 +01:00
$ ( "#galaxies_div" ) . html ( data ) ;
2022-04-24 18:29:32 +02:00
} else if ( scope === 'attribute' ) {
2019-01-05 05:03:04 +01:00
$ ( "#attribute_" + id + "_galaxy" ) . html ( data ) ;
}
2019-02-13 08:46:18 +01:00
} ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/galaxies/showGalaxies/" + id + "/" + scope ,
2019-02-13 08:46:18 +01:00
} ) ;
2019-01-05 05:03:04 +01:00
}
2022-04-17 17:12:10 +02:00
function loadAttributeTags ( attribute _id ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2021-10-18 17:27:58 +02:00
dataType : "html" ,
2019-02-13 08:46:18 +01:00
cache : false ,
2021-10-18 17:27:58 +02:00
success : function ( data ) {
2022-04-17 17:12:10 +02:00
$ ( "[data-primary-id=" + attribute _id + "] .attributeTagContainer" ) . html ( data ) ;
2019-02-13 08:46:18 +01:00
} ,
2021-02-19 15:38:03 +01:00
error : xhrFailCallback ,
2022-04-17 17:12:10 +02:00
url : baseurl + "/tags/showAttributeTag/" + attribute _id
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-09-29 16:52:47 +02:00
2019-01-14 12:30:19 +01:00
function removeObjectTagPopup ( clicked , context , object , tag ) {
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/" + context + "s/removeTag/" + object + '/' + tag , function ( data ) {
2019-02-13 08:46:18 +01:00
openPopover ( clicked , data ) ;
2021-02-19 15:38:03 +01:00
} ) . fail ( xhrFailCallback ) ;
2017-04-13 16:31:48 +02:00
}
2017-01-31 09:58:21 +01:00
2017-04-13 16:31:48 +02:00
function removeObjectTag ( context , object , tag ) {
2019-02-13 08:46:18 +01:00
var formData = $ ( '#PromptForm' ) . serialize ( ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
data : formData ,
type : "POST" ,
2021-02-19 15:38:03 +01:00
url : "/" + context . toLowerCase ( ) + "s/removeTag/" + object + '/' + tag ,
success : function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
if ( context == 'Attribute' ) {
loadAttributeTags ( object ) ;
2018-12-25 14:04:01 +01:00
} else if ( context == 'tag_collection' ) {
refreshTagCollectionRow ( object ) ;
2019-02-13 08:46:18 +01:00
} else {
loadEventTags ( object ) ;
}
handleGenericAjaxResponse ( data ) ;
} ,
} ) ;
return false ;
2017-04-13 16:31:48 +02:00
}
2016-09-29 16:52:47 +02:00
2019-01-17 08:36:21 +01:00
function redirectAddObject ( templateId , additionalData ) {
2019-02-13 08:46:18 +01:00
var eventId = additionalData [ 'event_id' ] ;
2020-08-16 13:31:31 +02:00
window . location = baseurl + '/objects/add/' + eventId + '/' + templateId ;
2019-01-17 08:36:21 +01:00
}
2020-05-13 11:01:16 +02:00
function openGenericModal ( url , modalData , callback ) {
2019-12-11 10:03:43 +01:00
$ . ajax ( {
type : "get" ,
url : url ,
success : function ( data ) {
$ ( '#genericModal' ) . remove ( ) ;
2020-07-16 11:23:07 +02:00
var htmlData ;
2020-05-13 11:01:16 +02:00
if ( modalData !== undefined ) {
2020-07-16 11:23:07 +02:00
var $modal = $ ( '<div id="genericModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="genericModalLabel" aria-hidden="true"></div>' ) ;
2020-05-13 11:01:16 +02:00
if ( modalData . classes !== undefined ) {
$modal . addClass ( modalData . classes ) ;
}
2020-07-16 11:23:07 +02:00
var $modalHeaderText = $ ( '<h3 id="genericModalLabel"></h3>' ) ;
2020-05-13 11:01:16 +02:00
if ( modalData . header !== undefined ) {
$modalHeaderText . text ( modalData . header )
}
2020-07-16 11:23:07 +02:00
var $modalHeader = $ ( '<div class="modal-header"></div>' ) . append (
2020-05-13 11:01:16 +02:00
$ ( '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>' ) ,
$modalHeaderText
) ;
2020-07-16 11:23:07 +02:00
var $modalBody = $ ( '<div class="modal-body"></div>' ) . html ( data ) ;
2020-05-13 11:01:16 +02:00
if ( modalData . bodyStyle !== undefined ) {
$modalBody . css ( modalData . bodyStyle ) ;
}
$modal . append (
$modalHeader ,
$modalBody
) ;
htmlData = $modal [ 0 ] . outerHTML ;
} else {
htmlData = data ;
}
2022-03-20 15:18:26 +01:00
$ ( document . body ) . append ( htmlData ) ;
2020-05-13 11:01:16 +02:00
$ ( '#genericModal' ) . modal ( ) . on ( 'shown' , function ( ) {
if ( callback !== undefined ) {
callback ( ) ;
}
} ) ;
2019-12-11 10:03:43 +01:00
} ,
2022-05-22 10:55:45 +02:00
error : xhrFailCallback ,
2019-12-11 10:03:43 +01:00
} ) ;
}
2020-03-01 18:05:21 +01:00
function openGenericModalPost ( url , body ) {
$ . ajax ( {
data : body ,
type : "post" ,
url : url ,
success : function ( data ) {
$ ( '#genericModal' ) . remove ( ) ;
$ ( 'body' ) . append ( data ) ;
$ ( '#genericModal' ) . modal ( ) ;
} ,
error : function ( data , textStatus , errorThrown ) {
showMessage ( 'fail' , textStatus + ": " + errorThrown ) ;
}
} ) ;
}
2020-04-07 13:21:01 +02:00
function submitPopoverForm ( context _id , referer , update _context _id , modal , popover _dismiss _id _to _close ) {
2022-05-05 17:48:24 +02:00
var $form ;
2019-02-13 08:46:18 +01:00
var context = 'event' ;
var contextNamingConvention = 'Attribute' ;
var closePopover = true ;
switch ( referer ) {
case 'addTextElement' :
context = 'template' ;
contextNamingConvention = 'TemplateElementText' ;
break ;
case 'editTextElement' :
context = 'template' ;
context _id = update _context _id ;
contextNamingConvention = 'TemplateElementText' ;
break ;
case 'addAttributeElement' :
context = 'template' ;
contextNamingConvention = 'TemplateElementAttribute' ;
break ;
case 'editAttributeElement' :
context = 'template' ;
context _id = update _context _id ;
contextNamingConvention = 'TemplateElementAttribute' ;
break ;
case 'addFileElement' :
context = 'template' ;
contextNamingConvention = 'TemplateElementFile' ;
break ;
case 'editFileElement' :
context = 'template' ;
context _id = update _context _id ;
contextNamingConvention = 'TemplateElementFile' ;
break ;
case 'addSighting' :
closePopover = false ;
break ;
}
2020-08-24 10:55:22 +02:00
var $submitButton = $ ( "#submitButton" ) ;
if ( $submitButton . parent ( ) . hasClass ( 'modal-footer' ) ) {
2022-05-05 17:48:24 +02:00
$form = $submitButton . parent ( ) . parent ( ) . find ( '.modal-body form' ) ;
2019-12-11 10:03:43 +01:00
} else {
2022-05-05 17:48:24 +02:00
$form = $submitButton . closest ( "form" ) ;
2019-12-11 10:03:43 +01:00
}
2022-05-05 17:48:24 +02:00
var url = $form . attr ( 'action' ) ;
2020-08-24 10:55:22 +02:00
// Prepend URL with baseurl if URL is relative
if ( ! url . startsWith ( 'http' ) ) {
url = baseurl + url ;
2019-12-11 10:03:43 +01:00
}
$ . ajax ( {
2022-05-05 17:48:24 +02:00
beforeSend : function ( ) {
2019-12-11 10:03:43 +01:00
if ( modal ) {
if ( closePopover ) {
$ ( '#genericModal' ) . modal ( 'hide' ) ;
}
} else {
2019-02-13 08:46:18 +01:00
if ( closePopover ) {
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( "#popover_form" ) . fadeOut ( ) ;
2020-04-07 13:21:01 +02:00
if ( popover _dismiss _id _to _close !== undefined ) {
$ ( '[data-dismissid="' + popover _dismiss _id _to _close + '"]' ) . popover ( 'destroy' ) ;
2019-12-16 13:43:07 +01:00
}
2019-12-11 10:03:43 +01:00
$ ( ".loading" ) . show ( ) ;
2019-02-13 08:46:18 +01:00
}
2019-12-11 10:03:43 +01:00
}
} ,
data : $form . serialize ( ) ,
2022-05-05 17:48:24 +02:00
success : function ( data ) {
2019-12-11 10:03:43 +01:00
if ( closePopover ) {
if ( modal ) {
2022-04-27 12:26:28 +02:00
handleAjaxModalResponse ( data , context _id , url , referer , context , contextNamingConvention ) ;
2019-12-11 10:03:43 +01:00
} else {
2022-05-05 17:48:24 +02:00
handleAjaxPopoverResponse ( data , context _id , url , referer , context , contextNamingConvention ) ;
2019-02-13 08:46:18 +01:00
}
2019-12-11 10:03:43 +01:00
}
2022-05-05 17:48:24 +02:00
if ( referer === 'addSighting' ) {
2019-12-11 10:03:43 +01:00
updateIndex ( update _context _id , 'event' ) ;
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/sightings/listSightings/" + id + "/attribute" , function ( data ) {
2019-12-11 10:03:43 +01:00
$ ( "#sightingsData" ) . html ( data ) ;
2021-02-19 15:38:03 +01:00
} ) . fail ( xhrFailCallback ) ;
2022-09-23 12:04:55 +02:00
$ ( '.sightingsToggle' ) . removeClass ( 'btn-primary' ) . addClass ( 'btn-inverse' ) ;
$ ( '#sightingsListAllToggle' ) . removeClass ( 'btn-inverse' ) . addClass ( 'btn-primary' ) ;
2019-12-11 10:03:43 +01:00
}
2022-05-05 17:48:24 +02:00
if ( referer === 'addEventReport' && typeof window . reloadEventReportTable === 'function' ) {
2020-09-16 14:56:13 +02:00
reloadEventReportTable ( )
2020-09-16 15:08:43 +02:00
eventUnpublish ( )
2020-09-16 14:56:13 +02:00
}
2019-12-16 13:36:01 +01:00
if (
(
2022-09-23 12:04:55 +02:00
context === 'event' &&
( referer === 'add' || referer === 'massEdit' || referer === 'replaceAttributes' || referer === 'addObjectReference' || referer === 'quickAddAttributeForm' )
2019-12-16 13:43:07 +01:00
)
2019-12-16 13:36:01 +01:00
) {
eventUnpublish ( ) ;
}
2019-12-11 10:03:43 +01:00
} ,
2022-05-05 17:48:24 +02:00
error : xhrFailCallback ,
2019-12-11 10:03:43 +01:00
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
type : "post" ,
url : url ,
} ) ;
return false ;
2020-08-24 10:55:22 +02:00
}
2019-12-11 10:03:43 +01:00
function handleAjaxModalResponse ( response , context _id , url , referer , context , contextNamingConvention ) {
2022-04-27 12:26:28 +02:00
var responseArray = response ;
2019-12-11 10:03:43 +01:00
if ( responseArray . saved ) {
updateIndex ( context _id , context ) ;
if ( responseArray . success ) {
2022-05-05 17:48:24 +02:00
var message = "message" in responseArray ? responseArray . message : responseArray . success ;
showMessage ( "success" , message ) ;
2022-04-27 12:26:28 +02:00
} else if ( responseArray . errors ) {
2019-12-11 10:03:43 +01:00
showMessage ( "fail" , responseArray . errors ) ;
}
} else {
2022-04-27 12:26:28 +02:00
if ( responseArray . errors && typeof responseArray . errors === 'string' ) {
2022-05-05 22:02:39 +02:00
var fullErrors = "full_errors" in responseArray ? responseArray . full _errors : '' ;
showMessage ( "fail" , responseArray . errors , fullErrors ) ;
2022-04-27 12:26:28 +02:00
} else {
var savedArray = saveValuesForPersistance ( ) ;
$ . ajax ( {
dataType : "html" ,
success : function ( data ) {
$ ( '#genericModal' ) . remove ( ) ;
$ ( 'body' ) . append ( data ) ;
$ ( '#genericModal' ) . modal ( ) ;
handleValidationErrors ( responseArray . errors , context , contextNamingConvention ) ;
recoverValuesFromPersistance ( savedArray ) ;
} ,
error : xhrFailCallback ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
url : url
} ) ;
2020-07-30 09:00:46 +02:00
}
2019-02-13 08:46:18 +01:00
}
2019-12-11 10:03:43 +01:00
}
2014-04-24 15:10:08 +02:00
2017-04-13 16:31:48 +02:00
function handleAjaxPopoverResponse ( response , context _id , url , referer , context , contextNamingConvention ) {
2019-02-13 08:46:18 +01:00
responseArray = response ;
var result = "fail" ;
if ( responseArray . saved ) {
2022-09-23 12:04:55 +02:00
var callback = function ( ) {
// Scroll to edited object after index is updated
if ( referer === 'quickAddAttributeForm' ) {
scrollToElementIfNotVisible ( $ ( "#Object_" + context _id + "_tr" ) ) ;
}
}
updateIndex ( context _id , context , callback ) ;
2019-02-13 08:46:18 +01:00
if ( responseArray . success ) {
showMessage ( "success" , responseArray . success ) ;
result = "success" ;
}
if ( responseArray . errors ) {
showMessage ( "fail" , responseArray . errors ) ;
}
} else {
var savedArray = saveValuesForPersistance ( ) ;
$ . ajax ( {
2022-09-23 12:04:55 +02:00
dataType : "html" ,
success : function ( data , textStatus ) {
2019-02-13 08:46:18 +01:00
$ ( "#popover_form" ) . html ( data ) ;
openPopup ( "#popover_form" ) ;
var error _context = context . charAt ( 0 ) . toUpperCase ( ) + context . slice ( 1 ) ;
handleValidationErrors ( responseArray . errors , context , contextNamingConvention ) ;
result = "success" ;
if ( ! $ . isEmptyObject ( responseArray ) ) {
result = "fail" ;
$ ( "#formWarning" ) . show ( ) ;
$ ( "#formWarning" ) . html ( 'The object(s) could not be saved. Please, try again.' ) ;
}
recoverValuesFromPersistance ( savedArray ) ;
$ ( ".loading" ) . hide ( ) ;
} ,
2022-09-23 12:04:55 +02:00
url : url
2019-02-13 08:46:18 +01:00
} ) ;
}
return result ;
2017-04-13 16:31:48 +02:00
}
2014-04-24 15:10:08 +02:00
2017-04-13 11:59:17 +02:00
//before we update the form (in case the action failed), we want to retrieve the data from every field, so that we can set the fields in the new form that we fetch
2017-04-13 16:31:48 +02:00
function saveValuesForPersistance ( ) {
2019-02-13 08:46:18 +01:00
var formPersistanceArray = new Array ( ) ;
for ( i = 0 ; i < fieldsArray . length ; i ++ ) {
formPersistanceArray [ fieldsArray [ i ] ] = $ ( '#' + fieldsArray [ i ] ) . val ( ) ;
}
return formPersistanceArray ;
2017-04-13 16:31:48 +02:00
}
2017-04-13 11:59:17 +02:00
2017-04-13 16:31:48 +02:00
function recoverValuesFromPersistance ( formPersistanceArray ) {
2019-02-13 08:46:18 +01:00
for ( i = 0 ; i < fieldsArray . length ; i ++ ) {
$ ( '#' + fieldsArray [ i ] ) . val ( formPersistanceArray [ fieldsArray [ i ] ] ) ;
}
2017-04-13 16:31:48 +02:00
}
2014-04-24 15:10:08 +02:00
2017-04-13 16:31:48 +02:00
function handleValidationErrors ( responseArray , context , contextNamingConvention ) {
2019-02-13 08:46:18 +01:00
for ( var k in responseArray ) {
var elementName = k . charAt ( 0 ) . toUpperCase ( ) + k . slice ( 1 ) ;
2022-04-27 12:26:28 +02:00
var $element = $ ( "#" + contextNamingConvention + elementName ) ;
$element . parent ( ) . addClass ( "error" ) ;
$element . parent ( ) . append ( "<div class=\"error-message\">" + responseArray [ k ] + "</div>" ) ;
2019-02-13 08:46:18 +01:00
}
2017-04-13 16:31:48 +02:00
}
2014-05-02 14:29:15 +02:00
2017-04-13 16:31:48 +02:00
function toggleHistogramType ( type , old ) {
2019-02-13 08:46:18 +01:00
var done = false ;
old . forEach ( function ( entry ) {
if ( type == entry ) {
done = true ;
old . splice ( old . indexOf ( entry ) , 1 ) ;
}
} ) ;
if ( done == false ) old . push ( type ) ;
updateHistogram ( JSON . stringify ( old ) ) ;
2017-04-13 16:31:48 +02:00
}
2014-05-02 14:29:15 +02:00
2017-04-13 16:31:48 +02:00
function updateHistogram ( selected ) {
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
dataType : "html" ,
2021-02-19 15:38:03 +01:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#histogram" ) . html ( data ) ;
} ,
2021-02-19 15:38:03 +01:00
url : "/users/histogram/" + selected ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-24 15:10:08 +02:00
2022-05-05 22:02:39 +02:00
function showMessage ( success , message , fullError ) {
var duration = 1000 + ( message . length * 40 ) ;
2022-04-27 12:26:28 +02:00
if ( message . indexOf ( "$flashErrorMessage" ) >= 0 ) {
2022-05-05 22:02:39 +02:00
var flashMessageLink = '<a href="#" class="bold" data-content="' + escapeHtml ( fullError ) + '" data-html="true" onclick="event.preventDefault();$(this).popover(\'show\')">here</a>' ;
2022-04-27 12:26:28 +02:00
message = message . replace ( "$flashErrorMessage" , flashMessageLink ) ;
2022-05-05 22:02:39 +02:00
duration = 5000 ;
2022-04-27 12:26:28 +02:00
}
2019-02-13 08:46:18 +01:00
$ ( "#ajax_" + success ) . html ( message ) ;
2020-07-19 16:22:16 +02:00
$ ( "#ajax_" + success + "_container" ) . fadeIn ( "slow" ) . delay ( duration ) . fadeOut ( "slow" ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2018-06-12 14:39:48 +02:00
function cancelPopoverForm ( id ) {
2019-02-13 08:46:18 +01:00
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( "#popover_form_large" ) . fadeOut ( ) ;
2022-04-21 16:20:25 +02:00
$ ( "#screenshot_box" ) . fadeOut ( 400 , function ( ) {
$ ( this ) . remove ( ) ;
} ) ;
2023-10-25 15:39:25 +02:00
$ ( '.tooltip' ) . remove ( )
2020-10-14 09:15:25 +02:00
$ ( "#popover_box" )
. fadeOut ( )
. removeAttr ( 'style' ) // remove all inline styles
. empty ( ) ; // remove all child elements
2019-02-13 08:46:18 +01:00
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( '#popover_form' ) . fadeOut ( ) ;
if ( id !== undefined && id !== '' ) {
$ ( id ) . fadeOut ( ) ;
}
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2017-04-13 16:31:48 +02:00
function activateTagField ( ) {
2019-02-13 08:46:18 +01:00
$ ( "#addTagButton" ) . hide ( ) ;
$ ( "#addTagField" ) . show ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2017-04-13 16:31:48 +02:00
function tagFieldChange ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( "#addTagField :selected" ) . val ( ) > 0 ) {
var selected _id = $ ( "#addTagField :selected" ) . val ( ) ;
var selected _text = $ ( "#addTagField :selected" ) . text ( ) ;
if ( $ . inArray ( selected _id , selectedTags ) == - 1 ) {
selectedTags . push ( selected _id ) ;
appendTemplateTag ( selected _id ) ;
}
}
$ ( "#addTagButton" ) . show ( ) ;
$ ( "#addTagField" ) . hide ( ) ;
2017-04-13 16:31:48 +02:00
}
2016-02-03 09:59:03 +01:00
2021-02-19 15:38:03 +01:00
function appendTemplateTag ( selected _id ) {
xhr ( {
dataType : "html" ,
success : function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#tags" ) . append ( data ) ;
} ,
2021-02-19 15:38:03 +01:00
url : "/tags/viewTag/" + selected _id ,
2019-02-13 08:46:18 +01:00
} ) ;
updateSelectedTags ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2017-04-13 16:31:48 +02:00
function addAllTags ( tagArray ) {
2019-02-13 08:46:18 +01:00
parsedTagArray = JSON . parse ( tagArray ) ;
parsedTagArray . forEach ( function ( tag ) {
appendTemplateTag ( tag ) ;
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2017-04-13 16:31:48 +02:00
function removeTemplateTag ( id , name ) {
2019-02-13 08:46:18 +01:00
selectedTags . forEach ( function ( tag ) {
if ( tag == id ) {
var index = selectedTags . indexOf ( id ) ;
if ( index > - 1 ) {
selectedTags . splice ( index , 1 ) ;
updateSelectedTags ( ) ;
}
}
} ) ;
$ ( '#tag_bubble_' + id ) . remove ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2017-04-13 16:31:48 +02:00
function updateSelectedTags ( ) {
2019-02-13 08:46:18 +01:00
$ ( '#hiddenTags' ) . attr ( "value" , JSON . stringify ( selectedTags ) ) ;
2017-04-13 16:31:48 +02:00
}
2017-04-13 11:59:17 +02:00
2017-04-13 16:31:48 +02:00
function saveElementSorting ( order ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
data : order ,
dataType : "json" ,
contentType : "application/json" ,
2021-02-19 15:38:03 +01:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
handleGenericAjaxResponse ( data ) ;
} ,
2022-04-22 12:00:18 +02:00
error : xhrFailCallback ,
2019-02-13 08:46:18 +01:00
type : "post" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/templates/saveElementSorting/" ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2017-04-13 16:31:48 +02:00
function templateAddElementClicked ( id ) {
2020-08-16 13:31:31 +02:00
simplePopup ( baseurl + "/template_elements/templateElementAddChoices/" + id ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2017-04-13 16:31:48 +02:00
function templateAddElement ( type , id ) {
2020-08-16 13:31:31 +02:00
simplePopup ( baseurl + "/template_elements/add/" + type + "/" + id ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2017-04-13 16:31:48 +02:00
function templateUpdateAvailableTypes ( ) {
2019-02-13 08:46:18 +01:00
$ ( "#innerTypes" ) . empty ( ) ;
var type = $ ( "#TemplateElementAttributeType option:selected" ) . text ( ) ;
var complex = $ ( '#TemplateElementAttributeComplex:checked' ) . val ( ) ;
if ( complex && type != 'Select Type' ) {
currentTypes . forEach ( function ( entry ) {
$ ( "#innerTypes" ) . append ( "<div class=\"templateTypeBox\" id=\"" + entry + "TypeBox\">" + entry + "</div>" ) ;
} ) ;
$ ( '#outerTypes' ) . show ( ) ;
}
else $ ( '#outerTypes' ) . hide ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2017-04-13 16:31:48 +02:00
function populateTemplateTypeDropdown ( ) {
2019-02-13 08:46:18 +01:00
var cat = $ ( "#TemplateElementAttributeCategory option:selected" ) . text ( ) ;
currentTypes = [ ] ;
if ( cat == 'Select Category' ) {
$ ( '#TemplateElementAttributeType' ) . html ( "<option>Select Type</option>" ) ;
} else {
var complex = $ ( '#TemplateElementAttributeComplex:checked' ) . val ( ) ;
if ( cat in typeGroupCategoryMapping ) {
$ ( '#TemplateElementAttributeType' ) . html ( "<option>Select Type</option>" ) ;
typeGroupCategoryMapping [ cat ] . forEach ( function ( entry ) {
$ ( '#TemplateElementAttributeType' ) . append ( "<option>" + entry + "</option>" ) ;
} ) ;
} else {
complex = false ;
}
if ( ! complex ) {
$ ( '#TemplateElementAttributeType' ) . html ( "<option>Select Type</option>" ) ;
categoryTypes [ cat ] . forEach ( function ( entry ) {
$ ( '#TemplateElementAttributeType' ) . append ( "<option>" + entry + "</option>" ) ;
} ) ;
}
}
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2017-04-13 16:31:48 +02:00
function templateElementAttributeTypeChange ( ) {
2019-02-13 08:46:18 +01:00
var complex = $ ( '#TemplateElementAttributeComplex:checked' ) . val ( ) ;
var type = $ ( "#TemplateElementAttributeType option:selected" ) . text ( ) ;
currentTypes = [ ] ;
if ( type != 'Select Type' ) {
if ( complex ) {
complexTypes [ type ] [ "types" ] . forEach ( function ( entry ) {
currentTypes . push ( entry ) ;
} ) ;
} else {
currentTypes . push ( type ) ;
}
} else {
currentTypes = [ ] ;
}
$ ( "#typeJSON" ) . html ( JSON . stringify ( currentTypes ) ) ;
templateUpdateAvailableTypes ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-12 13:59:54 +02:00
2017-04-13 16:31:48 +02:00
function templateElementAttributeCategoryChange ( category ) {
2019-02-13 08:46:18 +01:00
if ( category in typeGroupCategoryMapping ) {
$ ( '#complexToggle' ) . show ( ) ;
} else {
$ ( '#complexToggle' ) . hide ( ) ;
}
if ( category != 'Select Type' ) {
populateTemplateTypeDropdown ( ) ;
}
templateUpdateAvailableTypes ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-19 08:44:35 +02:00
2017-04-13 16:31:48 +02:00
function templateElementFileCategoryChange ( category ) {
2019-02-13 08:46:18 +01:00
if ( category == '' ) {
$ ( "#TemplateElementFileMalware" ) [ 0 ] . disabled = true ;
$ ( "#TemplateElementFileMalware" ) [ 0 ] . checked = false ;
} else {
if ( categoryArray [ category ] . length == 2 ) {
$ ( "#TemplateElementFileMalware" ) [ 0 ] . disabled = false ;
$ ( "#TemplateElementFileMalware" ) [ 0 ] . checked = true ;
} else {
$ ( "#TemplateElementFileMalware" ) [ 0 ] . disabled = true ;
if ( categoryArray [ category ] == 'attachment' ) $ ( "#TemplateElementFileMalware" ) [ 0 ] . checked = false ;
else $ ( "#TemplateElementFileMalware" ) [ 0 ] . checked = true ;
}
}
2017-04-13 16:31:48 +02:00
}
2014-06-19 08:44:35 +02:00
2022-03-27 22:07:36 +02:00
function openConfirmation ( data ) {
var $box = $ ( "#confirmation_box" ) ;
$box . html ( data ) ;
openPopup ( $box ) ;
}
2019-07-16 10:28:03 +02:00
function openPopup ( id , adjust _layout , callback ) {
2020-09-26 16:31:59 +02:00
var $id = $ ( id ) ;
2019-05-13 16:23:13 +02:00
adjust _layout = adjust _layout === undefined ? true : adjust _layout ;
if ( adjust _layout ) {
2020-09-26 16:57:51 +02:00
$id . css ( { 'top' : '' , 'height' : '' } ) . removeClass ( 'vertical-scroll' ) ; // reset inline values
2019-05-13 16:23:13 +02:00
var window _height = $ ( window ) . height ( ) ;
2020-09-26 16:31:59 +02:00
var popup _height = $id . height ( ) ;
2019-05-13 16:23:13 +02:00
if ( window _height < popup _height ) {
2020-09-26 16:31:59 +02:00
$id . css ( "top" , 50 ) ;
2020-09-26 16:57:51 +02:00
$id . css ( "height" , window _height - 50 ) ;
2020-09-26 16:31:59 +02:00
$id . addClass ( 'vertical-scroll' ) ;
2019-02-13 08:46:18 +01:00
} else {
2019-05-13 16:23:13 +02:00
if ( window _height > ( 300 + popup _height ) ) {
2022-11-12 20:22:51 +01:00
var top _offset = ( ( window _height - popup _height ) / 2 ) - 125 ;
2019-05-13 16:23:13 +02:00
} else {
var top _offset = ( window _height - popup _height ) / 2 ;
}
2020-09-26 16:57:51 +02:00
$id . css ( "top" , top _offset ) ;
2019-02-13 08:46:18 +01:00
}
}
$ ( "#gray_out" ) . fadeIn ( ) ;
2020-09-26 16:31:59 +02:00
$id . fadeIn ( 400 , function ( ) {
2019-07-16 10:28:03 +02:00
if ( callback !== undefined ) {
callback ( ) ;
}
} ) ;
2017-04-13 16:31:48 +02:00
}
2017-04-04 10:28:21 +02:00
2019-07-03 16:04:36 +02:00
function openPopover ( clicked , data , hover , placement , callback ) {
2019-02-13 08:46:18 +01:00
hover = hover === undefined ? false : hover ;
placement = placement === undefined ? 'right' : placement ;
/* popup handling */
var $clicked = $ ( clicked ) ;
var randomId = $clicked . attr ( 'data-dismissid' ) !== undefined ? $clicked . attr ( 'data-dismissid' ) : Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) ; // used to recover the button that triggered the popover (so that we can destroy the popover)
var loadingHtml = '<div style="height: 75px; width: 75px;"><div class="spinner"></div><div class="loadingText">Loading</div></div>' ;
$clicked . attr ( 'data-dismissid' , randomId ) ;
2022-05-04 16:54:10 +02:00
var closeButtonHtml = '<button class="close" style="margin-left: 5px;">× </button>' ;
2019-02-13 08:46:18 +01:00
2022-05-04 16:54:10 +02:00
if ( ! $clicked . data ( 'popover' ) ) { // true when popover was already created defined
2019-02-13 08:46:18 +01:00
$clicked . addClass ( 'have-a-popover' ) ;
2019-02-13 16:19:20 +01:00
var popoverOptions = {
2019-02-13 08:46:18 +01:00
html : true ,
placement : placement ,
trigger : 'manual' ,
content : loadingHtml ,
container : 'body' ,
template : '<div class="popover" role="tooltip" data-dismissid="' + randomId + '"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"><div class="data-content"></div></div></div>'
2019-02-13 16:19:20 +01:00
} ;
$clicked . popover ( popoverOptions )
2022-05-04 16:54:10 +02:00
. on ( 'shown.bs.popover' , function ( ) {
var $this = $ ( this ) ; // should be the same as $clicked
var $popover = $this . data ( "popover" ) . tip ( ) ; // should be the content of popover
2019-02-13 08:46:18 +01:00
var title = $this . attr ( 'title' ) ;
title = title === "" ? $this . attr ( 'data-original-title' ) : title ;
2022-05-04 16:54:10 +02:00
$popover . on ( "click" , ".close" , function ( ) {
$this . popover ( "hide" ) ;
} ) ;
2019-02-13 08:46:18 +01:00
if ( title === "" ) {
title = " " ;
// adjust popover position (title was empty)
2022-05-04 16:54:10 +02:00
var top = $popover . offset ( ) . top ;
$popover . css ( 'top' , ( top - 17 ) + 'px' ) ;
2019-02-13 08:46:18 +01:00
}
2022-05-04 16:54:10 +02:00
var popoverTitle = $popover . find ( 'h3.popover-title' ) ;
2019-02-13 08:46:18 +01:00
popoverTitle . html ( title + closeButtonHtml ) ;
2019-07-03 16:04:36 +02:00
if ( callback !== undefined ) {
2022-05-04 16:54:10 +02:00
callback ( $popover ) ;
2019-07-03 16:04:36 +02:00
}
2019-02-13 08:46:18 +01:00
} )
. on ( 'keydown.volatilePopover' , function ( e ) {
if ( e . keyCode == 27 ) { // ESC
$ ( this ) . popover ( 'destroy' ) ;
$ ( this ) . off ( 'keydown.volatilePopover' ) ;
}
} ) ;
if ( hover ) {
$clicked . on ( 'mouseenter' , function ( ) {
var _this = this ;
$clicked . popover ( 'show' ) ;
$ ( ".popover" ) . on ( "mouseleave" , function ( ) { // close popover when leaving it
$ ( _this ) . popover ( 'hide' ) ;
} ) ;
} )
. on ( 'mouseleave' , function ( ) { // close popover if button not hovered (timeout)
var _this = this ;
setTimeout ( function ( ) {
if ( $ ( '.popover:hover' ) . length == 0 && ! $ ( _this ) . is ( ":hover" ) ) {
$ ( _this ) . popover ( 'hide' ) ;
}
} ,
300 ) ;
} ) ;
2022-05-04 16:54:10 +02:00
} else if ( data !== undefined ) {
2019-02-13 08:46:18 +01:00
$clicked . popover ( 'show' ) ;
}
2022-05-04 16:54:10 +02:00
} else if ( data !== undefined ) {
2020-10-06 08:28:12 +02:00
$clicked . popover ( 'show' ) ;
2019-02-13 08:46:18 +01:00
}
var popover = $clicked . data ( 'popover' ) ;
2022-05-04 16:54:10 +02:00
if ( data !== undefined && popover . options . content !== data ) {
popover . options . content = data ;
2019-02-13 08:46:18 +01:00
$clicked . popover ( 'show' ) ;
}
2022-05-04 16:54:10 +02:00
return popover ;
2019-01-14 12:30:19 +01:00
}
2019-02-15 09:24:52 +01:00
function getMatrixPopup ( scope , scope _id , galaxy _id ) {
2019-02-13 08:46:18 +01:00
cancelPopoverForm ( ) ;
2019-05-13 16:23:13 +02:00
getPopup ( scope _id + '/' + galaxy _id + '/' + scope , 'events' , 'viewGalaxyMatrix' , '' , '#popover_matrix' ) ;
2018-06-12 16:25:43 +02:00
}
2017-04-13 16:31:48 +02:00
function getPopup ( id , context , target , admin , popupType ) {
2019-02-13 08:46:18 +01:00
$ ( "#gray_out" ) . fadeIn ( ) ;
2020-08-16 13:31:31 +02:00
var url = baseurl ;
2019-02-13 08:46:18 +01:00
if ( typeof admin !== 'undefined' && admin != '' ) url += "/admin" ;
if ( context != '' ) {
url += "/" + context ;
}
if ( target != '' ) url += "/" + target ;
if ( id != '' ) url += "/" + id ;
if ( popupType == '' || typeof popupType == 'undefined' ) popupType = '#popover_form' ;
$ . ajax ( {
2021-02-19 15:14:02 +01:00
beforeSend : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . show ( ) ;
} ,
dataType : "html" ,
cache : false ,
success : function ( data , textStatus ) {
$ ( ".loading" ) . hide ( ) ;
$ ( popupType ) . html ( data ) ;
2019-05-13 16:23:13 +02:00
openPopup ( popupType , false ) ;
2019-02-13 08:46:18 +01:00
} ,
2019-08-28 09:23:22 +02:00
error : function ( xhr ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . hide ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
2020-07-14 12:34:29 +02:00
xhrFailCallback ( xhr ) ;
2019-02-13 08:46:18 +01:00
} ,
url : url
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-19 08:44:35 +02:00
2019-01-08 14:50:55 +01:00
// Same as getPopup function but create a popover to populate first
2022-03-29 18:50:22 +02:00
// DEPRECATED
2019-01-08 14:50:55 +01:00
function popoverPopup ( clicked , id , context , target , admin ) {
2020-08-16 13:31:31 +02:00
var url = baseurl ;
2019-02-13 08:46:18 +01:00
if ( typeof admin !== 'undefined' && admin != '' ) url += "/admin" ;
if ( context != '' ) {
url += "/" + context ;
}
if ( target != '' ) url += "/" + target ;
if ( id != '' ) url += "/" + id ;
2022-03-29 18:50:22 +02:00
popoverPopupNew ( clicked , url ) ;
}
function popoverPopupNew ( clicked , url ) {
var $clicked = $ ( clicked ) ;
var popover = openPopover ( $clicked , undefined ) ;
2019-02-13 08:46:18 +01:00
2022-05-04 16:54:10 +02:00
// actual request
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2022-03-29 18:50:22 +02:00
dataType : "html" ,
2019-02-13 08:46:18 +01:00
cache : false ,
2022-03-29 18:50:22 +02:00
success : function ( data ) {
2022-05-04 16:54:10 +02:00
popover . options . content = data ;
$clicked . popover ( 'show' ) ;
2019-02-13 08:46:18 +01:00
} ,
2022-03-29 18:50:22 +02:00
error : function ( jqXHR ) {
2019-12-09 10:17:12 +01:00
var errorJSON = '' ;
try {
errorJSON = JSON . parse ( jqXHR . responseText ) ;
errorJSON = errorJSON [ 'errors' ] ;
if ( errorJSON === undefined ) {
errorJSON = '' ;
}
} catch ( SyntaxError ) {
// no error provided
2022-05-04 16:54:10 +02:00
if ( jqXHR . status === 401 ) {
errorJSON = 'Unauthorized. Please reload page to log again.' ;
}
2019-12-09 10:17:12 +01:00
}
var errorText = '<div class="alert alert-error" style="margin-bottom: 3px;">Something went wrong - the queried function returned an exception. Contact your administrator for further details (the exception has been logged).</div>' ;
if ( errorJSON !== '' ) {
2020-01-21 16:38:43 +01:00
errorText += '<div class="well"><strong>Returned error:</strong> ' + $ ( '<span/>' ) . text ( errorJSON ) . html ( ) + '</div>' ;
2019-12-09 10:17:12 +01:00
}
popover . options . content = errorText ;
2019-02-13 08:46:18 +01:00
$clicked . popover ( 'show' ) ;
} ,
url : url
} ) ;
2019-01-08 14:50:55 +01:00
}
2022-04-24 18:29:32 +02:00
function confirmClusterDetach ( clicked , target _type , target _id ) {
popoverConfirm ( clicked , undefined , undefined , function ( data ) {
handleGenericAjaxResponse ( data ) ;
if ( target _type === "event" ) {
loadGalaxies ( target _id , 'event' ) ;
} else if ( target _type === "attribute" ) {
loadGalaxies ( target _id , 'attribute' ) ;
} else {
location . reload ( ) ;
}
} )
}
2019-01-14 14:30:38 +01:00
// create a confirm popover on the clicked html node.
2022-04-24 18:29:32 +02:00
function popoverConfirm ( clicked , message , placement , callback ) {
2021-02-23 19:28:08 +01:00
event . preventDefault ( ) ;
2019-01-14 14:30:38 +01:00
var $clicked = $ ( clicked ) ;
2019-02-13 08:46:18 +01:00
var popoverContent = '<div>' ;
2019-11-19 01:06:41 +01:00
popoverContent += message === undefined ? '' : '<p>' + message + '</p>' ;
2022-04-24 18:29:32 +02:00
popoverContent += '<button id="popoverConfirmOK" class="btn btn-primary" style="margin-right: 5px;">Yes</button>' ;
popoverContent += '<button class="btn btn-inverse" style="float: right;" onclick="cancelPrompt()">Cancel</button>' ;
2019-02-13 08:46:18 +01:00
popoverContent += '</div>' ;
2019-11-19 18:07:30 +01:00
openPopover ( $clicked , popoverContent , undefined , placement ) ;
2022-04-24 18:29:32 +02:00
2019-02-13 08:46:18 +01:00
$ ( "#popoverConfirmOK" )
. focus ( )
. bind ( "keydown" , function ( e ) {
if ( e . ctrlKey && ( e . keyCode == 13 || e . keyCode == 10 ) ) {
$ ( this ) . click ( ) ;
2022-04-24 18:29:32 +02:00
} else if ( e . keyCode == 27 ) { // ESC
2019-02-13 08:46:18 +01:00
$clicked . popover ( 'destroy' ) ;
}
2022-04-24 18:29:32 +02:00
} ) . click ( function ( ) {
var href = $clicked . attr ( "href" ) ;
// Load form to get new token
fetchFormDataAjax ( href , function ( form ) {
2024-01-24 21:48:53 +01:00
var $formContainer = $ ( form ) ;
var $form = $formContainer . is ( 'form' ) ? $formContainer : $formContainer . find ( 'form' ) ;
$clicked . popover ( 'destroy' ) ;
2022-04-24 18:29:32 +02:00
xhr ( {
data : $form . serialize ( ) ,
success : function ( data ) {
if ( callback !== undefined ) {
callback ( data ) ;
} else {
location . reload ( ) ;
}
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
} ,
type : "post" ,
url : $form . attr ( 'action' )
} ) ;
} )
2019-02-13 08:46:18 +01:00
} ) ;
2019-01-14 14:30:38 +01:00
}
2020-07-27 12:10:53 +02:00
function simplePopup ( url , requestType , data ) {
requestType = requestType === undefined ? 'GET' : requestType
data = data === undefined ? [ ] : data
2019-02-13 08:46:18 +01:00
$ ( "#gray_out" ) . fadeIn ( ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2022-03-29 12:30:36 +02:00
dataType : "html" ,
success : function ( data ) {
var $popover = $ ( "#popover_form" ) ;
$popover . html ( data ) ;
openPopup ( $popover ) ;
2019-02-13 08:46:18 +01:00
} ,
2022-03-29 12:30:36 +02:00
error : function ( xhr ) {
2019-02-13 08:46:18 +01:00
$ ( "#gray_out" ) . fadeOut ( ) ;
2020-07-14 12:34:29 +02:00
xhrFailCallback ( xhr ) ;
2019-02-13 08:46:18 +01:00
} ,
url : url ,
2020-07-27 12:10:53 +02:00
type : requestType ,
data : data
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-02-19 01:23:15 +01:00
2018-03-19 15:07:51 +01:00
function choicePopup ( legend , list ) {
2019-02-13 08:46:18 +01:00
var popupHtml = '<div class="popover_choice">' ;
popupHtml += '<legend>Select Object Category</legend>' ;
popupHtml += '<div class="popover_choice_main" id ="popover_choice_main">' ;
popupHtml += '<table style="width:100%;" id="MainTable">' ;
popupHtml += '<tbody>' ;
list . forEach ( function ( item ) {
popupHtml += '<tr style="border-bottom:1px solid black;" class="templateChoiceButton">' ;
popupHtml += '<td role="button" tabindex="0" aria-label="All meta-categories" title="' + item . text + '" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="' + item . onclick + ';">' + item . text + '</td>' ;
popupHtml += '</tr>' ;
} ) ;
popupHtml += '</tbody>' ;
popupHtml += '</table>' ;
popupHtml += '</div>' ;
popupHtml += '<div role="button" tabindex="0" aria-label="Cancel" title="Cancel" class="templateChoiceButton templateChoiceButtonLast" onClick="cancelPopoverForm();">Cancel</div>' ;
popupHtml += '</div>' ;
$ ( "#popover_form" ) . html ( popupHtml ) ;
openPopup ( "#popover_form" ) ;
2018-03-19 15:07:51 +01:00
}
2023-07-25 15:39:45 +02:00
function openModal ( heading , body , footer , modal _option , css _container , css _body , class _container ) {
2019-08-23 15:32:28 +02:00
var modal _id = 'dynamic_modal_' + new Date ( ) . getTime ( ) ;
2023-07-25 15:39:45 +02:00
var modal _html = '<div id="' + modal _id + '" class="modal hide fade ' + ( class _container !== undefined ? class _container : '' ) + '" style="' + ( css _container !== undefined ? css _container : '' ) + '" tabindex="-1" role="dialog" aria-hidden="true">' ;
2019-08-23 15:32:28 +02:00
if ( heading !== undefined && heading !== '' ) {
modal _html += '<div class="modal-header">'
+ '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>'
+ '<h3 id="myModalLabel">' + heading + '</h3>'
+ '</div>' ;
}
if ( body !== undefined && body !== '' ) {
modal _html += '<div class="modal-body" style="' + ( css _body !== undefined ? css _body : '' ) + '">' + body + '</div>' ;
}
if ( footer !== undefined && footer !== '' ) {
modal _html += '<div class="modal-footer">' + footer + '</div>' ;
}
modal _html += '</div>' ;
$ ( 'body' ) . append ( $ ( modal _html ) ) ;
$ ( '#' + modal _id ) . modal ( modal _option !== undefined ? modal _option : { } ) ;
}
2017-04-13 16:31:48 +02:00
function resizePopoverBody ( ) {
2019-02-13 08:46:18 +01:00
var bodyheight = $ ( window ) . height ( ) ;
bodyheight = 3 * bodyheight / 4 - 150 ;
$ ( "#popover_choice_main" ) . css ( { "max-height" : bodyheight } ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-25 09:56:33 +02:00
2017-04-13 16:31:48 +02:00
function populateTemplateHiddenFileDiv ( files ) {
2019-02-13 08:46:18 +01:00
$ ( '#TemplateFileArray' ) . val ( JSON . stringify ( files ) ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-25 09:56:33 +02:00
2017-04-13 16:31:48 +02:00
function populateTemplateFileBubbles ( ) {
2019-02-13 08:46:18 +01:00
var fileObjectArray = JSON . parse ( $ ( '#TemplateFileArray' ) . val ( ) ) ;
fileObjectArray . forEach ( function ( entry ) {
templateAddFileBubble ( entry . element _id , false , entry . filename , entry . tmp _name , 'yes' ) ;
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-06-25 09:56:33 +02:00
2017-04-13 16:31:48 +02:00
function templateFileHiddenAdd ( files , element _id , batch ) {
2019-02-13 08:46:18 +01:00
var fileArray = $ . parseJSON ( $ ( '#TemplateFileArray' , window . parent . document ) . val ( ) ) ;
var contained = false ;
for ( var j = 0 ; j < files . length ; j ++ ) {
for ( var i = 0 ; i < fileArray . length ; i ++ ) {
if ( fileArray [ i ] . filename == files [ j ] . filename ) {
contained = true ;
}
if ( batch == 'no' && fileArray [ i ] . element _id == element _id ) {
templateDeleteFileBubble ( fileArray [ i ] . filename , fileArray [ i ] . tmp _name , fileArray [ i ] . element _id , 'iframe' , batch ) ;
contained = false ;
var removeId = i ;
}
}
if ( batch == 'no' ) fileArray . splice ( removeId , 1 ) ;
if ( contained == false ) {
fileArray . push ( files [ j ] ) ;
templateAddFileBubble ( element _id , true , files [ j ] . filename , files [ j ] . tmp _name , batch ) ;
$ ( '#TemplateFileArray' , window . parent . document ) . val ( JSON . stringify ( fileArray ) ) ;
}
}
2017-04-13 16:31:48 +02:00
}
2014-07-02 16:20:19 +02:00
2017-04-13 16:31:48 +02:00
function htmlEncode ( value ) {
2019-02-13 08:46:18 +01:00
return $ ( '<div/>' ) . text ( value ) . html ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-07-01 08:42:21 +02:00
2017-04-13 16:31:48 +02:00
function templateAddFileBubble ( element _id , iframe , filename , tmp _name , batch ) {
2019-02-13 08:46:18 +01:00
filename = htmlEncode ( filename ) ;
tmp _name = htmlEncode ( tmp _name ) ;
if ( batch == 'no' ) {
if ( iframe == true ) {
$ ( '#filenames_' + element _id , window . parent . document ) . html ( '<div id ="' + tmp _name + '_container" class ="template_file_box_container"><span class="tagFirstHalf template_file_box">' + filename + '</span><span onClick="templateDeleteFileBubble(\'' + filename + '\', \'' + tmp _name + '\', \'' + element _id + '\', \'normal\', \'no\');" class="tagSecondHalf useCursorPointer">x</span></div>' ) ;
} else {
$ ( '#filenames_' + element _id ) . html ( '<div id ="' + tmp _name + '_container" class ="template_file_box_container"><span class="tagFirstHalf template_file_box">' + filename + '</span><span onClick="templateDeleteFileBubble(\'' + filename + '\', \'' + tmp _name + '\', \'' + element _id + '\', \'normal\', \'no\');" class="tagSecondHalf useCursorPointer">x</span></div>' ) ;
}
} else {
if ( iframe == true ) {
$ ( '#filenames_' + element _id , window . parent . document ) . append ( '<div id ="' + tmp _name + '_container" class ="template_file_box_container"><span class="tagFirstHalf template_file_box">' + filename + '</span><span onClick="templateDeleteFileBubble(\'' + filename + '\', \'' + tmp _name + '\', \'' + element _id + '\', \'normal\', \'yes\');" class="tagSecondHalf useCursorPointer">x</span></div>' ) ;
} else {
$ ( '#filenames_' + element _id ) . append ( '<div id ="' + tmp _name + '_container" class ="template_file_box_container"><span class="tagFirstHalf template_file_box">' + filename + '</span><span onClick="templateDeleteFileBubble(\'' + filename + '\', \'' + tmp _name + '\', \'' + element _id + '\', \'normal\', \'yes\');" class="tagSecondHalf useCursorPointer">x</span></div>' ) ;
}
}
2017-04-13 16:31:48 +02:00
}
2014-07-02 16:20:19 +02:00
2017-04-13 16:31:48 +02:00
function templateDeleteFileBubble ( filename , tmp _name , element _id , context , batch ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . show ( ) ;
$ . ajax ( {
type : "post" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/templates/deleteTemporaryFile/" + tmp _name ,
2019-02-13 08:46:18 +01:00
} ) ;
var c = this ;
if ( context == 'iframe' ) {
$ ( '#' + tmp _name + '_container' , window . parent . document ) . remove ( ) ;
var oldArray = JSON . parse ( $ ( '#TemplateFileArray' , window . parent . document ) . val ( ) ) ;
} else {
$ ( '#' + tmp _name + '_container' ) . remove ( ) ;
var oldArray = JSON . parse ( $ ( '#TemplateFileArray' ) . val ( ) ) ;
}
var newArray = [ ] ;
oldArray . forEach ( function ( entry ) {
if ( batch == 'no' ) {
if ( entry . element _id != element _id ) {
newArray . push ( entry ) ;
}
} else {
if ( entry . tmp _name != tmp _name ) {
newArray . push ( entry ) ;
}
}
} ) ;
if ( batch == 'no' ) {
$ ( '#fileUploadButton_' + element _id , $ ( '#iframe_' + element _id ) . contents ( ) ) . html ( 'Upload File' ) ;
}
if ( context == 'iframe' ) {
$ ( '#TemplateFileArray' , window . parent . document ) . val ( JSON . stringify ( newArray ) ) ;
} else {
$ ( '#TemplateFileArray' ) . val ( JSON . stringify ( newArray ) ) ;
}
$ ( ".loading" ) . hide ( ) ;
2017-04-13 16:31:48 +02:00
}
2016-06-04 01:08:16 +02:00
2017-04-13 16:31:48 +02:00
function templateFileUploadTriggerBrowse ( id ) {
2019-02-13 08:46:18 +01:00
$ ( '#upload_' + id + '_file' ) . click ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-07-10 17:02:19 +02:00
2017-04-13 16:31:48 +02:00
function indexEvaluateFiltering ( ) {
2019-02-13 08:46:18 +01:00
if ( filterContext == "event" ) {
if ( filtering . published != 2 ) {
$ ( '#value_published' ) . html ( publishedOptions [ filtering . published ] ) ;
} else {
$ ( '#value_published' ) . html ( "" ) ;
}
if ( filtering . hasproposal != 2 ) {
$ ( '#value_hasproposal' ) . html ( publishedOptions [ filtering . hasproposal ] ) ;
} else {
$ ( '#value_hasproposal' ) . html ( "" ) ;
}
if ( filtering . date . from != null ) {
var text = "" ;
if ( filtering . date . from != "" ) text = "From: " + $ ( '<span>' ) . text ( filtering . date . from ) . html ( ) ;
if ( filtering . date . until != "" ) {
if ( text != "" ) text += " " ;
text += "Until: " + $ ( '<span>' ) . text ( filtering . date . until ) . html ( ) ;
}
}
$ ( '#value_date' ) . html ( text ) ;
2021-12-06 14:27:29 +01:00
2021-12-06 16:01:12 +01:00
if ( filtering . timestamp . from != null ) {
2021-12-06 14:27:29 +01:00
var text = "" ;
2021-12-06 16:01:12 +01:00
if ( filtering . timestamp . from != "" ) text = "From: " + $ ( '<span>' ) . text ( filtering . timestamp . from ) . html ( ) ;
if ( filtering . timestamp . until != "" ) {
if ( text != "" ) text += " " ;
text += "Until: " + $ ( '<span>' ) . text ( filtering . timestamp . until ) . html ( ) ;
}
2021-12-06 14:27:29 +01:00
}
$ ( '#value_timestamp' ) . html ( text ) ;
2021-12-06 16:01:12 +01:00
if ( filtering . publishtimestamp . from != null ) {
2021-12-06 14:27:29 +01:00
var text = "" ;
2021-12-06 16:01:12 +01:00
if ( filtering . publishtimestamp . from != "" ) text = "From: " + $ ( '<span>' ) . text ( filtering . publishtimestamp . from ) . html ( ) ;
if ( filtering . publishtimestamp . until != "" ) {
if ( text != "" ) text += " " ;
text += "Until: " + $ ( '<span>' ) . text ( filtering . publishtimestamp . until ) . html ( ) ;
}
2021-12-06 14:27:29 +01:00
}
$ ( '#value_publishtimestamp' ) . html ( text ) ;
2019-02-13 08:46:18 +01:00
for ( var i = 0 ; i < simpleFilters . length ; i ++ ) {
indexEvaluateSimpleFiltering ( simpleFilters [ i ] ) ;
}
indexRuleChange ( ) ;
} else {
for ( var i = 0 ; i < differentFilters . length ; i ++ ) {
if ( filtering [ differentFilters [ i ] ] != "" ) {
var text = "" ;
if ( filtering [ differentFilters [ i ] ] == 1 ) text = "Yes" ;
else if ( filtering [ differentFilters [ i ] ] == 0 ) text = "No" ;
$ ( '#value_' + differentFilters [ i ] ) . text ( text ) ;
} else {
$ ( '#value_' + differentFilters [ i ] ) . text ( "" ) ;
}
}
for ( var i = 0 ; i < simpleFilters . length ; i ++ ) {
indexEvaluateSimpleFiltering ( simpleFilters [ i ] ) ;
}
}
indexSetTableVisibility ( ) ;
indexSetRowVisibility ( ) ;
$ ( '#generatedURLContent' ) . text ( indexCreateFilters ( ) ) ;
2017-04-13 16:31:48 +02:00
}
2014-08-08 15:28:37 +02:00
2017-04-13 16:31:48 +02:00
function quickFilter ( passedArgs , url ) {
2019-02-13 08:46:18 +01:00
if ( ! passedArgs ) {
var passedArgs = [ ] ;
}
if ( $ ( '#quickFilterField' ) . val ( ) . trim ( ) . length > 0 ) {
2020-05-14 15:38:07 +02:00
passedArgs [ "searchall" ] = encodeURIComponent ( $ ( '#quickFilterField' ) . val ( ) . trim ( ) ) ;
2019-02-13 08:46:18 +01:00
for ( var key in passedArgs ) {
if ( key !== 'page' ) {
url += "/" + key + ":" + passedArgs [ key ] ;
}
}
}
window . location . href = url ;
2017-04-13 16:31:48 +02:00
}
2014-10-31 14:44:10 +01:00
2019-02-20 23:02:32 +01:00
function runIndexFilter ( element ) {
var dataFields = $ ( element ) . data ( ) ;
2022-03-27 21:47:46 +02:00
for ( var k in dataFields ) {
2019-02-20 23:02:32 +01:00
if ( k in passedArgsArray ) {
delete ( passedArgsArray [ k ] ) ;
} else {
passedArgsArray [ k ] = dataFields [ k ] ;
}
}
2022-03-27 21:47:46 +02:00
var url = here ;
2019-02-20 23:02:32 +01:00
for ( var key in passedArgsArray ) {
url += "/" + key + ":" + passedArgsArray [ key ] ;
}
window . location . href = url ;
}
2020-12-06 20:07:26 +01:00
function cancelSearch ( ) {
2020-12-05 14:13:28 +01:00
$ ( '#quickFilterField' ) . val ( '' ) ;
2020-12-06 20:07:26 +01:00
$ ( '#quickFilterButton' ) . click ( ) ;
2020-12-05 14:13:28 +01:00
}
2020-12-22 14:27:01 +01:00
// Deprecated, when possible use runIndexQuickFilterFixed that is cleaner
2020-11-30 23:41:34 +01:00
function runIndexQuickFilter ( preserveParams , url , target ) {
2020-12-11 16:01:19 +01:00
if ( typeof passedArgsArray === "undefined" ) {
2019-02-20 23:02:32 +01:00
var passedArgsArray = [ ] ;
}
2019-04-01 16:09:24 +02:00
var searchKey = 'searchall' ;
2022-04-25 12:08:20 +02:00
var $quickFilterField = $ ( '#quickFilterField' ) ;
if ( $quickFilterField . length > 0 ) {
if ( $quickFilterField . data ( 'searchkey' ) ) {
2020-12-02 11:51:19 +01:00
searchKey = $ ( '#quickFilterField' ) . data ( 'searchkey' ) ;
}
2022-04-25 12:08:20 +02:00
var value = $quickFilterField . val ( ) . trim ( ) ;
if ( value . length > 0 ) {
passedArgsArray [ searchKey ] = encodeURIComponent ( value ) ;
2020-12-02 11:51:19 +01:00
}
2019-02-20 23:02:32 +01:00
}
2020-11-30 23:41:34 +01:00
if ( typeof url === "undefined" ) {
url = here ;
}
2020-12-11 16:01:19 +01:00
if ( typeof preserveParams === "string" ) {
2020-11-30 23:41:34 +01:00
preserveParams = String ( preserveParams ) ;
if ( ! preserveParams . startsWith ( '/' ) ) {
preserveParams = '/' + preserveParams ;
}
2019-02-23 12:59:16 +01:00
url += preserveParams ;
2020-12-11 16:01:19 +01:00
} else if ( typeof preserveParams === "object" ) {
for ( var key in preserveParams ) {
if ( typeof key == 'number' ) {
url += "/" + preserveParams [ key ] ;
} else if ( key !== 'page' ) {
2021-01-05 08:40:37 +01:00
if ( key !== searchKey || ! ( searchKey in passedArgsArray ) ) {
url += "/" + key + ":" + preserveParams [ key ] ;
}
2020-12-11 16:01:19 +01:00
}
}
2019-02-23 12:59:16 +01:00
}
2019-02-20 23:02:32 +01:00
for ( var key in passedArgsArray ) {
2020-11-30 23:41:34 +01:00
if ( typeof key == 'number' ) {
url += "/" + passedArgsArray [ key ] ;
} else if ( key !== 'page' ) {
2019-02-20 23:02:32 +01:00
url += "/" + key + ":" + passedArgsArray [ key ] ;
}
}
2020-11-30 23:41:34 +01:00
if ( target !== undefined ) {
$ . ajax ( {
beforeSend : function ( ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data ) {
$ ( target ) . html ( data ) ;
} ,
error : function ( ) {
showMessage ( 'fail' , 'Could not fetch the requested data.' ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
type : "get" ,
url : url
} ) ;
} else {
window . location . href = url ;
}
2019-02-20 23:02:32 +01:00
}
2020-12-22 14:27:01 +01:00
/ * *
* @ param { object } preserveParams
* @ param { string } url
* @ param { string } [ target ]
* /
function runIndexQuickFilterFixed ( preserveParams , url , target ) {
var $quickFilterField = $ ( '#quickFilterField' ) ;
var searchKey ;
if ( $quickFilterField . data ( 'searchkey' ) ) {
searchKey = $quickFilterField . data ( 'searchkey' ) ;
} else {
searchKey = 'searchall' ;
}
if ( $quickFilterField . val ( ) . trim ( ) . length > 0 ) {
2023-06-14 18:39:06 +02:00
preserveParams [ searchKey ] = encodeURIComponent ( $quickFilterField . val ( ) . trim ( ) ) . replace ( '%20' , '+' ) ;
2020-12-22 14:27:01 +01:00
} else {
delete preserveParams [ searchKey ]
}
for ( var key in preserveParams ) {
2021-06-09 14:56:26 +02:00
if ( ! isNaN ( key ) ) {
2020-12-22 14:27:01 +01:00
url += "/" + preserveParams [ key ] ;
} else if ( key !== 'page' ) {
url += "/" + key + ":" + preserveParams [ key ] ;
}
}
if ( target !== undefined ) {
2021-02-19 15:38:03 +01:00
xhr ( {
2020-12-22 14:27:01 +01:00
success : function ( data ) {
$ ( target ) . html ( data ) ;
} ,
error : function ( ) {
showMessage ( 'fail' , 'Could not fetch the requested data.' ) ;
} ,
type : "get" ,
url : url
} ) ;
} else {
window . location . href = url ;
}
}
2017-04-13 16:31:48 +02:00
function executeFilter ( passedArgs , url ) {
2019-02-13 08:46:18 +01:00
for ( var key in passedArgs ) url += "/" + key + ":" + passedArgs [ key ] ;
window . location . href = url ;
2017-04-13 16:31:48 +02:00
}
2016-03-03 10:46:35 +01:00
2017-04-13 16:31:48 +02:00
function quickFilterTaxonomy ( taxonomy _id , passedArgs ) {
2020-08-16 13:31:31 +02:00
var url = baseurl + "/taxonomies/view/" + taxonomy _id + "/filter:" + encodeURIComponent ( $ ( '#quickFilterField' ) . val ( ) ) ;
2019-02-13 08:46:18 +01:00
window . location . href = url ;
2017-04-13 16:31:48 +02:00
}
2015-11-26 04:31:24 +01:00
2017-04-13 16:31:48 +02:00
function quickFilterRemoteEvents ( passedArgs , id ) {
2019-02-13 08:46:18 +01:00
passedArgs [ "searchall" ] = $ ( '#quickFilterField' ) . val ( ) ;
2020-08-16 13:31:31 +02:00
var url = baseurl + "/servers/previewIndex/" + id ;
2019-02-13 08:46:18 +01:00
for ( var key in passedArgs ) {
2020-05-14 15:38:07 +02:00
url += "/" + key + ":" + encodeURIComponent ( passedArgs [ key ] ) ;
2019-02-13 08:46:18 +01:00
}
window . location . href = url ;
2017-04-13 16:31:48 +02:00
}
2015-09-29 02:54:25 +02:00
2017-04-13 16:31:48 +02:00
function remoteIndexApplyFilters ( ) {
2019-02-13 08:46:18 +01:00
var url = actionUrl + '/' + $ ( "#EventFilter" ) . val ( ) ;
window . location . href = url ;
2017-04-13 16:31:48 +02:00
}
2016-06-04 01:08:16 +02:00
2017-04-13 16:31:48 +02:00
function indexApplyFilters ( ) {
2019-02-13 08:46:18 +01:00
var url = indexCreateFilters ( ) ;
window . location . href = url ;
2017-04-13 16:31:48 +02:00
}
2014-08-08 15:28:37 +02:00
2017-04-13 16:31:48 +02:00
function indexCreateFilters ( ) {
2019-02-13 08:46:18 +01:00
text = "" ;
if ( filterContext == 'event' ) {
if ( filtering . published != "2" ) {
text += "searchpublished:" + filtering . published ;
}
if ( filtering . hasproposal != "2" ) {
if ( text != "" ) text += "/" ;
text += "searchhasproposal:" + filtering . hasproposal ;
}
} else {
for ( var i = 0 ; i < differentFilters . length ; i ++ ) {
if ( filtering [ differentFilters [ i ] ] ) {
if ( text != "" ) text += "/" ;
text += "search" + differentFilters [ i ] + ":" + filtering [ differentFilters [ i ] ] ;
}
}
}
for ( var i = 0 ; i < simpleFilters . length ; i ++ ) {
text = indexBuildArray ( simpleFilters [ i ] , text ) ;
}
if ( filterContext == 'event' ) {
if ( filtering . date . from ) {
if ( text != "" ) text += "/" ;
text += "searchDatefrom:" + filtering . date . from ;
}
if ( filtering . date . until ) {
if ( text != "" ) text += "/" ;
text += "searchDateuntil:" + filtering . date . until ;
}
2021-12-06 16:01:12 +01:00
if ( filtering . timestamp . from ) {
2021-12-06 14:27:29 +01:00
if ( text != "" ) text += "/" ;
2021-12-06 16:01:12 +01:00
text += "searchTimestamp:" + filtering . timestamp . from ;
2021-12-06 14:27:29 +01:00
}
2021-12-06 16:01:12 +01:00
if ( filtering . timestamp . until ) {
2021-12-06 14:27:29 +01:00
if ( text != "" ) text += "/" ;
2021-12-06 16:01:12 +01:00
text += "searchTimestamp:" + filtering . timestamp . until ;
}
if ( filtering . publishtimestamp . from ) {
if ( text != "" ) text += "/" ;
text += "searchPublishTimestamp:" + filtering . publishtimestamp . from ;
}
if ( filtering . publishtimestamp . until ) {
if ( text != "" ) text += "/" ;
text += "searchPublishTimestamp:" + filtering . publishtimestamp . until ;
2021-12-06 14:27:29 +01:00
}
2019-02-13 08:46:18 +01:00
return baseurl + '/events/index/' + text ;
} else {
return baseurl + '/admin/users/index/' + text ;
}
2017-04-13 16:31:48 +02:00
}
2014-08-08 15:28:37 +02:00
2017-04-13 16:31:48 +02:00
function indexBuildArray ( type , text ) {
2019-02-13 08:46:18 +01:00
temp = "" ;
if ( text != "" ) temp += "/" ;
temp += "search" + type + ":" ;
if ( filtering [ type ] . NOT . length == 0 && filtering [ type ] . OR . length == 0 ) return text ;
var swap = filtering [ type ] . OR . length ;
var temp _array = filtering [ type ] . OR . concat ( filtering [ type ] . NOT ) ;
for ( var i = 0 ; i < temp _array . length ; i ++ ) {
if ( i > 0 ) temp += "|" ;
if ( i >= swap ) temp += "!" ;
temp += temp _array [ i ] ;
}
text += temp ;
return text ;
2017-04-13 16:31:48 +02:00
}
2014-08-08 15:28:37 +02:00
2017-04-13 16:31:48 +02:00
function indexSetRowVisibility ( ) {
2019-02-13 08:46:18 +01:00
for ( var i = 0 ; i < allFields . length ; i ++ ) {
if ( $ ( "#value_" + allFields [ i ] ) . text ( ) . trim ( ) != "" ) {
$ ( "#row_" + allFields [ i ] ) . show ( ) ;
} else {
$ ( "#row_" + allFields [ i ] ) . hide ( ) ;
}
}
2017-04-13 16:31:48 +02:00
}
2014-08-08 15:28:37 +02:00
2017-04-13 16:31:48 +02:00
function indexEvaluateSimpleFiltering ( field ) {
2021-03-20 20:02:00 +01:00
var text = "" ;
2019-02-13 08:46:18 +01:00
if ( filtering [ field ] . OR . length == 0 && filtering [ field ] . NOT . length == 0 ) {
$ ( '#value_' + field ) . html ( text ) ;
return false ;
}
if ( filtering [ field ] . OR . length != 0 ) {
for ( var i = 0 ; i < filtering [ field ] . OR . length ; i ++ ) {
if ( i > 0 ) text += '<span class="green bold"> OR </span>' ;
if ( typedFields . indexOf ( field ) == - 1 ) {
text += $ ( '<span>' ) . text ( filtering [ field ] . OR [ i ] ) . html ( ) ;
} else {
for ( var j = 0 ; j < typeArray [ field ] . length ; j ++ ) {
if ( typeArray [ field ] [ j ] . id == filtering [ field ] . OR [ i ] ) {
text += $ ( '<span>' ) . text ( typeArray [ field ] [ j ] . value ) . html ( ) ;
}
}
}
}
}
if ( filtering [ field ] . NOT . length != 0 ) {
for ( var i = 0 ; i < filtering [ field ] . NOT . length ; i ++ ) {
if ( i == 0 ) {
if ( text != "" ) text += '<span class="red bold"> AND NOT </span>' ;
else text += '<span class="red bold">NOT </span>' ;
} else text += '<span class="red bold"> AND NOT </span>' ;
if ( typedFields . indexOf ( field ) == - 1 ) {
text += $ ( '<span>' ) . text ( filtering [ field ] . NOT [ i ] ) . html ( ) ;
} else {
for ( var j = 0 ; j < typeArray [ field ] . length ; j ++ ) {
if ( typeArray [ field ] [ j ] . id == filtering [ field ] . NOT [ i ] ) {
text += $ ( '<span>' ) . text ( typeArray [ field ] [ j ] . value ) . html ( ) ;
}
}
}
}
}
$ ( '#value_' + field ) . html ( text ) ;
2017-04-13 16:31:48 +02:00
}
2014-08-08 15:28:37 +02:00
2017-04-13 16:31:48 +02:00
function indexAddRule ( param ) {
2019-02-13 08:46:18 +01:00
var found = false ;
if ( filterContext == 'event' ) {
2021-12-06 16:01:12 +01:00
if ( param . data . param1 == "date" || param . data . param1 == "timestamp" || param . data . param1 == "publishtimestamp" ) {
2020-05-14 15:38:07 +02:00
var val1 = encodeURIComponent ( $ ( '#EventSearch' + param . data . param1 + 'from' ) . val ( ) ) ;
var val2 = encodeURIComponent ( $ ( '#EventSearch' + param . data . param1 + 'until' ) . val ( ) ) ;
2021-12-06 16:01:12 +01:00
if ( val1 != "" ) filtering [ param . data . param1 ] . from = val1 ;
if ( val2 != "" ) filtering [ param . data . param1 ] . until = val2 ;
2019-02-13 08:46:18 +01:00
} else if ( param . data . param1 == "published" ) {
2020-05-14 15:38:07 +02:00
var value = encodeURIComponent ( $ ( '#EventSearchpublished' ) . val ( ) ) ;
2019-02-13 08:46:18 +01:00
if ( value != "" ) filtering . published = value ;
} else if ( param . data . param1 == "hasproposal" ) {
2020-05-14 15:38:07 +02:00
var value = encodeURIComponent ( $ ( '#EventSearchhasproposal' ) . val ( ) ) ;
2019-02-13 08:46:18 +01:00
if ( value != "" ) filtering . hasproposal = value ;
} else {
2020-05-14 15:38:07 +02:00
var value = encodeURIComponent ( $ ( '#EventSearch' + param . data . param1 ) . val ( ) ) ;
var operator = operators [ encodeURIComponent ( $ ( '#EventSearchbool' ) . val ( ) ) ] ;
2019-02-13 08:46:18 +01:00
if ( value != "" && filtering [ param . data . param1 ] [ operator ] . indexOf ( value ) < 0 ) filtering [ param . data . param1 ] [ operator ] . push ( value ) ;
}
} else if ( filterContext == 'user' ) {
if ( differentFilters . indexOf ( param . data . param1 ) != - 1 ) {
2020-05-14 15:38:07 +02:00
var value = encodeURIComponent ( $ ( '#UserSearch' + param . data . param1 ) . val ( ) ) ;
2019-02-13 08:46:18 +01:00
if ( value != "" ) filtering [ param . data . param1 ] = value ;
} else {
2020-05-14 15:38:07 +02:00
var value = encodeURIComponent ( $ ( '#UserSearch' + param . data . param1 ) . val ( ) ) ;
var operator = operators [ encodeURIComponent ( $ ( '#UserSearchbool' ) . val ( ) ) ] ;
2019-02-13 08:46:18 +01:00
if ( value != "" && filtering [ param . data . param1 ] [ operator ] . indexOf ( value ) < 0 ) filtering [ param . data . param1 ] [ operator ] . push ( value ) ;
}
}
indexEvaluateFiltering ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-08-08 15:28:37 +02:00
2017-04-13 16:31:48 +02:00
function indexSetTableVisibility ( ) {
2019-02-13 08:46:18 +01:00
var visible = false ;
if ( $ ( "[id^='value_']" ) . text ( ) . trim ( ) != "" && $ ( "[id^='value_']" ) . text ( ) . trim ( ) != "-1" ) {
visible = true ;
}
if ( visible == true ) $ ( '#FilterplaceholderTable' ) . hide ( ) ;
else $ ( '#FilterplaceholderTable' ) . show ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-08-08 15:28:37 +02:00
2017-04-13 16:31:48 +02:00
function indexRuleChange ( ) {
2019-02-13 08:46:18 +01:00
var context = filterContext . charAt ( 0 ) . toUpperCase ( ) + filterContext . slice ( 1 ) ;
$ ( '[id^=' + context + 'Search]' ) . hide ( ) ;
var rule = $ ( '#' + context + 'Rule' ) . val ( ) ;
var fieldName = '#' + context + 'Search' + rule ;
2021-12-06 16:01:12 +01:00
if ( fieldName === '#' + context + 'Searchdate' || fieldName === '#' + context + 'Searchtimestamp' || fieldName === '#' + context + 'Searchpublishtimestamp' ) {
2019-02-13 08:46:18 +01:00
$ ( fieldName + 'from' ) . show ( ) ;
$ ( fieldName + 'until' ) . show ( ) ;
} else {
2021-03-20 20:02:00 +01:00
if ( $ ( fieldName + '_chosen' ) . length ) {
$ ( fieldName + '_chosen' ) . show ( ) ;
} else {
$ ( fieldName ) . show ( ) ;
}
2019-02-13 08:46:18 +01:00
}
if ( simpleFilters . indexOf ( rule ) != - 1 ) {
$ ( '#' + context + 'Searchbool' ) . show ( ) ;
} else $ ( '#' + context + 'Searchbool' ) . hide ( ) ;
2021-03-20 20:02:00 +01:00
$ ( '#addRuleButton' ) . show ( ) . unbind ( "click" ) . click ( { param1 : rule } , indexAddRule ) ;
2017-04-13 16:31:48 +02:00
}
2014-08-08 15:28:37 +02:00
2017-04-13 16:31:48 +02:00
function indexFilterClearRow ( field ) {
2019-02-13 08:46:18 +01:00
$ ( '#value_' + field ) . html ( "" ) ;
$ ( '#row_' + field ) . hide ( ) ;
if ( field == "date" ) {
filtering . date . from = "" ;
filtering . date . until = "" ;
2021-12-06 14:27:29 +01:00
} else if ( field == "timestamp" ) {
2021-12-06 16:01:12 +01:00
filtering . timestamp . from = "" ;
filtering . timestamp . until = "" ;
2021-12-06 14:27:29 +01:00
} else if ( field == "publishtimestamp" ) {
2021-12-07 08:57:34 +01:00
filtering . publishtimestamp . from = "" ;
filtering . publishtimestamp . until = "" ;
2019-02-13 08:46:18 +01:00
} else if ( field == "published" ) {
filtering . published = 2 ;
} else if ( field == "hasproposal" ) {
filtering . hasproposal = 2 ;
} else if ( differentFilters . indexOf ( field ) != - 1 ) {
filtering [ field ] = "" ;
} else {
filtering [ field ] . NOT = [ ] ;
filtering [ field ] . OR = [ ] ;
}
indexSetTableVisibility ( ) ;
indexEvaluateFiltering ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-09-01 10:03:46 +02:00
2017-04-13 16:31:48 +02:00
function getSubGroupFromSetting ( setting ) {
2019-02-13 08:46:18 +01:00
var temp = setting . split ( '.' ) ;
if ( temp [ 0 ] == "Plugin" ) {
temp = temp [ 1 ] ;
if ( temp . indexOf ( '_' ) > - 1 ) {
temp = temp . split ( '_' ) ;
return temp [ 0 ] ;
}
}
return 'general' ;
2017-04-13 16:31:48 +02:00
}
2016-03-29 10:16:20 +02:00
2017-04-13 16:31:48 +02:00
function serverSettingsActivateField ( setting , id ) {
2019-02-13 08:46:18 +01:00
resetForms ( ) ;
$ ( '.inline-field-placeholder' ) . hide ( ) ;
var fieldName = "#setting_" + getSubGroupFromSetting ( setting ) + "_" + id ;
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
dataType : "html" ,
2021-02-19 15:38:03 +01:00
success : function ( data ) {
$ ( fieldName + "_placeholder" ) . html ( data ) . show ( ) ;
2019-02-13 08:46:18 +01:00
$ ( fieldName + "_solid" ) . hide ( ) ;
serverSettingsPostActivationScripts ( fieldName , setting , id ) ;
} ,
2021-02-19 15:38:03 +01:00
url : "/servers/serverSettingsEdit/" + setting + "/" + id ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-09-10 09:43:22 +02:00
2017-04-13 16:31:48 +02:00
function serverSettingsPostActivationScripts ( name , setting , id ) {
2019-02-13 08:46:18 +01:00
$ ( name + '_field' ) . focus ( ) ;
inputFieldButtonActive ( name + '_field' ) ;
$ ( name + '_form' ) . submit ( function ( e ) {
e . preventDefault ( ) ;
serverSettingSubmitForm ( name , setting , id ) ;
return false ;
} ) ;
$ ( name + '_form' ) . bind ( "focusout" , function ( ) {
inputFieldButtonPassive ( name + '_field' ) ;
} ) ;
$ ( name + '_form' ) . bind ( "focusin" , function ( ) {
inputFieldButtonActive ( name + '_field' ) ;
} ) ;
$ ( name + '_form' ) . bind ( "keydown" , function ( e ) {
if ( e . ctrlKey && ( e . keyCode == 13 || e . keyCode == 10 ) ) {
serverSettingSubmitForm ( name , setting , id ) ;
}
} ) ;
$ ( name + '_field' ) . closest ( '.inline-input-container' ) . children ( '.inline-input-accept' ) . bind ( 'click' , function ( ) {
serverSettingSubmitForm ( name , setting , id ) ;
} ) ;
$ ( name + '_field' ) . closest ( '.inline-input-container' ) . children ( '.inline-input-decline' ) . bind ( 'click' , function ( ) {
resetForms ( ) ;
$ ( '.inline-field-placeholder' ) . hide ( ) ;
} ) ;
$ ( name + '_solid' ) . hide ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-09-10 09:43:22 +02:00
2017-04-13 16:31:48 +02:00
function serverSettingSubmitForm ( name , setting , id ) {
2020-10-25 13:17:50 +01:00
var subGroup = getSubGroupFromSetting ( setting ) ;
2019-02-13 08:46:18 +01:00
var formData = $ ( name + '_field' ) . closest ( "form" ) . serialize ( ) ;
$ . ajax ( {
data : formData ,
cache : false ,
2020-10-25 13:17:50 +01:00
beforeSend : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . show ( ) ;
} ,
2020-10-25 13:17:50 +01:00
success : function ( data ) {
if ( ! data . saved ) {
$ ( ".loading" ) . hide ( ) ;
showMessage ( 'fail' , data . errors ) ;
resetForms ( ) ;
$ ( '.inline-field-placeholder' ) . hide ( ) ;
return ;
}
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2020-10-25 13:17:50 +01:00
type : "get" ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/servers/serverSettingsReloadSetting/" + setting + "/" + id ,
2020-10-25 13:17:50 +01:00
success : function ( data2 ) {
2019-02-13 08:46:18 +01:00
$ ( '#' + subGroup + "_" + id + '_row' ) . replaceWith ( data2 ) ;
$ ( ".loading" ) . hide ( ) ;
} ,
2020-10-25 13:17:50 +01:00
error : function ( ) {
2019-02-13 08:46:18 +01:00
showMessage ( 'fail' , 'Could not refresh the table.' ) ;
}
} ) ;
} ,
2020-10-25 13:17:50 +01:00
error : function ( ) {
$ ( ".loading" ) . hide ( ) ;
2019-02-13 08:46:18 +01:00
showMessage ( 'fail' , 'Request failed for an unknown reason.' ) ;
resetForms ( ) ;
$ ( '.inline-field-placeholder' ) . hide ( ) ;
} ,
2020-10-25 13:17:50 +01:00
type : "post" ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/servers/serverSettingsEdit/" + setting + "/" + id + "/" + 1
2019-02-13 08:46:18 +01:00
} ) ;
$ ( name + '_field' ) . unbind ( "keyup" ) ;
$ ( name + '_form' ) . unbind ( "focusout" ) ;
return false ;
2017-04-13 16:31:48 +02:00
}
2015-02-23 11:33:38 +01:00
2017-04-13 16:31:48 +02:00
function updateOrgCreateImageField ( string ) {
2020-05-14 15:38:07 +02:00
string = encodeURIComponent ( string ) ;
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2020-08-17 17:25:02 +02:00
url : baseurl + '/img/orgs/' + string + '.png' ,
2019-02-13 08:46:18 +01:00
type : 'HEAD' ,
error :
function ( ) {
$ ( '#logoDiv' ) . html ( 'No image uploaded for this identifier' ) ;
} ,
success :
function ( ) {
2020-08-17 17:57:30 +02:00
$ ( '#logoDiv' ) . html ( '<img src="' + baseurl + '/img/orgs/' + string + '.png" style="width:24px;height:24px;"></img>' ) ;
2019-02-13 08:46:18 +01:00
}
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-02-23 11:33:38 +01:00
2017-04-13 16:31:48 +02:00
function generateOrgUUID ( ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2020-08-16 13:31:31 +02:00
url : baseurl + '/admin/organisations/generateuuid.json' ,
2019-02-13 08:46:18 +01:00
success :
function ( data ) {
$ ( '#OrganisationUuid' ) . val ( data . uuid ) ;
}
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-02-23 11:33:38 +01:00
2017-04-13 16:31:48 +02:00
function sharingGroupIndexMembersCollapse ( id ) {
2019-02-13 08:46:18 +01:00
$ ( '#' + id + '_down' ) . show ( ) ;
$ ( '#' + id + '_up' ) . hide ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-02-23 11:33:38 +01:00
2017-04-13 16:31:48 +02:00
function sharingGroupIndexMembersExpand ( id ) {
2019-02-13 08:46:18 +01:00
$ ( '#' + id + '_down' ) . hide ( ) ;
$ ( '#' + id + '_up' ) . show ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-02-23 11:33:38 +01:00
2017-04-13 16:31:48 +02:00
function popoverStartup ( ) {
$ ( '[data-toggle="popover"]' ) . popover ( {
animation : true ,
html : true ,
} ) . click ( function ( e ) {
2019-02-13 08:46:18 +01:00
$ ( e . target ) . popover ( 'show' ) ;
$ ( '[data-toggle="popover"]' ) . not ( e . target ) . popover ( 'hide' ) ;
2017-04-13 16:31:48 +02:00
} ) ;
$ ( document ) . click ( function ( e ) {
2022-05-05 22:02:39 +02:00
var $popovers = $ ( '[data-toggle="popover"]' ) ;
if ( ! $popovers . is ( e . target ) ) {
$popovers . popover ( 'hide' ) ;
2017-04-13 16:31:48 +02:00
}
} ) ;
}
2015-02-23 11:38:54 +01:00
2017-04-13 16:31:48 +02:00
function changeFreetextImportFrom ( ) {
2022-04-15 19:28:57 +02:00
var $changeTo = $ ( '#changeTo' ) ;
$changeTo . empty ( ) ;
2019-02-13 08:46:18 +01:00
options [ $ ( '#changeFrom' ) . val ( ) ] . forEach ( function ( element ) {
2022-04-15 19:28:57 +02:00
$changeTo . append ( new Option ( element ) ) ;
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-12-10 13:06:52 +01:00
2017-04-13 16:31:48 +02:00
function changeFreetextImportCommentExecute ( ) {
2019-02-13 08:46:18 +01:00
$ ( '.freetextCommentField' ) . val ( $ ( '#changeComments' ) . val ( ) ) ;
2017-04-13 16:31:48 +02:00
}
2015-06-25 12:21:37 +02:00
2017-04-13 16:31:48 +02:00
function changeFreetextImportExecute ( ) {
2019-02-13 08:46:18 +01:00
var from = $ ( '#changeFrom' ) . val ( ) ;
var to = $ ( '#changeTo' ) . val ( ) ;
$ ( '.typeToggle' ) . each ( function ( ) {
2022-04-15 19:28:57 +02:00
if ( $ ( this ) . val ( ) === from ) {
if ( selectContainsOption ( "#" + $ ( this ) . attr ( 'id' ) , to ) ) {
$ ( this ) . val ( to ) ;
}
2019-02-13 08:46:18 +01:00
}
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-12-19 13:32:16 +01:00
2017-04-13 16:31:48 +02:00
function selectContainsOption ( selectid , value ) {
2019-02-13 08:46:18 +01:00
var exists = false ;
$ ( selectid + ' option' ) . each ( function ( ) {
2022-04-15 19:28:57 +02:00
if ( this . value === value ) {
2019-02-13 08:46:18 +01:00
exists = true ;
return false ;
}
} ) ;
return exists ;
2017-04-13 16:31:48 +02:00
}
2015-02-10 14:42:24 +01:00
2018-02-22 12:02:34 +01:00
function exportChoiceSelect ( e ) {
2019-02-13 08:46:18 +01:00
if ( $ ( e . target ) . is ( "input" ) ) {
return false ;
}
var url = $ ( e . target ) . parent ( ) . data ( "export-url" ) ;
var elementId = $ ( e . target ) . parent ( ) . data ( "export-key" ) ;
var checkbox = $ ( e . target ) . parent ( ) . data ( "export-checkbox" ) ;
if ( checkbox == 1 ) {
if ( $ ( '#' + elementId + '_toggle' ) . prop ( 'checked' ) ) {
url = $ ( '#' + elementId + '_set' ) . html ( ) ;
}
}
document . location . href = url ;
2017-04-13 16:31:48 +02:00
}
2015-02-10 14:42:24 +01:00
2022-10-03 20:35:56 +02:00
function importChoiceSelect ( url , ajax ) {
2019-02-13 08:46:18 +01:00
if ( ajax == 'false' ) {
document . location . href = url ;
} else {
simplePopup ( url ) ;
}
2017-04-13 16:31:48 +02:00
}
2016-08-01 16:15:24 +02:00
2022-10-03 15:31:56 +02:00
function freetextSerializeAttributes ( ) {
2019-02-13 08:46:18 +01:00
var attributeArray = [ ] ;
2022-10-03 15:31:56 +02:00
$ ( '.freetext_row' ) . each ( function ( ) {
var i = $ ( this ) . data ( 'row' ) ;
2019-02-13 08:46:18 +01:00
if ( $ ( '#Attribute' + i + 'Save' ) . val ( ) == 1 ) {
2022-04-15 16:14:52 +02:00
attributeArray . push ( {
2019-02-13 08:46:18 +01:00
value : $ ( '#Attribute' + i + 'Value' ) . val ( ) ,
category : $ ( '#Attribute' + i + 'Category' ) . val ( ) ,
type : $ ( '#Attribute' + i + 'Type' ) . val ( ) ,
to _ids : $ ( '#Attribute' + i + 'To_ids' ) [ 0 ] . checked ,
2019-04-03 16:19:17 +02:00
disable _correlation : $ ( '#Attribute' + i + 'Disable_correlation' ) [ 0 ] . checked ,
2019-02-13 08:46:18 +01:00
comment : $ ( '#Attribute' + i + 'Comment' ) . val ( ) ,
distribution : $ ( '#Attribute' + i + 'Distribution' ) . val ( ) ,
sharing _group _id : $ ( '#Attribute' + i + 'SharingGroupId' ) . val ( ) ,
data : $ ( '#Attribute' + i + 'Data' ) . val ( ) ,
data _is _handled : $ ( '#Attribute' + i + 'DataIsHandled' ) . val ( ) ,
tags : $ ( '#Attribute' + i + 'Tags' ) . val ( )
2022-04-15 16:14:52 +02:00
} )
2019-02-13 08:46:18 +01:00
}
2022-10-03 15:31:56 +02:00
} ) ;
return attributeArray ;
}
function freetextImportResultsSubmit ( event _id , count ) {
var attributeArray = freetextSerializeAttributes ( ) ;
2019-02-13 08:46:18 +01:00
$ ( "#AttributeJsonObject" ) . val ( JSON . stringify ( attributeArray ) ) ;
var formData = $ ( ".mainForm" ) . serialize ( ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
type : "post" ,
2022-04-15 16:14:52 +02:00
url : "/events/saveFreeText/" + event _id ,
2019-02-13 08:46:18 +01:00
data : formData ,
2020-10-11 11:50:11 +02:00
success : function ( ) {
2022-04-15 16:14:52 +02:00
window . location = baseurl + '/events/view/' + event _id ;
2019-02-13 08:46:18 +01:00
} ,
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-03-21 14:27:53 +01:00
2022-10-03 09:55:52 +02:00
function freetextRemoveRow ( id , event _id ) {
$ ( '.freetext_row[data-row=' + id + ']' ) . hide ( ) ;
$ ( '#Attribute' + id + 'Save' ) . attr ( "value" , "0" ) ;
if ( $ ( ".freetext_row:visible" ) . length == 0 ) {
window . location = baseurl + "/events/" + event _id ;
2022-10-03 15:31:56 +02:00
} else {
freetextPossibleObjectTemplates ( ) ;
2022-10-03 09:55:52 +02:00
}
}
2022-10-03 15:31:56 +02:00
function freetextCreateObject ( objectId ) {
var attributeArray = freetextSerializeAttributes ( ) ;
$ ( '#ObjectSelectedTemplateId' ) . val ( objectId ) ;
$ ( '#ObjectAttributes' ) . val ( JSON . stringify ( attributeArray ) ) ;
$ ( '#ObjectFreeTextImportForm' ) . submit ( ) ;
}
function freetextPossibleObjectTemplates ( ) {
2022-10-03 09:55:52 +02:00
var allTypes = [ ] ;
$ ( '.freetext_row' ) . each ( function ( ) {
var rowId = $ ( this ) . data ( 'row' ) ;
if ( $ ( '#Attribute' + rowId + 'Save' ) . val ( ) === "1" ) {
2022-10-03 15:31:56 +02:00
var type = $ ( this ) . find ( '.typeToggle' ) . val ( ) ;
if ( type === 'ip-src/ip-dst' ) {
allTypes . push ( 'ip-src' , 'ip-dst' ) ;
} else if ( type === 'ip-src|port/ip-dst|port' ) {
allTypes . push ( 'ip-src|port' , 'ip-dst|port' ) ;
} else {
allTypes . push ( type ) ;
}
2022-10-03 09:55:52 +02:00
}
} ) ;
if ( allTypes . length < 2 ) {
$ ( '.createObject' ) . hide ( ) ;
2022-10-03 15:31:56 +02:00
return ;
2022-10-03 09:55:52 +02:00
}
$ . ajax ( {
dataType : "json" ,
data : { "attributeTypes" : allTypes } ,
success : function ( data ) {
if ( data . length === 0 ) {
$ ( '.createObject' ) . hide ( ) ;
2022-10-03 15:31:56 +02:00
return ;
}
2022-10-03 09:55:52 +02:00
2022-10-03 15:31:56 +02:00
var $menu = $ ( '.createObject ul' ) ;
$menu . find ( 'li' ) . remove ( ) ;
2022-10-03 09:55:52 +02:00
2022-10-03 15:31:56 +02:00
$ . each ( data , function ( i , template ) {
var a = document . createElement ( 'a' ) ;
a . href = '#' ;
a . onclick = function ( ) {
freetextCreateObject ( template [ 'id' ] ) ;
} ;
a . textContent = template . name ;
a . title = template . description ;
2022-10-03 09:55:52 +02:00
2022-10-03 15:31:56 +02:00
var li = document . createElement ( 'li' ) ;
li . appendChild ( a ) ;
2022-10-03 09:55:52 +02:00
2022-10-03 15:31:56 +02:00
$menu . append ( li ) ;
} ) ;
$ ( '.createObject' ) . show ( ) ;
2022-10-03 09:55:52 +02:00
} ,
type : "post" ,
url : baseurl + "/objectTemplates/possibleObjectTemplates" ,
} ) ;
}
2019-04-03 22:59:58 +02:00
function moduleResultsSubmit ( id ) {
2019-06-20 14:37:33 +02:00
var typesWithData = [ 'attachment' , 'malware-sample' ] ;
2019-04-03 22:59:58 +02:00
var data _collected = { } ;
var temp ;
2019-06-14 18:11:47 +02:00
if ( $ ( '.meta_table' ) . length ) {
var tags = [ ] ;
$ ( '.meta_table' ) . find ( '.tag' ) . each ( function ( ) {
tags . push ( { name : $ ( this ) . text ( ) } ) ;
} ) ;
if ( tags . length ) {
data _collected [ 'Tag' ] = tags ;
}
}
2019-04-29 17:14:23 +02:00
if ( $ ( '.MISPObject' ) . length ) {
2019-04-03 22:59:58 +02:00
var objects = [ ] ;
2020-11-27 22:25:24 +01:00
$ ( ".MISPObject" ) . each ( function ( ) {
2019-04-03 22:59:58 +02:00
var object _uuid = $ ( this ) . find ( '.ObjectUUID' ) . text ( ) ;
temp = {
uuid : object _uuid ,
2019-12-12 15:24:20 +01:00
import _object : $ ( this ) . find ( '.ImportMISPObject' ) [ 0 ] . checked ,
2019-04-03 22:59:58 +02:00
name : $ ( this ) . find ( '.ObjectName' ) . text ( ) ,
2019-04-04 09:37:52 +02:00
meta _category : $ ( this ) . find ( '.ObjectMetaCategory' ) . text ( ) ,
2019-04-03 22:59:58 +02:00
distribution : $ ( this ) . find ( '.ObjectDistribution' ) . val ( ) ,
2019-08-08 15:50:09 +02:00
sharing _group _id : $ ( this ) . find ( '.ObjectSharingGroup' ) . val ( ) ,
comment : $ ( this ) . find ( '.ObjectComment' ) . val ( )
2019-04-03 22:59:58 +02:00
}
2019-12-12 15:24:20 +01:00
if ( ! temp [ 'import_object' ] ) {
return true ;
}
2019-04-04 16:28:49 +02:00
if ( temp [ 'distribution' ] != '4' ) {
temp [ 'sharing_group_id' ] = '0' ;
}
2019-04-03 22:59:58 +02:00
if ( $ ( this ) . has ( '.ObjectID' ) . length ) {
temp [ 'id' ] = $ ( this ) . find ( '.ObjectID' ) . text ( ) ;
}
2019-08-02 16:56:49 +02:00
if ( $ ( this ) . has ( '.ObjectDescription' ) . length ) {
temp [ 'description' ] = $ ( this ) . find ( '.ObjectDescription' ) . text ( ) ;
}
2019-04-09 16:36:58 +02:00
if ( $ ( this ) . has ( '.TemplateVersion' ) . length ) {
temp [ 'template_version' ] = $ ( this ) . find ( '.TemplateVersion' ) . text ( ) ;
}
if ( $ ( this ) . has ( '.TemplateUUID' ) . length ) {
temp [ 'template_uuid' ] = $ ( this ) . find ( '.TemplateUUID' ) . text ( ) ;
}
2021-03-31 13:25:11 +02:00
if ( $ ( this ) . has ( '.ObjectFirstSeen' ) . length ) {
temp [ 'first_seen' ] = $ ( this ) . find ( '.ObjectFirstSeen' ) . text ( ) ;
}
if ( $ ( this ) . has ( '.ObjectLastSeen' ) . length ) {
temp [ 'last_seen' ] = $ ( this ) . find ( '.ObjectLastSeen' ) . text ( ) ;
}
2019-04-29 17:14:23 +02:00
if ( $ ( this ) . has ( '.ObjectReference' ) . length ) {
2019-04-03 22:59:58 +02:00
var references = [ ] ;
$ ( this ) . find ( '.ObjectReference' ) . each ( function ( ) {
var reference = {
object _uuid : object _uuid ,
referenced _uuid : $ ( this ) . find ( '.ReferencedUUID' ) . text ( ) ,
2019-04-10 17:15:13 +02:00
relationship _type : $ ( this ) . find ( '.Relationship' ) . text ( )
2019-04-03 22:59:58 +02:00
} ;
references . push ( reference ) ;
} ) ;
temp [ 'ObjectReference' ] = references ;
}
2019-04-29 17:14:23 +02:00
if ( $ ( this ) . find ( '.ObjectAttribute' ) . length ) {
2019-04-03 22:59:58 +02:00
var object _attributes = [ ] ;
2020-11-27 22:25:24 +01:00
$ ( this ) . find ( '.ObjectAttribute' ) . each ( function ( ) {
2019-06-20 14:37:33 +02:00
var attribute _type = $ ( this ) . find ( '.AttributeType' ) . text ( ) ;
2020-11-27 22:25:24 +01:00
var attribute = {
2019-12-16 16:22:28 +01:00
import _attribute : $ ( this ) . find ( '.ImportMISPObjectAttribute' ) [ 0 ] . checked ,
2019-04-09 16:32:53 +02:00
object _relation : $ ( this ) . find ( '.ObjectRelation' ) . text ( ) ,
2019-04-03 22:59:58 +02:00
category : $ ( this ) . find ( '.AttributeCategory' ) . text ( ) ,
2019-06-20 14:37:33 +02:00
type : attribute _type ,
2022-10-05 18:28:46 +02:00
value : $ ( this ) . find ( '.AttributeValue' ) . data ( 'value' ) ,
2019-04-03 22:59:58 +02:00
uuid : $ ( this ) . find ( '.AttributeUuid' ) . text ( ) ,
to _ids : $ ( this ) . find ( '.AttributeToIds' ) [ 0 ] . checked ,
disable _correlation : $ ( this ) . find ( '.AttributeDisableCorrelation' ) [ 0 ] . checked ,
comment : $ ( this ) . find ( '.AttributeComment' ) . val ( ) ,
distribution : $ ( this ) . find ( '.AttributeDistribution' ) . val ( ) ,
sharing _group _id : $ ( this ) . find ( '.AttributeSharingGroup' ) . val ( )
}
2019-12-16 16:22:28 +01:00
if ( ! attribute [ 'import_attribute' ] ) {
return true ;
}
2019-04-04 16:28:49 +02:00
if ( attribute [ 'distribution' ] != '4' ) {
attribute [ 'sharing_group_id' ] = '0' ;
}
2019-06-14 18:16:09 +02:00
if ( $ ( this ) . find ( '.objectAttributeTagContainer' ) . length ) {
var tags = [ ] ;
$ ( this ) . find ( '.objectAttributeTag' ) . each ( function ( ) {
2020-08-10 10:38:28 +02:00
tags . push ( {
name : $ ( this ) . attr ( 'title' ) ,
2021-03-09 20:39:24 +01:00
colour : rgb2hex ( $ ( this ) . css ( 'background-color' ) ) ,
local : $ ( this ) . data ( 'local' ) ,
2020-08-10 10:38:28 +02:00
} ) ;
2019-06-14 18:16:09 +02:00
} ) ;
attribute [ 'Tag' ] = tags ;
}
2019-08-02 15:19:26 +02:00
if ( typesWithData . indexOf ( attribute _type ) != - 1 ) {
if ( $ ( this ) . find ( '.AttributeData' ) . length ) {
attribute [ 'data' ] = $ ( this ) . find ( '.AttributeData' ) . val ( ) ;
}
if ( $ ( this ) . find ( '.AttributeEncrypt' ) . length ) {
attribute [ 'encrypt' ] = $ ( this ) . find ( '.AttributeEncrypt' ) . val ( ) ;
}
2019-06-20 14:37:33 +02:00
}
2019-04-03 22:59:58 +02:00
object _attributes . push ( attribute ) ;
} ) ;
temp [ 'Attribute' ] = object _attributes ;
}
objects . push ( temp ) ;
} ) ;
data _collected [ 'Object' ] = objects ;
}
2019-04-29 17:14:23 +02:00
if ( $ ( '.MISPAttribute' ) . length ) {
2019-04-03 22:59:58 +02:00
var attributes = [ ] ;
2020-10-15 19:01:01 +02:00
$ ( '.MISPAttribute' ) . each ( function ( ) {
2019-04-25 16:30:42 +02:00
var category _value ;
var type _value ;
if ( $ ( this ) . find ( '.AttributeCategorySelect' ) . length ) {
category _value = $ ( this ) . find ( '.AttributeCategorySelect' ) . val ( ) ;
} else {
category _value = $ ( this ) . find ( '.AttributeCategory' ) . text ( ) ;
}
if ( $ ( this ) . find ( '.AttributeTypeSelect' ) . length ) {
type _value = $ ( this ) . find ( '.AttributeTypeSelect' ) . val ( ) ;
} else {
type _value = $ ( this ) . find ( '.AttributeType' ) . text ( ) ;
}
2019-04-03 22:59:58 +02:00
temp = {
2019-12-16 16:22:28 +01:00
import _attribute : $ ( this ) . find ( '.ImportMISPAttribute' ) [ 0 ] . checked ,
2019-04-25 16:30:42 +02:00
category : category _value ,
type : type _value ,
2022-10-05 18:28:46 +02:00
value : $ ( this ) . find ( '.AttributeValue' ) . data ( 'value' ) ,
2019-04-03 22:59:58 +02:00
uuid : $ ( this ) . find ( '.AttributeUuid' ) . text ( ) ,
to _ids : $ ( this ) . find ( '.AttributeToIds' ) [ 0 ] . checked ,
disable _correlation : $ ( this ) . find ( '.AttributeDisableCorrelation' ) [ 0 ] . checked ,
comment : $ ( this ) . find ( '.AttributeComment' ) . val ( ) ,
distribution : $ ( this ) . find ( '.AttributeDistribution' ) . val ( ) ,
sharing _group _id : $ ( this ) . find ( '.AttributeSharingGroup' ) . val ( )
}
2019-12-16 16:22:28 +01:00
if ( ! temp [ 'import_attribute' ] ) {
return true ;
}
2019-04-04 16:28:49 +02:00
if ( temp [ 'distribution' ] != '4' ) {
temp [ 'sharing_group_id' ] = '0' ;
}
2019-06-14 18:16:09 +02:00
if ( $ ( this ) . find ( '.attributeTagContainer' ) . length ) {
var tags = [ ] ;
$ ( this ) . find ( '.attributeTag' ) . each ( function ( ) {
2020-08-10 10:38:28 +02:00
tags . push ( {
name : $ ( this ) . attr ( 'title' ) ,
2021-03-09 20:39:24 +01:00
colour : rgb2hex ( $ ( this ) . css ( 'background-color' ) ) ,
local : $ ( this ) . data ( 'local' ) ,
2020-08-10 10:38:28 +02:00
} ) ;
2019-06-14 18:16:09 +02:00
} ) ;
temp [ 'Tag' ] = tags ;
}
2019-08-02 15:19:26 +02:00
if ( typesWithData . indexOf ( type _value ) != - 1 ) {
if ( $ ( this ) . find ( '.AttributeData' ) . length ) {
temp [ 'data' ] = $ ( this ) . find ( '.AttributeData' ) . val ( ) ;
}
if ( $ ( this ) . find ( '.AttributeEncrypt' ) . length ) {
temp [ 'encrypt' ] = $ ( this ) . find ( '.AttributeEncrypt' ) . val ( ) ;
}
2019-06-20 14:37:33 +02:00
}
2019-04-03 22:59:58 +02:00
attributes . push ( temp ) ;
} ) ;
data _collected [ 'Attribute' ] = attributes ;
}
2021-02-15 16:32:47 +01:00
if ( $ ( '.MISPEventReport' ) . length ) {
var reports = [ ] ;
$ ( '.MISPEventReport' ) . each ( function ( ) {
temp = {
import _report : $ ( this ) . find ( '.ImportMISPEventReport' ) [ 0 ] . checked ,
name : $ ( this ) . find ( '.EventReportName' ) . text ( ) ,
content : $ ( this ) . find ( '.EventReportContent' ) . text ( ) ,
uuid : $ ( this ) . find ( '.EventReportUUID' ) . text ( ) ,
distribution : $ ( this ) . find ( '.EventReportDistribution' ) . val ( ) ,
sharing _group _id : $ ( this ) . find ( '.EventReportSharingGroup' ) . val ( )
}
if ( temp [ 'import_report' ] ) {
reports . push ( temp ) ;
}
} ) ;
data _collected [ 'EventReport' ] = reports ;
}
2019-04-04 16:28:49 +02:00
$ ( "#EventJsonObject" ) . val ( JSON . stringify ( data _collected ) ) ;
var formData = $ ( '.mainForm' ) . serialize ( ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2019-04-03 22:59:58 +02:00
type : "post" ,
2021-02-19 15:38:03 +01:00
url : "/events/handleModuleResults/" + id ,
2019-04-04 16:28:49 +02:00
data : formData ,
2020-10-15 19:01:01 +02:00
success : function ( ) {
2020-08-16 13:31:31 +02:00
window . location = baseurl + '/events/view/' + id ;
2019-04-03 22:59:58 +02:00
} ,
} ) ;
}
2017-07-02 00:05:15 +02:00
function objectTemplateViewContent ( context , id ) {
2021-02-19 15:38:03 +01:00
var url = "/objectTemplateElements/viewElements/" + id + "/" + context ;
xhr ( {
2020-10-15 19:01:01 +02:00
url : url ,
type : 'GET' ,
error : function ( ) {
2021-02-19 15:38:03 +01:00
$ ( '#ajaxContent' ) . html ( 'An error has occurred, please reload the page.' ) ;
2020-10-15 19:01:01 +02:00
} ,
success : function ( response ) {
$ ( '#ajaxContent' ) . html ( response ) ;
} ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-07-02 00:05:15 +02:00
}
2017-04-13 16:31:48 +02:00
function organisationViewContent ( context , id ) {
2019-02-13 08:46:18 +01:00
organisationViewButtonHighlight ( context ) ;
2020-10-09 18:03:10 +02:00
var action ;
if ( context === 'members' ) {
2019-02-13 08:46:18 +01:00
action = "/admin/users/index/searchorg:" ;
2020-10-09 18:03:10 +02:00
} else if ( context === 'events' ) {
2019-02-13 08:46:18 +01:00
action = "/events/index/searchorg:" ;
2021-01-07 11:32:10 +01:00
} else if ( context === 'sharing_groups' ) {
action = "/sharing_groups/index/searchorg:" ;
2019-02-13 08:46:18 +01:00
}
2021-02-19 15:38:03 +01:00
xhr ( {
url : action + id ,
2019-02-13 08:46:18 +01:00
type : 'GET' ,
error : function ( ) {
2021-02-19 15:38:03 +01:00
$ ( '#ajaxContent' ) . html ( 'An error has occurred, please reload the page.' ) ;
2019-02-13 08:46:18 +01:00
} ,
success : function ( response ) {
$ ( '#ajaxContent' ) . html ( response ) ;
} ,
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-03-21 14:27:53 +01:00
2017-04-13 16:31:48 +02:00
function organisationViewButtonHighlight ( context ) {
2019-02-13 08:46:18 +01:00
$ ( ".orgViewButtonActive" ) . hide ( ) ;
$ ( ".orgViewButton" ) . show ( ) ;
$ ( "#button_" + context ) . hide ( ) ;
$ ( "#button_" + context + "_active" ) . show ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function simpleTabPage ( page ) {
2019-02-23 16:17:09 +01:00
$ ( ".progress_tab" ) . removeClass ( "btn-primary" ) . addClass ( "btn-inverse" ) ;
$ ( "#page" + page + "_tab" ) . removeClass ( "btn-inverse" ) . addClass ( "btn-primary" ) ;
2019-02-13 08:46:18 +01:00
$ ( ".tabContent" ) . hide ( ) ;
$ ( "#page" + page + "_content" ) . show ( ) ;
if ( page == lastPage ) simpleTabPageLast ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function simpleTabPageLast ( ) {
2019-02-13 08:46:18 +01:00
var summaryorgs = summaryextendorgs = remotesummaryorgs = remotesummaryextendorgs = summaryservers = "" ;
var orgcounter = extendcounter = remoteorgcounter = remoteextendcounter = servercounter = 0 ;
var sgname = "[Sharing group name not set!]" ;
if ( $ ( '#SharingGroupName' ) . val ( ) ) sgname = $ ( '#SharingGroupName' ) . val ( ) ;
var sgreleasability = "[Sharing group releasability not set!]" ;
if ( $ ( '#SharingGroupReleasability' ) . val ( ) ) sgreleasability = $ ( '#SharingGroupReleasability' ) . val ( ) ;
$ ( '#summarytitle' ) . text ( sgname ) ;
$ ( '#summaryreleasable' ) . text ( sgreleasability ) ;
organisations . forEach ( function ( organisation ) {
if ( organisation . type == 'local' ) {
if ( orgcounter > 0 ) summaryorgs += ", " ;
summaryorgs += organisation . name ;
if ( organisation . extend == true ) {
if ( extendcounter > 0 ) summaryextendorgs += ", "
summaryextendorgs += organisation . name ;
extendcounter ++ ;
}
orgcounter ++ ;
} else {
if ( remoteorgcounter > 0 ) remotesummaryorgs += ", " ;
remotesummaryorgs += organisation . name ;
if ( organisation . extend == true ) {
if ( remoteextendcounter > 0 ) remotesummaryextendorgs += ", "
remotesummaryextendorgs += organisation . name ;
remoteextendcounter ++ ;
}
remoteorgcounter ++ ;
}
} ) ;
if ( orgcounter == 0 ) $ ( '#localText' ) . hide ( ) ;
if ( remoteorgcounter == 0 ) $ ( '#externalText' ) . hide ( ) ;
if ( extendcounter == 0 ) summaryextendorgs = "nobody" ;
if ( remoteextendcounter == 0 ) remotesummaryextendorgs = "nobody" ;
servers . forEach ( function ( server ) {
if ( servercounter > 0 ) summaryservers += ", " ;
if ( server . id != 0 ) {
summaryservers += server . name ;
if ( extendcounter == 0 ) summaryextendorgs = "none" ;
servercounter ++ ;
}
if ( server . id == 0 && server . all _orgs == true ) summaryorgs = "all organisations on this instance" ;
} ) ;
if ( $ ( '#SharingGroupRoaming' ) . is ( ":checked" ) ) {
summaryservers = "any interconnected instances linked by an eligible organisation." ;
} else {
if ( servercounter == 0 ) {
summaryservers = "data marked with this sharing group will not be pushed." ;
}
}
$ ( '#summarylocal' ) . text ( summaryorgs ) ;
$ ( '#summarylocalextend' ) . text ( summaryextendorgs ) ;
$ ( '#summaryexternal' ) . text ( remotesummaryorgs ) ;
$ ( '#summaryexternalextend' ) . text ( remotesummaryextendorgs ) ;
$ ( '#summaryservers' ) . text ( summaryservers ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function sharingGroupPopulateOrganisations ( ) {
2019-02-13 08:46:18 +01:00
$ ( 'input[id=SharingGroupOrganisations]' ) . val ( JSON . stringify ( organisations ) ) ;
$ ( '.orgRow' ) . remove ( ) ;
var id = 0 ;
var html = '' ;
organisations . forEach ( function ( org ) {
html = '<tr id="orgRow' + id + '" class="orgRow">' ;
html += '<td class="short">' + org . type + ' </td>' ;
html += '<td>' + $ ( '<div>' ) . text ( org . name ) . html ( ) + ' </td>' ;
html += '<td>' + org . uuid + ' </td>' ;
html += '<td class="short" style="text-align:center;">' ;
if ( org . removable == 1 ) {
html += '<input id="orgExtend' + id + '" type="checkbox" onClick="sharingGroupExtendOrg(' + id + ')" ' ;
if ( org . extend ) html += 'checked' ;
2019-10-13 19:49:59 +02:00
html += '>' ;
2019-02-13 08:46:18 +01:00
} else {
html += '<span class="icon-ok"></span>'
}
html += '</td>' ;
html += '<td class="actions short">' ;
if ( org . removable == 1 ) html += '<span class="icon-trash" onClick="sharingGroupRemoveOrganisation(' + id + ')"></span>' ;
html += ' </td></tr>' ;
$ ( '#organisations_table tr:last' ) . after ( html ) ;
id ++ ;
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function sharingGroupPopulateServers ( ) {
2019-02-13 08:46:18 +01:00
$ ( 'input[id=SharingGroupServers]' ) . val ( JSON . stringify ( servers ) ) ;
$ ( '.serverRow' ) . remove ( ) ;
var id = 0 ;
var html = '' ;
servers . forEach ( function ( server ) {
html = '<tr id="serverRow' + id + '" class="serverRow">' ;
html += '<td>' + server . name + ' </td>' ;
html += '<td>' + server . url + ' </td>' ;
html += '<td>' ;
html += '<input id="serverAddOrgs' + id + '" type="checkbox" onClick="sharingGroupServerAddOrgs(' + id + ')" ' ;
if ( server . all _orgs ) html += 'checked' ;
2019-10-13 19:49:59 +02:00
html += '>' ;
2019-02-13 08:46:18 +01:00
html += '</td>' ;
html += '<td class="actions short">' ;
if ( server . removable == 1 ) html += '<span class="icon-trash" onClick="sharingGroupRemoveServer(' + id + ')"></span>' ;
html += ' </td></tr>' ;
$ ( '#servers_table tr:last' ) . after ( html ) ;
id ++ ;
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function sharingGroupExtendOrg ( id ) {
2019-02-13 08:46:18 +01:00
organisations [ id ] . extend = $ ( '#orgExtend' + id ) . is ( ":checked" ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function sharingGroupServerAddOrgs ( id ) {
2019-02-13 08:46:18 +01:00
servers [ id ] . all _orgs = $ ( '#serverAddOrgs' + id ) . is ( ":checked" ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function sharingGroupPopulateUsers ( ) {
2019-02-13 08:46:18 +01:00
$ ( 'input[id=SharingGroupServers]' ) . val ( JSON . stringify ( organisations ) ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function sharingGroupAdd ( context , type ) {
2019-02-13 08:46:18 +01:00
if ( context == 'organisation' ) {
var jsonids = JSON . stringify ( orgids ) ;
2020-08-16 13:31:31 +02:00
url = baseurl + '/organisations/fetchOrgsForSG/' + jsonids + '/' + type
2019-02-13 08:46:18 +01:00
} else if ( context == 'server' ) {
var jsonids = JSON . stringify ( serverids ) ;
2020-08-16 13:31:31 +02:00
url = baseurl + '/servers/fetchServersForSG/' + jsonids
2019-02-13 08:46:18 +01:00
}
$ ( "#gray_out" ) . fadeIn ( ) ;
simplePopup ( url ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function sharingGroupRemoveOrganisation ( id ) {
2019-02-13 08:46:18 +01:00
organisations . splice ( id , 1 ) ;
orgids . splice ( id , 1 ) ;
sharingGroupPopulateOrganisations ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function sharingGroupRemoveServer ( id ) {
2019-02-13 08:46:18 +01:00
servers . splice ( id , 1 ) ;
serverids . splice ( id , 1 ) ;
sharingGroupPopulateServers ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function submitPicklistValues ( context , local ) {
2019-02-13 08:46:18 +01:00
if ( context == 'org' ) {
var localType = 'local' ;
if ( local == 0 ) localType = 'remote' ;
$ ( "#rightValues option" ) . each ( function ( ) {
if ( orgids . indexOf ( $ ( this ) . val ( ) ) == - 1 ) {
organisations . push ( {
id : $ ( this ) . val ( ) ,
type : localType ,
name : $ ( this ) . text ( ) ,
extend : false ,
uuid : '' ,
removable : 1
} ) ;
}
orgids . push ( $ ( this ) . val ( ) ) ;
sharingGroupPopulateOrganisations ( ) ;
} ) ;
} else if ( context == 'server' ) {
$ ( "#rightValues option" ) . each ( function ( ) {
if ( serverids . indexOf ( $ ( this ) . val ( ) ) == - 1 ) {
servers . push ( {
id : $ ( this ) . val ( ) ,
name : $ ( this ) . text ( ) ,
url : $ ( this ) . attr ( "data-url" ) ,
all _orgs : false ,
removable : 1
} ) ;
}
serverids . push ( $ ( this ) . val ( ) ) ;
sharingGroupPopulateServers ( ) ;
} ) ;
}
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( "#popover_form" ) . fadeOut ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function cancelPicklistValues ( ) {
2019-02-13 08:46:18 +01:00
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function sgSubmitForm ( action ) {
2019-02-13 08:46:18 +01:00
var ajax = {
2022-03-04 17:53:07 +01:00
'organisations' : organisations ,
'servers' : servers ,
'sharingGroup' : {
'uuid' : $ ( '#SharingGroupUuid' ) . val ( ) ,
'name' : $ ( '#SharingGroupName' ) . val ( ) ,
'releasability' : $ ( '#SharingGroupReleasability' ) . val ( ) ,
'description' : $ ( '#SharingGroupDescription' ) . val ( ) ,
'active' : $ ( '#SharingGroupActive' ) . is ( ":checked" ) ,
'roaming' : $ ( '#SharingGroupRoaming' ) . is ( ":checked" ) ,
}
2019-02-13 08:46:18 +01:00
} ;
$ ( '#SharingGroupJson' ) . val ( JSON . stringify ( ajax ) ) ;
var formName = "#SharingGroup" + action + "Form" ;
$ ( formName ) . submit ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-07 00:24:44 +02:00
2017-04-13 16:31:48 +02:00
function serverSubmitForm ( action ) {
2019-02-13 08:46:18 +01:00
var ajax = { } ;
switch ( $ ( '#ServerOrganisationType' ) . val ( ) ) {
case '0' :
ajax = {
'id' : $ ( '#ServerLocal' ) . val ( )
} ;
break ;
case '1' :
ajax = {
'id' : $ ( '#ServerExternal' ) . val ( )
} ;
break ;
case '2' :
ajax = {
'name' : $ ( '#ServerExternalName' ) . val ( ) ,
'uuid' : $ ( '#ServerExternalUuid' ) . val ( )
} ;
break ;
}
$ ( '#ServerJson' ) . val ( JSON . stringify ( ajax ) ) ;
var formName = "#Server" + action + "Form" ;
$ ( formName ) . submit ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-20 22:36:29 +02:00
2017-04-13 16:31:48 +02:00
function serverOrgTypeChange ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".hiddenField" ) . hide ( ) ;
switch ( $ ( '#ServerOrganisationType' ) . val ( ) ) {
case '0' :
$ ( "#ServerLocalContainer" ) . show ( ) ;
break ;
case '1' :
$ ( "#ServerExternalContainer" ) . show ( ) ;
break ;
case '2' :
$ ( "#ServerExternalUuidContainer" ) . show ( ) ;
$ ( "#ServerExternalNameContainer" ) . show ( ) ;
break ;
}
2017-04-13 16:31:48 +02:00
}
2015-04-20 22:36:29 +02:00
2017-04-13 16:31:48 +02:00
function sharingGroupPopulateFromJson ( ) {
2019-02-13 08:46:18 +01:00
var jsonparsed = JSON . parse ( $ ( '#SharingGroupJson' ) . val ( ) ) ;
organisations = jsonparsed . organisations ;
servers = jsonparsed . servers ;
if ( jsonparsed . sharingGroup . active == 1 ) {
$ ( "#SharingGroupActive" ) . prop ( "checked" , true ) ;
}
if ( jsonparsed . sharingGroup . roaming == 1 ) {
$ ( "#SharingGroupRoaming" ) . prop ( "checked" , true ) ;
$ ( '#serverList' ) . show ( ) ;
}
$ ( '#SharingGroupName' ) . attr ( 'value' , jsonparsed . sharingGroup . name ) ;
$ ( '#SharingGroupReleasability' ) . attr ( 'value' , jsonparsed . sharingGroup . releasability ) ;
2022-03-04 17:53:07 +01:00
$ ( '#SharingGroupUuid' ) . attr ( 'value' , jsonparsed . sharingGroup . uuid ) ;
2019-02-13 08:46:18 +01:00
$ ( '#SharingGroupDescription' ) . text ( jsonparsed . sharingGroup . description ) ;
2017-04-13 16:31:48 +02:00
}
2015-04-21 00:31:43 +02:00
2019-11-06 21:20:04 +01:00
function runOnDemandAction ( element , url , target , postFormField ) {
var elementContainer = '#' + target ;
var type = 'GET' ;
var data = '' ;
if ( postFormField !== '' ) {
type = 'POST' ;
data = $ ( '#' + postFormField ) . val ( ) ;
data = { value : data }
}
$ . ajax ( {
url : url ,
type : type ,
data : data ,
2021-02-19 15:38:03 +01:00
beforeSend : function ( ) {
2019-11-06 21:20:04 +01:00
$ ( elementContainer ) . html ( 'Running...' ) ;
} ,
error : function ( response ) {
var result = JSON . parse ( response . responseText ) ;
$ ( elementContainer ) . empty ( ) ;
$ ( elementContainer )
. append (
$ ( '<div>' )
. attr ( 'class' , 'bold red' )
. text ( 'Error ' + response . status + ':' )
)
. append (
$ ( '<div>' )
. attr ( 'class' , 'bold' )
. text ( result . errors )
) ;
} ,
success : function ( response ) {
var result = JSON . parse ( response ) ;
$ ( elementContainer ) . empty ( ) ;
for ( var key in result ) {
$ ( elementContainer ) . append (
$ ( '<div>' )
. append (
$ ( '<span>' )
. attr ( 'class' , 'bold' )
. text ( key + ': ' )
) . append (
$ ( '<span>' )
. attr ( 'class' , 'bold blue' )
. text ( result [ key ] )
)
) ;
}
}
} )
}
2019-11-13 19:09:37 +01:00
function getRemoteSyncUser ( id ) {
var resultContainer = $ ( "#sync_user_test_" + id ) ;
$ . ajax ( {
2020-08-17 15:57:21 +02:00
url : baseurl + '/servers/getRemoteUser/' + id ,
2021-08-04 10:28:02 +02:00
type : 'GET' ,
2020-12-03 21:02:47 +01:00
beforeSend : function ( ) {
2021-08-04 10:28:02 +02:00
resultContainer . text ( 'Running test...' ) ;
2019-11-13 19:09:37 +01:00
} ,
2020-12-03 21:02:47 +01:00
error : function ( ) {
2021-08-04 10:28:02 +02:00
resultContainer . html ( '<span class="red bold">Internal error</span>' ) ;
2019-11-13 19:09:37 +01:00
} ,
success : function ( response ) {
2020-12-03 21:02:47 +01:00
resultContainer . empty ( ) ;
2021-08-03 09:38:36 +02:00
if ( typeof response !== 'object' ) {
2021-08-04 10:28:02 +02:00
resultContainer . html ( '<span class="red bold">Internal error</span>' ) ;
} else if ( "error" in response ) {
2019-11-13 19:09:37 +01:00
resultContainer . append (
$ ( '<span>' )
2021-08-04 10:28:02 +02:00
. attr ( 'class' , 'red bold' )
. text ( 'Error' )
2019-11-13 19:09:37 +01:00
) . append (
$ ( '<span>' )
2021-08-05 09:56:10 +02:00
. text ( ': #' + response . error )
2019-11-13 19:09:37 +01:00
) ;
} else {
Object . keys ( response ) . forEach ( function ( key ) {
var value = response [ key ] ;
resultContainer . append (
$ ( '<span>' )
. attr ( 'class' , 'blue bold' )
. text ( key )
) . append (
$ ( '<span>' )
. text ( ': ' + value )
) . append (
$ ( '<br>' )
) ;
} ) ;
}
}
} ) ;
}
2017-04-13 16:31:48 +02:00
function testConnection ( id ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2020-08-16 13:31:31 +02:00
url : baseurl + '/servers/testConnection/' + id ,
2020-10-16 17:34:55 +02:00
type : 'GET' ,
beforeSend : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( "#connection_test_" + id ) . html ( 'Running test...' ) ;
} ,
error : function ( ) {
2020-10-16 17:34:55 +02:00
$ ( "#connection_test_" + id ) . html ( '<span class="red bold">Internal error</span>' ) ;
} ,
success : function ( result ) {
function line ( name , value , valid ) {
var $value = $ ( '<span></span>' ) . text ( value ) ;
if ( valid === true ) {
$value . addClass ( 'green' ) ;
} else if ( valid === false ) {
$value . addClass ( 'red' ) ;
} else if ( valid ) {
$value . addClass ( valid ) ;
}
return $ ( '<div></div>' ) . text ( name + ': ' ) . append ( $value ) . html ( ) + '<br>' ;
}
var html = '' ;
if ( result . client _certificate ) {
var cert = result . client _certificate ;
html += '<span class="bold">Client certificate:</span><br>' ;
if ( cert . error ) {
html += '<span class="red bold">Error: ' + cert . error + '</span><br>' ;
} else {
html += line ( "Subject" , cert . subject ) ;
html += line ( "Issuer" , cert . issuer ) ;
html += line ( "Serial number" , cert . serial _number ) ;
html += line ( "Valid from" , cert . valid _from , cert . valid _from _ok ) ;
html += line ( "Valid to" , cert . valid _to , cert . valid _to _ok ) ;
html += line ( "Public key" , cert . public _key _type + ' (' + cert . public _key _size + ' bits)' , cert . public _key _size _ok ) ;
}
html += "<br>" ;
}
2019-02-13 08:46:18 +01:00
switch ( result . status ) {
case 1 :
2020-10-16 17:34:55 +02:00
var status _message = "OK" ;
var compatibility = "Compatible" ;
var compatibility _colour = "green" ;
var colours = { 'local' : 'class="green"' , 'remote' : 'class="green"' , 'status' : 'class="green"' } ;
var issue _colour = "red" ;
2019-02-13 08:46:18 +01:00
if ( result . mismatch == "hotfix" ) issue _colour = "orange" ;
if ( result . newer == "local" ) {
colours . remote = 'class="' + issue _colour + '"' ;
if ( result . mismatch == "minor" ) {
compatibility = "Pull only" ;
compatibility _colour = "orange" ;
} else if ( result . mismatch == "major" ) {
compatibility = "Incompatible" ;
compatibility _colour = "red" ;
}
} else if ( result . newer == "remote" ) {
colours . local = 'class="' + issue _colour + '"' ;
if ( result . mismatch != "hotfix" ) {
compatibility = "Incompatible" ;
compatibility _colour = "red" ;
}
2019-07-12 16:03:08 +02:00
} else if ( result . mismatch == "proposal" ) {
compatibility _colour = "orange" ;
compatibility = "Proposal pull disabled (remote version < v2.4.111)" ;
2019-02-13 08:46:18 +01:00
}
2019-07-12 16:03:08 +02:00
if ( result . mismatch != false && result . mismatch != "proposal" ) {
2019-02-13 08:46:18 +01:00
if ( result . newer == "remote" ) status _message = "Local instance outdated, update!" ;
else status _message = "Remote outdated, notify admin!"
colours . status = 'class="' + issue _colour + '"' ;
}
2020-10-16 17:34:55 +02:00
var post _result ;
2019-02-13 08:46:18 +01:00
if ( result . post != false ) {
var post _colour = "red" ;
if ( result . post == 1 ) {
post _colour = "green" ;
post _result = "Received sent package" ;
} else if ( result . post == 8 ) {
post _result = "Could not POST message" ;
} else if ( result . post == 9 ) {
post _result = "Invalid body" ;
} else if ( result . post == 10 ) {
post _result = "Invalid headers" ;
} else {
post _colour = "orange" ;
post _result = "Remote too old for this test" ;
}
}
2020-10-16 17:34:55 +02:00
html += line ( 'Local version' , result . local _version , colours . local ) ;
html += line ( 'Remote version' , result . version , colours . remote ) ;
html += line ( 'Status' , status _message , colours . status ) ;
html += line ( 'Compatibility' , compatibility , compatibility _colour ) ;
html += line ( 'POST test' , post _result , post _colour ) ;
2019-02-13 08:46:18 +01:00
break ;
case 2 :
2020-10-16 17:34:55 +02:00
html += '<span class="red bold" title="There seems to be a connection issue. Make sure that the entered URL is correct and that the certificates are in order.">Server unreachable</span>' ;
2019-02-13 08:46:18 +01:00
break ;
case 3 :
2020-10-16 17:34:55 +02:00
html += '<span class="red bold" title="The server returned an unexpected result. Make sure that the provided URL (or certificate if it applies) are correct.">Unexpected error</span>' ;
2019-02-13 08:46:18 +01:00
break ;
case 4 :
2020-10-16 17:34:55 +02:00
html += '<span class="red bold" title="Authentication failed due to incorrect authentication key or insufficient privileges on the remote instance.">Authentication failed</span>' ;
2019-02-13 08:46:18 +01:00
break ;
case 5 :
2020-10-16 17:34:55 +02:00
html += '<span class="red bold" title="Authentication failed because the sync user is expected to change passwords. Log into the remote MISP to rectify this.">Password change required</span>' ;
2019-02-13 08:46:18 +01:00
break ;
case 6 :
2020-10-16 17:34:55 +02:00
html += '<span class="red bold" title="Authentication failed because the sync user on the remote has not accepted the terms of use. Log into the remote MISP to rectify this.">Terms not accepted</span>' ;
2019-02-13 08:46:18 +01:00
break ;
case 7 :
2021-02-11 17:46:32 +01:00
html += '<span class="orange bold" title="The user account on the remote instance is not a sync user.">Remote user not a sync user, only pulling events is available.</span>' ;
2019-02-13 08:46:18 +01:00
break ;
2019-11-26 19:40:49 +01:00
case 8 :
2021-02-11 17:46:32 +01:00
html += '<span class="orange bold" title="The user account on the remote instance is only a sightings user.">Remote user not a sync user, only pulling events is available. Pushing availale for sightings only</span>' ;
2019-11-26 19:40:49 +01:00
break ;
2019-02-13 08:46:18 +01:00
}
2020-10-16 17:34:55 +02:00
$ ( "#connection_test_" + id ) . html ( html ) ;
2019-02-13 08:46:18 +01:00
}
} )
2017-04-13 16:31:48 +02:00
}
2015-06-10 18:07:48 +02:00
2019-06-25 16:57:44 +02:00
function getTextColour ( hex ) {
hex = hex . slice ( 1 ) ;
var r = parseInt ( hex . substring ( 0 , 2 ) , 16 ) ;
var g = parseInt ( hex . substring ( 2 , 4 ) , 16 ) ;
var b = parseInt ( hex . substring ( 4 , 6 ) , 16 ) ;
var avg = ( ( 2 * r ) + b + ( 3 * g ) ) / 6 ;
if ( avg < 128 ) {
return 'white' ;
} else {
return 'black' ;
}
}
2019-09-23 20:56:52 +02:00
function gpgSelect ( fingerprint ) {
2019-02-13 08:46:18 +01:00
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
type : "get" ,
2021-02-19 15:38:03 +01:00
url : "/users/fetchGpgKey/" + fingerprint ,
2019-02-13 08:46:18 +01:00
success : function ( data ) {
2019-09-23 20:56:52 +02:00
$ ( "#UserGpgkey" ) . val ( data ) ;
2019-02-13 08:46:18 +01:00
showMessage ( 'success' , "Key found!" ) ;
} ,
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-06-23 10:56:19 +02:00
2022-07-29 17:45:01 +02:00
function lookupPGPKey ( ) {
var email = $ ( '#UserEmail' ) . val ( ) ;
2020-08-16 13:31:31 +02:00
simplePopup ( baseurl + "/users/searchGpgKey/" + email ) ;
2017-04-13 16:31:48 +02:00
}
2015-06-29 08:56:45 +02:00
2017-04-13 16:31:48 +02:00
function zeroMQServerAction ( action ) {
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
type : "get" ,
2021-02-19 15:38:03 +01:00
url : "/servers/" + action + "ZeroMQServer/" ,
2019-02-13 08:46:18 +01:00
success : function ( data ) {
if ( action !== 'status' ) {
window . location . reload ( ) ;
} else {
2022-04-21 17:39:07 +02:00
openConfirmation ( data ) ;
2019-02-13 08:46:18 +01:00
}
}
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-07-24 18:19:34 +02:00
2017-04-13 16:31:48 +02:00
function convertServerFilterRules ( rules ) {
2019-02-13 08:46:18 +01:00
validOptions . forEach ( function ( type ) {
container = "#" + modelContext + type . ucfirst ( ) + "Rules" ;
2020-01-23 09:42:16 +01:00
if ( $ ( container ) . val ( ) != '' && $ ( container ) . val ( ) != '[]' ) {
rules [ type ] = JSON . parse ( $ ( container ) . val ( ) ) ;
} else {
if ( type === 'pull' ) {
2021-12-09 12:21:34 +01:00
rules [ type ] = { "tags" : { "OR" : [ ] , "NOT" : [ ] } , "orgs" : { "OR" : [ ] , "NOT" : [ ] } , "type_attributes" : { "NOT" : [ ] } , "type_objects" : { "NOT" : [ ] } , "url_params" : "" }
2020-01-23 09:42:16 +01:00
} else {
rules [ type ] = { "tags" : { "OR" : [ ] , "NOT" : [ ] } , "orgs" : { "OR" : [ ] , "NOT" : [ ] } }
}
} ;
2019-02-13 08:46:18 +01:00
} ) ;
serverRuleUpdate ( ) ;
return rules ;
2017-04-13 16:31:48 +02:00
}
2015-07-27 16:30:52 +02:00
2017-04-13 16:31:48 +02:00
function serverRuleUpdate ( ) {
2019-02-13 08:46:18 +01:00
var statusOptions = [ "OR" , "NOT" ] ;
validOptions . forEach ( function ( type ) {
validFields . forEach ( function ( field ) {
2021-12-15 16:10:42 +01:00
var indexedList = { } ;
2021-12-17 15:36:04 +01:00
if ( type === 'push' || field == 'type_objects' ) {
2021-12-09 12:21:34 +01:00
if ( window [ field ] !== undefined ) {
window [ field ] . forEach ( function ( item ) {
indexedList [ item . id ] = item . name ;
} ) ;
}
2019-02-13 08:46:18 +01:00
}
statusOptions . forEach ( function ( status ) {
2021-12-09 12:21:34 +01:00
if ( rules [ type ] [ field ] !== undefined && rules [ type ] [ field ] [ status ] !== undefined ) {
if ( rules [ type ] [ field ] [ status ] . length > 0 ) {
$ ( '#' + type + '_' + field + '_' + status ) . show ( ) ;
var t = '' ;
rules [ type ] [ field ] [ status ] . forEach ( function ( item ) {
if ( t . length > 0 ) t += ', ' ;
2021-12-17 15:36:04 +01:00
if ( type === 'pull' ) {
if ( indexedList [ item ] !== undefined ) {
t += indexedList [ item ] ;
} else {
t += item ;
}
} else {
2021-12-09 12:21:34 +01:00
t += indexedList [ item ] !== undefined ? indexedList [ item ] : item ;
}
} ) ;
$ ( '#' + type + '_' + field + '_' + status + '_text' ) . text ( t ) ;
} else {
$ ( '#' + type + '_' + field + '_' + status ) . hide ( ) ;
}
2019-02-13 08:46:18 +01:00
}
} ) ;
} ) ;
2020-01-23 09:42:16 +01:00
if ( type === 'pull' ) {
if ( rules [ type ] [ 'url_params' ] ) {
$ ( "#pull_url_params" ) . show ( ) ;
$ ( "#pull_url_params_text" ) . text ( rules [ type ] [ 'url_params' ] ) ;
} else {
$ ( "#pull_url_params" ) . hide ( ) ;
}
}
2019-02-13 08:46:18 +01:00
} ) ;
serverRuleGenerateJSON ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-07-27 16:30:52 +02:00
2017-04-13 16:31:48 +02:00
function serverRuleGenerateJSON ( ) {
2019-02-13 08:46:18 +01:00
validOptions . forEach ( function ( type ) {
if ( $ ( '#Server' + type . ucfirst ( ) + "Rules" ) . length ) {
$ ( '#Server' + type . ucfirst ( ) + "Rules" ) . val ( JSON . stringify ( rules [ type ] ) ) ;
} else {
$ ( '#Feed' + type . ucfirst ( ) + "Rules" ) . val ( JSON . stringify ( rules [ type ] ) ) ;
}
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-07-27 16:30:52 +02:00
2021-04-22 16:23:59 +02:00
function serverRulesUpdateState ( context ) {
var $rootContainer = $ ( '.server-rule-container-' + context )
2019-02-13 08:46:18 +01:00
validFields . forEach ( function ( field ) {
2021-04-22 16:23:59 +02:00
var $fieldContainer = $rootContainer . find ( '.scope-' + field )
rules [ context ] [ field ] = $fieldContainer . data ( 'rules' )
} )
2020-01-23 09:42:16 +01:00
if ( context === 'pull' ) {
2021-04-22 16:23:59 +02:00
rules [ context ] [ "url_params" ] = $rootContainer . find ( 'textarea#urlParams' ) . val ( ) ;
2020-01-23 09:42:16 +01:00
}
2019-02-13 08:46:18 +01:00
serverRuleUpdate ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-07-28 14:00:38 +02:00
2017-04-13 16:31:48 +02:00
function syncUserSelected ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '#UserRoleId :selected' ) . val ( ) in syncRoles ) {
$ ( '#syncServers' ) . show ( ) ;
} else {
$ ( '#syncServers' ) . hide ( ) ;
}
2017-04-13 16:31:48 +02:00
}
2016-01-04 10:23:07 +01:00
2021-03-20 13:35:58 +01:00
function eventIndexColumnsToggle ( columnName ) {
xhr ( {
url : "/userSettings/eventIndexColumnToggle/" + columnName ,
method : "post" ,
success : function ( ) {
window . location . reload ( ) ; // update page
}
} ) ;
}
2020-09-27 10:59:26 +02:00
// Find object or attribute by UUID on current page
function findObjectByUuid ( uuid ) {
var $tr = null ;
$ ( '#attributeList tr' ) . each ( function ( ) {
var trId = $ ( this ) . attr ( 'id' ) ;
2020-10-03 18:38:47 +02:00
if ( trId && ( trId . startsWith ( "Object" ) || trId . startsWith ( "Attribute" ) || trId . startsWith ( 'proposal' ) ) ) {
2020-09-27 10:59:26 +02:00
var objectUuid = $ ( '.uuid' , this ) . text ( ) . trim ( ) ;
if ( objectUuid === uuid ) {
$tr = $ ( this ) ;
return false ;
}
2019-02-13 08:46:18 +01:00
}
} ) ;
2020-09-27 10:59:26 +02:00
return $tr ;
}
function focusObjectByUuid ( uuid ) {
var $tr = findObjectByUuid ( uuid ) ;
if ( ! $tr ) {
return false ;
}
$ ( [ document . documentElement , document . body ] ) . animate ( {
scrollTop : $tr . offset ( ) . top - 45 , // 42px is #topBar size, so make little bit more space
} , 1000 , null , function ( ) {
$tr . fadeTo ( 100 , 0.3 , function ( ) { // blink active row
$ ( this ) . fadeTo ( 500 , 1.0 ) ;
} ) ;
$tr . focus ( ) ;
} ) ;
return true ;
2017-04-13 16:31:48 +02:00
}
2016-05-10 10:31:56 +02:00
2017-08-09 17:53:25 +02:00
function pivotObjectReferences ( url , uuid ) {
2020-09-27 10:59:26 +02:00
if ( focusObjectByUuid ( uuid ) ) {
return ; // object is on the same page, we don't need to reload page
2020-09-26 15:05:02 +02:00
}
2022-04-29 19:55:12 +02:00
fetchAttributes ( currentUri , { "focus" : uuid } ) ;
2017-08-09 17:53:25 +02:00
}
2022-09-23 12:04:55 +02:00
function scrollToElementIfNotVisible ( $el ) {
var isInViewport = function ( $el ) {
var elementTop = $el . offset ( ) . top ;
var elementBottom = elementTop + $el . outerHeight ( ) ;
var viewportTop = $ ( window ) . scrollTop ( ) ;
var viewportBottom = viewportTop + $ ( window ) . height ( ) ;
return elementBottom > viewportTop && elementTop < viewportBottom ;
} ;
if ( $el . length && ! isInViewport ( $el ) ) {
$ ( [ document . documentElement , document . body ] ) . animate ( {
scrollTop : $el . offset ( ) . top - 45 , // 42px is #topBar size, so make little bit more space
} ) ;
}
}
2022-04-30 18:27:14 +02:00
// Attribute filtering
function filterAttributes ( filter ) {
var data ;
if ( filter === 'value' ) {
filter = $ ( '#quickFilterField' ) . val ( ) . trim ( ) ;
data = { "searchFor" : filter }
} else if ( filter === 'all' ) {
$ ( '#quickFilterField' ) . val ( '' ) ; // clear input value
data = { }
} else {
data = { "attributeFilter" : filter }
filter = $ ( '#quickFilterField' ) . val ( ) . trim ( ) ;
if ( filter . length ) {
data [ "searchFor" ] = filter ;
}
}
2023-04-06 15:24:15 +02:00
currentUri = resetPaginationParameters ( currentUri )
2022-04-30 18:27:14 +02:00
fetchAttributes ( currentUri , data ) ;
}
2022-04-29 19:55:12 +02:00
function toggleBoolFilter ( param ) {
2019-04-18 10:20:08 +02:00
if ( querybuilderTool === undefined ) {
triggerEventFilteringTool ( true ) ; // allows to fetch rules
}
var rules = querybuilderTool . getRules ( { skip _empty : true , allow _invalid : true } ) ;
var res = cleanRules ( rules ) ;
2022-04-29 19:55:12 +02:00
2019-08-12 16:34:26 +02:00
if ( res [ param ] !== undefined ) {
2022-04-30 18:15:25 +02:00
res [ param ] = res [ param ] == 0 ? 1 : 0 ;
2019-02-13 08:46:18 +01:00
} else {
2022-04-30 18:15:25 +02:00
res [ param ] = 1 ;
2019-02-13 08:46:18 +01:00
}
2022-04-29 19:55:12 +02:00
fetchAttributes ( currentUri , res ) ;
2022-04-29 18:41:25 +02:00
}
2023-04-06 15:24:15 +02:00
function resetPaginationParameters ( currentUri ) {
var newUri = [ ]
currentUri . split ( '/' ) . forEach ( function ( el ) {
if (
el . startsWith ( 'sort:' ) ||
el . startsWith ( 'direction:' ) ||
el . startsWith ( 'page:' )
) {
return
}
newUri . push ( el )
} )
return newUri . join ( '/' )
}
2022-04-30 18:27:14 +02:00
function recursiveInject ( result , rules ) {
if ( rules . rules === undefined ) { // add to result
var field = rules . field ;
var value = rules . value ;
if ( result . hasOwnProperty ( field ) ) {
if ( Array . isArray ( result [ field ] ) ) {
result [ field ] . push ( value ) ;
} else {
result [ field ] = [ result [ field ] , value ] ;
}
} else {
result [ field ] = value ;
}
}
else if ( Array . isArray ( rules . rules ) ) {
rules . rules . forEach ( function ( subrules ) {
recursiveInject ( result , subrules ) ;
} ) ;
}
}
function cleanRules ( rules ) {
var res = { } ;
recursiveInject ( res , rules ) ;
// clean up invalid and unset
Object . keys ( res ) . forEach ( function ( k ) {
var v = res [ k ] ;
if ( v === undefined || v === '' ) {
delete res [ k ] ;
}
} ) ;
return res ;
}
function performQuery ( rules ) {
var res = cleanRules ( rules ) ;
fetchAttributes ( currentUri , res ) ;
}
2022-04-29 18:41:25 +02:00
function setAttributeFilter ( field , value ) {
if ( querybuilderTool === undefined ) {
triggerEventFilteringTool ( true ) ; // allows to fetch rules
}
var rules = querybuilderTool . getRules ( { skip _empty : true , allow _invalid : true } ) ;
var found = false
$ . each ( rules . rules , function ( index , rule ) {
if ( rule . field === field ) {
rule . value = value ;
found = true ;
}
} ) ;
if ( ! found ) {
rules . rules . push ( { "field" : field , "value" : value } )
}
performQuery ( rules ) ;
2022-04-29 18:04:41 +02:00
}
function fetchAttributes ( url , data ) {
var options = {
2020-08-25 18:30:03 +02:00
type : "get" ,
url : url ,
2021-09-02 10:19:06 +02:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#attributes_div" ) . html ( data ) ;
} ,
2021-09-02 10:19:06 +02:00
error : function ( ) {
2019-02-13 08:46:18 +01:00
showMessage ( 'fail' , 'Something went wrong - could not fetch attributes.' ) ;
}
2022-04-29 18:04:41 +02:00
} ;
if ( data !== undefined ) {
2022-04-29 19:55:12 +02:00
// Cleanup URL from rules that has default value or are part of POST request
for ( var param in data ) {
if ( defaultFilteringRules [ param ] == data [ param ] ) {
delete data [ param ] ;
}
2022-05-01 14:13:27 +02:00
}
2022-04-29 19:55:12 +02:00
2022-05-01 14:13:27 +02:00
// delete url rules thats are part of default rules
Object . keys ( defaultFilteringRules ) . forEach ( function ( param ) {
if ( url . indexOf ( param ) > - 1 ) {
2022-04-29 19:55:12 +02:00
var replace = '\/' + param + ".+/?" ;
var re = new RegExp ( replace , "i" ) ;
url = url . replace ( re , '' ) ;
}
2022-05-01 14:13:27 +02:00
} ) ;
2022-04-29 19:55:12 +02:00
if ( ! $ . isEmptyObject ( data ) ) {
options [ "type" ] = "post" ;
options [ "data" ] = data ;
}
options [ "url" ] = url ;
2022-04-29 18:04:41 +02:00
}
2022-04-29 19:55:12 +02:00
2022-04-29 18:04:41 +02:00
xhr ( options ) ;
2017-04-13 16:31:48 +02:00
}
2016-01-27 23:59:34 +01:00
2017-04-13 16:31:48 +02:00
function mergeOrganisationUpdate ( ) {
2019-02-13 08:46:18 +01:00
var orgTypeOptions = [ 'local' , 'external' ] ;
var orgTypeSelects = [ 'OrganisationOrgsLocal' , 'OrganisationOrgsExternal' ] ;
var orgTypeId = $ ( '#OrganisationTargetType' ) . val ( ) ;
var orgType = orgTypeSelects [ orgTypeId ] ;
var orgID = $ ( '#' + orgTypeSelects [ orgTypeId ] ) . val ( ) ;
console . log ( orgTypeSelects [ orgTypeId ] ) ;
console . log ( orgID ) ;
org = orgArray [ orgTypeOptions [ orgTypeId ] ] [ orgID ] [ 'Organisation' ] ;
console . log ( org ) ;
$ ( '#org_id' ) . text ( org [ 'id' ] ) ;
$ ( '#org_name' ) . text ( org [ 'name' ] ) ;
$ ( '#org_uuid' ) . text ( org [ 'uuid' ] ) ;
$ ( '#org_local' ) . text ( orgTypeOptions [ $ ( '#OrganisationTargetType' ) . val ( ) ] ) ;
2017-04-13 16:31:48 +02:00
}
2016-01-27 23:59:34 +01:00
2017-04-13 16:31:48 +02:00
function mergeOrganisationTypeToggle ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '#OrganisationTargetType' ) . val ( ) == 0 ) {
$ ( '#orgsLocal' ) . show ( ) ;
$ ( '#orgsExternal' ) . hide ( ) ;
} else {
$ ( '#orgsLocal' ) . hide ( ) ;
$ ( '#orgsExternal' ) . show ( ) ;
}
2017-04-13 16:31:48 +02:00
}
2016-02-03 09:59:03 +01:00
2017-04-13 16:31:48 +02:00
function checkUserPasswordEnabled ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '#UserEnablePassword' ) . is ( ':checked' ) ) {
$ ( '#PasswordDiv' ) . show ( ) ;
} else {
$ ( '#PasswordDiv' ) . hide ( ) ;
}
2017-04-13 16:31:48 +02:00
}
2016-03-15 23:04:20 +01:00
2017-04-13 16:31:48 +02:00
function checkUserExternalAuth ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '#UserExternalAuthRequired' ) . is ( ':checked' ) ) {
$ ( '#externalAuthDiv' ) . show ( ) ;
$ ( '#passwordDivDiv' ) . hide ( ) ;
} else {
$ ( '#externalAuthDiv' ) . hide ( ) ;
$ ( '#passwordDivDiv' ) . show ( ) ;
}
2017-04-13 16:31:48 +02:00
}
2016-03-27 12:15:51 +02:00
2017-04-13 16:31:48 +02:00
function toggleSettingSubGroup ( group ) {
2019-02-13 08:46:18 +01:00
$ ( '.subGroup_' + group ) . toggle ( ) ;
2017-04-13 16:31:48 +02:00
}
2016-03-21 12:08:20 +01:00
2020-10-07 20:56:44 +02:00
// Hover enrichment
var hoverEnrichmentPopoverTimer ;
function attributeHoverTitle ( id , type ) {
return ' < span > Lookup results : < / s p a n > \
< i class = "fa fa-search-plus useCursorPointer eventViewAttributePopup" \
style = "float: right;" \
data - object - id = "' + id + '" \
data - object - type = "' + type + '" > \
< / i > ' ;
2017-04-13 16:31:48 +02:00
}
2016-07-21 11:35:29 +02:00
2020-10-07 20:56:44 +02:00
function attributeHoverPlacement ( element ) {
var offset = element . offset ( ) ,
topOffset = offset . top - $ ( window ) . scrollTop ( ) ,
left = offset . left - $ ( window ) . scrollLeft ( ) ,
viewportHeight = window . innerHeight ,
viewportWidth = window . innerWidth ,
horiz = 0.5 * viewportWidth - left ,
horizPlacement = horiz > 0 ? 'right' : 'left' ,
popoverMaxHeight = . 75 * viewportHeight ;
// default to top placement
var placement = topOffset - popoverMaxHeight > 0 ? 'top' : horizPlacement ;
// more space on bottom
if ( topOffset < . 5 * viewportHeight ) {
// will popup fit on bottom
placement = popoverMaxHeight < topOffset ? 'bottom' : horizPlacement ;
}
return placement ;
}
function showHoverEnrichmentPopover ( type , id ) {
var html = ajaxResults [ "hover" ] [ type + "_" + id ] ;
var element = $ ( '#' + type + '_' + id + '_container' ) ;
element . popover ( {
title : attributeHoverTitle ( id , type ) ,
content : html ,
placement : attributeHoverPlacement ( element ) ,
html : true ,
trigger : 'manual' ,
container : 'body'
} ) . popover ( 'show' ) ;
if ( currentPopover !== undefined && currentPopover !== '' ) {
$ ( '#' + currentPopover ) . popover ( 'destroy' ) ;
}
currentPopover = type + '_' + id + '_container'
2017-04-13 16:31:48 +02:00
}
2016-07-21 11:35:29 +02:00
2020-10-07 20:56:44 +02:00
$ ( document . body ) . on ( 'mouseenter' , '.eventViewAttributeHover' , function ( ) {
if ( currentPopover !== undefined && currentPopover !== '' ) {
$ ( '#' + currentPopover ) . popover ( 'destroy' ) ;
currentPopover = '' ;
}
var type = $ ( this ) . attr ( 'data-object-type' ) ;
var id = $ ( this ) . attr ( 'data-object-id' ) ;
2018-09-05 11:28:18 +02:00
2020-10-07 20:56:44 +02:00
if ( type + "_" + id in ajaxResults [ "hover" ] ) {
showHoverEnrichmentPopover ( type , id ) ;
} else {
hoverEnrichmentPopoverTimer = setTimeout ( function ( ) {
$ . ajax ( {
success : function ( html ) {
ajaxResults [ "hover" ] [ type + "_" + id ] = html ;
showHoverEnrichmentPopover ( type , id ) ;
} ,
cache : false ,
url : baseurl + "/attributes/hoverEnrichment/" + id ,
} ) ;
} ,
500
) ;
}
} ) . on ( 'mouseout' , '.eventViewAttributeHover' , function ( ) {
clearTimeout ( hoverEnrichmentPopoverTimer ) ;
2018-09-05 11:28:18 +02:00
} ) ;
2020-10-06 19:43:23 +02:00
function showEnrichmentPopover ( type , id ) {
var $popoverBox = $ ( '#popover_box' ) ;
$popoverBox . empty ( ) ;
var enrichment _popover = ajaxResults [ "persistent" ] [ type + "_" + id ] ;
enrichment _popover += '<div class="close-icon useCursorPointer popup-close-icon" onClick="closeScreenshot();"></div>' ;
2020-10-07 18:39:41 +02:00
$popoverBox . html ( enrichment _popover ) ;
2020-10-06 19:43:23 +02:00
$popoverBox . show ( ) ;
$ ( "#gray_out" ) . fadeIn ( ) ;
2020-10-07 18:39:41 +02:00
let maxWidth = ( $ ( window ) . width ( ) * 0.9 | 0 ) ;
if ( maxWidth > 1400 ) { // limit popover width to 1400 px
maxWidth = 1400 ;
}
2020-10-06 19:43:23 +02:00
$popoverBox . css ( {
'padding' : '5px' ,
2020-10-07 18:39:41 +02:00
'max-width' : maxWidth + "px" ,
2020-10-07 20:24:45 +02:00
'min-width' : '700px' ,
2020-10-07 18:57:10 +02:00
'height' : ( $ ( window ) . height ( ) - 300 | 0 ) + "px" ,
2020-10-07 18:39:41 +02:00
'background-color' : 'white' ,
2020-10-06 19:43:23 +02:00
} ) ;
var left = ( $ ( window ) . width ( ) / 2 ) - ( $popoverBox . width ( ) / 2 ) ;
$popoverBox . css ( { 'left' : left + 'px' } ) ;
if ( currentPopover !== undefined && currentPopover !== '' ) {
$ ( '#' + currentPopover ) . popover ( 'destroy' ) ;
}
}
2018-09-05 11:28:18 +02:00
// add the same as below for click popup
2020-10-07 18:39:41 +02:00
$ ( document ) . on ( "click" , ".eventViewAttributePopup" , function ( ) {
2021-02-19 15:38:03 +01:00
clearTimeout ( hoverEnrichmentPopoverTimer ) ; // stop potential popover loading
2020-10-07 20:56:44 +02:00
2020-10-06 19:43:23 +02:00
var type = $ ( this ) . attr ( 'data-object-type' ) ;
var id = $ ( this ) . attr ( 'data-object-id' ) ;
2020-10-07 19:09:17 +02:00
if ( ! ( type + "_" + id in ajaxResults [ "persistent" ] ) ) { // not in cache
2021-02-19 15:38:03 +01:00
xhr ( {
2020-10-06 19:43:23 +02:00
success : function ( html ) {
2020-10-07 19:09:17 +02:00
ajaxResults [ "persistent" ] [ type + "_" + id ] = html ; // save to cache
2020-10-06 19:43:23 +02:00
showEnrichmentPopover ( type , id ) ;
2019-02-13 08:46:18 +01:00
} ,
2021-02-19 15:38:03 +01:00
url : "/attributes/hoverEnrichment/" + id + "/1" ,
2019-02-13 08:46:18 +01:00
} ) ;
2020-10-06 19:43:23 +02:00
} else {
showEnrichmentPopover ( type , id ) ;
2020-09-02 17:12:51 +02:00
}
2018-09-05 11:28:18 +02:00
} ) ;
2022-03-20 15:18:26 +01:00
$ ( document . body ) . on ( 'click' , function ( e ) {
2019-02-13 19:19:57 +01:00
$ ( '[data-toggle=popover]' ) . each ( function ( ) {
// hide any open popovers when the anywhere else in the body is clicked
2020-09-03 08:16:56 +02:00
if ( typeof currentPopover !== 'undefined' && currentPopover !== '' ) {
2019-08-23 11:56:50 +02:00
if ( ! $ ( this ) . is ( e . target ) && $ ( this ) . has ( e . target ) . length === 0 && $ ( '.popover' ) . has ( e . target ) . length === 0 ) {
$ ( '#' + currentPopover ) . popover ( 'destroy' ) ;
}
2019-02-13 19:19:57 +01:00
}
} ) ;
} ) ;
2017-04-13 16:31:48 +02:00
function serverOwnerOrganisationChange ( host _org _id ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '#ServerOrganisationType' ) . val ( ) == "0" && $ ( '#ServerLocal' ) . val ( ) == host _org _id ) {
$ ( '#InternalDiv' ) . show ( ) ;
} else {
$ ( '#ServerInternal' ) . prop ( "checked" , false ) ;
$ ( '#InternalDiv' ) . hide ( ) ;
}
2017-04-13 16:31:48 +02:00
}
2016-08-29 14:49:14 +02:00
2017-04-13 16:31:48 +02:00
function requestAPIAccess ( ) {
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
type : "get" ,
2021-02-19 15:38:03 +01:00
url : "/users/request_API/" ,
2019-02-13 08:46:18 +01:00
success : function ( data ) {
handleGenericAjaxResponse ( data ) ;
} ,
error : function ( ) {
showMessage ( 'fail' , 'Something went wrong - could not request API access.' ) ;
}
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-09-02 15:35:11 +02:00
2019-11-11 23:35:53 +01:00
function checkSharingGroup ( context ) {
2020-12-11 23:26:22 +01:00
var $sharingGroupSelect = $ ( '#' + context + 'SharingGroupId' ) ;
2019-11-11 23:35:53 +01:00
if ( $ ( '#' + context + 'Distribution' ) . val ( ) == 4 ) {
2020-12-11 23:26:22 +01:00
$sharingGroupSelect . show ( ) ;
$sharingGroupSelect . closest ( "div" ) . show ( ) ;
// For sharing group select with more than 10 items, use chosen
if ( $sharingGroupSelect . find ( 'option' ) . length > 10 ) {
$sharingGroupSelect . chosen ( ) ;
}
2019-11-11 23:35:53 +01:00
} else {
2020-12-11 23:26:22 +01:00
$sharingGroupSelect . hide ( ) ;
$sharingGroupSelect . closest ( "div" ) . hide ( ) ;
2019-11-11 23:35:53 +01:00
}
}
2017-04-13 16:31:48 +02:00
function formCategoryChanged ( id ) {
2019-02-13 08:46:18 +01:00
// fill in the types
2020-07-23 17:37:11 +02:00
var $type = $ ( '#' + id + 'Type' ) ;
2020-08-17 13:32:00 +02:00
var alreadySelected = $type . val ( ) ;
2020-07-23 17:37:11 +02:00
var options = $type . prop ( 'options' ) ;
$ ( 'option' , $type ) . remove ( ) ;
2020-10-14 16:15:54 +02:00
var selectedCategory = $ ( '#' + id + 'Category' ) . val ( ) ;
var optionsToPush ;
if ( selectedCategory === "" ) { // if no category is selected, insert all attribute types
optionsToPush = { } ;
for ( var category in category _type _mapping ) {
2021-09-14 13:20:05 +02:00
for ( var index in category _type _mapping [ category ] ) {
var type = category _type _mapping [ category ] [ index ] ;
2022-04-25 16:45:53 +02:00
optionsToPush [ type ] = type ;
2020-10-14 16:15:54 +02:00
}
}
} else {
optionsToPush = category _type _mapping [ selectedCategory ] ;
}
2022-04-25 16:45:53 +02:00
$ . each ( optionsToPush , function ( index , val ) {
var option = new Option ( val , val ) ;
2020-08-17 13:32:00 +02:00
if ( val === alreadySelected ) {
2022-04-25 16:45:53 +02:00
option . selected = true ;
2020-08-17 13:32:00 +02:00
}
2022-04-25 16:45:53 +02:00
options . add ( option ) ;
2019-02-13 08:46:18 +01:00
} ) ;
// enable the form element
2020-07-23 17:37:11 +02:00
$type . prop ( 'disabled' , false ) ;
2017-04-13 16:31:48 +02:00
}
2016-10-02 12:46:30 +02:00
2021-09-14 13:20:05 +02:00
function formTypeChanged ( idPrefix ) {
var $type = $ ( '#' + idPrefix + 'Type' ) ;
var currentType = $type . val ( ) ;
// Check if current type is correlatable and disable checkbox if yes
var nonCorrelatingType = non _correlating _types . indexOf ( currentType ) !== - 1 ;
$ ( '#' + idPrefix + 'DisableCorrelation' ) . prop ( 'disabled' , nonCorrelatingType ) ;
}
2017-04-13 16:31:48 +02:00
function malwareCheckboxSetter ( context ) {
2019-02-13 08:46:18 +01:00
var value = $ ( "#" + context + "Category" ) . val ( ) ; // get the selected value
// set the malware checkbox if the category is in the zip types
2021-07-20 17:30:17 +02:00
$ ( "#" + context + "Malware" ) . prop ( 'checked' , formZipTypeValues [ value ] ) ;
2017-04-13 16:31:48 +02:00
}
2016-10-02 12:46:30 +02:00
2017-04-13 16:31:48 +02:00
function feedFormUpdate ( ) {
2019-02-13 08:46:18 +01:00
$ ( '.optionalField' ) . hide ( ) ;
switch ( $ ( '#FeedSourceFormat' ) . val ( ) ) {
case 'freetext' :
$ ( '#TargetDiv' ) . show ( ) ;
2020-04-17 14:17:54 +02:00
$ ( '#OrgcDiv' ) . show ( ) ;
2019-02-13 08:46:18 +01:00
$ ( '#OverrideIdsDiv' ) . show ( ) ;
$ ( '#PublishDiv' ) . show ( ) ;
if ( $ ( '#FeedTarget' ) . val ( ) != 0 ) {
$ ( '#TargetEventDiv' ) . show ( ) ;
$ ( '#DeltaMergeDiv' ) . show ( ) ;
}
$ ( '#settingsCommonExcluderegexDiv' ) . show ( ) ;
break ;
case 'csv' :
$ ( '#TargetDiv' ) . show ( ) ;
2020-04-17 14:17:54 +02:00
$ ( '#OrgcDiv' ) . show ( ) ;
2019-02-13 08:46:18 +01:00
$ ( '#OverrideIdsDiv' ) . show ( ) ;
$ ( '#PublishDiv' ) . show ( ) ;
if ( $ ( '#FeedTarget' ) . val ( ) != 0 ) {
$ ( '#TargetEventDiv' ) . show ( ) ;
$ ( '#DeltaMergeDiv' ) . show ( ) ;
}
$ ( '#settingsCsvValueDiv' ) . show ( ) ;
$ ( '#settingsCsvDelimiterDiv' ) . show ( ) ;
$ ( '#settingsCommonExcluderegexDiv' ) . show ( ) ;
break ;
}
if ( $ ( '#FeedInputSource' ) . val ( ) == 'local' ) {
$ ( '#DeleteLocalFileDiv' ) . show ( ) ;
$ ( '#HeadersDiv' ) . hide ( ) ;
} else {
$ ( '#DeleteLocalFileDiv' ) . hide ( ) ;
$ ( '#HeadersDiv' ) . show ( ) ;
}
2022-09-26 17:02:06 +02:00
checkSharingGroup ( 'Feed' ) ;
2017-04-13 16:31:48 +02:00
}
2016-10-08 14:36:24 +02:00
2017-04-13 16:31:48 +02:00
function toggleContextFields ( ) {
2024-01-04 10:48:13 +01:00
$ ( '.context' ) . toggle ( )
$ ( '#show_attribute_context' ) . toggleClass ( "btn-inverse" ) . toggleClass ( "btn-primary" )
2017-04-13 16:31:48 +02:00
}
2016-11-04 00:13:17 +01:00
2017-04-13 16:31:48 +02:00
function checkOrphanedAttributes ( ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data , textStatus ) {
var color = 'red' ;
var text = ' (Removal recommended)' ;
if ( data == '0' ) {
color = 'green' ;
text = ' (OK)' ;
}
$ ( "#orphanedAttributeCount" ) . html ( '<span class="' + color + '">' + data + text + '</span>' ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
type : "get" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/attributes/checkOrphanedAttributes/" ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-11-04 13:14:03 +01:00
2017-05-11 14:11:08 +02:00
function checkAttachments ( ) {
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
success : function ( data , textStatus ) {
var color = 'red' ;
var text = ' (Bad links detected)' ;
if ( data !== undefined && data . trim ( ) == '0' ) {
color = 'green' ;
text = ' (OK)' ;
}
$ ( "#orphanedFileCount" ) . html ( '<span class="' + color + '">' + data + text + '</span>' ) ;
} ,
type : "get" ,
2021-02-19 15:38:03 +01:00
url : "/attributes/checkAttachments/" ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-05-11 14:11:08 +02:00
}
2017-04-13 16:31:48 +02:00
function loadTagTreemap ( ) {
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
success : function ( data , textStatus ) {
$ ( ".treemapdiv" ) . html ( data ) ;
} ,
type : "get" ,
2021-02-19 15:38:03 +01:00
url : "/users/tagStatisticsGraph" ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-11-14 07:09:40 +01:00
2017-04-13 16:31:48 +02:00
function selectAllInbetween ( last , current ) {
2022-04-18 11:49:14 +02:00
if ( last === false || last === current ) {
return false ;
}
var from = $ ( last ) . parent ( ) . parent ( ) . index ( ) ;
var to = $ ( current ) . parent ( ) . parent ( ) . index ( ) ;
2019-02-13 08:46:18 +01:00
if ( to < from ) {
var temp = from ;
from = to ;
to = temp ;
}
2022-04-18 11:49:14 +02:00
$ ( '.select_proposal, .select_attribute, .select' ) . each ( function ( ) {
var index = $ ( this ) . parent ( ) . parent ( ) . index ( ) ;
if ( index >= from && index <= to ) {
2019-02-13 08:46:18 +01:00
$ ( this ) . prop ( 'checked' , true ) ;
}
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-12-06 02:35:25 +01:00
2021-01-31 20:02:27 +01:00
$ ( '#eventToggleButtons button' ) . click ( function ( ) {
2019-02-13 08:46:18 +01:00
var element = $ ( this ) . data ( 'toggle-type' ) ;
2020-12-18 16:34:01 +01:00
var $button = $ ( this ) . children ( 'span' ) ;
2022-03-27 21:47:46 +02:00
var $element = $ ( '#' + element + '_div' ) ;
2021-01-31 20:02:27 +01:00
if ( $button . hasClass ( 'fa-minus' ) ) {
$button . addClass ( 'fa-plus' ) ;
$button . removeClass ( 'fa-minus' ) ;
2022-03-27 21:47:46 +02:00
$element . hide ( ) ;
2019-02-13 08:46:18 +01:00
} else {
2021-01-31 20:02:27 +01:00
$button . removeClass ( 'fa-plus' ) ;
$button . addClass ( 'fa-minus' ) ;
2022-03-27 21:47:46 +02:00
$element . show ( ) ;
// Special cases when another action must be made
if ( element === 'eventtimeline' ) {
enable _timeline ( ) ;
} else if ( element === 'eventgraph' ) {
enable _interactive _graph ( ) ;
}
2020-12-18 16:34:01 +01:00
var loadUrl = $ ( this ) . data ( 'load-url' ) ;
if ( loadUrl ) {
$ . get ( loadUrl , function ( data ) {
2022-03-27 21:47:46 +02:00
$element . html ( data ) ;
2021-02-19 15:38:03 +01:00
} ) . fail ( xhrFailCallback ) ;
2020-12-18 16:34:01 +01:00
}
2019-02-13 08:46:18 +01:00
}
2016-12-06 02:35:25 +01:00
} ) ;
2019-01-10 10:19:04 +01:00
function quickSubmitGalaxyForm ( cluster _ids , additionalData ) {
2019-07-09 13:59:39 +02:00
cluster _ids = cluster _ids === null ? [ ] : cluster _ids ;
2019-02-13 08:46:18 +01:00
var target _id = additionalData [ 'target_id' ] ;
var scope = additionalData [ 'target_type' ] ;
2019-07-08 11:39:41 +02:00
var local = additionalData [ 'local' ] ;
2022-04-26 12:27:17 +02:00
var mirrorOnEvent = additionalData [ 'mirrorOnEvent' ] ;
2020-08-16 13:31:31 +02:00
var url = baseurl + "/galaxies/attachMultipleClusters/" + target _id + "/" + scope + "/local:" + local ;
2019-07-08 11:39:41 +02:00
fetchFormDataAjax ( url , function ( formData ) {
2022-04-24 14:53:43 +02:00
var $formData = $ ( formData ) ;
$formData . find ( "#GalaxyTargetIds" ) . val ( JSON . stringify ( cluster _ids ) ) ;
2022-04-26 12:44:32 +02:00
$formData . find ( "#GalaxyMirrorOnEvent" ) . prop ( 'checked' , mirrorOnEvent ) ;
2022-04-24 14:53:43 +02:00
if ( target _id === 'selected' ) {
$formData . find ( '#GalaxyAttributeIds' ) . val ( getSelected ( ) ) ;
2019-06-07 14:44:39 +02:00
}
$ . ajax ( {
2022-04-24 14:53:43 +02:00
data : $formData . serialize ( ) ,
beforeSend : function ( ) {
2019-06-07 14:44:39 +02:00
$ ( ".loading" ) . show ( ) ;
} ,
2022-04-24 14:53:43 +02:00
success : function ( data ) {
if ( target _id === 'selected' || scope === 'tag_collection' ) {
2019-02-13 08:46:18 +01:00
location . reload ( ) ;
} else {
2022-04-24 14:53:43 +02:00
loadGalaxies ( target _id , scope ) ;
2022-04-26 12:44:32 +02:00
if ( mirrorOnEvent ) {
var event _id = $ ( '#eventgraph_network' ) . data ( 'event-id' )
loadGalaxies ( event _id , 'event' ) ;
2019-06-07 14:44:39 +02:00
}
2022-04-24 14:53:43 +02:00
handleGenericAjaxResponse ( data ) ;
2019-02-13 08:46:18 +01:00
}
2019-06-07 14:44:39 +02:00
} ,
error : function ( ) {
showMessage ( 'fail' , 'Could not add cluster.' ) ;
2022-04-24 14:53:43 +02:00
if ( target _id !== 'selected' ) {
loadGalaxies ( target _id , scope ) ;
}
2019-06-07 14:44:39 +02:00
} ,
complete : function ( ) {
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( ".loading" ) . hide ( ) ;
} ,
type : "post" ,
2019-07-08 11:39:41 +02:00
url : url
2019-06-07 14:44:39 +02:00
} ) ;
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-12-22 17:30:27 +01:00
2018-12-13 10:13:21 +01:00
function checkAndSetPublishedInfo ( skip _reload ) {
2019-02-13 08:46:18 +01:00
if ( typeof skip _reload === "undefined" ) {
skip _reload = false ;
}
2021-10-18 17:44:13 +02:00
var $el = $ ( '#hiddenSideMenuData' ) ;
if ( $el . length === 0 ) {
return ;
}
var id = $el . data ( 'event-id' ) ;
2019-02-13 08:46:18 +01:00
if ( id !== 'undefined' && ! skip _reload ) {
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/events/checkPublishedStatus/" + id , function ( data ) {
2019-02-13 08:46:18 +01:00
if ( data == 1 ) {
$ ( '.published' ) . removeClass ( 'hidden' ) ;
$ ( '.not-published' ) . addClass ( 'hidden' ) ;
} else {
$ ( '.published' ) . addClass ( 'hidden' ) ;
$ ( '.not-published' ) . removeClass ( 'hidden' ) ;
}
2021-02-19 15:38:03 +01:00
} ) . fail ( xhrFailCallback ) ;
2019-02-13 08:46:18 +01:00
}
2017-04-13 16:31:48 +02:00
}
2017-01-17 09:03:30 +01:00
2020-09-26 16:31:59 +02:00
$ ( function ( ) {
$ ( '#gray_out' ) . click ( function ( ) {
cancelPopoverForm ( ) ;
$ ( "#popover_matrix" ) . fadeOut ( ) ;
$ ( ".loading" ) . hide ( ) ;
resetForms ( ) ;
2022-04-16 21:33:38 +02:00
resetEditHoverForms ( ) ;
2020-09-26 16:31:59 +02:00
} )
} ) ;
2017-04-13 16:31:48 +02:00
$ ( document ) . keyup ( function ( e ) {
if ( e . keyCode === 27 ) {
2020-09-26 16:31:59 +02:00
cancelPopoverForm ( ) ;
2019-05-13 16:23:13 +02:00
$ ( "#popover_matrix" ) . fadeOut ( ) ;
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . hide ( ) ;
resetForms ( ) ;
2022-04-16 21:33:38 +02:00
resetEditHoverForms ( ) ;
2017-04-13 16:31:48 +02:00
}
2017-01-19 10:18:29 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
function closeScreenshot ( ) {
2019-05-21 10:10:14 +02:00
$ ( "#popover_box" ) . fadeOut ( ) ;
2022-04-21 16:20:25 +02:00
$ ( "#screenshot_box" ) . fadeOut ( 400 , function ( ) {
$ ( this ) . remove ( ) ;
} ) ;
2019-02-13 08:46:18 +01:00
$ ( "#gray_out" ) . fadeOut ( ) ;
2017-04-13 16:31:48 +02:00
}
2017-02-16 22:41:22 +01:00
2017-04-13 16:31:48 +02:00
function loadSightingGraph ( id , scope ) {
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/sightings/viewSightings/" + id + "/" + scope , function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#sightingsData" ) . html ( data ) ;
2021-02-19 15:38:03 +01:00
} ) . fail ( xhrFailCallback )
2017-04-13 16:31:48 +02:00
}
2017-02-20 13:26:49 +01:00
2017-04-13 16:31:48 +02:00
function checkRolePerms ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( "#RolePermission" ) . val ( ) == '0' || $ ( "#RolePermission" ) . val ( ) == '1' ) {
$ ( '.readonlydisabled' ) . prop ( 'checked' , false ) ;
$ ( '.readonlydisabled' ) . hide ( ) ;
} else {
$ ( '.readonlydisabled' ) . show ( ) ;
$ ( '.permFlags' ) . show ( ) ;
}
if ( $ ( "#RolePermSiteAdmin" ) . prop ( 'checked' ) ) {
2020-05-07 07:59:26 +02:00
$ ( '.site_admin_enforced' ) . prop ( 'checked' , true ) ;
2019-02-13 08:46:18 +01:00
}
2017-04-13 16:31:48 +02:00
}
2017-02-22 17:12:32 +01:00
2017-04-13 16:31:48 +02:00
function updateMISP ( ) {
2022-04-21 17:39:07 +02:00
$ . get ( baseurl + "/servers/update" , openConfirmation ) . fail ( xhrFailCallback )
2017-04-13 16:31:48 +02:00
}
2017-03-23 10:01:29 +01:00
2017-04-13 16:31:48 +02:00
function submitMISPUpdate ( ) {
2019-02-13 08:46:18 +01:00
var formData = $ ( '#PromptForm' ) . serialize ( ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2019-02-13 08:46:18 +01:00
data : formData ,
2021-02-19 15:38:03 +01:00
success : function ( data ) {
$ ( '#gitResult' ) . text ( data ) . removeClass ( 'hidden' ) ;
2019-02-13 08:46:18 +01:00
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
} ,
type : "post" ,
2021-02-19 15:38:03 +01:00
url : "/servers/update" ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2017-04-11 10:04:07 +02:00
2019-04-02 11:29:10 +02:00
function submitSubmoduleUpdate ( clicked ) {
var $clicked = $ ( clicked ) ;
2019-04-05 10:46:49 +02:00
var submodule _path = $clicked . data ( 'submodule' ) ;
2019-04-02 11:29:10 +02:00
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
2019-05-02 11:21:58 +02:00
$clicked . removeClass ( 'fa-download' ) ;
$clicked . addClass ( 'fa-spin fa-spinner' ) ;
2019-04-02 11:29:10 +02:00
} ,
2019-04-05 10:46:49 +02:00
dataType : "html" ,
2019-04-02 11:29:10 +02:00
cache : false ,
2019-04-05 10:46:49 +02:00
success : function ( formHTML , textStatus ) {
var $form = $ ( formHTML ) ;
$ ( 'body' ) . append ( $form ) ;
var formData = $form . serialize ( ) ;
$ . ajax ( {
data : formData ,
success : function ( data , textStatus ) {
if ( data . status ) {
2019-04-05 16:44:56 +02:00
var job _sent = data . job _sent !== undefined ? data . job _sent : false ;
var sync _result = data . sync _result !== undefined ? data . sync _result : '' ;
updateSubModulesStatus ( data . output , job _sent , sync _result ) ;
2019-04-05 10:46:49 +02:00
} else {
showMessage ( 'error' , 'Something went wrong' ) ;
$ ( '#submoduleGitResultDiv' ) . show ( ) ;
$ ( '#submoduleGitResult' ) . removeClass ( 'green' ) . addClass ( 'red' ) . text ( data . output ) ;
}
} ,
error : function ( data ) {
showMessage ( 'error' , 'Something went wrong' ) ;
$ ( '#submoduleGitResultDiv' ) . show ( ) ;
$ ( '#submoduleGitResult' ) . removeClass ( 'green' ) . addClass ( 'red' ) . text ( data . output ) ;
} ,
complete : function ( ) {
2019-05-02 11:21:58 +02:00
$clicked . removeClass ( 'fa-spin fa-spinner' ) ;
$clicked . addClass ( 'fa-download' ) ;
2019-04-05 10:46:49 +02:00
$form . remove ( ) ;
} ,
type : "post" ,
cache : false ,
url : $form . attr ( 'action' ) ,
} ) ;
} ,
2020-08-16 13:31:31 +02:00
url : baseurl + '/servers/getSubmoduleQuickUpdateForm/' + ( submodule _path !== undefined ? btoa ( submodule _path ) : '' ) ,
2019-04-02 11:29:10 +02:00
} ) ;
}
2017-07-02 20:32:30 +02:00
// Show $(id) if the enable parameter evaluates to true. Hide it otherwise
function checkAndEnable ( id , enable ) {
2019-02-13 08:46:18 +01:00
if ( enable ) {
$ ( id ) . show ( ) ;
} else {
$ ( id ) . hide ( ) ;
}
2017-07-02 20:32:30 +02:00
}
// Show and enable checkbox $(id) if the enable parameter evaluates to true. Hide and disable it otherwise.
function checkAndEnableCheckbox ( id , enable ) {
2019-02-13 08:46:18 +01:00
if ( enable ) {
$ ( id ) . removeAttr ( "disabled" ) ;
$ ( id ) . prop ( 'checked' , true ) ;
} else {
$ ( id ) . prop ( 'checked' , false ) ;
$ ( id ) . attr ( "disabled" , true ) ;
}
2017-07-02 20:32:30 +02:00
}
2017-08-09 17:53:25 +02:00
function enableDisableObjectRows ( rows ) {
2019-02-13 08:46:18 +01:00
rows . forEach ( function ( i ) {
if ( $ ( "#Attribute" + i + "ValueSelect" ) . length != 0 ) {
2019-05-15 16:31:22 +02:00
checkAndEnableCheckbox ( "#Attribute" + i + "Save" , $ ( "#Attribute" + i + "ValueSelect" ) . val ( ) != "" ) ;
$ ( "#Attribute" + i + "ValueSelect" ) . bind ( 'input propertychange' , function ( ) {
checkAndEnableCheckbox ( "#Attribute" + i + "Save" , $ ( this ) . val ( ) != "" ) ;
} )
2019-02-13 08:46:18 +01:00
} else if ( $ ( "#Attribute" + i + "Attachment" ) . length != 0 ) {
checkAndEnableCheckbox ( "#Attribute" + i + "Save" , $ ( "#Attribute" + i + "Attachment" ) . val ( ) != "" ) ;
} else {
checkAndEnableCheckbox ( "#Attribute" + i + "Save" , $ ( "#Attribute" + i + "Value" ) . val ( ) != "" ) ;
}
$ ( "#Attribute" + i + "Value" ) . bind ( 'input propertychange' , function ( ) {
checkAndEnableCheckbox ( "#Attribute" + i + "Save" , $ ( this ) . val ( ) != "" ) ;
} ) ;
$ ( "#Attribute" + i + "Attachment" ) . on ( 'change' , function ( ) {
checkAndEnableCheckbox ( "#Attribute" + i + "Save" , $ ( "#Attribute" + i + "Attachment" ) . val ( ) != "" ) ;
} ) ;
} ) ;
2017-08-09 17:53:25 +02:00
}
function objectReferenceInput ( ) {
2019-02-13 08:46:18 +01:00
var types = [ "Attribute" , "Object" ] ;
var $targetSelect = $ ( '[data-targetselect="targetSelect"]' ) ;
for ( var type in types ) {
for ( var k in targetEvent [ types [ type ] ] ) {
if ( targetEvent [ types [ type ] ] [ k ] [ 'uuid' ] == $ ( '#ObjectReferenceReferencedUuid' ) . val ( ) ) {
$targetSelect . val ( $ ( '#ObjectReferenceReferencedUuid' ) . val ( ) ) ;
changeObjectReferenceSelectOption ( $ ( '#ObjectReferenceReferencedUuid' ) . val ( ) , { type : types [ type ] } ) ;
$targetSelect . trigger ( 'chosen:updated' ) ;
}
}
}
2017-08-09 17:53:25 +02:00
}
2017-08-21 10:13:19 +02:00
function objectReferenceCheckForCustomRelationship ( ) {
2019-02-13 08:46:18 +01:00
var relationship _type _field = $ ( '#ObjectReferenceRelationshipTypeSelect option:selected' ) ;
var relationship _type = $ ( relationship _type _field ) . val ( ) ;
if ( relationship _type == 'custom' ) {
$ ( '#ObjectReferenceRelationshipType' ) . parent ( ) . removeClass ( 'hidden' ) ;
} else {
$ ( '#ObjectReferenceRelationshipType' ) . parent ( ) . addClass ( 'hidden' ) ;
}
2017-08-21 10:13:19 +02:00
}
2018-01-19 15:56:34 +01:00
function add _basic _auth ( ) {
2019-02-13 08:46:18 +01:00
var headers = $ ( '#FeedHeaders' ) . val ( ) . split ( "\n" ) ;
$ ( '#FeedHeaders' ) . val ( "" ) ;
headers . forEach ( function ( header ) {
header = header . trim ( ) ;
if ( header != "" ) {
header = header . split ( ":" ) ;
var key = header . shift ( ) ;
var value = header . join ( ":" ) ;
if ( key != 'Authorization' ) {
$ ( '#FeedHeaders' ) . val ( $ ( '#FeedHeaders' ) . val ( ) + key . trim ( ) + ":" + value . trim ( ) + "\n" ) ;
}
}
} ) ;
var basicAuth = $ ( '#BasicAuthUsername' ) . val ( ) . trim ( ) + ':' + $ ( '#BasicAuthPassword' ) . val ( ) . trim ( ) ;
$ ( '#FeedHeaders' ) . val ( $ ( '#FeedHeaders' ) . val ( ) + "Authorization: Basic " + btoa ( basicAuth ) + "\n" ) ;
$ ( '#basicAuthFormEnable' ) . show ( ) ;
$ ( '#basicAuthForm' ) . hide ( ) ;
2018-01-19 15:56:34 +01:00
}
2019-01-22 10:25:48 +01:00
function changeObjectReferenceSelectOption ( selected , additionalData ) {
2022-09-23 14:48:25 +02:00
var keys = {
"uuid" : "UUID" ,
"category" : "Category" ,
"type" : "Type" ,
"value" : "Value" ,
"to_ids" : "To IDS" ,
"name" : "Name" ,
"meta-category" : "Meta category" ,
} ;
2019-02-13 08:46:18 +01:00
var uuid = selected ;
2021-02-17 13:43:17 +01:00
var type = additionalData . itemOptions [ uuid ] . type ;
2019-02-13 08:46:18 +01:00
$ ( '#ObjectReferenceReferencedUuid' ) . val ( uuid ) ;
2022-09-23 14:48:25 +02:00
var $targetData = $ ( '#targetData' ) ;
if ( type === "Attribute" ) {
$targetData . html ( "" ) ;
2019-02-13 08:46:18 +01:00
for ( var k in targetEvent [ type ] [ uuid ] ) {
if ( $ . inArray ( k , [ 'uuid' , 'category' , 'type' , 'value' , 'to_ids' ] ) !== - 1 ) {
2022-09-23 14:48:25 +02:00
$targetData . append ( '<div><span class="bold">' + keys [ k ] + '</span>: ' + escapeHtml ( targetEvent [ type ] [ uuid ] [ k ] ) + '</div>' ) ;
2019-02-13 08:46:18 +01:00
}
}
} else {
2022-09-23 14:48:25 +02:00
$targetData . html ( "" ) ;
2019-02-13 08:46:18 +01:00
for ( var k in targetEvent [ type ] [ uuid ] ) {
2022-09-23 14:48:25 +02:00
if ( k === 'Attribute' ) {
$targetData . append ( '<br><div><span id="header" class="bold">Attributes:</span>' ) ;
for ( var attribute in targetEvent [ type ] [ uuid ] [ 'Attribute' ] ) {
for ( var k2 in targetEvent [ type ] [ uuid ] [ 'Attribute' ] [ attribute ] ) {
2019-02-13 08:46:18 +01:00
if ( $ . inArray ( k2 , [ 'category' , 'type' , 'value' , 'to_ids' ] ) !== - 1 ) {
2022-09-23 14:48:25 +02:00
$targetData . append ( '<div class="indent"><span class="bold">' + keys [ k2 ] + '</span>: ' + escapeHtml ( targetEvent [ type ] [ uuid ] [ 'Attribute' ] [ attribute ] [ k2 ] ) + '</div>' ) ;
2019-02-13 08:46:18 +01:00
}
}
2022-09-23 14:48:25 +02:00
$targetData . append ( '<br>' ) ;
2019-02-13 08:46:18 +01:00
}
} else {
if ( $ . inArray ( k , [ 'name' , 'uuid' , 'meta-category' ] ) !== - 1 ) {
2022-09-23 14:48:25 +02:00
$targetData . append ( '<div><span class="bold">' + keys [ k ] + '</span>: ' + escapeHtml ( targetEvent [ type ] [ uuid ] [ k ] ) + '</div>' ) ;
2019-02-13 08:46:18 +01:00
}
}
}
}
2017-08-09 17:53:25 +02:00
}
2017-07-02 20:32:30 +02:00
2020-07-19 19:57:07 +02:00
function delay ( callback , ms ) {
var timer = 0 ;
return function ( ) {
var context = this , args = arguments ;
clearTimeout ( timer ) ;
timer = setTimeout ( function ( ) {
callback . apply ( context , args ) ;
} , ms || 0 ) ;
} ;
}
2020-07-19 16:22:16 +02:00
function previewEventBasedOnUuids ( currentValue ) {
if ( currentValue === '' ) {
$ ( '#event_preview' ) . hide ( ) ;
2019-02-13 08:46:18 +01:00
} else {
$ . ajax ( {
2020-08-16 13:31:31 +02:00
url : baseurl + "/events/getEventInfoById/" + currentValue ,
2019-02-13 08:46:18 +01:00
type : "get" ,
2020-07-19 16:22:16 +02:00
error : function ( xhr ) {
$ ( '#event_preview' ) . hide ( ) ;
xhrFailCallback ( xhr ) ;
2019-02-13 08:46:18 +01:00
} ,
success : function ( data ) {
2020-07-19 16:22:16 +02:00
$ ( '#event_preview' ) . html ( data ) . show ( ) ;
2019-02-13 08:46:18 +01:00
}
} ) ;
}
2018-04-19 13:56:50 +02:00
}
2018-05-07 10:43:21 +02:00
function checkNoticeList ( type ) {
2019-02-13 08:46:18 +01:00
var fields _to _check = {
"attribute" : [ "category" , "type" ]
}
2021-09-14 13:20:05 +02:00
var $noticeMessage = $ ( '#notice_message' ) ;
$noticeMessage . html ( '<h4>Notices:</h4>' ) ;
$noticeMessage . hide ( ) ;
2019-02-13 08:46:18 +01:00
fields _to _check [ type ] . forEach ( function ( field _name ) {
if ( field _name in notice _list _triggers ) {
var field _value = $ ( '#' + type . ucfirst ( ) + field _name . ucfirst ( ) ) . val ( ) ;
if ( field _value in notice _list _triggers [ field _name ] ) {
notice _list _triggers [ field _name ] [ field _value ] . forEach ( function ( notice ) {
2021-09-14 13:20:05 +02:00
$noticeMessage . show ( ) ;
$noticeMessage . append (
2019-02-13 08:46:18 +01:00
$ ( '<div/>' )
. append ( $ ( '<span/>' ) . text ( '[' ) )
2020-08-16 13:31:31 +02:00
. append ( $ ( '<a/>' , { href : baseurl + '/noticelists/view/' + notice [ 'list_id' ] , class : 'bold' } ) . text ( notice [ 'list_name' ] ) )
2019-02-13 08:46:18 +01:00
. append ( $ ( '<span/>' ) . text ( ']: ' ) )
. append ( $ ( '<span/>' ) . text ( notice [ 'message' ] [ 'en' ] ) )
) ;
} ) ;
}
}
} ) ;
2018-05-07 10:43:21 +02:00
}
2022-02-19 15:09:23 +01:00
$ ( function ( ) {
2019-10-06 13:05:29 +02:00
// Show popover for disabled input that contains `data-disabled-reason`.
$ ( 'input:disabled[data-disabled-reason]' ) . popover ( "destroy" ) . popover ( {
placement : 'right' ,
html : 'true' ,
trigger : 'hover' ,
content : function ( ) {
return $ ( this ) . data ( 'disabled-reason' ) ;
}
} ) ;
2020-10-31 21:31:11 +01:00
$ ( '#PasswordPopover' ) . popover ( "destroy" ) . popover ( {
placement : 'right' ,
html : 'true' ,
trigger : 'hover' ,
content : function ( ) {
return $ ( this ) . data ( 'content' ) ;
}
} ) ;
2019-04-09 15:48:01 +02:00
$ ( ".queryPopover" ) . click ( function ( ) {
2022-05-13 16:14:56 +02:00
var url = $ ( this ) . data ( 'url' ) ;
$ . get ( url , function ( data ) {
var $popover = $ ( '#popover_form' ) ;
$popover . html ( data ) ;
openPopup ( $popover ) ;
2021-02-19 15:38:03 +01:00
} ) . fail ( xhrFailCallback )
2019-04-09 15:48:01 +02:00
} ) ;
$ ( '.servers_default_role_checkbox' ) . click ( function ( ) {
var id = $ ( this ) . data ( "id" ) ;
var state = $ ( this ) . is ( ":checked" ) ;
$ ( ".servers_default_role_checkbox" ) . not ( this ) . attr ( 'checked' , false ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
success : function ( data ) {
2019-04-09 15:48:01 +02:00
handleGenericAjaxResponse ( data ) ;
} ,
type : "get" ,
2021-02-19 15:38:03 +01:00
url : '/admin/roles/set_default/' + ( state ? id : "" ) ,
2019-04-09 15:48:01 +02:00
} ) ;
} ) ;
$ ( '.add_object_attribute_row' ) . click ( function ( ) {
var template _id = $ ( this ) . data ( 'template-id' ) ;
var object _relation = $ ( this ) . data ( 'object-relation' ) ;
var k = $ ( '#last-row' ) . data ( 'last-row' ) ;
var k = k + 1 ;
$ ( '#last-row' ) . data ( 'last-row' , k ) ;
2020-08-16 13:31:31 +02:00
url = baseurl + "/objects/get_row/" + template _id + "/" + object _relation + "/" + k ;
2019-04-09 15:48:01 +02:00
$ . get ( url , function ( data ) {
$ ( '#row_' + object _relation + '_expand' ) . before ( $ ( data ) . fadeIn ( ) ) . html ( ) ;
2019-05-16 09:07:50 +02:00
var $added _row = $ ( '#row_' + object _relation + '_expand' ) . prev ( ) . prev ( ) ;
$added _row . find ( 'select.Attribute_value_select option:first' ) . attr ( 'disabled' , true ) ;
2021-02-19 15:38:03 +01:00
} ) . fail ( xhrFailCallback ) ;
2019-04-09 15:48:01 +02:00
} ) ;
$ ( '.quickToggleCheckbox' ) . toggle ( function ( ) {
var url = $ ( this ) . data ( 'checkbox-url' ) ;
} ) ;
2020-09-28 21:33:12 +02:00
2022-02-19 15:09:23 +01:00
$ ( '#setHomePage' ) . parent ( ) . click ( function ( event ) {
2020-09-28 21:33:12 +02:00
event . preventDefault ( ) ;
setHomePage ( ) ;
2020-10-03 18:47:05 +02:00
} ) ;
2020-10-09 17:26:33 +02:00
$ ( document . body ) . on ( 'click' , '.privacy-toggle' , function ( ) {
2020-10-03 18:47:05 +02:00
var $this = $ ( this ) ;
var $privacy _target = $this . parent ( ) . find ( '.privacy-value' ) ;
if ( $this . hasClass ( 'fa-eye' ) ) {
$privacy _target . text ( $privacy _target . data ( 'hidden-value' ) ) ;
$this . removeClass ( 'fa-eye' ) ;
$this . addClass ( 'fa-eye-slash' ) ;
2020-10-10 09:45:23 +02:00
if ( $privacy _target . hasClass ( 'quickSelect' ) ) {
$privacy _target . click ( ) ;
}
2020-10-03 18:47:05 +02:00
} else {
$privacy _target . text ( '****************************************' ) ;
$this . removeClass ( 'fa-eye-slash' ) ;
$this . addClass ( 'fa-eye' ) ;
}
} ) ;
2020-12-18 22:56:49 +01:00
2021-02-23 19:28:08 +01:00
// For galaxyQuickViewNew.ctp
$ ( document . body ) . on ( 'click' , '*[data-clusterid]' , function ( ) {
loadClusterRelations ( $ ( this ) . data ( 'clusterid' ) ) ;
} ) ;
$ ( document . body ) . popover ( {
selector : '.galaxyQuickView ul li b' ,
html : true ,
trigger : 'hover' ,
container : 'body' ,
} ) . on ( 'shown' , function ( ) {
$ ( '.tooltip' ) . not ( ":last" ) . remove ( ) ;
} ) ;
2020-06-26 10:12:00 +02:00
} ) ;
2022-04-29 14:00:00 +02:00
// Correlation box for events
2022-04-29 12:13:47 +02:00
$ ( function ( ) {
var showAllCorrelations = false ;
var $eventCorrelations = $ ( "#event-correlations" ) ;
var $select = $eventCorrelations . find ( "select" ) ;
2022-04-29 14:00:00 +02:00
function changeEventOrder ( ) {
2022-04-29 12:13:47 +02:00
var orderBy = $select . val ( ) ;
var array = [ ] ;
$eventCorrelations . find ( ".event-correlation" ) . each ( function ( ) {
2022-04-29 15:05:23 +02:00
$ ( this ) . removeClass ( "hidden-important" ) ;
2022-04-29 12:13:47 +02:00
array . push ( {
"html" : $ ( this ) . prop ( "outerHTML" ) ,
"count" : $ ( this ) . data ( "count" ) ,
"date" : $ ( this ) . data ( "date" ) ,
} ) ;
} ) ;
// sort by defined property
array . sort ( function ( a , b ) {
var aProp = a [ orderBy ] ;
var bProp = b [ orderBy ] ;
if ( aProp < bProp ) {
return 1 ;
}
if ( aProp > bProp ) {
return - 1 ;
}
return 0 ;
} ) ;
var newHtml = array . map ( function ( item ) {
return item [ "html" ] ;
2022-04-29 14:00:00 +02:00
} ) . join ( " " ) ;
2022-04-29 12:13:47 +02:00
2022-04-29 15:05:23 +02:00
if ( $eventCorrelations . find ( ".expand-link" ) . length ) {
newHtml += $eventCorrelations . find ( ".expand-link" ) . prop ( "outerHTML" ) ;
newHtml += $eventCorrelations . find ( ".collapse-link" ) . prop ( "outerHTML" ) ;
2022-04-29 12:13:47 +02:00
}
$eventCorrelations . find ( ".correlation-container" ) . html ( newHtml ) ;
2022-04-29 14:00:00 +02:00
changeEventVisibility ( ) ;
}
function changeEventVisibility ( ) {
if ( showAllCorrelations ) {
2022-04-29 15:05:23 +02:00
$eventCorrelations . find ( ".event-correlation.hidden-important" ) . removeClass ( "hidden-important" ) ;
2022-04-29 14:00:00 +02:00
} else {
// Show just first ten
2022-04-29 15:05:23 +02:00
$eventCorrelations . find ( ".event-correlation" ) . slice ( 10 ) . addClass ( "hidden-important" ) ;
2022-04-29 12:13:47 +02:00
}
}
$select . change ( function ( ) {
2022-04-29 14:00:00 +02:00
changeEventOrder ( ) ;
2022-04-29 12:13:47 +02:00
} ) ;
2022-04-29 15:05:23 +02:00
$eventCorrelations . on ( "click" , ".expand-link" , function ( ) {
2022-04-29 12:13:47 +02:00
showAllCorrelations = true ;
2022-04-29 14:00:00 +02:00
changeEventVisibility ( ) ;
2022-04-29 15:05:23 +02:00
$eventCorrelations . find ( ".collapse-link" ) . show ( ) ;
2022-04-29 12:13:47 +02:00
$ ( this ) . hide ( ) ;
} ) ;
2022-04-29 15:05:23 +02:00
$eventCorrelations . on ( "click" , ".collapse-link" , function ( ) {
2022-04-29 12:13:47 +02:00
showAllCorrelations = false ;
2022-04-29 14:00:00 +02:00
changeEventVisibility ( ) ;
2022-04-29 15:05:23 +02:00
$eventCorrelations . find ( ".expand-link" ) . show ( ) ;
2022-04-29 12:13:47 +02:00
$ ( this ) . hide ( ) ;
} ) ;
2017-12-22 17:22:49 +01:00
} ) ;
2022-04-29 15:05:23 +02:00
// Handlers for showing/hiding attribute related events
$ ( document . body ) . on ( "click" , ".correlation-expand-button" , function ( ) {
$ ( this ) . parent ( ) . children ( ".correlation-expanded-area" ) . show ( ) ;
$ ( this ) . parent ( ) . children ( ".correlation-collapse-button" ) . show ( ) ;
$ ( this ) . hide ( ) ;
} ) . on ( "click" , ".correlation-collapse-button" , function ( ) {
$ ( this ) . parent ( ) . children ( ".correlation-expanded-area" ) . hide ( ) ;
$ ( this ) . parent ( ) . children ( ".correlation-expand-button" ) . show ( ) ;
$ ( this ) . hide ( ) ;
} ) ;
2020-10-07 09:33:53 +02:00
// Show full attribute value when value is truncated
$ ( document . body ) . on ( 'click' , 'span[data-full] a' , function ( e ) {
2020-09-26 16:31:59 +02:00
e . preventDefault ( ) ;
var $parent = $ ( this ) . parent ( ) ;
var data = $parent . attr ( 'data-full' ) ;
var type = $parent . attr ( 'data-full-type' ) ;
var $box ;
2020-10-14 16:28:13 +02:00
if ( type === 'raw' || type === 'cortex' ) {
if ( type === 'cortex' ) {
data = JSON . stringify ( JSON . parse ( data ) , null , 2 ) ; // make JSON nicer
}
2020-10-06 17:06:25 +02:00
$box = $ ( '<pre>' ) . css ( {
'background' : 'white' ,
'border' : '0' ,
2020-10-07 09:33:53 +02:00
'margin' : '0' ,
2020-10-06 17:06:25 +02:00
} ) . text ( data ) ;
2020-09-26 16:31:59 +02:00
} else {
2020-10-06 17:06:25 +02:00
$box = $ ( '<div>' ) . css ( {
'background' : 'white' ,
'white-space' : 'pre-wrap' ,
'word-wrap' : 'break-word' ,
'padding' : '1em' ,
} ) . text ( data ) ;
2020-09-26 16:31:59 +02:00
}
2020-10-07 09:33:53 +02:00
var $popoverFormLarge = $ ( '#popover_form_large' ) ;
$popoverFormLarge . html ( $box [ 0 ] . outerHTML ) ;
openPopup ( $popoverFormLarge ) ;
} )
// Submit quick filter form when user press enter in input field
$ ( document . body ) . on ( 'keyup' , '#quickFilterField' , function ( e ) {
2020-10-04 14:21:19 +02:00
if ( e . keyCode === 13 ) { // ENTER key
$ ( '#quickFilterButton' ) . trigger ( "click" ) ;
}
2017-12-22 17:22:49 +01:00
} ) ;
2022-10-14 12:58:08 +02:00
// Send textarea or select form on CMD+ENTER or CTRL+ENTER
$ ( document . body ) . on ( 'keydown' , 'textarea, select' , function ( e ) {
2020-10-11 12:45:05 +02:00
if ( e . keyCode === 13 && ( e . metaKey || e . ctrlKey ) ) { // CMD+ENTER or CTRL+ENTER key
if ( e . target . form ) {
2020-10-11 19:27:53 +02:00
$ ( e . target . form ) . submit ( ) ;
2020-10-11 12:45:05 +02:00
}
}
} ) ;
2020-11-15 10:49:13 +01:00
// Clicking on an element with this class will select all of its contents in a single click
$ ( document . body ) . on ( 'click' , '.quickSelect' , function ( ) {
var range = document . createRange ( ) ;
var selection = window . getSelection ( ) ;
range . selectNodeContents ( this ) ;
selection . removeAllRanges ( ) ;
selection . addRange ( range ) ;
} ) ;
2022-03-20 09:36:21 +01:00
// Any link with data-paginator attribute will be treated as AJAX paginator
2021-01-10 12:03:04 +01:00
$ ( document . body ) . on ( 'click' , 'a[data-paginator]' , function ( e ) {
2021-01-10 12:53:04 +01:00
e . preventDefault ( ) ;
var paginatorTarget = $ ( this ) . attr ( 'data-paginator' ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2021-01-10 12:03:04 +01:00
dataType : "html" ,
success : function ( data ) {
2022-07-01 09:59:34 +02:00
var $target = $ ( paginatorTarget ) ;
destroyPopovers ( $target ) ;
$target . html ( data ) ;
2021-01-10 12:53:04 +01:00
} ,
2021-01-10 12:03:04 +01:00
url : $ ( this ) . attr ( 'href' ) ,
} ) ;
} ) ;
2022-03-29 12:30:36 +02:00
// Any link with `modal-open` class will be treated as generic modal
2022-03-20 09:36:21 +01:00
$ ( document . body ) . on ( 'click' , 'a.modal-open' , function ( e ) {
e . preventDefault ( ) ;
openGenericModal ( $ ( this ) . attr ( 'href' ) ) ;
} ) ;
2022-03-29 17:17:48 +02:00
$ ( document . body ) . on ( 'click' , '[data-popover-popup]' , function ( e ) {
e . preventDefault ( ) ;
var url = $ ( this ) . data ( 'popover-popup' ) ;
2022-03-29 18:50:22 +02:00
popoverPopupNew ( this , url ) ;
2022-03-29 17:17:48 +02:00
} ) ;
2023-06-06 21:46:46 +02:00
$ ( document ) . ready ( function ( ) {
var d = new Date ( )
if ( d . getDate ( ) == 1 && d . getMonth ( ) == 3 ) {
$ ( "a:contains('tlp:unclear')" ) . css ( 'background-color' , '#ffffff' ) . addClass ( 'special-tag' )
}
} ) ;
2022-07-01 09:59:34 +02:00
function destroyPopovers ( $element ) {
$element . find ( '[data-dismissid]' ) . each ( function ( ) {
$ ( this ) . popover ( 'destroy' ) ;
} ) ;
}
2021-03-19 18:00:21 +01:00
function queryEventLock ( event _id , timestamp ) {
2022-05-04 17:01:00 +02:00
var interval = null ;
var errorCount = 0 ;
var $container = $ ( '#main-view-container' ) ;
function fetchLocks ( ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2021-03-19 18:00:21 +01:00
url : baseurl + "/events/checkLocks/" + event _id + "/" + timestamp ,
2019-02-13 08:46:18 +01:00
success : function ( data , statusText , xhr ) {
2022-05-04 17:01:00 +02:00
if ( xhr . status === 200 ) {
$ ( '#event_lock_warning' ) . remove ( ) ;
$container . append ( data ) ;
} else if ( xhr . status === 204 ) {
$ ( '#event_lock_warning' ) . remove ( ) ;
}
errorCount = 0 ;
} ,
error : function ( xhr ) {
if ( xhr . status === 401 ) {
var error = '<div id="event_lock_warning" class="alert">' +
'<button class="close" data-dismiss="alert">× </button>' +
'Unauthorized. Please reload page to log again.' +
'</div>' ;
$ ( '#event_lock_warning' ) . remove ( ) ;
$container . append ( error ) ;
}
++ errorCount ;
if ( errorCount > 60 ) { // 5 mins
clearInterval ( interval ) ;
interval = null ;
}
2019-02-13 08:46:18 +01:00
}
} ) ;
}
2022-05-04 17:01:00 +02:00
document . addEventListener ( "visibilitychange" , function ( ) {
if ( document . visibilityState === 'visible' ) {
if ( interval === null ) {
interval = setInterval ( fetchLocks , 5000 ) ; // 5 seconds
}
} else {
if ( interval ) {
clearInterval ( interval ) ;
interval = null ;
}
}
} ) ;
if ( ! document . hidden ) {
interval = setInterval ( fetchLocks , 5000 ) ; // 5 seconds
}
2018-06-12 09:40:23 +02:00
}
2018-06-12 16:09:50 +02:00
function checkIfLoggedIn ( ) {
2021-03-02 10:04:32 +01:00
if ( ! document . hidden ) {
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/users/checkIfLoggedIn.json" )
2019-10-14 09:06:17 +02:00
. fail ( function ( xhr ) {
if ( xhr . status === 403 ) {
window . location . replace ( baseurl + "/users/login" ) ;
}
} ) ;
2019-02-13 08:46:18 +01:00
}
2019-10-14 09:06:17 +02:00
setTimeout ( function ( ) {
checkIfLoggedIn ( ) ;
} , 5000 ) ;
2018-06-12 16:09:50 +02:00
}
2018-08-21 07:55:49 +02:00
function insertRawRestResponse ( ) {
2019-02-13 08:46:18 +01:00
$ ( '#rest-response-container' ) . append ( '<pre id="raw-response-container" />' ) ;
$ ( '#raw-response-container' ) . text ( $ ( '#rest-response-hidden-container' ) . text ( ) ) ;
2018-08-21 07:55:49 +02:00
}
2018-08-21 13:25:39 +02:00
2018-08-21 07:55:49 +02:00
function insertHTMLRestResponse ( ) {
2019-02-13 08:46:18 +01:00
$ ( '#rest-response-container' ) . append ( '<div id="html-response-container" style="border: 1px solid blue; padding:5px;" />' ) ;
$ ( '#html-response-container' ) . html ( $ ( '#rest-response-hidden-container' ) . text ( ) ) ;
2018-08-21 07:55:49 +02:00
}
2018-08-21 13:25:39 +02:00
2018-08-21 07:55:49 +02:00
function insertJSONRestResponse ( ) {
2019-09-20 11:54:24 +02:00
$ ( '#rest-response-container' ) . append ( '<p id="json-response-container" style="border: 1px solid blue; padding:5px; overflow-wrap: break-word;" />' ) ;
2019-02-13 08:46:18 +01:00
var parsedJson = syntaxHighlightJson ( $ ( '#rest-response-hidden-container' ) . text ( ) ) ;
$ ( '#json-response-container' ) . html ( parsedJson ) ;
2018-08-21 07:55:49 +02:00
}
2018-08-21 13:25:39 +02:00
2019-02-14 10:24:42 +01:00
function syntaxHighlightJson ( json , indent ) {
2019-02-14 10:27:32 +01:00
if ( indent === undefined ) {
indent = 2 ;
}
2019-02-13 08:46:18 +01:00
if ( typeof json == 'string' ) {
json = JSON . parse ( json ) ;
}
2019-09-29 20:20:39 +02:00
json = JSON . stringify ( json , undefined , indent ) ;
2019-02-13 08:46:18 +01:00
json = json . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /(?:\r\n|\r|\n)/g , '<br>' ) . replace ( / /g , ' ' ) ;
return json . replace ( /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g , function ( match ) {
2021-02-19 15:38:03 +01:00
var cls = 'json_number' ;
if ( /^"/ . test ( match ) ) {
if ( /:$/ . test ( match ) ) {
cls = 'json_key' ;
} else {
cls = 'json_string' ;
}
} else if ( /true|false/ . test ( match ) ) {
cls = 'json_boolean' ;
} else if ( /null/ . test ( match ) ) {
cls = 'json_null' ;
}
return '<span class="' + cls + '">' + match + '</span>' ;
2019-02-13 08:46:18 +01:00
} ) ;
2018-08-21 07:55:49 +02:00
}
2019-07-09 09:49:08 +02:00
function jsonToNestedTable ( json , header , table _classes ) {
if ( typeof json == 'string' ) {
json = JSON . parse ( json ) ;
}
2019-08-16 15:10:59 +02:00
if ( Object . keys ( json ) . length == 0 ) {
return '' ;
}
2019-07-09 09:49:08 +02:00
header = header === undefined ? [ ] : header ;
table _classes = table _classes === undefined ? [ ] : table _classes ;
2019-08-23 09:26:42 +02:00
var $table = $ ( '<table></table>' ) ;
2019-07-09 09:49:08 +02:00
table _classes . forEach ( function ( classname ) {
2019-08-16 15:10:59 +02:00
$table . addClass ( classname ) ;
2019-07-09 09:49:08 +02:00
} ) ;
if ( header . length > 0 ) {
2019-08-23 09:26:42 +02:00
var $header = $ ( '<thead><tr></tr></thead>' ) ;
2019-07-09 09:49:08 +02:00
header . forEach ( function ( col ) {
2019-09-26 14:34:05 +02:00
$header . children ( ) . append ( $ ( '<th></th>' ) . text ( col ) ) ;
2019-07-09 09:49:08 +02:00
} ) ;
$table . append ( $header ) ;
}
2019-08-23 09:26:42 +02:00
var $body = $ ( '<tbody></tbody>' ) ;
2019-07-09 09:49:08 +02:00
Object . keys ( json ) . forEach ( function ( k ) {
var value = json [ k ] ;
2019-08-23 09:21:52 +02:00
if ( typeof value === 'object' ) {
value = JSON . stringify ( value ) ;
}
2019-08-28 11:18:45 +02:00
$body . append (
$ ( '<tr></tr>' )
. append ( $ ( '<td></td>' ) . text ( k ) )
. append ( $ ( '<td></td>' ) . text ( value ) )
) ;
2019-07-09 09:49:08 +02:00
} ) ;
$table . append ( $body ) ;
return $table [ 0 ] . outerHTML ;
}
2019-09-26 14:34:05 +02:00
function arrayToNestedTable ( header , data , table _classes ) {
header = header === undefined ? [ ] : header ;
table _classes = table _classes === undefined ? [ 'table' , 'table-condensed' , 'table-bordered' ] : table _classes ;
var $table = $ ( '<table></table>' ) ;
table _classes . forEach ( function ( classname ) {
$table . addClass ( classname ) ;
} ) ;
if ( header . length > 0 ) {
var $header = $ ( '<thead><tr></tr></thead>' ) ;
header . forEach ( function ( col ) {
$header . children ( ) . append ( $ ( '<th></th>' ) . text ( col ) ) ;
} ) ;
$table . append ( $header ) ;
}
var $body = $ ( '<tbody></tbody>' ) ;
data . forEach ( function ( row , i ) {
var $tr = $ ( '<tr></tr>' ) ;
row . forEach ( function ( cell , j ) {
var $td = $ ( '<td></td>' ) . text ( cell ) ;
$tr . append ( $td ) ;
} ) ;
$body . append ( $tr ) ;
} ) ;
$table . append ( $body ) ;
return $table [ 0 ] . outerHTML ;
}
2019-02-23 17:50:32 +01:00
function liveFilter ( ) {
var lookupString = $ ( '#liveFilterField' ) . val ( ) ;
if ( lookupString == '' ) {
$ ( '.live_filter_target' ) . each ( function ( ) {
$ ( this ) . parent ( ) . show ( ) ;
} ) ;
} else {
$ ( '.live_filter_target' ) . each ( function ( ) {
$ ( this ) . parent ( ) . hide ( ) ;
} ) ;
$ ( '.live_filter_target' ) . each ( function ( ) {
if ( $ ( this ) . text ( ) . indexOf ( lookupString ) >= 0 ) {
$ ( this ) . parent ( ) . show ( ) ;
}
} ) ;
}
}
2019-03-11 14:24:15 +01:00
function sparklineBar ( elemId , data , lineCount ) {
data = d3 . csv . parse ( data ) ;
var y _max = 0 ;
data . forEach ( function ( e ) {
e = parseInt ( e . val ) ;
y _max = e > y _max ? e : y _max ;
} ) ;
var WIDTH = 50 ;
var HEIGHT = 25 ;
var DATA _COUNT = lineCount ;
var BAR _WIDTH = ( WIDTH - DATA _COUNT ) / DATA _COUNT ;
var x = d3 . scale . linear ( ) . domain ( [ 0 , DATA _COUNT ] ) . range ( [ 0 , WIDTH ] ) ;
var y = d3 . scale . linear ( ) . domain ( [ 0 , y _max ] ) . range ( [ 0 , HEIGHT ] ) ;
var distributionGraphBarTooltip = d3 . select ( "body" ) . append ( "div" )
. attr ( "class" , "distributionGraphBarTooltip" )
. style ( "opacity" , 0 ) ;
var svg = d3 . select ( elemId ) . append ( 'svg' )
. attr ( 'width' , WIDTH )
. attr ( 'height' , HEIGHT )
. append ( 'g' ) ;
svg . selectAll ( '.bar' ) . data ( data )
. enter ( )
. append ( 'g' )
. attr ( 'title' , function ( d , i ) { return d . scope + ': ' + d . val } )
. attr ( 'class' , 'DGbar' )
. append ( 'rect' )
. attr ( 'class' , 'bar' )
. attr ( 'x' , function ( d , i ) { return x ( i ) ; } )
. attr ( 'y' , function ( d , i ) { return HEIGHT - y ( d . val ) ; } )
. attr ( 'width' , BAR _WIDTH )
. attr ( 'height' , function ( d , i ) { return y ( d . val ) ; } )
. attr ( 'fill' , '#3465a4' ) ;
$ ( '.DGbar' ) . tooltip ( { container : 'body' } ) ;
}
2019-03-10 18:09:46 +01:00
function generic _picker _move ( scope , direction ) {
if ( direction === 'right' ) {
$ ( '#' + scope + 'Left option:selected' ) . remove ( ) . appendTo ( '#' + scope + 'Right' ) ;
} else {
$ ( '#' + scope + 'Right option:selected' ) . remove ( ) . appendTo ( '#' + scope + 'Left' ) ;
}
}
function submit _feed _overlap _tool ( feedId ) {
var result = { "Feed" : [ ] , "Server" : [ ] } ;
$ ( '#FeedLeft' ) . children ( ) . each ( function ( ) {
result . Feed . push ( $ ( this ) . val ( ) ) ;
} ) ;
$ ( '#ServerLeft' ) . children ( ) . each ( function ( ) {
result . Server . push ( $ ( this ) . val ( ) ) ;
} ) ;
2021-02-19 15:38:03 +01:00
xhr ( {
2019-03-10 18:09:46 +01:00
data : result ,
success : function ( data , textStatus ) {
if ( ! isNaN ( data ) ) {
$ ( '#feed_coverage_bar' ) . text ( data + '%' ) ;
$ ( '#feed_coverage_bar' ) . css ( 'width' , data + '%' ) ;
} else {
handleGenericAjaxResponse ( { 'saved' : false , 'errors' : [ 'Something went wrong. Received response not in the expected format.' ] } ) ;
}
} ,
error : function ( ) {
handleGenericAjaxResponse ( { 'saved' : false , 'errors' : [ 'Could not complete the requested action.' ] } ) ;
} ,
type : "post" ,
2021-02-19 15:38:03 +01:00
url : "/feeds/feedCoverage/" + feedId ,
2019-03-10 18:09:46 +01:00
} ) ;
}
2020-05-07 16:17:44 +02:00
function fetchFormDataAjax ( url , callback , errorCallback ) {
2019-03-19 15:59:31 +01:00
$ . ajax ( {
2021-02-26 10:49:15 +01:00
success : function ( data ) {
2019-06-07 14:44:39 +02:00
callback ( data ) ;
2019-03-19 15:59:31 +01:00
} ,
error : function ( ) {
2019-03-20 11:21:40 +01:00
handleGenericAjaxResponse ( { 'saved' : false , 'errors' : [ 'Request failed due to an unexpected error.' ] } ) ;
2020-05-07 16:17:44 +02:00
if ( errorCallback !== undefined ) {
errorCallback ( ) ;
}
2019-03-19 15:59:31 +01:00
} ,
2021-02-26 10:49:15 +01:00
type : "get" ,
2019-03-19 15:59:31 +01:00
cache : false ,
2019-03-20 11:21:40 +01:00
url : url
2019-03-19 15:59:31 +01:00
} ) ;
}
2019-09-13 11:49:12 +02:00
function moveIndexRow ( id , direction , endpoint ) {
var row = $ ( '#row_' + id ) ;
$ . ajax ( {
url : baseurl + endpoint + '/' + id + '/' + direction ,
type : 'GET' ,
success : function ( data ) {
if ( direction === 'up' ) {
if ( row . prev ( ) . length ) {
row . insertBefore ( row . prev ( ) ) ;
}
} else {
if ( row . next ( ) . length ) {
row . insertAfter ( row . next ( ) ) ;
}
}
handleGenericAjaxResponse ( { 'saved' : true , 'success' : [ 'Server priority changed.' ] } ) ;
} ,
error : function ( data ) {
handleGenericAjaxResponse ( { 'saved' : false , 'errors' : [ 'Something went wrong, could not change the priority as requested.' ] } ) ;
}
} ) ;
}
2019-10-08 11:43:56 +02:00
function checkRoleEnforceRateLimit ( ) {
if ( $ ( "#RoleEnforceRateLimit" ) . is ( ':checked' ) ) {
$ ( '#rateLimitCountContainer' ) . show ( ) ;
} else {
$ ( '#rateLimitCountContainer' ) . hide ( ) ;
}
}
2019-11-20 15:30:06 +01:00
function queryDeprecatedEndpointUsage ( ) {
$ . ajax ( {
2022-04-10 10:18:28 +02:00
url : baseurl + '/api/viewDeprecatedFunctionUse' ,
2019-11-20 15:30:06 +01:00
type : 'GET' ,
success : function ( data ) {
$ ( '#deprecationResults' ) . html ( data ) ;
} ,
2022-04-10 10:18:28 +02:00
error : function ( ) {
2019-11-20 15:30:06 +01:00
handleGenericAjaxResponse ( { 'saved' : false , 'errors' : [ 'Could not query the deprecation statistics.' ] } ) ;
}
} ) ;
}
2017-04-13 16:31:48 +02:00
( function ( ) {
"use strict" ;
$ ( ".datepicker" ) . datepicker ( {
format : 'yyyy-mm-dd' ,
} ) ;
2018-03-19 10:36:09 +01:00
} ( ) ) ;
2020-03-01 18:05:21 +01:00
function submitDashboardForm ( id ) {
var configData = $ ( '#DashboardConfig' ) . val ( ) ;
if ( configData != '' ) {
2021-02-17 15:15:08 +01:00
try {
configData = JSON . parse ( configData ) ;
} catch ( error ) {
showMessage ( 'fail' , error . message )
return
}
2020-03-01 18:05:21 +01:00
} else {
configData = { } ;
}
configData = JSON . stringify ( configData ) ;
$ ( '#' + id ) . attr ( 'config' , configData ) ;
$ ( '#genericModal' ) . modal ( 'hide' ) ;
saveDashboardState ( ) ;
}
function submitDashboardAddWidget ( ) {
var widget = $ ( '#DashboardWidget' ) . val ( ) ;
var config = $ ( '#DashboardConfig' ) . val ( ) ;
var width = $ ( '#DashboardWidth' ) . val ( ) ;
var height = $ ( '#DashboardHeight' ) . val ( ) ;
var el = null ;
2020-03-01 19:03:31 +01:00
var k = $ ( '#last-element-counter' ) . data ( 'element-counter' ) ;
2024-04-08 11:36:51 +02:00
if ( config === '' ) {
config = '[]'
}
try {
config = JSON . parse ( config ) ;
} catch ( error ) {
showMessage ( 'fail' , error . message )
return
}
config = JSON . stringify ( config ) ;
2020-03-01 18:05:21 +01:00
$ . ajax ( {
url : baseurl + '/dashboards/getEmptyWidget/' + widget + '/' + ( k + 1 ) ,
type : 'GET' ,
success : function ( data ) {
el = data ;
grid . addWidget (
el ,
{
"width" : width ,
"height" : height ,
"autoposition" : 1
}
) ;
2020-03-01 19:03:31 +01:00
$ ( '#widget_' + ( k + 1 ) ) . attr ( 'config' , config ) ;
2020-03-01 19:11:43 +01:00
$ ( '#last-element-counter' ) . data ( 'element-counter' , ( k + 1 ) ) ;
2020-03-01 18:05:21 +01:00
} ,
complete : function ( data ) {
$ ( '#genericModal' ) . modal ( 'hide' ) ;
} ,
error : function ( data ) {
handleGenericAjaxResponse ( { 'saved' : false , 'errors' : [ 'Could not fetch empty widget.' ] } ) ;
}
} ) ;
}
function saveDashboardState ( ) {
var dashBoardSettings = [ ] ;
2022-05-06 12:48:06 +02:00
$ ( '.grid-stack-item' ) . each ( function ( ) {
2020-03-01 18:05:21 +01:00
if ( $ ( this ) . attr ( 'config' ) !== undefined && $ ( this ) . attr ( 'widget' ) !== undefined ) {
var config = $ ( this ) . attr ( 'config' ) ;
config = JSON . parse ( config ) ;
var temp = {
'widget' : $ ( this ) . attr ( 'widget' ) ,
'config' : config ,
'position' : {
'x' : $ ( this ) . attr ( 'data-gs-x' ) ,
'y' : $ ( this ) . attr ( 'data-gs-y' ) ,
'width' : $ ( this ) . attr ( 'data-gs-width' ) ,
'height' : $ ( this ) . attr ( 'data-gs-height' )
}
} ;
dashBoardSettings . push ( temp ) ;
}
} ) ;
2021-06-04 16:35:32 +02:00
var url = baseurl + '/dashboards/updateSettings'
fetchFormDataAjax ( url , function ( formData ) {
2021-06-07 08:19:07 +02:00
var $formContainer = $ ( formData )
$formContainer . find ( '#DashboardValue' ) . val ( JSON . stringify ( dashBoardSettings ) )
var $theForm = $formContainer . find ( 'form' )
2021-06-04 16:35:32 +02:00
xhr ( {
2021-06-07 08:19:07 +02:00
data : $theForm . serialize ( ) ,
2022-05-06 12:48:06 +02:00
success : function ( ) {
2021-06-04 16:35:32 +02:00
showMessage ( 'success' , 'Dashboard settings saved.' ) ;
} ,
beforeSend : function ( ) {
} ,
type : "post" ,
2021-06-07 08:19:07 +02:00
url : $theForm . attr ( 'action' )
2021-06-04 16:35:32 +02:00
} ) ;
} )
2020-03-01 18:05:21 +01:00
}
function updateDashboardWidget ( element ) {
2021-02-03 17:47:51 +01:00
var $element = $ ( element ) ;
2021-02-15 17:26:48 +01:00
if ( $element . length ) {
2021-02-03 17:47:51 +01:00
var container _id = $element . attr ( 'id' ) . substring ( 7 ) ;
var container = $element . find ( '.widgetContent' ) ;
var titleText = $element . find ( '.widgetTitleText' ) ;
var temp = JSON . parse ( $element . attr ( 'config' ) ) ;
2020-03-10 10:58:41 +01:00
if ( temp [ 'alias' ] !== undefined ) {
titleText . text ( temp [ 'alias' ] ) ;
}
$ . ajax ( {
type : 'POST' ,
url : baseurl + '/dashboards/renderWidget/' + container _id ,
data : {
2021-02-03 17:47:51 +01:00
config : $element . attr ( 'config' ) ,
widget : $element . attr ( 'widget' )
2020-03-10 10:58:41 +01:00
} ,
2022-05-06 12:48:06 +02:00
success : function ( data ) {
2020-03-10 10:58:41 +01:00
container . html ( data ) ;
}
} ) ;
2020-03-01 18:05:21 +01:00
}
}
2022-05-06 12:48:06 +02:00
function resetDashboardGrid ( grid , save = true ) {
2020-03-10 11:34:30 +01:00
$ ( '.grid-stack-item' ) . each ( function ( ) {
updateDashboardWidget ( this ) ;
} ) ;
2022-05-06 12:48:06 +02:00
if ( save ) {
saveDashboardState ( ) ;
}
2020-03-10 11:34:30 +01:00
$ ( '.edit-widget' ) . click ( function ( ) {
2022-05-06 12:48:06 +02:00
var el = $ ( this ) . closest ( '.grid-stack-item' ) ;
var data = {
2020-03-10 11:34:30 +01:00
id : el . attr ( 'id' ) ,
config : JSON . parse ( el . attr ( 'config' ) ) ,
widget : el . attr ( 'widget' ) ,
alias : el . attr ( 'alias' )
}
openGenericModalPost ( baseurl + '/dashboards/getForm/edit' , data ) ;
} ) ;
$ ( '.remove-widget' ) . click ( function ( ) {
2022-05-06 12:48:06 +02:00
var el = $ ( this ) . closest ( '.grid-stack-item' ) ;
2020-03-10 11:34:30 +01:00
grid . removeWidget ( el ) ;
saveDashboardState ( ) ;
} ) ;
2023-08-07 14:32:21 +02:00
$ ( '.widget-export-menu' ) . find ( 'a[data-exporttype]' ) . click ( function ( ) {
var $element = $ ( this ) . closest ( 'div[widget]' ) ;
2023-06-26 18:16:31 +02:00
var container _id = $element . attr ( 'id' ) . substring ( 7 ) ;
2023-08-07 14:32:21 +02:00
var export _type = $ ( this ) . data ( 'exporttype' )
2023-06-26 18:16:31 +02:00
$ . ajax ( {
type : 'POST' ,
2023-08-07 14:32:21 +02:00
url : baseurl + '/dashboards/renderWidget/' + container _id + '/export' + export _type + ':1' ,
2023-06-26 18:16:31 +02:00
data : {
config : $element . attr ( 'config' ) ,
widget : $element . attr ( 'widget' )
} ,
success : function ( data ) {
2023-08-09 14:56:24 +02:00
if ( export _type == 'json' ) {
data = JSON . stringify ( data , null , 2 ) ;
}
var blob = new Blob ( [ data ] , { type : ( export _type == 'json' ? 'application/json' : 'text/csv' ) } ) ;
2023-06-26 18:16:31 +02:00
var link = window . document . createElement ( 'a' ) ;
link . href = window . URL . createObjectURL ( blob ) ;
2023-08-07 14:32:21 +02:00
link . download = $element . attr ( 'widget' ) + "_" + container _id + "_export." + export _type ;
2023-06-26 18:16:31 +02:00
link . click ( ) ;
}
} ) ;
2023-08-07 14:32:21 +02:00
} )
2020-03-10 11:34:30 +01:00
}
2020-03-01 18:05:21 +01:00
function setHomePage ( ) {
$ . ajax ( {
2020-07-13 12:19:11 +02:00
type : 'GET' ,
2020-03-01 18:05:21 +01:00
url : baseurl + '/userSettings/setHomePage' ,
2022-02-19 15:09:23 +01:00
success : function ( data ) {
2022-05-05 22:59:51 +02:00
var $tmp = $ ( data ) ;
2020-07-13 12:19:11 +02:00
var currentPage = $ ( '#setHomePage' ) . data ( 'current-page' ) ;
2022-05-05 22:59:51 +02:00
$tmp . find ( '#UserSettingPath' ) . val ( currentPage ) ;
2020-07-13 12:19:11 +02:00
$ . ajax ( {
type : 'POST' ,
url : baseurl + '/userSettings/setHomePage' ,
2022-05-05 22:59:51 +02:00
data : $tmp . serialize ( ) ,
success : function ( ) {
2020-07-13 12:19:11 +02:00
showMessage ( 'success' , 'Homepage set.' ) ;
$ ( '#setHomePage' ) . addClass ( 'orange' ) ;
} ,
} ) ;
}
2020-03-01 18:05:21 +01:00
} ) ;
}
2020-03-12 11:10:11 +01:00
2021-03-20 15:33:07 +01:00
$ ( document . body ) . on ( 'dblclick' , '.dblclickElement' , function ( ) {
var href = $ ( this ) . closest ( 'tr' ) . find ( '.dblclickActionElement' ) . attr ( 'href' ) ;
2020-03-12 11:10:11 +01:00
window . location = href ;
2021-03-20 15:33:07 +01:00
} ) ;
2020-05-13 11:09:48 +02:00
function loadClusterRelations ( clusterId ) {
if ( clusterId !== undefined ) {
openGenericModal (
baseurl + '/GalaxyClusters/viewRelationTree/' + clusterId ,
{
header : "Cluster relation tree" ,
classes : "modal-xl" ,
bodyStyle : { "min-height" : "700px" }
} ,
function ( ) {
if ( window . buildTree !== undefined ) {
buildTree ( ) ;
}
}
) ;
}
2020-07-07 08:16:46 +02:00
}
2020-11-09 10:07:43 +01:00
2024-01-24 21:48:53 +01:00
function submitGenericFormInPlace ( callback , forceApi = false ) {
2020-12-22 17:42:29 +01:00
var $genericForm = $ ( '.genericForm' ) ;
2024-01-24 21:48:53 +01:00
ajaxOptions = { }
if ( forceApi ) {
ajaxOptions [ 'headers' ] = { Accept : "application/json" }
}
$ . ajax ( Object . assign ( { } , {
2020-10-20 01:51:45 +02:00
type : "POST" ,
2020-12-22 17:42:29 +01:00
url : $genericForm . attr ( 'action' ) ,
data : $genericForm . serialize ( ) , // serializes the form's elements.
success : function ( data ) {
if ( typeof data === "object" && data . hasOwnProperty ( 'redirect' ) ) {
window . location = data . redirect ;
return ;
}
2022-10-11 08:01:49 +02:00
if ( callback ) {
callback ( data )
}
2020-12-22 17:42:29 +01:00
$ ( '#genericModal' ) . modal ( 'hide' ) . remove ( ) ;
2020-10-20 01:51:45 +02:00
$ ( 'body' ) . append ( data ) ;
$ ( '#genericModal' ) . modal ( ) ;
2021-02-27 11:13:47 +01:00
} ,
error : xhrFailCallback ,
2024-01-24 21:48:53 +01:00
} , ajaxOptions ) ) ;
2020-10-20 01:51:45 +02:00
}
2020-10-20 02:01:21 +02:00
2020-09-17 10:33:44 +02:00
function openIdSelection ( clicked , scope , action ) {
var onclick = 'redirectIdSelection(\'' + scope + '\', \'' + action + '\')'
var html = '<div class="input-append">'
2020-09-18 08:24:15 +02:00
+ '<input class="span2" id="eventIdSelectionInput" type="number" min="1" step="1" placeholder="42">'
2020-09-17 10:33:44 +02:00
+ '<button class="btn btn-primary" type="button" onclick="' + onclick + '">Submit</button>'
+ '</div>' ;
openPopover ( clicked , html , false , 'right' )
}
function redirectIdSelection ( scope , action ) {
var id = $ ( '#eventIdSelectionInput' ) . val ( )
2020-09-18 08:24:15 +02:00
if ( id . length > 0 ) {
window . location = baseurl + '/' + scope + '/' + action + '/' + id
} else {
showMessage ( 'fail' , 'Not an valid event id' ) ;
}
2020-09-17 10:33:44 +02:00
}
2020-10-01 10:38:28 +02:00
2022-11-21 13:29:35 +01:00
$ ( document . body ) . on ( 'click' , '.populateActionTrigger' , function ( ) {
var populate _script = $ ( this ) . data ( 'request-script' ) ;
populate _script = atob ( populate _script ) ;
populate _script = populate _script . replace ( /\{\{[A-Za-z0-9#_]*\}\}/gi , function ( fieldName ) {
fieldName = fieldName . substring ( 2 , fieldName . length - 2 ) ;
if ( $ ( fieldName ) . is ( 'input' ) ) {
return $ ( fieldName ) . val ( ) ;
} else {
//fieldName = fieldName.substring(1, fieldName.length);
var toReturn = $ ( fieldName + " option:selected" ) . val ( ) ;
return toReturn ;
}
} ) ;
populate _script = JSON . parse ( populate _script ) ;
var update _target = $ ( this ) . data ( 'update-target' ) ;
$ . ajax ( {
data : JSON . stringify ( populate _script [ 'body' ] ) ,
headers : {
"Accept" : "application/json" ,
"Content-type" : "application/json"
} ,
success : function ( data ) {
if ( typeof ( data ) != 'object' ) {
$ ( '#' + update _target ) . val ( data ) ;
} else {
$ ( '#' + update _target ) . empty ( ) ;
$ ( '#' + update _target ) . append ( $ ( '<option selected disabled hidden>' ) . text ( 'Choose' ) ) ;
$ . each ( data , function ( key , value ) {
$ ( '#' + update _target ) . append ( $ ( '<option>' ) . val ( key ) . text ( value ) ) ;
} ) ;
}
} ,
error : function ( data ) {
showMessage ( 'fail' , data [ 'responseJSON' ] [ 'errors' ] ) ;
} ,
type : populate _script [ 'type' ] ,
url : baseurl + populate _script [ 'uri' ]
} )
} ) ;
2022-03-20 15:18:26 +01:00
$ ( document . body ) . on ( 'click' , '.hex-value-convert' , function ( ) {
2020-09-26 18:26:01 +02:00
var $hexValueSpan = $ ( this ) . parent ( ) . children ( ':first-child' ) ;
var val = $hexValueSpan . text ( ) . trim ( ) ;
if ( ! $hexValueSpan . hasClass ( 'binary-representation' ) ) {
var bin = [ ] ;
val . split ( '' ) . forEach ( function ( entry ) {
var temp = parseInt ( entry , 16 ) . toString ( 2 ) ;
bin . push ( Array ( 5 - ( temp . length ) ) . join ( '0' ) + temp ) ;
} ) ;
bin = bin . join ( ' ' ) ;
$hexValueSpan
. text ( bin )
. attr ( 'data-original-title' , 'Binary representation' )
. addClass ( 'binary-representation' ) ;
if ( $hexValueSpan . attr ( 'title' ) ) {
$hexValueSpan . attr ( 'title' , 'Binary representation' ) ;
}
$ ( this )
. attr ( 'data-original-title' , 'Switch to hexadecimal representation' )
. attr ( 'aria-label' , 'Switch to hexadecimal representation' ) ;
} else {
var hex = '' ;
val . split ( ' ' ) . forEach ( function ( entry ) {
hex += parseInt ( entry , 2 ) . toString ( 16 ) . toUpperCase ( ) ;
} ) ;
$hexValueSpan
. text ( hex )
. attr ( 'data-original-title' , 'Hexadecimal representation' )
. removeClass ( 'binary-representation' ) ;
if ( $hexValueSpan . attr ( 'title' ) ) {
$hexValueSpan . attr ( 'title' , 'Hexadecimal representation' ) ;
}
$ ( this )
. attr ( 'data-original-title' , 'Switch to binary representation' )
. attr ( 'aria-label' , 'Switch to binary representation' ) ;
}
} ) ;
2020-12-18 19:30:59 +01:00
2020-12-18 22:56:49 +01:00
// Tag popover with taxonomy description
2020-12-18 19:30:59 +01:00
( function ( ) {
var tagDataCache = { } ;
function fetchTagInfo ( tagId , callback ) {
if ( tagId in tagDataCache ) {
callback ( tagDataCache [ tagId ] ) ;
return ;
}
$ . ajax ( {
success : function ( data ) {
data = $ . parseJSON ( data ) ;
var tagData ;
for ( var i = 0 ; i < data . length ; i ++ ) {
var tag = data [ i ] ;
if ( tag . Tag . id == tagId ) {
tagData = data [ i ]
break ;
}
}
if ( tagData !== undefined ) {
callback ( tagData ) ;
tagDataCache [ tagId ] = tagData ;
}
} ,
type : "get" ,
url : baseurl + "/tags/search/" + tagId + "/1/1"
} )
}
function constructTaxonomyInfo ( tagData ) {
var predicateText = tagData . TaxonomyPredicate . expanded ;
if ( tagData . TaxonomyPredicate . TaxonomyEntry ) {
predicateText += ": " + tagData . TaxonomyPredicate . TaxonomyEntry [ 0 ] . expanded ;
}
var $predicate = $ ( '<div/>' ) . append (
$ ( '<h3/>' ) . css ( "margin-top" , "5px" ) . text ( 'Tag info' ) ,
$ ( '<p/>' ) . css ( "margin-bottom" , "5px" ) . text ( predicateText )
) ;
if ( tagData . TaxonomyPredicate . description ) {
$predicate . append ( $ ( '<p/>' ) . css ( "margin-bottom" , "5px" ) . append (
$ ( '<strong/>' ) . text ( 'Description: ' ) ,
2021-02-23 14:51:48 +01:00
$ ( '<span/>' ) . text ( tagData . TaxonomyPredicate . description )
2020-12-18 19:30:59 +01:00
) ) ;
}
if ( tagData . TaxonomyPredicate . TaxonomyEntry && tagData . TaxonomyPredicate . TaxonomyEntry [ 0 ] . numerical _value ) {
$predicate . append ( $ ( '<p/>' ) . css ( "margin-bottom" , "5px" ) . append (
$ ( '<strong/>' ) . text ( 'Numerical value: ' ) ,
2021-02-23 14:51:48 +01:00
$ ( '<span/>' ) . text ( tagData . TaxonomyPredicate . TaxonomyEntry [ 0 ] . numerical _value )
2020-12-18 19:30:59 +01:00
) ) ;
}
var $meta = $ ( '<div/>' ) . append (
$ ( '<h3/>' ) . text ( 'Taxonomy: ' + tagData . Taxonomy . namespace . toUpperCase ( ) ) ,
$ ( '<p/>' ) . css ( "margin-bottom" , "5px" ) . append (
2021-02-23 14:51:48 +01:00
$ ( '<span/>' ) . text ( tagData . Taxonomy . description )
2020-12-18 19:30:59 +01:00
)
)
return $ ( '<div/>' ) . append ( $predicate , $meta )
}
var popoverDebounce = null ;
$ ( document . body ) . on ( {
mouseover : function ( ) {
var $tag = $ ( this ) ;
popoverDebounce = setTimeout ( function ( ) {
popoverDebounce = null ;
var tagId = $tag . data ( 'tag-id' ) ;
fetchTagInfo ( tagId , function ( tagData ) {
if ( tagData . TaxonomyPredicate === undefined ) {
return ;
}
// Check if user cursor is still on tag
if ( $ ( ':hover' ) . last ( ) [ 0 ] !== $tag [ 0 ] ) {
return ;
}
$tag . popover ( {
html : true ,
container : 'body' ,
placement : 'top' ,
template : '<div class="popover"><div class="arrow"></div><div class="popover-content"></div></div>' ,
content : function ( ) {
return constructTaxonomyInfo ( tagData ) ;
}
} ) . popover ( 'show' ) ;
} ) ;
} , 200 ) ;
} ,
mouseout : function ( ) {
if ( popoverDebounce ) {
clearTimeout ( popoverDebounce ) ;
popoverDebounce = null ;
}
$ ( this ) . popover ( 'destroy' ) ;
}
} , 'a.tag[data-tag-id]' ) ;
} ) ( ) ;
2021-02-11 12:41:03 +01:00
// Highlight column for roles table
$ ( 'td.rotate' ) . hover ( function ( ) {
var $table = $ ( this ) . closest ( 'table' ) ;
var t = parseInt ( $ ( this ) . index ( ) ) + 1 ;
$table . find ( 'td:nth-child(' + t + ')' ) . css ( 'background-color' , '#CFEFFF' ) ;
} , function ( ) {
var $table = $ ( this ) . closest ( 'table' ) ;
var t = parseInt ( $ ( this ) . index ( ) ) + 1 ;
$table . find ( 'td:nth-child(' + t + ')' ) . css ( 'background-color' , '' ) ;
} ) ;
2022-08-03 11:45:17 +02:00
function enableWorkflowDebugMode ( workflow _id , currentEnabledState , callback ) {
var enabled = currentEnabledState ? false : true
var url = baseurl + '/workflows/debugToggleField/' + workflow _id + '/' + ( enabled ? '1' : '0' )
fetchFormDataAjax ( url , function ( formData ) {
var $formData = $ ( formData ) ;
$ . ajax ( {
data : $formData . find ( 'form' ) . serialize ( ) ,
beforeSend : function ( ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data ) {
showMessage ( 'success' , data . message ) ;
if ( callback ) {
callback ( data )
}
} ,
error : function ( ) {
showMessage ( 'fail' , 'Could not toggle debug mode.' ) ;
} ,
complete : function ( ) {
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( ".loading" ) . hide ( ) ;
} ,
type : "post" ,
url : $formData . find ( 'form' ) . attr ( 'action' )
} ) ;
} ) ;
2022-11-12 20:33:00 +01:00
}
// Used in audit and access logs
function filterSearch ( callback ) {
$ ( 'td[data-search]' ) . mouseenter ( function ( ) {
var $td = $ ( this ) ;
var searchValue = $td . data ( 'search-value' ) ;
if ( searchValue . length === 0 ) {
return ;
}
$td . find ( '#quickEditButton' ) . remove ( ) ; // clean all similar if exist
var $div = $ ( '<div id="quickEditButton"></div>' ) ;
$div . addClass ( 'quick-edit-row-div' ) ;
var $span = $ ( '<span></span>' ) ;
$span . addClass ( 'fa-as-icon fa fa-search-plus' ) ;
$span . css ( 'font-size' , '12px' ) ;
$span . prop ( 'title' , 'Filter by this value' ) ;
$div . append ( $span ) ;
$td . append ( $div ) ;
$span . click ( function ( e ) {
var searchKey = $td . data ( 'search' ) ;
callback ( e , searchKey , searchValue ) ;
} ) ;
$td . off ( 'mouseleave' ) . on ( 'mouseleave' , function ( ) {
$div . remove ( ) ;
} ) ;
} ) ;
2022-08-03 11:45:17 +02:00
}