'+$.trim(tmp[i])+'
';
}
}
return '';
},
after_show: function()
{
var me = this,
tmp = me.dformat.split(' ');
$.validator.messages["phone"] = $.validator.messages["digits"];
if(!('phone' in $.validator.methods))
$.validator.addMethod("phone", function(value, element)
{
if( this.optional( element ) ) return true;
else return /^\+{0,1}\d*$/.test(value);
});
for (var i = 0, h = tmp.length; i < h; i++ )
{
$( '#'+me.name+'_'+i ).bind( 'change', function(){
var v = '';
for( var i = 0; i < tmp.length; i++ )
{
v += $( '#'+me.name+'_'+i ).val();
}
$( '#'+me.name ).val( v ).change();
} );
if( i+1 < h )
{
$('#'+me.name+'_'+i).bind( 'keyup', { 'next': i+1 }, function( evt ){
var e = $( this );
if( e.val().length == e.attr( 'maxlength' ) )
{
e.change();
$( '#'+me.name+'_'+evt.data.next ).focus();
}
} );
}
}
},
val:function(raw)
{
raw = raw || false;
var e = $( '[id="' + this.name + '"]:not(.ignore)' );
if( e.length ) return $.fbuilder.parseValStr( e.val(), raw );
return 0;
},
setVal:function( v )
{
$( '[name="'+this.name+'"]' ).val( v );
v = $.trim( v ).replace( /[^\d]/g, ' ').split( ' ' );
for( var i in v ) $( '[id="' + this.name + '_' + i + '"]' ).val( v[ i ] );
}
}
); $.fbuilder.controls[ 'fCommentArea' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fCommentArea' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Comments here",
ftype:"fCommentArea",
userhelp:"A description of the section goes here.",
show:function()
{
return '';
}
}
); $.fbuilder.controls[ 'fhidden' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fhidden' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
ftype:"fhidden",
title:"",
predefined:"",
show:function()
{
return '';
}
}
); $.fbuilder.controls[ 'fSectionBreak' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fSectionBreak' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Section Break",
ftype:"fSectionBreak",
userhelp:"A description of the section goes here.",
show:function()
{
return '';
}
}
); $.fbuilder.controls[ 'fPageBreak' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fPageBreak' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Page Break",
ftype:"fPageBreak",
show:function()
{
return '';
}
}
); $.fbuilder.controls[ 'fsummary' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fsummary' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Summary",
ftype:"fsummary",
fields:"",
titleClassname:"summary-field-title",
valueClassname:"summary-field-value",
fieldsArray:[],
show:function()
{
var me = this,
p = $.trim( me.fields.replace( /\,+/g, ',') ).split( ',' ),
l = p.length;
if( l )
{
var str = '';
return str;
}
},
after_show: function(){
var me = this,
p = $.trim(me.fields.replace( /\,+/g, ',') ).split( ',' ),
l = p.length;
if( l )
{
for( var i = 0; i < l; i++ )
{
if( !/^\s*$/.test( p[ i ] ) )
{
p[ i ] = $.trim( p[ i ] );
me.fieldsArray.push( p[ i ] + me.form_identifier );
$( document ).on( 'change', '#' + p[ i ] + me.form_identifier, function(){ me.update(); } );
}
}
$( document ).on( 'showHideDepEvent', function( evt, form_identifier )
{
me.update();
});
$( '#cp_calculatedfieldsf_pform'+me.form_identifier ).bind( 'reset', function(){ setTimeout( function(){ me.update(); }, 10 ); } );
}
},
update:function()
{
for ( var j = 0, k = this.fieldsArray.length; j < k; j++ )
{
var i = this.fieldsArray[ j ],
e = $( '[id="' + i + '"]'),
tt = $( '[ref="' + i + '"]');
if( e.length && tt.length )
{
//var t = $( '#' + i ).closest( '.fields' ).find( 'label[for="'+i+'"]' ).text(),
var t = $( '#' + i ).closest( '.fields' ).find( 'label:first' ).html(),
v = [];
e.each(
function(){
var e = $(this);
if( /(checkbox|radio)/i.test( e.attr( 'type' ) ) && !e.is( ':checked' ) )
{
return;
}
else if( e[0].tagName == 'SELECT' )
{
v.push( $(e[0].options[ e[0].selectedIndex ]).attr( 'vt' ) );
}
else
{
if( e.attr( 'vt' ) )
{
v.push( e.attr( 'vt' ) );
}
else if( e.attr( 'summary' ) )
{
v.push( $( '#' + i ).closest( '.fields' ).find( '.'+e.attr( 'summary' )+i ).html() );
}
else
{
v.push( e.val() );
}
}
}
);
try
{
if (t.substring(t.length-1)=='*')
t = t.substring(0, t.length-1);
if (t.substring(t.length-1)==':')
t = t.substring(0, t.length-1);
}
catch (e)
{}
tt.find( '.cff-summary-title' ).html( ( /^\s*$/.test( t ) ) ? '' : t );
tt.find( '.cff-summary-value' ).html( v.join( ', ' ) );
if (v.join( ', ' ).trim()=="")
tt.addClass("emptyvalue");
else
tt.removeClass("emptyvalue");
if( e.hasClass( 'ignore' ) )
{
tt.hide();
}
else
{
tt.show();
}
}
}
}
});
$.fbuilder.controls[ 'datasource' ] = function(){};
$.fbuilder.controls[ 'datasource' ].prototype = {
isDataSource:true,
active : '',
list : {
'database' : {
databaseData: '',
queryData : {
active: 'structure',
query: '',
value: '',
text: '',
table: '',
where: '',
orderby: ''
},
getData : function( callback, p )
{
var url = document.location.href,
data = $.extend( {}, this.queryData );
if( data.active == 'structure' )
{
data.where = btoa(p.replaceVariables( data.where ));
data.orderby = btoa(p.replaceVariables( data.orderby ));
}
else
{
data.query = p.replaceVariables( data.query );
}
$.ajax(
{
dataType : 'json',
url : url,
cache : false,
data : $.extend( { ahbqeaction7892593a5cc7587f8461ac29b05479bc: 'QmNpa2c2NktBVloyY1hiZmNLQWwweGo5VzRVVndJYzhvK3RRdUg0aGpGRT0=' }, this.databaseData, data ),
success : function( data ){
callback( data );
}
}
);
}
},
'csv' : {
csvData : {
text : 0,
value : 0,
fields : [],
rows : []
},
getData : function( callback )
{
var obj = {
data : []
};
for( var i in this.csvData.rows )
{
var text = this.csvData.text,
value = this.csvData.value;
if( typeof this.csvData.rows[ i ].length == 'undefined' )
{
text = this.csvData.fields[ text ];
value = this.csvData.fields[ value ];
}
obj.data.push( { text: this.csvData.rows[ i ][ text ], value : this.csvData.rows[ i ][ value ] } );
}
callback( obj );
}
},
'posttype' : {
posttypeData:{
posttype : '',
value : '',
text : '',
last : '',
id : ''
},
getData : function( callback, p )
{
var url = document.location.href,
data = $.extend( {}, this.posttypeData );
if( !/^\s*$/.test( data.id ) )
{
data.id = p.replaceVariables( data.id );
}
$.ajax(
{
dataType : 'json',
url : url,
cache : false,
data : $.extend( { ahbqeaction7892593a5cc7587f8461ac29b05479bc: 'MUxYcWZ1U09iblE4K2N6TDBMMEV1QT09' }, data ),
success : function( data ){
callback( data );
}
}
);
}
},
'taxonomy' : {
taxonomyData:{
taxonomy : '',
value : '',
text : '',
id : '',
slug : ''
},
getData : function( callback, p )
{
var url = document.location.href,
data = $.extend( {}, this.taxonomyData );
if( !/^\s*$/.test( data.id ) )
{
data.id = p.replaceVariables( data.id );
}
if( !/^\s*$/.test( data.slug ) )
{
data.slug = p.replaceVariables( data.slug );
}
$.ajax(
{
dataType : 'json',
url : url,
cache : false,
data : $.extend( { ahbqeaction7892593a5cc7587f8461ac29b05479bc: 'bTVSZGZYcUdRTENlVnRGRit1Y0RwQT09' }, data ),
success : function( data ){
callback( data );
}
}
);
}
},
'user' : {
userData : {
logged : false,
text : '',
value : '',
id : '',
login : ''
},
getData : function( callback, p )
{
var url = document.location.href,
data = $.extend( {}, this.userData );
if( !data.logged )
{
if( !/^\s*$/.test( data.id ) )
{
data.id = p.replaceVariables( data.id );
}
if( !/^\s*$/.test( data.login ) )
{
data.login = p.replaceVariables( data.login );
}
}
$.ajax(
{
dataType : 'json',
url : url,
cache : false,
data : $.extend( { ahbqeaction7892593a5cc7587f8461ac29b05479bc: 'akcrRnFLcW4zVnB2dFBIZFhza0F3dz09' }, data ),
success : function( data ){
callback( data );
}
}
);
}
}
},
getData : function( callback )
{
this.list[ this.active ].getData( callback, this );
},
replaceVariables : function( str )
{
var _match,
tmpArr = []; // To avoid duplicate handles
while ( _match = /<[%](fieldname\d+)[%]>/.exec( str ) )
{
var me = this,
e = _match[ 1 ]+this.form_identifier,
f = $.fbuilder[ 'forms' ][ this.form_identifier ].getItem( e );
if( ( typeof this.hasBeenPutRelationHandles == 'undefined' || !this.hasBeenPutRelationHandles ) && $.inArray( _match[ 1 ], tmpArr ) == -1 )
{
$( document ).on( 'change',
'#'+e,
function()
{
me.after_show();
}
);
tmpArr.push( _match[ 1 ] );
}
if( f )
{
str = str.replace( _match[ 0 ], f.val() );
}
}
this.hasBeenPutRelationHandles = true;
return str;
}
}; $.fbuilder.controls[ 'ftextds' ]=function(){};
$.extend(
$.fbuilder.controls[ 'ftextds' ].prototype,
$.fbuilder.controls[ 'ftext' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"ftextds",
show:function()
{
return $.fbuilder.controls[ 'ftext' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
if (!me.predefined) $( '#' + me.name ).val( data.data[ 0 ][ 'value' ] ).change();
}
}
}
);
}
}); $.fbuilder.controls[ 'femailds' ]=function(){};
$.extend(
$.fbuilder.controls[ 'femailds' ].prototype,
$.fbuilder.controls[ 'femail' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"femailds",
show:function()
{
return $.fbuilder.controls[ 'femail' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
if (!me.predefined) $( '#' + me.name ).val( data.data[ 0 ][ 'value' ] ).change();
}
}
}
);
}
}); $.fbuilder.controls[ 'ftextareads' ]=function(){};
$.extend(
$.fbuilder.controls[ 'ftextareads' ].prototype,
$.fbuilder.controls[ 'ftextarea' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"ftextareads",
show:function()
{
return $.fbuilder.controls[ 'ftextarea' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
if (!me.predefined) $( '#' + me.name ).val( data.data[ 0 ][ 'value' ] ).change();
}
}
}
);
}
}); $.fbuilder.controls[ 'fcheckds' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fcheckds' ].prototype,
$.fbuilder.controls[ 'fcheck' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fdropdownds",
show:function()
{
return '';
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
var str = '';
for( var i = 0, h = data.data.length; i < h; i++ )
{
var e = data.data[ i ];
str += ' ' + e.text + '
';
}
$( '#field' + me.form_identifier + '-' + me.index + ' .dfield' ).html( str ).change();
}
}
);
}
}); $.fbuilder.controls[ 'fradiods' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fradiods' ].prototype,
$.fbuilder.controls[ 'fradio' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fradiods",
show:function()
{
return '';
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
var str = '';
for( var i = 0, h = data.data.length; i < h; i++ )
{
var e = data.data[ i ];
str += ' ' + e.text + '
';
}
$( '#field' + me.form_identifier + '-' + me.index + ' .dfield' ).html( str ).change();
}
}
);
}
}
); $.fbuilder.controls[ 'fPhoneds' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fPhoneds' ].prototype,
$.fbuilder.controls[ 'fPhone' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fPhoneds",
show:function()
{
return $.fbuilder.controls[ 'fPhone' ].prototype.show.call( this );
},
after_show : function()
{
var me = this;
$.fbuilder.controls[ 'fPhone' ].prototype.after_show.call( me );
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( me, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
var v = data.data[ 0 ].value,
p = $.trim( me.dformat.replace(/[^\s#]/g, '' ).replace( /\s+/g, ' ' ) ).split( ' ' ),
h = p.length,
r = '', e;
for( var i = 0; i < h; i++ )
{
r += '(.{' + p[ i ].length + '})';
}
v = v.replace( /\s+/, '' );
e = ( new RegExp( r ) ).exec( v );
if( e )
{
for( var i = 0; i < h; i++ )
{
if (!me.predefined) $( '#' + me.name + '_' + i ).val( e[ i+1 ] ).change();
}
}
}
}
}
);
}
}
); $.fbuilder.controls[ 'fdropdownds' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fdropdownds' ].prototype,
$.fbuilder.controls[ 'fdropdown' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fdropdownds",
first_choice:false,
first_choice_text:"",
show:function()
{
this.choices = [];
return $.fbuilder.controls[ 'fdropdown' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
var str = '', t, v;
for( var i = 0, h = data.data.length; i < h; i++ )
{
v = ( ( typeof data.data[ i ][ 'value' ] != 'undefined' ) ? data.data[ i ][ 'value' ] : '' );
t = ( ( typeof data.data[ i ][ 'text' ] != 'undefined' ) ? data.data[ i ][ 'text' ] : v );
str += '' + t + ' ';
}
str = me.first_choice ? ''+$.fbuilder.htmlEncode(me.first_choice_text)+' ' + str : str;
$( '#' + me.name ).html( str ).change();
}
if(me.select2)
{
$('#'+me.name).next('.cff-select2-container').remove();
$('#'+me.name).after(' ');
$('#'+me.name).on('change', function(){$(this).valid();});
if('select2' in $.fn)
$('#'+me.name).select2({'dropdownParent':$('#'+me.name).next('.cff-select2-container')});
else
$(document).ready(function(){if('select2' in $.fn) $('#'+me.name).select2({'dropdownParent':$('#'+me.name).next('.cff-select2-container')});});
}
}
);
}
}); $.fbuilder.controls[ 'fhiddends' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fhiddends' ].prototype,
$.fbuilder.controls[ 'fhidden' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fhiddends",
show:function()
{
return $.fbuilder.controls[ 'fhidden' ].prototype.show.call( this );
},
after_show : function()
{
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
if (!me.predefined) $( '#' + me.name ).val( data.data[ 0 ][ 'value' ] ).change();
}
}
}
);
}
}
); $.fbuilder.controls[ 'fcontainer' ] = function(){};
$.fbuilder.controls[ 'fcontainer' ].prototype = {
fields:[],
columns:1,
after_show: function()
{
var e = $( '#'+this.name ), f;
for( var i = 0, h = this.fields.length; i < h; i++ )
{
f = $( '#'+this.fields[ i ]+this.form_identifier ).closest( '.fields' ).detach();
if( this.columns > 1 )
{
f.addClass( 'column'+this.columns );
if( i%this.columns == 0 ) f.css( 'clear', 'left' );
}
f.appendTo( e );
}
},
showHideDep:function( toShow, toHide )
{
var hide = ( $.inArray( this.name, toHide ) != -1 ),
index;
for( var i = 0, h = this.fields; i < h; i++ )
{
if( $.inArray( this.fields[ i ]+this.form_identifier, toHide ) == -1 )
{
toHide.push( this.fields[ i ]+this.form_identifier );
index = $.inArray( d[ i ], toShow );
if( index != -1 )
{
toShow.splice( index, 1);
}
$( '#' + this.fields[ i ]+this.form_identifier ).closest( '.fields' )
.find( '.field' )
.each(function()
{
$(this).addClass('ignore');
});
}
}
}
}; $.fbuilder.controls[ 'ffieldset' ]=function(){};
$.extend(
$.fbuilder.controls[ 'ffieldset' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Untitled",
ftype:"ffieldset",
fields:[],
columns:1,
show:function()
{
return '';
},
after_show: function()
{
$.fbuilder.controls[ 'fcontainer' ].prototype.after_show.call(this);
},
showHideDep:function( toShow, toHide )
{
$.fbuilder.controls[ 'fcontainer' ].prototype.showHideDep.call( this, toShow, toHide );
}
}
); $.fbuilder.controls[ 'fdiv' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fdiv' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
ftype:"fdiv",
fields:[],
columns:1,
show:function()
{
return '';
},
after_show: function()
{
$.fbuilder.controls[ 'fcontainer' ].prototype.after_show.call(this);
},
showHideDep:function( toShow, toHide )
{
$.fbuilder.controls[ 'fcontainer' ].prototype.showHideDep.call( this, toShow, toHide );
}
}
); $.fbuilder.controls[ 'fMedia' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fMedia' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
ftype:"fMedia",
sMediaType:"image", // image, audio, video
data:{
image:{
sWidth:"",
sHeight:"",
sSrc:"",
sAlt:"",
sLink:"",
sTarget:"",
sFigcaption: ""
},
audio:{
sWidth:"",
sSrc:"",
sSrcAlt:"",
sControls:1,
sLoop:0,
sAutoplay:0,
sMuted:0,
sPreload: "auto",
sFallback: "",
sFigcaption: ""
},
video:{
sWidth:"",
sHeight:"",
sSrc:"",
sSrcAlt:"",
sPoster:"",
sControls:1,
sLoop:0,
sAutoplay:0,
sMuted:0,
sPreload: "auto",
sFallback: "",
sFigcaption: ""
}
},
_show_image: function()
{
var d = this.data.image,
esc = $.fbuilder.htmlEncode,
a = [],
l = [],
r = '';
if( $.trim( d.sWidth ) ) a.push( 'width="'+esc( d.sWidth )+'"' );
if( $.trim( d.sHeight ) ) a.push( 'height="'+esc( d.sHeight )+'"' );
if( $.trim( d.sSrc ) ) a.push( 'src="'+esc( d.sSrc )+'"' );
if( $.trim( d.sAlt ) ) a.push( 'alt="'+esc( d.sAlt )+'"' );
if( $.trim( d.sLink ) )
{
l.push( 'href="'+esc( d.sLink )+'"' );
if( $.trim( d.sTarget ) ) l.push( 'target="'+esc( d.sTarget )+'"' );
r = ' ';
}
else
{
r = ' ';
}
return r;
},
_show_audio_video: function( d, isV )
{
var esc = $.fbuilder.htmlEncode,
a = [],
t = ( isV ) ? 'video' : 'audio' ;
if( $.trim( d.sWidth ) ) a.push( 'width="'+esc( d.sWidth )+'"' );
if( isV && $.trim( d.sHeight ) ) a.push( 'height="'+esc( d.sHeight )+'"' );
if( isV && $.trim( d.sPoster ) ) a.push( 'poster="'+esc( d.sPoster )+'"' );
if( $.trim( d.sSrc ) ) a.push( 'src="'+esc( d.sSrc )+'"' );
if( d.sAutoplay ) a.push( 'autoplay' );
if( d.sControls ) a.push( 'controls' );
if( d.sLoop ) a.push( 'loop' );
if( d.sMuted ) a.push( 'muted' );
a.push( 'preload="'+esc( d.sPreload )+'"' );
return '<'+t+' '+a.join( ' ' )+'>'+( ( $.trim( d.sSrcAlt ) ) ? ' ' : '' )+''+d.sFallback+'
'+t+'>';
},
_show_audio: function()
{
return this._show_audio_video( this.data.audio, false );
},
_show_video: function()
{
return this._show_audio_video( this.data.video, true );
},
show:function()
{
return '';
}
}
); $.fbuilder.controls[ 'fButton' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fButton' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
ftype:"fButton",
sType:"button",
sValue:"button",
sOnclick:"",
userhelp:"A description of the section goes here.",
show:function()
{
var esc = function( v ){ v = v.replace( /</g, '&').replace(/"/g, """).replace( /\n+/g, ' ' ); return v;},
type = this.sType,
clss = '';
if( this.sType == 'calculate' )
{
type = 'button';
clss = 'calculate-button';
}
else if( this.sType == 'reset' )
{
clss = 'reset-button';
}
return '';
},
after_show:function()
{
$( '#'+this.name ).click(
function()
{
var e = $( this );
if( e.hasClass( 'calculate-button' ) )
{
var suffix = e.attr( 'id' ).match(/_\d+$/)[0],
items = $.fbuilder[ 'forms' ][ suffix ].getItems();
$.fbuilder[ 'calculator' ].defaultCalc( '#'+e.closest( 'form' ).attr( 'id' ) );
for(var i = 0, h = items.length; i < h; i++ )
{
if(items[i].ftype == 'fsummary')
{
items[i].update();
}
}
}
if( e.hasClass( 'reset-button' ) )
{
setTimeout(
function()
{
var identifier = e.closest( 'form' ).attr( 'id' ).replace( /cp_calculatedfieldsf_pform/, '' );
$.fbuilder[ 'showHideDep' ]( { 'formIdentifier' : identifier } );
var page = parseInt( e.closest( '.pbreak' ).attr( 'page' ) );
if( page )
{
$("#fieldlist"+identifier+" .pbreak").css("display","none");
$("#fieldlist"+identifier+" .pbreak").find(".field").addClass("ignorepb");
$("#fieldlist"+identifier+" .pb0").css("display","block");
if ($("#fieldlist"+identifier+" .pb0").find(".field").length>0)
{
$("#fieldlist"+identifier+" .pb0").find(".field").removeClass("ignorepb");
try
{
$("#fieldlist"+identifier+" .pb0").find(".field")[0].focus();
}
catch(e){}
}
}
},
50
);
}
}
);
}
}
); $.fbuilder.controls[ 'fnumberds' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fnumberds' ].prototype,
$.fbuilder.controls[ 'fnumber' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fnumberds",
show:function()
{
return $.fbuilder.controls[ 'fnumber' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
var v = '';
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
v = data.data[ 0 ][ 'value' ];
}
}
if (!me.predefined) $( '#' + me.name ).val( v ).change();
}
);
}
}); $.fbuilder.controls[ 'fhtml' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fhtml' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
ftype:"fhtml",
fcontent:"",
show:function()
{
return '';
}
}
);$.fbuilder[ 'nDate' ] = function()
{
if ($("#ahbstid").length > 0 && $("#ahbstid").val()!="") {
if (typeof cp_hourbk_timezone !== 'undefined') {
const dateTime = new Date( new Date((new Date($("#ahbstid").val())).getTime()) );
var tz = $.fbuilder.calculateTimeZoneDifferenceIntl(dateTime, cp_hourbk_timezone, cp_hourbk_timezone_local);
return new Date((new Date($("#ahbstid").val())).getTime()-tz*60*60*1000);
}
else
return new Date($("#ahbstid").val());
}
return new Date();
};
$.fbuilder[ 'strip_tags' ] = function(str)
{
return $('').html(str).text();
};
$.fbuilder[ 'calculateTimeZoneDifferenceIntl' ] = function(dateTime, timeZone1, timeZone2)
{
const date1 = new Date(dateTime.toLocaleString('en-US', { timeZone: timeZone1 }));
const date2 = new Date(dateTime.toLocaleString('en-US', { timeZone: timeZone2 }));
const differenceMilliseconds = date2.getTime() - date1.getTime();
const differenceHours = differenceMilliseconds / (1000 * 60 * 60);
return differenceHours;
};
$.fbuilder.controls[ 'fapp' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fapp' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Number",
ftype:"fapp",
services:new Array({name:"Service 1",price:1,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})}),
usedSlots:new Array(),
dateFormat:"mm/dd/yy",
showDropdown:false,
showTotalCost:false,
showTotalCostFormat:"$ {0}",
showEndTime: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,
showAllServices:false,
allowDifferentQuantities:false,
allowSelectSameSlot:false,
firstDay:0,
minDate:"0",
maxDate:"",
defaultDate:"",
invalidDates:"",
required:true,
bSlotsCheckbox: true,
bSlots:30,
militaryTime:1,
cacheArr:new Array(),
getD:$.fbuilder.nDate(),
formId:0,
getMinDate:"",
getMaxDate:"",
arr:new Array(),
allUsedSlots:new Array(),
service_selected:0,
quantity_selected:1,
tz:0,
tzCache:[],
loadOK:false,
ignoreUsedSlots:false,
initialapp:"",
initialID:0,
pctByDay:new Array(),
htmlUsedSlots:new Array(),
extras:0,
sub_cost:0,
percent:0,
notShowBookedDate:true,
showWeek:false,
autonum:0,
availableSlotsByService:[],
slotsDate:[],
allowTZCache:true,
getSplittedSlots:function(d,s)
{
function splitSlots (a,serviceindex) {
var dots = new Array();
for (var i=0;i
a[j].t1 && sa[j].t1 && e 0)
ind--;
return ind;
},
getCapacity:function(i,d)
{
return this.services[i].capacity || 1;
},
show:function()
{
return '';
},
tzf: function(d)
{
function getTZ_old(o,d)
{
var tz = ((new Date($.datepicker.parseDate("yy-mm-dd",d).getTime()+12*60*60*1000)).getTimezoneOffset() * -1)/60 - parseFloat(cp_hourbk_timezone);
if (typeof cp_hourbk_observedaylight !== 'undefined' && cp_hourbk_observedaylight)
{
try{
if ($.datepicker.parseDate("yy-mm-dd",cp_hourbk_daylightnextchange).getTime() <= $.datepicker.parseDate("yy-mm-dd",d).getTime())
tz += parseFloat(cp_hourbk_daylightnexaction);
}catch (e) {}
}
o.tzCache[d] = tz;
return tz;
}
function getTZ(o,d)
{
const dateTime = new Date($.datepicker.parseDate("yy-mm-dd",d).getTime()+12*60*60*1000);
var tz = $.fbuilder.calculateTimeZoneDifferenceIntl(dateTime, cp_hourbk_timezone, cp_hourbk_timezone_local);
o.tzCache[d] = tz;
return tz;
}
return (typeof cp_hourbk_timezone !== 'undefined')?((typeof this.tzCache[d] !== 'undefined' && this.allowTZCache)?this.tzCache[d]:getTZ(this,d)):this.tz;
},
getSpecialDays:function()
{
var me = this;
var a = 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;i= a[i].t2)
a[i].t2 += 24 * 60;
}
},
initcacheOpenHours: function()
{
var me = this;
for (j=0;j=arr[i].t2)
arr[i].t2 += 24 * 60;
}
if (me.ignoreUsedSlots)
var data2 = $.merge(data1.slice(0),[]);
else
{
me.usedSlots[d] = me.usedSlots[d] || [];
var data2 = $.merge(data1.slice(0),me.usedSlots[d]);
var t = $.datepicker.parseDate("yy-mm-dd", d);
t.setDate(t.getDate() - 1);
var bd = $.datepicker.formatDate("yy-mm-dd", t);
me.usedSlots[bd] = me.usedSlots[bd] || [];
for (var i=0;i me.usedSlots[bd][i].h2 && me.usedSlots[bd][i].h2!=0) || me.usedSlots[bd][i].h2>24)
{
if (me.usedSlots[bd][i].h1>me.usedSlots[bd][i].h2)
me.usedSlots[bd][i].h2 += 24;
var obj = jQuery.extend({}, me.usedSlots[bd][i]);
obj.h2 = me.usedSlots[bd][i].h2 - 24;
obj.h1 = 0;obj.m1 = 0;
obj.d = d;
data2[data2.length] = obj;
}
}
}
for (var i=0;idata[i].t2)
data[i].t2 += 24 * 60;
}
if (typeof cp_hourbk_cmpublic !== 'undefined')
data = me.getSplittedSlots(data,s);
data = me.getCompatSlots(data);
for (var i=0;icapacity_service || (data[i].service.length==0 || (data[i].service.length && data[i].service[0]!=s)))
//|| (!me.avoidOverlaping && (data[i].quantity+me.quantity_selected>capacity_service && (typeof data[i].serviceindex === 'undefined' || data[i].serviceindex==s)) ))
|| (!me.avoidOverlaping && ((data[i].quantity+me.quantity_selected>capacity_service && data[i].serviceindex==s) || typeof data[i].serviceindex === 'undefined') ))
{
for (var j=0;j arr[j].t1) && (data[i].t1 < arr[j].t2) && (data[i].t2 > arr[j].t1) && (data[i].t2 < arr[j].t2))
{
var v1 = {t1:arr[j].t1, t2:data[i].t1, h1:arr[j].h1, h2:data[i].h1, m1:arr[j].m1, m2:data[i].m1};
var v2 = {t1:data[i].t2, t2:arr[j].t2, h1:data[i].h2, h2:arr[j].h2, m1:data[i].m2, m2:arr[j].m2};
arr.splice(j, 1, v1, v2);
j--;
}
else if ((data[i].t1 > arr[j].t1) && (data[i].t1 < arr[j].t2))
{
arr[j].t2 = data[i].t1;
arr[j].h2 = data[i].h1;
arr[j].m2 = data[i].m1;
}
else if ((data[i].t2 > arr[j].t1) && (data[i].t2 < arr[j].t2))
{
arr[j].t1 = data[i].t2;
arr[j].h1 = data[i].h2;
arr[j].m1 = data[i].m2;
}
else if ((data[i].t1 <= arr[j].t1) && (data[i].t2 >= arr[j].t2))
{
arr.splice(j, 1);
j--;
}
}
}
}
for (var i=0;i=0;i--)
{
if ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime()+arr[i].t2*60*1000 <= currenttime)
arr.splice(i, 1 );
else if ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime()+arr[i].t1*60*1000 <= currenttime)
{
var st = arr[i].t1;//var st = arr[i].t1 + duration + me.pb + me.pa;
while ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime() + st*60*1000 < currenttime)
{
if (!me.bSlotsCheckbox)
st += me.bduration;
else
st += duration + me.pb + me.pa;
//st += duration + me.pb + me.pa;
}
var m1 = st % 60;
var h1 = (st - m1)/60;
arr[i].t1 = st;
arr[i].h1 = h1;
arr[i].m1 = m1;
}
}
}
if (me.maxDate!=="" && me.getMaxDate!="")
{
var current = me.getMaxDate;
var currenttime = current.getTime()+me.tzf(d)*60*60*1000;
for (var i=arr.length-1;i>=0;i--)
{
if ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime()+arr[i].t1*60*1000 >= currenttime)
arr.splice(i, 1 );
else if ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime()+arr[i].t2*60*1000 >= currenttime)
{
var et = arr[i].t1;
while ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime() + (et + duration)*60*1000 <= currenttime)
et += duration;
var m2 = et % 60;
var h2 = (et - m2)/60;
arr[i].t2 = et;
arr[i].h2 = h2;
arr[i].m2 = m2;
}
}
}
for (var i=arr.length-1;i>=0;i--)
if (arr[i].t1+duration + me.pb + me.pa > arr[i].t2 || arr[i].t1 > 24*60) //if (arr[i].t1+duration > arr[i].t2 || arr[i].t1 > 24*60)
arr.splice(i, 1 );
return arr;
},
formattime: function(t,mt)/*mt=2 for database 09:00*/
{
if (t<0) t+=(24*60);
t = t % (24*60);
var h = Math.floor(t/60);
var m = t%60;
var suffix = "";
if (mt==0)
{
if (h>12)
{
h = h-12;
suffix = " PM";
}
else if (h==12)
suffix = " PM";
else
{
if (h==0 && mt!=2) h=12;
suffix = " AM";
}
}
return (((h<10)?((mt==2)?"0":"0"):"")+h+":"+(m<10?"0":"")+m)+suffix;
},
formatString: function(obj,showdate,tz)
{
var me = this;
tz = tz * 60;
if (typeof obj.st === 'undefined')
obj.st = obj.h1*60+obj.m1*1;
if (typeof obj.et === 'undefined')
obj.et = obj.h2*60+obj.m2*1;
var str = "";
if (showdate)
{
var d = $.datepicker.parseDate("yy-mm-dd", obj.d);
if (tz!=0)
{
if (obj.st+tz<0)
d.setDate(d.getDate() - 1);
else if (obj.st+tz>24*60)
d.setDate(d.getDate() + 1);
}
str += ""+$.datepicker.formatDate(me.dateFormat, d)+" ";
}
str += (showdate?"":"");
str += me.formattime(obj.st+tz,me.militaryTime)+(me.showEndTime?("-"+me.formattime(obj.et+tz,me.militaryTime)):"");
str += (showdate?" ":"");
return str;
},
getCurrentSlots: function(arr,d,s)
{
var me = this;
var duration = parseFloat(me.services[s].duration);
var html = "";
var htmlSlots = new Array();
var pb = 0;
var pa = 0;
var v = false;
var capacity_service = me.getCapacity(s,d);
if (true)
{
var compactUsedSlots = me.getCompatSlots(me.htmlUsedSlots[d])
for (var i=0;i=capacity_service && compactUsedSlots[i].serviceindex==s)
if (compactUsedSlots[i].serviceindex==s)
{
compactUsedSlots[i].st = compactUsedSlots[i].h1 * 60 + compactUsedSlots[i].m1;
compactUsedSlots[i].t = $.datepicker.parseDate("yy-mm-dd",compactUsedSlots[i].d).getTime()+compactUsedSlots[i].st*60*1000;
compactUsedSlots[i].html = "";
var v = false;
if (me.minDate!=="" && me.getMinDate!="") //check with the min date
{
var current = me.getMinDate;
var currenttime = current.getTime()-me.tzf(d)*60*60*1000;
if (compactUsedSlots[i].t > currenttime)
{
v = true;
}
}
else
v = true;
if (v)
{
if (compactUsedSlots[i].quantity>=capacity_service || compactUsedSlots[i].currentSelection)
compactUsedSlots[i].html = '';
compactUsedSlots[i].availableslot = false;
htmlSlots[htmlSlots.length] = compactUsedSlots[i];
}
}
}
}
if ((typeof specialPadding === 'undefined'))
{
pb = me.pb;
pa = me.pa;
}
for (var i=0;i= et)
et += 24 * 60;
st += me.pb;
while (st + duration + me.pa <=et && st < 24 * 60)
{
html = "";
htmlSlots[htmlSlots.length] = {availableslot:true,st:st,serviceindex:s,h1:Math.floor((st)/60),m1:((st)%60),h2:Math.floor((st+duration)/60),m2:((st+duration)%60),html:html,t:$.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime()+st*60*1000};
if (!me.bSlotsCheckbox)
st += me.bduration;
else
st += me.bduration + pa + pb;
}
}
htmlSlots.sort(function(a, b){
if ((typeof cp_hourbk_cmpublic !== 'undefined') && (a.t == b.t))
{
if ((typeof a.quantity !== 'undefined') && (typeof b.quantity === 'undefined'))
{
b.html = b.html.replace("ahbslotavailabilityP",(capacity_service - a.quantity));
b.quantity = a.quantity;
}
else if ((typeof b.quantity !== 'undefined') && (typeof a.quantity === 'undefined'))
{
a.html = a.html.replace("ahbslotavailabilityP",(capacity_service - b.quantity));
a.quantity = b.quantity;
}
}
return a.t - b.t
});
//remove duplicates
htmlSlots = htmlSlots.reduce(function(field, e1){
var matches = field.filter(function(e2){return e1.html== e2.html});
if (matches.length == 0){
field.push(e1);
}return field;
}, []);
htmlSlots = htmlSlots.reduce(function(field, e1){
var matches = field.filter(function(e2){return e1.t== e2.t});
if (matches.length == 0){
field.push(e1);
}
else
{
for (var i=0;i0 && htmlSlots.length>0)
for (var i=0;i=me.cacheArr[d][i].t2)
me.cacheArr[d][i].t2 += 24 * 60;
if (st<=me.cacheArr[d][i].t1 && et>=me.cacheArr[d][i].t1)
htmlSlots[htmlSlots.length] = jQuery.extend({}, me.cacheArr[d][i]);
}
for (var i=0;me.usedSlots[d] && i=me.usedSlots[d][i].t2)
me.usedSlots[d][i].t2 += 24 * 60;
if (st<=me.usedSlots[d][i].t1 && et>=me.usedSlots[d][i].t1)
htmlSlots[htmlSlots.length] = jQuery.extend({}, me.usedSlots[d][i]);
}
}
return htmlSlots;
}
var day = $.datepicker.parseDate("yy-mm-dd", d);
if (this.tzf(d)==0)
{
me.htmlUsedSlots[d] = setHtmlUsedSlots(d,0,24);
var arr = this.getAvailablePartialSlots(d,[{h1:0,m1:0,h2:0,m2:0}],s);
}
else if (this.tzf(d) > 0)
{
day.setDate(day.getDate() - 1);
var d1 = $.datepicker.formatDate("yy-mm-dd",day);
var arr = $.merge(this.getAvailablePartialSlots(d1,[{h1:0,m1:0,h2:24-this.tzf(d),m2:0}],s),this.getAvailablePartialSlots(d,[{h1:24-this.tzf(d),m1:0,h2:24,m2:0}],s));
me.htmlUsedSlots[d] = $.merge(setHtmlUsedSlots(d1,24-this.tzf(d),24), setHtmlUsedSlots(d,0,24-this.tzf(d)));
}
else
{
day.setDate(day.getDate() + 1);
var d1 = $.datepicker.formatDate("yy-mm-dd",day);
var arr = $.merge(this.getAvailablePartialSlots(d,[{h1:0,m1:0,h2:this.tzf(d)*-1,m2:0}],s),this.getAvailablePartialSlots(d1,[{h1:this.tzf(d)*-1,m1:0,h2:24,m2:0}],s));
me.htmlUsedSlots[d] = $.merge(setHtmlUsedSlots(d,this.tzf(d)*-1,24), setHtmlUsedSlots(d1,0,this.tzf(d)*-1));
}
me.slotsDate[c] = arr;
return arr;
},
getAvailableSlots: function(d)
{
var me = this;
var c = "s"+(me.showAllServices?"":me.service_selected)+"q"+me.quantity_selected+"d"+d;
if (me.tzf(d)==0 && typeof me.slotsDate[c]!== 'undefined')
return me.slotsDate[c];
var a_max = [];
if (!me.showAllServices)
a_max = this.getAvailableSlotsByService(d,me.service_selected);
else
{
me.availableSlotsByService[d] = [];
for (var i=0; i< me.services.length;i++)
{
me.availableSlotsByService[d][i] = this.getAvailableSlotsByService(d,i);
if (me.availableSlotsByService[d][i].length > a_max.length)
a_max = me.availableSlotsByService[d][i].slice(0);
}
}
me.slotsDate[c] = a_max;
return a_max;
},
rC: function(d)
{
var me = this;
var day = $.datepicker.formatDate('yy-mm-dd', d);
var c = new Array(day,"d"+day);
if (me.working_dates[d.getDay()]==0 && ($.inArray(day, me.special_days) == -1))
c.push("nonworking","ui-datepicker-unselectable","ui-state-disabled");
for( var i = 0, l = me.invalidDates.length; i < l; i++ )
{
if (d.getTime() === me.invalidDates[i].getTime() && ($.inArray(day, me.special_days) == -1))
c.push("nonworking","ui-datepicker-unselectable","ui-state-disabled","invalidDate");
}
if (me.minDate!=="" && me.getMinDate!="" && day < $.datepicker.formatDate('yy-mm-dd', me.getMinDate))
c.push("nonworking","ui-datepicker-unselectable","ui-state-disabled","beforemindate");
if (me.maxDate!=="" && me.getMaxDate!="" && day > $.datepicker.formatDate('yy-mm-dd', new Date(me.getMaxDate.getTime()-1))) //because me.getMaxDate.setHours(24, 0, 0, 0) add a date
c.push("nonworking","ui-datepicker-unselectable","ui-state-disabled","aftermaxdate");
if (($.inArray("ui-datepicker-unselectable",c)==-1) && !me.emptySelectCheckbox || (me.emptySelectCheckbox && $(".fieldCalendarService"+me.name+" select option:selected").index() > 0 ))
{
var arr = me.getAvailableSlots(day);
if (arr.length==0 && me.notShowBookedDate)
c.push("nonworking","ui-datepicker-unselectable","ui-state-disabled","notavailslot");
if (typeof cp_hourbk_cmpublic !== 'undefined')
{
var used = 0;
var cclass = c.join(" ");
var q = 0;
var total = 0;
if (!me.showAllServices)
{
var htmlSlots = me.getCurrentSlots(arr,day,me.service_selected);
for (var i=0;i0)/*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();
}
var dd = "";
if (me.initialapp!="")
{
try{
var s = me.initialapp.split(";");
var s2 = "";
var ind = 0;
for (var i=0;i 0 )))
{
$( '#field' + me.form_identifier + '-' + me.index + ' .slotsCalendar'+me.name ).html("");
return;
}
function getSlots(d)
{
var data1 = me.cacheArr[d];
var duration = me.duration;
me.bduration = me.duration;
if (!me.bSlotsCheckbox)
me.bduration = me.bSlots*1;
var arr = me.getAvailableSlots(d);
var nextdateAvailable = $.datepicker.parseDate("yy-mm-dd", d);
var c = "s"+(me.showAllServices?"":me.service_selected)+"q"+me.quantity_selected;
var s = $( '#field' + me.form_identifier + '-' + me.index + ' .slotsCalendar'+me.name );
var i =0;
if (me.notShowBookedDate && (me.maxNumberOfApp==0 || me.allUsedSlots.length0 )
{
e.datepicker("setDate", nextdateAvailable);
me.getD = nextdateAvailable;
onChangeDateOrService($.datepicker.formatDate("yy-mm-dd", nextdateAvailable));
}
else
{
e.datepicker("setDate", me.getMinDate);
s.html(""+cp_hourbk_nomore_label+"
");
}
return;
}
me.service_change = false;
function getStrSlots(arr,d,s)
{
var str = "";
var htmlSlots = me.getCurrentSlots(arr,d,s);
var capacity_service = me.getCapacity(s);
for (var i=0;i'+me.services[i].name+'
'+str_s+' ';
}
}
if (str=="") str = cp_hourbk_nomore_label;
var before = "";
if (s.find(".slots").length>0)
{
before = s.find(".slots").attr("d");
}
s.html(""+$.datepicker.formatDate(me.dateFormat, $.datepicker.parseDate("yy-mm-dd", d))+" "+str+"
");
if (before!="" && before!=d)
{
s.find(".slots span:first").hide().show(200);
}
var str1="",str2="";
me.allUsedSlots = me.allUsedSlots || [];
me.allUsedSlots.sort(function(a, b){ return ($.datepicker.parseDate("yy-mm-dd", a.d).getTime()+(a.h1*60+a.m1)*60*1000) - ($.datepicker.parseDate("yy-mm-dd", b.d).getTime()+(b.h1*60+b.m1)*60*1000)});
j = 0;
var total = 0;
for (var i=0;i"+me.formatString(me.allUsedSlots[i],true,me.tzf(d))+" "+me.services[me.allUsedSlots[i].serviceindex].name+" ("+me.allUsedSlots[i].quantity+") ["+(cp_hourbk_cancel_label?cp_hourbk_cancel_label:'cancel')+"] "+(((typeof cp_hourbk_repeat !== 'undefined'))?showrepeat(me,i):"")+"";
str2 += ((str2=="")?"":";")+me.allUsedSlots[i].d+" "+me.formattime(me.allUsedSlots[i].h1*60+me.allUsedSlots[i].m1*1,2)+"/"+me.formattime(me.allUsedSlots[i].h2*60+me.allUsedSlots[i].m2*1,2)+" "+me.allUsedSlots[i].serviceindex+" "+me.allUsedSlots[i].quantity;
if (me.allUsedSlots[i].d==d)
j++;
}
me.sub_cost = total;
total = me.sub_cost + me.extras;
total = total*(1+me.percent/100);
total = total.toFixed(2);
if (me.showTotalCost && (str1!=""))
str1 += ''+cp_hourbk_cost_label+' '+me.showTotalCostFormat.replace("{0}", total)+'
';
$( '.usedSlots'+me.name ).html(str1);
$( '#field' + me.form_identifier + '-' + me.index + ' #'+me.name ).val(str2);
$( '#field' + me.form_identifier + '-' + me.index + ' #tcost'+me.name ).val(total);
$( '#field' + me.form_identifier + '-' + me.index + ' #'+me.name ).change();
try {
$( "#fbuilder .slots div a" ).tooltip({
position: {
my: "left top+10"
},
open: function (event, ui) {
$(this).tooltip( "option", "content", $(this).parent().find(".ahbmoreinfo").html() );
},
tooltipClass: "ahbtooltip"
});
} catch (e) {}
$( '.slotsCalendar' + me.name + ' .slots a').off("click").on("click", function()
{
var q = parseFloat($(".fieldCalendarService"+me.name+" select.ahbfield_quantity option:selected").val());
if ((me.maxNumberOfApp==1 && me.allUsedSlots.length==me.maxNumberOfApp) || (me.allUsedSlots.length>0 && me.allUsedSlots[0].quantity!=q && !me.allowDifferentQuantities)) //cancel previous slot
{
for (var i = 0; (idata[i].h2 && data[i].h2!=0) || data[i].h2>24)
{
if (data[i].h1>data[i].h2)
data[i].h2 += 24;
var obj = jQuery.extend({}, data[i]);
obj.h2 = data[i].h2 - 24;
obj.h1 = 0;obj.m1 = 0;
var d = $.datepicker.parseDate("yy-mm-dd", dd);
d.setDate(d.getDate() + 1);
obj.d = $.datepicker.formatDate("yy-mm-dd", d);
data[i].h2 = 24;
me.cacheArr[obj.d] = me.cacheArr[obj.d] || [];
me.cacheArr[obj.d][me.cacheArr[obj.d].length] = obj;
}
}
me.slotsDate = [];
me.loadOK = true;
}
});
}
this.invalidDates = this.invalidDates.replace( /\s+/g, '' );
try{
var df = "mm/dd/yy";
if (this.invalidDates.indexOf(".")!=-1)
df = me.dateFormat;
if( !/^\s*$/.test( this.invalidDates ) )
{
var counter = 0, dates = this.invalidDates.split( ',' );
this.invalidDates = [];
for( var i = 0, h = dates.length; i < h; i++ )
{
var range = dates[ i ].split( '-' );
if( range.length == 2 )
{
var fromD = $.datepicker.parseDate(df,range[ 0 ]),
toD = $.datepicker.parseDate(df,range[ 1 ]);
while( fromD <= toD )
{
if (fromD !== null)
{
this.invalidDates[ 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 ($.datepicker.parseDate(df,range[ j ]) !== null)
{
this.invalidDates[ counter ] = $.datepicker.parseDate(df,range[ j ]);
counter++;
}
}
}
}
}
} catch (e) {}
if ($.validator.messages.date_format && $.validator.messages.date_format!="")
me.dateFormat = $.validator.messages.date_format;
var capacity = 1;
for (var i=0;i'+me.services[i].name+'';
if (capacity'+ str ;
var str2 = "";
for (var i=1;i<=me.getCapacity(0);i++)
str2 += ''+i+' ';
d.html(''+str+' '+((typeof cp_hourbk_quantity_label !== 'undefined')?cp_hourbk_quantity_label:'Quantity')+' '+str2+'
');
me.service_selected = me.normalizeSelectIndex($(".fieldCalendarService"+me.name+" select.ahbfield_service option:selected").index());
me.quantity_selected = parseFloat($(".fieldCalendarService"+me.name+" select.ahbfield_quantity option:selected").val());
me.duration = parseFloat(me.services[me.service_selected].duration);
me.pa = me.services[me.service_selected].pa * 1 || 0;
me.pb = me.services[me.service_selected].pb * 1 || 0;
$(".fieldCalendarService"+me.name+" select.ahbfield_service").bind("change", function()
{
me.service_change = true;
me.service_selected = me.normalizeSelectIndex($(".fieldCalendarService"+me.name+" select.ahbfield_service option:selected").index());
me.duration = parseFloat(me.services[me.service_selected].duration);
me.pa = me.services[me.service_selected].pa * 1 || 0;
me.pb = me.services[me.service_selected].pb * 1 || 0;
//me.cacheOpenHours = new Array();
me.special_days = me.getSpecialDays();
var str2 = "";
for (var i=1;i<=me.getCapacity(me.service_selected);i++)
str2 += ''+i+' ';
$(".fieldCalendarService"+me.name+" select.ahbfield_quantity").html(str2);
me.quantity_selected = parseFloat($(".fieldCalendarService"+me.name+" select.ahbfield_quantity option:selected").val());
if (typeof me.getDMin!='undefined') me.getD = me.getDMin;
$( '#field' + me.form_identifier + '-' + me.index + ' .fieldCalendar'+me.name ).datepicker( "option", "beforeShowDay", function(d){return me.rC(d)} );
onChangeDateOrService($.datepicker.formatDate('yy-mm-dd', me.getD));
});
$(".fieldCalendarService"+me.name+" select.ahbfield_quantity").bind("change", function()
{
if (!me.allowDifferentQuantities)
{
me.quantity_selected = parseFloat($(".fieldCalendarService"+me.name+" select.ahbfield_quantity option:selected").val());
me.allUsedSlots = me.allUsedSlots || [];
for (var i=0;i=arr[j].t1 && s.h2*60+s.m2*1<=arr[j].t2)
find = true;
}
me.usedSlots[s.d] = me.usedSlots[s.d] || [];
f = false;
for (var j=0;j=0 && parseFloat(a[0]) < 24 && parseFloat(a[1])>=0 && parseFloat(a[1]) < 60 )
me.getMinDate = new Date(me.getMinDate.getFullYear(),me.getMinDate.getMonth(),me.getMinDate.getDate(),parseFloat(a[0]),parseFloat(a[1]));
}
e.datepicker("option", "minDate", me.getMinDate );
e.datepicker("setDate", me.getMinDate);
}
if (me.maxDate!=="")
try{me.getMaxDate = $.datepicker._getMinMaxDate( e.data('datepicker'), 'max' ); me.getMaxDate.setHours(24, 0, 0, 0);} catch (e) {}
if (typeof hrsMax !== 'undefined')
{
var t = $.fbuilder.nDate();
me.getMaxDate.setHours(t.getHours()-24, t.getMinutes(), t.getSeconds());// -24 because me.getMaxDate.setHours(24, 0, 0, 0) add a date
me.getMaxDate = new Date((me.getMaxDate.getTime() + hrsMax * 60 * 60 * 1000) );
if (onlyHour) me.getMaxDate = new Date(me.maxDate);
}
if (maxdatetime!="")
{
var a = maxdatetime.split(":")
if (parseFloat(a[0])>=0 && parseFloat(a[0]) < 24 && parseFloat(a[1])>=0 && parseFloat(a[1]) < 60 )
me.getMaxDate = new Date(me.getMaxDate.getFullYear(),me.getMaxDate.getMonth(),me.getMaxDate.getDate(),parseFloat(a[0]),parseFloat(a[1]));
}
try{
if (me.defaultDate!=="")
e.datepicker("setDate", me.defaultDate);
} catch (e) {}
e.datepicker("option", "maxDate", me.maxDate );
if (me.getMaxDate!="" && me.tzf($.datepicker.formatDate("yy-mm-dd",me.getMaxDate))!=0) e.datepicker("option", "maxDate", new Date(me.getMaxDate.getTime()+me.tzf($.datepicker.formatDate("yy-mm-dd",me.getMaxDate))*60*60*1000) );
me.tmpinvalidDatestime = new Array();
try {
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");
var i = 0;
while (!DisableSpecificDates(nextdateAvailable) && i<400)
{
nextdateAvailable.setDate(nextdateAvailable.getDate() + 1);
i++;
}
e.datepicker("setDate", nextdateAvailable);
me.getD = nextdateAvailable;
function ifLoadOk()
{
if (!me.loadOK)
setTimeout(ifLoadOk,100);
else
{
$( '#field' + me.form_identifier + '-' + me.index + ' .fieldCalendar'+me.name ).datepicker( "option", "beforeShowDay", function(d){return me.rC(d)} );
onChangeDateOrService($.datepicker.formatDate('yy-mm-dd', me.getD));
$( '#field' + me.form_identifier + '-' + me.index + ' .fieldCalendar'+me.name ).datepicker( "option", "beforeShowDay", function(d){return me.rC(d)} );
}
}
ifLoadOk();
}
preselect_service = function(v)
{
$(".fieldCalendarService"+me.name+" select.ahbfield_service").children().removeAttr("selected");
if (me.emptySelectCheckbox)
$(".fieldCalendarService"+me.name+" select.ahbfield_service").children().eq(v+1).prop('selected', 'selected').change();
else
$(".fieldCalendarService"+me.name+" select.ahbfield_service").children().eq(v).prop('selected', 'selected').change();
if (me.maxNumberOfApp==1 && me.allUsedSlots.length==me.maxNumberOfApp)
$(".fieldCalendarService"+me.name+" select.ahbfield_quantity").val(me.allUsedSlots[0].quantity);
}
if (typeof cp_hourbk_preselect !== 'undefined' && typeof cp_hourbk_preselect[me.form_identifier] !== 'undefined' && cp_hourbk_preselect[me.form_identifier]!="")
preselect_service(cp_hourbk_preselect[me.form_identifier]*1);
else
if (me.initialapp!="" && dd!="")
{
try{
me.getD = $.datepicker.parseDate("yy-mm-dd",dd);
e.datepicker("setDate", me.getD);
preselect_service(me.initialServiceInd);
onChangeDateOrService(dd);
} catch (e) {}
}
getExtrasVisible = function(f)
{
try{
var p = f.attr("id").split( '_' );
var items = $.fbuilder[ 'forms' ]["_"+p[p.length-1]].getItems();
for (var i=0;i 1 ) ? '_'+p[ 1 ] : '',
me = (
typeof $.fbuilder[ 'forms' ] != 'undefined' &&
typeof $.fbuilder[ 'forms' ][ _index ] != 'undefined'
) ? $.fbuilder[ 'forms' ][ _index ].getItem( p[ 0 ]+'_'+p[ 1 ] ) : null;
if( me != null )
{
$.ajax({
dataType : 'json',
type: "POST",
url : document.location.href,
data : { cp_app_action: 'get_slots',
formid: me.formId,
initialID: me.initialID,
formfield: me.name.replace(me.form_identifier, "")
},
success: function(data) {
var overlapping = false;
var find = false;
me.ignoreUsedSlots = true;
me.cacheArr = new Array();
for (var i=0;i=t2)
find = true;
}
if (!find)
{
overlapping = true;
if (msg == "") msg = "Affected times:
";
msg += "
"+me.formatString(me.allUsedSlots[i],true,me.tzf(d))+" "+me.services[me.allUsedSlots[i].serviceindex].name+"
";
}
//overlapping = !find;
}
me.ignoreUsedSlots = false;
var isValid = !overlapping;
if (true === isValid) {
var submitted = validator.formSubmitted;
validator.prepareElement( element );
validator.formSubmitted = submitted;
validator.successList.push( element );
delete validator.invalid[ element.name ];
validator.showErrors();
} else {
for (var i=0;i
";
errors[ element.name ] = validator.defaultMessage( element, "avoid_overlapping" )+msg;
validator.invalid[ element.name ] = true;
validator.showErrors( errors );
element.focus();
}
previous.valid = isValid;
validator.stopRequest( element, isValid );
cp_hourbk_avoid_overlapping--;
}
});
return "pending";
}
return true;
}
$.validator.addMethod('avoid_overlapping', avoid_over_function);
}
},
val:function()
{
return 0;
}
}
); $.fbuilder.controls[ 'fcurrencyds' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fcurrencyds' ].prototype,
$.fbuilder.controls[ 'fcurrency' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fcurrencyds",
show:function()
{
return $.fbuilder.controls[ 'fcurrency' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'fcurrency' ].prototype.after_show.call( this );
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
var v = '';
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
v = data.data[ 0 ][ 'value' ];
}
}
$( '#' + me.name ).val( v ).change();
}
);
}
}); $.fbuilder.controls[ 'facceptance' ]=function(){};
$.extend(
$.fbuilder.controls[ 'facceptance' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Accept terms and conditions",
ftype:"facceptance",
value:"I accept",
required:true,
url:"",
message:"",
show:function()
{
var me = this,
dlg = '',
label = me.title;
if(!/^\s*$/.test(me.url))
{
label = ''+label+' ';
}
else if(!/^\s*$/.test(me.message))
{
label = ''+label+' ';
dlg += ''
}
return '';
},
after_show:function()
{
$(document).on('click','.cff-open-dlg', function(){
var dlg = $(this).closest('.fields').find('.cff-dialog'), w = dlg.data('width'), h=dlg.data('height');
dlg.removeClass('hide');
if('undefined' == typeof w) w = Math.min($(this).closest('form').width(), $(window).width(), dlg.width());
if('undefined' == typeof h) h = Math.min($(this).closest('form').height(), $(window).height(), dlg.height());
dlg.data('width',w);
dlg.data('height',h);
dlg.css({'width': w+'px', 'height': h+'px', 'margin-top': (-1*h/2)+'px', 'margin-left': (-1*w/2)+'px'});
});
$(document).on('click','.cff-close-dlg', function(){$(this).closest('.cff-dialog').addClass('hide');});
},
val:function()
{
var e = $('[id="'+this.name+'"]:checked:not(.ignore)');
if( e.length )
{
var t = $.fbuilder.parseValStr( e[0].value );
if(!$.isNumeric(t)) t = t.replace(/^"/,'').replace(/"$/,'');
}
return (v) ? (($.isNumeric(v)) ? v : '"'+v+'"') : 0;
}
}
); var fcount = 1;
var fcount_tags = 1;
var fnum = "_"+fcount;
var cp_avoid_hidden = false;
while (20>fcount || eval("typeof cp_appbooking_fbuilder_config"+fnum+" != 'undefined'"))
{
try {
var cp_appbooking_fbuilder_config = eval("cp_appbooking_fbuilder_config"+fnum);
while (20>fcount_tags && !$("#fbuilder_"+fcount_tags).length)
fcount_tags++;
cp_appbooking_fbuilder_config = $.parseJSON(cp_appbooking_fbuilder_config.obj);
cp_appbooking_fbuilder_config.identifier = "_"+fcount_tags;
if (!$("#fieldlist_"+fcount_tags).html().length)
{
var opt_identifier = $("#fieldlist_"+fcount_tags);
opt_identifier.attr("fcount_tags",fcount_tags);
opt_identifier.attr("fnum",fnum);
opt_identifier.addClass("cp_avoid_hidden")
var f = $("#fbuilder_"+fcount_tags).fbuilder(cp_appbooking_fbuilder_config);
f.fBuild.loadData("form_structure_"+fcount_tags);
$.fbuilder.configValidate($("#cp_appbooking_pform_"+fcount_tags));
if((typeof opt_identifier.attr("fnum") !== 'undefined') && !opt_identifier.is(':hidden'))
$(opt_identifier).addClass("cp_v_v");
else
cp_avoid_hidden = true;
}
} catch (e) {}
fcount++;
fcount_tags++;
fnum = "_"+fcount;
}
if (cp_avoid_hidden)
$( document ).each(
function()
{
(new MutationObserver(
function(mutationsList, observer)
{
for(let k in mutationsList)
{
var mutation = mutationsList[k];
if (mutation.type === 'childList')
{
if(mutation.addedNodes.length)
{
try{
$(".cp_avoid_hidden").each(function(){
var opt_identifier= $("#"+$(this).attr("id"));
if((typeof opt_identifier.attr("fnum") !== 'undefined') && !opt_identifier.is(':hidden') && opt_identifier.find(".avoid_overlapping_before").length>0)
$(opt_identifier).addClass("cp_v_v");
if((typeof opt_identifier.attr("fnum") !== 'undefined') && !opt_identifier.is(':hidden') && !opt_identifier.hasClass("cp_v_v"))
{
$(opt_identifier).addClass("cp_v_v");
var fnum = opt_identifier.attr("fnum");
var fcount_tags = opt_identifier.attr("fcount_tags");
var cp_appbooking_fbuilder_config = eval("cp_appbooking_fbuilder_config"+fnum);
cp_appbooking_fbuilder_config = $.parseJSON(cp_appbooking_fbuilder_config.obj);
cp_appbooking_fbuilder_config.identifier = "_"+fcount_tags;
var f = $("#fbuilder_"+fcount_tags).fbuilder(cp_appbooking_fbuilder_config);
f.fBuild.loadData("form_structure_"+fcount_tags);
$.fbuilder.configValidate(opt_identifier.closest("form"));
}
})
}catch(err){}
}
}
}
}
)).observe(this, { childList: true, subtree: true });
}
);
})(fbuilderjQuery);
});