2017-07-07 23:44:48 -07:00
@ extends ( 'layouts/default' )
{{ -- Page title -- }}
@ section ( 'title' )
2021-11-19 06:23:48 -08:00
{{ trans ( 'admin/settings/general.slack_title' ) }}
2017-07-07 23:44:48 -07:00
@ parent
@ stop
@ section ( 'header_right' )
2020-04-01 03:21:15 -07:00
< a href = " { { route('settings.index') }} " class = " btn btn-primary " > {{ trans ( 'general.back' ) }} </ a >
2017-07-07 23:44:48 -07:00
@ stop
{{ -- Page content -- }}
@ section ( 'content' )
< style >
. checkbox label {
padding - right : 40 px ;
}
</ style >
2017-10-17 17:18:17 -07:00
{{ Form :: open ([ 'method' => 'POST' , 'files' => false , 'autocomplete' => 'off' , 'class' => 'form-horizontal' , 'role' => 'form' ]) }}
2017-07-07 23:44:48 -07:00
<!-- CSRF Token -->
{{ csrf_field ()}}
< div class = " row " >
< div class = " col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 " >
< div class = " panel box box-default " >
< div class = " box-header with-border " >
2020-04-01 03:21:15 -07:00
< h2 class = " box-title " >
2021-11-19 06:23:48 -08:00
< i class = " fab fa-slack " ></ i > {{ trans ( 'admin/settings/general.slack' ) }}
2020-04-01 03:21:15 -07:00
</ h2 >
2017-07-07 23:44:48 -07:00
</ div >
< div class = " box-body " >
2018-10-05 00:57:18 -07:00
< p style = " padding: 20px; " >
2018-02-22 16:35:34 -08:00
{ !! trans ( 'admin/settings/general.slack_integration_help' , array ( 'slack_link' => 'https://my.slack.com/services/new/incoming-webhook' )) !! }
2018-02-22 21:47:36 -08:00
@ if (( $setting -> slack_channel == '' ) && ( $setting -> slack_endpoint == '' ))
{{ trans ( 'admin/settings/general.slack_integration_help_button' ) }}
@ endif
</ p >
2018-02-22 16:35:34 -08:00
2020-09-15 23:14:10 -07:00
< div class = " col-md-12 " style = " border-top: 0px; " >
2017-07-07 23:44:48 -07:00
<!-- slack endpoint -->
2020-09-16 12:29:20 -07:00
< div class = " form-group required { { $errors->has ('slack_endpoint') ? 'error' : '' }} " >
2020-09-15 23:14:10 -07:00
< div class = " col-md-2 " >
2017-07-07 23:44:48 -07:00
{{ Form :: label ( 'slack_endpoint' , trans ( 'admin/settings/general.slack_endpoint' )) }}
</ div >
2020-09-15 23:14:10 -07:00
< div class = " col-md-10 " >
2017-07-07 23:44:48 -07:00
@ if ( config ( 'app.lock_passwords' ) === true )
2020-11-10 08:36:18 -08:00
{{ Form :: text ( 'slack_endpoint' , old ( 'slack_endpoint' , $setting -> slack_endpoint ), array ( 'class' => 'form-control' , 'disabled' => 'disabled' , 'placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX' , 'id' => 'slack_endpoint' )) }}
2021-09-26 01:11:08 -07:00
< p class = " text-warning " >< i class = " fas fa-lock " ></ i > {{ trans ( 'general.feature_disabled' ) }} </ p >
2020-09-16 12:36:33 -07:00
2017-07-07 23:44:48 -07:00
@ else
2020-11-10 08:36:18 -08:00
{{ Form :: text ( 'slack_endpoint' , old ( 'slack_endpoint' , $setting -> slack_endpoint ), array ( 'class' => 'form-control' , 'placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX' , 'id' => 'slack_endpoint' )) }}
2017-07-07 23:44:48 -07:00
@ endif
2020-04-01 03:21:15 -07:00
{ !! $errors -> first ( 'slack_endpoint' , '<span class="alert-msg" aria-hidden="true">:message</span>' ) !! }
2017-07-07 23:44:48 -07:00
</ div >
</ div >
<!-- slack channel -->
2020-09-16 12:29:20 -07:00
< div class = " form-group required { { $errors->has ('slack_channel') ? 'error' : '' }} " >
2020-09-15 23:14:10 -07:00
< div class = " col-md-2 " >
2017-07-07 23:44:48 -07:00
{{ Form :: label ( 'slack_channel' , trans ( 'admin/settings/general.slack_channel' )) }}
</ div >
2020-09-15 23:14:10 -07:00
< div class = " col-md-10 " >
2017-07-07 23:44:48 -07:00
@ if ( config ( 'app.lock_passwords' ) === true )
2020-11-10 08:36:18 -08:00
{{ Form :: text ( 'slack_channel' , old ( 'slack_channel' , $setting -> slack_channel ), array ( 'class' => 'form-control' , 'disabled' => 'disabled' , 'placeholder' => '#IT-Ops' )) }}
2021-09-26 01:11:08 -07:00
< p class = " text-warning " >< i class = " fas fa-lock " ></ i > {{ trans ( 'general.feature_disabled' ) }} </ p >
2020-09-16 12:36:33 -07:00
2017-07-07 23:44:48 -07:00
@ else
2020-11-10 08:36:18 -08:00
{{ Form :: text ( 'slack_channel' , old ( 'slack_channel' , $setting -> slack_channel ), array ( 'class' => 'form-control' , 'placeholder' => '#IT-Ops' )) }}
2017-07-07 23:44:48 -07:00
@ endif
2020-04-01 03:21:15 -07:00
{ !! $errors -> first ( 'slack_channel' , '<span class="alert-msg" aria-hidden="true">:message</span>' ) !! }
2017-07-07 23:44:48 -07:00
</ div >
</ div >
<!-- slack botname -->
2020-09-16 12:29:20 -07:00
< div class = " form-group required { { $errors->has ('slack_botname') ? 'error' : '' }} " >
2020-09-15 23:14:10 -07:00
< div class = " col-md-2 " >
2017-07-07 23:44:48 -07:00
{{ Form :: label ( 'slack_botname' , trans ( 'admin/settings/general.slack_botname' )) }}
</ div >
2020-09-15 23:14:10 -07:00
< div class = " col-md-10 " >
2017-07-07 23:44:48 -07:00
@ if ( config ( 'app.lock_passwords' ) === true )
2020-11-10 08:36:18 -08:00
{{ Form :: text ( 'slack_botname' , old ( 'slack_botname' , $setting -> slack_botname ), array ( 'class' => 'form-control' , 'disabled' => 'disabled' , 'placeholder' => 'Snipe-Bot' )) }}
2021-09-26 01:11:08 -07:00
< p class = " text-warning " >< i class = " fas fa-lock " ></ i > {{ trans ( 'general.feature_disabled' ) }} </ p >
2020-09-16 12:36:33 -07:00
2017-07-07 23:44:48 -07:00
@ else
2020-11-10 08:36:18 -08:00
{{ Form :: text ( 'slack_botname' , old ( 'slack_botname' , $setting -> slack_botname ), array ( 'class' => 'form-control' , 'placeholder' => 'Snipe-Bot' )) }}
2017-07-07 23:44:48 -07:00
@ endif
2020-04-01 03:21:15 -07:00
{ !! $errors -> first ( 'slack_botname' , '<span class="alert-msg" aria-hidden="true">:message</span>' ) !! }
2017-07-07 23:44:48 -07:00
</ div >
</ div >
2020-09-16 13:15:39 -07:00
< div class = " form-group " id = " slacktestcontainer " style = " display: none " >
2020-09-15 23:14:10 -07:00
< div class = " col-md-2 " >
{{ Form :: label ( 'test_slack' , 'Test Slack' ) }}
2018-02-22 16:35:34 -08:00
</ div >
2020-09-15 23:14:10 -07:00
< div class = " col-md-10 " id = " slacktestrow " >
2021-09-26 01:11:08 -07:00
< a class = " btn btn-default btn-sm pull-left " id = " slacktest " style = " margin-right: 10px; " > Test < i class = " fab fa-slack " ></ i > Integration </ a >
2018-02-22 16:35:34 -08:00
</ div >
2020-09-15 23:14:10 -07:00
< div class = " col-md-10 col-md-offset-2 " >
2018-02-22 16:35:34 -08:00
< span id = " slacktesticon " ></ span >
< span id = " slacktestresult " ></ span >
< span id = " slackteststatus " ></ span >
</ div >
2020-09-15 23:14:10 -07:00
2017-07-07 23:44:48 -07:00
2018-02-22 16:35:34 -08:00
</ div >
</ div > <!--/-->
2017-07-07 23:44:48 -07:00
</ div > <!--/. box - body -->
< div class = " box-footer " >
< div class = " text-left col-md-6 " >
< a class = " btn btn-link text-left " href = " { { route('settings.index') }} " > {{ trans ( 'button.cancel' ) }} </ a >
</ div >
< div class = " text-right col-md-6 " >
2021-09-26 01:11:08 -07:00
< button type = " submit " id = " save_slack " class = " btn btn-primary " disabled >< i class = " fas fa-check icon-white " aria - hidden = " true " ></ i > {{ trans ( 'general.save' ) }} </ button >
2017-07-07 23:44:48 -07:00
</ div >
</ div >
</ div > <!-- / box -->
</ div > <!-- /. col - md - 8 -->
</ div > <!-- /. row -->
{{ Form :: close ()}}
@ stop
2018-02-22 16:35:34 -08:00
2020-09-15 23:14:10 -07:00
@ push ( 'js' )
2018-02-22 16:35:34 -08:00
< script nonce = " { { csrf_token() }} " >
2020-09-16 13:15:39 -07:00
var fieldcheck = function ( event ) {
if ( $ ( '#slack_endpoint' ) . val () != " " && $ ( '#slack_channel' ) . val () != " " && $ ( '#slack_botname' ) . val () != " " ) {
//enable test button *only* if all three fields are filled in
$ ( '#slacktestcontainer' ) . fadeIn ( 500 );
} else {
//otherwise it's hidden
$ ( '#slacktestcontainer' ) . fadeOut ( 500 );
}
if ( event ) { //on 'initial load' we don't *have* an 'event', but in the regular keyup callback, we *do*. So this only fires on 'real' callback events, not on first load
if ( $ ( '#slack_endpoint' ) . val () == " " && $ ( '#slack_channel' ) . val () == " " && $ ( '#slack_botname' ) . val () == " " ) {
// if all three fields are blank, the user may want to disable Slack integration; enable the Save button
$ ( '#save_slack' ) . removeAttr ( 'disabled' );
}
}
};
fieldcheck (); //run our field-checker once on page-load to set the initial state correctly.
2020-09-15 23:14:10 -07:00
2020-09-16 13:15:39 -07:00
$ ( 'input:text' ) . keyup ( fieldcheck ); // if *any* text field changes, we recalculate button states
2020-09-15 23:14:10 -07:00
2018-02-22 16:35:34 -08:00
$ ( " #slacktest " ) . click ( function () {
2020-09-16 12:29:20 -07:00
2018-02-22 16:35:34 -08:00
$ ( " #slacktestrow " ) . removeClass ( 'text-success' );
$ ( " #slacktestrow " ) . removeClass ( 'text-danger' );
$ ( " #slackteststatus " ) . removeClass ( 'text-danger' );
$ ( " #slackteststatus " ) . html ( '' );
2021-11-19 06:23:48 -08:00
$ ( " #slacktesticon " ) . html ( '<i class="fas fa-spinner spin"></i> {{ trans(' admin / settings / message . slack . sending ') }}' );
2018-02-22 16:35:34 -08:00
$ . ajax ({
2021-12-16 14:38:04 -08:00
2021-12-08 17:58:46 -08:00
// If I comment this back in, I always get a success (200) message
// Without it, I get
// beforeSend: function (xhr) {
// xhr.setRequestHeader("Content-Type","application/json");
// xhr.setRequestHeader("Accept","text/json");
// },
2021-12-08 15:56:05 -08:00
2021-12-08 17:58:46 -08:00
2018-02-22 16:35:34 -08:00
url : '{{ route(' api . settings . slacktest ') }}' ,
type : 'POST' ,
headers : {
" X-Requested-With " : 'XMLHttpRequest' ,
2021-12-08 15:56:05 -08:00
" X-CSRF-TOKEN " : $ ( 'meta[name="csrf-token"]' ) . attr ( 'content' ),
2021-12-08 17:58:46 -08:00
// 'Accept': 'application/json',
// 'Content-Type': 'application/json',
2018-02-22 16:35:34 -08:00
},
data : {
2020-09-15 23:14:10 -07:00
'slack_endpoint' : $ ( '#slack_endpoint' ) . val (),
'slack_channel' : $ ( '#slack_channel' ) . val (),
'slack_botname' : $ ( '#slack_botname' ) . val (),
2018-02-22 16:35:34 -08:00
},
dataType : 'json' ,
2021-12-08 15:56:05 -08:00
accepts : {
text : " application/json "
},
2018-02-22 16:35:34 -08:00
success : function ( data ) {
2020-09-15 23:14:10 -07:00
$ ( '#save_slack' ) . removeAttr ( 'disabled' );
2018-02-22 16:35:34 -08:00
$ ( " #slacktesticon " ) . html ( '' );
$ ( " #slacktestrow " ) . addClass ( 'text-success' );
$ ( " #slackteststatus " ) . addClass ( 'text-success' );
2021-11-19 06:23:48 -08:00
//TODO: This is a bit hacky...Might need some cleanup
$ ( " #slackteststatus " ) . html ( '<i class="fas fa-check text-success"></i> {{ trans(' admin / settings / message . slack . success_pt1 ') }} ' + $ ( '#slack_channel' ) . val () + '{{ trans(' admin / settings / message . slack . success_pt2 ') }}' );
2018-02-22 16:35:34 -08:00
},
error : function ( data ) {
2020-09-15 23:14:10 -07:00
2018-02-22 16:35:34 -08:00
if ( data . responseJSON ) {
2021-12-06 11:40:24 -08:00
var errors = data . responseJSON . errors ;
var error_msg = data . responseJSON . message ;
2018-02-22 16:35:34 -08:00
} else {
var errors ;
2021-12-06 11:40:24 -08:00
var error_msg = 'Something went wrong.' ;
2018-02-22 16:35:34 -08:00
}
var error_text = '' ;
2020-09-15 23:14:10 -07:00
$ ( '#save_slack' ) . attr ( " disabled " , true );
2018-02-22 16:35:34 -08:00
$ ( " #slacktesticon " ) . html ( '' );
$ ( " #slackteststatus " ) . addClass ( 'text-danger' );
2021-12-06 11:40:24 -08:00
$ ( " #slacktesticon " ) . html ( '<i class="fas fa-exclamation-triangle text-danger"></i><span class="text-danger">' + error_msg + '</span>' );
2018-02-22 16:35:34 -08:00
2021-12-06 11:40:24 -08:00
2018-02-22 16:35:34 -08:00
if ( data . status == 500 ) {
2021-11-19 06:23:48 -08:00
$ ( '#slackteststatus' ) . html ( '{{ trans(' admin / settings / message . slack . 500 ') }}' );
2021-12-06 11:40:24 -08:00
} else if (( data . status == 400 ) || ( data . status == 422 )) {
2021-12-14 10:48:59 -08:00
// TODO: Needs translation
2021-12-06 11:40:24 -08:00
console . log ( 'Type of errors is ' + typeof errors );
console . log ( 'Data status was 400 or 422' );
2018-02-22 16:35:34 -08:00
if ( typeof errors != 'string' ) {
2021-12-06 11:40:24 -08:00
console . log ( errors . length );
2018-02-22 16:35:34 -08:00
2021-12-06 11:40:24 -08:00
for ( i in errors ) {
2018-02-22 16:35:34 -08:00
if ( errors [ i ]) {
error_text += '<li>Error: ' + errors [ i ];
}
}
} else {
2021-12-06 11:40:24 -08:00
2018-02-22 16:35:34 -08:00
error_text = errors ;
}
$ ( '#slackteststatus' ) . html ( error_text );
} else {
$ ( '#slackteststatus' ) . html ( data . responseText . message );
}
}
});
2020-09-16 13:15:39 -07:00
return false ;
2018-02-22 16:35:34 -08:00
});
</ script >
2020-09-15 23:14:10 -07:00
@ endpush