// Copyright 2002-2006 Adobe Macromedia Software LLC and its licensors. All rights reserved.
// *************** GLOBALS VARS *****************
var HELP_DOC = MM.HELP_sbPHPInsertRecord;
var SB_NAME = dwscripts.getSBFileName();
var _FormName = new TagMenu(SB_NAME, "form__tag", "form");
var _ConnectionName = new ConnectionMenu("Recordset.htm", "ConnectionName");
var _TableName = new ConnectionTableMenu(SB_NAME, "TableName");
var _ColumnList = null;
var _SubmittedValueList = new FormFieldsMenu(SB_NAME, "SubmittedValueList", true,
FormFieldsMenu.LABELS_MASK_FORMREF,
[{prop: "type", value: "submit"},
{prop: "type", value: "reset"},
{prop: "name", value: "MM_insert"},
{prop: "name", value: "MM_delete"},
{prop: "name", value: "MM_update"}]);
var _FieldColFormat = null;
var _Redirect_url = new TextField(SB_NAME, "Redirect_url");
// Array constants to hold field format values and labels from the _FieldColFormat
// control.
var FieldColFormatValues = null;
var FieldColFormatLabels = null;
// Constants used to index into the above arrays.
INDEX_FORMAT_TEXT = 0;
INDEX_FORMAT_INTEGER = 1;
INDEX_FORMAT_NUMERIC = 1;
INDEX_FORMAT_DOUBLE = 2;
INDEX_FORMAT_DATE = 3;
INDEX_FORMAT_CHECKBOX_YN = 4;
INDEX_FORMAT_CHECKBOX_POS = 5;
INDEX_FORMAT_CHECKBOX_NEG = 6;
// ***************** LOCAL FUNCTIONS ******************
//--------------------------------------------------------------------
// FUNCTION:
// initializeUI
//
// DESCRIPTION:
// This function is called in the onLoad event. It is responsible
// for initializing the UI.
//
// ARGUMENTS:
// none
//
// RETURNS:
// nothing
//--------------------------------------------------------------------
function initializeUI()
{
// Get the UI elements
setConnectionSuccess = _ConnectionName.initializeUI();
if (!setConnectionSuccess)
{
clickedCancel();
}
_FormName.initializeUI();
_ConnectionName.initializeUI();
_TableName.initializeUI();
_ColumnList = new ListControl("ColumnList");
_SubmittedValueList.initializeUI(_FormName);
_Redirect_url.initializeUI();
// Load the labels and values from the html for _FieldColFormat. The store the
// loaded labels and values for later use.
_FieldColFormat = new ListControl("FieldColFormat", null, true);
FieldColFormatValues = _FieldColFormat.getValue('all');
FieldColFormatLabels = _FieldColFormat.get('all');
updateUI('ConnectionName');
updateUI('FormName');
setSubmitAsDisabledState();
}
//--------------------------------------------------------------------
// FUNCTION:
// updateUI
//
// DESCRIPTION:
// This function is called by the UI controls to handle UI updates
//
// ARGUMENTS:
// control - string - the name of the control sending the event
// event - string - the event which is being sent
//
// RETURNS:
// nothing
//--------------------------------------------------------------------
function updateUI(control, event)
{
if (control == "FormName")
{
_SubmittedValueList.updateUI(_FormName, event);
}
else if (control == "ConnectionName")
{
// update the table
_TableName.updateUI(_ConnectionName, event);
}
else if (control == "TableName")
{
// Update the ColumnList
var columnInfo = dwscripts.getColumnValueList
(_ConnectionName.getValue(), _TableName.getValue());
var names = new Array();
for (var i=0; i < columnInfo.length; i++)
{
// map the columns to matching form items
setDefaultMapping(columnInfo[i], _SubmittedValueList.get('all'),
_SubmittedValueList.getValue('all'));
names.push(getDisplayString(columnInfo[i]));
}
_ColumnList.setAll(names, columnInfo);
updateUI("ColumnList");
}
else if (control=="ColumnList")
{
var columnInfo = _ColumnList.getValue();
if (columnInfo)
{
var value = getSubmitAsValueFromVarName(columnInfo.getVariableName());
_SubmittedValueList.pick(value);
_FieldColFormat.pickValue(columnInfo.getSubmitAs());
}
setSubmitAsDisabledState();
}
else if (control=="FieldColFormat")
{
var columnInfo = _ColumnList.getValue();
columnInfo.setSubmitAs(_FieldColFormat.getValue());
_ColumnList.set(getDisplayString(columnInfo));
setSubmitAsDisabledState();
}
else if (control == "SubmittedValueList")
{
if (event == "onChange")
{
var columnInfo = _ColumnList.getValue();
if (columnInfo)
{
columnInfo.setVariableName(getVarNameFromSubmitAsValue(_SubmittedValueList.get()));
// Set the default SubmitAs value based on the new submitted value type.
setDefaultSubmitAs(columnInfo, _SubmittedValueList.get('all'),
_SubmittedValueList.getValue('all'));
_FieldColFormat.pickValue(columnInfo.getSubmitAs());
_ColumnList.set(getDisplayString(columnInfo));
setSubmitAsDisabledState();
}
}
}
else if (control == "Redirect_url")
{
var theRedirect_url = dw.browseForFileURL("select", MM.LABEL_FileRedirect,0,0);
if (theRedirect_url.length > 0)
{
// convert any script blocks to concat values
theRedirect_url = theRedirect_url.replace(/<\?php\s+(?:echo\s+)?/gi, "\" . ");
theRedirect_url = theRedirect_url.replace(/;?\s*\?>/gi, " . \"");
_Redirect_url.setValue(theRedirect_url);
}
}
// default case - throw error message
else
{
alert("The following control does not exist: " + control);
}
}
//--------------------------------------------------------------------
// FUNCTION:
// findServerBehaviors
//
// DESCRIPTION:
// Returns an array of ServerBehavior objects, each one representing
// an instance of this Server Behavior on the page
//
// ARGUMENTS:
// none
//
// RETURNS:
// JavaScript Array of ServerBehavior objects
//--------------------------------------------------------------------
function findServerBehaviors()
{
var sbArray = new Array();
sbArray = dwscripts.findSBs(MM.LABEL_TitleInsertRecord, SBInsertRecord);
for (var i=0; i < sbArray.length; i++)
{
sbArray[i].postProcessFind();
}
return sbArray;
}
//--------------------------------------------------------------------
// FUNCTION:
// canApplyServerBehavior
//
// DESCRIPTION:
// Returns true if a Server Behavior can be applied to the current
// document
//
// ARGUMENTS:
// sbObj - ServerBehavior object - one of the objects returned
// from findServerBehaviors
//
// RETURNS:
// boolean - true if the behavior can be applied, false otherwise
//--------------------------------------------------------------------
function canApplyServerBehavior(sbObj)
{
var success = true;
var errMsgStr = "";
if (findAllForms().length == 0) { //if there are no forms
errMsgStr += MM.MSG_NoForms;
success = false;
}
if (errMsgStr) alert(errMsgStr); //popup error message
return success;
}
//--------------------------------------------------------------------
// FUNCTION:
// applyServerBehavior
//
// DESCRIPTION:
// Collects values from the form elements in the dialog box and
// adds the Server Behavior to the user's document
//
// ARGUMENTS:
// sbObj - ServerBehavior object - one of the objects returned
// from findServerBehaviors
//
// RETURNS: