WiP Added field to input form.
This commit is contained in:
@@ -50,7 +50,7 @@ const BASIC_BOOLEAN_PUBLISH = [
|
||||
}
|
||||
];
|
||||
|
||||
const BASIC_INPUT_PUBLISH_NO = [
|
||||
const BASIC_INPUT_PUBLISH = [
|
||||
{
|
||||
dbField: "price",
|
||||
title: "Cijena (KM)",
|
||||
@@ -111,10 +111,7 @@ const BASIC_INPUT_PUBLISH_NO = [
|
||||
AD_CATEGORY.APARTMENT,
|
||||
AD_CATEGORY.OFFICE
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
const BASIC_INPUT_PUBLISH = [
|
||||
},
|
||||
{
|
||||
dbField: "title",
|
||||
title: "Naslov",
|
||||
@@ -477,7 +474,6 @@ const ADDITIONAL_SEGMENT_PUBLISH = [
|
||||
|
||||
module.exports = {
|
||||
BASIC_INPUT_PUBLISH,
|
||||
BASIC_INPUT_PUBLISH_NO,
|
||||
BASIC_SEGMENT_PUBLISH,
|
||||
BASIC_BOOLEAN_PUBLISH,
|
||||
ADDITIONAL_BOOLEAN_PUBLISH,
|
||||
|
||||
@@ -3,6 +3,13 @@ const { createRealEstate } = require("../helpers/db/realEstate");
|
||||
const { createKiviOriginal } = require("../helpers/db/kiviOriginal");
|
||||
|
||||
const { AD_CATEGORY, AD_TYPE, AD_AGENCY } = require("../common/enums");
|
||||
const {
|
||||
BASIC_BOOLEAN_PUBLISH,
|
||||
BASIC_SEGMENT_PUBLISH,
|
||||
ADDITIONAL_BOOLEAN_PUBLISH,
|
||||
ADDITIONAL_SEGMENT_PUBLISH,
|
||||
BASIC_INPUT_PUBLISH
|
||||
} = require("../common/publishEnums");
|
||||
|
||||
const getPublishInputs = async (req, res) => {
|
||||
const realEstate = await currentRealEstate(req);
|
||||
@@ -14,8 +21,133 @@ const getPublishInputs = async (req, res) => {
|
||||
|
||||
const title = "Podaci o nekretnini";
|
||||
|
||||
const {
|
||||
price,
|
||||
area,
|
||||
adType,
|
||||
realEstateType,
|
||||
locationLat,
|
||||
locationLong,
|
||||
accessRoadType,
|
||||
heatingType,
|
||||
balcony,
|
||||
newBuilding,
|
||||
elevator,
|
||||
recentlyAdapted,
|
||||
gardenSize,
|
||||
numberOfRooms,
|
||||
numberOfFloors,
|
||||
floor,
|
||||
water,
|
||||
electricity,
|
||||
drainageSystem,
|
||||
registeredInZkBooks,
|
||||
parking,
|
||||
garage,
|
||||
gas,
|
||||
antiTheftDoor,
|
||||
airCondition,
|
||||
phoneConnection,
|
||||
cableTV,
|
||||
internet,
|
||||
basementAttic,
|
||||
storeRoom,
|
||||
videoSurveillance,
|
||||
alarm,
|
||||
suitableForStudents,
|
||||
includingBills,
|
||||
animalsAllowed,
|
||||
pool,
|
||||
exchange,
|
||||
urbanPlanPermit,
|
||||
buildingPermit,
|
||||
furnishingType,
|
||||
shortDescription,
|
||||
streetName
|
||||
} = realEstate;
|
||||
const category = AD_CATEGORY[realEstateType] || AD_CATEGORY.FLAT;
|
||||
|
||||
// TODO: Maybe this is slow, pay attention to this
|
||||
const filterInputs = filterObject => {
|
||||
const filterCategories = filterObject.categoriesToShow;
|
||||
return filterCategories.indexOf(category) !== -1;
|
||||
};
|
||||
//Boolean inputs to be shown on Basic Data tab
|
||||
const basicBooleanPublishInputs = BASIC_BOOLEAN_PUBLISH.filter(filterInputs);
|
||||
const basicBooleanPublishValues = {
|
||||
balcony,
|
||||
elevator,
|
||||
newBuilding,
|
||||
recentlyAdapted
|
||||
};
|
||||
//Boolean inputs to be shown on Additional Data tab
|
||||
const additionalBooleanPublishInputs = ADDITIONAL_BOOLEAN_PUBLISH.filter(
|
||||
filterInputs
|
||||
);
|
||||
const additionalBooleanPublishValues = {
|
||||
water,
|
||||
electricity,
|
||||
drainageSystem,
|
||||
registeredInZkBooks,
|
||||
parking,
|
||||
garage,
|
||||
gas,
|
||||
antiTheftDoor,
|
||||
airCondition,
|
||||
phoneConnection,
|
||||
cableTV,
|
||||
internet,
|
||||
basementAttic,
|
||||
storeRoom,
|
||||
videoSurveillance,
|
||||
alarm,
|
||||
suitableForStudents,
|
||||
includingBills,
|
||||
animalsAllowed,
|
||||
pool,
|
||||
exchange,
|
||||
urbanPlanPermit,
|
||||
buildingPermit
|
||||
};
|
||||
//Segment select inputs to be shown on Basic Data tab
|
||||
const basicSegmentSelectInputs = BASIC_SEGMENT_PUBLISH.filter(filterInputs);
|
||||
const basicSegmentSelectValues = {
|
||||
furnishingType
|
||||
};
|
||||
//Segment select inputs to be shown on Additional Data tab
|
||||
const additionalSegmentSelectInputs = ADDITIONAL_SEGMENT_PUBLISH.filter(
|
||||
filterInputs
|
||||
);
|
||||
const additionalSegmentSelectValues = {
|
||||
accessRoadType,
|
||||
heatingType
|
||||
};
|
||||
//Input text type inputs to be shown on Basic Data tab
|
||||
const basicInputInputs = BASIC_INPUT_PUBLISH.filter(filterInputs);
|
||||
const basicInputValues = {
|
||||
price,
|
||||
area,
|
||||
gardenSize,
|
||||
numberOfRooms,
|
||||
numberOfFloors,
|
||||
floor,
|
||||
title,
|
||||
shortDescription,
|
||||
streetName
|
||||
};
|
||||
|
||||
res.render("publishRealEstate", {
|
||||
title
|
||||
title,
|
||||
basicBooleanPublishInputs,
|
||||
basicBooleanPublishValues,
|
||||
additionalBooleanPublishInputs,
|
||||
additionalBooleanPublishValues,
|
||||
basicSegmentSelectInputs,
|
||||
basicSegmentSelectValues,
|
||||
additionalSegmentSelectInputs,
|
||||
additionalSegmentSelectValues,
|
||||
basicInputInputs,
|
||||
basicInputValues
|
||||
});
|
||||
};
|
||||
|
||||
@@ -26,6 +158,85 @@ const postPublishInputs = async (req, res) => {
|
||||
res.render("notFound", { title: " " });
|
||||
return;
|
||||
}
|
||||
|
||||
const balcony = req.body.balcony === "on";
|
||||
const elevator = req.body.elevator === "on";
|
||||
const newBuilding = req.body.newBuilding === "on";
|
||||
const recentlyAdapted = req.body.recentlyAdapted === "on";
|
||||
const water = req.body.water === "on";
|
||||
const electricity = req.body.electricity === "on";
|
||||
const drainageSystem = req.body.drainageSystem === "on";
|
||||
const registeredInZkBooks = req.body.registeredInZkBooks === "on";
|
||||
const parking = req.body.parking === "on";
|
||||
const garage = req.body.garage === "on";
|
||||
const gas = req.body.gas === "on";
|
||||
const antiTheftDoor = req.body.antiTheftDoor === "on";
|
||||
const airCondition = req.body.airCondition === "on";
|
||||
const phoneConnection = req.body.phoneConnection === "on";
|
||||
const cableTV = req.body.cableTV === "on";
|
||||
const internet = req.body.internet === "on";
|
||||
const basementAttic = req.body.basementAttic === "on";
|
||||
const storeRoom = req.body.storeRoom === "on";
|
||||
const videoSurveillance = req.body.videoSurveillance === "on";
|
||||
const alarm = req.body.alarm === "on";
|
||||
const suitableForStudents = req.body.suitableForStudents === "on";
|
||||
const includingBills = req.body.includingBills === "on";
|
||||
const animalsAllowed = req.body.animalsAllowed === "on";
|
||||
const pool = req.body.pool === "on";
|
||||
const exchange = req.body.exchange === "on";
|
||||
const urbanPlanPermit = req.body.urbanPlanPermit === "on";
|
||||
const buildingPermit = req.body.buildingPermit === "on";
|
||||
|
||||
const furnishingType = req.body.furnishingType;
|
||||
if (!FURNISHING_TYPE[furnishingType]) {
|
||||
res.render("notFound", { title: " Greška !" });
|
||||
return;
|
||||
}
|
||||
const accessRoadType = req.body.accessRoadType;
|
||||
if (!ACCESS_ROAD_TYPE[accessRoadType]) {
|
||||
res.render("notFound", { title: " Greška !" });
|
||||
return;
|
||||
}
|
||||
const heatingType = req.body.heatingType;
|
||||
if (!HEATING_TYPE[heatingType]) {
|
||||
res.render("notFound", { title: " Greška !" });
|
||||
return;
|
||||
}
|
||||
|
||||
realEstate.balcony = balcony;
|
||||
realEstate.elevator = elevator;
|
||||
realEstate.newBuilding = newBuilding;
|
||||
realEstate.recentlyAdapted = recentlyAdapted;
|
||||
realEstate.water = water;
|
||||
realEstate.electricity = electricity;
|
||||
realEstate.drainageSystem = drainageSystem;
|
||||
realEstate.registeredInZkBooks = registeredInZkBooks;
|
||||
realEstate.parking = parking;
|
||||
realEstate.garage = garage;
|
||||
realEstate.gas = gas;
|
||||
realEstate.antiTheftDoor = antiTheftDoor;
|
||||
realEstate.airCondition = airCondition;
|
||||
realEstate.phoneConnection = phoneConnection;
|
||||
realEstate.cableTV = cableTV;
|
||||
realEstate.internet = internet;
|
||||
realEstate.basementAttic = basementAttic;
|
||||
realEstate.storeRoom = storeRoom;
|
||||
realEstate.videoSurveillance = videoSurveillance;
|
||||
realEstate.alarm = alarm;
|
||||
realEstate.suitableForStudents = suitableForStudents;
|
||||
realEstate.includingBills = includingBills;
|
||||
realEstate.animalsAllowed = animalsAllowed;
|
||||
realEstate.pool = pool;
|
||||
realEstate.exchange = exchange;
|
||||
realEstate.urbanPlanPermit = urbanPlanPermit;
|
||||
realEstate.buildingPermit = buildingPermit;
|
||||
|
||||
realEstate.furnishingType = furnishingType;
|
||||
realEstate.accessRoadType = accessRoadType;
|
||||
realEstate.heatingType = heatingType;
|
||||
//
|
||||
console.log("postPublishInputs");
|
||||
await realEstate.save();
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1 +1,31 @@
|
||||
Publish Additional Data
|
||||
<br>
|
||||
|
||||
<% for (const input of additionalBooleanPublishInputs){ %>
|
||||
<p>
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" class="filled-in" name="<%= input.dbField %>"
|
||||
<% if (additionalBooleanPublishValues[input.dbField]) { %>
|
||||
checked
|
||||
<% } %>>
|
||||
<span><%= input.title %></span>
|
||||
</label>
|
||||
</p>
|
||||
<% } %>
|
||||
|
||||
<br>
|
||||
<% for (const input of additionalSegmentSelectInputs){ %>
|
||||
<div>
|
||||
<label class="checkbox-label"><%= input.title %>: </label><br><br>
|
||||
<span class="segmented small">
|
||||
<% for (const segmentObject of input.values) { %>
|
||||
<label>
|
||||
<input type="radio" name="<%= input.dbField %>" value="<%= segmentObject.id %>"
|
||||
<% if (additionalSegmentSelectValues[input.dbField] === segmentObject.id) { %>
|
||||
checked
|
||||
<% } %>>
|
||||
<span class="label"><%= segmentObject.title %></span>
|
||||
</label>
|
||||
<% } %>
|
||||
</span>
|
||||
</div>
|
||||
<% } %>
|
||||
@@ -1,2 +1,49 @@
|
||||
<br>
|
||||
Publish Basic Data
|
||||
<div class="row">
|
||||
<% for (const input of basicInputInputs){ %>
|
||||
<div class="input-field col s3 m4 l5">
|
||||
<input
|
||||
id="<%= input.dbField %>"
|
||||
name="<%= input.dbField %>"
|
||||
type="text"
|
||||
value="<%= basicInputValues[input.dbField] !== undefined ? basicInputValues[input.dbField] : ""%>"
|
||||
>
|
||||
<label for="<%= input.dbField %>"><%= input.title %></label>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
<br>
|
||||
<div class="row">
|
||||
<% for (const input of basicBooleanPublishInputs){ %>
|
||||
<p>
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" class="filled-in" name="<%= input.dbField %>"
|
||||
<% if (basicBooleanPublishValues[input.dbField]) { %>
|
||||
checked
|
||||
<% } %>>
|
||||
<span><%= input.title %></span>
|
||||
</label>
|
||||
</p>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<% for (const input of basicSegmentSelectInputs){ %>
|
||||
<div>
|
||||
<label class="checkbox-label"><%= input.title %>: </label><br><br>
|
||||
<span class="segmented small">
|
||||
<% for (const segmentObject of input.values) { %>
|
||||
<label>
|
||||
<input type="radio" name="<%= input.dbField %>" value="<%= segmentObject.id %>"
|
||||
<% if (basicSegmentSelectValues[input.dbField] === segmentObject.id) { %>
|
||||
checked
|
||||
<% } %>>
|
||||
<span class="label"><%= segmentObject.title %></span>
|
||||
</label>
|
||||
<% } %>
|
||||
</span>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user