From dd0bce2b3f6bdd732f71d4b44bfda48c7cd2b1d8 Mon Sep 17 00:00:00 2001
From: Nicolas Dumazet <nicolas.dumazet@nexedi.com>
Date: Wed, 9 Jun 2010 06:53:44 +0000
Subject: [PATCH] if field is a checkbox, do not allow click on it while its
 readonly

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36120 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/dtml/proxyFieldEdit.dtml  | 16 ++++++++++++++--
 product/ERP5Form/dtml/proxyFieldTales.dtml | 16 ++++++++++++++--
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/product/ERP5Form/dtml/proxyFieldEdit.dtml b/product/ERP5Form/dtml/proxyFieldEdit.dtml
index 9c9e015b36..9f1b5680bd 100644
--- a/product/ERP5Form/dtml/proxyFieldEdit.dtml
+++ b/product/ERP5Form/dtml/proxyFieldEdit.dtml
@@ -155,13 +155,19 @@ function GetElementsWithClassName(elementName,className) {
         }
         return elemColl;
 }
+function normalEvent() { return true; }
+function ignoreEvent() { return false; }
+
 var class_deletaged_list = GetElementsWithClassName('td','delegated');
 for(var i=0; i<class_deletaged_list.length; i++) {
   element = class_deletaged_list[i].childNodes[1];
   if (element.type == 'hidden'){
-    element = class_deletaged_list[i].childNodes[2];
+    element = element.nextSibling;
   }
   element.readOnly = true;
+  if (element.type == 'checkbox'){
+    element.onclick = ignoreEvent;
+  }
 }
 
 function toggleFieldState(evt) {
@@ -173,13 +179,19 @@ function toggleFieldState(evt) {
     if (isClass(allElements[i], 'to_disable')) {
       field = allElements[i].childNodes[1];
       if (field.type == 'hidden'){
-        field = allElements[i].childNodes[2];
+        field = field.nextSibling;
       }
       if (field.readOnly){
         field.readOnly = false;
+        if (field.type == 'checkbox'){
+          field.onclick = normalEvent;
+        }
       }
       else{
         field.readOnly = true;
+        if (field.type == 'checkbox'){
+          field.onclick = ignoreEvent;
+        }
       }
     }
   }
diff --git a/product/ERP5Form/dtml/proxyFieldTales.dtml b/product/ERP5Form/dtml/proxyFieldTales.dtml
index 4577725f4c..63d443c24e 100644
--- a/product/ERP5Form/dtml/proxyFieldTales.dtml
+++ b/product/ERP5Form/dtml/proxyFieldTales.dtml
@@ -155,13 +155,19 @@ function GetElementsWithClassName(elementName,className) {
         }
         return elemColl;
 }
+function normalEvent() { return true; }
+function ignoreEvent() { return false; }
+
 var class_deletaged_list = GetElementsWithClassName('td','delegated');
 for(var i=0; i<class_deletaged_list.length; i++) {
   element = class_deletaged_list[i].childNodes[1];
   if (element.type == 'hidden'){
-    element = class_deletaged_list[i].childNodes[2];
+    element = element.nextSibling;
   }
   element.readOnly = true;
+  if (element.type == 'checkbox'){
+    element.onclick = ignoreEvent;
+  }
 }
 
 function toggleFieldState(evt) {
@@ -173,13 +179,19 @@ function toggleFieldState(evt) {
     if (isClass(allElements[i], 'to_disable')) {
       field = allElements[i].childNodes[1];
       if (field.type == 'hidden'){
-        field = allElements[i].childNodes[2];
+        field = field.nextSibling;
       }
       if (field.readOnly){
         field.readOnly = false;
+        if (field.type == 'checkbox'){
+          field.onclick = normalEvent;
+        }
       }
       else{
         field.readOnly = true;
+        if (field.type == 'checkbox'){
+          field.onclick = ignoreEvent;
+        }
       }
     }
   }
-- 
2.30.9