// Removed the following validate function because it's making asynchronous calls within a validate event,
// which can lead to inconsistent data. It's better to handle this logic in a different way or at a different time.
/frappe.ui.form.on("Rent", "validate", function(frm, cdt, cdn) {
$.each(frm.doc.time_logs || [], function(i, d) {
frappe.call({
'method': 'frappe.client.get_value',
'args': {
'doctype': 'Bin',
'fieldname': 'actual_qty',
'filters': {
'item_code': d.item_code,
"warehouse": cur_frm.doc.source_warehouse
}
},
callback: function(r) {
d.actual_qty = r.message.actual_qty;
}
});
});
});/
// Modified the following 'item_code' event to correctly update the rate field in the 'Rent Detail' table.
frappe.ui.form.on("Rent Detail", "item_code", function(frm, cdt, cdn) {
const row = locals[cdt][cdn]; // Get current row
const priceList = cur_frm.doc.rent_type == "Daily" ? "Daily" : "Monthly";
Assistant
User
اريد ان تكون تنسيقات البطائق تتناسب مع جديع مقاسات الشاشات
Assistant
لتكون تنسيقات البطائق (cards) تتناسب مع جميع مقاسات الشاشات وتوفر تجربة مستخدم أفضل، يمكنك استخدام تقنية تصميم استجابة (Responsive Design). باستخدام CSS وخصائص الوسائط (media queries)، يمكنك تحسين عرض بطاقاتك بناءً على حجم الشاشة.
User
اعد كتابة الكود كاملاً
Assistant
code
if (row.item_code) {
frappe.call({
'method': 'frappe.client.get_value',
'args': {
'doctype': 'Item Price',
'fieldname': 'price_list_rate',
'filters': {
'item_code': row.item_code,
"price_list": priceList
}
},
callback: function(r) {
if (r.message) {
frappe.model.set_value(cdt, cdn, 'rate', r.message.price_list_rate); // Set the rate
frappe.model.set_value(cdt, cdn, 'amount', r.message.price_list_rate * row.qty); // Calculate and set amount
} else {
frappe.model.set_value(cdt, cdn, 'rate', 0); // Set rate to 0 if no price found
frappe.model.set_value(cdt, cdn, 'amount', 0); // Set amount to 0 if no price found
}
cur_frm.refresh_field('time_logs');
}
});
}
});
//----------------------------------------------------------------------------------
// سلايدر مجموعات الأصناف
//----------------------------------------------------------------------------------
function initialize_slider(frm) {
let html_field = frm.get_field('item_group_html');
if (!html_field || html_field.slider_initialized) return;
if (item_details) {
frappe.call({
method: 'frappe.client.get_value',
args: {
doctype: 'Item Price',
filters: {
item_code: item_details.name,
price_list: priceList
},
fieldname: 'price_list_rate'
},
callback: function(price_response) {
const price = price_response.message ? price_response.message.price_list_rate : 0;
let item_found = false;
let row_name = null;
// Search for existing item in the table and store the row name if found
for (let i = 0; i < frm.doc.time_logs.length; i++) { // Use a for loop for better control
const log = frm.doc.time_logs[i];
if (log.item_code === item_details.name) {
item_found = true;
row_name = log.name;
break; // Exit loop once found
}
}
if (item_found && row_name) {
// Get the existing row by name to update it
const current_qty = frappe.model.get_value('Rent Detail', row_name, 'qty');
const new_qty = current_qty + 1;
frappe.model.set_value(
'Rent Detail', row_name, 'qty', new_qty
);
frappe.model.set_value(
'Rent Detail', row_name, 'amount', new_qty * price
);
} else {
// Add a new row if the item is not found
const new_row = frm.add_child('time_logs');
new_row.item_code = item_details.name;
new_row.item_name = item_details.item_name;
new_row.rate = price;
new_row.qty = 1;
new_row.amount = new_row.qty * new_row.rate;
}
// Refresh the field to show updated data
frm.refresh_field('time_logs');
// Save the form
frm.save_or_update().then(() => {
frappe.msgprint(__('تم حفظ التغييرات بنجاح.'));
}).catch(err => {
frappe.msgprint(__('حدث خطأ أثناء حفظ التغييرات.'));
});
},
error: function(err) {
console.error("Error fetching item price: ", err);
frappe.msgprint(__('Could not fetch item price.'));
}
});
} else {
frappe.msgprint(__('Item not found or invalid item code.'));
}
},
error: function(err) {
console.error("Error fetching item details: ", err);
frappe.msgprint(__('Could not fetch item details.'));
}
});
}
It looks like you have a fairly complex JavaScript code snippet intended for managing a "Rent" form in a Frappe framework application. This code handles a variety of tasks including:
Initializing a Slider for item groups and individual items using Swiper.js.
Loading Items based on a selected item group.
Managing Events such as button clicks and updates to item detail rates dynamically.
Handling Form Validation to ensure that certain fields are correctly populated.
Saving Form Data and providing user feedback.
Suggested Modifications
You mentioned that you want to remove the buttons inside the cards and replace them with image clicks. To do this effectively, we can remove the button elements and ensure all the interactions can be handled via clicking on the images. Here's the revised part of your code focusing on creating image-based interactions:
Adjust the Card HTML: Remove unnecessary button elements and ensure all interaction is image-based.
Update Image Click Handlers: Ensure the images trigger the same actions that were previously assigned to buttons.
Here's how you would modify the relevant sections of your code:
Example Suggested Code Changes
In the function that loads the item groups and items, you can modify it like this:
Adjusting the Slider for Item Groups
Replace this part in the load_item_group function:
const slide = `
<div class="swiper-slide">
<div class="card">
<img src="${image_src}" class="card-img-top fixed-image select_item_group_image" data-item_group="${ig.name}" alt="${ig.name}" style="width: 100%; object-fit: contain; cursor: pointer;">
<div class="card-body">
<h5 class="card-title">${ig.name}</h5>
<!-- No button, only the image is clickable -->
</div>
</div>
</div>
`;
Similarly, Adjust for Items
Modify the part of the code inside load_items function like this:
javascript
const slide = `
<div class="swiper-slide">
<div class="card">
<img src="${item.image || '/assets/your_app/images/default.png'}" class="card-img-top fixed-image select_item_image" data-item_code="${item.name}" alt="${item.item_name}" style="width: 100%; object-fit: contain; cursor: pointer;">
<div class="card-body">
<h5 class="card-title">${item.item_name}</h5>
<!-- No button, only the image is clickable -->
</div>
</div>
</div>
`;
Conclusion
Once you've made these changes, the entire interaction for selecting an item group or item can be done by merely clicking the respective images. This simplifies the user experience as it streamlines the selection process without the need for additional buttons.
Make sure to test the changes to ensure that everything behaves as expected. If you encounter issues or need further assistance, feel free to reach out!
فيما يلي بعض التعديلات والنصائح لتسهيل تحقيق ذلك:
1. استخدام Flexbox أو Grid
استخدم Flexbox أو CSS Grid لتنسيق بطاقاتك بمرونة.
2. تعديل CSS
هنا بعض التعديلات التي يمكنك إضافتها إلى أكواد CSS الخاصة بك لضمان استجابة البطائق:
css
.card {
width: 100%; /* عرض البطاقة يتناسب مع حجم العنصر الأب */
max-width: 200px; /* الحد الأقصى للعرض */
height: auto; /* ارتفاع تلقائي */
margin: 10px; /* إضافة بعض الهامش */
border: 1px solid #E0E0E0;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
transition: transform 0.2s, box-shadow 0.2s;
flex: 1 1 auto; /* أهمية استخدام Flexbox */
}
.swiper-container {
display: flex; /* استخدم Flexbox للتنسيق */
justify-content: center; /* محاذاة للعناصر داخل الحاوية */
flex-wrap: wrap; /* تجميع العناصر في صفوف متعددة */
}
.card img.fixed-image {
width: 100%; /* صورة تتناسب مع عرض البطاقة */
height: 150px; /* ارتفاع ثابت للصور */
object-fit: contain; /* اجعل الصورة تتناسب مع المساحة */
}
3. إعدادات Media Queries
قم بإضافة استعلامات وسائط (media queries) لتحسين التصميم بناءً على الأحجام المختلفة للشاشات. إليك بعض الأمثلة:
css
@media (max-width: 1200px) {
.swiper-slide {
flex: 0 0 30%; /* استخدم 30% من عرض الحاوية للبطاقات */
margin: 10px; /* أضف مسافة بين البطائق */
}
}
@media (max-width: 992px) {
.swiper-slide {
flex: 0 0 45%; /* استخدم 45% من عرض الحاوية للبطاقات */
}
}
@media (max-width: 768px) {
.swiper-slide {
flex: 0 0 100%; /* البطاقة تأخذ عرض كامل */
margin-bottom: 15px; /* أضف مسافة تحت كل بطاقة */
}
}
4. التعامل مع إعدادات صورة البطاقة
لضمان تناسب الصور مع المحتوى، استخدم object-fit لضبطها بشكل صحيح. يمكن استخدام القيم مثل contain و cover.
5. شيفرة بطاقات ديناميكية
تأكد من أن شيفرة JavaScript الخاصة بك تتناسب مع التغييرات المتعلقة بتنسيق CSS الخاصة بالبطاقات.
في النهاية
باستخدام هذه الأنماط، ستتحسن تجربة المستخدم عبر جميع الأحجام المختلفة للشاشات. تأكد من اختبار التصميم على أجهزة متعددة لضمان توافق جميع العناصر.
إذا كنت بحاجة إلى المزيد من المساعدة أو التعديلات، فلا تتردد في السؤال!
بالطبع! سأقوم بإعادة كتابة الكود بشكل كامل مع التركيز على تحسين التنسيق لاستجابة البطائق عبر مختلف مقاسات الشاشات، بالإضافة إلى استخدام CSS Grid أو Flexbox. إليك الشيفرة الكاملة بعد إدخال تلك التعديلات: