/*
*	Description: Ecoplan Application
*	Modified: 10-11-2015
*	Version: 1.0.0
*	Author: Philippe De Pauw - Waterschoot
* 	-----------------------------------------------
*	Ecoplan API: http://datatank.stad.gent/4/milieuennatuur/ecoplan.json
*/

// Anonymous function executed when document loaded
(function() {
	
	// Declare an App object
	var App = {
		init: function() {
			// Create the service via a corresponding clone
			this._ecoplanAPI = EcoplanAPI;
			this._ecoplanAPI.init('http://datatank.stad.gent/4/milieuennatuur/ecoplan.json');
			// Create the DbContext for Ecoplan by clone
			this._ecoplanDbContext = EcoplanDbContext;
			this._ecoplanDbContext.init('dds.ghent.ecoplan');
			// Call the method getEcoplanFromAPI in order to load the JSON data if no data present in localstorage
			if(this._ecoplanDbContext.getEcoplan() == null || (this._ecoplanDbContext.getEcoplan() != null && this._ecoplanDbContext.getEcoplan().length == 0)) {
				this.getEcoplanFromAPI();
			} else {
				
			}			
		},
		getEcoplanFromAPI: function() {
			var self = this;
			// Load the JSON data from API
			this._ecoplanAPI.getEcoplan().then(
				function(data) {
					var ecoplanPlaceOriginal = null, ecoplanPlace = null;
					for(var i = 0; i < data.length; i++) {
						ecoplanPlaceOriginal = data[i];
						ecoplanPlace = {
							"name": ecoplanPlaceOriginal.NAAM,
							"description": ecoplanPlaceOriginal.opmerkingen,
							"category": ecoplanPlaceOriginal.CATEGORIE,
							"tags": ecoplanPlaceOriginal.LABEL,
							"address": {
								"street": ecoplanPlaceOriginal.STRAAT,
								"housenr": ecoplanPlaceOriginal.NUMMER,
								"postalcode": ecoplanPlaceOriginal.POSTCODE,
								"city": ecoplanPlaceOriginal.GEMEENTE,
								"geolocation": {
									"lat": parseFloat(ecoplanPlaceOriginal.lat),
									"lng": parseFloat(ecoplanPlaceOriginal.lng)
								}
							},
							"url": ecoplanPlaceOriginal.WEBADRES,
							"tel": ecoplanPlaceOriginal.telefoon		
						};
						self._ecoplanDbContext.addEcoplanPlace(ecoplanPlace);
					}
				},
				function(error) {
					
				}
			)
		}	
	};
	
	App.init();// Call the init function from the App object
	
})();
@@ -984,24 +984,79 @@
  else %7B%0A%09%09%09%09
+this.renderEcoplanUI();// Render Ecoplan User Interface
 %0A%09%09%09%7D%09%09%09%0A%09%09%7D
@@ -2103,49 +2103,157 @@
 %09%09%09%09
-%7D,%0A%09%09%09%09function(error) %7B%0A%09%09%09%09%09%0A%09%09%09%09%7D%0A%09%09%09)
+%09%0A%09%09%09%09%09self.renderEcoplanUI();// Render Ecoplan User Interface%0A%09%09%09%09%7D,%0A%09%09%09%09function(error) %7B%0A%09%09%09%09%09%0A%09%09%09%09%7D%0A%09%09%09)%0A%09%09%7D,%0A%09%09renderEcoplanUI: function() %7B%0A%09%09%09
 %0A%09%09%7D

Update Ecoplan App