easybooking - Packages widget readme

To use the packages widget you need to add the following code to your website:

<div class="eb-packages"></div>
<script src="../jquery.easybooking.packages.js"></script>
<script type="text/javascript">
    function ebPackagesLoadedCheck() {
        if (typeof jQuery != "undefined") {
            var data = ({
                        multiUser: false,
                        users: [
                            {
                                customerId: 331,
                                serialNo: "2729-3350-3485"
                            }
                        ],
                        localeId: 1,
                        localeName: "en",
                        ...
                    })
                    ;
            loadPackages(data);
        } else {
            setTimeout(ebPackagesLoadedCheck, 200);
        }
    }
    ebPackagesLoadedCheck();
</script>
    

Set up the data parameters

You can set up the widget with the following parameters, the marked items are required and if you don't need them, you can leave the other ones. If you leave a parameter it's value is interpreted as false. The widget has 3 views, list, latest and detailed, the parameters are labeled depending on which view(s) use(s) them.

All every widget type uses this parameter
List the list widget type uses this parameter
Latest the latest widget type uses this parameter
Detailed the detailed widget type uses this parameter

Widget types

List: The list view displays the packages' data as a list
Latest: The latest view displays the packages which has the highlighted status turned on in the config.
Detailed: The detail view displays the details of one package
multiUser:
All
(bool) true | false
Load data from multiple users or not. If false, load only the first user's data from the users array.

users:
All
(array of objects)
[
{ customerId: (int),
serialNo: (str) }, ...
]
The users auth data.

localeId:
All
(int) 1
Defines the language of the data you get from the server
  • 1: english
  • 2: german
  • 3: dutch
  • 4: italian
  • 5: french
  • 6: hungarian
  • 10: russian

localeName:
All
(str) "en"
The name of the key what the template engine uses to load the texts from the locales attribute. For example "en"

widgetType:
All
(str) "list"
Defines the widget's type: list, latest, detailed.

stepOne:
All
(str) "on" | "off"
At the booking engine start at the first step (date selection) or direct to the room selection at once.

loadCSS:
All
(str) "URL" | (bool) false
The URL of your custom CSS file, if you want to use one.

loadJS:
All
(str) "URL" | (bool) false
The URL of your custom JS file, if you want to use one.

disableEBcss:
All
(bool) true | false
Prevent the loading of easybooking's default CSS file.

templateID:
All
(int) 1
The ID of the template on the easybooking server. The default value is 1, you can leave this field if you use your own template html defined in the templateURL parameter.

templateURL:
All
(str) "URL" | (bool) false
Your custom html template's URL if you want to use your own solution. If you want to use the easybooking's default template, don't use this parameter, set the templateId: 1

detailPrice:
All
(bool) true | false
Hide or show the price that is displayed on the package's image using the default template.

bookingPage:
All
(str) "URL" | (bool) false
If false, the default booking engine page opens in a lighbox. If the URL is set, the browser redirects to that page.

locales:
All
Please see the next chapter.

packageID:
Detailed
(int) 1
Which package's data displayed in the detailed widget.
or
Use the #offer=packageID in the URL. For details please see the enxt chapter.

packagesPerPage:
Latest
(int) 4
How many packages will be displayed at once on a desktop screen in the latest widget.

maxPackages:
Latest
(int) 8
The maximum amount of how many packages will be loaded and displayed.

arrivalDate:
List Latest
(date) "2016-10-10"
The default from date to dispaly the packages.

sortBy:
List Latest
(str) "random" | "high" | "low"
The display order of the packeges. High is started with the highest price, low is started with the lowest minimum price.

category:
List Latest
(str) "all" | "category"
To which category's packages dispaly.

detailPage:
List Latest
(str) "URL" | (bool) false
If false, the default details view opens in a lighbox. If the URL is set, the browser redirects to that page.

datePicker:
List
(bool) true | false
Display a date picker to modify the arrivalDate, or not.

showFilters:
List
(bool) true | false
Show the filters or not.

customFilters:
List
(bool) false | (objects)
[{
name: "Holidays",
categories: ["family", "winter"]
}, {...}]
Define custom filters. If this attribute is set, it overrides the default filters.

Set up the detailed view of the widget

If you use the widget in detailed mode (widgetType: "list"), you can load the desired offer in 2 ways:

Set up the locales

You find, set up and modify the texts translations in the widget's data parameter list's locales node. To determine which language should the template engine load and pass to the widget we use the localeName variable's value from the data list.
The default values that the easybooking default template uses and requires are the following:

  locales: [
    {
      en: {
        allCategories: "All categories",
        from: "from",
        persons: "persons",
        nights: "nights",
        fromDate: "from",
        toOffer: "Show Offer",
        perPerson: "per person",
        request: "Request",
        booking: "Booking",
        services: 'Included services',
        next: 'next',
        prev: 'previous',
        noPackages: 'There are no packages to show',
        dateSelect: 'Select a date'
    },
    de: {
        allCategories: "Alle Kategorien",
        from: "ab",
        persons: "Personen",
        nights: "Nächte",
        fromDate: "vom",
        toOffer: "Zum Angebot",
        perPerson: "per person",
        request: "Anfragen",
        booking: "Buchen",
        allRooms: "Alle Zimmer",
        services: 'Inklusive Leistungen',
        next: 'next',
        prev: 'previous',
        noPackages: 'Es sind keine Pauschalen zur Anzeige vorhanden',
        dateSelect: 'Datum auswählen'
      }
    }
  ]
     
You can freely change all of the values, add new keys or even more languages. For example, if the localeName: "en", the english node's translation data is going to be passed to the template and shown to the users.

Full sample code of the widget's init

        <div class="eb-packages"></div>

        <script src="https://www.easy-booking.at/ebPlugins/packages_v2/jquery.easybooking.packages.js"></script>
        <script type="text/javascript">
            function ebPackagesLoadedCheck() {
                if (typeof jQuery != "undefined") {
                    var data = ({
                                multiUser: false,
                                users: [
                                    {
                                        customerId: 331,
                                        serialNo: "2729-3350-3485"
                                    }
                                ],
                                localeId: 1,
                                localeName: "en",
                                widgetType: "list",
                                packageID: 21,
                                packagesPerPage: 4,
                                maxPackages: 10,
                                loadCSS: false,
                                sortBy: "high",
                                arrivalDate: "2016-10-10",
                                datePicker: true,
                                showFilters: true,
                                templateID: 1,
                                templateURL: false,
                                detailPage: false,
                                bookingPage: false,
                                stepOne: "off",
                                detailPrice: true,
                                category: "all",
                                customFilters: false,
                                locales: [
                                    {
                                        en: {
                                            allCategories: "All categories",
                                            from: "from",
                                            persons: "persons",
                                            nights: "nights",
                                            fromDate: "from",
                                            toOffer: "Show Offer",
                                            perPerson: "per person",
                                            request: "Request",
                                            booking: "Booking",
                                            services: 'Included services',
                                            next: 'next',
                                            prev: 'previous',
                                            noPackages: 'There are no packages to show',
                                            dateSelect: 'Select a date'
                                        },
                                        de: {
                                            allCategories: "Alle Kategorien",
                                            from: "ab",
                                            persons: "Personen",
                                            nights: "Nächte",
                                            fromDate: "vom",
                                            toOffer: "Zum Angebot",
                                            perPerson: "per person",
                                            request: "Anfragen",
                                            booking: "Buchen",
                                            allRooms: "Alle Zimmer",
                                            services: 'Inklusive Leistungen',
                                            next: 'next',
                                            prev: 'previous',
                                            noPackages: 'Es sind keine Pauschalen zur Anzeige vorhanden',
                                            dateSelect: 'Datum auswählen'
                                        }
                                    }
                                ]
                            })
                            ;
                    loadPackages(data);
                } else {
                    setTimeout(ebPackagesLoadedCheck, 200);
                }
            }
            ebPackagesLoadedCheck();
        </script>
    

How to build an HTML template

The packages widget uses mustache.js as template engine. You find all of the necessary information about it and the example codes on the project's GitHub page.

Basically, you only need to use the following methods:


{{variable}}
This code will display the variable's value in your template.

{{#variable}}
...
{{/variable}}
If the variable is an array, this is a foreach loop that iterates over it's items. If your array has objects, you can get each item's attribute with the {{attribute}} code inside the loop.

{{#variable}} ... {{/variable}}
If the variable is a boolean, this is an if(variable){ ... } statement.

{{^variable}} ... {{/variable}}
If the variable is a boolean, this is an if(!variable){ ... } statement.

To use the packages widget with your custom template, you need to define your template's URL in the widget's init code, at the templateURL key. In this way, when the widget loads, the jquery.easybooking.packages.js loads all of the required data from the easybooking server, processes and passes it to your template file.

The variables you can use in your template


users:
(array) objects
The array that contains the package data for all of the users. For the array's detailed description please see the next chapter.

filters:
(array) objects
This array contains the filter objects for the packages. Each filter object has the same model:
{
filterTitle: "Family holiday", //the display name
slug: "familyholiday //the slug name
}

locales:
(object)
This object contains the texts that you can display in your template. The keys based on the data you set on init at the locales and localeName parameters.

bookingPage:
(bool) true | false
If a custom booking url is set in the bookingPage parameter it's true.

bookingPageURL:
(bool) false | (str) "URL"
The URL of the booking page. It's the default easybooking hosted booking engine by default, or the value you set in the bookingPage parameter.

bookingURL:
(str) "URL"
The default easybooking booking URL.

customFilters:
(bool) true | false
Based on the customFilters parameter, if there are custom filters defined, it's true.

datePicker:
(bool) true | false
Based on the datePicker parameter, should the datepicker be visible?

detailPage:
(bool) true | false
If a custom details page url is set in the detailPage parameter it's true. If false, the details opens in a lightbox.

detailPageURL:
(bool) false | (str) "URL"
The URL of the detail page, the value you set in the detailPage parameter. If false, the details opens in a lightbox.

fromDate:
(str) "201x-xx-xx'
Packages that from date is after this date are loaded and displayed.

havePackages:
(bool) true | false
If there are no packages it's value is false.

isEbBookingURL:
(bool) true | false
IF the booking page uses our default booking URL or not.

localeID:
(int) 1
The language ID you set on init.

localeName:
(str) "en_GB"
The selected language's name based on the localeId.

localeNameShort:
(str) "en"
The language's short name based on the localeName you set on init.

showFilters:
(bool) true | false
Show or hide the filters? Based on the showFilters parameter you set on init.

showPrice:
(bool) true | false
Show or hide the prices? Based on the detailPrice parameter you set on init.

stepOne:
(bool) true | false
At the booking engine start at the first step (date selection) or direct to the room selection at once based on the stepOne parameter you set on init.

template:
(str) "TPL DATA"
The source code of the template file.

The users array

This array contains all user data, including the loaded packages. This array contains user objects, which data is the following:


customerId:
(int) 331
The ID of the current customer.

packages:
(array) objects
The package objects that contains the displayed data. Their key-value pairs are the following: ↓

category:
(str) "Family" | null
The package's category display name if it has.

categorySlug:
(str) "family" | null
The package's category slug name if it has.

minPrice:
(int) 1200
The lowest price available for this package.

price:
(array) priceObjects
The available room categories and their prices are listed as objects. Each object has the same data model:
{
customerId: "0331",
eg_id: 1, //the ID of the category
egl_name: "Double Room", //the room category's name
minPrice: 1500 //the lowest available price for this category for this package
}

so_maxPersons:
(int) 3
The amount of the minimum persons.

so_nightsStay:
(int) 6
For how many nights is this package available.

sol_title:
(str) "title"
The title of the package.

sol_shortDesc:
(str) "<b>Description..."
The short description, formatted.

sol_shortDescStripped:

(str) "Description..."
The short description without formatting.

sol_longDesc:
(str) "<b>Description..."
The long description, formatted.

sol_longDescStripped:

(str) "Description..."
The long description without formatting.

st_name:
(str) "serviceName"
The included services' slug name, for example "HalfBoard"

stl_name:
(str) "Service name"
The included services' display name, for example "Halfboard"

Locales object

This object contains the texts that you can display in your template. The keys based on the data you set on init at the locales and localeName parameters.
For example you have an attr, called allRooms: "Show all rooms" you can access it like this:

<p>{{locales.allRooms}}</p>
The output is going to be:
Show all rooms

Sample code, how your template gets the data

(parsed to JSON format)

[
  bookingPage: false,
  bookingPageURL: false,
  bookingURL: "https://www.easy-booking.at/clientWeb001/#0331/1",
  datepicker: true,
  detailPage: false,
  detailPageURL: false,
  filters: [
    {
      filterTitle: "family",
      slug: "family"
    }
  ],
  fromDate: "2016-10-10",
  havePackages: true,
  isEbBookingURL: true,
  localeID: 1,
  localeName: "en_GB",
  localeNameShort: "en",
  locales: {
    allCategories: "All categories",
    booking: "Booking",
    dateSelect: "Select a date",
    from: "from",
    fromDate: "from",
    next: "next",
    nights: "nights",
    noPackages: "There are no packages to show",
    perPerson: "per person",
    persons: "persons",
    prev: "previous",
    request: "Request",
    services: "Included services",
    toOffer: "Show Offer"
  },
  showFilters: true,
  showPrice: true,
  stepOne: false,
  template: "TPL",
  users: [
    {
      customerId: "0331",
      packages: [
        {
          category: "family",
          categorySlug: "family",
          minPrice: 340,
          price: [
            {
              customerId: "0331",
              eg_id: "6",
              egl_name: "Familyroom",
              minPrice: 340
            }
          ],
          so_fromDate: "2017-03-01",
          so_highlighted: "on",
          so_id: "21",
          so_img001: "/wo/Services/images/srv0010331/201311815414421_index.jpg",
          so_maxPersons: "2",
          so_minPersons: "2",
          so_nightsStay: "3",
          so_untilDate: "2017-04-30",
          sol_longDesc: "<TEXTFORMAT LEADING="2"><P ALIGN="LEFT">...",
          sol_longDescStripped: "Included services in our Easter package:...",
          sol_shortDesc: "<TEXTFORMAT LEADING="2"><P ALIGN="LEFT">...",
          sol_shortDescStripped: "Our family package during...",
          sol_title: "Happy Easter in the capital",
          st_name: "2OverNightBreakfast",
          stl_name: "B&B"
        }
      ]
    }
  ]
]
    

Template building example

The data your template gets:
[
  title: "Hello World!",
  packages: [
    {
      "id": "1",
      "value": "Summer package",
      "bookable": true
    },
    {
      "id": "2",
      "value": "Winter package",
      "bookable": false
    }
  ],
  locales: {
    booking: "Online booking"
  }
]
    
Your template file:
{{title}}
{{#packages}}
<div class="package" id="pkg-{{id}}">
    <h1>{{value}}</h1>
    {{#bookable}}<button class="booking">{{locales.booking}}</button>{{/bookable}}
</div>
{{/packages}}
    
The output:
Hello World!
<div class="package" id="pkg-1">
    <h1>Summer package</h1>
    <button class="booking">Online booking</button>
</div>
<div class="package" id="pkg-2">
    <h1>Winter package</h1>
</div>