changeset 56:fc907b00604a

Cleanup javascript.
author Daniele Nicolodi <daniele@grinta.net>
date Sat, 13 Aug 2011 20:27:24 +0200
parents 018599af92f5
children 84c1573a3e97
files src/ltpdarepo/static/querywidget.js
diffstat 1 files changed, 17 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/ltpdarepo/static/querywidget.js	Sat Aug 13 20:27:24 2011 +0200
+++ b/src/ltpdarepo/static/querywidget.js	Sat Aug 13 20:27:24 2011 +0200
@@ -1,5 +1,5 @@
 ;(function($) {
-    
+
     // namespace
     if (typeof($.querywidget) == "undefined") {
       $.querywidget = {
@@ -32,9 +32,9 @@
     // create label
     $.querywidget.createQueryLabel = function (index) {
       var name = $.querywidget.config.indexes[index].name;
-      return $(document.createElement('span')).html(name).addClass('querywidget field'); 
+      return $(document.createElement('span')).html(name).addClass('querywidget field');
     };
-    
+
     // create field name
     $.querywidget.createQueryField = function (index) {
       var value = $.querywidget.config.indexes[index].val;
@@ -47,9 +47,7 @@
     // create operator select menu
     $.querywidget.createQueryOperator = function (index, value) {
       return $.querywidget.createSelect($.querywidget.config.indexes[index].operators,
-                                        value,
-                                        'querywidget operator',
-                                        'operator');
+                                        value, 'querywidget operator', 'operator');
     };
 
     // create value field
@@ -57,7 +55,8 @@
       var type = $.querywidget.config.indexes[index].type;
       switch (type) {
       case 'enum':
-        return $.querywidget.createSelect($.querywidget.config.indexes[index].values, '', 'value', 'value');
+        return $.querywidget.createSelect($.querywidget.config.indexes[index].values,
+                                          '', 'value', 'value');
         break;
       default:
         return $(document.createElement('input')).attr({
@@ -82,38 +81,35 @@
         // return nothing done
         return false;
       }
-      
+
       // set initialized
       $.querywidget.initialized = true;
 
       // configuration
       $.querywidget.config.indexes = criteria;
-      
+
       $('#add').live('change', function () {
           var index = $(this).find(':selected')[0].value;
-          var newcriteria = $(document.createElement('div')).addClass('criteria');
+          if (! index)
+            return false;
+          var newcriteria = $(document.createElement('div')).addClass('criteria wrapper');
           newcriteria.append($.querywidget.createQueryLabel(index));
           newcriteria.append($.querywidget.createQueryField(index));
           newcriteria.append($.querywidget.createQueryOperator(index,''));
           newcriteria.append($.querywidget.createWidget(index));
-          newcriteria.append(
-                             $(document.createElement('input'))
-                             .attr({
-                                 'value': '\u00D7',
-                                 'type': 'button',
-                                 'name': 'remove'})
-                             .addClass('querywidget remove')
-                             );
+          newcriteria.append($(document.createElement('input'))
+                             .attr({'value': '\u00D7', 'type': 'button', 'name': 'remove'})
+                             .addClass('querywidget remove'));
           $('#criteria').append(newcriteria);
           $(this).val('');
+          $(this).change();
         });
-      
+
       $('.remove').live('click', function () {
           $(this).parents('.criteria').remove();
           return false;
         });
-      
+
     };
 
   })(jQuery);
-