function fetchPlaces (places) {
    $.ajax({
      url: 'http://0.0.0.0:5001/api/v1/places_search/',
      type: 'POST',
      data: JSON.stringify(places),
      dataType: 'json',
      contentType: 'application/json; charset=utf-8',
      success: function (data) {
        function compare (a, b) {
          if (a.last_nom < b.last_nom) { return -1; }
          if (a.last_nom > b.last_nom) { return 1; }
          return 0;
        }

        let newData = data.sort(compare);

        data.sort(function (a, b) {
          let nameA = a.name.toLowerCase();
          let nameB = b.name.toLowerCase();

          if (nameA < nameB) { return -1; }
          if (nameA > nameB) { return 1; }
          return 0;
        });

        $.each(newData, function (index, value) {
          let article = $('<article>');

          let header = $('<div>', {'class': 'title'})
            .append($('<h2>').text(value.name))
            .append($('<div>', {'class': 'price_by_night', 'text': '$' + value.price_by_night}));

          article.append(header);

          let info = $('<div>', {'class': 'information'});

          info.append($('<div>', {'class': 'max_guest'})
            .append($('<i>', {'class': 'fa fa-users fa-3x'}))
            .append('</br>' + value.max_guest + ' Guest'));

          info.append($('<div>', {'class': 'number_rooms'})
            .append($('<i>', {'class': 'fa fa-bed fa-3x'}))
            .append('</br>' + value.number_rooms + ' Bedrooms'));

          info.append($('<div>', {'class': 'number_bathrooms'})
            .append($('<i>', {'class': 'fa fa-bath fa-3x'}))
            .append('</br>' + value.number_bathrooms + ' Bathrooms'));

          article.append(info);

          let userInfo = $('<div>', {'class': 'user'});
          article.append(userInfo);
          userInfo.append('<strong>' + 'Owner: ' + allUsers[value.user_id]);

          article.append($('<div>', {'class': 'description', 'html': value.description}));
          $('.places').append(article);
        });
      }
    });
  }
/**
   * fetchPlaces - fetches amenity from backend api
   *
   * makes individual <article> blocks that hold the content
   * replaces jinja templating
   *
   * @param places object of search parameters (CAN BE EMPTY)
   * If empty, returns all places
   *
   * {
   *  "states": [list of ids],
   *  "cities": [list of ids],
   *  "amenities": [list of ids]
   * }
   *
   */
fetches amenity from backend api
makes individual  blocks that hold the content
replaces jinja templating

@param places object of search parameters (CAN BE EMPTY)
If empty, returns all places


fetches amenity from backend api makes individual blocks that hold the content replaces jinja templating @param places object of search parameters ( CAN BE EMPTY ) If empty returns all places
function fetchPlaces (places) {
    $.ajax({
      url: 'http://0.0.0.0:5001/api/v1/places_search/',
      type: 'POST',
      data: JSON.stringify(places),
      dataType: 'json',
      contentType: 'application/json; charset=utf-8',
      success: function (data) {
        function compare (a, b) {
          if (a.last_nom < b.last_nom) { return -1; }
          if (a.last_nom > b.last_nom) { return 1; }
          return 0;
        }
        let newData = data.sort(compare);
        data.sort(function (a, b) {
          let nameA = a.name.toLowerCase();
          let nameB = b.name.toLowerCase();
          if (nameA < nameB) { return -1; }
          if (nameA > nameB) { return 1; }
          return 0;
        });
        $.each(newData, function (index, value) {
          let article = $('<article>');
          let header = $('<div>', {'class': 'title'})
            .append($('<h2>').text(value.name))
            .append($('<div>', {'class': 'price_by_night', 'text': '$' + value.price_by_night}));
          article.append(header);
          let info = $('<div>', {'class': 'information'});
          info.append($('<div>', {'class': 'max_guest'})
            .append($('<i>', {'class': 'fa fa-users fa-3x'}))
            .append('</br>' + value.max_guest + ' Guest'));
          info.append($('<div>', {'class': 'number_rooms'})
            .append($('<i>', {'class': 'fa fa-bed fa-3x'}))
            .append('</br>' + value.number_rooms + ' Bedrooms'));
          info.append($('<div>', {'class': 'number_bathrooms'})
            .append($('<i>', {'class': 'fa fa-bath fa-3x'}))
            .append('</br>' + value.number_bathrooms + ' Bathrooms'));
          article.append(info);
          let userInfo = $('<div>', {'class': 'user'});
          article.append(userInfo);
          userInfo.append('<strong>' + 'Owner: ' + allUsers[value.user_id]);
          article.append($('<div>', {'class': 'description', 'html': value.description}));
          $('.places').append(article);
        });
      }
    });
  }
function fetchPlaces ( places ) { $ . ajax ( { url : 'http://0.0.0.0:5001/api/v1/places_search/' , type : 'POST' , data : JSON . stringify ( places ) , dataType : 'json' , contentType : 'application/json; charset=utf-8' , success : function ( data ) { function compare ( a , b ) { if ( a . last_nom < b . last_nom ) { return - 1 ; } if ( a . last_nom > b . last_nom ) { return 1 ; } return 0 ; } let newData = data . sort ( compare ) ; data . sort ( function ( a , b ) { let nameA = a . name . toLowerCase ( ) ; let nameB = b . name . toLowerCase ( ) ; if ( nameA < nameB ) { return - 1 ; } if ( nameA > nameB ) { return 1 ; } return 0 ; } ) ; $ . each ( newData , function ( index , value ) { let article = $ ( '<article>' ) ; let header = $ ( '<div>' , { 'class' : 'title' } ) . append ( $ ( '<h2>' ) . text ( value . name ) ) . append ( $ ( '<div>' , { 'class' : 'price_by_night' , 'text' : '$' + value . price_by_night } ) ) ; article . append ( header ) ; let info = $ ( '<div>' , { 'class' : 'information' } ) ; info . append ( $ ( '<div>' , { 'class' : 'max_guest' } ) . append ( $ ( '<i>' , { 'class' : 'fa fa-users fa-3x' } ) ) . append ( '</br>' + value . max_guest + ' Guest' ) ) ; info . append ( $ ( '<div>' , { 'class' : 'number_rooms' } ) . append ( $ ( '<i>' , { 'class' : 'fa fa-bed fa-3x' } ) ) . append ( '</br>' + value . number_rooms + ' Bedrooms' ) ) ; info . append ( $ ( '<div>' , { 'class' : 'number_bathrooms' } ) . append ( $ ( '<i>' , { 'class' : 'fa fa-bath fa-3x' } ) ) . append ( '</br>' + value . number_bathrooms + ' Bathrooms' ) ) ; article . append ( info ) ; let userInfo = $ ( '<div>' , { 'class' : 'user' } ) ; article . append ( userInfo ) ; userInfo . append ( '<strong>' + 'Owner: ' + allUsers [ value . user_id ] ) ; article . append ( $ ( '<div>' , { 'class' : 'description' , 'html' : value . description } ) ) ; $ ( '.places' ) . append ( article ) ; } ) ; } } ) ; }
fetchPlaces - fetches amenity from backend api
 makes individual <article> blocks that hold the content
 replaces jinja templating
fetchPlaces - fetches amenity from backend api makes individual <article > blocks that hold the content replaces jinja templating