Commit acaeaa5d authored by Clément Damiens's avatar Clément Damiens
Browse files

capacity / select quantity in calendar / quantt prod / shopping cart

parent caae1bf2
......@@ -66,7 +66,7 @@ dynForm = {
name : dyFInputs.name( "service" ) ,
price : dyFInputs.price(),
//devise : dyFInputs.inputSelect("Devise", "Iniquez la monnaie utilisée pour votre annonce", ["€", "$"]),
quantity : dyFInputs.quantity(),
capacity : dyFInputs.quantity(),
openingHours : dyFInputs.openingHours(true),
description : dyFInputs.textarea("Description", "..."),
image : dyFInputs.image(),
......
......@@ -261,14 +261,14 @@ function getLocalityForSearch(){
if(typeof globalCommunexion == "undefined") var globalCommunexion = false;
mylog.log("getLocalityForSearch", $.cookie('communexionActivated'), globalCommunexion);
if(globalCommunexion == true ){
//if(globalCommunexion == true ){
var searchLocality = {}
searchLocality[communexion.currentValue] = { type : communexion.currentLevel,
/*searchLocality[communexion.currentValue] = { type : communexion.currentLevel,
name : communexion.currentName,
active : true };
}else{
var searchLocality = getMultiScopeForSearch();
}
}*/
return searchLocality;
}
......
......@@ -131,6 +131,9 @@ HtmlHelper::registerCssAndScriptsFiles($cssAnsScriptFilesTheme, Yii::app()->requ
<script type="text/javascript">
var element=<?php echo json_encode($element); ?>;
element.imgProfil = "<i class='fa fa-image fa-3x'></i>";
if("undefined" != typeof element.profilMediumImageUrl && element.profilMediumImageUrl != "")
element.imgProfil= "<img class='img-responsive' src='"+baseUrl+element.profilMediumImageUrl+"'/>";
var type="<?php echo $type; ?>";
jQuery(document).ready(function() {
var nav = directory.findNextPrev("#page.type."+type+".id."+element['_id']['$id']);
......@@ -161,27 +164,129 @@ HtmlHelper::registerCssAndScriptsFiles($cssAnsScriptFilesTheme, Yii::app()->requ
});
}
});
function selectServiceDate(id,type){
function addToShoppingCart(id, type, ranges){
incCart=true;
if(typeof userId != "undefined" && userId != ""){
params=new Object;
params.name=element.name,
params.price=element.price
params.countQuantity=1;
if(typeof element.imgProfil != "undefined")
params.imgProfil=element.imgProfil;
if(typeof element.description != "undefined")
params.description=element.description;
if(typeof shoppingCart[type] == "undefined")
shoppingCart[type]=new Object;
if(type=="services" ){
if(typeof shoppingCart[type][element.type]=="undefined")
shoppingCart[type][element.type]=new Object;
if(typeof shoppingCart[type][element.type][id]=="undefined")
shoppingCart[type][element.type][id]=params;
else{
shoppingCart[type][element.type][id]["countQuantity"]++;
incCart=false;
}
if(typeof ranges != "undefined" && notNull(ranges)){
if(typeof shoppingCart[type][element.type][id]["reservations"] == "undefined")
shoppingCart[type][element.type][id]["reservations"]=new Object;
if(typeof shoppingCart[type][element.type][id]["reservations"][ranges.date] == "undefined"){
shoppingCart[type][element.type][id]["reservations"][ranges.date] = {"countQuantity":1};
}else{
shoppingCart[type][element.type][id]["reservations"][ranges.date]["countQuantity"]++;
incCart=false;
}
if(typeof ranges.hours != "undefined"){
ranges.hours.countQuantity=1;
if(typeof shoppingCart[type][element.type][id]["reservations"][ranges.date]["hours"] == "undefined")
shoppingCart[type][element.type][id]["reservations"][ranges.date]["hours"]=[];
if(jQuery.isEmptyObject(shoppingCart[type][element.type][id]["reservations"][ranges.date]["hours"])){
shoppingCart[type][element.type][id]["reservations"][ranges.date]["hours"].push(ranges.hours);
}else{
hoursInArray=false;
$.each(shoppingCart[type][element.type][id]["reservations"][ranges.date]["hours"], function(e,v){
if(v.start==ranges.hours.start && v.end==ranges.hours.end){
shoppingCart[type][element.type][id]["reservations"][ranges.date]["hours"][e]["countQuantity"]++;
hoursInArray=true;
}
});
if(!hoursInArray)
shoppingCart[type][element.type][id]["reservations"][ranges.date]["hours"].push(ranges.hours);
}
}
}
}else{
if(typeof shoppingCart[type][id] == "undefined"){
shoppingCart[type][id]={};
shoppingCart[type][id]=params;
}else{
shoppingCart[type][id].countQuantity++;
incCart=false;
}
}
if(incCart)
countShoppingCart(true);
//console.log("element",mapElements[id]);
}else{
$('#modalLogin').modal("show");
}
}
function addToShoppingCart(id, type, data){
function removeFromShoppingCart(id, type, ranges){
incCart=false;
if(typeof userId != "undefined" && userId != ""){
if(typeof shoppingCart[type] == "undefined")
shoppingCart[type]=[];
shoppingCart[type].push(mapElements[id]);
countShoppingCart(true);
console.log("element",mapElements[id]);
if(type=="services" ){
if(shoppingCart[type][element.type][id]["countQuantity"]==1){
delete shoppingCart[type][element.type][id];
incCart=true;
}else{
shoppingCart[type][element.type][id]["countQuantity"]--;
if(typeof ranges != "undefined" && notNull(ranges)){
if(shoppingCart[type][element.type][id]["reservations"][ranges.date]["countQuantity"]==1){
delete shoppingCart[type][element.type][id]["reservations"][ranges.date];
}else{
shoppingCart[type][element.type][id]["reservations"][ranges.date]["countQuantity"]--;
if(typeof ranges.hours != "undefined"){
$.each(shoppingCart[type][element.type][id]["reservations"][ranges.date]["hours"], function(e,v){
if(v.start==ranges.hours.start && v.end==ranges.hours.end){
if(v.countQuantity==1)
delete shoppingCart[type][element.type][id]["reservations"][ranges.date]["hours"][e];
else
shoppingCart[type][element.type][id]["reservations"][ranges.date]["hours"][e]["countQuantity"]--;
}
});
}
}
}
}
}else{
if(shoppingCart[type][id].countQuantity==1){
incCart=true;
delete shoppingCart[type][id];
}else{
shoppingCart[type][id].countQuantity--;
}
}
if(incCart)
countShoppingCart(false);
}else{
$('#modalLogin').modal("show");
}
}
function countShoppingCart(){
total=0;
$.each(shoppingCart, function(k, v){
total+=v.length;
});
if(total > 0){
$(".shoppingCart-count").html(total);
function countShoppingCart(pos){
//total=0;
//$.each(shoppingCart, function(k, v){
// total+=v.length;
//});
if(pos)
shoppingCart.countQuantity++;
else
shoppingCart.countQuantity--;
if(shoppingCart.countQuantity > 0){
$(".shoppingCart-count").html(shoppingCart.countQuantity);
$('.shoppingCart-count').removeClass('hide');
$('.shoppingCart-count').addClass('animated bounceIn');
$('.shoppingCart-count').addClass('badge-success');
......
......@@ -42,7 +42,24 @@
.contentProduct h4, .totalPrice{
text-transform: inherit;
}
.contentProduct .dateHoursDetail{
display:none;
}
.contentProduct .showDetail{
cursor: pointer;
}
.contentProduct .showDetail.rotate{
transform: rotate(180deg);
-ms-transform: rotate(180deg);
-webkit-transform: rotate(180deg);
}
.dateHeader{
/*border-bottom: 1px solid rgba(0,0,0,0.1);*/
padding: 15px 0px;
}
.contentHoursSession{
border-top: 1px solid rgba(0,0,0,0.1);
}
</style>
<div class="headerTitleStanalone"></div>
<div class="col-md-10 col-md-offset-1 contentOnePage">
......@@ -50,6 +67,7 @@
</div>
</div>
<script type="text/javascript">
var totalCart=0;
jQuery(document).ready(function() {
//if(typeof params.name != "undefined" && params.name != "")
str = "<div class='col-md-6 no-padding'>"+
......@@ -57,11 +75,12 @@
"</div>";
$(".headerTitleStanalone").html(str);
initBtnLink();
if(!jQuery.isEmptyObject(shoppingCart))
if(shoppingCart.countQuantity > 0 )
html=generateCartView();
else
html=generateEmptyCartView();
$(".contentCart").html(html);
bindCartEvent();
});
function generateEmptyCartView(){
str="<span>Va vite faire tes courses</span><br/>"+
......@@ -69,7 +88,6 @@
return str;
}
function generateCartView(){
total=0;
str="<div class='col-md-12 bg-orange padding-10'>"+
"<div class='pull-right'>"+
"<a href='javascript:alert(\"Rapha pour toi\")' class='text-white padding-5' onclick=''><i class='fa fa-print'></i> Print</a>"+
......@@ -79,37 +97,10 @@
"</div>"+
"</div>"+
"<div class='col-md-11' style='margin-left:4.133333333%'>";
$.each(shoppingCart,function(i,v){
str+="<div class='col-md-12 headerCategory margin-top-20'>"+
"<div class='col-md-12'>"+
"<h2 class='letter-orange mainTitle text-left'>"+i+"</h2>"+
"</div>"+
"<div class='col-md-1'></div>"+
"<div class='col-md-5'><h3 class='subTitleCart letter-orange'>Label<h3></div>"+
"<div class='col-md-2'><h3 class='subTitleCart letter-orange'>Price ht<h3></div>"+
"<div class='col-md-1'><h3 class='subTitleCart letter-orange'>Detail<h3></div>"+
"<div class='col-md-2'><h3 class='subTitleCart letter-orange'>Price ttc<h3></div>"+
"<div class='col-md-1'></div>"+
"</div>";
$.each(v,function(e,data){
str+="<div class='col-md-12 contentProduct text-left'>"+
"<div class='col-md-1'>"+data.imgProfil+"</div>"+
"<div class='col-md-5'>"+
"<h4 class='text-dark'>"+data.name+"</h4><br>"+
"<span>"+data.description+"</span><br>"+
"<a href='javascript:;' class='letter-blue' onclick='alert(\"What's the quoi???\")'> Save / Update</a>"+
"</div>"+
"<div class='col-md-2'><span>"+data.price+"</span></div>"+
"<div class='col-md-1'><span><i class='fa fa-angle-down'></i></span></div>"+
"<div class='col-md-2'><span>"+data.price+"</span></div>"+
"<div class='col-md-1'><span><i class='fa fa-trash'></i></span></div>"+
"</div>";
total=total+data.price;
})
});
str+=getComponentsHtml(shoppingCart,true);
str+="<div class='col-md-12 bg-orange-1 padding-5 margin-top-20'>"+
"<div class='pull-right'>"+
"<h3 class='letter-orange no-margin totalPrice'>Total of your order: "+total+" euros</h3>"+
"<h3 class='letter-orange no-margin totalPrice'>Total of your order: "+totalCart+" euros</h3>"+
"</div>"+
"</div>";
str+="<div class='col-md-12 pull-right btn-cart margin-top-20'>"+
......@@ -121,4 +112,128 @@
"</div></div>";
return str;
}
function getComponentsHtml(data,firstLevel){
itemHtml="";
$.each(data,function(i,v){
console.log(v);
if(i!="countQuantity"){
if(i=="services"){
$.each(v,function(e, service){
console.log(service);
itemHtml+=getItemByCategory(e,service,"services");
});
}
else{
itemHtml+=getItemByCategory(i,v, "products");
}
}
});
return itemHtml;
}
function getItemByCategory(label,item, type){
itemHtml="<div class='col-md-12 headerCategory margin-top-20'>"+
"<div class='col-md-12'>"+
"<h2 class='letter-orange mainTitle text-left'>"+label+"</h2>"+
"</div>"+
"<div class='col-md-1'></div>"+
"<div class='col-md-5'><h3 class='subTitleCart letter-orange'>Label<h3></div>"+
"<div class='col-md-2'><h3 class='subTitleCart letter-orange'>Price ht<h3></div>"+
"<div class='col-md-1'><h3 class='subTitleCart letter-orange'>Detail<h3></div>"+
"<div class='col-md-2'><h3 class='subTitleCart letter-orange'>Price ttc<h3></div>"+
"<div class='col-md-1'></div>"+
"</div>";
$.each(item,function(e,data){
itemHtml+=getViewItem(e, data, type);
totalCart=totalCart+(data.price*data.countQuantity);
});
return itemHtml;
}
function getViewItem(key, data, type){
itemId=key;
itemType=type;
itemHtml="<div class='col-md-12 contentProduct contentProduct"+itemId+" text-left'>"+
"<div class='col-md-1'>"+data.imgProfil+"</div>"+
"<div class='col-md-5'>"+
"<h4 class='text-dark'>"+data.name+"</h4><br>"+
"<span>Quantity booked:"+data.countQuantity+"</span><br>";
if(typeof data.description != "undefined" && data.description != "")
itemHtml += "<span>"+data.description+"</span><br>";
itemHtml += "<a href='javascript:;' class='letter-blue' onclick='alert(\"What's the quoi???\")'> Save / Update</a>"+
"</div>"+
"<div class='col-md-2 text-center'><span>"+(data.price*data.countQuantity)+"</span></div>"+
"<div class='col-md-1 text-center'><span class='showDetail'><i class='fa fa-2x fa-angle-down'></i></span></div>"+
"<div class='col-md-2 text-center'><span>"+(data.price*data.countQuantity)+"</span></div>"+
"<div class='col-md-1 text-center'><span> <a href='javascript:;' class='text-red' onclick='removeInCart(\""+itemId+"\", \""+itemType+"\");'><i class='fa fa-trash'></i></a></span></div>";
if(typeof data.reservations != "undefined"){
itemHtml += "<div class='col-md-12 col-sm-12 col-xs-12 dateHoursDetail'>";
// countDate=Object.keys(data.reservations).length;
// s=(countDate > 1) ? "s" : "";
//itemHtml += "<span>"+countDate+" date"+s+" booked</span><br/>";
$.each(data.reservations, function(date, value){
s=(value.countQuantity > 1) ? "s" : "";
itemHtml += "<div class='col-md-12 col-sm-12 col-xs-12 bookDate"+date+" shadow2 margin-bottom-10'>"+
"<div class='col-md-12 col-sm-12 col-xs-12 dateHeader'>"+
"<h4 class='pull-left margin-bottom-5 no-margin margin-right-10'><i class='fa fa-calendar'></i> "+date+"</h4>"+
"<span class='pull-left'>"+value.countQuantity+" reservation"+s+"</span>"+
"<div class='pull-right'>"+
"<a href='javascript:;' class='text-red' onclick='removeInCart(\""+itemId+"\", \""+itemType+"\",\""+date+"\");'>"+
"<i class='fa fa-trash'></i> Remove this date</a>"+
"</div>"+
"</div>";
if(typeof value.hours != "undefined"){
//countSession=Object.keys(value.hours).length;
//s=(countSession > 1) ? "s" : "";
//itemHtml += "<span>"+countSession+" session"+s+"</span><br/>";
$.each(value.hours, function(key, hours){
s=(hours.countQuantity > 1) ? "s" : "";
itemHtml += "<div class='col-md-12 col-sm-12 col-xs-12 margin-bottom-10 padding-5 contentHoursSession'>"+
"<h4 class='col-md-4 col-sm-4 col-xs-3 no-padding no-margin'><i class='fa fa-times'></i> "+hours.start+" - "+hours.end+"</h4>"+
"<span class='col-md-5 col-sm-5 col-xs-6'>"+hours.countQuantity+" reservation"+s+" on this session</span>"+
"<div class='pull-right'>"+
"<a href='javascript:;' class='text-red' onclick='removeInCart(\""+itemId+"\", \""+itemType+"\",\""+date+"\",\""+hours.start+"\",\""+hours.end+"\");'>"+
"<i class='fa fa-trash'></i>"+
"</a>"+
"</div>"+
"</div>";
});
}
itemHtml += "</div>";
});
itemHtml += "</div>";
}
itemHtml += "</div>";
return itemHtml;
}
function removeInCart(id,type,date,start,end){
ranges=null;
if(notNull(date)){
ranges=new Object;
ranges.date=date;
if(notNull(start))
ranges.hours={start: start , end: end};
}
removeFromShoppingCart(id, type, ranges);
reloadViewCart();
}
function reloadViewCart(){
if(shoppingCart.countQuantity > 0 )
html=generateCartView();
else
html=generateEmptyCartView();
$(".contentCart").html(html);
bindCartEvent();
}
function bindCartEvent(){
$(".showDetail").click(function(){
if($(this).hasClass("rotate")){
$(this).removeClass("rotate");
$(this).parents().eq(1).find(".dateHoursDetail").fadeOut("slow");
}else{
$(this).addClass("rotate");
$(this).parents().eq(1).find(".dateHoursDetail").fadeIn("slow");
}
});
}
</script>
\ No newline at end of file
......@@ -92,6 +92,8 @@
</div>
<script type="text/javascript">
var element=<?php echo json_encode($element); ?>;
var itemType="<?php echo $type; ?>";
var itemId=element._id.$id;
var templateColor = ["#93be3d", "#eb4124", "#0073b0", "#ed553b", "#df01a5", "#b45f04", "#2e2e2e"];
var dateToShow, calendar, $eventDetail, eventClass, eventCategory;
var widgetNotes = $('#notes .e-slider'), sliderNotes = $('#readNote .e-slider'), $note;
......@@ -173,11 +175,12 @@ function showCalendar() {
value.closes="24:00";
calendar.push({
//title:"My repeating event",
quantity:element.quantity,
capacity:element.capacity,
start: value.opens, // a start time (10am in this example)
end: value.closes,
startTime:startTime,
endTime:endTime,
quantity:0,
// an end time (2pm in this example)
dow: [ e ] // Repeat monday and thursday
});
......@@ -186,7 +189,8 @@ function showCalendar() {
calendar.push({
//title:"My repeating event",
allDay:true,
quantity:element.quantity,
capacity:element.capacity,
quantity:0,
dow: [ e ] // Repeat monday and thursday
});
}
......@@ -204,68 +208,109 @@ function showCalendar() {
mylog.log(calendar);
dateToShow = new Date();
$('#calendar').fullCalendar({
header : {
left : 'prev,next',
center : 'title',
right : 'today, month, agendaWeek, agendaDay'
},
lang : 'fr',
year : dateToShow.getFullYear(),
month : dateToShow.getMonth(),
date : dateToShow.getDate(),
editable : false,
events : calendar,
eventColor: '#EF5B34',
eventBackgroundColor: '#EF5B34',
textColor: '#fff',
//eventOrder:["start","end"],
hiddenDays:hiddenDays,
eventLimit: true,
timezone : 'local',
//allDaySlot : false,
//defaultDate:momment(),
eventLimitText:"sessions",
dayRender: function(date, cell){
if (date > dateToShow){
$(cell).addClass('disabled');
}
},
<?php
if(@$defaultView){?>
defaultView: '<?php echo $defaultView?>',
<?php } ?>
eventRender: function(event, element) {
if(event.start < Date.now()) { return false; }
element.find(".fc-event-title").remove();
element.find(".fc-event-time").remove();
hoursRender="All day<br/>";
if(typeof event.start !="undefined" && !event.allDay){
hoursRender=moment(event.start).format("HH:mm") + ' - '
+ moment(event.end).format("HH:mm") + '<br/>';
}
var new_description =
//+ event.quantity + '<br/>'
hoursRender
+ 'Disponible: ' + event.quantity + '<br/>'
+'<button class="btn bg-orange">Book</button>'
;
element.find(".fc-content").html(new_description);
},
eventClick : function(calEvent, jsEvent, view) {
//show event in subview
console.log(calEvent);
alert('Event: ' + calEvent.start);
alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
alert('View: ' + view.name);
//data={}
//addTo
// change the border color just for fun
//$(this).css('border-color', 'red');
//dateToShow = calEvent.start;
//urlCtrl.loadByHash("#event.detail.id."+calEvent._id);
}
});
header : {
left : 'prev,next',
center : 'title',
right : 'today, month, agendaWeek, agendaDay'
},
lang : 'fr',
year : dateToShow.getFullYear(),
month : dateToShow.getMonth(),
date : dateToShow.getDate(),
editable : false,
events : calendar,
eventColor: '#EF5B34',
eventBackgroundColor: '#EF5B34',
textColor: '#fff',
//eventOrder:["start","end"],
hiddenDays:hiddenDays,
eventLimit: true,
timezone : 'local',
//allDaySlot : false,
//defaultDate:momment(),
eventLimitText:"sessions",
dayRender: function(date, cell){
if (date > dateToShow){
$(cell).addClass('disabled');
}
},
<?php
if(@$defaultView){?>
defaultView: '<?php echo $defaultView?>',
<?php } ?>
eventRender: function(event, element) {
if(event.start < Date.now()) { return false; }
element.find(".fc-event-title").remove();
element.find(".fc-event-time").remove();
hoursRender="All day<br/>";
if(typeof event.start !="undefined" && !event.allDay){
hoursRender=moment(event.start).format("HH:mm") + ' - '
+ moment(event.end).format("HH:mm") + '<br/>';
}
var new_description =
//+ event.quantity + '<br/>'
hoursRender
+ 'Disponible: <span class="inc-capacity">' + event.capacity + '</span><br/>'
+'<a href="javascript:;" class="letter-orange remove-session hide"><i class="fa fa-minus"></i></a>'
+'<span class="inc-session"> '+event.quantity+' </span>'
+'<a href="javascript:;" class="letter-orange add-session"><i class="fa fa-plus"></i></a>';
element.find(".fc-content").html(new_description);
element.find(".remove-session").on('click', function (e) {
bookDate=event.start.format('YYYY-MM-DD');
event.capacity++;
event.quantity--;
if(event.capacity > 0)
element.find(".add-session").removeClass("hide");
if(event.quantity === 0)
element.find(".remove-session").addClass("hide");
element.find(".inc-session").text(event.quantity);
element.find(".inc-capacity").text(event.capacity);
var ranges = new Object;
ranges.date=bookDate;
if(typeof event.allDay == "undefined" || !event.allDay)
ranges.hours={start: event.startTime , end: event.endTime};
calendar.push(event);
removeFromShoppingCart(itemId, itemType, ranges);
});
element.find(".add-session").on('click', function (e) {
console.log(event);
bookDate=event.start.format('YYYY-MM-DD');
var ranges = new Object;
ranges.date=bookDate;
event.capacity--;
event.quantity++;
if(event.quantity > 0)
element.find(".remove-session").removeClass("hide");
if(event.capacity === 0)
element.find(".add-session").addClass("hide");
element.find(".inc-session").data("value",event.quantity).text(event.quantity);
element.find(".inc-capacity").data("value",event.capacity).text(event.capacity);
if(typeof event.allDay == "undefined" || !event.allDay)
ranges.hours={start: event.startTime , end: event.endTime};
addToShoppingCart(itemId, itemType, ranges);
calendar.push(event);