$.fbuilder.typeList.push( { id:"fapp", name:"Appointment", control_category:1 } ); $.fbuilder.controls[ 'fapp' ]=function(){ this.init(); }; $.extend( $.fbuilder.controls[ 'fapp' ].prototype, $.fbuilder.controls[ 'ffields' ].prototype, { title:"Appointment", ftype:"fapp", services:new Array({name:"Sample Service",price:24.99,capacity:1,duration:60,pb:0,pa:0,ohindex:0}), /*openhours:new Array({type:"all",d:"",h1:8,m1:0,h2:17,m2:0}),new Array({name:"Default",openhours:new Array({type:"all",d:"",h1:8,m1:0,h2:17,m2:0})})*/ openhours:new Array(), allOH:new Array({name:"Default",openhours:new Array({type:"all",d:"",h1:8,m1:0,h2:17,m2:0})}), dateFormat:"mm/dd/yy", showDropdown:false, showTotalCost:false, showTotalCostFormat:"$ {0}", showEndTime:false, showQuantity:false, usedSlotsCheckbox:false, avoidOverlaping:true, emptySelectCheckbox:false, emptySelect:"-- Please select service --", dropdownRange:"-10:+10", working_dates:[true,true,true,true,true,true,true], numberOfMonths:1, maxNumberOfApp:0, firstDay:0, minDate:"0", maxDate:"", defaultDate:"", invalidDates:"", tmpinvalidDates:[], required:true, bSlotsCheckbox: true, bSlots:30, militaryTime:1, display:function() { return '
'+this.userhelp+'
'; }, msort:function(arr){ for(var i =0;iarr[j].type || (arr[i].type==arr[j].type && arr[i].type=="special" && arr[i].d>arr[j].d) || (arr[i].type==arr[j].type && arr[i].type!="special" && arr[i].h1*60+arr[i].m1>arr[j].h1*60+arr[j].m1)){ var swap = arr[i]; arr[i] = arr[j]; arr[j] = swap; } } } return arr; }, normalizeSelectIndex:function(ind) { if (this.emptySelectCheckbox) ind--; return ind; }, showopenhourAll:function() { var str = "", e = $( '#field' + this.form_identifier + '-' + this.index + ' .fieldCalendar'+this.name ); var me = this; for (var i=0;i'; if (i>0) str += '
'; str += me.showOpenHours(me.allOH[i].openhours,me.dateFormat); str += '
'; } $("#openHoursSection").html(str); $(".openhours_special").datepicker('destroy').datepicker({dateFormat:me.dateFormat, onSelect: function(d,inst) { var i = inst.input.parents(".openhoursdiv").attr("i")*1; me.allOH[i].openhours[inst.input.attr("i")].d = $.datepicker.formatDate("yy-mm-dd", $.datepicker.parseDate(me.dateFormat, d)); $.fbuilder.reloadItems({'field':me}); }}); $(".service_openhours").each( function(){ var str = ""; for (var i=0;i'+me.allOH[i].name+''; $(this).html(str); $(this).val(me.services[$(this).attr("i")*1].ohindex); if (me.allOH.length>1) $(this).parent().css("display","block"); else $(this).parent().css("display","none"); }); }, showOpenHours:function(openhours,df) { var str="", dayNames = $.datepicker.regional[""].dayNames; str += '
Day(s)
From
To
'; for (var i=0;i'; for (var d=0;d<7;d++) str += ''; str += ''; str += ''; str += ''; str += ''; str += ''; } return str; }, showSlots:function() { function isOpen(h,m,s) { for (var i=0;i=s[i].h1*60+s[i].m1) && (h*60+m<=s[i].h2*60+s[i].m2)) return "sopen"; return ""; } var slots = ''; for (var i=0;i<24;i++) { slots += '
'+i+'
'; for (var j=0;j<60;j=j+5) slots += '
'; slots += '
'; } return slots+this.slots.length; }, editItemEvents:function() { var me = this; me.showopenhourAll(); var evt = [ {s:"#sDateFormat",e:"change", l:"dateFormat"}, {s:"#sNumberOfMonths",e:"change", l:"numberOfMonths"}, {s:"#sMaxNumberOfApp",e:"change", l:"maxNumberOfApp"}, {s:"#sFirstDay",e:"change", l:"firstDay"}, {s:"#sMilitaryTime",e:"change", l:"militaryTime"}, {s:"#sMinDate",e:"change", l:"minDate"}, {s:"#sMaxDate",e:"change", l:"maxDate"}, {s:"#sInvalidDates",e:"change", l:"invalidDates"}, {s:"#sDefaultDate",e:"change", l:"defaultDate"}, {s:"#sDropdownRange",e:"keyup", l:"dropdownRange"}, {s:"#sShowTotalCostFormat",e:"keyup", l:"showTotalCostFormat"}, {s:"#sEmptySelectCheckbox",e:"click", l:"emptySelectCheckbox", f:function(el){ var v = el.is(':checked'); $("#sEmptySelectDiv")[( v ) ? 'show' : 'hide'](); return v; } }, {s:"#sBSlotsCheckbox",e:"click", l:"bSlotsCheckbox", f:function(el){ var v = el.is(':checked'); $("#sBSlotsDiv")[( v ) ? 'hide' : 'show'](); return v; } }, {s:"#sEmptySelect",e:"keyup", l:"emptySelect"}, {s:"#sBSlots",e:"change", l:"bSlots"}, {s:"#sShowEndTime",e:"click", l:"showEndTime", f:function(el){ return el.is(':checked'); } }, {s:"#sShowQuantity",e:"click", l:"showQuantity", f:function(el){ return el.is(':checked'); } }, {s:"#sUsedSlotsCheckbox",e:"click", l:"usedSlotsCheckbox", f:function(el){ return el.is(':checked'); } }, {s:"#sAvoidOverlaping",e:"click", l:"avoidOverlaping", f:function(el){ return el.is(':checked'); } }, {s:"#sShowTotalCost",e:"click", l:"showTotalCost", f:function(el){ var v = el.is(':checked'); $("#divTotalCostFormat")[( v ) ? 'show' : 'hide'](); return v; } }, {s:"#sShowDropdown",e:"click", l:"showDropdown", f:function(el){ var v = el.is(':checked'); $("#divdropdownRange")[( v ) ? 'show' : 'hide'](); return v; } } ]; $(".working_dates input").bind("click", {obj: this}, function(e) { e.data.obj.working_dates[$(this).val()] = $(this).is(':checked'); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(".service_name").bind("keyup", {obj: this}, function(e) { e.data.obj.services[$(this).attr("i")].name= $(this).val(); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(".service_price").bind("keyup", {obj: this}, function(e) { e.data.obj.services[$(this).attr("i")].price= Number($(this).val().replace(/[^0-9\.]+/g,"")); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(".service_capacity").bind("keyup", {obj: this}, function(e) { e.data.obj.services[$(this).attr("i")].capacity= $(this).val(); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(".service_duration").bind("change", {obj: this}, function(e) { e.data.obj.services[$(this).attr("i")].duration= $(this).val(); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(".service_paddingbefore").bind("change", {obj: this}, function(e) { e.data.obj.services[$(this).attr("i")].pb = parseInt($(this).val()); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(".service_paddingafter").bind("change", {obj: this}, function(e) { e.data.obj.services[$(this).attr("i")].pa = parseInt($(this).val()); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(document).off("change", ".service_openhours").on("change", ".service_openhours", {obj: this}, function(e) { e.data.obj.services[$(this).attr("i")].ohindex = parseInt($(this).val()); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(".services .choice_up").bind("click", {obj: this}, function(e) { var i = $(this).attr("i")*1; if (i!=0) e.data.obj.services.splice(i-1, 0, e.data.obj.services.splice(i, 1)[0]); $.fbuilder.editItem(e.data.obj.index); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(".services .choice_down").bind("click", {obj: this}, function(e) { var i = $(this).attr("i")*1; var n = $(this).attr("n")*1; if (i!=n) e.data.obj.services.splice(i, 0, e.data.obj.services.splice(i+1, 1)[0]); $.fbuilder.editItem(e.data.obj.index); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(".services .choice_add").bind("click", {obj: this}, function(e) { e.data.obj.services.splice($(this).attr("i")*1+1,0,{name:"Sample Service",price:24.99,capacity:1,duration:60,pb:0,pa:0,ohindex:0}); $.fbuilder.editItem(e.data.obj.index); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(".services .choice_remove").bind("click", {obj: this}, function(e) { if (e.data.obj.services.length>1) e.data.obj.services.splice( $(this).attr("i")*1, 1 ) $.fbuilder.editItem(e.data.obj.index); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(document).off("change", ".openhours_type").on("change", ".openhours_type", {obj: this}, function(e) { var i = $(this).parents(".openhoursdiv").attr("i")*1; e.data.obj.allOH[i].openhours[$(this).attr("i")].type= $(this).val(); if ($(this).val()=="special") $(this).parents(".choicesEdit").find(".openhours_special").css("visibility","visible"); else $(this).parents(".choicesEdit").find(".openhours_special").css("visibility","hidden"); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(document).off("change", ".openhours_from").on("change", ".openhours_from", {obj: this}, function(e) { var i = $(this).parents(".openhoursdiv").attr("i")*1; e.data.obj.allOH[i].openhours[$(this).attr("i")].h1= $(this).find(":selected").attr("h"); e.data.obj.allOH[i].openhours[$(this).attr("i")].m1= $(this).find(":selected").attr("m"); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(document).off("change", ".openhours_to").on("change", ".openhours_to", {obj: this}, function(e) { var i = $(this).parents(".openhoursdiv").attr("i")*1; e.data.obj.allOH[i].openhours[$(this).attr("i")].h2= $(this).find(":selected").attr("h"); e.data.obj.allOH[i].openhours[$(this).attr("i")].m2= $(this).find(":selected").attr("m"); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(document).off("click", ".openhours .choice_add").on("click", ".openhours .choice_add", {obj: this}, function(e) { var i = $(this).parents(".openhoursdiv").attr("i")*1; e.data.obj.allOH[i].openhours.splice($(this).attr("i")*1+1,0,{type:"all",d:"",h1:8,m1:0,h2:17,m2:0}); e.data.obj.allOH[i].openhours = me.msort(e.data.obj.allOH[i].openhours); $.fbuilder.editItem(e.data.obj.index); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(document).off("click", ".openhours .choice_remove").on("click", ".openhours .choice_remove", {obj: this}, function(e) { var i = $(this).parents(".openhoursdiv").attr("i")*1; if (e.data.obj.allOH[i].openhours.length>1) e.data.obj.allOH[i].openhours.splice( $(this).attr("i")*1, 1 ); $.fbuilder.editItem(e.data.obj.index); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(document).off("click", "input.addOpenHours").on("click", "input.addOpenHours", {obj: this}, function(e) { e.data.obj.allOH[e.data.obj.allOH.length] = {name:"Special",openhours:new Array({type:"all",d:"",h1:8,m1:0,h2:17,m2:0})}; me.showopenhourAll(); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(document).off("click", "input.deleteopenhours").on("click", "input.deleteopenhours", {obj: this}, function(e) { var ind = $(this).attr("i")*1; for (var i=0;i ind) e.data.obj.services[i].ohindex--; else if (e.data.obj.services[i].ohindex == ind) e.data.obj.services[i].ohindex = 0; e.data.obj.allOH.splice(ind, 1 ); me.showopenhourAll(); $.fbuilder.reloadItems({'field':e.data.obj}); }); $(document).off("keyup", "input.nameopenhours").on("keyup", "input.nameopenhours", {obj: this}, function(e) { e.data.obj.allOH[$(this).attr("i")*1].name = $(this).val(); $.fbuilder.reloadItems({'field':e.data.obj}); }); $.fbuilder.controls[ 'ffields' ].prototype.editItemEvents.call(this, evt); }, after_show:function() { var me = this, e = $( '#field' + me.form_identifier + '-' + me.index + ' .fieldCalendar'+me.name ), d = $( '#field' + me.form_identifier + '-' + me.index + ' .fieldCalendarService'+me.name ), str = "", op = ""; if (me.openhours.length>0)/*compatible with old version*/ { if (!me.openhours[0].name) { var obj = {name:"Default",openhours:me.openhours.slice(0)}; me.openhours = new Array(); me.openhours[0] = obj; } me.allOH = new Array(); me.allOH = me.openhours.slice(0); me.openhours = new Array(); } for (var i=0; i< me.services.length;i++) me.services[i].ohindex = me.services[i].ohindex || 0; function onChangeDateOrService(d) { if (!(!me.emptySelectCheckbox || (me.emptySelectCheckbox && $(".fieldCalendarService"+me.name+" select option:selected").index() > 0 ))) { $( '#field' + me.form_identifier + '-' + me.index + ' .slotsCalendar'+me.name ).html(""); return; } function formattime(t) { var h = Math.floor(t/60); var m = t%60; var suffix = ""; if (me.militaryTime==0) { if (h>12) { h = h-12; suffix = " PM"; } else if (h==12) suffix = " PM"; else suffix = " AM"; } return (((h<10)?"":"")+h+":"+(m<10?"0":"")+m)+suffix; } function getSlots(arr, duration, bduration, pa, pb) { var str = ""; var a1 = new Array(); var minutesStart = 0; bduration += pa + pb; for (var i=0;i= et) et += 24 * 60; while (st + duration + pa <= et && st<24 * 60) { if ($.inArray(st ,a1)==-1 ) if (st>=minutesStart) a1[a1.length] = st; st += bduration; } } a1.sort(function (a, b) {return a - b;}); for (var i=0;i"; return str; } var arr = new Array(); var day = d; var s = $( '#field' + me.form_identifier + '-' + me.index + ' .slotsCalendar'+me.name ); var ohindex = me.services[me.normalizeSelectIndex($(".fieldCalendarService"+me.name+" select option:selected").index())].ohindex; for (var i=0;i"+$.datepicker.formatDate(me.dateFormat, $.datepicker.parseDate("yy-mm-dd", d))+"
"+str+""); } for (var i=0;i'+me.services[i].name+''; if (me.emptySelectCheckbox) str = ''+ str ; d.html(''); if (me.emptySelectCheckbox) d.find("select").prop('selectedIndex', 1); $(".fieldCalendarService"+me.name+" select").bind("change", function() { if (e.datepicker("getDate")) onChangeDateOrService($.datepicker.formatDate('yy-mm-dd', e.datepicker("getDate"))) }); this.tmpinvalidDates = this.invalidDates; this.tmpinvalidDates = this.tmpinvalidDates.replace( /\s+/g, '' ); if( !/^\s*$/.test( this.tmpinvalidDates ) ) { var dateRegExp = new RegExp( /^\d{1,2}\/\d{1,2}\/\d{4}$/ ), counter = 0, dates = this.tmpinvalidDates.split( ',' ); this.tmpinvalidDates = []; for( var i = 0, h = dates.length; i < h; i++ ) { var range = dates[ i ].split( '-' ); if( range.length == 2 && range[0].match( dateRegExp ) != null && range[1].match( dateRegExp ) != null ) { var fromD = new Date( range[ 0 ] ), toD = new Date( range[ 1 ] ); while( fromD <= toD ) { this.tmpinvalidDates[ counter ] = fromD; var tmp = new Date( fromD.valueOf() ); tmp.setDate( tmp.getDate() + 1 ); fromD = tmp; counter++; } } else { for( var j = 0, k = range.length; j < k; j++ ) { if( range[ j ].match( dateRegExp ) != null ) { this.tmpinvalidDates[ counter ] = new Date( range[ j ] ); counter++; } } } } } me.special_days = new Array(); if (!me.emptySelectCheckbox || (me.emptySelectCheckbox && $(".fieldCalendarService"+me.name+" select option:selected").index() > 0 )) { var ohindex = me.services[me.normalizeSelectIndex($(".fieldCalendarService"+me.name+" select option:selected").index())].ohindex; for (var i=0;i0) me.dateFormat = $("#date_format").val(); var hrs = 0; me.minDateTmp = me.minDate; if (me.minDate!=="") { if (me.minDate.indexOf("h")!= -1) { if (me.minDate.indexOf(" ")!= -1) { var a = me.minDate.split(" "); var find = false; for (var i=0;(i -1 ) return false; if (me.working_dates[date.getDay()]==0) return false; return true; } var sum = 0; for (var i=0;i0) { var nextdateAvailable = e.datepicker("getDate"); while (!DisableSpecificDates(nextdateAvailable)) nextdateAvailable.setDate(nextdateAvailable.getDate() + 1); e.datepicker("setDate", nextdateAvailable); onChangeDateOrService($.datepicker.formatDate('yy-mm-dd', nextdateAvailable)); } }, showSpecialDataInstance: function() { var str = "", e = $( '#field' + this.form_identifier + '-' + this.index + ' .fieldCalendar'+this.name ),dayNames = $.datepicker.regional[""].dayNames; str += '
'; for (var i=0;i'; str += ''; str += '
Duration
Padding time before and after
'; str += ''; str += ''; str += ''; str += '
Open hours
'; str += '
'; } str += '
Generate time slots automatically based on service duration'; str += '
Generate slots every
'; str += '
Show used slots
'; str += '
Make user choose service before display times'; if (typeof apphourbk_cmadmin !== 'undefined') str += '
Avoid overlaping between services [help?]
'; str += '
Text '; str += '
'; str += ''; str += '
'; str += '
'; if (typeof apphourbk_cmadmin !== 'undefined') str += ''; str += '
'; str += '

SuMoTuWeThFrSa
'; var sfirst = ""; for (var i=0;i<7;i++) sfirst += ''; str += '

'; var snumberOfM = ""; for (var i=1;i<=12;i++) snumberOfM += ''; str += '

'; str += '

'; var snumberOfApp = ""; for (var i=0;i<=10;i++) snumberOfApp += ''; str += '

'; str += '

'; str += '

'; str += '

'; str += '

'; str += '
Year Range [help?]:
'; str += '
'; str += '
Total cost format [help?]:
'; str += '
'; str += '
'; return str; } } );