Adding the SQL Form and editForm error feedback.

This commit is contained in:
Martin Kamerbeek 2006-04-18 15:09:07 +00:00
parent 82b2ad934d
commit 179e4a89ef
15 changed files with 6293 additions and 4 deletions

View file

@ -105,7 +105,7 @@
- fix [ 1344665 ] Cache does not remember mimetype
- fix [ 1172613 ] Header Tag Not Accessibility Friendly
- fix [ 1340839 ] If can't use item in adminConsole don't display it
- Added SQL Form and error feedback for asset addition (Martin Kamerbeek/Procolix)
6.8.8
- fix [ 1452466 ] File size not set in File asset (Thanks to Eric S)

View file

@ -0,0 +1,33 @@
#SQLFormEditTmpl0000001
#create
#title:Default SQLForm Edit template
#menuTitle:Default SQLForm Edit template
#url:default_sqlform_edit_template
#namespace:SQLForm/Edit
<a name="id<tmpl_var assetId>"></a>
<tmpl_if session.var.adminOn>
<p><tmpl_var controls></p>
</tmpl_if>
<div class="SQLForm-contentBox">
<tmpl_if displayTitle>
<h1><tmpl_var title></h1>
</tmpl_if>
<tmpl_unless isNew>
<a href="<tmpl_var viewHistory.url>"><tmpl_var viewHistory.label></a><br /><br />
</tmpl_unless>
<tmpl_if errorOccurred>
<h1>Some errors occurred</h1>
<ul>
<tmpl_loop errorLoop>
<li><tmpl_var error.message></li>
</tmpl_loop>
</ul>
</tmpl_if>
<tmpl_var managementLinks>
<tmpl_var completeForm>
</div>

View file

@ -0,0 +1,85 @@
#SQLFormSearchTmpl00001
#create
#title:Default SQLForm Search template
#menuTitle:Default SQLForm Search template
#url:default_sqlform_search_template
#namespace:SQLForm/Search
<a name="id<tmpl_var assetId>"></a>
<tmpl_if session.var.adminOn>
<p><tmpl_var controls></p>
</tmpl_if>
<div class="SQLForm-contentBox">
<tmpl_if displayTitle>
<h1><tmpl_var title></h1>
</tmpl_if>
<tmpl_var managementLinks>
<h2>Search records</h2>
<a href="<tmpl_var superSearch.url>"><tmpl_var superSearch.label></a><br>
<tmpl_if errorOccurred>
Some error(s) occurred:
<ul>
<tmpl_loop errorLoop>
<li><tmpl_var error.message></li>
</tmpl_loop>
</ul>
</tmpl_if>
<tmpl_var searchForm>
<tmpl_if showFieldsDefined>
<tmpl_var searchResults.header>
<tmpl_var searchResults.actionButtons>
<table border="0">
<tr>
<th></th>
<tmpl_if showMetaData>
<th>Last update</th>
<th>Last update by</th>
</tmpl_if>
<tmpl_loop headerLoop>
<th <tmpl_if
header.sort.onThis>color="red"</tmpl_if>>
<a href="<tmpl_var header.sort.url>">
<tmpl_var header.title>
<tmpl_if header.sort.onThis><tmpl_if header.sort.ascending>(asc)<tmpl_else>(desc)</tmpl_if></tmpl_if></a></th>
</tmpl_loop>
</tr>
<tmpl_loop searchResults.recordLoop>
<tr>
<td><tmpl_var record.controls></td>
<tmpl_if showMetaData>
<td><tmpl_var record.updateDate></td>
<td><tmpl_var record.updatedBy></td>
</tmpl_if>
<tmpl_loop record.valueLoop>
<td>
<tmpl_if record.value.isFile>
<tmpl_if record.value>
<a href="<tmpl_var record.value.downloadUrl>">
<tmpl_if record.value.isImage>
<img width="100" src="<tmpl_var record.value.downloadUrl>">
<tmpl_else>
Click here for file
</tmpl_if>
</a>
</tmpl_if>
<tmpl_else>
<tmpl_var record.value>
</tmpl_if>
</td>
</tmpl_loop>
</tr>
</tmpl_loop>
</table>
<tmpl_var searchResults.actionButtons>
<tmpl_var searchResults.footer>
<tmpl_else>
No fields are defined to be shown in the search results.
</tmpl_if>
</div>

View file

@ -17,6 +17,7 @@ use File::Path;
use WebGUI::Workflow;
use WebGUI::Workflow::Cron;
use WebGUI::Group;
use WebGUI::Utility;
use WebGUI::Storage;
my $toVersion = "6.99.0"; # make this match what version you're going to
@ -48,6 +49,7 @@ updateMatrix();
updateFolder();
addRichEditUpload();
updateArticle();
installSQLForm();
finish($session); # this line required
@ -927,6 +929,82 @@ EOT
$asset->addRevision({template=>$template});
}
sub installSQLForm {
print "\tInstalling SQLForm tables.\n" unless ($quiet);
# Skip table creation if the SQLForm is already installed.
return "" if WebGUI::Utility::isIn('SQLForm', $session->db->buildArray("show tables"));
# Create tables;
$session->db->write(<<ENDOFQUERY1
CREATE TABLE SQLForm (
assetId varchar(22) NOT NULL default '',
formId varchar(22) default NULL,
tableName varchar(255) default NULL,
viewTemplateId varchar(22) default NULL,
searchTemplateId varchar(22) default NULL,
editTemplateId varchar(22) default NULL,
submitGroupId varchar(22) default NULL,
alterGroupId varchar(22) default NULL,
databaseLinkId varchar(22) default '0',
maxFileSize bigint(20) default NULL,
sendMailTo varchar(255) default NULL,
showMetaData tinyint(1) default '1',
revisionDate bigint(20) NOT NULL default '0',
PRIMARY KEY (assetId,revisionDate)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
ENDOFQUERY1
);
$session->db->write(<<ENDOFQUERY2
CREATE TABLE SQLForm_fieldDefinitions (
fieldId varchar(22) NOT NULL default '',
assetId varchar(22) NOT NULL default '',
property varchar(255) NOT NULL default '',
`value` text,
UNIQUE KEY fieldId (fieldId,property)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
ENDOFQUERY2
);
$session->db->write(<<ENDOFQUERY3
CREATE TABLE SQLForm_fieldOrder (
assetId varchar(22) NOT NULL default '',
fieldId varchar(22) NOT NULL default '',
rank int(11) NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
ENDOFQUERY3
);
$session->db->write(<<ENDOFQUERY4
CREATE TABLE SQLForm_fieldTypes (
fieldTypeId varchar(22) NOT NULL default '',
dbFieldType varchar(22) NOT NULL default '',
formFieldType varchar(22) NOT NULL default '',
PRIMARY KEY (fieldTypeId)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
ENDOFQUERY4
);
$session->db->write(<<ENDOFQUERY5
CREATE TABLE SQLForm_regexes (
regexId varchar(22) default NULL,
name varchar(255) NOT NULL default '',
regex varchar(255) NOT NULL default '',
UNIQUE KEY regex (regex)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
ENDOFQUERY5
);
# Insert default regexes
$session->db->write("insert into SQLForm_regexes (regexId, name, regex) values ('defaultText', 'Text', '^[\\\\w\\\\d\\\\s]*\$')");
$session->db->write("insert into SQLForm_regexes (regexId, name, regex) values ('defaultUnsigned', 'Unsigned integer', '^\\\\d+\$')");
$session->db->write("insert into SQLForm_regexes (regexId, name, regex) values ('defaultSigned', 'Signed integer', '^-?\\\\d+\$')");
$session->db->write("insert into SQLForm_regexes (regexId, name, regex) values ('defaultFloat', 'Floating point number', '^-?\\\\d+(\\.\\\\d+)?\$')");
}
# ---- DO NOT EDIT BELOW THIS LINE ----
#-------------------------------------------------

View file

@ -181,7 +181,8 @@
"WebGUI::Asset::Wobject::SyndicatedContent",
"WebGUI::Asset::Wobject::InOutBoard",
"WebGUI::Asset::File::ZipArchive",
"WebGUI::Asset::Wobject::WSClient"
"WebGUI::Asset::Wobject::WSClient",
"WebGUI::Asset::Wobject::SQLForm"
],
# Specify the list assets that are used for utility purposes only

View file

@ -542,6 +542,16 @@ sub getEditForm {
});
}
$tabform->addTab("properties",$i18n->get("properties"));
# process errors
my $errors = $self->session->stow->get('editFormErrors');
print "[$errors]";
if ($errors) {
$tabform->getTab("properties")->readOnly(
-value=>"<p>Some error(s) occurred:<ul><li>".join('</li><li>', @$errors).'</li></ul></p>',
)
}
$tabform->getTab("properties")->readOnly(
-label=>$i18n->get("asset id"),
-value=>$self->get("assetId"),
@ -1523,7 +1533,9 @@ sub prepareView {
=head2 processPropertiesFromFormPost ( )
Updates current Asset with data from Form.
Updates current Asset with data from Form. You can feed back errors by returning an
arrayref containing the error messages. If there is no error you do not have to return
anything.
=cut
@ -1906,7 +1918,19 @@ sub www_editSave {
return $self->getContainer->www_view;
}
}
$object->processPropertiesFromFormPost;
my $error = $object->processPropertiesFromFormPost;
if (ref $error eq 'ARRAY') {
$self->session->stow->set('editFormErrors', $error);
if ($self->session->form->process('assetId') eq 'new') {
$object->purge;
return $self->www_add();
} else {
$object->purgeRevision;
return $self->www_edit();
}
}
$object->updateHistory("edited");
if ($self->session->form->process("proceed") eq "manageAssets") {
$self->session->asset($object->getParent);
@ -1921,6 +1945,7 @@ sub www_editSave {
$self->session->asset($object);
return $self->session->asset->$method();
}
$self->session->asset($object->getContainer);
return $self->session->asset->www_view;
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,366 @@
package WebGUI::Help::Asset_SQLForm;
our $HELP = {
'sqlform add/edit ' => {
title => 'edit sqlform',
body => 'sqlform description',
fields => [
{
title => 'gef table name',
description => 'gef table name description',
namespace => 'Asset_SQLForm',
},
{
title => 'gef import table',
description => 'gef import table description',
namespace => 'Asset_SQLForm',
},
{
title => 'gef database to use',
description => 'gef database to use description',
namespace => 'Asset_SQLForm',
},
{
title => 'gef max file size',
description => 'gef max file size description',
namespace => 'Asset_SQLForm',
},
{
title => 'gef send mail to',
description => 'gef send mail to description',
namespace => 'Asset_SQLForm',
},
{
title =>'show meta data',
description => 'gef show meta data description',
namespace => 'Asset_SQLForm',
},
{
title => 'gef edit template',
description => 'gef edit template description',
namespace => 'Asset_SQLForm',
},
{
title => 'gef search template',
description => 'gef search template description',
namespace => 'Asset_SQLForm',
},
{
title => 'gef submit group',
description => 'gef submit group description',
namespace => 'Asset_SQLForm',
},
],
related => [
{
tag => 'manage fields',
namespace => 'Asset_SQLForm',
},
{
tag => 'manage field types',
namespace => 'Asset_SQLForm'
},
{
tag => 'manage regexes',
namespace => 'Asset_SQLForm',
},
],
},
'edit field' => {
title => 'edit field title',
body => 'edit field description',
fields => [
{
title => 'ef field name',
description => 'ef field name description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef display name',
description => 'ef display name description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef field type',
description => 'ef field type description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef signed',
description => 'ef signed description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef autoincrement',
description => 'ef autoincrement description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef form height',
description => 'ef form height description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef max field length',
description => 'ef max field length description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef max field length',
description => 'ef max field length description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef regex',
description => 'ef regex description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef required',
description => 'ef required description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef read only',
description => 'ef read only description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef default value',
description => 'ef default value description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef field constraint',
description => 'ef field constraint description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef searchable',
description => 'ef searchable description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef fulltext',
description => 'ef fulltext description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef show in search',
description => 'ef show in search description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef summary length',
description => 'ef summary length description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef populate keys',
description => 'ef populate keys description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef populate values',
description => 'ef populate values description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef join selector',
description => 'ef join selector description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef join constraint',
description => 'ef join constraint description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef join keys',
description => 'ef join keys description',
namespace => 'Asset_SQLForm',
},
{
title => 'ef join values',
description => 'ef join values description',
namespace => 'Asset_SQLForm',
},
],
related => [
{
tag => 'manage field types',
namespace => 'Asset_SQLForm'
},
{
tag => 'manage regexes',
namespace => 'Asset_SQLForm',
},
],
},
'edit field type' => {
title => 'edit field type title',
body => 'edit field type description',
fields => [
{
title => 'eft db field type',
description => 'eft db field type description',
namespace => 'Asset_SQLForm',
},
{
title => 'eft form field type',
description => 'eft form field type description',
namespace => 'Asset_SQLForm',
},
],
related => [
{
tag => 'manage fields',
namespace => 'Asset_SQLForm'
},
],
},
'edit regex' => {
title =>'edit regex title',
body => 'edit regex description',
fields =>[
{
title => 'er name',
description => 'er name description',
namespace => 'Asset_SQLForm',
},
{
title => 'er regex',
description => 'er regex description',
namespace => 'Asset_SQLForm',
},
],
related => [
{
tag => 'manage fields',
namespace => 'Asset_SQLForm'
},
],
},
'manage fields' => {
title =>'manage fields title',
body => 'edit field description',
related => [
{
tag => 'edit field',
namespace => 'Asset_SQLForm',
},
{
tag => 'manage field types',
namespace => 'Asset_SQLForm'
},
{
tag => 'manage regexes',
namespace => 'Asset_SQLForm',
},
],
},
'manage field types' => {
title => 'manage field types title',
body => 'edit field type description',
related => [
{
tag => 'edit field type',
namespace => 'Asset_SQLForm',
},
{
tag => 'manage fields',
namespace => 'Asset_SQLForm'
},
],
},
'manage regexes' => {
title =>'manage regexes title',
body => 'edit regex description',
related => [
{
tag => 'edit regex',
namespace => 'Asset_SQLForm',
},
{
tag => 'manage fields',
namespace => 'Asset_SQLForm'
},
],
},
'edit record template' => {
title => 'edit template help title',
body => 'edit template help',
related => [
{
tag => 'sqlform add/edit',
namespace => 'Asset_SQLForm',
},
{
tag => 'template language',
namespace => 'Asset_SQLForm',
},
],
},
'search record template' => {
title => 'search template help title',
body => 'search template help',
related => [
{
tag => 'sqlform add/edit',
namespace => 'Asset_SQLForm',
},
{
tag => 'template language',
namespace => 'Asset_SQLForm',
},
],
},
};
1;

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

View file

@ -0,0 +1,91 @@
function updateFormFields() {
//alert(fieldCombo);
var fieldTypeList = document.getElementById('SQLFormFieldType');
if (fieldTypeList.selectedIndex < 0) {
fieldTypeList.selectedIndex = 0;
}
var re = fieldTypeList.options[fieldTypeList.selectedIndex].text.match(/^[^\/]+\/([^\/]+)$/);
var fieldType = RegExp.$1;
var fieldProperties = fieldTypes[fieldType];
// Hanlde sign field
if (fieldProperties['hasSign'] == 1) {
enableField('SQLFormSigned');
} else {
disableField('SQLFormSigned');
}
// Handle autoincrement field
if (fieldProperties['canAutoIncrement'] == 1) {
enableField('SQLFormAutoIncrement');
} else {
disableField('SQLFormAutoIncrement');
}
// Handle regex field
if (
(fieldProperties['canAutoIncrement'] && document.getElementById('autoIncrementField')) ||
(document.getElementById('SQLFormReadOnly') == 1)
) {
disableField('SQLFormRegex');
} else {
enableField('SQLFormRegex');
}
// Handle Field constraints section
if (document.getElementById('SQLFormFieldConstraintType').value > 0) {
enableField('SQLFormFieldConstraintTarget');
if (document.getElementById('SQLFormFieldConstraintTarget').value == 'value') {
enableField('SQLFormFieldConstraintValue');
} else {
disableField('SQLFormFieldConstraintValue');
}
} else {
disableField('SQLFormFieldConstraintTarget');
disableField('SQLFormFieldConstraintValue');
}
}
function enableField(id) {
var e = document.getElementById(id);
if (e) {
e.disabled = false;
e.style.display = '';
}
// also hide row if applicable
var tr = document.getElementsByTagName("tr");
if (tr == null) return;
for (i=0; i < tr.length; i++) {
if(tr[i].className == id+'Row') {
tr[i].style.display = '';
}
}
// document.getElementById(id+'row').style.display = '';
}
function disableField(id) {
var e = document.getElementById(id);
if (e) {
e.disabled = true;
e.style.display = 'none';
}
var tr = document.getElementsByTagName("tr");
if (tr == null) return;
for (i=0; i < tr.length; i++) {
if(tr[i].className == id+'Row') {
tr[i].style.display = 'none';
}
}
// document.getElementById(id+'row').style.display = 'none';
}

View file

@ -0,0 +1,375 @@
// databaseMap is use to store the available db's
var databaseMap = new Object;
// tableMap is used to cache array of table options. This could lessen the
// number of requests to the server.
var tableMap = new Object;
// columnMap will hold the columnnames (including db and tablename) for each
// joinselector
var columnMap = new Object;
var resultList1, resultList2 = null
function initDatabaseMap(databases) {
databaseMap = databases;
}
function setResultFields(field1, field2) {
resultList1 = field1;
resultList2 = field2;
}
//-----------------------------------------------------------------------------
function setAvailableDatabaseOptions(zup) {
zup.options[zup.options.length] = new Option('Please select a database', '');
for (var i = 0; i < databaseMap.length; i++) {
zup.options[zup.options.length] = new Option(databaseMap[i].key, databaseMap[i].value);
}
}
// Processes <Option><Key>Key</Key><Value>Value</Value></Option> XML
//-----------------------------------------------------------------------------
function processAjaxXml(req, selectList, cache, prepend) {
var options = req.responseXML.getElementsByTagName("Option");
if (!prepend) {
prepend = '';
}
for (var i = 0; i < options.length; i++) {
var optionKey = prepend + options[i].getElementsByTagName("Key")[0].firstChild.nodeValue;
var optionValue = prepend + options[i].getElementsByTagName("Value")[0].firstChild.nodeValue;
if (cache) {
cache[cache.length] = {
key : optionKey,
value : optionValue
};
}
if (selectList) {
selectList.options[selectList.options.length] = new Option(optionKey, optionValue); //currentOption;
}
}
}
//-----------------------------------------------------------------------------
function addJoinButtonRow(tableId, rowNumber) {
table = document.getElementById(tableId);
//rowNumber = table.rows.length - 1;
// Create join button
tr = table.insertRow(table.rows.length);
tr.id = 'joinButtonRow';
td = tr.insertCell(tr.cells.length);
td.innerHTML = '<input type="button" id="joinButton'+rowNumber+'" value="Join with another table" />';
td.colSpan = 7;
document.getElementById('joinButton'+rowNumber).onclick = function() {
hideElement('joinButton'+rowNumber);
table.deleteRow(table.rows.length - 1); // Delete row with button
addSelectorRow(tableId);
}
hideElement('joinButton'+rowNumber);
}
//-----------------------------------------------------------------------------
function deleteRows(tableId, stopAtRow) {
table = document.getElementById(tableId);
for (var i = table.rows.length; i > stopAtRow; i--) {
table.deleteRow(table.rows.length - 1);
}
addJoinButtonRow(tableId, stopAtRow);
}
//-----------------------------------------------------------------------------
function hideElement(elementId) {
element = document.getElementById(elementId);
if (element) {
element.style.display = 'none';
element.disabled = true;
}
}
//-----------------------------------------------------------------------------
function unhideElement(elementId) {
element = document.getElementById(elementId);
if (element) {
element.style.display = '';
element.disabled = false;
}
}
//-----------------------------------------------------------------------------
function hideJoinConstraints(rowNumber) {
hideElement('on'+rowNumber);
hideElement('joinFunction'+rowNumber);
hideElement('joinOnA'+rowNumber);
hideElement('joinOnB'+rowNumber);
}
//-----------------------------------------------------------------------------
function unhideJoinConstraints(rowNumber) {
unhideElement('on'+rowNumber);
unhideElement('joinFunction'+rowNumber);
unhideElement('joinOnA'+rowNumber);
unhideElement('joinOnB'+rowNumber);
}
//-----------------------------------------------------------------------------
function addSelectorRow(tableId, formDatabase, formTable, formJoinOnA, formJoinOnB, formJoinFunction) {
var table = document.getElementById(tableId);
var tr, selectName, tds = '';
if (!table) {
alert('Fatal error: tableId does not exist.');
}
var rowNumber = table.rows.length + 1;
// Insert a row
tr = table.insertRow(table.rows.length);
// Table label
tr.insertCell(tr.cells.length).innerHTML = '<b>table'+rowNumber+'</b>';
// Create database selector
selectName = 'database'+rowNumber;
td = tr.insertCell(tr.cells.length);
td.innerHTML = '<select id="'+selectName+'" name="'+selectName+'"></select>';
s = document.getElementById(selectName);
setAvailableDatabaseOptions(s);
s.onchange = function() {
setTablesInSelectList(rowNumber, s.value);
deleteRows(tableId, rowNumber);
hideJoinConstraints(rowNumber);
unhideElement('table'+rowNumber);
toggleJoinButton(rowNumber);
};
if (formDatabase) {
s.value = formDatabase;
}
// Create table selector
selectName = 'table'+rowNumber;
td = tr.insertCell(tr.cells.length);
td.innerHTML = '<select id="'+selectName+'" name="'+selectName+'"></select>';
document.getElementById(selectName).onchange = function() {
setJoinOnA(rowNumber);
setJoinOnB(rowNumber);
updateFields(rowNumber);
deleteRows(tableId, rowNumber);
if (rowNumber > 1) {
unhideJoinConstraints(rowNumber);
}
toggleJoinButton(rowNumber);
}
if (formDatabase) {
setTablesInSelectList(rowNumber, formDatabase);
document.getElementById(selectName).value = formTable;
} else {
hideElement(selectName);
}
// Create on word
td = tr.insertCell(tr.cells.length);
td.innerHTML = ' on ';
td.id = 'on'+rowNumber;
// Create first join selector
selectName = 'joinOnA'+rowNumber;
td = tr.insertCell(tr.cells.length);
td.innerHTML = '<select id="'+selectName+'" name="'+selectName+'"></select>';
document.getElementById(selectName).onchange = function() {
toggleJoinButton(rowNumber);
}
// Create joinFunction thingy
selectName = 'joinFunction'+rowNumber;
td = tr.insertCell(tr.cells.length);
td.innerHTML = '<select id="'+selectName+'" name="'+selectName+'"></select>';
document.getElementById(selectName).options[0] = new Option('Intersect on', 'intersection');
document.getElementById(selectName).options[1] = new Option('Difference on', 'difference');
// Create second join selector
selectName = 'joinOnB'+rowNumber;
td = tr.insertCell(tr.cells.length);
td.innerHTML = '<select id="'+selectName+'" name="'+selectName+'"></select>';
document.getElementById(selectName).onchange = function() {
toggleJoinButton(rowNumber);
}
if (formDatabase && formTable) {
setJoinOnA(rowNumber, formJoinOnA, formDatabase, formTable);
setJoinOnB(rowNumber);
document.getElementById('joinOnA'+rowNumber).value = formJoinOnA;
document.getElementById('joinOnB'+rowNumber).value = formJoinOnB;
document.getElementById('joinFunction'+rowNumber).value = formJoinFunction;
} else {
// Hide the join constraint controls
hideJoinConstraints(rowNumber);
}
if (rowNumber == 1) {
hideJoinConstraints(rowNumber);
}
// Finally add a row containing a hidden 'join with' button
if (!(formDatabase || formTable || formJoinOnA || formJoinOnB)) {
addJoinButtonRow(tableId, rowNumber);
}
}
//-----------------------------------------------------------------------------
function setJoinOnA(rowNumber) {
var databaseName = document.getElementById('database'+rowNumber).value;
var tableName = document.getElementById('table'+rowNumber).value;
var prepend = 'table' + rowNumber + '.';
var s = document.getElementById('joinOnA'+rowNumber);
s.length = 0;
s.options[s.options.length] = new Option('Please select a column', '');
columnMap[rowNumber] = [ ];
// Do AJAX request
var r = new AjaxRequest;
var params = {
'parameters' : {
'func' : 'processAjaxRequest',
'dbName' : databaseName,
'tName' : tableName
},
'async' : false,
'onSuccess' : function(req) { processAjaxXml(req, s, columnMap[rowNumber], prepend); }
};
r.method = 'POST';
r.handleArguments(params);
r.process();
r.onCompleteInternal();
}
//-----------------------------------------------------------------------------
function setJoinOnB(rowNumber) {
if (rowNumber > 1) {
var s = document.getElementById('joinOnB'+rowNumber);
s.length = 0;
s.options[s.options.length] = new Option('Please select a column', '');
for (var currentRow = 1; currentRow < rowNumber; currentRow++) {
if (currentRow == 1 || document.getElementById('joinFunction'+currentRow).value != 'difference') {
for (var i = 0; i < columnMap[currentRow].length; i++) {
s.options[s.options.length] = new Option(columnMap[currentRow][i].key, columnMap[currentRow][i].value);
}
}
}
}
}
//-----------------------------------------------------------------------------
function updateFields(rowNumber,value1,value2, ccValue, fcValue) {
var s1 = document.getElementById(resultList1);
s1.length = 0;
s1.options[s1.options.length] = new Option('Please select a column', '');
var s2 = document.getElementById(resultList2);
s2.length = 0;
s2.options[s2.options.length] = new Option('Please select a column', '');
var cc = document.getElementById('joinConstraintColumn');
cc.length = 0;
cc.options[cc.options.length] = new Option('Please select a column', '');
var fc = document.getElementById('SQLFormFieldConstraintTarget');
fc.length = 0;
fc.options[fc.options.length] = new Option('Custom value', 'value');
for (var currentRow = 1; currentRow <= rowNumber; currentRow++) {
if (columnMap[currentRow] && (currentRow == 1 || document.getElementById('joinFunction'+currentRow).value != 'difference')) {
for (var i = 0; i < columnMap[currentRow].length; i++) {
s1.options[s1.options.length] = new Option(columnMap[currentRow][i].key, columnMap[currentRow][i].value);
s2.options[s2.options.length] = new Option(columnMap[currentRow][i].key, columnMap[currentRow][i].value);
cc.options[cc.options.length] = new Option(columnMap[currentRow][i].key, columnMap[currentRow][i].value);
fc.options[fc.options.length] = new Option(columnMap[currentRow][i].key, columnMap[currentRow][i].value);
}
}
}
if (value1) {
s1.value = value1;
}
if (value2) {
s2.value = value2;
}
if (ccValue) {
cc.value = ccValue;
}
if (fcValue) {
fc.value = fcValue;
}
}
//-----------------------------------------------------------------------------
function setTablesInSelectList(rowNumber, database) {
var s = document.getElementById('table'+rowNumber);
if (!s) {
alert('Fatal error: selectList (table'+rowNumber+') does not exist.');
}
// Empty select list.
s.length = 0;
s.options[s.options.length] = new Option('Please select a table', '');
// If the tables aren't cached in tableMap yet, fetch them using AJAX.
if (!tableMap[database]) {
tableMap[database] = [ ];
// Do AJAX request
var r = new AjaxRequest;
var params = {
'parameters' : {
'func' : 'processAjaxRequest',
'dbName' : database
},
'async' : false,
'onSuccess' : function(req) { processAjaxXml(req, s, tableMap[database]); }
};
r.method = 'POST';
r.handleArguments(params);
r.process();
// Must run this by hand because in sync-mode the internal event handlers are not called.
r.onCompleteInternal();
// If they are cached then put them in the select list.
} else {
for (var i = 0; i < tableMap[database].length; i++) {
s.options[s.options.length] = new Option(tableMap[database][i].key, tableMap[database][i].value);
}
}
}
//-----------------------------------------------------------------------------
function toggleJoinButton(rowNumber) {
if (document.getElementById('database'+rowNumber) && document.getElementById('table'+rowNumber)) {
if (
(document.getElementById('database'+rowNumber).selectedIndex > 0) &&
(document.getElementById('table'+rowNumber).selectedIndex > 0) &&
(
(rowNumber == 1) ||
(
(document.getElementById('joinOnA'+rowNumber).selectedIndex > 0) &&
(document.getElementById('joinOnB'+rowNumber).selectedIndex > 0)
)
)
) {
unhideElement('joinButton'+rowNumber);
} else {
hideElement('joinButton'+rowNumber);
}
}
}

View file

@ -0,0 +1,69 @@
function switchField(id, switchOn) {
e = document.getElementById(id);
if (!e) {
alert("Not a valid id: ["+id+"]");
}
if (switchOn) {
document.getElementById(id).disabled = false;
document.getElementById(id).style.display = '';
} else {
document.getElementById(id).disabled = true;
document.getElementById(id).style.display = 'none';
}
}
function switchListField(conditional, id) {
if (conditional == '') {
switchField(id+'-1', false);
switchField(id+'-2', false);
} else {
if (conditional == 100 || conditional == 101) {
switchField(id+'-1', true);
switchField(id+'-2', false);
} else {
switchField(id+'-1', false);
switchField(id+'-2', true);
}
}
}
function switchNumberField(conditional, id) {
if (conditional == '') {
switchField(id+'-1', false);
switchField(id+'-2', false);
} else {
if (conditional == 10) {
switchField(id+'-1', true);
switchField(id+'-2', true);
} else {
switchField(id+'-1', true);
switchField(id+'-2', false);
}
}
}
function switchTemporalField(conditional, id) {
if (conditional == '') {
switchField(id+'-1', false);
switchField(id+'-2', false);
} else {
if (conditional == 10) {
switchField(id+'-1', true);
switchField(id+'-2', true);
} else {
switchField(id+'-1', true);
switchField(id+'-2', false);
}
}
}
function switchTextField(conditional, id) {
if (conditional == '') {
switchField(id+'-1', false);
} else {
switchField(id+'-1', true);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB