How to add jump-to functionality using laravel - php

I want to implement a jump to functionality. It is basically like a breadcrums but not exactly. It is a dropdown and can have left and right button. Please see my code below:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="btn-group" role="group" aria-label="...">
←
<div class="btn-group" role="group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Jump to
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Assignment1</li>
<li>Quiz2</li>
<li>Quiz4</li>
<li>Assignment2</li>
</ul>
</div>
→
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
Controller
$course = Course::with([
'assignments' => $undeleted,
'quizzes' => $undeleted,
'add_links' => $undeleted
])->findOrFail($course_id);
$course_items = collect($course->assignments);
$course_items = $course_items->merge(collect($course->quizzes));
$course_items = $course_items->merge(collect($course->add_links));
$course_items = $course_items->sortBy('item_number');
Result want:
If the $course loops, it can list the items sort by item_number. If you are click the first item, then there should be no left arrow, same with the last item, if you click the last item, there should be no right arrow. The list of items are listed in the dropdown I've created.
Problem
I don't have any idea how can I add a condition if the item is the first item so I can remove the left button, and same with the last item.
Note: I'm using laravel 5.1

i think you mean in the template:
you can use
#foreach ($users as $user)
<p>This is user {{ $user->id }}</p>
#endforeach
inside the "foreach" loop you has the variable loop
#foreach ($users as $user)
#if ($user == reset($users ))
This is the first iteration.
#endif
#if ($user == end($users))
This is the last iteration.
#endif
<p>This is user {{ $user->id }}</p>
#endforeach
so you can see if first or last item
more:
http://php.net/manual/en/function.reset.php
http://php.net/manual/en/function.end.php

Hello Try this
it will start with no prev button, when you click on any thing has prev, prev will be shown, also when you click on anything has no nex the next will be hidden.. and so on..
give id="next" to next and id="prev" to prev buttons
Please run this snippet
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="btn-group" role="group" aria-label="...">
←
<div class="btn-group" role="group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Jump to
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Assignment1</li>
<li>Quiz2</li>
<li>Quiz4</li>
<li>Assignment2</li>
</ul>
</div>
→
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script>
$('#prev').hide();
$(".dropdown-menu li").click(function(){
if($(this).next('li').length <= 0) {
$('#next').hide();
} else {
$('#next').show();
}
if($(this).prev('li').length <= 0) {
$('#prev').hide();
} else {
$('#prev').show();
}
});
</script>

Related

click on domain name modal should open like popup

in notification list I used sql query to display domain name but i want to each domain name when I click on that will open popup with there details.
this is header file---
<!-- notification start -->
<li class="dropdown">
Notification <b class="caret"></b>
<ul class="dropdown-menu short-dropdown-menu">
<li class=""> <a href="<?=Url::to(['domains/index']);?>">
<?php
$domains=Domains::find()
->Where('expirydate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 1 MONTH)')
->andWhere(['or',
['status'=> 'Active'],
['status'=> 'Pending Transfer']
])
->orderBy(['expirydate' => SORT_ASC])
->all();
$domainList=ArrayHelper::map($domains,'id','domainname');
foreach($domainList as $key => $value)
{
print '<br>'. $value .'<br>';
}
?>
</a></li>
</ul>
</li>
<!-- notification ends -->
now result is open like ---
when click on that domain name it have to display popup with details like below image-----
UPDATE QUESTION:
<li class="dropdown">
Notification <b class="caret"></b>
<ul class="dropdown-menu short-dropdown-menu">
<li class="">
<a href="#modal-domaindetails" data-toggle="modal" onclick="getDomainDetails('2696')">
<?php
$domains=Domains::find()
->Where('expirydate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 1 MONTH)')
->andWhere([
'or',
['status'=> 'Active'],
['status'=> 'Pending Transfer']
])
->orderBy(['expirydate' => SORT_ASC])
->all();
$domainList=ArrayHelper::map($domains,'did','domainname');
foreach($domainList as $key => $value) {
print '<br>'. $value .'<br>';
}
?>
</a>
</li>
</ul>
</a>
</li>
see this now i am passing id 2696 but i want to take id as per domain name how is it possible
In my opinion, I have some view of it.
If you want to open a new popup modal, you have to create a modal popup, like that https://getbootstrap.com/docs/4.1/components/modal/
You put URL redirect to domain name as ">, it will be redirected to this link. You can not get any pop up here, except you want to open a new tab or new window in chrome. (with open new tab or new window you can search it on google)
In "li" and "a" tag
<li class="">
<a href="your_url">
... your code php
foreach($domainList as $key => $value) {
print '<br>'. $value .'<br>';
}
</a>
</li>
you put an iterator, it will be rending a list but they have the same redirect to a URL
UPDATE MY ANSWER
Maybe I hope it will help you.
HTML:
<li class="dropdown">
Notification <b class="caret"></b>
<ul class="dropdown-menu short-dropdown-menu">
<li class="">
<?php
$domains=Domains::find()
->Where('expirydate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 1 MONTH)')
->andWhere([
'or',
['status'=> 'Active'],
['status'=> 'Pending Transfer']
])
->orderBy(['expirydate' => SORT_ASC])
->all();
$domainList=ArrayHelper::map($domains,'did','domainname');
foreach($domainList as $key => $value) {
?>
<?= $value ?>
<?php
}
?>
</li>
</ul>
</a>
</li>
Added Modal popup
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
JAVASCRIPT
<script>
function getDomainDetails(domain_id) {
$.ajax({
url: 'domains/index',
method: 'GET', // or 'POST'
data: { domain_id : domain_id }
})
.done(function(response) {
$('#exampleModal').find('.modal-body').html(response); // append reponse html from server
$('#exampleModal').modal('show'); // show modal
});
}
</script>
Using bootstrap modal
When click link, open modal
Request to server get data
Using jquery for render data again

Boostrap modal integration in laravel table

I have a laravel datatable the following:
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs/dt-1.10.16/datatables.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs/dt-1.10.16/datatables.min.css"/>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.2.1/css/responsive.bootstrap.min.css"/>
</head>
This is the table:
<td><button
type="button"
class="btn btn-primary btn-lg"
data-toggle="modal"
data-target="#favoritesModal">
Add to Favorites
</button></td>
and here I have created the modal:
<div class="modal fade" id="favoritesModal"
tabindex="-1" role="dialog"
aria-labelledby="favoritesModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close"
data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title"
id="favoritesModalLabel">The Sun Also Rises</h4>
</div>
<div class="modal-body">
<p>
Please confirm you would like to add
<b><span id="fav-title">The Sun Also Rises</span></b>
to your favorites list.
</p>
</div>
<div class="modal-footer">
<button type="button"
class="btn btn-default"
data-dismiss="modal">Close</button>
<span class="pull-right">
<button type="button" class="btn btn-primary">
Add to Favorites
</button>
</span>
</div>
</div>
</div>
</div>
Can anyone please help me how do I implement this modal in a datatable row?
Basically I want everytime the user clicks a button show Image to open a modal with the image inside
Thanks in advance
Probably easiest if you add a unique class (say... 'imageButton') as well as a data-image-id to the button to identify which image you want. If you want individual title, you may wish to add a data-img-title on the same button.
So - sort of like this:
<td><button
type="button"
class="btn btn-primary btn-lg imageButton"
data-toggle="modal"
data-img-title ="{{$looped->title}}"
data-img-id = "{{$looped->id}}"
data-target="#favoritesModal">
Add to Favorites
</button></td>
Then, some jquery AJAX to get the image data from your controller and then place that HTML inside the modal. Something like this:
$('.imageButton').on('click', function () {
var imgTitle = $(this).data('img-title');
var imgId = $(this).data('img-id');
$.ajax({
url: "{{url('url_for_your_image_returning_controller_method)}}" + "/" + imgId,
type: "GET",
success: function (h) {
$(".modal-title").text(imgTitle);
$(".modal-body").html(h);
$('#modal').modal();
},
error: function () {
swal("Error", "Unable to bring up the creation dialog.", "error");
}
})
});
Depending on what you are sending through that would work. You can also chose to create an image tag, and send through the new src instead of photo data something like this if you want to show thumbnails as well:
<img id="modalImage" src="{{url('images')."/".(isset($image->thumb)?$image->thumb:$image->image)}}"
class="picToModal">
Then replace the src within the $("#modalImage") element with your new source and trigger. There are lots of options and branches, and you'll need to re-work to suit, but this should get you started.

Laravel scheduling app

I am trying to make a front end time table where you can click on a cell for example in row 8:30, and then a modal pops up and you can pick until when you will reserve the term going from 9:00 onward in half hour increments.
Reserving only one term works fine, as I can pick the variable directly from a loop, however I am in doubt as how to forward it to modal.
Controller:
public function index()
{
$scheduler_start_time = Carbon::createFromTime(6, 0, 0);
$scheduler_end_time = Carbon::createFromTime(20, 0, 0);
$equipment = Equipment::with('reservations', 'reservations.user')->get();
return view('landing', compact('equipment', 'scheduler_start_time', 'scheduler_end_time'));
}
Table loop in front-end:
#while($scheduler_start_time < $scheduler_end_time)
<tr>
<td>{{$scheduler_start_time->format('H:i:s')}}</td>
#foreach($equipment as $instrument)
<td>
<a href="#" style="display: block;"
data-href="{{route('reserve-me', [$instrument->id, $scheduler_start_time->timestamp])}}"
data-toggle="modal" data-target="#confirm-reservation">
#if(!$instrument->reservations->where('reserved_from', $scheduler_start_time)->isEmpty())
{{$instrument->reservations->where('reserved_from', $scheduler_start_time)->first()->user->name}}
#else
#endif
</a>
</td>
#endforeach
<?php $scheduler_start_time->addMinutes(30) ?>
</tr>
#endwhile
Modal:
<!-- Modal -->
<div class="modal fade" id="confirm-reservation" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
New reservation
</div>
<div class="modal-body">
Are you sure you want to add this reservation?
<br><br>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Reserve until
<span class="caret"></span></button>
<ul class="dropdown-menu">
<!-- *CLARIFICATION -->
<li>{{$scheduler_start_time}}</li>
</ul>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-primary btn-ok">Yes</a>
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
<script>
$('#confirm-reservation').on('show.bs.modal', function(e) {
$(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
});
</script>
Where it says *Clarification: I was trying in small steps and getting at least the value on which I clicked, but I am always getting the final time 20:00h

How to pass a php while result variable to include.php located inside the bootstrap modal

I want pass a variable from php while to include.php inside the bootstrap modal.
My php while is on the whileresult.php
<?php
$i=0;
while ($i < $rows) {
$title_books=mysql_result($result,$i,"title_books");
$pages_books=mysql_result($result,$i,"pages_books");
$author_books=mysql_result($result,$i,"author_books");
?>
<?php echo $title_books; ?>
after, there is a bootstrap modal and this there are a include.php
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="col-md-1">
<div class="btn-group">
<button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-cog fa-2x" aria-hidden="true"></i><span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
Book in library
</li>
</ul>
</div>
</div>
<!-- start modal with include.php -->
<div id="modalShareBk" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Your Books</h4>
</div>
<div class="modal-body">
<?php include("include.php"); ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-xs" data-dismiss="modal">
<i class="fa fa-times-circle" aria-hidden="true"></i> Close
</button>
</div>
</div>
</div>
</div>
Now, how to pass the value of variable $title_books inside the include.php page?
Thanks
Simply echo out the values in the include file the scope of the variable will be there in include.php
PS. Use require_once() instead of include()
Edit 1:
You need to change the whileresult.php code to something like this
whileresult.php
<?php
$i=0;
$title_books = array();
$pages_books = array();
$author_books = array();
while ($i < $rows) {
$title_books[$i]=mysql_result($result,$i,"title_books");
$pages_books[$i]=mysql_result($result,$i,"pages_books");
$author_books[$i]=mysql_result($result,$i,"author_books");
$i++;
?>
include.php
<?php
for($j=0;$j<$i;$j++)
{
echo 'Book - '.$title_books[$j].' Pages - '.$pages_books[$j].'Author - '.$author_books[$j];
}
?>

Collapsable bootstrap multilevel listview populated from database for beginners

As a beginning coder, I could use some help understanding what's involved in building a listview populated from a database with rows that can expand and collapse, providing more information, with embedded buttons for controls? I'd like to use mostly bootstrap and python or PHP and replicate this: http://preview.iatistandard.org/index.php?url=http%3A//iati.oxfam.org.uk/xml/oxfamgb-lb.xml
Answers to similar questions are too high-level. Can someone please map out the example's basic components and functions at least and where the database scripts go and what they do? Thanks!
Here is the DEMO that you required
$('.collapse').on('shown.bs.collapse', function (e) {
//Get the id of the collapsible which is opened
var id = $(this).attr("id");
//Set the minus icon as this collapsible is now opened
$('a[href="#'+ id +'"]').find("span.glyphicon-plus").removeClass("glyphicon-plus").addClass("glyphicon-minus");
//You know now which collapsible is clicked, so get the data for this id which is in attribute data-collapisbleId
var collapsibleDataId = $(this).data("collapisbleId");
//Now we have the id of the collapisble whihc we can use to get the deatails for this id, and then we will insert that into the detail section
}).on('hide.bs.collapse', function (e) {
var id = $(this).attr("id");
$('a[href="#'+ id +'"]').find("span.glyphicon-minus").removeClass("glyphicon-minus").addClass("glyphicon-plus");
var collapsibleDataId = $(this).data("collapisbleId");
$.ajax({
//Make hit to get the detials using ajax and on success of that insert the data in the dic with id = $(this).attr("id"); whihc is current div
});
});
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Here I have just added the hardwired collapisbles, you have to make here loop to make these
for example. You got here the list of the collapisable heading and then you are making loop to make the collapisble
I have used here ASP.Net MVC as am not good in PHP or Python but the logic will go same here. Think as the below div are created using this loop
#(for var i= 0; i> Model.Count(); i++){
<div>
<a class="btn btn-link" role="button" data-toggle="collapse" href="#link#(i+1)" aria-expanded="false" aria-controls="collapseExample">
<span class="glyphicon glyphicon-plus"></span> Link 1
</a>
<div class="collapse" id="link#(i+1)" data-collapisbleId="#Model.Id">
//Detials section
</div>
</div>
} -->
<div>
<a class="btn btn-link" role="button" data-toggle="collapse" href="#link1" aria-expanded="false" aria-controls="collapseExample">
<span class="glyphicon glyphicon-plus"></span> Link 1
</a>
<div class="collapse" id="link1" data-collapisbleId="1">
<!--Detials section-->
Link 1
</div>
</div>
<div>
<a class="btn btn-link" role="button" data-toggle="collapse" href="#link2" aria-expanded="false" aria-controls="collapseExample">
<span class="glyphicon glyphicon-plus"></span> Link 2
</a>
<div class="collapse" id="link2" data-collapisbleId="2">
<!--Detials section-->
<ul class="list-group">
<li class="list-group-item">Cras justo odio</li>
<li class="list-group-item">Dapibus ac facilisis in</li>
<li class="list-group-item">Morbi leo risus</li>
<li class="list-group-item">Porta ac consectetur ac</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
</div>
</div>
**Complete DEMO**
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$('.collapse').on('shown.bs.collapse', function (e) {
//Get the id of the collapsible which is opened
var id = $(this).attr("id");
//Set the minus icon as this collapsible is now opened
$('a[href="#'+ id +'"]').find("span.glyphicon-plus").removeClass("glyphicon-plus").addClass("glyphicon-minus");
//You know now which collapsible is clicked, so get the data for this id which is in attribute data-collapisbleId
var collapsibleDataId = $(this).data("collapisbleId");
//Now we have the id of the collapisble whihc we can use to get the deatails for this id, and then we will insert that into the detail section
}).on('hide.bs.collapse', function (e) {
var id = $(this).attr("id");
$('a[href="#'+ id +'"]').find("span.glyphicon-minus").removeClass("glyphicon-minus").addClass("glyphicon-plus");
var collapsibleDataId = $(this).data("collapisbleId");
$.ajax({
//Make hit to get the detials using ajax and on success of that insert the data in the dic with id = $(this).attr("id"); whihc is current div
});
});
});
</script>
</head>
<body>
<!-- Here I have just added the hardwired collapisbles, you have to make here loop to make these
for example. You got here the list of the collapisable heading and then you are making loop to make the collapisble
I have used here ASP.Net MVC as am not good in PHP or Python but the logic will go same here. Think as the below div are created using this loop
#(for var i= 0; i> Model.Count(); i++){
<div>
<a class="btn btn-link" role="button" data-toggle="collapse" href="#link#(i+1)" aria-expanded="false" aria-controls="collapseExample">
<span class="glyphicon glyphicon-plus"></span> Link 1
</a>
<div class="collapse" id="link#(i+1)" data-collapisbleId="#Model.Id">
//Detials section
</div>
</div>
} -->
<div>
<a class="btn btn-link" role="button" data-toggle="collapse" href="#link1" aria-expanded="false" aria-controls="collapseExample">
<span class="glyphicon glyphicon-plus"></span> Link 1
</a>
<div class="collapse" id="link1" data-collapisbleId="1">
<!--Detials section-->
Link 1
</div>
</div>
<div>
<a class="btn btn-link" role="button" data-toggle="collapse" href="#link2" aria-expanded="false" aria-controls="collapseExample">
<span class="glyphicon glyphicon-plus"></span> Link 2
</a>
<div class="collapse" id="link2" data-collapisbleId="2">
<!--Detials section-->
<ul class="list-group">
<li class="list-group-item">Cras justo odio</li>
<li class="list-group-item">Dapibus ac facilisis in</li>
<li class="list-group-item">Morbi leo risus</li>
<li class="list-group-item">Porta ac consectetur ac</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
</div>
</div>
</body>
</html>

Categories