QBE: Modifi UX pour état
authorPA Parent <paparent@paparent.me>
Tue, 26 Jun 2012 20:21:29 +0000 (16:21 -0400)
committerPA Parent <paparent@paparent.me>
Tue, 26 Jun 2012 20:21:29 +0000 (16:21 -0400)
src/qbe/django_qbe/forms.py
src/qbe/django_qbe/static/django_qbe/css/qbe.css
src/qbe/django_qbe/static/django_qbe/js/qbe.core.js
src/qbe/django_qbe/templates/qbe.html

index eb71e7a..6e60150 100644 (file)
@@ -44,10 +44,10 @@ STATUS_CHOICES = (
 class QueryByExampleForm(forms.Form):
     show = forms.BooleanField(label=_("Show"), required=False)
     model = forms.CharField(label=_("Model"))
-    status = forms.ChoiceField(label=_("Statut"), choices=STATUS_CHOICES,
-                             required=False)
     field = forms.CharField(label=_("Field"))
     criteria = forms.CharField(label=_("Criteria"), required=False)
+    status = forms.ChoiceField(label=_("Statut"), choices=STATUS_CHOICES,
+                             required=False)
     sort = forms.ChoiceField(label=_("Sort"), choices=SORT_CHOICES,
                              required=False)
 
@@ -69,6 +69,10 @@ class QueryByExampleForm(forms.Form):
             field_attr_class = "qbeFillFields enable:sort,%s" % criteria_names
         else:
             field_attr_class = "qbeFillFields enable:sort,criteria"
+        status_widget = forms.Select(attrs={'disabled': "disabled",
+                                          'class': 'hidden'},
+                                   choices=STATUS_CHOICES)
+        self.fields['status'].widget = status_widget
         field_widget = forms.Select(attrs={'class': field_attr_class})
         self.fields['field'].widget = field_widget
 
@@ -192,7 +196,10 @@ class BaseQueryByExampleFormSet(BaseFormSet):
             status = data["status"]
             db_field = u"%s.%s" % (qn(model), qn(field))
             operator, over = criteria
-            is_join = operator.lower() == 'join'
+            try:
+                is_join = operator.lower() == 'join'
+            except:
+                is_join = False
             if show and not is_join:
                 selects.append(db_field)
             if sort:
index 7564825..ad8fb80 100644 (file)
@@ -166,3 +166,7 @@ input.qbeCheckModels {
     overflow: auto;
     margin-top: 10px;
 }
+
+.qbeTabular .hidden {
+       display: none;
+}
index 5f230bb..7ef17f5 100644 (file)
@@ -199,7 +199,8 @@ qbe.Core = function() {};
                         optFields.push(option);
                     }
                 }
-                $("#"+ domTo).html('<option value="">*</option>' + optPrimaries.join("") + optForeigns.join("") + optManies.join("") + optFields.join(""));
+                optEtat = '<option value="status">État</option>'
+                $("#"+ domTo).html('<option value="">*</option>' + optPrimaries.join("") + optForeigns.join("") + optManies.join("") + optFields.join("") + optEtat);
                 // We need to raise change event
                 $("#"+ domTo).change();
             }
@@ -216,11 +217,32 @@ qbe.Core = function() {};
             css = $(this).attr("class");
             cssSplit = css.split("enable:")
             inputs = cssSplit[cssSplit.length-1].split(",");
+            if (field == 'status') {
+                $("#"+ prefix + "-sort").attr("disabled", "disabled");
+                $("#"+ prefix + "-sort").val("");
+                $("#"+ prefix + "-criteria").attr("disabled", "disabled");
+                $("#"+ prefix + "-criteria").val("");
+                $("#"+ prefix + "-criteria").addClass("hidden");
+                $("#"+ prefix + "-criteria_0").attr("disabled", "disabled");
+                $("#"+ prefix + "-criteria_0").val("");
+                $("#"+ prefix + "-criteria_0").addClass("hidden");
+                $("#"+ prefix + "-criteria_1").attr("disabled", "disabled");
+                $("#"+ prefix + "-criteria_1").val("");
+                $("#"+ prefix + "-criteria_1").addClass("hidden");
+                $("#"+ prefix + "-status").removeClass("hidden");
+                $("#"+ prefix + "-status").removeAttr("disabled");
+
+            }
+            else {
+                $("#"+ prefix + "-status").val("");
+                $("#"+ prefix + "-status").addClass("hidden");
+
             for(var i=0; i<inputs.length; i++) {
                 input = inputs[i];
                 domTo = prefix +"-"+ input;
                 if (field) {
                     $("#"+ domTo).removeAttr("disabled");
+                    $("#"+ domTo).removeClass("hidden");
                 } else {
                     $("#"+ domTo).attr("disabled", "disabled");
                     $("#"+ domTo).val("");
@@ -262,6 +284,7 @@ qbe.Core = function() {};
                     }
                 }
             }
+            }
         };
 
         /**
index eba78df..bb4763c 100644 (file)
@@ -47,7 +47,6 @@
             <tr>
                 <th>{% trans "Show" %}</th>
                 <th>{% trans "Model" %}</th>
-                <th>État</th>
                 <th>{% trans "Field" %}</th>
                 <th>{% trans "Sort" %}</th>
                 <th>{% trans "Criteria" %}</th>
             <tr class="{% cycle 'row1' 'row2' %}">
                 <td>{{ form.show.errors }}{{ form.show }}</td>
                 <td>{{ form.model.errors }}{{ form.model }}</td>
-                <td>{{ form.status.errors }}{{ form.status }}</td>
                 <td>{{ form.field.errors }}{{ form.field }}</td>
                 <td>{{ form.sort.errors }}{{ form.sort }}</td>
-                <td>{{ form.criteria.errors }}{{ form.criteria }}</td>
+                <td>{{ form.criteria.errors }}{{ form.criteria }}{{ form.status }}</td>
                 <td class="delete"></td>
             </tr>
         {% endfor %}