Author: david
Date: Tue Dec 8 15:17:33 2009
New Revision: 4120
Log:
Auto-build dialog data representation, and add cached dialog data to form on
submit.
Modified:
trunk/web/js/dialog.js
Modified: trunk/web/js/dialog.js
==============================================================================
--- trunk/web/js/dialog.js Tue Dec 8 15:16:26 2009 (r4119)
+++ trunk/web/js/dialog.js Tue Dec 8 15:17:33 2009 (r4120)
@@ -1,11 +1,56 @@
// $Id$
+
+function submitDialog(formData, dialog, i)
+{
+ var cachedData = $('body').data('cachedData');
+
+ dialog.loadData(formData, i);
+
+ // cache event data locally
+ cachedData[dialog.id] = dialog;
+ $('body').data('cachedData', cachedData);
+
+ return dialog;
+}
+
+function appendHiddenFields(thisForm)
+{
+ // Build hidden form input fields
+ var newHiddens = '';
+ var cachedData = $('body').data('cachedData');
+ //var deleteEvents = $('body').data('deleteEvents');
+ var i = 0;
+
+ for(var key in cachedData)
+ {
+ var thisData = cachedData[key];
+
+ // Convert all event data into a hidden input fields
+ for (var name in thisData.fields)
+ {
+ // Don't include "id" if parameter == null
+ if ('id' == name && null == thisEvent.data.id)
+ {
+ continue;
+ }
+
+ newHiddens += '<input type="hidden" name="relations[' + i + '][' + name
+ ']" value="' + thisData.fields[name].value + '" />\n';
+ }
+ i++;
+ }
+
+ // Append hidden input fields
+ thisForm.append(newHiddens);
+}
+
Drupal.behaviors.autocomplete = {
attach: function (context)
{
$('table.dialog').each(function()
{
var table = this;
- var label = $(table).children('caption').remove().text();
+ var label = $(table).children('caption').remove().text();
+ var thisForm = $(this).parents('form').eq(0);
// Create YUI container for dialog
var yuiDialogWrapper = $(
@@ -29,10 +74,36 @@
// Instantiate YUI dialog object
var counter = 0; // Counter
-
+ $('body').data('cachedData', new Array()); // Data cache
+
+ // Build dialog data class
+ var DialogData = function()
+ {
+ var DataObject = this;
+
+ DataObject.id = null;
+ DataObject.fields = [];
+
+ $(table).find(':input').each(function()
+ {
+ DataObject.fields[this.name] = { "type": this.type, "value": null }
+ } );
+
+ DataObject.loadData = function(data, i)
+ {
+ // Get a unique id (derive one if form doesn't provide one)
+ DataObject.id = (data['id'] != undefined) ? data['id'] : 'new' + i;
+
+ for (j in DataObject.fields)
+ {
+ DataObject.fields[j].value = data[j];
+ }
+ }
+ }
+
// Write data from dialog to informationobject/edit form for
submission.
var handleSubmit = function() {
- //submitActorEventDialog(this.getData(), counter++); // Save the
data to the main form
+ submitDialog(this.getData(), new DialogData, counter++); // Save the
data to the main form
this.hide(); // Hide dialog
//clearActorEventDialog(); // Clear the dialog form
};
@@ -57,6 +128,11 @@
} );
yuiDialog.render();
+
+ // Bind addHiddenFields() to form submit
+ thisForm.submit(function () {
+ appendHiddenFields($(this))
+ } );
})
}
}
--
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.