bxslider How is it possible to make thumbnails like a carousel? - slideshow

I use this slider http://bxslider.com/examples/thumbnail-pager-1.
It works, but I have a lots of elements and thumbnails don't fit on one line and move to the next line. How is it possible to do thumbnails like a carousel?
I'll be very grateful to you for help.
Regards.
My code is here [http://jsfiddle.net/dmeX5/]

There is an open issue for this bxslider's Github. For the moment you can use the code provided here.
The code below produces this.
/*............ slider realizzazioni (BIG) */
var realSlider= $j("#sliderBigReal ul").bxSlider({
speed:1000,
pager:false,
nextText:'',
prevText:'',
infiniteLoop:false,
hideControlOnEnd:true,
onSlideBefore:function($slideElement, oldIndex, newIndex){
changeRealThumb(realThumbSlider,newIndex);
}
});
var realThumbSlider=$j("#sliderThumbReal ul").bxSlider({
minSlides: 4,
maxSlides: 4,
slideWidth: 156,
slideMargin: 12,
moveSlides: 1,
pager:false,
speed:1000,
infiniteLoop:false,
hideControlOnEnd:true,
nextText:'<span></span>',
prevText:'<span></span>',
onSlideBefore:function($slideElement, oldIndex, newIndex){
/*$j("#sliderThumbReal ul .active").removeClass("active");
$slideElement.addClass("active"); */
}
});
linkRealSliders(realSlider,realThumbSlider);
if($j("#sliderThumbReal li").length<5){
$j("#sliderThumbReal .bx-next").hide();
}
// sincronizza sliders realizzazioni
function linkRealSliders(bigS,thumbS){
$j("#sliderThumbReal ul").on("click","a",function(event){
event.preventDefault();
var newIndex=$j(this).parent().attr("slideIndex");
bigS.goToSlide(newIndex);
});
}
//slider!=$thumbSlider. slider is the realslider
function changeRealThumb(slider,newIndex){
var $thumbS=$j("#sliderThumbReal");
$thumbS.find('.active').removeClass("active");
$thumbS.find('li[slideIndex="'+newIndex+'"]').addClass("active");
if(slider.getSlideCount()-newIndex>=4)slider.goToSlide(newIndex);
else slider.goToSlide(slider.getSlideCount()-4);
}

The answer above is correct, but there was a typo, it had slideIndex when we are using data-slideIndex or data-slide-index on bxslider4.
Here is a jsfiddle with it working perfectly:
http://jsfiddle.net/DcpdT/25/
var $j = jQuery.noConflict();
var realSlider= $j("ul#bxslider").bxSlider({
speed:1000,
pager:false,
nextText:'',
prevText:'',
infiniteLoop:false,
hideControlOnEnd:true,
onSlideBefore:function($slideElement, oldIndex, newIndex){
changeRealThumb(realThumbSlider,newIndex);
}
});
var realThumbSlider=$j("ul#bxslider-pager").bxSlider({
minSlides: 4,
maxSlides: 4,
slideWidth: 156,
slideMargin: 12,
moveSlides: 1,
pager:false,
speed:1000,
infiniteLoop:false,
hideControlOnEnd:true,
nextText:'<span></span>',
prevText:'<span></span>',
onSlideBefore:function($slideElement, oldIndex, newIndex){
/*$j("#sliderThumbReal ul .active").removeClass("active");
$slideElement.addClass("active"); */
}
});
linkRealSliders(realSlider,realThumbSlider);
if($j("#bxslider-pager li").length<5){
$j("#bxslider-pager .bx-next").hide();
}
// sincronizza sliders realizzazioni
function linkRealSliders(bigS,thumbS){
$j("ul#bxslider-pager").on("click","a",function(event){
event.preventDefault();
var newIndex=$j(this).parent().attr("data-slideIndex");
bigS.goToSlide(newIndex);
});
}
//slider!=$thumbSlider. slider is the realslider
function changeRealThumb(slider,newIndex){
var $thumbS=$j("#bxslider-pager");
$thumbS.find('.active').removeClass("active");
$thumbS.find('li[data-slideIndex="'+newIndex+'"]').addClass("active");
if(slider.getSlideCount()-newIndex>=4)slider.goToSlide(newIndex);
else slider.goToSlide(slider.getSlideCount()-4);
}
<!-- The main images -->
<ul id="bxslider">
<li><img src="http://dummyimage.com/600x400/000/fff.png" alt=""></li>
<li><img src="http://dummyimage.com/600x400/000/ff0099.png" alt=""></li>
<li><img src="http://dummyimage.com/600x400/000/ff0000.png" alt=""></li>
<li><img src="http://dummyimage.com/600x400/000/fff000.png" alt=""></li>
<li><img src="http://dummyimage.com/600x400/000/fff.png" alt=""></li>
<li><img src="http://dummyimage.com/600x400/000/fff.png" alt=""></li>
</ul>
<!-- The thumbnails -->
<ul id="bxslider-pager">
<li data-slideIndex="0"><img src="http://dummyimage.com/200x200/000/fff.png"></li>
<li data-slideIndex="1"><img src="http://dummyimage.com/200x200/000/ff0099.png"></li>
<li data-slideIndex="2"><img src="http://dummyimage.com/200x200/000/ff0000.png"></li>
<li data-slideIndex="3"><img src="http://dummyimage.com/200x200/000/fff000.png"></li>
<li data-slideIndex="4"><img src="http://dummyimage.com/200x200/000/fff.png"></li>
<li data-slideIndex="5"><img src="http://dummyimage.com/200x200/000/fff.png"></li>
</ul>

Related

how to add groups attribute in qweb template

I want to add groups attribute in qweb template like this:
<t t-extend="UserMenu">
<t t-jquery=".dropdown-menu" t-operation="replace">
<ul class="dropdown-menu">
<li>Preferences</li>
<li>My Odoo.com account</li>
<li groups="custom_preference_menu.group_yook_about_menu">About Odoo</li>
<li>Help</li>
<li>Log out</li>
</ul>
</t>
</t>
but it'is not working.
how can i solve this problem?
Well the syntax is right. Are you sure that you selected the right group with module_where_the_group_is_created.group_name?
Here is an incomplete answer. It will hide the Preferences menu item for non-admin users:
xml:
<t t-extend="UserMenu">
<t t-jquery="div.dropdown-menu.dropdown-menu-right" t-operation="replace">
<div class="dropdown-menu dropdown-menu-right" role="menu">
<a role="menuitem" href="#" data-menu="shortcuts" class="dropdown-item d-none d-md-inline-block">Shortcuts</a>
<a role="menuitem" href="#" data-menu="settings" class="dropdown-item" id="preference_menuitem">Preferences</a>
<a role="menuitem" href="#" data-menu="logout" class="dropdown-item">Log out</a>
</div>
</t>
</t>
js:
odoo.define('pos_custom_ui.custom_menuitems', function (require) {
"use strict";
var config = require('web.config');
var UserMenu = require('web.UserMenu');
UserMenu.include({
start: function () {
var self = this;
var session = this.getSession();
if (!session.is_admin){
this.$('#preference_menuitem').hide();
}
this.$el.on('click', '[data-menu]', function (ev) {
ev.preventDefault();
var menu = $(this).data('menu');
self['_onMenu' + menu.charAt(0).toUpperCase() + menu.slice(1)]();
});
return this._super.apply(this, arguments).then(function () {
var $avatar = self.$('.oe_topbar_avatar');
if (!session.uid) {
$avatar.attr('src', $avatar.data('default-src'));
return Promise.resolve();
}
var topbar_name = session.name;
if (config.isDebug()) {
topbar_name = _.str.sprintf("%s (%s)", topbar_name, session.db);
}
self.$('.oe_topbar_name').text(topbar_name);
var avatar_src = session.url('/web/image', {
model:'res.users',
field: 'image_128',
id: session.uid,
});
$avatar.attr('src', avatar_src);
});
},
});
});
Include the js file in web.assets_backend:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="custom_dashboard" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_custom_ui/static/src/js/custom_menuitems.js"></script>
</xpath>
</template>
</odoo>

Cloud 9 carousel for Ionic 2

I want to integrate Cloud9 Carousel in Ionic 2.
Case-1: I import file like this.
import { Cloud9Carousel } from '../../assets/js/jquery.cloud9carousel.js';
Doesn't work
Case-2: I import like this.
import * as Cloud9Carousel from '../../assets/js/jquery.cloud9carousel.js';
Doesn't work too.
My .ts is written as
ngOnInit(){
$(function() {
var showcase = $("#showcase")
showcase.Cloud9Carousel( {
yPos: 42,
yRadius: 48,
mirrorOptions: {
gap: 12,
height: 0.2
},
buttonLeft: $(".nav > .left"),
buttonRight: $(".nav > .right"),
bringToFront: true,
onLoaded: function() {
showcase.css( 'visibility', 'visible' )
showcase.css( 'display', 'none' )
showcase.fadeIn( 1500 )
}
} );
})
}
HTML
<div id="wrap">
<div id="showcase" class="noselect">
<img class="cloud9-item" src="assets/menu/firefox.png" alt="Firefox">
<img class="cloud9-item" src="assets/menu/wyzo.png" alt="Wyzo">
<img class="cloud9-item" src="assets/menu/opera.png" alt="Opera">
<img class="cloud9-item" src="assets/menu/chrome.png" alt="Chrome">
<img class="cloud9-item" src="assets/menu/iexplore.png" alt="Internet Explorer">
<img class="cloud9-item" src="assets/menu/safari.png" alt="Safari">
</div>
</div>
Error:
showcase.Cloud9Carousel is not a function.
Thanks in advance
Put in ngAfterViewInit(), because this function is launched after content is presented, then the DOM is ready to be modified.

Google Chart not display data

I have a problem with Google Chart, Twig ans Symfony. I make an ajax call to a function which send data to the js function drawing chart. I displayed data outside of the chart and it's working well. I also tried to display a chart with data hard-coded in it and it also displays well. It's only when I put datas from my Controller in chart's datatable that it's not working.
I don't show my Controller because it's sending datas correctly.
Here's my code :
Drawing function :
function drawGraphRepNoteOfColle() {
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Notes', 'Nombre'],
{% for r in repartitionsColle %}
[{{ r.note }}, {{ r.nombre }}],
{% endfor %}
]);
var options = {
chart: {
title: 'Company Performance',
subtitle: 'Sales, Expenses, and Profit: 2014-2017'
}
};
var chart = new google.charts.Bar(document.getElementById('graphRepNoteColle'));
chart.draw(data, options);
}
}
Ajax Call :
function rechargerColleStats() {
var groupes = document.getElementsByClassName("filled-in");
var groupesSelected = getSelectedGroupesOf(groupes);
var colleId = document.getElementById('collapside_colle_form_colles').value;
var numAdherent = document.getElementById('numAdherent').value;
var DATA = {groupesSelected: groupesSelected, idColle: colleId, numAdherent: numAdherent};
var request = $.ajax({
type: "POST",
url: "{{ path('paces_statistique_calculstatistique_getstatscolle') }}",
datatype: "html",
data: DATA,
success: function (response) {
document.getElementById("bodyColapColle").innerHTML = response;
drawGraphRepNoteOfColle();
document.getElementById("tableauQ").reload(true);
}
});
}
index.html.twig :
<nav class="top-nav panel-title">Statistiques</nav>
<div class="card-panel hoverable">
// Groupes selected field (checkboxes)
<div id="bodyColapGroupes">
{% include 'PACESStatistiqueBundle:Default:groupesCheckBoxes.html.twig' %}
</div>
// Form to get colleId
<fieldset style='display: inline; border: 2px solid deepskyblue;'>
<legend> Choix de la colle</legend>
{{ form_start(formColle) }}
{{ form_end(formColle) }}
</fieldset>
</div>
<div class="card-panel hoverable">
Colles
<div id="bodyColapColle">
{% include 'PACESStatistiqueBundle:Default:collapsideColle.html.twig' %}
</div>
</div>
collapsibleColle.html.twig :
<div id="colles">
<fieldset style='display: inline; border: 2px solid deepskyblue;'>
<legend> Minor </legend>
{% if minor is defined %}
{{ minor }} / {% if typeColle == 'QC' %}{{ nbQc }}{% else %}20{% endif %}
{% endif %}
</fieldset>
<div class="center">
<fieldset id="fieldchartA" style='height:100%; width: 100% ;border: 2px solid deepskyblue;'>
<legend> Chart1</legend>
<div id="graphRepNoteColle"></div>
</fieldset>
</div>
</div>
getStatsColleAction in Controller :
$repartitionsColles=$em->getRepository( RepartitionColle::class )->findBy(['idStatColle'=>$statsColle]);
//on en recupere les données minor, major, medianne
$notes=array();
$nbRepartition = 0;
foreach($repartitionsColles as $repartitionsColle){
$repartition[$nbRepartition]['note'] = $repartitionsColle->getNote();
$repartition[$nbRepartition]['nombre'] = $repartitionsColle->getNombre();
$nbRepartition++;
}
array_multisort(array_column($repartition, 'note'), SORT_ASC, SORT_NUMERIC, $repartition);
Array sent is $repartition. getNote() is a float and getNombre is an integer.
Drawing function and Ajax call are in index.html.twig.
GetStatsColle (function called with AJAX) returns collapsideColle.html.twig with required datas.
Ajax is working : I send other infos with the same call and it is rendered.
i would recommend not relying on google.charts.setOnLoadCallback to draw the chart everytime,
especially if you plan to draw multiple charts, it should only be called once per page
instead, swap the order of things and start with google.chart.load first,
then you can draw the chart directly from the ajax call
you can include the callback in the load statement as well...
try something like...
google.charts.load('current', {
callback: rechargerColleStats,
packages:['bar']
});
function drawGraphRepNoteOfColle() {
var data = google.visualization.arrayToDataTable([
['Notes', 'Nombre'],
{% for r in repartitionsColle %}
[{{ r.note }}, {{ r.nombre }}],
{% endfor %}
]);
var options = {
chart: {
title: 'Company Performance',
subtitle: 'Sales, Expenses, and Profit: 2014-2017'
}
};
var chart = new google.charts.Bar(document.getElementById('graphRepNoteColle'));
chart.draw(data, options);
}
function rechargerColleStats() {
var groupes = document.getElementsByClassName("filled-in");
var groupesSelected = getSelectedGroupesOf(groupes);
var colleId = document.getElementById('collapside_colle_form_colles').value;
var numAdherent = document.getElementById('numAdherent').value;
var DATA = {groupesSelected: groupesSelected, idColle: colleId, numAdherent: numAdherent};
var request = $.ajax({
type: "POST",
url: "{{ path('paces_statistique_calculstatistique_getstatscolle') }}",
datatype: "html",
data: DATA,
success: function (response) {
document.getElementById("bodyColapColle").innerHTML = response;
drawGraphRepNoteOfColle();
document.getElementById("tableauQ").reload(true);
}
});
}

AngularJS with list

I'm doing an employees list that is loaded from SQLite database. I don't know why my list is empty, but I can see via JSON.stringify that data is comming.
I'm using AngularJS and Cordova Framework. Debugging with Ripple.
listEmployees.html
<div data-role="page" apply-jq-mobile>
<div data-theme="a" data-role="header">
<h3>
Header
</h3>
</div>
<div data-role="content">
<div class="ui-grid-a">
<div class="ui-block-a">
</div>
<div class="ui-block-b">
<a data-role="button" href="#/new" data-icon="plus" data-iconpos="left">
New
</a>
</div>
</div>
<input type="text" ng-model="search" class="search-query" placeholder="Search">
<ul data-role="listview" data-divider-theme="b" data-inset="true">
<li data-role="list-divider" role="heading">
Employees
</li>
<li data-theme="c" ng-repeat="employee in employees">
{{employee.name}}
</li>
</ul>
</div>
</div>
EmployeeCtrl
function EmployeeCtrl($scope, Employee){
$scope.employees = Employee.getAllEmployees();
$scope.saveEmployee = function(id) {
if(id){
//TODO
} else {
Employee.addEmployee($scope.employee);
}
}
}
Employee
app.factory('Employee', function() {
var data = {};
data.addEmployee = function(_employee, callback) {
var employee = new Employee();
employee = _employee;
DbService.db.employees.add(employee);
DbService.db.saveChanges(callback);
}
data.getAllEmployees = function() {
DbService.db.employees.toArray(function(employees) {
console.log(JSON.stringify(employees));
return employees;
});
};
return data;
});
I think you need to use promises. Your call to db is asynchronous and therefore view is getting rendered before your data arrives.
data.getAllEmployees = function() {
var $d = $q.defer();
DbService.db.employees.toArray(function(employees) {
console.log(JSON.stringify(employees));
$d.resolve(employees);
});
return $d.promise;
};
Angular templating system wait for all the promises to get resolved before rendering. So I think this will solve your problem.
So, I solved it.
function EmployeeCtrl($scope, Employee){
Employee.getAllEmployees(function(employees){
$scope.employees = employees;
$scope.$apply();
});
}
.
app.factory('Employee', function() {
var data = {};
data.getAllEmployees = function(callback) {
DbService.db.employees.toArray(function(employees) {
callback(employees);
});
};
return data;
});
Thank you all!

jQueryUI Slider is not scrolling div

I am new to jquery, so apologies if this is a lengthy question. The following is what I have come up with for a horizontal slider to scroll a div containing lists of images.
The result is the slider not scrolling the div. Any help would be great.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var slideDrag,
slideWidth = 330,
slideSpeed = 200;
animated = false;
$(".scroll-slider").slider({
animate: slideSpeed,
start: checkType,
slide: doSlide,
max: slideWidth
});
// Set each slider to a value
$(".scroll-slider").each(function(index){
$(this).slider("value", 330 / 5 * index);
});
// You can also change a slider at any time like so:
// $(".scroll-slider:eq(0)").slider("value", value);
//
// That would move the first slider to a value, along with its content
function checkType(e){
slideDrag = $(e.originalEvent.target).hasClass("ui-slider-handle");
}
function doSlide(e, ui){
var target = $(e.target).prev(".scroll-content"),
// If sliders were above the content instead of below, we'd use:
// target = $(e.target).next(".scroll-content")
maxScroll = target.attr("scrollWidth") - target.width();
// Need to check type now to prevent the new change handler from firing twice when user clicks on slider,
// because both 'slide' and 'change' events are fired on a click, but only a 'change' when setting slider
// value manually via code.
if (e.type == 'slide'){
// Was it a click or drag?
if (slideDrag === true){
// User dragged slider head, match position
target.attr({scrollLeft: ui.value * (maxScroll / slideWidth) });
}
else{
// User clicked on slider itself, animate to position
target.stop().animate({scrollLeft: ui.value * (maxScroll / slideWidth) }, slideSpeed);
}
animated = true;
}
else{
if (animated === false){
target.stop().animate({scrollLeft: ui.value * (maxScroll / slideWidth) }, slideSpeed);
}
animated = false;
}
}
});
</script>
</script>
<style>
/* Styling the scroll elements */
.scroll-container{padding-bottom:30px}
.scroll-content{width:330px;height:110px;overflow:hidden;margin-bottom:10px}
.scroll-content ul{
width:880px;
height:110px;
margin-bottom:5px
}
.scroll-content li{
float:left;
}
.ui-slider .ui-slider-handle{width:16px;height:12px;position:absolute;top:-3px;background:#234786;border:none}
</style>
<body>
<div id="wrapper">
<h2>Multiple Slider Control Demo</h2>
<div id="left">
<div class="scroll-container">
<div class="scroll-content">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
</ul>
</div>
</div>
<div class="scroll-slider"></div>
</div>
</div>
Are you trying to work from this demo?
http://cnanney.com/journal/demo/div-slide/
I had the same error, and replaced the version of jQuery I was using with the one used in the demo and it worked.