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 ;
} ;
}
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 ) {
if ( xhr . status === 403 ) {
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.' ) ;
}
}
function deleteObject ( type , action , id ) {
2020-08-16 13:31:31 +02:00
var url = baseurl + "/" + type + "/" + action + "/" + id ;
2019-02-13 08:46:18 +01:00
$ . get ( url , function ( data ) {
openPopup ( "#confirmation_box" ) ;
$ ( "#confirmation_box" ) . html ( data ) ;
2020-07-14 12:34:29 +02:00
} ) . 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 ) {
2020-08-16 13:31:31 +02:00
url = baseurl + "/sightings/quickDelete/" + id + "/" + rawId + "/" + context ;
2019-02-13 08:46:18 +01:00
$ . get ( url , function ( data ) {
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
2020-07-14 12:34:29 +02:00
} ) . 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" ;
}
2019-02-13 08:46:18 +01:00
$ . get ( url , function ( data ) {
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
} ) ;
2018-10-30 17:14:42 +01:00
}
2020-10-05 20:38:58 +02:00
function flexibleAddSighting ( clicked , type , attribute _id , event _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>'
2020-10-05 20:38:58 +02:00
+ '<button class="btn btn-primary" onclick="addSighting(\'' + type + '\', \'' + attribute _id + '\', \'' + event _id + '\')">This attribute</button>'
+ '<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
}
2017-04-13 16:31:48 +02:00
function publishPopup ( id , type ) {
2019-02-13 08:46:18 +01:00
var action = "alert" ;
if ( type == "publish" ) action = "publish" ;
2019-01-17 08:27:16 +01:00
if ( type == "unpublish" ) action = "unpublish" ;
2019-11-25 16:21:42 +01:00
if ( type == "sighting" ) action = "publishSightings" ;
2019-02-13 08:46:18 +01:00
var destination = 'attributes' ;
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/events/" + action + "/" + id , function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
} ) ;
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 ) ;
2020-06-05 18:05:40 +02: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 ( ) ;
}
} ) ;
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 ) ;
}
2020-09-27 10:59:26 +02:00
var popupHtml = '<it class="fa fa-spin fa-spinner" style="font-size: xx-large; color: white; position: fixed; left: 50%; top: 50%;"></it>' ;
2019-05-07 09:01:05 +02:00
url = $ ( '<div>' ) . text ( url ) . html ( ) ;
title = $ ( '<div>' ) . text ( title ) . html ( ) ;
2019-03-18 10:31:09 +01:00
popupHtml += '<img class="screenshot_box-content hidden" src="' + url + '" id="screenshot-image" title="' + title + '" alt="' + title + '" onload="$(this).show(); $(this).parent().find(\'.fa-spinner\').remove();"/>' ;
2019-02-13 08:46:18 +01:00
popupHtml += '<div class="close-icon useCursorPointer" onClick="closeScreenshot();"></div>' ;
2019-03-28 15:35:10 +01:00
if ( ! url . startsWith ( 'data:image/' ) ) {
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-13 15:57:52 +01:00
popupHtml += '<div style="height: 20px;"></div>' ; // see bottom of image for large one
2019-02-13 08:46:18 +01:00
$ ( '#screenshot_box' ) . html ( popupHtml ) ;
2019-03-13 15:57:52 +01:00
$ ( '#screenshot_box' ) . css ( {
display : 'block' ,
top : ( document . documentElement . scrollTop + 100 ) + 'px'
} ) ;
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 submitPublish ( id , type ) {
2019-02-13 08:46:18 +01:00
$ ( "#PromptForm" ) . submit ( ) ;
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 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-09-15 17:12:49 +02:00
$ ( "#popover_form" ) . fadeOut ( ) ;
2019-02-13 08:46:18 +01:00
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( "#confirmation_box" ) . empty ( ) ;
$ ( '.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 ( ) ;
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
data : formData ,
success : function ( data , textStatus ) {
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 ( ) ;
} ,
type : "post" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/" + 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 ( ) ;
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
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 ) ;
} ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#confirmation_box" ) . fadeOut ( ) ;
} ,
type : "post" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/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 ) {
case 'warninglist_enable' :
formID = '#WarninglistIndexForm' ;
dataDiv = '#WarninglistData' ;
2020-08-17 17:13:58 +02:00
replacementForm = baseurl + '/warninglists/getToggleField/' ;
2019-02-13 08:46:18 +01:00
searchString = 'enabled' ;
break ;
case 'favourite_tag' :
formID = '#FavouriteTagIndexForm' ;
dataDiv = '#FavouriteTagData' ;
2020-08-17 17:13:58 +02:00
replacementForm = baseurl + '/favourite_tags/getToggleField/' ;
2019-02-13 08:46:18 +01:00
searchString = 'Adding' ;
break ;
case 'activate_object_template' :
formID = '#ObjectTemplateIndexForm' ;
dataDiv = '#ObjectTemplateData' ;
2020-08-17 17:13:58 +02:00
replacementForm = baseurl + '/ObjectTemplates/getToggleField/' ;
2019-02-13 08:46:18 +01:00
searchString = 'activated' ;
break ;
case 'noticelist_enable' :
formID = '#NoticelistIndexForm' ;
dataDiv = '#NoticelistData' ;
2020-08-17 17:13:58 +02:00
replacementForm = baseurl + '/noticelists/getToggleField/' ;
2019-02-13 08:46:18 +01:00
searchString = 'enabled' ;
break ;
}
$ ( dataDiv ) . val ( id ) ;
var formData = $ ( formID ) . serialize ( ) ;
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
data : formData ,
success : function ( data , textStatus ) {
var result = data ;
if ( result . success ) {
var setting = false ;
if ( result . success . indexOf ( searchString ) > - 1 ) setting = true ;
$ ( '#checkBox_' + id ) . prop ( 'checked' , setting ) ;
}
handleGenericAjaxResponse ( data ) ;
} ,
complete : function ( ) {
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + replacementForm , function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( '#hiddenFormDiv' ) . html ( data ) ;
} ) ;
$ ( ".loading" ) . hide ( ) ;
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
} ,
error : function ( ) {
handleGenericAjaxResponse ( { 'saved' : false , 'errors' : [ 'Request failed due to an unexpected error.' ] } ) ;
} ,
type : "post" ,
cache : false ,
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 ) {
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/users/initiatePasswordReset/" + id , function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
} ) ;
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 ( ) ;
2020-08-16 13:31:31 +02:00
var url = baseurl + "/users/initiatePasswordReset/" + id ;
2019-02-13 08:46:18 +01:00
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
data : formData ,
success : function ( data , textStatus ) {
handleGenericAjaxResponse ( data ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
} ,
type : "post" ,
cache : false ,
url : url ,
} ) ;
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 submitMessageForm ( url , form , target ) {
2019-02-13 08:46:18 +01:00
if ( ! $ ( '#PostMessage' ) . val ( ) ) {
showMessage ( "fail" , "Cannot submit empty message." ) ;
} else {
submitGenericForm ( url , form , target ) ;
}
2017-04-13 16:31:48 +02:00
}
2016-06-20 19:11:39 +02:00
2017-04-13 16:31:48 +02:00
function submitGenericForm ( url , form , target ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
data : $ ( '#' + form ) . serialize ( ) ,
success : function ( data , textStatus ) {
$ ( '#top' ) . html ( data ) ;
showMessage ( "success" , "Message added." ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
2020-07-24 15:26:09 +02:00
error : xhrFailCallback ,
2019-02-13 08:46:18 +01:00
type : "post" ,
cache : false ,
url : url ,
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-06-20 19:11:39 +02:00
2017-04-13 16:31:48 +02:00
function acceptObject ( type , id , event ) {
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 ,
2020-08-14 13:40:05 +02:00
success : function ( data , textStatus ) {
2019-02-13 08:46:18 +01:00
updateIndex ( event , 'event' ) ;
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 ;
}
2019-02-13 08:46:18 +01:00
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
data : $ ( '#PromptForm' ) . serialize ( ) ,
success : function ( data , textStatus ) {
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" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + '/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 ;
}
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
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" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + '/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
2017-04-13 16:31:48 +02:00
function updateIndex ( id , context , newPage ) {
2019-02-13 08:46:18 +01:00
if ( typeof newPage !== 'undefined' ) page = newPage ;
var url , div ;
if ( context == 'event' ) {
if ( typeof currentUri == 'undefined' ) {
location . reload ( ) ;
return true ;
}
url = currentUri ;
div = "#attributes_div" ;
}
if ( context == 'template' ) {
2020-08-16 13:31:31 +02:00
url = baseurl + "/template_elements/index/" + id ;
2019-02-13 08:46:18 +01:00
div = "#templateElements" ;
}
$ . ajax ( {
2020-10-15 19:20:43 +02:00
beforeSend : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . show ( ) ;
} ,
dataType : "html" ,
cache : false ,
success : function ( data , textStatus ) {
$ ( ".loading" ) . hide ( ) ;
$ ( div ) . html ( data ) ;
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
2017-04-13 16:31:48 +02:00
function updateAttributeFieldOnSuccess ( name , type , id , field , event ) {
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 ( ) ;
}
} ,
dataType : "html" ,
cache : false ,
success : function ( data , textStatus ) {
2020-10-15 20:20:44 +02:00
if ( field !== 'timestamp' ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . hide ( ) ;
$ ( name + '_solid' ) . html ( data ) ;
$ ( name + '_placeholder' ) . empty ( ) ;
$ ( name + '_solid' ) . show ( ) ;
} else {
$ ( '#' + type + '_' + id + '_' + 'timestamp_solid' ) . html ( data ) ;
}
2020-10-15 20:20:44 +02:00
popoverStartup ( ) ; // reactive popovers
2019-02-13 08:46:18 +01:00
} ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/attributes/fetchViewValue/" + 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
2019-06-13 09:16:34 +02:00
function updateObjectFieldOnSuccess ( name , type , id , field , event ) {
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
if ( field != 'timestamp' ) {
$ ( ".loading" ) . show ( ) ;
}
} ,
dataType : "html" ,
cache : false ,
success : function ( data , textStatus ) {
if ( field != 'timestamp' ) {
$ ( ".loading" ) . hide ( ) ;
$ ( name + '_solid' ) . html ( data ) ;
$ ( name + '_placeholder' ) . empty ( ) ;
$ ( name + '_solid' ) . show ( ) ;
} else {
$ ( '#' + type + '_' + id + '_' + 'timestamp_solid' ) . html ( data ) ;
}
} ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/objects/fetchViewValue/" + id + "/" + field ,
2019-06-13 09:16:34 +02:00
} ) ;
}
2017-04-13 16:31:48 +02:00
function activateField ( type , id , field , event ) {
2019-02-13 08:46:18 +01:00
resetForms ( ) ;
2020-10-15 09:48:45 +02:00
if ( type === 'denyForm' ) {
return ;
}
var objectType , containerName ;
if ( type === 'Object' ) {
2019-06-13 09:16:34 +02:00
objectType = 'objects' ;
containerName = 'Object' ;
2020-10-15 09:48:45 +02:00
} else {
objectType = 'attributes' ;
containerName = 'Attribute' ;
2019-02-13 08:46:18 +01:00
}
var name = '#' + type + '_' + id + '_' + field ;
2019-06-13 10:53:34 +02:00
var container _name = '#' + containerName + '_' + id + '_' + field ;
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2020-10-15 09:48:45 +02:00
beforeSend : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . show ( ) ;
} ,
2020-10-15 09:48:45 +02:00
dataType : "html" ,
2019-02-13 08:46:18 +01:00
cache : false ,
2020-10-15 09:48:45 +02:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( container _name + '_placeholder' ) . html ( data ) ;
postActivationScripts ( name , type , id , field , event ) ;
} ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/" + objectType + "/fetchEditForm/" + id + "/" + field ,
2020-10-15 09:48:45 +02:00
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
error : xhrFailCallback
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-17 11:44:40 +02:00
2017-04-13 16:31:48 +02:00
function submitQuickTag ( form ) {
2019-02-13 08:46:18 +01:00
$ ( '#' + form ) . submit ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-11-24 03:27:14 +01: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
2017-04-13 16:31:48 +02:00
function postActivationScripts ( name , type , id , field , event ) {
2019-02-13 08:46:18 +01:00
$ ( name + '_field' ) . focus ( ) ;
inputFieldButtonActive ( name + '_field' ) ;
if ( field == 'value' || field == 'comment' ) {
autoresize ( $ ( name + '_field' ) [ 0 ] ) ;
$ ( name + '_field' ) . on ( 'keyup' , function ( ) {
autoresize ( this ) ;
} ) ;
}
$ ( name + '_form' ) . submit ( function ( e ) {
e . preventDefault ( ) ;
submitForm ( type , id , field , event ) ;
return false ;
} ) ;
$ ( name + '_form' ) . bind ( "focusout" , function ( ) {
inputFieldButtonPassive ( name + '_field' ) ;
} ) ;
$ ( name + '_form' ) . bind ( "focusin" , function ( ) {
inputFieldButtonActive ( name + '_field' ) ;
} ) ;
$ ( name + '_field' ) . closest ( '.inline-input-container' ) . children ( '.inline-input-accept' ) . bind ( 'click' , function ( ) {
submitForm ( type , id , field , event ) ;
} ) ;
$ ( name + '_field' ) . closest ( '.inline-input-container' ) . children ( '.inline-input-decline' ) . bind ( 'click' , function ( ) {
resetForms ( ) ;
} ) ;
$ ( name + '_solid' ) . hide ( ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-17 11:44:40 +02:00
2018-12-12 14:45:18 +01:00
function quickEditHover ( td , type , id , field , event ) {
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 ) ;
2018-12-12 15:38:22 +01:00
$td . find ( "[id*=_solid]" ) . append ( $div ) ;
2018-12-12 14:45:18 +01:00
$span . click ( function ( ) {
activateField ( type , id , field , event ) ;
} ) ;
2018-12-12 15:16:01 +01:00
$td . off ( 'mouseleave' ) . on ( 'mouseleave' , function ( ) {
2018-12-12 14:45:18 +01:00
$div . remove ( ) ;
} ) ;
}
2020-10-05 20:38:58 +02:00
function addSighting ( type , attribute _id , event _id ) {
2019-02-13 08:46:18 +01:00
$ ( '#Sighting_' + attribute _id + '_type' ) . val ( type ) ;
$ . ajax ( {
data : $ ( '#Sighting_' + attribute _id ) . closest ( "form" ) . serialize ( ) ,
cache : false ,
2020-10-05 20:38:58 +02:00
success : function ( data , textStatus ) {
2019-02-13 08:46:18 +01:00
handleGenericAjaxResponse ( data ) ;
var result = data ;
if ( result . saved == true ) {
$ ( '.sightingsCounter' ) . each ( function ( counter ) {
$ ( this ) . html ( parseInt ( $ ( this ) . html ( ) ) + 1 ) ;
} ) ;
2020-10-05 20:38:58 +02:00
updateIndex ( event _id , 'event' ) ;
2019-02-13 08:46:18 +01:00
}
} ,
2020-10-05 20:38:58 +02:00
error : function ( ) {
2019-02-13 08:46:18 +01:00
showMessage ( 'fail' , 'Request failed for an unknown reason.' ) ;
2020-10-05 20:38:58 +02:00
updateIndex ( event _id , 'event' ) ;
2019-02-13 08:46:18 +01:00
} ,
2020-10-05 20:38:58 +02:00
type : "post" ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/sightings/add/" + attribute _id
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-12-20 13:41:52 +01:00
2017-04-13 16:31:48 +02:00
function resetForms ( ) {
2019-02-13 08:46:18 +01:00
$ ( '.inline-field-solid' ) . show ( ) ;
$ ( '.inline-field-placeholder' ) . empty ( ) ;
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
2017-04-13 16:31:48 +02:00
function submitForm ( type , id , field , context ) {
2019-02-13 08:46:18 +01:00
var object _type = 'attributes' ;
var action = "editField" ;
var name = '#' + type + '_' + id + '_' + field ;
2020-07-06 09:08:07 +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 ,
success : function ( data , textStatus ) {
handleAjaxEditResponse ( data , name , type , id , field , context ) ;
} ,
error : function ( ) {
showMessage ( 'fail' , 'Request failed for an unknown reason.' ) ;
updateIndex ( context , 'event' ) ;
} ,
type : "post" ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/" + object _type + "/" + action + "/" + id
2019-02-13 08:46:18 +01:00
} ) ;
$ ( name + '_field' ) . unbind ( "keyup" ) ;
$ ( name + '_form' ) . unbind ( "focusout" ) ;
return false ;
2014-04-14 15:13:01 +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' ;
}
2020-08-16 13:31:31 +02:00
url = baseurl + "/events/addTag/" + event _id + localFlag ;
2019-07-08 11:39:41 +02:00
fetchFormDataAjax ( url , function ( formData ) {
2019-06-07 15:25:32 +02:00
$ ( 'body' ) . append ( $ ( '<div id="temp"/>' ) . html ( formData ) ) ;
$ ( '#temp #EventTag' ) . val ( JSON . stringify ( selected _tag _ids ) ) ;
2019-06-07 14:44:39 +02:00
$ . ajax ( {
data : $ ( '#EventAddTagForm' ) . serialize ( ) ,
cache : false ,
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data , textStatus ) {
loadEventTags ( event _id ) ;
loadGalaxies ( event _id , 'event' ) ;
handleGenericAjaxResponse ( data ) ;
} ,
error : function ( ) {
showMessage ( 'fail' , 'Could not add tag.' ) ;
loadEventTags ( event _id ) ;
loadGalaxies ( event _id , 'event' ) ;
} ,
complete : function ( ) {
2019-06-07 15:25:32 +02:00
$ ( '#temp' ) . remove ( ) ;
2019-06-07 14:44:39 +02:00
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( ".loading" ) . hide ( ) ;
2019-06-07 15:25:32 +02:00
$ ( '#temp' ) . remove ( ) ;
2019-06-07 14:44:39 +02:00
} ,
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
}
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' ;
}
2020-08-16 13:31:31 +02:00
url = baseurl + "/attributes/addTag/" + attribute _id + localFlag ;
2019-07-08 11:39:41 +02:00
fetchFormDataAjax ( url , function ( formData ) {
2019-06-07 15:25:32 +02:00
$ ( 'body' ) . append ( $ ( '<div id="temp"/>' ) . html ( formData ) ) ;
$ ( '#temp #AttributeTag' ) . val ( JSON . stringify ( selected _tag _ids ) ) ;
2019-06-07 14:44:39 +02:00
if ( attribute _id == 'selected' ) {
$ ( '#AttributeAttributeIds' ) . val ( getSelected ( ) ) ;
}
$ . ajax ( {
data : $ ( '#AttributeAddTagForm' ) . serialize ( ) ,
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data , textStatus ) {
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 ( ) ;
2019-06-07 15:25:32 +02:00
$ ( '#temp' ) . remove ( ) ;
2019-06-07 14:44:39 +02:00
} ,
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' ;
}
2020-08-16 13:31:31 +02:00
url = baseurl + "/tag_collections/addTag/" + tag _collection _id + localFlag ;
2019-07-08 11:39:41 +02:00
fetchFormDataAjax ( url , function ( formData ) {
2019-06-07 15:25:32 +02:00
$ ( 'body' ) . append ( $ ( '<div id="temp"/>' ) . html ( formData ) ) ;
$ ( '#temp #TagCollectionTag' ) . val ( JSON . stringify ( selected _tag _ids ) ) ;
2019-06-07 14:44:39 +02:00
$ . ajax ( {
data : $ ( '#TagCollectionAddTagForm' ) . serialize ( ) ,
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data , textStatus ) {
handleGenericAjaxResponse ( data ) ;
refreshTagCollectionRow ( tag _collection _id ) ;
} ,
error : function ( ) {
showMessage ( 'fail' , 'Could not add tag.' ) ;
loadTagCollectionTags ( tag _collection _id ) ;
} ,
complete : function ( ) {
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( ".loading" ) . hide ( ) ;
2019-06-07 15:25:32 +02:00
$ ( '#temp' ) . remove ( ) ;
2019-06-07 14:44:39 +02:00
} ,
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.' ) ;
} ,
success : function ( data , textStatus ) {
$ ( '[data-row-id="' + tag _collection _id + '"]' ) . replaceWith ( data ) ;
}
} ) ;
}
2017-04-13 16:31:48 +02:00
function handleAjaxEditResponse ( data , name , type , id , field , event ) {
2019-02-13 08:46:18 +01:00
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 ) ;
2019-02-13 08:46:18 +01:00
updateAttributeFieldOnSuccess ( name , type , id , field , event ) ;
updateAttributeFieldOnSuccess ( name , type , id , 'timestamp' , event ) ;
eventUnpublish ( ) ;
} else {
showMessage ( 'fail' , 'Validation failed: ' + responseArray . errors . value ) ;
updateAttributeFieldOnSuccess ( name , type , id , field , event ) ;
}
2020-10-18 13:35:16 +02:00
} else if ( type === 'ShadowAttribute' ) {
2019-02-13 08:46:18 +01:00
updateIndex ( event , '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 ) ;
2019-06-13 09:16:34 +02:00
updateObjectFieldOnSuccess ( name , type , id , field , event ) ;
updateObjectFieldOnSuccess ( name , type , id , 'timestamp' , event ) ;
eventUnpublish ( ) ;
} else {
showMessage ( 'fail' , 'Validation failed: ' + responseArray . errors . value ) ;
updateObjectFieldOnSuccess ( name , type , id , field , event ) ;
}
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" ) ) {
$ ( ".select_attribute" ) . prop ( "checked" , true ) ;
$ ( ".select_proposal" ) . prop ( "checked" , true ) ;
} else {
$ ( ".select_attribute" ) . prop ( "checked" , false ) ;
$ ( ".select_proposal" ) . prop ( "checked" , false ) ;
}
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 ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '.select_attribute:checked' ) . length > 0 ) $ ( '.mass-select' ) . removeClass ( 'hidden' ) ;
else $ ( '.mass-select' ) . addClass ( 'hidden' ) ;
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 ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '.select:checked' ) . length > 0 ) $ ( '.mass-select' ) . removeClass ( 'hidden' ) ;
else $ ( '.mass-select' ) . 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 = [ ] ;
$ ( ".select" ) . each ( function ( ) {
if ( $ ( this ) . is ( ":checked" ) ) {
var temp = $ ( this ) . data ( "id" ) ;
if ( temp != null ) {
selected . push ( temp ) ;
}
}
} ) ;
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/events/delete/" + JSON . stringify ( selected ) , function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
} ) ;
2017-06-01 09:45:10 +02:00
}
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 ) ;
}
}
} ) ;
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/feeds/toggleSelected/" + on + "/" + cache + "/" + JSON . stringify ( selected ) , function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
} ) ;
2018-01-15 17:25:11 +01:00
}
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 ) ;
}
}
} ) ;
2020-09-07 18:14:01 +02:00
$ . get ( baseurl + "/eventBlocklists/massDelete?ids=" + JSON . stringify ( selected ) , function ( data ) {
2019-06-12 15:27:39 +02:00
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
} ) ;
}
2017-04-13 16:31:48 +02:00
function multiSelectAction ( event , 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 = [ ] ;
$ ( ".select_" + settings [ context ] [ "alias" ] ) . each ( function ( ) {
if ( $ ( this ) . is ( ":checked" ) ) {
var temp = $ ( this ) . data ( "id" ) ;
selected . push ( temp ) ;
}
} ) ;
$ ( '#' + 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 {
2020-08-16 13:31:31 +02:00
var url = baseurl + "/" + settings [ context ] [ "controller" ] + "/" + settings [ context ] [ "action" ] + "Selected/" + event ;
2019-02-13 08:46:18 +01:00
}
$ . ajax ( {
data : formData ,
cache : false ,
type : "POST" ,
url : url ,
2020-10-15 19:20:43 +02:00
beforeSend : function ( ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data ) {
2019-02-13 08:46:18 +01:00
updateIndex ( event , 'event' ) ;
var result = handleGenericAjaxResponse ( data ) ;
2020-10-15 19:20:43 +02:00
if ( settings [ context ] [ "action" ] != "discard" && result == true ) {
eventUnpublish ( ) ;
}
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
2019-02-13 08:46:18 +01:00
} ,
2020-10-15 19:20:43 +02:00
error : xhrFailCallback ,
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 ) {
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/taxonomies/taxonomyMassConfirmation/" + taxonomy , function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
} ) ;
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' ) ;
}
2018-09-10 12:53:33 +02:00
function hideSelectedTags ( taxonomy ) {
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/taxonomies/taxonomyMassHide/" + taxonomy , function ( data ) {
2018-09-10 12:53:33 +02:00
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
} ) ;
}
function unhideSelectedTags ( taxonomy ) {
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/taxonomies/taxonomyMassUnhide/" + taxonomy , function ( data ) {
2018-09-10 12:53:33 +02:00
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
} ) ;
}
2017-04-13 16:31:48 +02:00
function submitMassTaxonomyTag ( ) {
2019-02-13 08:46:18 +01:00
$ ( '#PromptForm' ) . submit ( ) ;
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 submitMassEventDelete ( ) {
2019-02-13 08:46:18 +01:00
$ ( '#PromptForm' ) . trigger ( 'submit' ) ;
event . preventDefault ( ) ;
2017-06-01 09:45:10 +02:00
}
2017-04-13 16:31:48 +02:00
function getSelected ( ) {
2019-02-13 08:46:18 +01:00
var selected = [ ] ;
$ ( ".select_attribute" ) . each ( function ( ) {
if ( $ ( this ) . is ( ":checked" ) ) {
var test = $ ( this ) . data ( "id" ) ;
selected . push ( test ) ;
}
} ) ;
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 ( {
dataType : "html" ,
cache : false ,
success : function ( data , textStatus ) {
$ ( ".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 ,
success : function ( data , textStatus ) {
2019-01-05 05:03:04 +01:00
if ( scope == 'event' ) {
2019-02-13 08:46:18 +01:00
$ ( "#galaxies_div" ) . html ( data ) ;
2019-01-06 17:04:10 +01: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
}
2018-12-20 21:48:04 +01:00
function loadTagCollectionTags ( id ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
dataType : "html" ,
cache : false ,
success : function ( data , textStatus ) {
$ ( ".tagCollectionTagContainer" ) . html ( data ) ;
} ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/tags/showEventTag/" + id ,
2019-02-13 08:46:18 +01:00
} ) ;
2018-12-20 21:48:04 +01:00
}
2017-04-13 16:31:48 +02:00
function removeEventTag ( event , tag ) {
2019-02-13 08:46:18 +01:00
var answer = confirm ( "Are you sure you want to remove this tag from the event?" ) ;
if ( answer ) {
var formData = $ ( '#removeTag_' + tag ) . serialize ( ) ;
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
data : formData ,
type : "POST" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/events/removeTag/" + event + '/' + tag ,
2019-02-13 08:46:18 +01:00
success : function ( data , textStatus ) {
loadEventTags ( event ) ;
handleGenericAjaxResponse ( data ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
}
} ) ;
}
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 loadAttributeTags ( id ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
dataType : "html" ,
cache : false ,
success : function ( data , textStatus ) {
$ ( "#Attribute_" + id + "_tr .attributeTagContainer" ) . html ( data ) ;
} ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/tags/showAttributeTag/" + 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 ) ;
} ) ;
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 ( ) ;
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
data : formData ,
type : "POST" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/" + context . toLowerCase ( ) + "s/removeTag/" + object + '/' + tag ,
2019-02-13 08:46:18 +01:00
success : function ( data , textStatus ) {
$ ( "#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 ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
}
} ) ;
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
}
2017-04-13 16:31:48 +02:00
function clickCreateButton ( event , type ) {
2019-02-13 08:46:18 +01:00
var destination = 'attributes' ;
if ( type == 'Proposal' ) destination = 'shadow_attributes' ;
2020-08-16 13:31:31 +02:00
simplePopup ( baseurl + "/" + destination + "/add/" + event ) ;
2017-04-13 16:31:48 +02:00
}
2014-04-24 15:10:08 +02:00
2019-12-11 10:03:43 +01:00
function openGenericModal ( url ) {
$ . ajax ( {
type : "get" ,
url : url ,
success : function ( data ) {
$ ( '#genericModal' ) . remove ( ) ;
$ ( 'body' ) . append ( data ) ;
$ ( '#genericModal' ) . modal ( ) ;
} ,
error : function ( data , textStatus , errorThrown ) {
showMessage ( 'fail' , textStatus + ": " + errorThrown ) ;
}
} ) ;
}
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 ) {
2019-02-13 08:46:18 +01:00
var url = null ;
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' ) ) {
var $form = $submitButton . parent ( ) . parent ( ) . find ( '.modal-body form' ) ;
2020-08-24 17:20:57 +02:00
url = $form . attr ( 'action' ) ;
2019-12-11 10:03:43 +01:00
} else {
2020-08-24 10:55:22 +02:00
var $form = $submitButton . closest ( "form" ) ;
2020-08-24 17:20:57 +02:00
url = $form . attr ( 'action' ) ;
2019-12-11 10:03:43 +01:00
}
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 ( {
beforeSend : function ( XMLHttpRequest ) {
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 ( ) ,
2020-08-24 10:55:22 +02:00
success : function ( data , textStatus ) {
2019-12-11 10:03:43 +01:00
var result ;
if ( closePopover ) {
if ( modal ) {
result = handleAjaxModalResponse ( data , context _id , url , referer , context , contextNamingConvention ) ;
} else {
2019-02-13 08:46:18 +01:00
result = handleAjaxPopoverResponse ( data , context _id , url , referer , context , contextNamingConvention ) ;
}
2019-12-11 10:03:43 +01:00
}
if ( referer == 'addSighting' ) {
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 ) ;
} ) ;
$ ( '.sightingsToggle' ) . removeClass ( 'btn-primary' ) ;
$ ( '.sightingsToggle' ) . addClass ( 'btn-inverse' ) ;
$ ( '#sightingsListAllToggle' ) . removeClass ( 'btn-inverse' ) ;
$ ( '#sightingsListAllToggle' ) . addClass ( 'btn-primary' ) ;
}
2020-09-16 14:56:13 +02:00
if ( referer == 'addEventReport' && typeof window . reloadEventReportTable === 'function' ) {
2020-09-16 15:08:43 +02:00
context == 'eventReport'
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 (
(
context == 'event' &&
2019-12-16 13:43:07 +01:00
( referer == 'add' || referer == 'massEdit' || referer == 'replaceAttributes' || referer == 'addObjectReference' || referer == 'quickAddAttributeForm' )
)
2019-12-16 13:36:01 +01:00
) {
eventUnpublish ( ) ;
}
2019-12-11 10:03:43 +01:00
} ,
error : function ( jqXHR , textStatus , errorThrown ) {
showMessage ( 'fail' , textStatus + ": " + errorThrown ) ;
} ,
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 ) {
responseArray = response ;
var message = null ;
var result = "fail" ;
if ( responseArray . saved ) {
updateIndex ( context _id , context ) ;
if ( responseArray . success ) {
showMessage ( "success" , responseArray . success ) ;
result = "success" ;
}
if ( responseArray . errors ) {
showMessage ( "fail" , responseArray . errors ) ;
}
} else {
2020-07-30 09:00:46 +02:00
if ( responseArray . errors ) {
showMessage ( "fail" , responseArray . errors ) ;
}
2019-12-11 10:03:43 +01:00
var savedArray = saveValuesForPersistance ( ) ;
$ . ajax ( {
async : true ,
dataType : "html" ,
success : function ( data , textStatus ) {
$ ( '#genericModal' ) . remove ( ) ;
$ ( 'body' ) . append ( data ) ;
$ ( '#genericModal' ) . modal ( ) ;
var error _context = context . charAt ( 0 ) . toUpperCase ( ) + context . slice ( 1 ) ;
handleValidationErrors ( responseArray . errors , context , contextNamingConvention ) ;
result = "success" ;
if ( ! $ . isEmptyObject ( responseArray ) ) {
result = "fail" ;
2019-10-02 14:30:34 +02:00
}
2019-12-11 10:03:43 +01:00
recoverValuesFromPersistance ( savedArray ) ;
2019-09-23 17:44:56 +02:00
} ,
error : function ( jqXHR , textStatus , errorThrown ) {
showMessage ( 'fail' , textStatus + ": " + errorThrown ) ;
} ,
complete : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . hide ( ) ;
} ,
2019-12-11 10:03:43 +01:00
url : url
2019-02-13 08:46:18 +01:00
} ) ;
}
2019-12-11 10:03:43 +01:00
return result ;
}
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 message = null ;
var result = "fail" ;
if ( responseArray . saved ) {
updateIndex ( context _id , context ) ;
if ( responseArray . success ) {
showMessage ( "success" , responseArray . success ) ;
result = "success" ;
}
if ( responseArray . errors ) {
showMessage ( "fail" , responseArray . errors ) ;
}
} else {
var savedArray = saveValuesForPersistance ( ) ;
$ . ajax ( {
async : true ,
dataType : "html" ,
success : function ( data , textStatus ) {
$ ( "#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 ( ) ;
} ,
url : url
} ) ;
}
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 ) ;
$ ( "#" + contextNamingConvention + elementName ) . parent ( ) . addClass ( "error" ) ;
$ ( "#" + contextNamingConvention + elementName ) . parent ( ) . append ( "<div class=\"error-message\">" + responseArray [ k ] + "</div>" ) ;
}
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 ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
dataType : "html" ,
cache : false ,
success : function ( data , textStatus ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#histogram" ) . html ( data ) ;
} ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/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
2017-04-13 16:31:48 +02:00
function showMessage ( success , message , context ) {
2019-02-13 08:46:18 +01:00
if ( typeof context !== "undefined" ) {
$ ( "#ajax_" + success , window . parent . document ) . html ( message ) ;
var duration = 1000 + ( message . length * 40 ) ;
$ ( "#ajax_" + success + "_container" , window . parent . document ) . fadeIn ( "slow" ) ;
$ ( "#ajax_" + success + "_container" , window . parent . document ) . delay ( duration ) . fadeOut ( "slow" ) ;
}
$ ( "#ajax_" + success ) . html ( message ) ;
var duration = 1000 + ( message . length * 40 ) ;
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 ( ) ;
$ ( "#screenshot_box" ) . fadeOut ( ) ;
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
2017-04-13 16:31:48 +02:00
function appendTemplateTag ( selected _id ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
dataType : "html" ,
cache : false ,
success : function ( data , textStatus ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#tags" ) . append ( data ) ;
} ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/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" ,
cache : false ,
success : function ( data , textStatus ) {
handleGenericAjaxResponse ( data ) ;
} ,
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
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 ) ) {
var top _offset = ( ( window _height - popup _height ) / 2 ) - 150 ;
} 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 ) ;
2019-10-08 11:46:22 +02:00
var closeButtonHtml = '<button type="button" class="close" style="margin-left: 5px;" onclick="$('[data-dismissid="' + randomId + '"]').popover(\'hide\');">× </button>' ;
2019-02-13 08:46:18 +01:00
if ( ! $clicked . data ( 'popover' ) ) {
$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 )
2019-02-13 08:46:18 +01:00
. on ( 'shown.bs.popover' , function ( event ) {
var $this = $ ( this ) ;
var title = $this . attr ( 'title' ) ;
var popover = $ ( 'div.popover[data-dismissid="' + randomId + '"]' ) ;
title = title === "" ? $this . attr ( 'data-original-title' ) : title ;
if ( title === "" ) {
title = " " ;
// adjust popover position (title was empty)
var top = popover . offset ( ) . top ;
popover . css ( 'top' , ( top - 17 ) + 'px' ) ;
}
var popoverTitle = popover . find ( 'h3.popover-title' ) ;
popoverTitle . html ( title + closeButtonHtml ) ;
2019-07-03 16:04:36 +02:00
if ( callback !== undefined ) {
callback ( popover ) ;
}
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 ) ;
} ) ;
} else {
$clicked . popover ( 'show' ) ;
}
} else {
2020-10-06 08:28:12 +02:00
$clicked . popover ( 'show' ) ;
2019-02-13 08:46:18 +01:00
}
var popover = $clicked . data ( 'popover' ) ;
if ( data === undefined ) {
return popover
} else if ( popover . options . content !== data ) {
popover . options . content = data ;
$clicked . popover ( 'show' ) ;
2019-02-13 16:19:20 +01:00
return popover ;
2019-02-13 08:46:18 +01:00
}
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 ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
dataType : "html" ,
async : true ,
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
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 ;
var popover = openPopover ( clicked , undefined ) ;
$clicked = $ ( clicked ) ;
// actual request //
$ . ajax ( {
dataType : "html" ,
async : true ,
cache : false ,
success : function ( data , textStatus ) {
if ( popover . options . content !== data ) {
popover . options . content = data ;
$clicked . popover ( 'show' ) ;
}
} ,
2019-12-09 10:17:12 +01:00
error : function ( jqXHR , textStatus , errorThrown ) {
var errorJSON = '' ;
try {
errorJSON = JSON . parse ( jqXHR . responseText ) ;
errorJSON = errorJSON [ 'errors' ] ;
if ( errorJSON === undefined ) {
errorJSON = '' ;
}
} catch ( SyntaxError ) {
// no error provided
}
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
}
2019-01-14 14:30:38 +01:00
// create a confirm popover on the clicked html node.
2019-11-19 18:07:30 +01:00
function popoverConfirm ( clicked , message , placement ) {
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>' ;
popoverContent += '<button id="popoverConfirmOK" class="btn btn-primary" style="margin-right: 5px;" onclick=submitPopover(this)>Yes</button>' ;
2019-02-13 08:46:18 +01:00
popoverContent += '<button class="btn btn-inverse" style="float: right;" onclick=cancelPrompt()>Cancel</button>' ;
popoverContent += '</div>' ;
2019-11-19 18:07:30 +01:00
openPopover ( $clicked , popoverContent , undefined , placement ) ;
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 ( ) ;
}
if ( e . keyCode == 27 ) { // ESC
$clicked . popover ( 'destroy' ) ;
}
} ) ;
2019-01-14 14:30:38 +01:00
}
2019-01-14 16:50:59 +01:00
function submitPopover ( clicked ) {
2019-02-13 08:46:18 +01:00
var $clicked = $ ( clicked ) ;
var $form = $clicked . closest ( 'form' ) ;
if ( $form . length === 0 ) { // popover container is body, submit from original node
var dismissid = $clicked . closest ( 'div.popover' ) . attr ( 'data-dismissid' ) ;
$form = $ ( '[data-dismissid="' + dismissid + '"]' ) . closest ( 'form' ) ;
}
2019-11-19 01:06:41 +01:00
if ( $form . data ( 'ajax' ) ) {
$ . ajax ( {
data : $form . serialize ( ) ,
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data , textStatus ) {
location . reload ( ) ;
} ,
error : function ( ) {
showMessage ( 'fail' , 'Could not perform query.' ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
2019-11-19 18:07:30 +01:00
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( '#temp' ) . remove ( ) ;
2019-11-19 01:06:41 +01:00
} ,
type : "post" ,
url : $form . attr ( 'action' )
} ) ;
} else {
$form . submit ( ) ;
}
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 ( ) ;
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
dataType : "html" ,
async : true ,
cache : false ,
success : function ( data , textStatus ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#popover_form" ) . html ( data ) ;
openPopup ( "#popover_form" ) ;
} ,
error : function ( xhr ) {
$ ( ".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 ,
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
}
2019-08-23 15:32:28 +02:00
function openModal ( heading , body , footer , modal _option , css _container , css _body ) {
var modal _id = 'dynamic_modal_' + new Date ( ) . getTime ( ) ;
var modal _html = '<div id="' + modal _id + '" class="modal hide fade" style="' + ( css _container !== undefined ? css _container : '' ) + '" tabindex="-1" role="dialog" aria-hidden="true">' ;
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 freetextRemoveRow ( id , event _id ) {
2019-02-13 08:46:18 +01:00
$ ( '#row_' + id ) . hide ( ) ;
$ ( '#Attribute' + id + 'Save' ) . attr ( "value" , "0" ) ;
if ( $ ( ".freetext_row:visible" ) . length == 0 ) {
2020-08-16 13:31:31 +02:00
window . location = baseurl + "/events/" + event _id ;
2019-02-13 08:46:18 +01:00
}
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 ) ;
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 ( ) ;
for ( var k in $ ( element ) . data ( ) ) {
if ( k in passedArgsArray ) {
delete ( passedArgsArray [ k ] ) ;
} else {
passedArgsArray [ k ] = dataFields [ k ] ;
}
}
url = here ;
for ( var key in passedArgsArray ) {
url += "/" + key + ":" + passedArgsArray [ key ] ;
}
window . location . href = url ;
}
2019-02-23 12:59:16 +01:00
function runIndexQuickFilter ( preserveParams ) {
2019-02-20 23:02:32 +01:00
if ( ! passedArgsArray ) {
var passedArgsArray = [ ] ;
}
2019-04-01 16:09:24 +02:00
var searchKey = 'searchall' ;
if ( $ ( '#quickFilterField' ) . data ( 'searchkey' ) ) {
searchKey = $ ( '#quickFilterField' ) . data ( 'searchkey' ) ;
}
2019-02-20 23:02:32 +01:00
if ( $ ( '#quickFilterField' ) . val ( ) . trim ( ) . length > 0 ) {
2020-05-14 15:38:07 +02:00
passedArgsArray [ searchKey ] = encodeURIComponent ( $ ( '#quickFilterField' ) . val ( ) . trim ( ) ) ;
2019-02-20 23:02:32 +01:00
}
url = here ;
2019-02-23 12:59:16 +01:00
if ( typeof preserveParams !== "undefined" ) {
url += preserveParams ;
}
2019-02-20 23:02:32 +01:00
for ( var key in passedArgsArray ) {
if ( key !== 'page' ) {
url += "/" + key + ":" + passedArgsArray [ key ] ;
}
}
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 ;
}
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 ) {
2019-02-13 08:46:18 +01:00
text = "" ;
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' ) {
if ( param . data . param1 == "date" ) {
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 ( ) ) ;
2019-02-13 08:46:18 +01:00
if ( val1 != "" ) filtering . date . from = val1 ;
if ( val2 != "" ) filtering . date . until = val2 ;
} 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 ;
if ( fieldName == '#' + context + 'Searchdate' ) {
$ ( fieldName + 'from' ) . show ( ) ;
$ ( fieldName + 'until' ) . show ( ) ;
} else {
$ ( fieldName ) . show ( ) ;
}
if ( simpleFilters . indexOf ( rule ) != - 1 ) {
$ ( '#' + context + 'Searchbool' ) . show ( ) ;
} else $ ( '#' + context + 'Searchbool' ) . hide ( ) ;
$ ( '#addRuleButton' ) . show ( ) ;
$ ( '#addRuleButton' ) . unbind ( "click" ) ;
$ ( '#addRuleButton' ) . 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 = "" ;
} 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 restrictEventViewPagination ( ) {
2019-02-13 08:46:18 +01:00
var showPages = new Array ( ) ;
var start ;
var end ;
var i ;
if ( page < 6 ) {
start = 1 ;
if ( count - page < 6 ) {
end = count ;
} else {
end = page + ( 9 - ( page - start ) ) ;
}
} else if ( count - page < 6 ) {
end = count ;
start = count - 10 ;
} else {
start = page - 5 ;
end = page + 5 ;
}
if ( start > 2 ) {
$ ( "#apage" + start ) . parent ( ) . before ( "<li><a href id='aExpandLeft'>...</a></li>" ) ;
$ ( "#aExpandLeft" ) . click ( function ( ) { expandPagination ( 0 , 0 ) ; return false ; } ) ;
$ ( "#bpage" + start ) . parent ( ) . before ( "<li><a href id='bExpandLeft'>...</a></li>" ) ;
$ ( "#bExpandLeft" ) . click ( function ( ) { expandPagination ( 1 , 0 ) ; return false ; } )
}
if ( end < ( count - 1 ) ) {
$ ( "#apage" + end ) . parent ( ) . after ( "<li><a href id='aExpandRight'>...</a></li>" ) ;
$ ( "#aExpandRight" ) . click ( function ( ) { expandPagination ( 0 , 1 ) ; return false ; } ) ;
$ ( "#bpage" + end ) . parent ( ) . after ( "<li><a href id='bExpandRight'>...</a></li>" ) ;
$ ( "#bExpandRight" ) . click ( function ( ) { expandPagination ( 1 , 1 ) ; return false ; } )
}
for ( i = 1 ; i < ( count + 1 ) ; i ++ ) {
if ( i != 1 && i != count && ( i < start || i > end ) ) {
$ ( "#apage" + i ) . hide ( ) ;
$ ( "#bpage" + i ) . hide ( ) ;
}
}
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 expandPagination ( bottom , right ) {
2019-02-13 08:46:18 +01:00
var i ;
var prefix = "a" ;
if ( bottom == 1 ) prefix = "b" ;
var start = 1 ;
var end = page ;
if ( right == 1 ) {
start = page ;
end = count ;
$ ( "#" + prefix + "ExpandRight" ) . remove ( ) ;
} else $ ( "#" + prefix + "ExpandLeft" ) . remove ( ) ;
for ( i = start ; i < end ; i ++ ) {
$ ( "#" + prefix + "page" + i ) . show ( ) ;
}
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 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 ;
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
dataType : "html" ,
cache : false ,
success : function ( data , textStatus ) {
$ ( ".loading" ) . hide ( ) ;
$ ( fieldName + "_placeholder" ) . html ( data ) ;
$ ( fieldName + "_solid" ) . hide ( ) ;
$ ( fieldName + "_placeholder" ) . show ( ) ;
serverSettingsPostActivationScripts ( fieldName , setting , id ) ;
} ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/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 ) {
if ( ! $ ( '[data-toggle="popover"]' ) . is ( e . target ) ) {
$ ( '[data-toggle="popover"]' ) . popover ( 'hide' ) ;
}
} ) ;
}
2015-02-23 11:38:54 +01:00
2017-04-13 16:31:48 +02:00
function changeFreetextImportFrom ( ) {
2019-02-13 08:46:18 +01:00
$ ( '#changeTo' ) . find ( 'option' ) . remove ( ) ;
options [ $ ( '#changeFrom' ) . val ( ) ] . forEach ( function ( element ) {
$ ( '#changeTo' ) . append ( '<option value="' + element + '">' + element + '</option>' ) ;
} ) ;
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 ( ) {
if ( $ ( this ) . val ( ) == from ) {
if ( selectContainsOption ( "#" + $ ( this ) . attr ( 'id' ) , to ) ) $ ( this ) . val ( to ) ;
}
} ) ;
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 ( ) {
if ( this . value == value ) {
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
2017-04-13 16:31:48 +02:00
function importChoiceSelect ( url , elementId , 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
2017-04-13 16:31:48 +02:00
function freetextImportResultsSubmit ( id , count ) {
2019-02-13 08:46:18 +01:00
var attributeArray = [ ] ;
var temp ;
2020-10-11 11:50:11 +02:00
for ( var i = 0 ; i < count ; i ++ ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '#Attribute' + i + 'Save' ) . val ( ) == 1 ) {
temp = {
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 ( )
}
attributeArray [ attributeArray . length ] = temp ;
}
2020-10-11 11:50:11 +02:00
}
2019-02-13 08:46:18 +01:00
$ ( "#AttributeJsonObject" ) . val ( JSON . stringify ( attributeArray ) ) ;
var formData = $ ( ".mainForm" ) . serialize ( ) ;
$ . ajax ( {
type : "post" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/events/saveFreeText/" + id ,
2019-02-13 08:46:18 +01:00
data : formData ,
2020-10-11 11:50:11 +02:00
beforeSend : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . show ( ) ;
} ,
2020-10-11 11:50:11 +02:00
success : function ( ) {
2020-08-16 13:31:31 +02:00
window . location = baseurl + '/events/view/' + id ;
2019-02-13 08:46:18 +01:00
} ,
2020-10-11 11:50:11 +02:00
complete : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . hide ( ) ;
} ,
2020-10-11 11:50:11 +02:00
error : xhrFailCallback ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-03-21 14:27:53 +01:00
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 = [ ] ;
$ ( ".MISPObject" ) . each ( function ( o ) {
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 ( ) ;
}
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 = [ ] ;
$ ( this ) . find ( '.ObjectAttribute' ) . each ( function ( a ) {
2019-06-20 14:37:33 +02:00
var attribute _type = $ ( this ) . find ( '.AttributeType' ) . text ( ) ;
2019-04-03 22:59:58 +02:00
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 ,
2019-04-03 22:59:58 +02:00
value : $ ( this ) . find ( '.AttributeValue' ) . text ( ) ,
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' ) ,
colour : rgb2hex ( $ ( this ) . css ( 'background-color' ) )
} ) ;
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 ,
2019-04-03 22:59:58 +02:00
value : $ ( this ) . find ( '.AttributeValue' ) . text ( ) ,
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' ) ,
colour : rgb2hex ( $ ( this ) . css ( 'background-color' ) )
} ) ;
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 ;
}
2019-04-04 16:28:49 +02:00
$ ( "#EventJsonObject" ) . val ( JSON . stringify ( data _collected ) ) ;
var formData = $ ( '.mainForm' ) . serialize ( ) ;
2019-04-03 22:59:58 +02:00
$ . ajax ( {
type : "post" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/events/handleModuleResults/" + id ,
2019-04-04 16:28:49 +02:00
data : formData ,
2020-10-15 19:01:01 +02:00
beforeSend : function ( ) {
2019-04-03 22:59:58 +02:00
$ ( ".loading" ) . show ( ) ;
} ,
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
} ,
2020-10-15 19:01:01 +02:00
complete : function ( ) {
2019-04-03 22:59:58 +02:00
$ ( ".loading" ) . hide ( ) ;
2020-10-15 19:01:01 +02:00
} ,
error : xhrFailCallback ,
2019-04-03 22:59:58 +02:00
} ) ;
}
2017-07-02 00:05:15 +02:00
function objectTemplateViewContent ( context , id ) {
2020-08-16 13:31:31 +02:00
var url = baseurl + "/objectTemplateElements/viewElements/" + id + "/" + context ;
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2020-10-15 19:01:01 +02:00
url : url ,
type : 'GET' ,
2019-02-13 08:46:18 +01:00
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
2020-10-15 19:01:01 +02:00
error : function ( ) {
$ ( '#ajaxContent' ) . html ( 'An error has occured, please reload the page.' ) ;
} ,
success : function ( response ) {
$ ( '#ajaxContent' ) . html ( response ) ;
} ,
2019-02-13 08:46:18 +01:00
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
} ) ;
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' ) {
2020-06-05 10:30:02 +02:00
action = "/admin/users/index/searchorg:" ;
2020-10-09 18:03:10 +02:00
} else if ( context === 'events' ) {
2020-06-05 10:30:02 +02:00
action = "/events/index/searchorg:" ;
2019-02-13 08:46:18 +01:00
}
$ . ajax ( {
2020-08-16 13:31:31 +02:00
url : baseurl + action + id ,
2019-02-13 08:46:18 +01:00
type : 'GET' ,
2020-10-09 18:03:10 +02:00
beforeSend : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . show ( ) ;
} ,
error : function ( ) {
$ ( '#ajaxContent' ) . html ( 'An error has occured, please reload the page.' ) ;
} ,
success : function ( response ) {
$ ( '#ajaxContent' ) . html ( response ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
} ) ;
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 = {
'organisations' : organisations ,
'servers' : servers ,
'sharingGroup' : {
'name' : $ ( '#SharingGroupName' ) . val ( ) ,
'releasability' : $ ( '#SharingGroupReleasability' ) . val ( ) ,
'description' : $ ( '#SharingGroupDescription' ) . val ( ) ,
'active' : $ ( '#SharingGroupActive' ) . is ( ":checked" ) ,
'roaming' : $ ( '#SharingGroupRoaming' ) . is ( ":checked" ) ,
}
} ;
$ ( '#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 ) ;
$ ( '#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 ,
beforeSend : function ( XMLHttpRequest ) {
$ ( 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 ,
2019-11-13 19:09:37 +01:00
type : 'GET' ,
beforeSend : function ( XMLHttpRequest ) {
resultContainer . html ( 'Running test...' ) ;
} ,
error : function ( ) {
resultContainer . html ( 'Internal error.' ) ;
} ,
success : function ( response ) {
if ( typeof ( response . message ) != 'undefined' ) {
resultContainer . empty ( ) ;
resultContainer . append (
$ ( '<span>' )
. attr ( 'class' , 'red bold' )
. text ( 'Error' )
) . append (
$ ( '<span>' )
. text ( ': #' + response . message )
) ;
} else {
resultContainer . empty ( ) ;
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>' )
) ;
} ) ;
}
var result = response ;
}
} ) ;
}
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 :
2020-10-16 17:34:55 +02:00
html += '<span class="red bold" title="The user account on the remote instance is not a sync user.">Remote user not a sync user</span>' ;
2019-02-13 08:46:18 +01:00
break ;
2019-11-26 19:40:49 +01:00
case 8 :
2020-10-16 17:34:55 +02: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, syncing 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 ( ) ;
$ . ajax ( {
type : "get" ,
2020-08-17 15:57:21 +02:00
url : baseurl + "/users/fetchGpgKey/" + fingerprint ,
2019-09-23 20:56:52 +02:00
beforeSend : function ( ) {
$ ( ".loading" ) . show ( ) ;
} ,
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!" ) ;
} ,
error : function ( data , textStatus , errorThrown ) {
showMessage ( 'fail' , textStatus + ": " + errorThrown ) ;
2019-09-23 20:56:52 +02:00
} ,
complete : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . hide ( ) ;
2019-09-23 20:56:52 +02:00
} ,
2019-02-13 08:46:18 +01:00
} ) ;
2017-04-13 16:31:48 +02:00
}
2015-06-23 10:56:19 +02:00
2017-04-13 16:31:48 +02:00
function lookupPGPKey ( emailFieldName ) {
2019-09-23 20:56:52 +02:00
var email = $ ( '#' + emailFieldName ) . 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 ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
type : "get" ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/servers/" + action + "ZeroMQServer/" ,
2019-02-13 08:46:18 +01:00
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data ) {
$ ( ".loading" ) . hide ( ) ;
if ( action !== 'status' ) {
window . location . reload ( ) ;
} else {
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
}
} ,
error : function ( data , textStatus , errorThrown ) {
showMessage ( 'fail' , textStatus + ": " + errorThrown ) ;
}
} ) ;
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' ) {
rules [ type ] = { "tags" : { "OR" : [ ] , "NOT" : [ ] } , "orgs" : { "OR" : [ ] , "NOT" : [ ] } , "url_params" : "" }
} 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 ) {
if ( type === 'push' ) {
var indexedList = { } ;
window [ field ] . forEach ( function ( item ) {
indexedList [ item . id ] = item . name ;
} ) ;
}
statusOptions . forEach ( function ( status ) {
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 += ', ' ;
if ( type === 'pull' ) t += item ;
else t += indexedList [ item ] ;
} ) ;
$ ( '#' + type + '_' + field + '_' + status + '_text' ) . text ( t ) ;
} else {
$ ( '#' + type + '_' + field + '_' + status ) . hide ( ) ;
}
} ) ;
} ) ;
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 serverRuleFormActivate ( type ) {
2019-02-13 08:46:18 +01:00
if ( type != 'pull' && type != 'push' ) return false ;
$ ( '.server_rule_popover' ) . hide ( ) ;
$ ( '#gray_out' ) . fadeIn ( ) ;
$ ( '#server_' + type + '_rule_popover' ) . show ( ) ;
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 serverRuleCancel ( ) {
2019-02-13 08:46:18 +01:00
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( ".server_rule_popover" ) . fadeOut ( ) ;
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
2017-04-13 16:31:48 +02:00
function serverRulePopulateTagPicklist ( ) {
2019-02-13 08:46:18 +01:00
var fields = [ "tags" , "orgs" ] ;
var target = "" ;
fields . forEach ( function ( field ) {
target = "" ;
window [ field ] . forEach ( function ( element ) {
if ( $ . inArray ( element . id , rules [ "push" ] [ field ] [ "OR" ] ) != - 1 ) target = "#" + field + "pushLeftValues" ;
else if ( $ . inArray ( element . id , rules [ "push" ] [ field ] [ "NOT" ] ) != - 1 ) target = "#" + field + "pushRightValues" ;
else target = "#" + field + "pushMiddleValues" ;
$ ( target ) . append ( $ ( '<option/>' , {
value : element . id ,
text : element . name
} ) ) ;
} ) ;
target = "#" + field + "pullLeftValues" ;
rules [ "pull" ] [ field ] [ "OR" ] . forEach ( function ( t ) {
$ ( target ) . append ( $ ( '<option/>' , {
value : t ,
text : t
} ) ) ;
} ) ;
target = "#" + field + "pullRightValues" ;
rules [ "pull" ] [ field ] [ "NOT" ] . forEach ( function ( t ) {
$ ( target ) . append ( $ ( '<option/>' , {
value : t ,
text : t
} ) ) ;
} ) ;
} ) ;
2020-01-23 09:42:16 +01:00
$ ( '#urlParams' ) . val ( rules [ "pull" ] [ "url_params" ] ) ;
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 submitServerRulePopulateTagPicklistValues ( context ) {
2019-02-13 08:46:18 +01:00
validFields . forEach ( function ( field ) {
rules [ context ] [ field ] [ "OR" ] = [ ] ;
$ ( "#" + field + context + "LeftValues option" ) . each ( function ( ) {
rules [ context ] [ field ] [ "OR" ] . push ( $ ( this ) . val ( ) ) ;
} ) ;
rules [ context ] [ field ] [ "NOT" ] = [ ] ;
$ ( "#" + field + context + "RightValues option" ) . each ( function ( ) {
rules [ context ] [ field ] [ "NOT" ] . push ( $ ( this ) . val ( ) ) ;
} ) ;
} ) ;
2020-01-23 09:42:16 +01:00
if ( context === 'pull' ) {
rules [ context ] [ "url_params" ] = $ ( '#urlParams' ) . val ( ) ;
}
2019-02-13 08:46:18 +01:00
$ ( '#server_' + context + '_rule_popover' ) . fadeOut ( ) ;
$ ( '#gray_out' ) . fadeOut ( ) ;
serverRuleUpdate ( ) ;
2017-04-13 16:31:48 +02:00
}
2015-07-28 14:00:38 +02:00
// type = pull/push, field = tags/orgs, from = Left/Middle/Right, to = Left/Middle/Right
2017-04-13 16:31:48 +02:00
function serverRuleMoveFilter ( type , field , from , to ) {
2019-02-13 08:46:18 +01:00
var opposites = { "Left" : "Right" , "Right" : "Left" } ;
// first fetch the value
var value = "" ;
if ( type == "pull" && from == "Middle" ) {
var doInsert = true ;
value = $ ( "#" + field + type + "NewValue" ) . val ( ) ;
if ( value . length !== 0 && value . trim ( ) ) {
$ ( "#" + field + type + to + "Values" + " option" ) . each ( function ( ) {
if ( value == $ ( this ) . val ( ) ) doInsert = false ;
} ) ;
$ ( "#" + field + type + opposites [ to ] + "Values" + " option" ) . each ( function ( ) {
if ( value == $ ( this ) . val ( ) ) $ ( this ) . remove ( ) ;
} ) ;
if ( doInsert ) {
$ ( "#" + field + type + to + "Values" ) . append ( $ ( '<option/>' , {
value : value ,
text : value
} ) ) ;
}
}
$ ( "#" + field + type + "NewValue" ) . val ( '' ) ;
} else {
$ ( "#" + field + type + from + "Values option:selected" ) . each ( function ( ) {
if ( type != "pull" || to != "Middle" ) {
value = $ ( this ) . val ( ) ;
text = $ ( this ) . text ( ) ;
$ ( "#" + field + type + to + "Values" ) . append ( $ ( '<option/>' , {
value : value ,
text : text
} ) ) ;
}
$ ( this ) . remove ( ) ;
} ) ;
}
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
2020-10-05 21:52:09 +02:00
function filterAttributes ( filter , event _id ) {
var url = baseurl + "/events/viewEventAttributes/" + event _id ;
if ( filter === 'value' ) {
2020-05-14 15:38:07 +02:00
filter = encodeURIComponent ( $ ( '#quickFilterField' ) . val ( ) . trim ( ) ) ;
2019-02-13 08:46:18 +01:00
url += filter . length > 0 ? "/searchFor:" + filter : "" ;
2020-10-05 21:52:09 +02:00
} else if ( filter === 'all' ) {
$ ( '#quickFilterField' ) . val ( '' ) ; // clear input value
} else {
2019-03-15 10:44:17 +01:00
url += "/attributeFilter:" + filter
2020-05-14 15:38:07 +02:00
filter = encodeURIComponent ( $ ( '#quickFilterField' ) . val ( ) . trim ( ) ) ;
2019-02-13 08:46:18 +01:00
url += filter . length > 0 ? "/searchFor:" + filter : "" ;
}
if ( deleted ) url += '/deleted:true' ;
$ . ajax ( {
2020-08-25 18:30:03 +02:00
type : "get" ,
url : url ,
2020-10-05 21:52:09 +02:00
beforeSend : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . show ( ) ;
} ,
2020-10-05 21:52:09 +02:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#attributes_div" ) . html ( data ) ;
$ ( ".loading" ) . hide ( ) ;
} ,
2020-10-05 21:52:09 +02:00
error : function ( ) {
2019-02-13 08:46:18 +01:00
showMessage ( 'fail' , 'Something went wrong - could not fetch attributes.' ) ;
2020-10-05 21:52:09 +02:00
$ ( ".loading" ) . hide ( ) ;
2019-02-13 08:46:18 +01:00
}
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-05-10 10:31:56 +02:00
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 ;
}
2020-09-26 15:05:02 +02: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 ;
}
2020-09-26 15:05:02 +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
}
2019-02-13 08:46:18 +01:00
url += '/focus:' + uuid ;
$ . ajax ( {
2020-09-26 15:05:02 +02:00
type : "get" ,
url : url ,
beforeSend : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . show ( ) ;
} ,
2020-08-25 18:30:03 +02:00
success : function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#attributes_div" ) . html ( data ) ;
} ,
2020-08-25 18:30:03 +02:00
error : function ( ) {
2019-02-13 08:46:18 +01:00
showMessage ( 'fail' , 'Something went wrong - could not fetch attributes.' ) ;
2020-08-25 18:30:03 +02:00
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
2019-02-13 08:46:18 +01:00
}
} ) ;
2017-08-09 17:53:25 +02:00
}
new: [related tags] View the related tags of attributes on the event view (via a toggle)
,,.,,+zznzzzzzzzzzzzzzzzzzzzzzzzzzzxMMMMMMMMMMMMMMMMMMMMMxMxMMWMMMWMMz*ii****iiiiiiiii**iiii,....
,,.,,#zzzzzzzzzzzzzzzzzzzzzzzznxMMMMMWMMMMMMMMMMMMMMMMMMxMxMMMWWWWWWWWx+*iii*iiiiiiiii*iiiii,,,..
,,,,,#zzzzzzzzzzzzzzzzzzzzzzznMWWMMMMMMMMMMMMMMMMMMMMMMMWWMxnnzxxMWWWWMn*iiiiiiiiiiiiiiiiiii..,..
,,,,,#znzzzzzzzzzzzzzzzzzzzznMMMMMMWWWWMMMMMMMMMMMMMMMMWWWMMMxnxxxxMMMMW#*iiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzzzzznMMMMMMMMMWMMMMMMMMMMMMMMMMMMMMWxMMMMMMxxxxnxxz*iiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzzzzzxMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWWMWWWWMWMMMxxxni*iiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzzzznMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWWWMMWWMWMMWWWMMMni*iiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzzzzxWMMMMMMMMMMMMMMMMMMMMMMMMMMMWMMMWMMMMMMWMWWMMMMMz*iiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzznzzznMMMMMMMMMMMWMMMMMMMMMMMMMMMMMMMMMMMMWWWWMMMMMMMMMWn*iiiiiiiiiiii*i,.,.,
,,.,,#zzzzzzzzzzzzzzznzzzxMMMMMMMMMMMWMMMMMMMMMMMMMMMMMMMMMWWWWWWWWWWWMMMMMWWM+*iiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzznzzznzznMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWMWWWWWWWWWWWWWMMWWn*iiiiiiiiii*i,.,.,
,,.,,#zzzzzzzzzzznzzzznzxMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWMMMMWWWWMMWWWWWMMMM**iiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzznMMMMMMMMMMMMMWMMMMMWMMMMMMMMMMMMMMWWWWWMMMMMMMMWWWWWMWM#iiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzxMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWWWWWWWWWMMMMMMMWWWWMzi*iiiiiiii*i,.,.,
,,.,,#zzzzzzzzzzzzzzzzzMMMMMMMMMMMMMMMWMnzxMMMMMMMMMMMMMWWWWWWWWWWWWMMMMMMMWWWWni*iiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzWMMMMMMMMMMMMMMMnnzznxMWMMMMMMMMMMWWWWWWWWWWWWWWWWWMMWWMn**iiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzMMMMMMMMMMMWMMMMzz#+#znxMWMMMMMMMMMMMMMWWWWWWWWWWWWWMWWMn**iiiiiiii*i,.,,,
,,.,,#zzzzzzzzzzzzzzzzzxMMMMMMMMMMMMMMxz#*i**+zznMMMMMMMMMMMMMMMWWWWWWWMWWWWWWWx**iiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzxMMMMMMMMMMWWMMn#*iii*i*+znxMWMMMMMMMMMMMMWWWWWMMMMMMMMMM+*iiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzznMWMMMMMMMMMMMMn#*iiii*i*i+#znMMWWMMMMMWMWMMWWWMMMMMMMMWWx+iiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzMMMMMMMMMMMMMx#i*iii**iiii*#znxMWMMMMMMMMMMMWWMMMMWWWWWWniiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzznzMMMMMMMMMMMMxn+ii**i**iiii*i*zznMMMMMMMMMMMMMMMMMxMWWWMMx*iiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzznnMMMMMMMMMMMMxz*ii*iiiiiiiii:;*+znMWMMMMMMMMMMMMMMMMMWWWMx**iiiiiiii*i,.,,.
,,.,,#zzzzzzzzzzzzzzzznMMMMMMMMMMMMMn+ii*iiiii**;;:.:i*zznxMMMMMMMMMMMMMMWWWWWWni*ii**iiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzxMMMMMMMMMMMMMn*ii*iii*i;:,.,..,.,;+znxxMMMMMMMMMMMMMMWWWziiii**iiii*i,.,..
,,.,,#zzzzzzzzzzzzzzznxMMMMMMMMMMMMxzi*ii*ii*;,,,,,,,,,,,,:i*i#znnnxMWWMMMMMMMWn*iii*iiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzznxMMMMMMMMMMMMz*i*i*i*;:,.,,,,,,,,,,,,.,,,;i*#zznxMMMMMMWWM+iiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzznMMMWMMMMMMMMx#iii*i*i:.,.,,,.,.,,,,,,,,,,,,,,;i#znxMMMMMWM+iiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzznMMMWMMMMMMMMx#iiiiii:.,,.,,.......,,,,..,,,,,,,,iznxMMMMWM*iiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzznMMMMMMMMMMMMx#ii*ii:.,,,,,,..........,.....,,,,,,:*#MMMMWxi*iiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzMMMMMMMMMMMMn+i*i;:,.,,,......,.............,....,,;xMMMWniiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzznzzMMMMMMMMMWMn+iiii;,,,,,,.,..........,....,.,...,,,,.zMMMMxiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzznznMMMMMMMMMMnz*iiii:,,,,,,,,,,,,................,,,...zMMMMzi*iiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzznznMMMMMMMMMxzz**ii;..,,,.,,,,,,.................,,,...nMMMM#**iiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzznzzMMMMMMMWxzzz+iii:.,,,,.,,,,,....,............,,,,..,nMMWx*iiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzznznMMMMMMMWnzzzn+i*,...,,..,,,.,..,.,...,........,,,.,;MWMM+iiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzznMMMMMMMWnzzzzzzii*++++z+;,,,.,,,,,,,,,...,.....,...;MWMxii**iiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzznMMMMMMMWnzzznzzzzznnnzzzn#i,,,.,...................,MWM#iii*iiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzxMMMMMMMMzz+#znzznznMWWMMWMx#i:,,,,,,,,,,,,,,.,,..,,:MMx*iiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzxMMMMMMMxzz**#znMMnnxxxxxMWWWMnz;,,,,,.,.,,,,,,,,,,,,MMziiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzMMMMxMMMnzz*ii#nWWWWMWWnMMMWWWWWn*,,;i;i;**+#zzz+i,,,Mx*iiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzMMMMMMMxzzzi*;,+xWWMnxMnx+xMWWMWWn,.,znMMMxxMMMMxni:*Mziiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzznxnxMMMMxznziii.,:+nxiinn*.iMMMWMM+,,.*WWWWWWM#:,:#z##M*iiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzznzznxzMWMMMxznziii,..,+#n:,:,,,izzMM#;,,,+WWWWWzxn+i,:zzzMi**iiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzznzznnzxMMMMxzz#ii;,,,,:**++i::,:::zx;,,,,#MM#zxxMznWx#+izxiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzxnzMWMMMnzzz*i:.,,,,,,,i;i;,,.,*n,,,,,+#+::#n*,#xni,,zniiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzxnzMMMMWnzzz**;..,,,.,..,;,,,,,;n,.,,:*;,:::,,,:*,.,,n#i*iiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzznxzMWMMMnzzz**i,..,,.,,,,,,,,,,+#,...,i,.,;**++*:.,,:x***iiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzznzznnxWWMxnzzzz+*i,,,,,.,,,,,,,,,:z;,,..,:..,,,,::.,..,;xi*iiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzznxxxzzzzzz+ii,...,.,,,,,,.,,+zi.,,.,,.,,.,,..,,,,,++iiiiiiiiiiiiiiii*i,.,,.
,,.,,#zzzzzzzzzzzzzzzzzznMzzzznz#ii:.,.,..,,,,,,,izn:,..,.,,..,...,,.,,,#*iiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzznxzzzzzz#ii;.,.,..,,,,.,:zzz,,..,,,,.,...,,,,,,:+*iiiiiiiiiiiiiiii*i,.,,.
,,.,,#zzzzzzzzzzzzzzzznzxxzzzznzz*i;..,,,.,,,,..;zz*..,.,,,,........,.,**iiiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzznzxMnzzznzz*ii,.,,,,,,,,,,ii:,,,,,,,,,,,,,,.,,.,;+*iiiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzzxMzzzzzzz**i,,.,..,,,,,;*:*,,,.,,...,,,,,,.,,,**iiiiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzzzzzMMnnzzzzz*ii:.,,,,,,..,#nnn#+,,,,,..,,....,.,i+i*iiiiiiiiiiiiiiiii*i,.,,.
,,.,,#zzzzzzzzzzzznzznnzMMnxzzzzz**i;.,,,,.,,.,zxWWWxi,,,:*,,,..,.,,,#**iiiiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzzznM+WMxxzzzzz***;..,,,,,,..;xWWWWn+**#;,,,,.,,,.i#*iiiiiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzznW#zWMxnnzzzz*iii,.,,,,,,,,,+nWMWWWMx+,,,,,.,,,,++i*iiiiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzznMM,zWMMnnzzz#*ii*;.,,,,,,::iznxMMWWWWn#;,,.,,,,*#**iiiiiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzzzzMWz,zMMMxxznn#*ii*i::;i++#zznxWxxxWWWxxxzi,.,,,,#+iiiiiiiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzznMWW#,#MMMMMnznz*ii**izzzzzzxMMWWnxM@WMMMMzzi,.,,+*+iiiiiiiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzznMWWW#,*xMMMMnznz*iiii+MnnnnnxMWWWxxMxMxMxxxnz*,,,*+*iiii**iiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzzzMWWWW#;;zMMMMMnnz#*i*#MWxxxxxMWMxMMxMxMWWWWxMzn;.i:#*iiii**iiiiiiiiiiiiiii*i,.,..
,,,,,#zzzzzznnzxWWWWW#:;+MMMMMxzzz#*zzxWMWMWxMWWMMWWMMWWWWMxxMn:,*:#iiiiiiiiiiiiiiiiiiiiii*i,.,..
,,.,,#zzzzzzzzxWWWWWWz::inMMMMMxznzzzzznxMMMxxxMMxxxzxMWWWMMWWx:ii+*iiiiiiiiiiiiiiiiiiiiii*i,.,..
....,#zzzzzzznWWWWWWWz;,;+MMMMMMxzzzzzzzzznz#**i;::,,:;#nxxWMM+;*;+*iiiiiiiiiiiiiiiiiiiiii*i,.,..
...,,#zzzzzznMWWWWWWWni,,*nWMMMMMxnzzzzzzzz#i*i,,,,:,,,,:+#z##i#+#*iiiiiiiiiiiiiiiiiiiiiii*i,.,..
...,,#zzznnnxWWWWWWWWx*,.i+MMMMMMMMxxnzz#+****i,i**#z+;,:*iiii*zz+*iiiiiiiiiiiiiiiiiiiiiii*i,.,..
,,,,,#nzzzxMMWWWWWWWWW*;.:*#WMMMMMMMMxz+**iiiii;*++####:;i****zz#*iiiiiiiiiiiiiiiiiiiiiiii*i,.,,.
,,,,,#zznMWxWWWWWWWWWWz;,.;*nWMMMMMMMMnz#ii:.....,,,,,,,,ii*+zzz*ii**iiiiiiiiiiiiiiiiiiiii*i,.,..
,,,,,#nxWWMxWWWWWWWWWWW;:,,*+xMMMMMMMMMxnz*:.,,,,,..,,,,,,i#nnx+i*i*iiiiiiiiiiiiiiiiiiiiii*i,.,..
,,,,,zWWWWMxWWWWWWWWWWW*;,.,*+MMMMMMWMMWMx#*:,,,,....,,,,:#nMM#+*ii*iiiiiiiiiiiiiiiiiiiiii*i,.,..
,,,,,xWWWWxWWWWWWWWWWWWx::,,:;+MMMMMMWMWMMnz+:....,,.,,,,+MWMM*#z+*iiiiiiii**iiiiiiiiiiiii*i,.,..
,,,,,xWWWMxWWWWWWWWWWWWW+:,,,;:+MMMMMMMMMMMxnz*;,,:,,,i+#xM++W#+nz#iii*iiiiiiiiiiiiiiiiiii*i,.,..
,,,,,xWWWMMWWWWWWWWWWWWWx,,..,;,*xWMMMMMMMWMWxnn####+##nxx#,+Wx*nznz:i**iiiiiiiiiiiiiiiiii*i,.,..
,,.,,xWWWxMWWWWWWWWWWWWWWi.,,,,:,*#MMMMMMMMMMWMMxxxxxxxMnn,.zWM#;zzMn;*i*iiiiiiiiiiiiiiiii*i,.,..
,..,,xWWWxWWWWWWWWWWWWWWWx,,,,,,:,;+MMWMMMMWWWWWWWMMMMMxn:..nWWni+nzMn#niii**iiiiiiiiiiiii*i,.,..
,..,,xWWMxWWWWWWWWWWWWWWWWi,,,,.,:,,;xWMMMMMMMMMMMMMMxnni...xMWxz;znnMxxM#;i*i**iiiiiiiiii*i,.,..
,..,,xWWMMWWWWWWWWWWWWWWWWz.,,...::,,;zWMMMMMMMMMMMMnzzi,,,,MMMMx*innxMxxWx+iiii**iiiiiiii*i,.,..
,..,,xWWMMWWWWWWWWWWWWWWWWM:,,...,:,,,,+xWMMMMMMMMxnnzi,.,,,MMMMMzinxMxMxxMMM#;i**iiiiiiii*i,.,..
,..,,xWWxWWWWWWWWWWWWWWWWWW*.,.,.,,:,,.,i+xWWMMMMxnnni,,,,,.WMMMMMz#nMMxMMMMMWxi;i*iiii*ii*i,,,..
,..,,xWWxWWWWWWWWWWWWWWWWWWz.,,,,.,,:,,,,::#@WMMxnnn;..,,.,:WMWMMMMznxWxxWMMMMMM#;iiiiiiii*i,,,..
,..,.nWMMWWWWWWWWWWWWWWWWWWM,.,,,...,,..,.,.iMWMxnz:.,.,,.,;WMWMMMMnzxMMxMMMMMMWMxi;i*iii*ii..,..
,..,,nWWMMWWWWWWWWWWWWWWWWWWi,,,....,.,,.,,,,:nxxz:,.,,,...iWMWMMMWMznMMMxMMMMMMMMMzi;i**iii..,.,
,..,,xWWWMMWWWWWWWWWWWWWWWWW#:.....,....,.,,..:#+,..,,,....:WWMMMMMMxnnMMMxWMMMMMMMWM#;;*i*i,.,..
,..,,xWWWWWMMWWWWWWWWWWWWWWWxi:..,.......,,,,..;;,...,,...,,@WMMMMMMMxzxMMxxMMWMMMMMMWx+;iii,,,..
,..,,xWWWWWWMMMWWWWWWWWWWWWWM*i,,,,......,,,,,;MWx+,..,,,..,@WMMMMMMMMnzxxnMMMMMMMMMMMWWx+ii,,,,.
,..,,xWWWWWWWMxWWWWWWWWWWWWWW+*;,,,,.....,,.,,xWWW@n:.,,,,.,WWMMMMMMMMMnnnMMMMMMMMMMMMWMWMxz,,,..
,..,,xWWWWWWWWMxWWWWWWWWWWWWWzi*;,,,,.....,,,nWMMMWWM:.,,,..MWMMMWMMMMMMnMMMMMMMMMMMMMMMMMMx,.,.,
,..,,xWWWWWWWWMxWWWWWWWWWWWWWMiii;,,.,,...,.zWWWWWWWWn,.....zWMMMMMMMMMMMxMMMMMMMMMMMMMMMMMx,,,..
,..,,xWWWWWWWWMWWWWWWWWWWWWWWWiii*;,,,,,,.,z@WWWWWWWWW*,..,,zWMMMMMMMMMMMMnMMMMMMMMMMMMMMMMx,,,..
,..,,xWWWWWWWMWWWWWWWWWWWWWWW@+,;ii:,,.,,,zWWWWWWWWWWWM:.,,,#WMMMMMMMMMMMMxnMMWMMMMMMMMMMMMx,,,..
,..,,xWWWWWWWWWWWWWWWWWWWWWWWWz,.;i*:...,ixWWWWWWWWWMMW+,,,.+WMMMMMMMMMMMMMxxMWWMMMMMMMMMMMx,,,..
,..,.xWWWWWWWWWWWWWWWWWWWWWWWWM,,,iii,,,;i+WWWWWWWWW#+xx;,,.+WWMMMMMMMMMMMWMxxMMMMMMMMMMMMMx,,,,,
,..,.xWWWMWWWWWWWWWWWWWWWWWWWWW;.,:iii,:ii*xWWWWWWWW+i*Mz,.,*WWMMMMMMMMMMMMWMxnMMMMMMMMMMMMx,,,..
,..,.xWWWMWWWWWWWWWWWWWWWWWWWWWz.,.;i*iiiiinWWWWWWWW*i*+z*.,iWWMMMMMMMMMMMMMMMxxMMMMMMMMMMMx,,,..
,..,.xWWWMMWWWWWWWWWWWWWWWWWWWWx,,,.i***;:i#WWWWWWWMi*ii*zi,;WWMMMMMMMMMMMMMMMMxMMMMMMMMMMMx,,,,.
,..,,xWWWWMMWWWWWWWWWWWWWWWWWWWW;,,.:*ii,,i+WWWWWWWM::iiiizi:WWMMMMMMMMMMMMMMMMMMMMMMMMMMMMx,,,..
,..,,xWWWWWWWWWWWWWWWWWWWWWWWWWW+,,,.,i,,,;*WWWWWWWx:.:iii*z*MWMMMMMMMMMMMMMMMMMWMMMMMMMMMMx,,,..
,..,,xWWWWWWWWWWWWWWWWWWWWWWWWWWn,,,,...,,:*MWWWWWWn:..;ii**xWWMMMMMMMMMMMMMMMMWWMMMMMMMMMMx,,,..
,..,,xWWWWWWWWWWWWWWWWWWWWWWWWWWW:.,.,,,.,,iMWWWWWWz,.,,i*i*nWWMMMMMMMMMMMMMMMWWMMMMMMMMMMMx,,,..
,..,,xWWWWWWWWWWWWWWWWWWWWWWWWWW@*..,,,..,,ixWWWWWWz..,.,i*inWWMMMMMMMMMMMMMMMWWMMMMMMMMMMMx,,,,.
,..,,xWWWWWWWWWWWWWWWWWWWWWWWWWWWn,.,,,,,,,;n@WWWWWn..,,,:*izWWMMMMMMMMMMMMMMWWWWMMMMMMMMMMx,,,..
,..,,xWWWWWWWWWWWWWWWWWWWWWWWWWWWM:.,,,....:xWWWWWWM,,,,,.:izMWMMMMMMMMMMMMMMMWWMMMMMMMMMMMx,,,..
,..,,nMWWWWWWWWWWWWWWWWWWWWWMWWWWM#*********MWWWWWWW+*******nMWMMMMMMMMMMMMMMMMMMMMMMMMMMMMx,,,..
,..,,nMWWMMMMMMMMMMMMMMMMWWMMMMMWMMMWWMMMWWMMMMMMMMMMMMWWMWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMx,,,..
2018-10-11 17:37:58 +02:00
function toggleBoolFilter ( url , 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 ) ;
Object . keys ( res ) . forEach ( function ( k ) {
if ( url . indexOf ( k ) > - 1 ) { // delete url rule (will be replaced by query builder value later on)
var replace = '\/' + k + ".+/?" ;
var re = new RegExp ( replace , "i" ) ;
url = url . replace ( re , '' ) ;
}
} ) ;
2019-08-12 16:34:26 +02:00
if ( res [ param ] !== undefined ) {
2019-09-06 11:22:14 +02:00
if ( param == 'deleted' ) {
res [ param ] = res [ param ] == 0 ? 2 : 0 ;
2019-08-12 16:34:26 +02:00
} else {
2019-09-06 11:22:14 +02:00
res [ param ] = res [ param ] == 0 ? 1 : 0 ;
2019-08-12 16:34:26 +02:00
}
2019-02-13 08:46:18 +01:00
} else {
2019-09-06 11:22:14 +02:00
if ( param == 'deleted' ) {
res [ param ] = 0 ;
} else {
res [ param ] = 1 ;
}
2019-02-13 08:46:18 +01:00
}
2019-04-18 10:20:08 +02:00
url += buildFilterURL ( res ) ;
url = url . replace ( /view\//i , 'viewEventAttributes/' ) ;
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2020-08-25 18:30:03 +02:00
type : "get" ,
url : url ,
beforeSend : function ( ) {
2019-02-13 08:46:18 +01:00
$ ( ".loading" ) . show ( ) ;
} ,
2020-08-25 18:30:03 +02:00
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
2019-02-13 08:46:18 +01:00
success : function ( data ) {
$ ( "#attributes_div" ) . html ( data ) ;
2019-04-18 10:20:08 +02:00
querybuilderTool = undefined ;
2020-08-25 18:30:03 +02:00
2019-02-13 08:46:18 +01:00
} ,
error : function ( ) {
showMessage ( 'fail' , 'Something went wrong - could not fetch attributes.' ) ;
}
} ) ;
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 feedDistributionChange ( ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '#FeedDistribution' ) . val ( ) == 4 ) $ ( '#SGContainer' ) . show ( ) ;
else $ ( '#SGContainer' ) . 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 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' ) ;
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 ) ;
} ) ;
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 ( ) {
2020-10-07 20:56:44 +02:00
clearTimeout ( hoverEnrichmentPopoverTimer ) ; // stop potentional popover loading
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
2019-02-13 08:46:18 +01:00
$ . ajax ( {
2020-10-07 19:09:17 +02:00
beforeSend : function ( ) {
$ ( ".loading" ) . show ( ) ;
} ,
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
} ,
2020-10-06 19:43:23 +02:00
error : xhrFailCallback ,
2020-10-07 19:09:17 +02:00
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
2019-02-13 08:46:18 +01:00
} ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/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
} ) ;
2018-11-13 11:48:12 +01:00
function flashErrorPopover ( ) {
2019-02-13 08:46:18 +01:00
$ ( '#popover_form' ) . css ( "minWidth" , "200px" ) ;
$ ( '#popover_form' ) . html ( $ ( '#flashErrorMessage' ) . html ( ) ) ;
$ ( '#popover_form' ) . show ( ) ;
var left = ( $ ( window ) . width ( ) / 2 ) - ( $ ( '#popover_form' ) . width ( ) / 2 ) ;
$ ( '#popover_form' ) . css ( { 'left' : left + 'px' } ) ;
$ ( "#gray_out" ) . fadeIn ( ) ;
}
2018-11-13 11:48:12 +01:00
2019-02-13 19:19:57 +01:00
$ ( 'body' ) . on ( 'click' , function ( e ) {
$ ( '[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 ( ) {
2020-08-16 13:31:31 +02:00
url = baseurl + "/users/request_API/" ;
2019-02-13 08:46:18 +01:00
$ . ajax ( {
type : "get" ,
url : url ,
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data ) {
$ ( ".loading" ) . hide ( ) ;
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
2017-04-13 16:31:48 +02:00
function initPopoverContent ( context ) {
2019-02-13 08:46:18 +01:00
for ( var property in formInfoFields ) {
if ( formInfoFields . hasOwnProperty ( property ) ) {
$ ( '#' + property + 'InfoPopover' ) . popover ( "destroy" ) . popover ( {
placement : 'right' ,
html : 'true' ,
trigger : 'hover' ,
content : getFormInfoContent ( property , '#' + context + formInfoFields [ property ] )
} ) ;
}
}
2017-04-13 16:31:48 +02:00
}
2016-10-01 23:25:15 +02:00
2019-11-11 23:35:53 +01:00
function checkSharingGroup ( context ) {
if ( $ ( '#' + context + 'Distribution' ) . val ( ) == 4 ) {
2019-11-12 11:02:46 +01:00
$ ( '#' + context + 'SharingGroupId' ) . show ( ) ;
$ ( '#' + context + 'SharingGroupId' ) . closest ( "div" ) . show ( ) ;
2019-11-11 23:35:53 +01:00
} else {
2019-11-12 11:02:46 +01:00
$ ( '#' + context + 'SharingGroupId' ) . hide ( ) ;
$ ( '#' + context + 'SharingGroupId' ) . closest ( "div" ) . hide ( ) ;
2019-11-11 23:35:53 +01:00
}
}
2017-04-13 16:31:48 +02:00
function getFormInfoContent ( property , field ) {
2019-02-13 08:46:18 +01:00
var content = window [ property + 'FormInfoValues' ] [ $ ( field ) . val ( ) ] ;
if ( content === undefined || content === null ) {
return 'N/A' ;
}
return content ;
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 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 ) {
for ( var type in category _type _mapping [ category ] ) {
optionsToPush [ type ] = category _type _mapping [ category ] [ type ] ;
}
}
} else {
optionsToPush = category _type _mapping [ selectedCategory ] ;
}
$ . each ( optionsToPush , function ( val , text ) {
2019-02-13 08:46:18 +01:00
options [ options . length ] = new Option ( text , val ) ;
2020-08-17 13:32:00 +02:00
if ( val === alreadySelected ) {
2020-10-14 16:15:54 +02:00
options [ options . length - 1 ] . selected = true ;
2020-08-17 13:32:00 +02:00
}
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
2017-04-13 16:31:48 +02:00
function malwareCheckboxSetter ( context ) {
2019-02-13 08:46:18 +01:00
idDiv = "#" + context + "Category" + 'Div' ;
var value = $ ( "#" + context + "Category" ) . val ( ) ; // get the selected value
// set the malware checkbox if the category is in the zip types
$ ( "#" + context + "Malware" ) . prop ( 'checked' , formZipTypeValues [ value ] == "true" ) ;
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 ( ) ;
}
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 setContextFields ( ) {
2019-02-13 08:46:18 +01:00
if ( showContext ) {
$ ( '.context' ) . show ( ) ;
$ ( '#show_context' ) . addClass ( "attribute_filter_text_active" ) ;
$ ( '#show_context' ) . removeClass ( "attribute_filter_text" ) ;
} else {
$ ( '.context' ) . hide ( ) ;
$ ( '#show_context' ) . addClass ( "attribute_filter_text" ) ;
$ ( '#show_context' ) . removeClass ( "attribute_filter_text_active" ) ;
}
2017-04-13 16:31:48 +02:00
}
2016-10-25 09:55:41 +02:00
2017-04-13 16:31:48 +02:00
function toggleContextFields ( ) {
2019-02-13 08:46:18 +01:00
if ( ! showContext ) {
showContext = true ;
} else {
showContext = false ;
}
setContextFields ( ) ;
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 ( ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
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>' ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
type : "get" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/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 ( ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
async : true ,
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data , textStatus ) {
$ ( ".treemapdiv" ) . html ( data ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
type : "get" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/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 quickEditEvent ( id , field ) {
2019-02-13 08:46:18 +01:00
$ . ajax ( {
async : true ,
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data , textStatus ) {
$ ( "#" + field + "Field" ) . html ( data ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
type : "get" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/events/quickEdit/" + id + "/" + field ,
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 ) {
2019-02-13 08:46:18 +01:00
if ( last === false || last == current ) return false ;
var from = $ ( '#' + last ) . parent ( ) . parent ( ) . index ( ) ;
var to = $ ( '#' + current ) . parent ( ) . parent ( ) . index ( ) ;
if ( to < from ) {
var temp = from ;
from = to ;
to = temp ;
}
2019-08-23 14:24:45 +02:00
$ ( '.select_proposal, .select_attribute, .select' ) . each ( function ( e ) {
2019-02-13 08:46:18 +01:00
if ( $ ( '#' + this . id ) . parent ( ) . parent ( ) . index ( ) >= from && $ ( '#' + this . id ) . parent ( ) . parent ( ) . index ( ) <= to ) {
$ ( this ) . prop ( 'checked' , true ) ;
}
} ) ;
2017-04-13 16:31:48 +02:00
}
2016-12-06 02:35:25 +01:00
2017-04-13 16:31:48 +02:00
$ ( '.galaxy-toggle-button' ) . click ( function ( ) {
2019-02-13 08:46:18 +01:00
var element = $ ( this ) . data ( 'toggle-type' ) ;
if ( $ ( this ) . children ( 'span' ) . hasClass ( 'icon-minus' ) ) {
$ ( this ) . children ( 'span' ) . addClass ( 'icon-plus' ) ;
$ ( this ) . children ( 'span' ) . removeClass ( 'icon-minus' ) ;
$ ( '#' + element + '_div' ) . hide ( ) ;
} else {
$ ( this ) . children ( 'span' ) . removeClass ( 'icon-plus' ) ;
$ ( this ) . children ( 'span' ) . addClass ( 'icon-minus' ) ;
$ ( '#' + element + '_div' ) . show ( ) ;
}
2016-12-06 02:35:25 +01:00
} ) ;
2018-06-22 14:02:17 +02:00
2018-06-22 12:08:26 +02:00
function addGalaxyListener ( id ) {
2019-02-13 08:46:18 +01:00
var target _type = $ ( id ) . data ( 'target-type' ) ;
var target _id = $ ( id ) . data ( 'target-id' ) ;
2019-07-08 11:39:41 +02:00
var local = $ ( id ) . data ( 'local' ) ;
console . log ( local ) ;
if ( local ) {
local = 1 ;
} else {
local = 0 ;
}
popoverPopup ( id , target _id + '/' + target _type + '/local:' + local , 'galaxies' , 'selectGalaxyNamespace' ) ;
2018-06-21 09:07:38 +02: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' ] ;
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 ) {
2019-06-07 15:25:32 +02:00
$ ( 'body' ) . append ( $ ( '<div id="temp"/>' ) . html ( formData ) ) ;
2019-06-12 13:10:47 +02:00
$ ( '#temp #GalaxyTargetIds' ) . val ( JSON . stringify ( cluster _ids ) ) ;
2019-06-07 14:44:39 +02:00
if ( target _id == 'selected' ) {
$ ( '#AttributeAttributeIds, #GalaxyAttributeIds' ) . val ( getSelected ( ) ) ;
}
$ . ajax ( {
data : $ ( '#GalaxyAttachMultipleClustersForm' ) . serialize ( ) ,
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data , textStatus ) {
if ( target _id === 'selected' ) {
2019-02-13 08:46:18 +01:00
location . reload ( ) ;
} else {
2019-06-07 14:44:39 +02:00
if ( scope == 'tag_collection' ) {
location . reload ( ) ;
} else {
loadGalaxies ( target _id , scope ) ;
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.' ) ;
loadGalaxies ( target _id , scope ) ;
} ,
complete : function ( ) {
$ ( "#popover_form" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
$ ( ".loading" ) . hide ( ) ;
2019-06-07 15:25:32 +02:00
$ ( '#temp' ) . remove ( ) ;
2019-06-07 14:44:39 +02:00
} ,
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 ;
}
var id = $ ( '#hiddenSideMenuData' ) . data ( 'event-id' ) ;
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' ) ;
}
} ) ;
}
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 ( ) ;
} )
} ) ;
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 ( ) ;
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 ( ) ;
2019-02-13 08:46:18 +01:00
$ ( "#screenshot_box" ) . fadeOut ( ) ;
$ ( "#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 ) ;
} ) ;
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 ( ) {
2020-08-16 13:31:31 +02:00
$ . get ( baseurl + "/servers/update" , function ( data ) {
2019-02-13 08:46:18 +01:00
$ ( "#confirmation_box" ) . html ( data ) ;
openPopup ( "#confirmation_box" ) ;
} ) ;
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 ( ) ;
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
data : formData ,
success : function ( data , textStatus ) {
$ ( '#gitResult' ) . text ( data ) ;
$ ( '#gitResult' ) . removeClass ( 'hidden' ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
$ ( "#confirmation_box" ) . fadeOut ( ) ;
$ ( "#gray_out" ) . fadeOut ( ) ;
} ,
type : "post" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/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 ) {
2019-02-13 08:46:18 +01:00
var uuid = selected ;
var type = additionalData . type ;
$ ( '#ObjectReferenceReferencedUuid' ) . val ( uuid ) ;
if ( type == "Attribute" ) {
$ ( '#targetData' ) . html ( "" ) ;
for ( var k in targetEvent [ type ] [ uuid ] ) {
if ( $ . inArray ( k , [ 'uuid' , 'category' , 'type' , 'value' , 'to_ids' ] ) !== - 1 ) {
$ ( '#targetData' ) . append ( '<div><span id="' + uuid + '_' + k + '_key" class="bold"></span>: <span id="' + uuid + '_' + k + '_data"></span></div>' ) ;
$ ( '#' + uuid + '_' + k + '_key' ) . text ( k ) ;
$ ( '#' + uuid + '_' + k + '_data' ) . text ( targetEvent [ type ] [ uuid ] [ k ] ) ;
}
}
} else {
$ ( '#targetData' ) . html ( "" ) ;
for ( var k in targetEvent [ type ] [ uuid ] ) {
if ( k == 'Attribute' ) {
$ ( '#targetData' ) . append ( '<br /><div><span id="header" class="bold">Attributes:</span>' ) ;
for ( attribute in targetEvent [ type ] [ uuid ] [ 'Attribute' ] ) {
for ( k2 in targetEvent [ type ] [ uuid ] [ 'Attribute' ] [ attribute ] ) {
if ( $ . inArray ( k2 , [ 'category' , 'type' , 'value' , 'to_ids' ] ) !== - 1 ) {
$ ( '#targetData' ) . append ( '<div class="indent"><span id="' + targetEvent [ type ] [ uuid ] [ 'Attribute' ] [ attribute ] [ 'uuid' ] + '_' + k2 + '_key" class="bold"></span>: <span id="' + targetEvent [ type ] [ uuid ] [ 'Attribute' ] [ attribute ] [ 'uuid' ] + '_' + k2 + '_data"></span></div>' ) ;
$ ( '#' + targetEvent [ type ] [ uuid ] [ 'Attribute' ] [ attribute ] [ 'uuid' ] + '_' + k2 + '_key' ) . text ( k2 ) ;
$ ( '#' + targetEvent [ type ] [ uuid ] [ 'Attribute' ] [ attribute ] [ 'uuid' ] + '_' + k2 + '_data' ) . text ( targetEvent [ type ] [ uuid ] [ 'Attribute' ] [ attribute ] [ k2 ] ) ;
}
}
$ ( '#targetData' ) . append ( '<br />' ) ;
}
} else {
if ( $ . inArray ( k , [ 'name' , 'uuid' , 'meta-category' ] ) !== - 1 ) {
$ ( '#targetData' ) . append ( '<div><span id="' + uuid + '_' + k + '_key" class="bold"></span>: <span id="' + uuid + '_' + k + '_data"></span></div>' ) ;
$ ( '#' + uuid + '_' + k + '_key' ) . text ( k ) ;
$ ( '#' + uuid + '_' + k + '_data' ) . text ( targetEvent [ type ] [ uuid ] [ k ] ) ;
}
}
}
}
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" ]
}
var warnings = [ ] ;
$ ( '#notice_message' ) . html ( '<h4>Notices:</h4>' ) ;
$ ( '#notice_message' ) . hide ( ) ;
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 ) {
$ ( '#notice_message' ) . show ( ) ;
$ ( '#notice_message' ) . append (
$ ( '<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
}
2020-03-08 23:36:27 +01:00
function quickSelect ( target ) {
var range = document . createRange ( ) ;
var selection = window . getSelection ( ) ;
range . selectNodeContents ( target ) ;
selection . removeAllRanges ( ) ;
selection . addRange ( range ) ;
}
2017-12-22 17:22:49 +01:00
$ ( document ) . ready ( 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' ) ;
}
} ) ;
2019-04-09 15:48:01 +02:00
$ ( ".queryPopover" ) . click ( function ( ) {
url = $ ( this ) . data ( 'url' ) ;
id = $ ( this ) . data ( 'id' ) ;
$ . get ( url + '/' + id , function ( data ) {
$ ( '#popover_form' ) . html ( data ) ;
openPopup ( '#popover_form' ) ;
} ) ;
} ) ;
$ ( '.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 ) ;
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
success : function ( data , textStatus ) {
handleGenericAjaxResponse ( data ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
type : "get" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + '/admin/roles/set_default/' + ( state ? id : "" ) ,
2019-04-09 15:48:01 +02:00
} ) ;
} ) ;
// clicking on an element with this class will select all of its contents in a
// single click
$ ( '.quickSelect' ) . click ( function ( ) {
2020-03-08 23:36:27 +01:00
quickSelect ( this ) ;
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 ) ;
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
$ ( '#setHomePage' ) . click ( function ( event ) {
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-06-26 10:12:00 +02:00
} ) ;
2020-10-07 09:33:53 +02:00
$ ( document . body ) . on ( "click" , ".correlation-expand-button" , function ( ) {
2020-06-26 10:12:00 +02:00
$ ( 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
} ) ;
2020-10-11 12:45:05 +02:00
// Send textarea form on CMD+ENTER or CTRL+ENTER
$ ( document . body ) . on ( 'keydown' , 'textarea' , function ( e ) {
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
}
}
} ) ;
2018-06-12 09:40:23 +02:00
function queryEventLock ( event _id , user _org _id ) {
2019-02-13 08:46:18 +01:00
if ( tabIsActive ) {
$ . ajax ( {
2020-08-16 13:31:31 +02:00
url : baseurl + "/events/checkLocks/" + event _id ,
2019-02-13 08:46:18 +01:00
type : "get" ,
success : function ( data , statusText , xhr ) {
if ( xhr . status == 200 ) {
if ( $ ( '#event_lock_warning' ) . length != 0 ) {
$ ( '#event_lock_warning' ) . remove ( ) ;
}
2019-04-24 11:39:00 +02:00
if ( data != '' ) {
2019-02-13 08:46:18 +01:00
$ ( '#main-view-container' ) . append ( data ) ;
}
}
}
} ) ;
}
setTimeout ( function ( ) { queryEventLock ( event _id , user _org _id ) ; } , 5000 ) ;
2018-06-12 09:40:23 +02:00
}
2018-06-12 16:09:50 +02:00
function checkIfLoggedIn ( ) {
2019-02-13 08:46:18 +01:00
if ( tabIsActive ) {
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 ) {
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>' ;
} ) ;
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 ( ) ) ;
} ) ;
$ . ajax ( {
beforeSend : function ( XMLHttpRequest ) {
$ ( ".loading" ) . show ( ) ;
} ,
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.' ] } ) ;
} ,
complete : function ( ) {
$ ( ".loading" ) . hide ( ) ;
} ,
type : "post" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + "/feeds/feedCoverage/" + feedId ,
2019-03-10 18:09:46 +01:00
} ) ;
}
2019-03-19 15:59:31 +01:00
function changeTaxonomyRequiredState ( checkbox ) {
var checkbox _state = $ ( checkbox ) . is ( ":checked" ) ;
var taxonomy _id = $ ( checkbox ) . data ( 'taxonomy-id' ) ;
2020-08-16 13:31:31 +02:00
fetchFormDataAjax ( baseurl + '/taxonomies/toggleRequired/' + taxonomy _id , function ( formData ) {
2019-06-07 14:44:39 +02:00
$ . ajax ( {
data : $ ( formData ) . serialize ( ) ,
success : function ( data , textStatus ) {
handleGenericAjaxResponse ( { 'saved' : true , 'success' : [ 'Taxonomy\'s required state toggled.' ] } ) ;
} ,
error : function ( ) {
$ ( checkbox ) . prop ( 'checked' , ! $ ( checkbox ) . prop ( 'checked' ) ) ;
handleGenericAjaxResponse ( { 'saved' : false , 'errors' : [ 'Could not toggle the required state of the taxonomy.' ] } ) ;
} ,
async : "false" ,
type : "post" ,
cache : false ,
2020-08-16 13:31:31 +02:00
url : baseurl + '/taxonomies/toggleRequired/' + taxonomy _id ,
2019-06-07 14:44:39 +02:00
} ) ;
2019-03-19 15:59:31 +01:00
} ) ;
2019-03-20 11:21:40 +01:00
}
2019-06-07 14:44:39 +02:00
function fetchFormDataAjax ( url , callback ) {
2019-03-20 11:21:40 +01:00
var formData = false ;
2019-03-19 15:59:31 +01:00
$ . ajax ( {
2019-03-20 11:21:40 +01:00
data : '[]' ,
2019-03-19 15:59:31 +01:00
success : function ( data , textStatus ) {
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.' ] } ) ;
2019-03-19 15:59:31 +01:00
} ,
2019-03-20 11:21:40 +01:00
async : false ,
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 ( {
url : baseurl + '/servers/viewDeprecatedFunctionUse' ,
type : 'GET' ,
success : function ( data ) {
$ ( '#deprecationResults' ) . html ( data ) ;
} ,
error : function ( data ) {
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 != '' ) {
configData = JSON . parse ( configData ) ;
} 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' ) ;
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 23:55:46 +01:00
if ( config !== '' ) {
config = JSON . parse ( config ) ;
2020-03-10 10:58:41 +01:00
config = JSON . stringify ( config ) ;
} else {
config = '[]' ;
2020-03-01 23:55:46 +01:00
}
2020-03-01 19:03:31 +01:00
$ ( '#widget_' + ( k + 1 ) ) . attr ( 'config' , config ) ;
saveDashboardState ( ) ;
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 = [ ] ;
$ ( '.grid-stack-item' ) . each ( function ( index ) {
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 ) ;
}
} ) ;
$ . ajax ( {
data : { value : dashBoardSettings } ,
success : function ( data , textStatus ) {
showMessage ( 'success' , 'Dashboard settings saved.' ) ;
} ,
error : function ( jqXHR , textStatus , errorThrown ) {
showMessage ( 'fail' , textStatus + ": " + errorThrown ) ;
} ,
type : "post" ,
url : baseurl + '/dashboards/updateSettings' ,
} ) ;
}
function updateDashboardWidget ( element ) {
2020-03-10 10:58:41 +01:00
element = $ ( element ) ;
if ( element . length ) {
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' ) ) ;
if ( temp [ 'alias' ] !== undefined ) {
titleText . text ( temp [ 'alias' ] ) ;
}
$ . ajax ( {
type : 'POST' ,
url : baseurl + '/dashboards/renderWidget/' + container _id ,
data : {
config : $ ( element ) . attr ( 'config' ) ,
widget : $ ( element ) . attr ( 'widget' )
} ,
success : function ( data , textStatus ) {
container . html ( data ) ;
}
} ) ;
2020-03-01 18:05:21 +01:00
}
}
2020-03-10 11:34:30 +01:00
function resetDashboardGrid ( grid ) {
$ ( '.grid-stack-item' ) . each ( function ( ) {
updateDashboardWidget ( this ) ;
} ) ;
saveDashboardState ( ) ;
$ ( '.edit-widget' ) . click ( function ( ) {
el = $ ( this ) . closest ( '.grid-stack-item' ) ;
data = {
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 ( ) {
el = $ ( this ) . closest ( '.grid-stack-item' ) ;
grid . removeWidget ( el ) ;
saveDashboardState ( ) ;
} ) ;
}
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' ,
success : function ( data , textStatus ) {
2020-07-13 12:19:11 +02:00
$ ( '#ajax_hidden_container' ) . html ( data ) ;
var currentPage = $ ( '#setHomePage' ) . data ( 'current-page' ) ;
$ ( '#UserSettingPath' ) . val ( currentPage ) ;
$ . ajax ( {
type : 'POST' ,
url : baseurl + '/userSettings/setHomePage' ,
data : $ ( '#UserSettingSetHomePageForm' ) . serialize ( ) ,
success : function ( data , textStatus ) {
showMessage ( 'success' , 'Homepage set.' ) ;
$ ( '#setHomePage' ) . addClass ( 'orange' ) ;
} ,
} ) ;
}
2020-03-01 18:05:21 +01:00
} ) ;
}
2020-03-12 11:10:11 +01:00
function changeLocationFromIndexDblclick ( row _index ) {
2020-04-09 11:01:53 +02:00
var href = $ ( 'table tr[data-row-id=\"' + row _index + '\"] .dblclickActionElement' ) . attr ( 'href' )
2020-03-12 11:10:11 +01:00
window . location = href ;
}
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
2020-09-26 18:26:01 +02:00
$ ( 'body' ) . on ( 'click' , '.hex-value-convert' , function ( ) {
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' ) ;
}
} ) ;