Index: 0.11/condfields/templates/condfields.js
===================================================================
--- 0.11/condfields/templates/condfields.js	(revision 13373)
+++ 0.11/condfields/templates/condfields.js	(working copy)
@@ -4,111 +4,149 @@
 
 jQuery(document).ready(function ($) {
   var mode = '$condfields.mode';
-  var all_fields = [];
-  $('#properties tbody').find('label[for]').each(function (i, e) {
-    var field = e.getAttribute('for') ? e.getAttribute('for').substr(6) : e.getAttribute('htmlFor').substr(6);
-    all_fields.push(field)
-  });
+  var all_fields = {};
   var field_data = {};
-  for (var i = 0; i < all_fields.length; i++) {
-    var field = all_fields[i];
-    field_data[field] = {
-      label: $('label[for="field-' + field + '"]').parents('th'),
-      input: $('#field-' + field).parents('td')
+  if (typeof field_groups != 'undefined') {
+    var isMain = false;
+    for (var k = 0; k < field_groups.length; k++) {
+      if (field_groups[k]["name"] == "main") isMain = true;
     }
+    if (!isMain) field_groups.push({name: "main"});
+  } else {
+    field_groups = [];
+    field_groups.push({name: "main"});
   }
-  //console.info(field_data);
-  //console.info(mode);
+  for (var l = 0; l < field_groups.length; l++) {
+    var group = field_groups[l];
+    var fieldset_id = 'properties';
+    if (group["name"] != "main") {
+      fieldset_id = fieldset_id + "_" + group["name"];
+    }
+    all_fields[fieldset_id] = [];
+    $('#'+fieldset_id+' tbody').find('label[for]').each(function (i, e) {
+      var field = e.getAttribute('for') ? e.getAttribute('for').substr(6) : e.getAttribute('htmlFor').substr(6);
+      all_fields[fieldset_id].push(field)
 
-  function set_type(t) {
+      field_data[fieldset_id] = {};
 
-    var condfields_fragement = $("<div/>");
-    $('#properties tbody tr').each(function (i, e) {
-      var lf = $(this).find("label[for]").attr('for');
-      if (lf && lf.length > 6 && required_fields.join(' ').indexOf(lf.substr(6)) == -1) {
-        $(this).appendTo(condfields_fragement);
+      for (var i = 0; i < all_fields[fieldset_id].length; i++) {
+        var field = all_fields[fieldset_id][i];
+        field_data[fieldset_id][field] = {
+          label: $('label[for="field-' + field + '"]').parents('th'),
+          input: $('#field-' + field).parents('td')
+        }
       }
-    })
+      //console.info(mode);
+    });
+  }
+  //console.info(field_data)
+  //console.info(all_fields)
 
-    var col = 1;
-    var rows = [];
-    for (var i = 0; i < all_fields.length; i++) {
-      var field = all_fields[i];
-      if (!field_data[field] || field_data[field].label == null) continue;
-      if (mode == 'view' && field == 'owner') continue;
-      if (required_fields.join(' ').indexOf(field) != -1 || condfields[t][field] == 0) continue;
+  function set_type(t) {
+    for (var l = 0; l < field_groups.length; l++) {
+      var group = field_groups[l];
+      var fieldset_id = 'properties';
+      if (group["name"] != "main") {
+        fieldset_id = fieldset_id + "_" + group["name"];
+      }
+      
+      var condfields_fragement = $("<div/>");
+      $('#'+fieldset_id+' tbody tr').each(function (i, e) {
+        var lf = $(this).find("label[for]").attr('for');
+        if (lf && lf.length > 6 && required_fields.join(' ').indexOf(lf.substr(6)) == -1) {
+          $(this).appendTo(condfields_fragement);
+        }
+      })
 
-      full_row = field_types[field] == 'textarea'
-
-      if (col == 1 || full_row) {
-        var tr = $("<tr/>");
-        field_data[field].label.removeClass("col2");
-        field_data[field].label.addClass("col1");
-        tr.append(field_data[field].label);
-        field_data[field].input.removeClass("col2");
-        field_data[field].input.addClass("col1");
-        tr.append(field_data[field].input);
-        rows.push(tr);
-        col = 2;
-      } else {
+      var col = 1;
+      var rows = [];
+      var maxcol = 2;
+      if (group['columns']) {
+        maxcol = group['columns'];
+      }
+      for (var i = 0; i < all_fields[fieldset_id].length; i++) {
+        var field = all_fields[fieldset_id][i];
+        if (!field_data[fieldset_id][field] || field_data[fieldset_id][field].label == null) continue;
+        if (mode == 'view' && field == 'owner') continue;
+        if (required_fields.join(' ').indexOf(field) == -1 && condfields[t][field] == 0) continue;
+        
+        full_row = field_types[field] == 'textarea'
+        if (col == 1 || full_row) {
+          var tr = $("<tr/>");
+          field_data[fieldset_id][field].label.removeClass("col2");
+          field_data[fieldset_id][field].label.addClass("col1");
+          tr.append(field_data[fieldset_id][field].label);
+          field_data[fieldset_id][field].input.removeClass("col2");
+          field_data[fieldset_id][field].input.addClass("col1");
+          tr.append(field_data[fieldset_id][field].input);
+          rows.push(tr);
+          if (maxcol == 2) col = 2; 
+        } else {
+          tr = rows[rows.length - 1];
+          field_data[fieldset_id][field].label.removeClass("col1");
+          field_data[fieldset_id][field].label.addClass("col2");
+          tr.append(field_data[fieldset_id][field].label);
+          field_data[fieldset_id][field].input.removeClass("col1");
+          field_data[fieldset_id][field].input.addClass("col2");
+          tr.append(field_data[fieldset_id][field].input);
+          col = 1;
+        }
+        
+        if (full_row) col = 1;
+      }
+      
+      if (col == 2) {
         tr = rows[rows.length - 1];
-        field_data[field].label.removeClass("col1");
-        field_data[field].label.addClass("col2");
-        tr.append(field_data[field].label);
-        field_data[field].input.removeClass("col1");
-        field_data[field].input.addClass("col2");
-        tr.append(field_data[field].input);
-        col = 1;
+        tr.append('<th class="col2"/><td class="col2"/>');
       }
-
-      if (full_row) {
-        col = 1
+      for (var i = 0; i < rows.length; i++) {
+        $('#'+fieldset_id+' tbody').append(rows[i]);
       }
     }
-
-    if (col == 2) {
-      tr = rows[rows.length - 1];
-      tr.append('<th class="col2"/><td class="col2"/>');
-    }
-    for (var i = 0; i < rows.length; i++) {
-      $('#properties tbody').append(rows[i]);
-    }
   }
 
   function set_header_type(t) {
-    var elms = [
-      []
-    ];
-    $('table.properties tr').each(function () {
-      $(this).children().each(function () {
-        var attr = {TH: 'id', TD: 'headers'}[this.nodeName];
-        if ($(this).attr(attr) != null && condfields[t][$(this).attr(attr).substring(2)] == 1) {
-          elms[0].push(this);
-          if (elms[0].length == 4) {
-            var tmp = $('<tr></tr>');
-            $.each(elms[0], function (i, e) {
-              tmp.append(e);
-            });
-            elms[0] = tmp;
-            elms.unshift([]);
+   for (var l = 0; l < field_groups.length; l++) {
+     var group = field_groups[l];
+     var fieldset_id = 'properties';
+     if (group["name"] != "main") {
+       fieldset_id = fieldset_id + "_" + group["name"];
+     }
+                                     
+      var elms = [
+        []
+      ];
+      $('table.'+fieldset_id+' tr').each(function () {
+        $(this).children().each(function () {
+          var attr = {TH: 'id', TD: 'headers'}[this.nodeName];
+          if ($(this).attr(attr) != null && condfields[t][$(this).attr(attr).substring(2)] == 1) {
+            elms[0].push(this);
+            if (elms[0].length == 4) {
+              var tmp = $('<tr></tr>');
+              $.each(elms[0], function (i, e) {
+                tmp.append(e);
+              });
+              elms[0] = tmp;
+              elms.unshift([]);
+            }
           }
+          });
+      });
+      if (elms[0].length == 0) {
+        elms.shift();
+      } else {
+        var tmp = $('<tr></tr>');
+        $.each(elms[0], function (i, e) {
+          tmp.append(e);
+        });
+        elms[0] = tmp;
         }
+      elms.reverse();
+      $('table.'+fieldset_id).empty();
+      $.each(elms, function (i, row) {
+        $('table.'+fieldset_id).append(row);
       });
-    });
-    if (elms[0].length == 0) {
-      elms.shift();
-    } else {
-      var tmp = $('<tr></tr>');
-      $.each(elms[0], function (i, e) {
-        tmp.append(e);
-      });
-      elms[0] = tmp;
     }
-    elms.reverse();
-    $('table.properties').empty();
-    $.each(elms, function (i, row) {
-      $('table.properties').append(row);
-    });
   }
 
   if (mode == 'view') {
