$(document).ready(function () {
/*Navbar
* Dropdown is not handled!
*/
//Navbar handling onclick
var navBarA = $(".navbar-nav a");
navBarA.click(function() {
$(".nav li").removeClass('active');
SetCookie('lastHref', $(this).attr('href'));
NavbarSetActive ($(this));
//if ($(".navbar-toggle").css('display') != 'none') {
if(site.isMobile()){
window.location = $(this).attr('href');
}
});
var currentLocation = window.location.href;
var aLinkFound = false;
navBarA.each(function() {
var linkHref = '';
linkHref = $(this).attr('href');
var indexOf = currentLocation.indexOf(linkHref);
if (indexOf >= 0) {
var nextChar = currentLocation[indexOf + linkHref.length];
if (nextChar == undefined || nextChar == '&') {
NavbarSetActive ($(this));
aLinkFound = true;
}
}
});
//If not found by href, active latest href
if (!aLinkFound) {
var aLink = $("a[href='"+GetCookie('lastHref')+"']");
NavbarSetActive ($(this));
}
setBackToTopListener();
InitDatePickers ();
//mobile: automatically expand sub menus when opening menu
$('.collapse.navbar-collapse').on('show.bs.collapse', function () {
window.setTimeout(OpenDropDown, 1);
});
if($('body').hasClass('show_ps')){
progressbar.set('show_ps');
}
});
function OpenDropDown() {
$('.dropdown-menu').dropdown('toggle');
};
function removeMenuLinks(className) {
var navBarLi = $(".navbar-nav li");
navBarLi.each(function() {
if($(this).hasClass(className)){
$(this).hide();
}
});
};
function InitDatePickers () {
//Init datepickers
if ($.fn.datepicker.dates != undefined) {
(function ($) {
$.fn.datepicker.dates['xxx'] = {
days: ['Sunnuntai', 'Maanantai', 'Tiistai', 'Keskiviikko', 'Torstai', 'Perjantai', 'Lauantai'],
daysMin: ['Su', 'Ma', 'Ti', 'Ke', 'To', 'Pe', 'La'],
daysShort: ['Su', 'Ma', 'Ti', 'Ke', 'To', 'Pe', 'La'],
months: ['Tammikuu', 'Helmikuu', 'Maaliskuu', 'Huhtikuu', 'Toukokuu', 'Kesäkuu', 'Heinäkuu', 'Elokuu', 'Syyskuu', 'Lokakuu', 'Marraskuu', 'Joulukuu'],
monthsShort: ['Tammi', 'Helmi', 'Maalis', 'Huhti', 'Touko', 'Kesä', 'Heinä', 'Elo', 'Syys', 'Loka', 'Marras', 'Joulu'],
today: 'Tänään',
format: (DATEFMT == 'd.m.Y' ? 'dd.mm.yyyy' : 'yyyy-mm-dd'),
todayHighlight: true
};
}
(jQuery));
}
$('.datepicker').datepicker({
weekStart: 1,
language: 'xxx',
autoclose: true,
forceParse: true
});
$('.datepicker').find('input').focus(function() {
$(this).attr("readonly", true);
});
$('.datepicker').find('input').blur(function() {
$(this).attr("readonly", false);
});
}
function NavbarSetActive (aLink) {
aLink.parent().addClass('active'); //Set
active
}
function RsvBasketRemove () {
$.get('index.php?func=rsv_basket_remove', function(data){
$("#notification_rsv_basket").hide();
});
}
function ScrollTo (selector) {
var navBar = $(".navbar");
var paddingTop = 0;
if (navBar.hasClass('navbar-fixed-top')){
paddingTop = parseInt (navBar.height(), 10);
}
$('html, body').animate({
scrollTop: ($(selector).offset().top) - paddingTop
}, 500);
if(self !== top) {
//if site is in iframe, and the iframe has a specific height (not 100%) the above scrolling will not work because the parent page's scrollbar will not scroll automatically.
//commented out because caused problems with page scrolling all the way to the bottom
//$(selector).get(0).scrollIntoView();
}
}
function ShoppingCartToggle () {
$("#shopping_cart").toggle('1000');
}
/**
* Sets a scroll event listener for back to top button if back to top button is found
* in the current DOM.
*/
function setBackToTopListener() {
//Scroll to top button.
var $backToTopBtn = $(".js-back-to-top");
if ($backToTopBtn.length > 0) {
$(window).scroll(function () {
if ($(this).scrollTop() > window.innerHeight) {
$backToTopBtn.fadeIn(400);
} else {
$backToTopBtn.fadeOut(400);
}
});
}
}
/*Classes*/
/*
Cookie
Cookie name get prefix from install_code.
*/
var Cookie = new function () {
this.get = function (name) {
name = this.nameGet(name);
return GetCookie(name);
};
this.set = function (name, value) {
name = this.nameGet(name);
SetCookie(name, value);
};
this.remove = function (name) {
name = this.nameGet(name);
DeleteCookie(name);
};
this.nameGet = function (name) {
return INSTALL_CODE + '_' + name;
};
};
var site = new function () {
this.isMobile = function () {
//Does is_mobile element exist in template
return $("#is_mobile").is(":visible");
};
this.isSmallScreen = function () {
//Does is_smallscreen element exist in template
return $("#is_smallscreen").is(":visible");
};
this.isSmallDevice = function () {
//Does is_mobile or is_smallscreen element exist in template
return this.isMobile() || this.isSmallScreen();
};
this.isMediumScreen = function () {
//Does is_medium element exist in template
return $("#is_mediumscreen").is(":visible");
};
this.isSmallOrMediumDevice = function () {
//Does is_mobile or is_smallscreen or is_mediumscreen element exist in template
return this.isMobile() || this.isSmallScreen() || this.isMediumScreen();
};
this.scrollTo = function (selector) {
ScrollTo (selector);
};
this.fixWebShopProductList = function (addHeight, rezizeProductName, resizeProductDescription) {
//if tabs (=groups) loop each group
$('.product_list').each(function(){
var selector = '';
if($(this).attr('id')){
selector = '#' + $(this).attr('id');
}
site.calculateProductCardMaxHeight(selector, addHeight, rezizeProductName, resizeProductDescription);
});
};
this.calculateProductCardMaxHeight = function(selector, addHeight, rezizeProductName, resizeProductDescription) {
var maxHeight = 0; //.product_card
if(typeof(addHeight)=='undefined'){
addHeight = 0;
}
var maxHeightProductName = 0; //TrainingCard v2 selector=#contract_products_v2
var maxHeightProductDescription = 0; //TrainingCard v2 selector=#contract_products_v2
var parent = '';
if(selector){
parent = selector + ' '; //add space
//if product is on tab(group) which is not selected, the height will return 0 because element is hidden.
//temporarily set the group to visible
var previousCss = null;
if ($(selector).length) {
previousCss = $(selector).attr("style");
if(!$(selector).is(':visible')) {
$(selector)
.css({
visibility: 'hidden',
display: 'block'
});
}
}
}
$(parent + ".product_card").each (function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
if($(this).find('.product_name').length) {
if ($(this).find('.product_name').height() > maxHeightProductName) {
maxHeightProductName =$(this).find('.product_name').height();
}
}
if($(this).find('.product_details').length) {
var descriptionHeight = $(this).find('.product_details').height();
if($(this).find('.show_more').length) {
descriptionHeight += $(this).find('.show_more').height();
}
if (descriptionHeight > maxHeightProductDescription) {
maxHeightProductDescription = descriptionHeight;
}
}
});
if(selector){
if($(selector).length) {
$(selector).attr("style", previousCss ? previousCss : "");
}
}
$(parent + ".product_card").css('height', maxHeight+addHeight);
$(parent + ".product_card").css('position', 'relative');
if(!$('#contract_products_v2').length) {
//lws
$(parent + ".product_card").find('.details').css('position', 'absolute');
$(parent + ".product_card").find('.details').css('bottom', '0');
}
if(rezizeProductName) {
$(parent + ".product_card .product_name").css('height', maxHeightProductName);
}
if(resizeProductDescription){
$(parent + ".product_card .product_details").css('height', maxHeightProductDescription);
}
}
};
var summary = new function () {
this.show = function(){
if (!use_mobile_summary) {
summary.maximize();
}
else {
$("#base_summary").show();
}
};
this.maximize = function () {
$("#base_summary").show();
if (!use_mobile_summary) {
$("#content").removeClass("col-sm-7 col-md-7 col-lg-8 col-lg-11 col-lg-12");
$("#content").addClass("col-sm-7 col-md-7 col-lg-8");
$("#base_summary").removeClass("col-sm-1 col-md-1 col-lg-1");
$("#base_summary").addClass("col-sm-5 col-md-5 col-lg-4");
$("#btn_summary_maximize").hide();
$("#base_summary_panel").show('slide', {direction: 'right'}, 500);
}
else {
$('#tc_summary_mobile .minimized').hide();
$('#tc_summary_mobile .maximized').show('slide', {direction: 'down'}, 500, function() {
});
}
};
this.minimize = function () {
if (!use_mobile_summary) {
$("#base_summary").show();
$("#base_summary_panel").hide('slide', {direction: 'right'}, 500, function() {
$("#content").removeClass("col-sm-7 col-md-7 col-lg-4 col-lg-8 col-lg-11 col-lg-12");
$("#content").addClass("col-sm-11 col-md-11 col-lg-11");
$("#base_summary").addClass("col-sm-1 col-md-1 col-lg-1");
$("#btn_summary_maximize").show();
});
}
else {
$('#tc_summary_mobile .maximized').hide('slide', {direction: 'down'}, 500, function() {
$('#tc_summary_mobile .minimized').show();
});
}
};
this.hide = function () {
if (!use_mobile_summary) {
$("#content").removeClass("col-sm-7 col-md-7 col-sm-11 col-md-11 col-lg-8 col-lg-11 col-lg-12");
$("#content").addClass("col-sm-12 col-md-12 col-lg-12");
}
$("#base_summary").hide();
};
};
var reservationBasket = new function() {
this.inProgress = false;
this.id = null;
this.locationCode = null;
this.currentAction = '';
this.callback = function(status){
if(status){
switch(reservationBasket.currentAction) {
case 'select':
if(!$('#rsv_basket_select').hasClass('invalid')){
if(!$('#rsv_basket_select input.invalid').length){
return reservationBasket.add();
}
}
break;
case 'confirmRemove':
return reservationBasket.remove(reservationBasket.id, reservationBasket.locationCode);
break;
case 'showConfirm':
return reservationBasket.confirm();
break;
}
}
else {
switch(reservationBasket.currentAction) {
case 'showConfirm':
reservationBasket.show();
break;
default:
return false;
}
}
};
this.select = function (elem){
reservationBasket.currentAction = 'select';
reservationBasket.id = $(elem).data('id');
reservationBasket.locationCode = $(elem).data('location');
if($(elem).hasClass('in_basket')){
console.log($(elem).prop('basket-allow-remove'));
if($(elem).data('basket-allow-remove') == 0){
return reservationBasket.showConfirm();
}
else {
return reservationBasket.confirmRemove();
}
}
var isQueue = 0;
if($(elem).hasClass('queue')){
isQueue = 1;
}
var url ='index.php?func=rsv_basket_select&no_framework=1&shopping_cart=0&id='+reservationBasket.id+'&location='+reservationBasket.locationCode;
if(isQueue){
//add to queue
url += '&add_queue=1';
}
var rs = $.get(url);
rs.success(function (data) {
var modal = {
title: 'Varauksen tiedot',
body: data,
buttons: {accept: 'Lisää varauskoriin', reject: 'Sulje'}
};
showConfirmation(reservationBasket.callback, modal);
if($('.select_rsv_time').length){
//suggest next reservations (group reservations, calendar)
var max_suggestions = $('.select_rsv_group').data('max-suggestions');
var suggestedItems = [];
var currElem = $(elem);
var todaysEvents = $('.fc-event-container').find('.tt_event.use_basket[data-start-date="'+$(elem).data('start-date')+'"]');
var currElemFound = false;
if($(todaysEvents).length) {
$(todaysEvents).each(function(){
if($(this).data('id') == $(elem).data('id')){
currElemFound = true;
}
else {
//suggested item must be right after current element
if(currElemFound){
if(suggestedItems.length < max_suggestions) {
if ($(this).data('start-time') == $(currElem).data('end-time')) {
suggestedItems.push($(this));
currElem = $(this);
}
}
}
}
});
}
if(suggestedItems.length > 0){
var no = 1;
var txt;
var optionValue = '';
$(suggestedItems).each(function(){
//custom txt
switch(no){
case 1:
txt = '';
break;
case 2:
txt = '';
break;
case 3:
txt = '';
break;
default:
txt = '';
break;
}
if(optionValue != ''){
optionValue += '|'; //add value separator
}
//ei oteta location huomioon vuorokohtaisesti, kalenterinäkymässä on aina sama sijainti
optionValue += $(this).data('id');
var displayTxt = $(elem).data('start-time') + ' - ' + $(this).data('end-time');
$('#select_rsv_'+no).val(optionValue);
$('#select_rsv_'+no).closest('label').prop('title', displayTxt);
$('#select_rsv_'+no).closest('label').find('span.start_end_time').html(displayTxt);
$('#select_rsv_'+no).closest('label').find('span.select_rsv_no').html(txt);
$('#select_rsv_'+no).closest('label').show();
$('#select_rsv_'+no).closest('label').addClass('visible');
no++;
});
}
else {
$('#rsv_basket_select').addClass('invalid');
$('#rsv_basket_select #error_msg').html('Varattavia aikoja ei löydy.');
$('#rsv_basket_select #error_msg').show();
//remove select
$('#rsv_basket_select .select_rsv_time').remove();
}
}
});
};
this.setCustQty = function(id){
var elem = $('#rsv_basket_select');
var inp = $(elem).find('#cust_qty');
var custQty = $(inp).val();
Cookie.set('defaultCustQty', custQty);
$(inp).removeClass('invalid');
$(elem).find('#error_msg').hide();
if(custQty != '') {
if(custQty < $(inp).prop('min')){
return $(inp).addClass('invalid');
}
reservationBasket.checkCustomersAllowed(custQty, id, elem);
if (reservationBasket.isMultipleRsv()) {
var arrId = reservationBasket.getMultipleRsvIds();
if(arrId) {
for (var i = 0; i < arrId.length; i++) {
reservationBasket.checkCustomersAllowed(custQty, arrId[i], elem);
}
}
}
}
};
this.checkCustomersAllowed = function(custQty, id, elem) {
var item = reservationBasket.getCalendarItemById(id);
if (!$(item).data('add-to-queue')) {
//tarkistetaan asiakasmäärät
var spaces_left = $(item).data('spaces-left');
if (custQty > spaces_left) {
$(elem).find('#error_msg').html('Tapahtumaan ei valitettavasti mahdu kaikki osallistujat. Vapaita paikkoja jäljellä: ' + spaces_left);
$(elem).find('#error_msg').show();
$(inp).addClass('invalid');
}
}
};
this.add = function(){
hideUserNotification();
var elem = reservationBasket.getCalendarItemById(reservationBasket.id, reservationBasket.locationCode);
var custQty = null;
if($('#rsv_basket_select').find('#cust_qty').length){
custQty = $('#rsv_basket_select').find('#cust_qty').val();
}
if(reservationBasket.inProgress){
return false;
}
var paramId = '&id='+reservationBasket.id;
var selectMultipleRsv = reservationBasket.isMultipleRsv();
if(selectMultipleRsv){
//array
paramId = '';
var arrId = reservationBasket.getMultipleRsvIds();
if(arrId) {
//add reservation id to beginning of ids array
arrId.unshift(reservationBasket.id);
for (var i = 0; i < arrId.length; i++) {
paramId += '&id[]=' + arrId[i];
}
}
}
var url ='index.php?func=rsv_basket' + paramId + '&location='+reservationBasket.locationCode;
if(custQty){
url += '&cust_qty='+custQty;
}
ShowPageLoading();
reservationBasket.inProgress = true;
var rs = $.get(url);
rs.success(function (data) {
$(elem).addClass('in_basket');
$(elem).prop('title', 'Poista korista');
if(selectMultipleRsv){
//show confirm
reservationBasket.showConfirm();
}
});
rs.fail(function (data) {
if(data && data.status == 401){
//ei kirjautunut
//window.location = 'index.php?func=login&add_res_id='+id+'&add_res_location='+location+'&add_basket=1&add_queue='+isQueue;
window.location = 'index.php?func=login';
return false;
}
reservationBasket.showErrors(data);
});
rs.always(function(data) {
reservationBasket.inProgress = false;
HidePageLoading();
var basketHtml = '';
if(data && data){
var basket = JSON.parse(data);
if(basket.basket_html){
basketHtml = basket.basket_html;
}
}
reservationBasket.update(basketHtml);
});
};
this.redirectToLogin = function(elem){
var id = $(elem).data('id');
var location = $(elem).data('location');
var isQueue = 0;
if($(elem).hasClass('queue')){
isQueue = 1;
}
if(reservationBasket.inProgress){
return false;
}
//window.location = 'index.php?func=login&add_res_id='+id+'&add_res_location='+location+'&add_basket=1&add_queue='+isQueue;
window.location = 'index.php?func=login';
return false;
};
this.confirmRemove = function(){
reservationBasket.currentAction = 'confirmRemove';
var modal = {
title: 'Varauskori',
body: 'Poista korista'+'?',
buttons: {accept: 'Kyllä', reject: 'Ei'}
};
showConfirmation(reservationBasket.callback, modal);
};
this.remove = function (id, location){
if (reservationBasket.currentAction == 'showConfirm') {
//close dialog
hideConfirmation();
}
var url ='index.php?func=rsv_basket&id='+id+'&location='+location +'&case=remove';
var rs = $.get(url);
rs.success(function (data) {
var basket = JSON.parse(data);
var basket_html = '';
if(basket.basket_html){
basket_html = basket.basket_html;
}
reservationBasket.update(basket_html);
var elem = reservationBasket.getCalendarItemById(id, location);
if($(elem).length){
$(elem).removeClass('in_basket');
$(elem).prop('title', 'Lisää varauskoriin');
}
showUserNotification('success', 'Varauksen peruminen onnistui');
});
rs.fail(function (data) {
showUserNotification('danger', 'Varauksen peruminen epäonnistui');
});
};
this.update = function(basket){
$('#rsv_basket').html(basket);
};
this.showConfirm = function(){
reservationBasket.currentAction = 'showConfirm';
var url ='index.php?func=rsv_basket_confirm&no_framework=1&shopping_cart=0';
ShowPageLoading();
var rs = $.get(url);
rs.success(function (data) {
reservationBasket.hide();
var modal = {
title: 'Vahvista varaus',
body: data,
buttons: {accept: 'Vahvista', reject: 'Sulje'}
};
showConfirmation(reservationBasket.callback, modal);
});
rs.fail(function (data) {
window.location = 'index.php?func=login';
});
rs.always(function(data){
HidePageLoading();
});
};
this.confirm = function(){
reservationBasket.currentAction = 'confirm';
var url ='index.php?func=rsv_basket&case=confirm';
ShowPageLoading();
var rs = $.get(url);
rs.success(function (data) {
Cookie.remove('defaultCustQty');
//ladataan sivu, näytetään mahdolliset viestit
location.reload(5);
});
rs.fail(function(data){
if(data && data.status == 402) {
//HTTP_PAYMENT_REQUIRED
Cookie.remove('defaultCustQty');
window.location = 'index.php?func=checkout';
return;
}
HidePageLoading();
reservationBasket.showErrors(data);
});
};
this.cancel = function(){
if (reservationBasket.currentAction == 'showConfirm') {
//close dialog
hideConfirmation();
}
var url ='index.php?func=rsv_basket&case=cancel';
ShowPageLoading();
var rs = $.get(url);
rs.success(function (data) {
Cookie.remove('defaultCustQty');
var basket = JSON.parse(data);
var basket_html = '';
if(basket.basket_html){
basket_html = basket.basket_html;
}
reservationBasket.update(basket_html);
if($("#rsv_timetable .tt_event.in_basket").length) {
$("#rsv_timetable .tt_event.in_basket").prop('title', 'Lisää varauskoriin');
$("#rsv_timetable .tt_event.in_basket").addClass('use_basket');
$("#rsv_timetable .tt_event.in_basket").removeClass('in_basket');
}
});
rs.always(function(data){
HidePageLoading();
});
};
this.showErrors = function (data){
if(data && data.responseText) {
var obj = JSON.parse(data.responseText);
if (obj.errors) {
var errorMsg = '';
for (var i in obj.errors) {
errorMsg = errorMsg + "" + obj.errors[i] + "
";
}
showUserNotification('danger', errorMsg);
}
else {
showUserNotification('danger', 'Varaus epäonnistui!');
}
}
else {
showUserNotification('danger', 'Varaus epäonnistui!');
}
};
this.getCalendarItemById = function(id, location){
if(location){
return $("#rsv_timetable .tt_event[data-id="+id+"][data-location='"+location+"']");
}
return $("#rsv_timetable .tt_event[data-id="+id+"]");
};
this.isMultipleRsv = function() {
if($('#rsv_basket_select .select_rsv_group input:checked').length){
return true;
}
return false;
};
this.getMultipleRsvIds = function(){
var ret = false;
$('#rsv_basket_select .select_rsv_group input:checked').each(function(){
ret = $(this).val().toString().split('|');
});
return ret;
};
this.toggle = function(){
$('#rsv_basket .panel-body').toggle();
$('#rsv_basket .header .badge').hide();
};
this.toggleDetail = function(elem){
$(elem).parent('.item').find('.detail').toggle();
};
this.hide = function() {
$('#rsv_basket').hide();
};
this.show = function() {
$('#rsv_basket').show();
};
}
function showUserNotification (msgType, msg) {
var notification_cont = $("#js_user_notification_cont");
var notification_alert = $("#js_user_notification_alert");
var notification_msg = $("#js_user_notification_msg");
//if modal dialog is open, there are probably several notification elements..lets show that one
if($("#dialog-confirmation #js_user_notification_cont").length){
notification_cont = $("#dialog-confirmation #js_user_notification_cont");
notification_alert = $("#dialog-confirmation #js_user_notification_alert");
notification_msg = $("#dialog-confirmation #js_user_notification_msg");
}
$(notification_cont).show();
$(notification_alert).removeClass('alert alert-success alert-danger alert-info'); //remove previous class
$(notification_alert).addClass('alert alert-'+msgType);
$(notification_msg).html(msg);
ScrollTo("body");
}
function hideUserNotification () {
var notification_cont = $("#js_user_notification_cont");
if($("#dialog-confirmation #js_user_notification_cont").length){
notification_cont = $("#dialog-confirmation #js_user_notification_cont");
}
$(notification_cont).hide();
}
function positionConfirmationDialog(selector) {
var dlg = $("#dialog-confirmation");
dlg.find('.modal-content').css("margin-top", $(selector).offset().top);
}
function showConfirmation(cb,text){
//prevent user from clicking outside the modal dialog
$('#dialog-confirmation').modal({
backdrop: 'static',
keyboard: false
});
$('#dialog-confirmation').modal('show');
$('#dialog-confirmation').attr('action','false');
/*iPhone 4 fix for modal*/
var userAgent = navigator.userAgent;
if (userAgent.match('iPhone OS 4')) {
$(".modal").css('position', 'absolute');
ScrollTo (".modal-content");
}
if(text && text != undefined){
if(text.title){
$('#dialog-confirmation .modal-title').text(text.title);
}
if(text.body){
$('#dialog-confirmation .modal-body').html(text.body);
}
if(text.buttons){
if(text.buttons.accept){
$('#dialog-confirmation button.user-accept').text(text.buttons.accept);
$('#dialog-confirmation button.user-accept').show();
}
else if(text.buttons.accept === ''){
//käännöstä ei saatu (laitekohtainen(mac) js ongelma) #19592
$('#dialog-confirmation button.user-accept').text(Lang_Ok);
$('#dialog-confirmation button.user-accept').show();
}
else {
$('#dialog-confirmation button.user-accept').hide();
}
if(text.buttons.reject){
$('#dialog-confirmation button.user-reject').text(text.buttons.reject);
$('#dialog-confirmation button.user-reject').show();
}
else if(text.buttons.reject === ''){
//käännöstä ei saatu (laitekohtainen(mac) js ongelma) #19592
$('#dialog-confirmation button.user-reject').text(Lang_Cancel);
$('#dialog-confirmation button.user-reject').show();
}
else {
$('#dialog-confirmation button.user-reject').hide();
}
}
}
$('#dialog-confirmation button').unbind('click');
$('#dialog-confirmation button').bind('click',function(){
$('#dialog-confirmation').attr('action',$(this).hasClass('user-accept'));
});
if($('#dialog-confirmation').attr('init')!='1'){
$('#dialog-confirmation').on('hidden.bs.modal', function (e) {
if(cb){
cb($('#dialog-confirmation').attr('action')=='true'?true:false);
}
});
}
$('#dialog-confirmation').attr('init','1');
InitDatePickers();
}
function hideConfirmation(){
//hide all modal dialogs
$("#dialog-confirmation").modal('hide');
$('body').removeClass('modal-open');
}
function showDetails(content){
var modal = {
title: 'Näytä lisätiedot',
body: content,
buttons: {accept: '', reject: 'Sulje'}
};
showConfirmation(null, modal);
//hide modal ok button
$('#dialog-confirmation .user-accept').hide();
}
/* rsv ask qty modal */
var rsvAskCustomerQtyData = {
title: 'Valitse henkilömäärä',
body: 'Ole hyvä syötä osallistujien määrä tapahtumaan.' +
'
' +
'',
buttons: {accept: 'Varaa',reject:'Peruuta'}
};
function rsvAskCustomerQtyCallback(status){
var do_rsv_url = GetCookie('do_rsv_url') + '&rsv_cust_qty=' + $('#rsv_cust_qty').val();
DeleteCookie('do_rsv_url');
if(status && do_rsv_url != ''){
window.location = do_rsv_url;
}
else {
return false;
}
}
var webshop = new function(){
this.viewMembership = function(id, params){
var productCard = $(".product_list .product_card[data-id="+ id +"]");
if(productCard.length){
var codes = $(productCard).data('codes');
var ids = $(productCard).data('ids');
$.get('index.php?func=lws_view_ms&ids='+ ids +'&codes='+ codes +'¶ms=' + params +'&id=' + id+'&no_framework=1', function (data) {
})
.done(function (html) {
var modal = {
title: 'Valitse seuraavat tiedot',
body: html,
buttons: {accept: 'Lisää koriin', reject: 'Sulje'}
};
showConfirmation(function(status){
if(status){
var p_id = webshop.getSelectedMembership();
if(p_id){
//gather list of extra fields
if($('.pt_extra_fields').length){
$('.pt_extra_fields select, .pt_extra_fields input').each(function(){
if($(this).val()){
params += '&'+$(this).prop('name')+'='+$(this).val();
}
});
}
window.location = 'index.php?func=lws&addcart='+ p_id + '&contract='+ id + params+'&redirect_func=checkout';
}
}
else {
return false;
}
}, modal);
})
.fail(function(data) {
})
}
return false;
};
this.getSelectedMembership = function(){
var id = '';
var rows = $('#pt_contract_products .product_row.visible');
if($(rows).length){
id = $(rows).data('id');
}
return id;
};
this.filterMembership = function(filterElement){
if(!filterElement){
filterElement = $('#pt_contract_product_filter select').first();
}
var dataFilter = $(filterElement).data('filter');
var rows = $('#pt_contract_products .product_row');
if($(rows)){
$(rows).hide();
$(rows).removeClass('visible');
var match = false;
$(rows).each(function(){
if($(this).data(dataFilter)==$(filterElement).val()){
match = true;
$(this).show();
$(this).addClass('visible');
}
});
if(!match){
$('#pt_contract_products .product_row.product_not_found').show();
}
}
};
};
function cancelPayment() {
var modal = {
title: 'Keskeytä ostos',
body: 'Haluatko varmasti keskeyttää ostoprosessin?',
buttons: {accept: Lang_yes, reject: Lang_no}
};
showConfirmation(cancelPaymentCallback, modal);
}
function cancelPaymentCallback(status) {
if(status) {
if($('#cancel_url').length) {
var cancel_url = $('#cancel_url').val();
if(cancel_url != '') {
window.location = cancel_url;
}
}
}
return false;
}
var progressbar = new function(){
this.set = function(name) {
var step;
//set every step before current step active
var item = $('#progressbar ul.progressbar li[data-name="' + name + '"]');
if (item) {
$('#progressbar ul.progressbar li').removeClass('active').removeClass('current');
step = $(item).data('value');
$('#progressbar ul.progressbar li').each(function() {
if ($(this).data('value') <= step) {
$(this).addClass('active');
if ($(this).data('value') == step) {
$(this).addClass('current');
}
}
});
}
};
this.setOnClick = function(name, setFunction){
var item = $('#progressbar ul.progressbar li[data-name="' + name + '"]');
if(item){
$(item).css('cursor', 'pointer');
$(item).off().click(setFunction);
}
};
}