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:
commit
9bca8f8300
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"/>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue