Linking to any page through Dropdown menu in Angular JS - drop-down-menu

I have a dropdown menu created within Angular JS but I am having problem linking the menus internally to the pages.
The main problem is to know which parent menu we are in and then reaching out to the respective sub menu.
My HTML is:
<div id="menu">
<ul>
<li ng-class="{selected: $index==currPage}" ng-repeat="page in data.pages">
{{page.menuTitle}}
<ul>
<li ng-class="{$index==currMenu}" ng-repeat="smenu in data.subMenu[$index].list">
{{data.subMenu[$parent.$index].list[$index].heading}}
</li>
</ul>
</li>
</ul>
</div>
And my JS Code is:
function getPresentationData(){
var data = {};
data.title = 'My Site Title';
data.pages = [];
data.subMenu = [];
data.subMenu[0] = {};
data.subMenu[0].list = [];
data.subMenu[0].list[0] = {heading:'Profile', number: '1'};
data.subMenu[0].list[1] = {heading:'Background', number: '2'};
data.subMenu[0].list[2] = {heading:'What is KAM', number: '3'};
data.pages[0] = {};
data.pages[0].menuTitle = 'Introduction';
data.pages[0].slides = [];
data.pages[0].slides[0] = {heading:'profile', speaker: 'Me', title:'Expert ', img:'content/3.jpg', video:'content/videos/3.m4v'};
data.pages[0].slides[1] = {heading:'profile', speaker: 'Me', title:'Expert ', img:'content/4.jpg', video:'content/videos/3.m4v'};
...
data.subMenu[1] = {};
data.subMenu[1].list = [];
data.subMenu[1].list[0] = {heading:'2 Profile', number: '1'};
data.subMenu[1].list[1] = {heading:'2 Background', number: '2'};
data.subMenu[1].list[2] = {heading:'2 What is KAM', number: '3'};
data.pages[1] = {};
data.pages[1].menuTitle = 'Cases';
data.pages[1].slides = [];
data.pages[1].slides[0] = {heading:'profile', speaker: 'Me', title:'Expert ', img:'content/3.jpg', video:'content/videos/3.m4v'};
data.pages[1].slides[1] = {heading:'profile', speaker: 'Me', title:'Expert ', img:'content/4.jpg', video:'content/videos/3.m4v'};
...
data.pages[2] = {};
data.pages[2].menuTitle = 'Valdsff ns';
data.pages[2].slides = [];
data.pages[2].slides[0] = {heading:'asdf asdf asdfles', speaker: 'asdf asdfas', title:'Expert ', img:'casdf.jpg', video:'content/df3.m4v'};
return data;
}
function presentationController($scope, $location){
$scope.data = getPresentationData();
$scope.currPage = 0;
$scope.currSlide = 0;
$scope.currMenu = 0;
$scope.goToPage = function(pageIndex){
$('.slide-container').hide();
$scope.currSlide = 0;
$scope.currPage = pageIndex;
$('.slide-container').fadeIn(500);
};
}

Solved it.
Changed Menu as following:-
<div id="menu">
<ul>
<li ng-class="{selected: $index==currPage}" ng-repeat="page in data.pages">
{{page.menuTitle}}
<ul>
<li ng-class="{$index==currMenu}" ng-repeat="smenu in data.subMenu[$index].list">
{{data.subMenu[$parent.$index].list[$index].heading}}
</li>
</ul>
</li>
</ul>
</div>
and added this function:-
$scope.goToSpecificPage = function(pageIndex, slideIndex){
$('.slide-container').hide();
$scope.currSlide = slideIndex;
$scope.currPage = pageIndex;
$('.slide-container').fadeIn(500);
};

Related

Get IDGenerator Helper laravel 9 database schema table containers column equip_code

I'm new in Laravel. I'm trying retrieve and show a consecutive in a label, implementing or programming in PHP v8, Laravel v9, I'll share a screenshot of the project, which I'm working.
this is Container Model
class Container extends Model
{
use HasFactory;protected $table = 'containers';
protected $fillable = ['equip_code', 'equipment_number','size', 'equip_type', 'equip_iso','tare','date_manufacture','date_in_depot', 'location','component','damage','repair','height','width','charge', 'state_initial', 'user_id', 'shipline_id' ];
protected $date = ['date_in_depot'];
public function shipline(){
return $this-> belongsTo(Shipline::class,'id','shipline_id')->get();
}
public function user(){
return $this-> belongsTo(User::class,'id','user_id')->get();
}
** this is the Controller EquipmentController**
public function createContainer(Request $req)
{$equipment_number = $req->equipment_number;
$size = $req->size;
$equip_type = $req->equip_type;
$equip_iso = $req->equip_iso;
$tare = $req->tare;
$date_manufacture = $req->date_manufacture;
$location = $req->location;
$component = $req->component;
$damage = $req->damage;
$repair = $req->repair;
$height = $req->height;
$width = $req->width;
$charge = $req->charge;
$state_initial = $req->state_initial;
$user_id = User::find(3)->getAuthIdentifier();
$shipline_id = Shipline::where('id',1)->pluck('id')->first();
$generator = Helper::IDGenerator(new Container,'equip_code',5,"CON");
$container = new Container;
$container->equip_code = $generator;
$container->equipment_number = $equipment_number;
$container->size = $size;
$container->equip_type = $equip_type;
$container->equip_iso = $equip_iso;
$container->tare = $tare;
$container->date_in_depot = Carbon::now();
$container->date_manufacture = $date_manufacture;
$container->location = $location;
$container->component = $component;
$container->damage = $damage;
$container->repair = $repair;
$container->height = $height;
$container->width = $width;
$container->charge = $charge;
$container->state_initial = $state_initial;
$container->user_id = $user_id;
$container->shipline_id = $shipline_id;
$res = $container->save();
if ($res) {
return back()->with('success','Contenedor registrado exitosamente.!');
}else {
return back()->with('fail','Algo ha sucedido.!');
}
}
Finally, this is the View dashboard.blade
<form action="{{route('create-container', '$user_id')}}" method="post" id="container-form">
#if(Session::has('success'))
<div class="alert alert-success">{{Session::get('success')}}</div>
#endif
#if(Session::has('fail'))
<div class="alert alert-danger">{{Session::get('fail')}}</div>
#endif
#csrf
<div>
<label id ="consecutive">Consecutivo:</label>
#if (is_array($containers) || is_object($containers))
#foreach ($containers as $cont)
<label>{{ $cont['equip_code'] }}</label>
#endforeach
#endif
</div>

Select day of links laravel

I want to make a modal with a select of day that the links are showed... Showing the 10 past days and paginate with scroll... How can I do it? Carbon? If yes, I don't know how, because I'm beginner.
VIEW:
<div class="white-balloon" id="selectday-balloon">
<ul id="selectday-scroll">
<!--current day = 19/02/2018-->
<!--past days-->
<li rel="18/02/2016"><h1>Yesterday</h1></li>
<li rel="17/02/2016"><h1>17/02/2018</h1></li>
<li rel="16/02/2016"><h1>16/02/2018</h1></li>
<li rel="15/02/2016"><h1>15/02/2018</h1></li>
<li rel="14/02/2016"><h1>14/02/2018</h1></li>
<li rel="13/02/2016"><h1>13/02/2018</h1></li>
<li rel="12/02/2016"><h1>12/02/2018</h1></li>
<li rel="11/02/2016"><h1>11/02/2018</h1></li>
<li rel="10/02/2016"><h1>10/02/2018</h1></li>
<li rel="09/02/2016"><h1>09/02/2018</h1></li>
<!--continue in paginate-->
</ul>
</div>
JQUERY LOAD MORE:
$('#selectday-scroll').bind('scroll', function () {
if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
var isLoading = false;
var last_day = $("#selectday-scroll li").last().attr("rel");
if (isLoading === false) {
var isLoading = true;
$.ajax({
url: window.location.origin + '/balloons/selectday/',
dataType: "HTML",
type: 'POST',
data: {last_day: last_day},
beforeSend: function () {
},
success: function (response) {
$('#selectday-scroll').append(response);
var isLoading = false;
}
});
}
}
});
you can use for loop for that, try below code. This code is controller code, you need to add lastDays in view return statement.
$today = Carbon::today();
$lastDays = array();
for ($i = 1; $i < 10; $i++) {
$day = $today->subDays(1)->format('d/m/Y');
$lastDays[] = $day;
}
Try this, at the end you have an array with the dates.
You can change de format like you wnat.
$today = Carbon::now();
$days = 10;
for($i = 0; $i <= $days; $i++)
{
$date = '';
// $date = $today->addDays($i); if you want add day
$date = $today->subDays($i);
$arrayDate[] = $date->format('Y-m-d') ;
}
Carbon Documentation

Ajax call, displaying a json response instead of success?

I have a form with a click event on submit button like this:
<div class="col-md-6 col-md-offset-4" id="submit_div">
<button type="submit" id="submit" class="btn btn-warning" onclick="entity();">
Update Entity
</button>
</div>
ajax:
$(document).ready(function() {
function entity() {
$.ajax({
url: 'entity/create/add',
type: 'post',
dataType: 'JSON',
success: function(data) {
$('#submit_div').html('<button type="button" class="btn.btn-success">Edit</button')
},
error: function(data) {
alert("Oh no!");
},
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content');
}
});
}
});
controller:
public function store(EntityRequestCreate $request)
{
$geoloc = new Geoloc;
$geoloc->lat = $request->input('lat');
$geoloc->lng = $request->input('lng');
$geoloc->slug = $request->input('name');
$geoloc->save();
$user_id = Auth::id();
$entity = new Entity;
$entity->name = $request->input('name');
$entity->type = $request->input('type');
$entity->email = $request->input('email');
$entity->tags = $request->input('tags');
$entity->_geoloc()->associate($geoloc);
$entity->save();
$entity_id = $entity->id;
$address = new Address;
$address->building_name = $request->input('building_name');
$address->address = $request->input('address');
$address->town = $request->input('town');
$address->postcode = $request->input('postcode');
$address->telephone = $request->input('telephone');
$address->entity_id = $entity_id;
$address->save();
$role = User::find($user_id);
$role->role = "2";
$role->save();
DB::table('entity_user')->insert(array('entity_id' => $entity_id, 'user_id' => $user_id));
$result = $geoloc->save();
$result2 = $entity->save();
$result3 = $address->save();
$result4 = $role->save();
if ($result && $result2 && $result3 && $result4) {
$data = $entity_id;
} else {
$data = 'error';
}
return response()->json(['results' => $data]);
}
route:
Route::post('entity/create/add', 'EntityController#store');
Everything seems to work, there are no errors but instead of a button from success(data) I get the actual response:
{
"results": 112
}
But I don't even know why it is happening can someone please help me?
form doesn't have any action and it looks like ajax is not being called?

Grab images from another website, like pinterest

Im trying to build something like images bookmarklet site like Pinterest, but somehow some of the website doesnt grab any image. Some are works just fine. Also as additional information, I use jquery wookmark as the grid templates.
Here are the codes im currently use... I dont know if its right or simply i used the wrong method to retrieve the images. Cheers guys in advance for any comment or help... really appreciated.
-- html
<ul id="tiles"></ul>
<div id="loader">
<div id="loaderCircle" style="display:none"></div>
</div>
-- javascript
<script type="text/javascript">
function loadData() {
isLoading = true;
var link_pin ='http://www.somewebsite.com';
$('#loaderCircle').show();
$.ajax({
url: '<?php echo(base_url('index.php/home/pin_ajax'))?>',
dataType: 'json',
data: {link_pin:link_pin},
success: onLoadData
});
};
function onLoadData(data) {
isLoading = false;
$('#loaderCircle').hide();
var html = '';
var i=0, length=data.length, returns_data;
for(; i<length; i++) {
var link_foto = data[i];
var newImg = new Image();
newImg.src = link_foto;
var height = newImg.height;
var width = newImg.width;
var image_click="image_clicks('"+link_foto+"')";
if (width >="200" && height >="200"){
html += '<li onclick="'+image_click+'" id="image_'+i+'">';
html += '<a>';
html += '<div class="back_tristlist">';
html += '<span class="hover-icon icon-text">🔍</span>';
html += '<img src="'+link_foto+'">';
html += '</div>';
html += '</a>';
html += '<div class="space_image"></div>';
html += '</li>';
}
}
$('#tiles').append(html);
handler = $('#tiles li');
handler.wookmark(options);
};
</script>
-- php
public function pin_ajax(){
extract($_GET);
$page = file_get_contents($link_pin);
error_reporting(0);
$doc = new DOMDocument();
#$doc->loadHTML($page);
$images = $doc->getElementsByTagName('img');
echo($images);
$_datas[]="";
foreach($images as $image){
$raw_img_url = $image->getAttribute('src');
$img_final_link = $raw_img_url;
$img_url = explode('http://www.', $raw_img_url);
$img_check = $img_url[1];
if($img_check==''){
$img_url = explode('http://', $raw_img_url);
$img_check = $img_url[1];
if($img_check!=''){ $img_check_error=1; }
if($img_check==''){ $img_check_error=2; }
}
$_datas[] = ($img_check);
}
$output = json_encode($_datas);
echo($output);
}

$ajax is being send but is missing a value

Ok, so my script tries to request from php results from mysql and load them into a div. The results are based on nid value which is has to send this value is extracted from id="record-#" the record- is removed and the # is left to be used by ajax as id for the nid.
here is the ajax data function
$(document).ready(function() {
$(".note").live('click',function() {
$("#note_utm_con").show();
$("#note_utm_nt").html("<img src='http://www.ajaxload.info/images/exemples/4.gif' />");
$.ajax({
type: "GET",
url: "_class/view.php",
data: "ajax=1&nid=" + parent.attr('id'),
success: function(html){
$("#note_utm").html(html);
$("#note_utm_nt").html("");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {$("#note_utm_nt").html(errorThrown);}
});
});
$("#note_utm_con_cls").click(function() {
$("#note_utm_con").hide();
});
});
and here is the rest of the page
<div id="note_utm_con" style="display: none;">
<button id="note_utm_con_cls" style="width: 20px;float: right; padding: 2px;clear: both;">X</button>
<div id="note_utm"></div>
<div id="note_utm_nt"></div>
</div>
<?php
class notes {
var $host;
var $username;
var $password;
var $table;
public function display_notes() {
$q = "SELECT * FROM `notice` ORDER BY nid ASC LIMIT 12";
$r = mysql_query($q);
if ( $r !== false && mysql_num_rows($r) > 0 ) {
while ( $a = mysql_fetch_assoc($r) ) {
$nid = stripslashes($a['nid']);
$note = stripslashes($a['note']);
$type = stripslashes($a['type']);
$private = stripslashes($a['private']);
$date = stripslashes($a['date']);
$author = stripslashes($a['author']);
if($type == 1) {
$type = "posted a comment."; $icon = "http://cdn1.iconfinder.com/data/icons/Basic_set2_Png/16/megaphone.png";
} elseif($type == 2) {
$type = "raised a support ticket."; $icon = "http://cdn1.iconfinder.com/data/icons/basicset/help_16.png";
} elseif($type == 3) {
$type = "added new photo."; $icon = "http://cdn1.iconfinder.com/data/icons/Basic_set2_Png/16/photo.png";
} elseif($type == 4) {
$type = "updated profile details."; $icon = "http://cdn1.iconfinder.com/data/icons/Basic_set2_Png/16/user_info.png";
} else { }
$entry_display .= <<<ENTRY_DISPLAY
<ul class="list">
<li id="$nid">
<a href="javascript:;" id="$nid" onClick="retun false;" class="note">
<img src="$icon" />
$author,
$type
</a>
</li>
</ul>
ENTRY_DISPLAY;
}
} else {
$entry_display = <<<ENTRY_DISPLAY
<ul class="list">
<li>
<p>
<img src="http://cdn1.iconfinder.com/data/icons/basicset/monitor_16.png" />
Nothing to display
</p>
</li>
</ul>
ENTRY_DISPLAY;
}
return $entry_display;
}
public function connect() {
mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error());
mysql_select_db($this->table) or die("Could not select database. " . mysql_error());
return $this;
}
private function note_type() {
if($type == 1) { $type = "posted a comment!"; } elseif($type == 2) { $type = "raised a support ticket!"; } else { }
return $type;
}
}
?>
so when a LI with a class="note" is clicked it triggers AJAX call. The call then uses the ID in the href to extract the $nid from the id="record-
In my case it seems as AJAX is sending the request since view.php returns the fields where the data should be but it does not seem to pass much needed nid so PHP is uable to select proper nid from MySQL to use.
Can some one tell me whats wrong with it and how it can be fixed to get the id?enter code here
Your quotation marks are wrong. Try this:
data: "ajax=1&nid=" + parent.attr('id').replace('record-',''),
Edit: Unless you haven't posted the full code still, you don't actually set parent anywhere. This means that you will use the window.parent object, which surprisingly enough doesn't have an id. You should use this.parentNode.id instead:
data: "ajax=1&nid=" + this.parentNode.id,
From what you've written it looks as if you're passing the parent.attr("id") replace call as a string rather than extracting the variable:
data: "ajax=1&nid=" + parent.attr('id').replace('record-',''),

Resources