fix: Correct UI buttons logic - readonly in all states except draft

**Problem with previous PR #5369:**
The merged PR had WRONG logic that allowed buttons to become editable
when user clicks 'Edit' on confirmed/posted records.

**Previous WRONG Logic:**
```javascript
var isReadonly = currentData.state !== 'draft' || self.mode === 'readonly';
//  If mode='edit' AND state!='draft' → buttons become clickable!
```

**New CORRECT Logic:**
```javascript
var isDraftState = currentData.state === 'draft';
//  Buttons ONLY work if state='draft', regardless of form mode
```

**Key Change:**
-  OLD: Check both state AND mode → allows editing in non-draft states
-  NEW: Check ONLY state → readonly in ALL non-draft states

**User Requirement:**
الأزرار تكون للقراءة فقط في جميع الحالات ما عدا draft فقط،
حتى لو عملت تحرير للسجل.

**Behavior Now:**
- draft state → Buttons work 
- confirmed/posted + readonly mode → Buttons disabled 
- confirmed/posted + edit mode → Buttons REMAIN disabled  (FIXED!)

This is the correct implementation that meets the exact requirement.

Synced with latest dev_odex25_ensan on Wed Nov 12 03:58:56 +03 2025
This commit is contained in:
Mohamed Eltayar 2025-11-12 03:58:56 +03:00
parent ea823f2806
commit 4acf2a72c0
1 changed files with 7 additions and 5 deletions

View File

@ -206,14 +206,16 @@
_setupSimpleUI: function () {
var self = this;
var currentData = self.model.localData[self.handle].data;
var isReadonly = currentData.state !== 'draft' || self.mode === 'readonly';
// CRITICAL: Buttons are ONLY editable in 'draft' state
// Even if user clicks "Edit", buttons remain readonly if state != 'draft'
var isDraftState = currentData.state === 'draft';
// Remove old event handlers to prevent duplicates
this.$('.record_option').off('click');
this.$('.mechanism_option').off('click');
// Disable buttons if readonly
if (isReadonly) {
// Disable buttons if NOT in draft state (regardless of form mode)
if (!isDraftState) {
this.$('.record_option').css({
'pointer-events': 'none',
'opacity': '0.6',
@ -224,9 +226,9 @@
'opacity': '0.6',
'cursor': 'not-allowed'
});
return; // Don't attach click handlers if readonly
return; // Don't attach click handlers if not draft
} else {
// Re-enable buttons if not readonly
// Enable buttons ONLY in draft state
this.$('.record_option').css({
'pointer-events': 'auto',
'opacity': '1',