
	<?php $mt = explode('.',microtime(true))[1]; ?>

	<div id="embed_<?php echo e($mt); ?>">
	    <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($set->title); ?> 
	                    <?php if(Auth::user()->checkPermission(28)): ?>
	                    	<a href="<?php echo e(url('uadmin/builder/data/'.$set->id)); ?>" title="Edit Data" style="float: right;"><i class="fa fa-pencil"></i></a>
	                    <?php endif; ?>
	                </div>
	                <div class="panel-body">
	                    <div class="row">
	                        <div class="col-lg-12">
	                        	<table id="data_<?php echo e($mt); ?>" class="display table table-striped table-bordered table-hover" style="width:100%">
							        <thead>
							            <tr>
							                <?php foreach($fields as $field): ?>
							                	<th><?php echo e($field->title); ?></th>
							                <?php endforeach; ?>
							            </tr>
							        </thead>
							    </table>
	                        </div>
	                    </div>
	                </div>
	            </div>
	        </div>
	    </div>
	</div>

	<script>
		function loadCSS(url){
			var fileref=document.createElement("link");
        	fileref.setAttribute("rel", "stylesheet");
        	fileref.setAttribute("type", "text/css");
        	fileref.setAttribute("href", url);

        	if (typeof fileref!="undefined")
        	{
        		document.getElementsByTagName("head")[0].appendChild(fileref);
        	}
		}
		function loadJS(url){

			var list = document.getElementsByTagName('script');
			var i = list.length, flag = false;

			while (i--) {
			    if (list[i].src != "" & list[i].src === url) {
			        flag = true; 
			    }
			   
			}

			if (!flag) {
				var tag = document.createElement('script');
	    		tag.src = url;

	    		if (typeof tag!="undefined")
	        	{
	   				document.getElementsByTagName('body')[0].appendChild(tag);
	   			}
			}
			
		}

		loadCSS("https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap4.min.css");
		loadCSS("https://cdn.datatables.net/buttons/1.5.1/css/buttons.dataTables.min.css");
		loadCSS("https://cdn.datatables.net/select/1.2.5/css/select.dataTables.min.css");
		loadCSS("<?php echo e(asset('editor/css/editor.bootstrap4.css')); ?>");

		loadJS("https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js");
		
		<?php if($type == 'editable'): ?>
				
			loadJS("<?php echo e(asset('editor/js/dataTables.editor.min.js')); ?>");
		

		<?php endif; ?>
		

	</script>


	

	

	<script>
		var editor; // use a global for the submit and return data rendering in the examples
 
		window.addEventListener("load", function(evt) {
			loadJS("https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js");
			loadJS("https://cdn.datatables.net/select/1.2.5/js/dataTables.select.min.js");

			<?php if($type == 'editable'): ?>
			
				loadJS("<?php echo e(asset('editor/js/editor.bootstrap4.min.js')); ?>");

			    editor = new $.fn.dataTable.Editor( {
			        ajax: "<?php echo e(url('admin/builder/editrecord/'.$set->id)); ?>",
			        table: "#data_<?php echo e($mt); ?>",
			        idSrc: "record_id",
			        fields: [ 
			        	<?php foreach($fields as $field): ?>
			        		{
			                	label: "<?php echo e($field->title); ?>", 
			               		name: "<?php echo e($field->name); ?>"
			            	},
			        	<?php endforeach; ?>
			        ]
			    } );
		 	<?php endif; ?>
		    $('#data_<?php echo e($mt); ?>').DataTable( {
		    	<?php if($type == 'editable'): ?>
		        	dom: "Bfrtip",
		       	<?php endif; ?>
		        ajax: "<?php echo e(url('admin/builder/getdata/'.$set->id)); ?>",
		        "pageLength": 100,
		        columns: [
		        	<?php foreach($fields as $field): ?>
		        		{ data: "<?php echo e($field->name); ?>" },
		        	<?php endforeach; ?>
		        ],
		        <?php if($type == 'editable'): ?>
			        select: true,
			        buttons: [
			            { extend: "create", editor: editor },
			            { extend: "edit",   editor: editor },
			            { extend: "remove", editor: editor }
			        ]
		        <?php endif; ?>
		    } );
		});
	</script>





