Merge pull request #5372 from expsa/fix/ui-readonly-logic-complete-20251112-053000

fix: Complete Readonly Logic for UI Buttons & Boolean Toggle
This commit is contained in:
Mohamed Eltayar 2025-11-12 04:27:29 +03:00 committed by GitHub
commit 9bca8f8300
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 12 deletions

View File

@ -77,7 +77,7 @@
'reports/transfer_deduction_report.xml',
'reports/transfer_deduction_report_templates.xml',
],
'icon': 'static/description/icon5.png',
'icon': 'static/description/icon.png',
# 'installable': True,
# 'application': True,
# 'auto_install': False,

View File

@ -206,37 +206,63 @@
_setupSimpleUI: function () {
var self = this;
var currentData = self.model.localData[self.handle].data;
// CRITICAL: Buttons are ONLY editable in 'draft' state
// Even if user clicks "Edit", buttons remain readonly if state != 'draft'
// CRITICAL: Buttons are editable ONLY if:
// 1. Form is in edit mode (self.mode === 'edit')
// 2. AND state is 'draft'
var isFormEdit = self.mode === 'edit';
var isDraftState = currentData.state === 'draft';
var isEditable = isFormEdit && isDraftState;
// Remove old event handlers to prevent duplicates
this.$('.record_option').off('click');
this.$('.mechanism_option').off('click');
// Disable buttons if NOT in draft state (regardless of form mode)
if (!isDraftState) {
// Maintain visual selection (selected class) but disable interaction
// Update selected state based on current values
var recordType = currentData.record_type;
var donationMechanism = currentData.donation_mechanism;
// Update visual selection for record_type
this.$('.record_option').each(function() {
var $opt = $(this);
if ($opt.data('value') === recordType) {
$opt.addClass('selected');
} else {
$opt.removeClass('selected');
}
});
// Update visual selection for donation_mechanism
this.$('.mechanism_option').each(function() {
var $opt = $(this);
if ($opt.data('value') === donationMechanism) {
$opt.addClass('selected');
} else {
$opt.removeClass('selected');
}
});
// Disable/Enable buttons based on edit state
if (!isEditable) {
// Disable buttons but KEEP their visual appearance (colors, selection)
this.$('.record_option').css({
'pointer-events': 'none',
'opacity': '0.6',
'cursor': 'not-allowed'
});
this.$('.mechanism_option').css({
'pointer-events': 'none',
'opacity': '0.6',
'cursor': 'not-allowed'
});
return; // Don't attach click handlers if not draft
return; // Don't attach click handlers
} else {
// Enable buttons ONLY in draft state
// Enable buttons in draft state AND edit mode
this.$('.record_option').css({
'pointer-events': 'auto',
'opacity': '1',
'cursor': 'pointer'
});
this.$('.mechanism_option').css({
'pointer-events': 'auto',
'opacity': '1',
'cursor': 'pointer'
});
}

View File

@ -218,7 +218,8 @@
<field name="has_delay" invisible="1"/>
<field name="members_domain_ids" invisible="1"/>
<field name="donate_for_another_person" widget="boolean_toggle"/>
<field name="donate_for_another_person" widget="boolean_toggle"
attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="sponsorship_creation_date" readonly="1"/>
<field name="create_uid" string="Sponsorship Creator" readonly="1"/>