Datetimepicker javascript

1

I have this datepicker, in which I show the blocked dates according to the condition that they are accepted or not, I try to filter now by a new parameter, area_id. If the area_id of the data is equal to the user's, the dates must be shown in orange and if accepted, it is equal to 1, blocked and painted in red.

This is the code I have:

var daysData = <?= json_encode($data) ?>;
var isArea = {{ Auth::user()->area_id }}
var newA = [];
for( j of daysData){
  let start = moment(j["start"]);
  let end   = moment(j["end"]);

  for (let m = moment(start); m.diff(end, 'days') <= 0; m.add(1, 'days')) {
    newA[m.format('DD/MM/YYYY')] = j;
  }
}

$('input[name="datefilter"]').daterangepicker({

isInvalidDate: function(date) {
    var valid = false ; // default css class
    let d =  date.format("DD/MM/YYYY");
    if(typeof newA[d] !== 'undefined'){
        if(newA[d].acept == 1 && newA[d].area_id == isArea){
            valid =  true;
        }
    }
    return valid;
},
isCustomDate: function(date) {

  var daySettings = 'day_green';
  let d =  date.format("DD/MM/YYYY");
  if(typeof newA[d] !== 'undefined'){
       daySettings = 'day_red';
           if(newA[d].acept == 0 && newA[d].area_id ==isArea){
            daySettings = 'day_orange';
           }
        }
  }
  return daySettings;
},

Pro keeps on painting the dates that do not correspond to the user's area_id, which makes me a bit frustrated. I would appreciate a little hand.

Greetings and thanks

    
asked by Peisou 04.09.2018 в 11:39
source

1 answer

1

Solved, I made the filter directly in php, with which, when I make the query to the database and filter directly by the area_id, without having to modify anything in javascript since I bring the correct data to the front.

I enclose the query:

$data =  \DB::table('vacations')->select('*')
        ->join('users','users.id','=','vacations.user_id')
        ->where(['vacations.area_id' => $fil])
        ->get();

    return $data;
    
answered by 05.09.2018 в 09:14