From 55cb01c3c2a1368407a47f9e77dae8e3c82eb42e Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Thu, 19 Mar 2020 15:24:58 +0100 Subject: [PATCH] Started edit ad option. --- app/controllers/publishRealEstate.js | 15 +++++++++++- app/helpers/emailContentGenerator.js | 2 +- app/views/publishEnd.ejs | 10 +++++++- app/views/publishLocation.ejs | 34 +++++++++++++++++++++++++--- app/views/publishRealEstate.ejs | 4 ++++ 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/app/controllers/publishRealEstate.js b/app/controllers/publishRealEstate.js index 7e00e3d..1d7378b 100644 --- a/app/controllers/publishRealEstate.js +++ b/app/controllers/publishRealEstate.js @@ -82,6 +82,15 @@ const getPublishInputs = async (req, res) => { title, longDescription } = realEstate; + + const { email } = kiviOriginal; + //If email is not empty - has string value, then proces of publishing has been conducted alredy + //That means user is editing existing real estate ad not publishing new one + let editingRealEstate = false; + if (email) { + editingRealEstate = true; + } + const category = AD_CATEGORY[realEstateType] || AD_CATEGORY.FLAT; // TODO: Maybe this is slow, pay attention to this @@ -172,7 +181,11 @@ const getPublishInputs = async (req, res) => { basicInputValues, additionalInputInputs, additionalInputValues, - validate: validate + validate: validate, + email, + locationLat: locationLat || 0, + locationLong: locationLong || 0, + editingRealEstate }); }; diff --git a/app/helpers/emailContentGenerator.js b/app/helpers/emailContentGenerator.js index e522876..2c5a03d 100644 --- a/app/helpers/emailContentGenerator.js +++ b/app/helpers/emailContentGenerator.js @@ -231,7 +231,7 @@ const generateNewAdPublishEmail = (
Pregledajte Vaš oglas na sljedećem linku: ${realEstate.title}

-
Ako želite izmijeniti detalje oglasa, izmjenite ovdje.
+
Ako želite izmijeniti detalje oglasa, izmjenite ovdje.
Ako želite izbrisati Vaš oglas iz Kivi baze, izbrišite ovdje.

Hvala na ukazanom povjerenju!
diff --git a/app/views/publishEnd.ejs b/app/views/publishEnd.ejs index 452d005..6b455dd 100644 --- a/app/views/publishEnd.ejs +++ b/app/views/publishEnd.ejs @@ -9,6 +9,7 @@ id="email" name="email" type="email" + value="<%= email !== undefined ? email : ""%>" >
@@ -17,7 +18,14 @@
diff --git a/app/views/publishLocation.ejs b/app/views/publishLocation.ejs index 6c574f3..a3ae44c 100644 --- a/app/views/publishLocation.ejs +++ b/app/views/publishLocation.ejs @@ -36,6 +36,9 @@ let places; let geocoder; let marker =false; //Initialy no marker on map + + const editingRealEstate = <%- editingRealEstate %>; + function locateMe() { if (navigator.geolocation) { @@ -101,6 +104,13 @@ autocomplete.addListener("place_changed", onPlaceChanged); pacSelectFirst(inputElement); addLocateMeButton(map); + + //Move map and marker to already selected position if in editing mode + if( editingRealEstate===true) { + console.log('Editujem mapu!'); + setMarkerToLocation(map); + } + //Add event listener to position marker on map google.maps.event.addListener(map, 'click', positionMarker); @@ -114,13 +124,31 @@ map: map, draggable: true }); - google.maps.event.addListener(marker, 'dragend', function(event){ - markerLocation(); - }); + //google.maps.event.addListener(marker, 'dragend', function(event){ + // markerLocation(); + // }); } else{ marker.setPosition(clickedLocation); } } + function setMarkerToLocation(map) { + const ESTATE_COORDINATES = { + lat: <%= locationLat %>, + lng: <%= locationLong %> + }; + + marker = new google.maps.Marker({ + position: ESTATE_COORDINATES, + map: map, + draggable: true + }); + // google.maps.event.addListener(marker, 'dragend', function(event){ + // markerLocation(); + // }); + //Zooming map to current location + map.setCenter(ESTATE_COORDINATES); + map.setZoom(13); + } function addLocateMeButton(map) { var parent = document.createElement("div"); diff --git a/app/views/publishRealEstate.ejs b/app/views/publishRealEstate.ejs index 0e61eda..9b52038 100644 --- a/app/views/publishRealEstate.ejs +++ b/app/views/publishRealEstate.ejs @@ -1,4 +1,8 @@
+<% if(editingRealEstate) { %> +
Editujem oglas!
+<% } %> +