<?php $__env->startSection('content'); ?>

	<div id="root">
		<div class="row">
	    	<div class="col-lg-12">
	    		<h1 class="page-header">Knowledge Base</h1>
	    	</div>
	    </div>
	    <div class="row">
            <div class="col-lg-12">
                <?php if(session('status')): ?>
				<div class="alert alert-success">
					<?php echo e(session('status')); ?>

				</div>
				<?php endif; ?>
				<?php if(count($errors) > 0): ?>
					<div class="alert alert-danger">
						<strong>Whoops!</strong> There were some problems with your input.<br><br>
						<ul>
							<?php foreach($errors->all() as $error): ?>
								<li><?php echo e($error); ?></li>
							<?php endforeach; ?>
						</ul>
					</div>
				<?php endif; ?>
				<div class="panel panel-default">
					<div class="panel-heading">
	                    <?php echo e(ucfirst($action)); ?> Article
	                    <?php if($action == 'edit'): ?>
                            <a href="<?php echo e(url('uadmin/kb/view/'.$article->id)); ?>"> <i class="fa fa-eye fa-fw" style="float: right;"></i> </a>
                       <?php endif; ?>
	                </div>
	                <div class="panel-body">
	                    <div class="row">
	                        <div class="col-lg-12">
			                    <form id="theForm" class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="<?php echo e(url('admin/kb/'.$action)); ?>" onsubmit="getContent()">
									<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
									<?php if($action == 'edit'): ?>
										<input type="hidden" name="articleID" value="<?php echo e($article->id); ?>">
									<?php endif; ?>
									<input type="hidden" id="content" name="content" value="">
									<div class="form-group">
										<div class="col-sm-12 col-md-4 morePadding morePadding2" onclick="inputFocus('title')">
											<input type="text" class="form-control" id="title" name="title" value="<?php echo e(old('title') ? old('title') : (isset($article) ? $article->title : '')); ?>" title="Title">
											<span id="title-label" class="label-text">Title</span>	
										</div>
										<div class="col-sm-12 col-md-8 morePadding morePadding2" onclick="inputFocus('keywords')">
											<input type="text" class="form-control" id="keywords" name="keywords" value="<?php echo e(old('keywords') ? old('keywords') : (isset($article) ? $article->keywords : '')); ?>" title="Keywords">
											<span id="keywords-label" class="label-text">Keywords</span>	
										</div>
									</div>
									<div id="editor">
										<?php echo old('content') ? old('content') : (isset($article) ? $article->content : ''); ?>

									</div>
									<div class="form-group">
										<div class="col-sm-12 col-md-12 morePadding">
											<button type="submit" class="btn btn-primary" style="float: right;">
												Save
											</button>
										</div>
									</div>
								</form>
							</div>
						</div>

					</div>
				</div>
				<?php if($action == "edit"): ?>
				<div class="panel panel-default">
					<div class="panel-heading">
	                    Article Attachments
	                </div>
	                <div class="panel-body">
	                	<div class="row">
	                        <div class="col-lg-12">
	                        	<div class="dataTable_wrapper">
	                                <table class="table table-striped table-bordered table-hover" id="dataTables-example2">
	                                    <thead>
	                                        <tr>
	                                       		
	                                       		<th>ID</th>
	                                            <th>Title</th>
	                                            <th>File</th>
	                                            <th>KB Embed</th>
	                                            <th>Uploaded</th>
	                                            
	                                        </tr>
	                                    </thead>
	                                    <tbody>
	                                    <?php $count = 0; ?>
	                                    <?php foreach(\App\Kb_attachment::where('article_id','=',$article->id)->get() as $attachment): ?>
	                                    <?php $count++; ?>
	                                    <?php if($count % 2 == 1): ?>
	                                        <tr class="odd">
	                                    <?php else: ?>
	                                    	<tr class="even">
	                                    <?php endif; ?>
	                                    		<td>
	                                    			<?php echo e($attachment->id); ?>

	                                    		</td>
	                                            <td>
	                                            	<a target="_blank" href="<?php echo e(url('uadmin/kb/attachment/'.$attachment->id)); ?>">
	                                            		<?php echo e($attachment->title); ?>

	                                            	</a>
	                                            </td>
	                                            <td>
	                                            	<a target="_blank" href="<?php echo e(url('uadmin/kb/attachment/'.$attachment->id)); ?>">
	                                            		<?php echo e($attachment->filename); ?>

	                                            	</a>
	                                            	<form class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="<?php echo e(url('admin/kb/attachment/delete')); ?>" onsubmit="return confirm('All unsaved article changes will be lost and attachment will be permanently removed. Proceed?');"
	                                            	style="display: inline;"
	                                            	>
	                                            		<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
	                                            		<input type="hidden" name="attachmentID" value="<?php echo e($attachment->id); ?>">
	                                            		<button type="submit" style="border:none; background-color: transparent; float: right;" title="Delete Attachment">
	                                            			<i class="fa fa-trash"></i>
	                                            		</button>
	                                            	</form>
	                                            </td>
	                                            <td>
	                                            	{#<?php echo e($attachment->id); ?>#}
	                                            </td>
	                                            <td>
	                                            	<?php echo e($attachment->created_at); ?>

	                                            </td>

	                                        </tr>
	                                  	<?php endforeach; ?>
	                                   </tbody>
	                            	</table>
	                            </div>
	                        </div>
	                    </div>
	                    <br><br>
						<div class="row">
							<label class="col-lg-12">Upload New Attachment</label>
	                        <div class="col-lg-12">
			                    <form id="theForm2" class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="<?php echo e(url('admin/kb/attachment')); ?>" onsubmit="return confirm('All unsaved article changes will be lost. Proceed?');">
									<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
									<input type="hidden" name="articleID" value="<?php echo e($article->id); ?>">

									<div class="form-group">
										<div class="col-sm-12 col-md-4 morePadding morePadding2" onclick="inputFocus('title_a')">
											<input type="text" class="form-control" id="title_a" name="title" value="<?php echo e(old('title')); ?>" title="Title">
											<span id="title_a-label" class="label-text">Title</span>	
										</div>
										<div class="col-sm-12 col-md-4 morePadding morePadding2" onclick="inputFocus('file_a')">
											<input type="file" class="form-control" id="file_a" name="file" value="" title="File">
											<span id="file_a-label" class="hasValue">File</span>	
										</div>
										<div class="col-sm-12 col-md-4 morePadding">
											<button type="submit" class="btn btn-primary" style="float: right;">
												Upload
											</button>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>

				<form class="form-horizontal" role="form" method="POST" action="<?php echo e(url('admin/kb/delete')); ?>">
					<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
					<input type="hidden" name="articleID" value="<?php echo e($article->id); ?>">
					<div class="col-sm-12 col-md-12 morePadding">
						<button type="submit" class="btn btn-default" style="float: right;">
							Delete Article
						</button>
					</div>
				</form>
				<?php endif; ?>
			</div>
		</div>

	</div>
	
<?php $__env->stopSection(); ?>

<?php $__env->startSection('extras'); ?>

	<link href="//cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/t/bs/pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2/datatables.min.css"/>
    

	<style>
		input:focus+.label-text, input:not([value=""])+.label-text, select+.label-text {
		    font-weight: normal;
		    padding: 0;
		    padding-left: 20px;
		    -webkit-transform: translateY(-2rem) scale(.7);
		    transform: translateY(-2rem) scale(.7);
		}
		input+.label-text, select+.label-text, .hasValue{
		    font-size: 1.5rem;
		    font-weight: 400;
		    position: absolute;
		    top: 0;
		    left: 0;
		    display: block;

		    padding-left: 20px;
		    padding-top: 5px;
		    padding-bottom: 5px;
		    opacity: .8;
		    transition: all .3s ease-out,opacity 150ms ease .3s;
		    -webkit-transform: translateY(0) scale(1);
		    transform: translateY(0) scale(1);
		    -webkit-transform-origin: left top;
		    transform-origin: left top;
		}
		span {
		    font-size: 1rem;
		    font-weight: 600;
		    display: block;
		    padding-top: .25rem;
		    padding-bottom: .25rem;
		    margin-left: 1rem;
		    color: #317aba;
		}
		.hasValue
		{
		    font-weight: normal;
		    padding: 0;
		    padding-left: 20px;
		    -webkit-transform: translateY(-2rem) scale(.7);
		    transform: translateY(-2rem) scale(.7);
		}
		

		@media (max-width: 959px)
		{
			.morePadding {
			    margin-top: 1.5em;
			}
		}

		@media (min-width: 960px)
		{
			.morePadding {
			    margin-top: 1em;
			}
		}

		a:hover{
    		text-decoration: none;
    	}
    	.odd .subBack {
    		background-color: #f0fcff;
    	}
    	.even .subBack {
    		background-color: #ecf7fa;
    	}
    	.floatLeft
    	{
    		float: left;
    	}
		
	</style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('bottom'); ?>

	<script src="//cdn.quilljs.com/1.3.6/quill.min.js"></script>

	<script type="text/javascript" src="https://cdn.datatables.net/t/bs/pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2/datatables.min.js"></script>

	
    
    <!-- Page-Level Demo Scripts - Tables - Use for reference -->
    <script>
	    $(document).ready(function() {
	    var table1 =    $('#dataTables-example2').dataTable( {
						"pageLength": 25,
						"order": [ 1, 'asc' ],
						"stateSave" : false,
						"scrollX" : window.innerWidth < 800 ? true : false

						
	        } ); 
	 


	    });

	</script>

	<script>
		var quill = new Quill('#editor', {
		  theme: 'snow',
		  modules: {
		    toolbar: [
		      [{ header: [1, 2, false] }],
		      ['bold', 'italic', 'underline'],
		      ['link', 'blockquote'],
		      [{ list: 'ordered' }, { list: 'bullet' }],
		      ['clean']
		    ]
		  },
		});

		function getContent() {
			document.getElementById('content').value = document.getElementById('editor').firstChild.innerHTML;

		}
	</script>

	<script>
		$('.form-control').each(function() {
		   var elem = $(this);

		   // Save current value of element
		   elem.data('oldVal', elem.val());

		   // Look for changes in the value
		   elem.bind("propertychange change click keyup input paste", function(event){
		      // If value has changed...
		      if (elem.data('oldVal') != elem.val()) {
		       // Updated stored value
		       elem.data('oldVal', elem.val());
		       var elem2 = $('#'+elem.attr('id')+"-label");
		       elem2.addClass('hasValue');
		       elem2.removeClass('label-text');
		       if(elem.val() == "")
		       {
			       
		    	   elem2.addClass('label-text');
			       elem2.removeClass('hasValue');
		       }
		     }
		   });
		 });

		function inputFocus(id)
		{
			document.getElementById(id).focus();
		}

		var keys = [];
	
		document.onkeydown = function(evt){    
		   var key = evt.keyCode;
		   keys[key] = true;
		    if(keys[17] && keys[83]){
				
				keys[17] = false;
				keys[83] = false;

				getContent();
				document.getElementById('theForm').submit();
		    } 

		    if(keys[91] && keys[83]){
				
				keys[91] = false;
				keys[83] = false;

				getContent();
				document.getElementById('theForm').submit();
		    } 

		}
		document.onkeyup = function(evt){    
		   var key = evt.keyCode;
		   keys[key] = false;
		}
	</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>