<commit_before><?
	$support = $this->support;
	$order = $support->order();

	$this->title = 'Support';
	$this->titleicon = 'comments';
	$this->titleLink = '/support/plus';
	
	$this->title2 = 'Issue #'.$this->support->id_support;
	$this->title2icon = 'warning-sign';

?>

<!-- support page -->
<div class="container-fluid padded">
	<div class="row-fluid">
		<div class="span6">
			<?=$this->display('support/plus/info')?>
			<?=$this->display('support/plus/update')?>
			<?=$this->display('support/plus/actions')?>
		</div>
		<div class="span6">
			<?=$this->display('support/plus/conversation')?>
			<?=$this->display('support/plus/addnote')?>
		</div>
	</div>
</div>
<!-- // end support page -->

<script>
/* Shows the feedbacks */
function showAlert( box, css, message ){
	var alert = $( box );
	alert.removeClass( 'alert-error' );
	alert.removeClass( 'alert-success' );
	alert.addClass( 'alert-' + css );
	alert.find( '.alert-message' ).html( message );
	alert.show();
	setTimeout( function(){
		$( '.alert' ).hide();
	}, 3000 );
}

/* Update the Log history */
function updateConversationHistory(){
	var url = '/support/plus/<?php echo $support->id_support; ?>/history';
	$.ajax( {
		url: url
	} ).done( function( content ) {
		$( '#history' ).html( content );
		setTimeout( function(){
			var box = $( '.chat-box-wrapper' );
			box.animate( { scrollTop: box[0].scrollHeight + 300 }, 100 );
		}, 10 );
	} );
}

$(function() {

	/* Control the conversation's filter */
	$( '.show-conversation' ).on( 'ifChanged', function( event ){
		var allChecked = true;
		var checkbox = $( this );
		/* If the user choose show-all check all */
		if( checkbox.attr( 'id' ) == 'show-all' && checkbox.is( ':checked' ) ){
			allChecked = true;
			$( '.show-conversation' ).iCheck( 'check' );
		} else {
			$( '#show-system, #show-client, #show-rep' ).each( function(){
				var checkbox = $( this );
				if( !checkbox.is( ':checked' ) ){
					allChecked = false;
				}
			} );
			if( allChecked ){
				$( '.show-conversation' ).iCheck( 'check' );
			} else {
				$( '#show-all' ).iCheck( 'uncheck' );
			}
		}
		/* Apply the filter */
		$( '.show-conversation' ).each( function(){
			var checkbox = $( this );
			var css = '.conversation-' + checkbox.val();
			if( checkbox.is( ':checked' ) ){
				$( css ).show();
			} else {
				$( css ).hide();
			}
		} ); 
	} );

	/* Form reply conversation */
	$( document ).on( 'click', '.btn-conversation-reply', function(){

		var text = $( '#text-conversation-reply' );
		var val = text.val();

		if( $.trim( val ) == '' ){
			alert( 'Please type the text!' );
			text.focus();
			return;
		}

		text.val( 'Sending...' );
		text.prop( 'enabled', false );
		
		$.post('/support/plus/<?php echo $support->id_support; ?>/conversation', {
			text: val
		}, function( ) {
			text.prop( 'enabled',true );
			text.val( '' );
			updateConversationHistory();
		} );
		return;
	} );

	/* Show the hidden field */
	$( document ).on( 'change', '#user_perspective', function(){
		if( $( this ).val() == 'Other' ){
			$( ".user_perspective_other" ).show();		
		} else {
			$( ".user_perspective_other" ).hide();
		}
	} );

	/* Form update */
	$(document).on('click', '.button-update', function() {
		
		$( '.alert' ).hide();

		var fault_of = $( '#fault_of' ).val();
		var customer_happy = ( $('#customer_happy').is(':checked') ? 1 : 0 );
		var status = ( $('#status').is(':checked') ? 'open' : 'closed' );
		var id_github = $( '#id_github' ).val();
		var description_client = $( '#description_client' ).val();
		var description_cb = $( '#description_cb' ).val();
		var user_perspective = $( '#user_perspective' ).val();
		var user_perspective_other = $( '#user_perspective_other' ).val();
		var how_to_prevent = $( '#how_to_prevent' ).val();
		var id_restaurant = $( '#id_restaurant' ).val();

		var data = { 
								'status' : status,
								'fault_of' : fault_of,
								'customer_happy' : customer_happy,
								'id_restaurant' : id_restaurant,
								'id_github' : id_github,
								'description_client' : description_client,
								'description_cb' : description_cb,
								'user_perspective' : user_perspective,
								'user_perspective_other' : user_perspective_other,
								'how_to_prevent' : how_to_prevent
							};

		var url = '/support/plus/<?php echo $support->id_support; ?>/update';
		$.ajax({
			type: 'POST',
			dataType: 'json',
			data: data,
			url: url,
			success: function(content) {
				showAlert( '.alert-update', 'success', '<strong>Ok!</strong> Support saved!' );
				updateConversationHistory();
			},
			error: function( ){
				showAlert( '.alert-update', 'error', '<strong>Oops!</strong> Failed to save, please try it again' );
				updateConversationHistory();
			}
		});
	} );

	/* Form add note */
	$(document).on('click', '.button-add-note', function() {
		
		$( '.alert' ).hide();

		if( $( '.add-note-field' ).css('display') != 'none' ){
			var text = $( '#add-note-text' );
			var val = text.val();
			if( $.trim( val ) == '' ){
				alert( 'Please type the text!' );
				text.focus();
				return;
			}
			text.val( 'Sending...' );
			text.prop( 'enabled', false );

			$.post(' /support/plus/<?php echo $support->id_support; ?>/note', {
				text: val
			}, function( ) {
				text.prop( 'enabled',true );
				text.val( '' );
				updateConversationHistory();
				$( '.add-note-field' ).hide();
				$( '.button-add-note' ).html( $( '.button-add-note' ).attr( 'text-backup' ) );
				showAlert( '.alert-note', 'success', '<strong>Ok!</strong> Note saved!' );
			} );

		} else {
			$( '.add-note-field' ).show();
			$( '.button-add-note' ).attr( 'text-backup', $( '.button-add-note' ).html() );
			$( '.button-add-note' ).html( 'Save note' );
		}

	} );

	/* Button refund */
	$(document).on('click', '.button-refund', function() {
		
		$( '.alert' ).hide();

		var el = $( this );
		var parent = el.parent();

		var question = 'Are you sure you want to refund this?';
		if( parseFloat( el.attr( 'data-gift' ) ) > 0 ){
			question += "\n";
			question += 'A gift card was used at this order the refund value will be $' + el.attr( 'data-charged' ) + ' + $' + el.attr( 'data-gift' ) + ' as gift card.' ;
		}
		if (!confirm( question )) {
			return;
		}
		
		var button = parent.html();
		
		parent.html( '<i class="icon-cogs"></i> Processing' );
		
		$.getJSON('/api/order/' + el.attr('data-uuid') + '/refund', function( json ) {
			showAlert( '.alert-refund', 'success', '<strong>Ok!</strong> Order refunded!' );
			parent.html( '<b>Order refunded.</b>' );
			updateConversationHistory();
		});
	});

	var restaurants = [];
	<? foreach (Restaurant::q('select * from restaurant where active=1 order by name') as $restaurant) : ?>
		restaurants.push({
			id: '<?=$restaurant->id_restaurant?>',
			text: '<?=str_replace("'","\'",$restaurant->name)?>'
		});
	<? endforeach ; ?>

	$('.editable-restaurants').editable({
		inputclass: "input-large",
		source: restaurants
	});

	updateConversationHistory();

});
</script><commit_msg>changed the position of the box actions<commit_after><?
	$support = $this->support;
	$order = $support->order();

	$this->title = 'Support';
	$this->titleicon = 'comments';
	$this->titleLink = '/support/plus';
	
	$this->title2 = 'Issue #'.$this->support->id_support;
	$this->title2icon = 'warning-sign';

?>

<!-- support page -->
<div class="container-fluid padded">
	<div class="row-fluid">
		<div class="span6">
			<?=$this->display('support/plus/info')?>
			<?=$this->display('support/plus/actions')?>
			<?=$this->display('support/plus/update')?>
		</div>
		<div class="span6">
			<?=$this->display('support/plus/conversation')?>
			<?=$this->display('support/plus/addnote')?>
		</div>
	</div>
</div>
<!-- // end support page -->

<script>
/* Shows the feedbacks */
function showAlert( box, css, message ){
	var alert = $( box );
	alert.removeClass( 'alert-error' );
	alert.removeClass( 'alert-success' );
	alert.addClass( 'alert-' + css );
	alert.find( '.alert-message' ).html( message );
	alert.show();
	setTimeout( function(){
		$( '.alert' ).hide();
	}, 3000 );
}

/* Update the Log history */
function updateConversationHistory(){
	var url = '/support/plus/<?php echo $support->id_support; ?>/history';
	$.ajax( {
		url: url
	} ).done( function( content ) {
		$( '#history' ).html( content );
		setTimeout( function(){
			var box = $( '.chat-box-wrapper' );
			box.animate( { scrollTop: box[0].scrollHeight + 300 }, 100 );
		}, 10 );
	} );
}

$(function() {

	/* Control the conversation's filter */
	$( '.show-conversation' ).on( 'ifChanged', function( event ){
		var allChecked = true;
		var checkbox = $( this );
		/* If the user choose show-all check all */
		if( checkbox.attr( 'id' ) == 'show-all' && checkbox.is( ':checked' ) ){
			allChecked = true;
			$( '.show-conversation' ).iCheck( 'check' );
		} else {
			$( '#show-system, #show-client, #show-rep' ).each( function(){
				var checkbox = $( this );
				if( !checkbox.is( ':checked' ) ){
					allChecked = false;
				}
			} );
			if( allChecked ){
				$( '.show-conversation' ).iCheck( 'check' );
			} else {
				$( '#show-all' ).iCheck( 'uncheck' );
			}
		}
		/* Apply the filter */
		$( '.show-conversation' ).each( function(){
			var checkbox = $( this );
			var css = '.conversation-' + checkbox.val();
			if( checkbox.is( ':checked' ) ){
				$( css ).show();
			} else {
				$( css ).hide();
			}
		} ); 
	} );

	/* Form reply conversation */
	$( document ).on( 'click', '.btn-conversation-reply', function(){

		var text = $( '#text-conversation-reply' );
		var val = text.val();

		if( $.trim( val ) == '' ){
			alert( 'Please type the text!' );
			text.focus();
			return;
		}

		text.val( 'Sending...' );
		text.prop( 'enabled', false );
		
		$.post('/support/plus/<?php echo $support->id_support; ?>/conversation', {
			text: val
		}, function( ) {
			text.prop( 'enabled',true );
			text.val( '' );
			updateConversationHistory();
		} );
		return;
	} );

	/* Show the hidden field */
	$( document ).on( 'change', '#user_perspective', function(){
		if( $( this ).val() == 'Other' ){
			$( ".user_perspective_other" ).show();		
		} else {
			$( ".user_perspective_other" ).hide();
		}
	} );

	/* Form update */
	$(document).on('click', '.button-update', function() {
		
		$( '.alert' ).hide();

		var fault_of = $( '#fault_of' ).val();
		var customer_happy = ( $('#customer_happy').is(':checked') ? 1 : 0 );
		var status = ( $('#status').is(':checked') ? 'open' : 'closed' );
		var id_github = $( '#id_github' ).val();
		var description_client = $( '#description_client' ).val();
		var description_cb = $( '#description_cb' ).val();
		var user_perspective = $( '#user_perspective' ).val();
		var user_perspective_other = $( '#user_perspective_other' ).val();
		var how_to_prevent = $( '#how_to_prevent' ).val();
		var id_restaurant = $( '#id_restaurant' ).val();

		var data = { 
								'status' : status,
								'fault_of' : fault_of,
								'customer_happy' : customer_happy,
								'id_restaurant' : id_restaurant,
								'id_github' : id_github,
								'description_client' : description_client,
								'description_cb' : description_cb,
								'user_perspective' : user_perspective,
								'user_perspective_other' : user_perspective_other,
								'how_to_prevent' : how_to_prevent
							};

		var url = '/support/plus/<?php echo $support->id_support; ?>/update';
		$.ajax({
			type: 'POST',
			dataType: 'json',
			data: data,
			url: url,
			success: function(content) {
				showAlert( '.alert-update', 'success', '<strong>Ok!</strong> Support saved!' );
				updateConversationHistory();
			},
			error: function( ){
				showAlert( '.alert-update', 'error', '<strong>Oops!</strong> Failed to save, please try it again' );
				updateConversationHistory();
			}
		});
	} );

	/* Form add note */
	$(document).on('click', '.button-add-note', function() {
		
		$( '.alert' ).hide();

		if( $( '.add-note-field' ).css('display') != 'none' ){
			var text = $( '#add-note-text' );
			var val = text.val();
			if( $.trim( val ) == '' ){
				alert( 'Please type the text!' );
				text.focus();
				return;
			}
			text.val( 'Sending...' );
			text.prop( 'enabled', false );

			$.post(' /support/plus/<?php echo $support->id_support; ?>/note', {
				text: val
			}, function( ) {
				text.prop( 'enabled',true );
				text.val( '' );
				updateConversationHistory();
				$( '.add-note-field' ).hide();
				$( '.button-add-note' ).html( $( '.button-add-note' ).attr( 'text-backup' ) );
				showAlert( '.alert-note', 'success', '<strong>Ok!</strong> Note saved!' );
			} );

		} else {
			$( '.add-note-field' ).show();
			$( '.button-add-note' ).attr( 'text-backup', $( '.button-add-note' ).html() );
			$( '.button-add-note' ).html( 'Save note' );
		}

	} );

	/* Button refund */
	$(document).on('click', '.button-refund', function() {
		
		$( '.alert' ).hide();

		var el = $( this );
		var parent = el.parent();

		var question = 'Are you sure you want to refund this?';
		if( parseFloat( el.attr( 'data-gift' ) ) > 0 ){
			question += "\n";
			question += 'A gift card was used at this order the refund value will be $' + el.attr( 'data-charged' ) + ' + $' + el.attr( 'data-gift' ) + ' as gift card.' ;
		}
		if (!confirm( question )) {
			return;
		}
		
		var button = parent.html();
		
		parent.html( '<i class="icon-cogs"></i> Processing' );
		
		$.getJSON('/api/order/' + el.attr('data-uuid') + '/refund', function( json ) {
			showAlert( '.alert-refund', 'success', '<strong>Ok!</strong> Order refunded!' );
			parent.html( '<b>Order refunded.</b>' );
			updateConversationHistory();
		});
	});

	var restaurants = [];
	<? foreach (Restaurant::q('select * from restaurant where active=1 order by name') as $restaurant) : ?>
		restaurants.push({
			id: '<?=$restaurant->id_restaurant?>',
			text: '<?=str_replace("'","\'",$restaurant->name)?>'
		});
	<? endforeach ; ?>

	$('.editable-restaurants').editable({
		inputclass: "input-large",
		source: restaurants
	});

	updateConversationHistory();

});
</script>
{'fraction_non_alphanumeric': 0.22409604116049736, 'fraction_numerical': 0.003001286265542375, 'mean_word_length': 3.1888656090990724, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '253047', 'n_tokens_mistral': 5542, 'n_tokens_neox': 4719, 'n_words': 1043}