Skip to content

Commit

Permalink
Places calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulaaSTIC committed Dec 30, 2024
1 parent 78e5d33 commit 3b9747c
Show file tree
Hide file tree
Showing 9 changed files with 462 additions and 248 deletions.
216 changes: 114 additions & 102 deletions modules/stic_Bookings/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,52 +176,64 @@ switch (viewType()) {
previousPlannedEndHours = $("#planned_end_date_hours").val();
previousPlannedEndMinutes = $("#planned_end_date_minutes").val();

setInterval(function() {
currentPlannedStartDate = $("#planned_start_date_date").val();
currentPlannedStartHours = $("#planned_start_date_hours").val();
currentPlannedStartMinutes = $("#planned_start_date_minutes").val()
currentPlannedEndDate = $("#planned_end_date_date").val();
currentPlannedEndHours = $("#planned_end_date_hours").val();
currentPlannedEndMinutes = $("#planned_end_date_minutes").val()

if (currentPlannedStartDate !== previousPlannedStartDate) {
$("#start_date_date").val(currentPlannedStartDate).trigger("change");
previousPlannedStartDate = currentPlannedStartDate;
}

if (currentPlannedStartHours !== previousPlannedStartHours) {
$("#start_date_hours").val(currentPlannedStartHours).trigger("change");
previousPlannedStartHours = currentPlannedStartHours;
}

if (currentPlannedStartMinutes !== previousPlannedStartMinutes) {
$("#start_date_minutes").val(currentPlannedStartMinutes).trigger("change");
previousPlannedStartMinutes = currentPlannedStartMinutes;
}
if (currentPlannedEndDate !== previousPlannedEndDate) {
$("#end_date_date").val(currentPlannedEndDate).trigger("change");
previousPlannedEndDate = currentPlannedEndDate;
setInterval(function () {
currentPlannedStartDate = $("#planned_start_date_date").val();
currentPlannedStartHours = $("#planned_start_date_hours").val();
currentPlannedStartMinutes = $("#planned_start_date_minutes").val();
currentPlannedEndDate = $("#planned_end_date_date").val();
currentPlannedEndHours = $("#planned_end_date_hours").val();
currentPlannedEndMinutes = $("#planned_end_date_minutes").val();

if (currentPlannedStartDate !== previousPlannedStartDate) {
$("#start_date_date").val(currentPlannedStartDate).trigger("change");
previousPlannedStartDate = currentPlannedStartDate;
}

if (currentPlannedStartHours !== previousPlannedStartHours) {
$("#start_date_hours").val(currentPlannedStartHours).trigger("change");
previousPlannedStartHours = currentPlannedStartHours;
}

if (currentPlannedStartMinutes !== previousPlannedStartMinutes) {
$("#start_date_minutes")
.val(currentPlannedStartMinutes)
.trigger("change");
previousPlannedStartMinutes = currentPlannedStartMinutes;
}

if (currentPlannedEndDate !== previousPlannedEndDate) {
$("#end_date_date").val(currentPlannedEndDate).trigger("change");
previousPlannedEndDate = currentPlannedEndDate;
}

if (currentPlannedEndHours !== previousPlannedEndHours) {
$("#end_date_hours").val(currentPlannedEndHours).trigger("change");
previousPlannedEndHours = currentPlannedEndHours;
$("#end_date_hours").val(currentPlannedEndHours).trigger("change");
previousPlannedEndHours = currentPlannedEndHours;
}

if (currentPlannedEndMinutes !== previousPlannedEndMinutes) {
$("#end_date_minutes").val(currentPlannedEndMinutes).trigger("change");
previousPlannedEndMinutes = currentPlannedEndMinutes;
$("#end_date_minutes").val(currentPlannedEndMinutes).trigger("change");
previousPlannedEndMinutes = currentPlannedEndMinutes;
}
}, 500);

}, 500);

// Set event listener for center popup
$("#openCenterPopup").click(function () {
openCenterPopup();
});

// Set autofill mark beside field label
setAutofill(["name"]);
document
.getElementById("place_booking")
.addEventListener("change", function () {
if (this.checked) {
updateResourceFields();
$("#openCenterPopup").show();
} else {
$("#openCenterPopup").hide();
updateResourceFields();
}
});

break;

Expand Down Expand Up @@ -376,39 +388,37 @@ function resourceLineWithData(resourcesCount) {
return false;
}
function updateResourceFields() {
var isPlaceBooking = $("#place_booking").is(":checked");
var fields = isPlaceBooking ? config_place_fields : config_resource_fields;

var header = "<tr>";
fields.forEach(function (field) {
header +=
"<th class='resource_column " +
field +
"'>" +
SUGAR.language.get(
"stic_Bookings",
"LBL_RESOURCES_" + field.toUpperCase()
) +
"</th>";
});
header += "<th class='resource_column'></th></tr>";
$("#resourceLine thead").html(header);

$("#resourceLine tbody").empty();
resourceMaxCount = 0;
var isPlaceBooking = $("#place_booking").is(":checked");
var fields = isPlaceBooking ? config_place_fields : config_resource_fields;

insertResourceLine();
if (!isPlaceBooking) {
$("#resourceSearchFields").hide();
$("#resourceType").val('');
$("#resourceStatus").val('');
$("#resourceName").val('');
$("#numberOfCenters").val('');
}
var header = "<tr>";
fields.forEach(function (field) {
header +=
"<th class='resource_column " +
field +
"'>" +
SUGAR.language.get(
"stic_Bookings",
"LBL_RESOURCES_" + field.toUpperCase()
) +
"</th>";
});
header += "<th class='resource_column'></th></tr>";
$("#resourceLine thead").html(header);

$("#resourceLine tbody").empty();
resourceMaxCount = 0;

insertResourceLine();
if (!isPlaceBooking) {
$("#resourceSearchFields").hide();
$("#resourceType").val("");
$("#resourceStatus").val("");
$("#resourceName").val("");
$("#numberOfCenters").val("");
}
// Delete a resource row
}
// Delete a resource row
function markResourceLineDeleted(ln) {
$("#resourceLine" + ln).remove();

Expand Down Expand Up @@ -436,17 +446,29 @@ function openResourceSelectPopup(ln) {
field_to_name_array: field_to_name_array,
};

var resourceTypes = SUGAR.language.languages['app_list_strings']['stic_resources_types_list'];
var resourceTypes =
SUGAR.language.languages["app_list_strings"]["stic_resources_types_list"];
var filteredTypes = Object.keys(resourceTypes).filter(function (type) {
return isPlaceBooking ? type === "places" : type !== "places" && type !== "";
return isPlaceBooking
? type === "places"
: type !== "places" && type !== "";
});

var typeQuery = filteredTypes.map(function (type) {
return "&type_advanced[]=" + encodeURIComponent(type);
}).join("");

open_popup("stic_Resources", 600, 400, typeQuery, true, false, popupRequestData);

var typeQuery = filteredTypes
.map(function (type) {
return "&type_advanced[]=" + encodeURIComponent(type);
})
.join("");

open_popup(
"stic_Resources",
600,
400,
typeQuery,
true,
false,
popupRequestData
);
}

function callbackResourceSelectQS(ln) {
Expand Down Expand Up @@ -617,18 +639,6 @@ function loadResources() {
);
}

document
.getElementById("place_booking")
.addEventListener("change", function () {
if (this.checked) {
updateResourceFields();
$("#openCenterPopup").show();
} else {
$("#openCenterPopup").hide();
updateResourceFields();
}
});

$(document).ready(function () {
$("#resourceSearchFields").hide();
$("#openCenterPopup").hide();
Expand Down Expand Up @@ -754,25 +764,27 @@ function updateResourceLines(resources) {
});
}
function closeResource(resourceId, bookingId) {
if (confirm(SUGAR.language.get("stic_Bookings", "LBL_CLOSE_RESOURCE_CONFIRM"))) {
$.ajax({
url: "index.php?module=stic_Bookings&action=closeResource&sugar_body_only=true",
dataType: "json",
data: {
record_id: bookingId,
resource_id: resourceId
},
success: function(res) {
if (res.success) {
// Recargar la vista de detalle
window.location.reload();
} else {
alert(res.message);
}
},
error: function() {
alert("Error al cerrar el recurso");
}
});
if (
confirm(SUGAR.language.get("stic_Bookings", "LBL_CLOSE_RESOURCE_CONFIRM"))
) {
$.ajax({
url: "index.php?module=stic_Bookings&action=closeResource&sugar_body_only=true",
dataType: "json",
data: {
record_id: bookingId,
resource_id: resourceId,
},
success: function (res) {
if (res.success) {
// Recargar la vista de detalle
window.location.reload();
} else {
alert(res.message);
}
},
error: function () {
alert("Error al cerrar el recurso");
},
});
}
}
1 change: 1 addition & 0 deletions modules/stic_Bookings/views/view.edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function parseResourceItems($resourcesBeanArray)
$parsedResources = array();
foreach ($resourcesBeanArray as $resourceBean) {
$resource = array();
$resource['resource_id'] = $resourceBean->id;
foreach ($config_resource_fields as $field => $label) {
$value = $resourceBean->$field;
if ($field === 'status' || $field === 'type') {
Expand Down
Loading

0 comments on commit 3b9747c

Please sign in to comment.