Author: jablko
Date: Mon Oct 18 10:26:53 2010
New Revision: 8228

Log:
Indentation

Modified:
   trunk/js/dialog.js

Modified: trunk/js/dialog.js
==============================================================================
--- trunk/js/dialog.js  Mon Oct 18 10:04:16 2010        (r8227)
+++ trunk/js/dialog.js  Mon Oct 18 10:26:53 2010        (r8228)
@@ -1,7 +1,7 @@
 // $Id$
 
 /**
- * Extra String methods
+ * Extra string methods
  */
 
 String.prototype.replaceAll = function (sFind, sReplace)
@@ -17,7 +17,7 @@
 }
 
 /**
- * Define Qubit Dialog classes
+ * Define Qubit dialog classes
  */
 
 // Build object for holding dialog data
@@ -52,31 +52,32 @@
 
   // Build an internal representation of HTML table elements
   $(':input', thisDialog.table).each(function ()
-  {
-    if ('' == this.name || undefined != thisDialog.fields[this.name])
     {
-      return;
-    }
+      if ('' == this.name || undefined != thisDialog.fields[this.name])
+      {
+        return;
+      }
 
-    // Store initialValue of element
-    switch (this.type)
-    {
-      case 'radio':
-      case 'checkbox':
-        var input = $('input[name='+this.name+']', thisDialog.table);
-        thisDialog.fields[this.name] = new Array();
-        input.each(function () {
-          thisDialog.fields[this.name].push(this);
-        });
+      // Store initialValue of element
+      switch (this.type)
+      {
+        case 'radio':
+        case 'checkbox':
+          var input = $('input[name=' + this.name + ']', thisDialog.table);
+          thisDialog.fields[this.name] = new Array();
+          input.each(function ()
+            {
+              thisDialog.fields[this.name].push(this);
+            });
 
-        thisDialog.initialValues[this.name] = input.filter(':checked').val();
-        break;
+          thisDialog.initialValues[this.name] = input.filter(':checked').val();
+          break;
 
-      default:
-        thisDialog.fields[this.name] = this;
-        thisDialog.initialValues[this.name] = this.value;
-    }
-  } );
+        default:
+          thisDialog.fields[this.name] = this;
+          thisDialog.initialValues[this.name] = this.value;
+      }
+    });
 
   // Create YUI container for dialog
   var $yuiDialogWrapper = $('<div class="yui-skin-sam">'
@@ -91,10 +92,11 @@
 
   // Bind onClick event to "Add" link
   var addLink = $('<a href="#">Add new</a>');
-  addLink.click(function () {
-    thisDialog.open();
-    return false; // Prevent default action: "go to top of page"
-  });
+  addLink.click(function ()
+    {
+      thisDialog.open();
+      return false; // Prevent default action: "go to top of page"
+    });
 
   // Replace dialog table with "Add" link and move into dialog wrapper
   $(this.table)
@@ -122,18 +124,19 @@
   $('body').prepend($yuiDialogWrapper);
 
   // Submit dialog data
-  var handleYuiSubmit = function () {
-    this.hide(); // Hide dialog
-    thisDialog.submit(this.getData()); // Save dialog data
-  };
-
-  var handleYuiCancel = function () {
-    this.cancel(); // Cancel yui submit
-    thisDialog.clear(); // Clear dialog fields
-  };
+  var handleYuiSubmit = function ()
+    {
+      this.hide(); // Hide dialog
+      thisDialog.submit(this.getData()); // Save dialog data
+    };
 
-  this.yuiDialog = new YAHOO.widget.Dialog(this.table.id,
-  {
+  var handleYuiCancel = function ()
+    {
+      this.cancel(); // Cancel YUI submit
+      thisDialog.clear(); // Clear dialog fields
+    };
+
+  this.yuiDialog = new YAHOO.widget.Dialog(this.table.id, {
     width: '480px',
     zIndex: '100',
     fixedcenter: true,
@@ -142,20 +145,21 @@
     modal: true,
     constraintoviewport: true,
     postmethod: 'none',
-    buttons: [ { text: 'Submit', handler: handleYuiSubmit, isDefault: true },
-                { text: 'Cancel', handler: handleYuiCancel } ],
-    effect: { effect: YAHOO.widget.ContainerEffect.FADE, duration: 0.25 }
-  } );
-
-  var keyListener_Esc = new YAHOO.util.KeyListener(document, { keys: 27 },
-                            { fn: handleYuiCancel,
-                              scope: this.yuiDialog,
-                              correctScope: true });
-
-  var keyListener_Enter = new YAHOO.util.KeyListener(document, { keys: 13 },
-                            { fn: handleYuiSubmit,
-                              scope: this.yuiDialog,
-                              correctScope: true });
+    buttons: [{ text: 'Submit', handler: handleYuiSubmit, isDefault: true },
+      { text: 'Cancel', handler: handleYuiCancel }],
+    effect: {
+      effect: YAHOO.widget.ContainerEffect.FADE,
+      duration: 0.25 } });
+
+  var keyListener_Esc = new YAHOO.util.KeyListener(document, { keys: 27 }, {
+    fn: handleYuiCancel,
+    scope: this.yuiDialog,
+    correctScope: true });
+
+  var keyListener_Enter = new YAHOO.util.KeyListener(document, { keys: 13 }, {
+    fn: handleYuiSubmit,
+    scope: this.yuiDialog,
+    correctScope: true });
 
   this.yuiDialog.cfg.queueProperty('keylisteners', keyListener_Enter.enable());
   this.yuiDialog.cfg.queueProperty('keylisteners', keyListener_Esc.enable());
@@ -194,64 +198,61 @@
 
   // Wait for all iframes to finish before submitting main form
   this.done = function ()
-  {
-    // Decrement count of listeners and submit if all done
-    if (1 > --this.count)
     {
-      $(thisDialog.form)
+      // Decrement count of listeners and submit if all done
+      if (1 > --this.count)
+      {
+        $(thisDialog.form)
 
-        // Unbind submit listeners to avoid triggering again
-        .unbind('submit', this.onSubmit)
+          // Unbind submit listeners to avoid triggering again
+          .unbind('submit', this.onSubmit)
 
-        .submit();
+          .submit();
+      }
     }
-  }
 
   /*
    * Methods
    */
   this.renderField = function (fname)
-  {
-    if ($(this.fields[fname]).next().hasClass('form-autocomplete'))
-    {
-      // Autocomplete text
-      return $(this.fields[fname]).next().val();
-    }
-    else if ('select-one' == this.fields[fname].type || 'select-multi' == 
this.fields[fname].type)
-    {
-      // Select box text
-      return $(this.fields[fname]).children(':selected').text();
-    }
-    else if ('radio' == this.fields[fname].type)
-    {
-      return $('input[name=' + fname + ']:checked', thisDialog.table).val();
-    }
-    else if (undefined != this.fields[fname].value)
-    {
-      return this.fields[fname].value;
-    }
-    else
     {
+      if ($(this.fields[fname]).next().hasClass('form-autocomplete'))
+      {
+        // Autocomplete text
+        return $(this.fields[fname]).next().val();
+      }
+      else if ('select-one' == this.fields[fname].type || 'select-multi' == 
this.fields[fname].type)
+      {
+        // Select box text
+        return $(this.fields[fname]).children(':selected').text();
+      }
+      else if ('radio' == this.fields[fname].type)
+      {
+        return $('input[name=' + fname + ']:checked', thisDialog.table).val();
+      }
+      else if (undefined != this.fields[fname].value)
+      {
+        return this.fields[fname].value;
+      }
+
       return '';
     }
-  }
 
   /**
    * Helper to get a field that has a prefix (e.g. formname[myField]) without
    * specifying the prefix name
    */
   this.getField = function (fname)
-  {
-    if (null != this.fieldPrefix && null == fname.match(this.fieldNameFilter))
-    {
-      var fullname = this.fieldPrefix + '[' + fname + ']';
-      return this.fields[fullname];
-    }
-    else
     {
+      if (null != this.fieldPrefix && null == 
fname.match(this.fieldNameFilter))
+      {
+        var fullname = this.fieldPrefix + '[' + fname + ']';
+
+        return this.fields[fullname];
+      }
+
       return this.fields[fname];
     }
-  }
 
   this.open = function ()
   {
@@ -273,384 +274,389 @@
     }
     else
     {
-      this.loadData(this.id, function () {
-        thisDialog.yuiDialog.show();
-      });
+      this.loadData(this.id, function ()
+        {
+          thisDialog.yuiDialog.show();
+        });
     }
   }
 
   this.loadData = function ()
-  {
-    if (undefined == arguments[0])
-    {
-      return this;
-    }
-    else
     {
+      if (undefined == arguments[0])
+      {
+        return this;
+      }
+
       var id = arguments[0];
-    }
 
-    if (1 < arguments.length)
-    {
-      var callback = arguments[1];
-    }
+      if (1 < arguments.length)
+      {
+        var callback = arguments[1];
+      }
 
-    if (undefined != this.data[id])
-    {
-      this.updateDialog(id, this.data[id], callback)
-    }
-    else
-    {
-      // TODO Ajax call to get relation data from database
-      var dataSource = new YAHOO.util.XHRDataSource(id);
-      dataSource.responseType = YAHOO.util.DataSourceBase.TYPE_JSON;
-      dataSource.parseJSONData = function (request, response)
+      if (undefined != this.data[id])
       {
-        if (undefined != thisDialog.options.relationTableMap)
-        {
-          return { results: [ thisDialog.options.relationTableMap(response) ]};
-        }
-        else
+        this.updateDialog(id, this.data[id], callback)
+      }
+      else
+      {
+        // TODO Ajax call to get relation data from database
+        var dataSource = new YAHOO.util.XHRDataSource(id);
+        dataSource.responseType = YAHOO.util.DataSourceBase.TYPE_JSON;
+        dataSource.parseJSONData = function (request, response)
         {
-          var dataMap = function (response) {
-            for (name in response)
-            {
-              this[thisDialog.fieldPrefix + '[' + name + ']'] = response[name];
-            }
+          if (undefined != thisDialog.options.relationTableMap)
+          {
+            return { results: [thisDialog.options.relationTableMap(response)] 
};
           }
+          else
+          {
+            var dataMap = function (response)
+              {
+                for (name in response)
+                {
+                  this[thisDialog.fieldPrefix + '[' + name + ']'] = 
response[name];
+                }
+              }
 
-          return { results: [ new dataMap(response) ] };
+            return { results: [new dataMap(response)] };
+          }
         }
-      }
 
-      dataSource.sendRequest(null, function (req, res)
-      {
-        success: thisDialog.updateDialog(id, res.results[0], callback);
-        failure: null;
-      });
+        dataSource.sendRequest(null, function (req, res)
+          {
+            success: thisDialog.updateDialog(id, res.results[0], callback);
+            failure: null;
+          });
+      }
     }
-  }
 
   this.updateDialog = function ()
-  {
-    var thisId = arguments[0];
-    var thisData = arguments[1];
-    var callback = arguments[2];
-
-    if (undefined == this.data[thisId])
-    {
-      this.data[thisId] = thisData;
-    }
-
-    for (fieldname in this.fields)
     {
-      // Set dialog field
-      var thisTable = this.table;
+      var thisId = arguments[0];
+      var thisData = arguments[1];
+      var callback = arguments[2];
 
-      if (null == thisData[fieldname])
+      if (undefined == this.data[thisId])
       {
-        continue;
+        this.data[thisId] = thisData;
       }
 
-      this.fields[fieldname].value = thisData[fieldname];
-
-      // Get display value for autocompletes
-      if 
($(this.fields[fieldname]).next('input').hasClass('form-autocomplete'))
+      for (fieldname in this.fields)
       {
-        var hiddenInput = this.fields[fieldname];
+        // Set dialog field
+        var thisTable = this.table;
 
-        // First check if a "Display" value is include in "thisData"
-        var displayField = fieldname.substr(0, fieldname.length-1)+'Display]';
-        if (undefined != thisData[displayField])
+        if (null == thisData[fieldname])
         {
-          
$(hiddenInput).next('input').val(jQuery.trim(thisData[displayField]));
+          continue;
         }
-        else if (0 < hiddenInput.value.length)
+
+        this.fields[fieldname].value = thisData[fieldname];
+
+        // Get display value for autocompletes
+        if 
($(this.fields[fieldname]).next('input').hasClass('form-autocomplete'))
         {
-          // If necessary, get name via Ajax request to show page
-          var dataSource = new YAHOO.util.XHRDataSource(hiddenInput.value);
-          dataSource.responseType = YAHOO.util.DataSourceBase.TYPE_TEXT;
-          dataSource.parseTextData = function (request, response)
-          {
-            var text = $('h1.label', response.toString()).text();
-            return { "results": [ text ]};
-          };
-
-          var myCallback = {
-            success: function (req, res, payload) {
-              
$(payload.hiddenInput).next('input.form-autocomplete').val(res.results[0]);
-            },
-            argument: { "hiddenInput": hiddenInput }
+          var hiddenInput = this.fields[fieldname];
+
+          // First check if a "Display" value is include in "thisData"
+          var displayField = fieldname.substr(0, fieldname.length - 1) + 
'Display]';
+          if (undefined != thisData[displayField])
+          {
+            
$(hiddenInput).next('input').val(jQuery.trim(thisData[displayField]));
           }
+          else if (0 < hiddenInput.value.length)
+          {
+            // If necessary, get name via Ajax request to show page
+            var dataSource = new YAHOO.util.XHRDataSource(hiddenInput.value);
+            dataSource.responseType = YAHOO.util.DataSourceBase.TYPE_TEXT;
+            dataSource.parseTextData = function (request, response)
+            {
+              var text = $('h1.label', response.toString()).text();
+              return { 'results': [ text ]};
+            };
+
+            var myCallback = {
+              success: function (req, res, payload)
+                {
+                  
$(payload.hiddenInput).next('input.form-autocomplete').val(res.results[0]);
+                },
+              argument: { 'hiddenInput': hiddenInput }
+            }
 
-          // Set visible input field of yui-autocomplete
-          dataSource.sendRequest(null, myCallback);
+            // Set visible input field of yui-autocomplete
+            dataSource.sendRequest(null, myCallback);
+          }
         }
       }
-    }
 
-    if (undefined != callback)
-    {
-      callback();
+      if (undefined != callback)
+      {
+        callback();
+      }
     }
-  }
 
   this.save = function (yuiDialogData)
-  {
-    $('input.form-autocomplete', thisDialog.table).each(function ()
-      {
-        $hidden = $(this).prev('input:hidden');
-
-        // Test for existing iframe
-        for (var i in thisDialog.iframes)
+    {
+      $('input.form-autocomplete', thisDialog.table).each(function ()
         {
-          if (thisDialog.id == thisDialog.iframes[i].dialogId && 
$hidden.attr('name') == thisDialog.iframes[i].inputName)
+          $hidden = $(this).prev('input:hidden');
+
+          // Test for existing <iframe/>
+          for (var i in thisDialog.iframes)
           {
-            var index = i;
+            if (thisDialog.id == thisDialog.iframes[i].dialogId && 
$hidden.attr('name') == thisDialog.iframes[i].inputName)
+            {
+              var index = i;
+            }
           }
-        }
 
-        // Test if autocomplete has a value
-        if (0 < this.value.length)
-        {
-          // If no URI is set, then selecting unmatched value
-          if (0 == $hidden.val().length)
+          // Test if autocomplete has a value
+          if (0 < this.value.length)
           {
-            // Allowing adding new values via iframe
-            var value = $('~ .add', this).val();
-            if (value)
+            // If no URI is set, then selecting unmatched value
+            if (0 == $hidden.val().length)
             {
-              var components = value.split(' ', 2);
-
-              if (undefined == index)
+              // Allowing adding new values via iframe
+              var value = $('~ .add', this).val();
+              if (value)
               {
-                // Add hidden <iframe/> for each new choice
-                $iframe = $('<iframe src="' + components[0] + '"/>')
-                  .width(0)
-                  .height(0)
-                  .css('border', 0)
-                  .appendTo('body');
-
-                thisDialog.iframes.push({
-                  'dialogId': thisDialog.id,
-                  'inputName': $(this).prev('input:hidden').attr('name'),
-                  'iframe': $iframe,
-                  'selector': components[1],
-                  'value': this.value
-                });
-              }
-              else
-              {
-                // Update existing iframe
-                thisDialog.iframes[index].value = this.value;
+                var components = value.split(' ', 2);
+
+                if (undefined == index)
+                {
+                  // Add hidden <iframe/> for each new choice
+                  $iframe = $('<iframe src="' + components[0] + '"/>')
+                    .width(0)
+                    .height(0)
+                    .css('border', 0)
+                    .appendTo('body');
+
+                  thisDialog.iframes.push({
+                    'dialogId': thisDialog.id,
+                    'inputName': $(this).prev('input:hidden').attr('name'),
+                    'iframe': $iframe,
+                    'selector': components[1],
+                    'value': this.value });
+                }
+                else
+                {
+                  // Update existing <iframe/>
+                  thisDialog.iframes[index].value = this.value;
+                }
               }
             }
-          }
 
-          // Remove iframe if selecting a pre-existing value
-          else if (undefined != index && this.value != 
thisDialog.iframes[index].iframe.value)
-          {
-            delete thisDialog.iframes[index];
+            // Remove <iframe/> if selecting a pre-existing value
+            else if (undefined != index && this.value != 
thisDialog.iframes[index].iframe.value)
+            {
+              delete thisDialog.iframes[index];
+            }
           }
-        }
-      } );
+        });
 
-    this.data[this.id] = yuiDialogData;
+      this.data[this.id] = yuiDialogData;
 
-    return this;
-  }
+      return this;
+    }
 
   this.clear = function ()
-  {
-    // Remove "id" field
-    $('input[name=id]', this.table).remove();
-
-    // Clear fields
-    for (fname in this.fields)
     {
-      // Radio and checkbox inputs have a length > 0
-      if (0 < this.fields[fname].length)
+      // Remove "id" field
+      $('input[name=id]', this.table).remove();
+
+      // Clear fields
+      for (fname in this.fields)
       {
-        var initVal = this.initialValues[fname];
-        if ('string' == typeof initVal)
+        // Radio and checkbox inputs have a length > 0
+        if (0 < this.fields[fname].length)
         {
-          initVal = [initVal]; // Cast as array
-        }
+          var initVal = this.initialValues[fname];
+          if ('string' == typeof initVal)
+          {
+            initVal = [initVal]; // Cast as array
+          }
 
-        $(this.fields[fname]).val(initVal);
-      }
-      else if ('select-one' == this.fields[fname].type)
-      {
-        // Select first option in single option select controls
-        this.fields[fname].options[0].selected = true;
-      }
-      else
-      {
-        $(this.fields[fname]).val(this.initialValues[fname]);
+          $(this.fields[fname]).val(initVal);
+        }
+        else if ('select-one' == this.fields[fname].type)
+        {
+          // Select first option in single option select controls
+          this.fields[fname].options[0].selected = true;
+        }
+        else
+        {
+          $(this.fields[fname]).val(this.initialValues[fname]);
+        }
       }
-    }
 
-    // Clear autocomplete fields
-    $('input.form-autocomplete', $(this.table)).val('');
+      // Clear autocomplete fields
+      $('input.form-autocomplete', $(this.table)).val('');
 
-    return this;
-  }
+      return this;
+    }
 
   this.remove = function (thisId)
-  {
-    if (undefined == this.data[thisId])
     {
-      return;
-    }
+      if (undefined == this.data[thisId])
+      {
+        return;
+      }
 
-    var tr = $('#' + this.options.displayTable + ' tr[id=' + thisId + ']');
+      var tr = $('#' + this.options.displayTable + ' tr[id=' + thisId + ']');
 
-    // Wrap <td/> contents in <div/> so the row hides nicely then hide and
-    // remove row
-    tr.children('td')
-      .wrapInner('<div></div>')
-      .children('div').hide('normal', function () {
-        tr.remove();
-      });
+      // Wrap <td/> contents in <div/> so the row hides nicely then hide and
+      // remove row
+      tr.find('> td').wrapInner('<div/>')
+        .find('> div').hide('normal', function ()
+          {
+            tr.remove();
+          });
 
-    // If this is an existing relationship, then store id for deletion
-    if ('new' != thisId.substr(0,3))
-    {
-      this.deletes.push(thisId.match(/\d+$/));
-    }
+      // If this is an existing relationship, then store id for deletion
+      if ('new' != thisId.substr(0,3))
+      {
+        this.deletes.push(thisId.match(/\d+$/));
+      }
 
-    // Remove data for relation
-    delete this.data[thisId];
-  }
+      // Remove data for relation
+      delete this.data[thisId];
+    }
 
   this.appendDisplayRow = function ()
-  {
-    var displayTable = document.getElementById(this.options.displayTable);
-    var newRowTemplate = this.options.newRowTemplate;
-
-    if (undefined == displayTable || undefined == newRowTemplate)
     {
-      return;
-    }
+      var displayTable = document.getElementById(this.options.displayTable);
+      var newRowTemplate = this.options.newRowTemplate;
 
-    // Check for special field render handler
-    if (undefined != this.options.handleFieldRender)
-    {
-      var render = function (fname)
+      if (undefined == displayTable || undefined == newRowTemplate)
       {
-        return thisDialog.options.handleFieldRender(thisDialog, fname);
+        return;
       }
-    }
-    else
-    {
-      var render = function (fname)
+
+      // Check for special field render handler
+      if (undefined != this.options.handleFieldRender)
       {
-        return thisDialog.renderField(fname);
+        var render = function (fname)
+          {
+            return thisDialog.options.handleFieldRender(thisDialog, fname);
+          }
+      }
+      else
+      {
+        var render = function (fname)
+          {
+            return thisDialog.renderField(fname);
+          }
       }
-    }
 
-    tr = newRowTemplate.replaceAll('{' + this.fieldPrefix + '[id]}', this.id);
-    for (fname in this.fields)
-    {
-      if (0 < fname.length)
+      tr = newRowTemplate.replaceAll('{' + this.fieldPrefix + '[id]}', 
this.id);
+      for (fname in this.fields)
       {
-        tr = tr.replaceAll('{' + fname + '}', render(fname));
+        if (0 < fname.length)
+        {
+          tr = tr.replaceAll('{' + fname + '}', render(fname));
+        }
       }
-    }
 
-    if(0 == $('tr[id=' + this.id + ']', displayTable).length)
-    {
-      $(displayTable).append(tr);
-    }
-    else
-    {
-      $('tr[id=' + this.id + ']', displayTable).replaceWith(tr);
-    }
+      if (0 == $('tr[id=' + this.id + ']', displayTable).length)
+      {
+        $(displayTable).append(tr);
+      }
+      else
+      {
+        $('tr[id=' + this.id + ']', displayTable).replaceWith(tr);
+      }
 
-    // Bind events
-    $('tr[id=' + this.id + '] img[alt=edit]').click(function () {
-      thisDialog.open($(this).parents('tr').attr('id'));
-    });
-    $('tr[id=' + this.id + '] button[name=delete]').click(function () {
-      thisDialog.remove($(this).parents('tr').attr('id'));
-      return false;
-    });
-  }
+      // Bind events
+      $('tr[id=' + this.id + '] img[alt=edit]').click(function ()
+        {
+          thisDialog.open($(this).parents('tr').attr('id'));
+        });
 
-  // Submit dialog
-  this.submit = function (yuiDialogData)
-  {
-    this.save(yuiDialogData);
-    this.appendDisplayRow();
-    this.clear();
-  }
+      $('tr[id=' + this.id + '] button[name=delete]').click(function ()
+        {
+          thisDialog.remove($(this).parents('tr').attr('id'));
 
-  // Append all cached data to form
-  this.appendHiddenFields = function ()
-  {
-    // Build hidden form input fields
-    var i = 0;
-    if (null != this.fieldPrefix)
-    {
-      // Append "s" to old prefix to indicate multiple nature
-      var outputPrefix = this.fieldPrefix + 's';
+          return false;
+        });
     }
-    else
+
+  // Submit dialog
+  this.submit = function (yuiDialogData)
     {
-      var outputPrefix = 'dialog';
+      this.save(yuiDialogData);
+      this.appendDisplayRow();
+      this.clear();
     }
 
-    for(var id in this.data)
+  // Append all cached data to form
+  this.appendHiddenFields = function ()
     {
-      var thisData = this.data[id];
-
-      // Don't include "id" if it's a "new" object
-      if (null != id && 'new' != id.substr(0,3))
+      // Build hidden form input fields
+      var i = 0;
+      if (null != this.fieldPrefix)
       {
-        var name = outputPrefix + '[' + i + '][id]';
-        $(this.form).append('<input type="hidden" name="' + name + '" value="' 
+ id + '" />');
+        // Append "s" to old prefix to indicate multiple nature
+        var outputPrefix = this.fieldPrefix + 's';
+      }
+      else
+      {
+        var outputPrefix = 'dialog';
       }
 
-      // Convert all event data into hidden input fields
-      for (var j in thisData)
+      for (var id in this.data)
       {
-        // Format name according to input and output name formats
-        var matches = j.match(this.fieldNameFilter);
-        if (null != matches)
+        var thisData = this.data[id];
+
+        // Don't include "id" if it's a "new" object
+        if (null != id && 'new' != id.substr(0,3))
         {
-          name = outputPrefix + '[' + i + '][' + matches[2] + ']';
+          var name = outputPrefix + '[' + i + '][id]';
+          $(this.form).append('<input type="hidden" name="' + name + '" 
value="' + id + '"/>');
         }
-        else
+
+        // Convert all event data into hidden input fields
+        for (var j in thisData)
         {
-          name = outputPrefix + '[' + i + '][' + name + ']';
-        }
+          // Format name according to input and output name formats
+          var matches = j.match(this.fieldNameFilter);
+          if (null != matches)
+          {
+            name = outputPrefix + '[' + i + '][' + matches[2] + ']';
+          }
+          else
+          {
+            name = outputPrefix + '[' + i + '][' + name + ']';
+          }
 
-        var $hidden = $('<input type="hidden" name="' + name + '" value="' + 
thisData[j] + '" />');
-        $hidden.appendTo(this.form);
+          var $hidden = $('<input type="hidden" name="' + name + '" value="' + 
thisData[j] + '"/>');
+          $hidden.appendTo(this.form);
 
-        // Update this value from iframe
-        for(var k in this.iframes)
-        {
-          if (id == this.iframes[k].dialogId && j == this.iframes[k].inputName)
+          // Update this value from iframe
+          for (var k in this.iframes)
           {
-            this.iframes[k].iframe.one('load', {'hdn': $hidden}, function (e)
-              {
-                // Update value of hidden input with URI of new resource
-                e.data.hdn.val(this.contentWindow.document.location);
+            if (id == this.iframes[k].dialogId && j == 
this.iframes[k].inputName)
+            {
+              this.iframes[k].iframe.one('load', { 'hdn': $hidden }, function 
(e)
+                {
+                  // Update value of hidden input with URI of new resource
+                  e.data.hdn.val(this.contentWindow.document.location);
 
-                // Decrement count of listeners and submit if all done
-                thisDialog.done();
-              } );
+                  // Decrement count of listeners and submit if all done
+                  thisDialog.done();
+                });
+            }
           }
         }
+
+        i++;
       }
-      i++;
-    }
 
-    // Delete relations that have been removed
-    for (var k=0; k < this.deletes.length; k++)
-    {
-      $(this.form).append('<input type="hidden" name="deleteRelations[' + 
this.deletes[k] + ']" value="delete" />');
+      // Delete relations that have been removed
+      for (var k=0; k < this.deletes.length; k++)
+      {
+        $(this.form).append('<input type="hidden" name="deleteRelations[' + 
this.deletes[k] + ']" value="delete"/>');
+      }
     }
-  }
 }

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to