Solei
member
- Scor reacție
- 0
Salutare,
Va rog sa verificati si sa aprobati, daca considerati ca este conform regulilor interne, urmatorul script care ajuta la crearea de rute comerciale, adaugand un nou field pentru introducerea unui timp (ex: 3:30), reprezentand timpul care trebuie adaugat la timpul rutei create anterior, astfel incat facilitand crearea rapida de rute din satul X in Y din T in T timp.
Multumesc!
Scriptul se imparte in 2:
1) Partea care face ca field-ul nou sa apara in tabelul de creare a rutelor
2) Partea care aduna timpul trecut in noul field la timpul rutei create anterior
1)
2)
Va rog sa verificati si sa aprobati, daca considerati ca este conform regulilor interne, urmatorul script care ajuta la crearea de rute comerciale, adaugand un nou field pentru introducerea unui timp (ex: 3:30), reprezentand timpul care trebuie adaugat la timpul rutei create anterior, astfel incat facilitand crearea rapida de rute din satul X in Y din T in T timp.
Multumesc!
Scriptul se imparte in 2:
1) Partea care face ca field-ul nou sa apara in tabelul de creare a rutelor
2) Partea care aduna timpul trecut in noul field la timpul rutei create anterior
1)
JavaScript:
javascript:
function addNewRow() {
// Find the first table in the form
const table = document.querySelector('form[name="market"] table tbody');
// Create a new table row and cell
const newRow = document.createElement('tr');
const newCell = document.createElement('td');
newCell.colSpan = 2; // Span the cell across two columns
// Create the new input element
const input = document.createElement('input');
input.type = 'text';
input.name = 'interval_time';
input.placeholder = 'Din cat in cat?';
input.size = 7; // Adjust as needed
// Add event listener to restrict input
input.addEventListener('input', function (event) {
// Use a regular expression to allow only numbers and colon
this.value = this.value.replace(/[^0-9:]/g, '');
});
// Append the input to the new cell, and the cell to the row
newCell.appendChild(input);
newRow.appendChild(newCell);
// Append the new row to the table
table.appendChild(newRow);
}
// Function to set a cookie
function setCookie(name, value, days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
const expires = "expires=" + date.toUTCString();
console.log(name + "=" + value + ";" + expires + ";path=/");
document.cookie = name + "=" + value + ";" + expires + ";path=/";
}
// Event listener to save the interval time to cookies on form submission
document.querySelector('form[name="market"]').addEventListener('submit', function (event) {
const intervalInput = document.querySelector('input[name="interval_time"]');
if (intervalInput) {
setCookie('interval_time', intervalInput.value, 7); // Save cookie for 7 days
}
// Optionally prevent form submission if needed
// event.preventDefault();
});
// Call the function to add the new row
addNewRow();
void 0
2)
JavaScript:
javascript:
// Function to get a cookie value by name
function getCookie(name) {
const nameEQ = name + "=";
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca;
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
// Function to highlight the submit button
function highlightSubmitButton() {
const submitButton = document.querySelector('input[type="submit"].btn');
if (submitButton) {
submitButton.focus();
}
}
// Function to parse time in "hh:mm" format and convert it to minutes
function parseTimeToMinutes(time) {
const [hours, minutes] = time.split(':').map(Number);
return (hours * 60) + (minutes 0);
}
// Function to convert minutes back to "hh:mm" format, considering the 24-hour wrap-around
function convertMinutesToTime(minutes) {
const totalHours = Math.floor(minutes / 60);
const hours = totalHours % 24; // Wrap around at 24 hours
const mins = minutes % 60;
return `${hours}:${mins.toString().padStart(2, '0')}`;
}
// Function to add the interval time to the current time input
function addIntervalTime() {
const timeInput = document.querySelector('input[name="time"]');
const intervalTime = getCookie('interval_time');
if (timeInput && intervalTime) {
const currentTime = timeInput.value '0:0';
// Parse both current time and interval time to minutes
const currentMinutes = parseTimeToMinutes(currentTime);
const intervalMinutes = parseTimeToMinutes(intervalTime);
// Add them together and convert back to time format
const newTimeMinutes = currentMinutes + intervalMinutes;
const newTime = convertMinutesToTime(newTimeMinutes);
// Update the time input value
timeInput.value = newTime;
// Highlight the submit button
highlightSubmitButton();
}
}
addIntervalTime();
void 0
Ultima editare: