Author: david
Date: Tue Dec 8 18:10:04 2009
New Revision: 4126
Log:
Create QubitDialog class to simplify passing dialog DOM structure + data
representation.
Modified:
trunk/apps/qubit/modules/function/templates/_relationships.php
trunk/web/js/dialog.js
Modified: trunk/apps/qubit/modules/function/templates/_relationships.php
==============================================================================
--- trunk/apps/qubit/modules/function/templates/_relationships.php Tue Dec
8 17:29:45 2009 (r4125)
+++ trunk/apps/qubit/modules/function/templates/_relationships.php Tue Dec
8 18:10:04 2009 (r4126)
@@ -62,7 +62,7 @@
<!-- "functionRelation" table and pastes it in a YUI dialog object. -->
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
<table class="inline dialog" id="functionRelation">
- <caption><?php echo __('new relationship') ?></caption>
+ <caption><?php echo __('relationship') ?></caption>
<tbody>
<tr>
<th colspan="4">
Modified: trunk/web/js/dialog.js
==============================================================================
--- trunk/web/js/dialog.js Tue Dec 8 17:29:45 2009 (r4125)
+++ trunk/web/js/dialog.js Tue Dec 8 18:10:04 2009 (r4126)
@@ -1,37 +1,69 @@
// $Id$
-function submitDialog(dialogData, dataObject, i)
+
+// Build object for holding dialog data
+var QubitDialog = function()
+{
+ var obj = this;
+
+ obj.id = null;
+ obj.fields = [];
+ obj.dom = null;
+ obj.label = null;
+
+ obj.buildDataRepresention = function()
+ {
+ $(obj.dom).find(':input').each(function()
+ {
+ obj.fields[this.name] = { "type": this.type, "value": null }
+ } );
+ }
+
+ obj.loadData = function(data, i)
+ {
+ // Get a unique id (derive one if form doesn't provide one)
+ obj.id = (data['id'] != undefined) ? data['id'] : 'new' + i;
+
+ for (j in obj.fields)
+ {
+ obj.fields[j].value = data[j];
+ }
+ }
+}
+
+function submitDialog(dialogData, qubitDialog, i)
{
var cachedData = $('body').data('cachedData');
- dataObject.loadData(dialogData, i);
+ qubitDialog.loadData(dialogData, i);
// cache event data locally
- cachedData[dataObject.id] = dataObject;
+ cachedData[qubitDialog.id] = qubitDialog;
$('body').data('cachedData', cachedData);
- return dataObject;
+ return qubitDialog;
}
-function clearDialog(dialog, dialogData)
+function clearDialog(qubitDialog)
{
// Remove "id" input
- $(dialog).find('input[name="id"]').remove();
+ var selector = '#' + qubitDialog.dom.id;
+ $(selector).find('input[name="id"]').remove();
// Clear input fields
- for (name in dialogData.fields)
+ for (name in qubitDialog.fields)
{
- switch (dialogData.fields[name].type)
+ switch (qubitDialog.fields[name].type)
{
case 'text':
- $(dialog).find('input[name="' + name + '"]').val('');
+ $(selector).find('input[name="' + name + '"]').val('');
break;
case 'textarea':
- $(dialog).find('textarea[name="' + name + '"]').val('');
+ $(selector).find('textarea[name="' + name + '"]').val('');
break;
case 'select-one':
// Select first option in single option select controls
- $(dialog).find('select[name="' + name +
'"]').get(0).options[0].selected = true;
+ $(selector).find('select[name="' + name +
'"]').get(0).options[0].selected = true;
break;
}
}
@@ -93,17 +125,22 @@
Drupal.behaviors.autocomplete = {
attach: function (context)
{
+ var qubitDialog = new QubitDialog();
+
$('table.dialog').each(function()
{
- var dialog = this;
- var label = $(dialog).children('caption').remove().text();
+ qubitDialog.dom = this;
+ qubitDialog.buildDataRepresention();
+ qubitDialog.label =
$(qubitDialog.dom).children('caption').remove().text();
+
+ // Get parent form
var thisForm = $(this).parents('form').eq(0);
// Create YUI container for dialog
var yuiDialogWrapper = $(
'<div class="yui-skin-sam">' +
- '<div id="' + $(dialog).attr('id') + '">' +
- '<div class="hd">' + label + '</div>' +
+ '<div id="' + this.id + '">' +
+ '<div class="hd">' + qubitDialog.label + '</div>' +
'<div class="bd">' +
'<form action="" method="POST" style="border: none"></form>' +
'</div>' +
@@ -111,56 +148,33 @@
'</div>');
// Replace dialog table with "add" link and move into dialog wrapper
- $(dialog)
- .removeClass('dialog')
+ $(this)
+ .removeClass('dialogTable')
.replaceWith('<a href="javascript:yuiDialog.show();">Add</a>')
.appendTo(yuiDialogWrapper.find('form'))
- // append yuiDialogWrapper to document body
+ // prepend yuiDialogWrapper to document body
$('body').prepend(yuiDialogWrapper);
// Instantiate YUI dialog object
var counter = 0; // Counter
- $('body').data('cachedData', new Array()); // Data cache
- // Build object for holding dialog data
- var DialogObject = function()
- {
- var obj = this;
-
- obj.id = null;
- obj.fields = [];
-
- $(dialog).find(':input').each(function()
- {
- obj.fields[this.name] = { "type": this.type, "value": null }
- } );
-
- obj.loadData = function(data, i)
- {
- // Get a unique id (derive one if form doesn't provide one)
- obj.id = (data['id'] != undefined) ? data['id'] : 'new' + i;
-
- for (j in obj.fields)
- {
- obj.fields[j].value = data[j];
- }
- }
- }
-
+ // Data cache
+ $('body').data('cachedData', new Array());
+
// Submit dialog data
var handleSubmit = function() {
- submitDialog(this.getData(), new DialogObject, counter++); // Save
the data to the main form
+ submitDialog(this.getData(), qubitDialog, counter++); // Save the
data to the main form
this.hide(); // Hide dialog
- clearDialog(dialog, new DialogObject); // Clear dialog values
+ clearDialog(qubitDialog); // Clear dialog values
};
var handleCancel = function() {
this.cancel();
- clearDialog(dialog, new DialogObject);
+ clearDialog(qubitDialog);
};
- yuiDialog = new YAHOO.widget.Dialog($(dialog).attr('id'),
+ yuiDialog = new YAHOO.widget.Dialog(qubitDialog.dom.id,
{
width: "480px",
zIndex: "100",
--
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.