multiple calendar for laravel-admin grid and fullcalendar(3.1.0) - fullcalendar

I want to display more calendars on laravel-admin grid, but fullcalendar events were accumulated, so what can I do? I think maybe can clear events before? thanks.
my code like this:
$grid->column('name', __('name'))->modal('calendar', function ($model) {
$id = $model->id;
$punches = DB::table('punches')->where('userid', $id)->get();
$punches = $punches->map(function ($punch) use ($id) {
return Calendar::event($punch->id, true, $punch->start_date, $punch->end_date, "stringEventId");
});
$calendar = Calendar::addEvents($punches)->setId('calendar-' . $id);
return $calendar->calendar().$calendar->script();
});

Related

Full Calendar Default View

Since Full Calendar is not really suitable for smaller screen I'm trying to change the "default view" of the full calendar according to the width size of the screen.
I'm trying to implement that with this line code:
defaultView: (function () {
if ($(window).width() >= 768) {
return defaultView = 'agendaDay';
} else {
return defaultView = 'month';
}
})
It's working fine however you have to refresh the browser every time to view the changes.
I tried windowResize function but no Luck. Any help would really be appreciated. Looking for sulotion without refresh the page.
Thanks in advance.
I'm not sure if fullcalendar will accept a function for the defaultView optiont but your code will work if you make two adjustments:
Return the name of the view i.e. 'month'
Make your function into an IIFE
defaultView: (function () {
if ($(window).width() >= 768) {
return 'agendaDay';
} else {
return 'month';
}
})()
As of v5, defaultView was renamed to intialView so this works:
initialView: window.innerwidth >= 768 ? 'agendaDay' : 'month',

Contact Form 7: Is it possible to have a greyed out Submit-Button until required fields are filled out?

Would it be possible to have the "Submit"-button in Contact Form 7 greyed out or inactive until all requiered fields are filled out?
Where do I have to implement the code?
Thank you! Cheers!
You can use jQuery to disable submit button untill it is filled.
You can place below code in .js file or in footer.php
var disableSubmit = false;
jQuery('input.wpcf7-submit[type="submit"]').click(function() {
jQuery(':input[type="submit"]').attr('value',"Sending...")
if (disableSubmit == true) {
return false;
}
disableSubmit = true;
return true;
})
var wpcf7Elm = document.querySelector( '.wpcf7' );
wpcf7Elm.addEventListener( 'wpcf7submit', function( event ) {
jQuery(':input[type="submit"]').attr('value',"send")
disableSubmit = false;
}, false );

Adding filtering to jquery-isotope within Wordpress theme

I'm using the Vitrux theme in Wordpress that uses Isotope jQuery plugin to display a work porfolio. Isotope allows categories to be used to sort the items, but within the theme it's only possible to sort by one category at a time (e.g. 'Year' or 'Type', not 'Year' and 'Type'.
You can see a mock-up here: http://snaprockandpop.samcampsall.co.uk/shoots/
The jQuery attached to each category item, that sorts the posts, is as follows:
function (){
var selector = $(this).attr('data-filter');
$container_isotope.isotope({ filter: selector });
var $parent = $(this).parents(".filter_list");
$parent.find(".active").removeClass('active');
$(".filter_list").not($parent).find("li").removeClass('active').first().addClass("active");
$(this).parent().addClass("active");
return false;
}
I can see from the Isotope site that it's possible to use multiple filters, and I've found the authors notes on this here: http://jsfiddle.net/desandro/pJ6W8/31/
EDIT:
Editing the theme files has allowed me to assign appropriate classes and properties to the filter lists (you can see these in the page source) and I'm targeting them through an edited version of the jsfiddle to reflect the classes and id's in the theme styling:
$( function() {
var $container = $('#portfolio_container');
$container.isotope({
animationOptions: { duration: 300, easing: 'linear', queue: false },
getSortData : {
year : function ( $elem ) { return parseFloat( $elem.find('._year').text() ); },
live-shows : function ( $elem ) { return parseFloat( $elem.find('._live-shows').text() ); }
}
});
var filters = {};
$('.ql_filter a').click(function(){
var $this = $(this);
if ( $this.hasClass('selected') ) {
return;
}
var $optionSet = $this.parents('.filter_list');
$optionSet.find('.active').removeClass('active');
$this.addClass('active');
var group = $optionSet.attr('data-filter-group');
filters[ group ] = $this.attr('data-filter');
var isoFilters = [];
for ( var prop in filters ) {
isoFilters.push( filters[ prop ] )
}
var selector = isoFilters.join('');
$container.isotope({ filter: selector });
return false;
});
});
Two (fairly major) things:
1) I'm not 100% that I've edited this correctly. Despite Rich's excellent comments I'm still out of my depth. I'm particularly not clear on how to set-up the 'getSortData' section - I think it's right but any input would be great.
2) I'm not sure that this JavaScript is being initiated. At the moment I've placed it immediately before the closing head tag but a check on the page suggests that the original script outlined above is the one running on the filter items.
Any pointers at this stage would be fantastic!
I see what you mean. You are looking for the intersection of both filters and not the mutually exclusive filter values.
Short answer: Contact the theme vendor and see if they can make the intersection filters for you.
Longer assistance (not an answer):
Your ultimate goal is to get the Vitrux theme working the way you want.
Your first goal is to understand what the jsfiddle code is doing.
I can handle your first goal by explicating the code.
// hook into the JQuery Document Load event and run an anonymous function
$( function() {
// Create a variable called container
// make container refer to the element with ID Container
var $container = $('#container');
// initialize isotope
// Call the isotope method on the container element
$container.isotope({
// options...
//distracting options
animationOptions: { duration: 300, easing: 'linear', queue: false },
getSortData : {
price : function ( $elem ) { return parseFloat( $elem.find('.price').text() ); },
size : function ( $elem ) { return parseFloat( $elem.find('.size').text() ); }
}
});
// sorting button
//for the anchor tag that has a class of 'pricelow', wire up an anonymous function to the click event
$('a.pricelow').click(function(){
//Rerun the isotope method when it is clicked, pass an array of options as a parameter
$('#container').isotope({ sortBy : 'price',sortAscending : true });
//return false for the anonymous function. Not 100% sure why this is necessary but it has bitten me before
return false;
});
//removed the rest of the click methods, because it does the same thing with different params
//Here is what you are interested in understanding
//Create an empty filters object
var filters = {};
// filter buttons
//When an anchor tag with class filters is clicked, run our anonymous function
$('.filters a').click(function(){
//Create a variable that is the action anchor element
var $this = $(this);
// don't proceed if already selected by checking if a class of "selected" has already been applied to the anchor
if ( $this.hasClass('selected') ) {
return;
}
//Create an optionSet Variable, point it to the anchor's parent's class of "option-set"
var $optionSet = $this.parents('.option-set');
// change selected class
//Inside the optionSet, find elements that match the "selected" class and then remove the "selected class"
$optionSet.find('.selected').removeClass('selected');
// set this (the anchor element) class to "selected"
$this.addClass('selected');
// store filter value in object
// create a variable called 'group' that points to the optionsSet variable and grab the data-filter-group expando attribute
var group = $optionSet.attr('data-filter-group');
//Append to the filters object at the top of this section and set the data-filter-group value to the anchor tag's data-filter value
filters[ group ] = $this.attr('data-filter');
//create an isoFilters array variable
var isoFilters = [];
//Loop through each one of the items in filters (give the item an alias variable called 'prop'
for ( var prop in filters ) {
//push the prop into the isoFilters array (the opposite is pop)
isoFilters.push( filters[ prop ] )
//keep looping until there are no more items in the object
}
//create a variable called selector and turn the array into a string by joining all of the arrays together
var selector = isoFilters.join('');
//Like always, call the 'isotope' method of the 'container' element and pass our newly concatenated 'selector' string as the 'filter' option.
$container.isotope({ filter: selector });
//return false for some reason (maybe someone can expand on that)
return false;
});
});
Next is your ultimate goal which is modifying the Vitrux theme to handle intersection filters.
This gets a little tricky because
You have automatically generated tags from PHP to create the category links and the Year filter. So, there will be definitely some PHP code changes.
You must convert the jsfiddle code to handle your PHP changes
Try it using jQuery noconflict. In effect, replace any "$" with "jQuery" and see if it works.
Wordpress doesn't play well with the dollar sign.

EmbeddedForm symfony saving

I'm experiencing a problem to solve the newly added "Prix" in my Soiree Form
I've embedded the PRixForm in my SoireeForm and i'm using ajax calls to add as many prix as we want.
The problem is, when I want to add a new PRix by clicking on the "+" and after filling my fields nothing is saved...
When i'm editing or filling the first default embedded form prix it works which is weird. Only those added by ajax are not saved..
Here is my code
in my form, SoireeForm:
public function addNewPrix($number){
$new_prix = new BaseForm();
for($i=0; $i <= $number; $i+=1){
$pri = new Prix();
$pri->setSoiree($this->getObject());
$prix_form = new PrixForm($pri);
$new_prix ->embedForm($i, $prix_form);
}
$this->embedForm('new', $new_prix);
}
public function saveEmbeddedForm($con = null, $forms = null){
$dataForms = $this->getEmbeddedForm('new')->getEmbeddedForms();
foreach ($dataForms as $dataForm)
$dataForm->getObject()->setSoiree($this->getObject());
parent::saveEmbeddedForm($con, $forms);
}
In my action:
public function executeAdd($request)
{
$this->forward404unless($request->isXmlHttpRequest());
$number = intval($request->getParameter("num"));
$this->form = new SoireeForm();
$this->form->addNewPrix($number);
return $this->renderPartial('addPri',array('form' => $this->form, 'num' => $number));
}
my partial addPri:
<li>
<?php echo $form['new'][$num]['titre']->renderLabel();?>
<?php echo $form['new'][$num]['titre']->render()?>
<?php echo $form['new'][$num]['montant']->renderLabel();?>
<?php echo $form['new'][$num]['montant']->render();?>
<br />
<br />
and my prix.js file:
newfieldscount = 0;
function addPri(num) {
return $.ajax({
type: 'GET',
url: '/backend_dev.php/soiree/add?num='+num,
async: false
}).responseText;
};
var removeNew = function(){
$('.removenew').click(function(e){
e.preventDefault();
$(this).parent().remove();
})
};
$(document).ready(function(){
$('#add_prix').click(function(e) {
e.preventDefault();
$("ul#extraprix").append(addPri(newfieldscount));
newfieldscount = newfieldscount + 1;
$('.removenew').unbind('click');
removeNew();
});
});
I guess the problem comes from my saveEmbed method in my form, but i don't understand why or how to make everything work as it should.
Thank you in advance you guys
So you want save an 1:n relation, so you should find everything you need here
http://www.thatsquality.com/articles/stretching-sfform-with-dynamic-elements-ajax-a-love-story
http://www.symfony-project.org/more-with-symfony/1_4/en/06-Advanced-Forms
If not, please provide information or code of your PrixForm->configure() function !
PS: Your saveEmbeddedForm() function is unneeded, you'll find more information about the form saving process in the second link in chapter 6 !

looping thru a list of checkboxes and saving the values, not working properly

I'm having a bit of a problem with this code.
The program gives me a list of checkboxes but a user ID. then u user can change his selection and push the save button (id="btnSaveUserIntersts") and i am trying to save in the hidden textbox all the values of the checkboxes that was choosen.
The problem is that i am getting all the time the same selections that came form the database and not getting the new selection that the user made.
Can any one tell me what am i doing wrong here?
$(document).ready(
function()
{
$('#btnSaveUserIntersts').bind(
'click',
function()
{
var strCheckBoxChecked = new String();
$('input[type=checkbox][checked]').each(
function()
{
strCheckBoxChecked += $(this).val();
strCheckBoxChecked += ',';
}
);
$('#hidUserInterests').val(strCheckBoxChecked);
}
);
}
);
10x
Try using:
$('input:checkbox:checked').each(
function()
{
strCheckBoxChecked += $(this).val();
strCheckBoxChecked += ',';
}
);
As the selector instead of what you're currently using.
$('input[type="checkbox"]:checked')
Use .map, it's far prettier:
var strCheckBoxChecked = $('input:checkbox:checked').map(function()
return this.value;
}).get().join(",");
And the selector you are using is close, $('input[type=checkbox][checked=checked]')

Resources