<div style="margin-top: 35px;">
	<button class="btn btn-secondary" data-job="{{ job_id }}" id="jobConfiginitial">
        Конфиг
    </button>

    <button type="button" class="btn btn-secondary" id="online_stop_button">
          Остановить
	</button> 
	<div class="input-group" id="online_stop__dialog" style="display: none;">
  		<span class="input-group-addon" id="basic-addon3">
           Остановить?
        </span>
        <span class="input-group-btn">
	        <button type="button" class="btn btn-danger" id="online_stop__ok" data-job="{{ job_id }}">
	                     Да
	        </button>
	        <button type="button" class="btn btn-secondary" id="online_stop__cancel">
	                     Нет
			</button>
		</span>
	</div>
	
	<div id="onlinestop_krutilka" style="display: none; margin-top: 35px; margin-left: 10px;">
        <i class="b-lunapark-onlinepage__loading_img krutilka fa fa-circle-o-notch fa-spin" aria-hidden="true"></i>&ensp;Остановка стрельбы ...
	</div>
</div>

<div class="modal fade" id="configModal" tabindex="-1" role="dialog" aria-labelledby="configModalLabel">
 		<div class="modal-dialog" role="document">
  			<div class="modal-content">
			<div class="modal-header">
                <span id="configTitle"></span>
			</div>
			<div class="modal-body">
                <span id="configContents"></span>
		    </div>
  			</div>
  		</div>
</div>

<script nonce='{{ common.CSP_SCRIPT_NONCE }}'>
    /*
	 * CONFIG BUTTON
	 */
	$('#jobConfiginitial').on('click', function(event){
	    var job = $(this).data('job'),
	        configTitle = $('#configTitle'),
            configContents = $('#configContents'),
	        modal = $('#configModal');
        $.get('/api/job/'+job+'/configinitial.txt', function(data_initial){
            if (data_initial) {
                configTitle.text('Исходный конфиг стрельбы');
                configContents.text(data_initial);
                modal.modal('show');
            } else {
                $.get('/api/job/'+job+'/configinfo.txt', function(data){
                    if (data) {
                        configTitle.text('Конфиг стрельбы');
                        configContents.text(data_initial);
                        modal.modal('show');
                    } else {
                        configTitle.text('В конфиге пусто');
                        modal.modal('show');
                    }
                })
            }
        })
    });
	/*
	 * STOP BUTTON
	 */
	$('#online_stop_button').on('click', function(event) {
		$(this).hide();
		$('#online_stop__dialog').show()
	});
	
	$('#online_stop__cancel').on('click', function(event) {
		$('#online_stop__dialog').hide();
		$('#online_stop_button').show()
	});
	
	$('#online_stop__ok').on('click', function(event) {
		var job = $(this).data('job');
		$('#online_stop__dialog').hide();
		$('#onlinestop_krutilka').show();
		$.ajax({
			url : '/api/jobclose_frontend?job_n=' + job,
			type : 'GET',
			async: false,
			success: function(){
				window.location = '/' + job
			},
			error: function(){
				console.log('errir!');
				$('#onlinestop_krutilka').hide();
				$('#online_stop_button').show()
			}
		})
	})
	
</script>