%--
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>
<%@ include file="/init.jsp" %>
<%
String titleXml = GetterUtil.getString(LocalizationUtil.getLocalizationXmlFromPreferences(portletPreferences, renderRequest, "title"), StringPool.BLANK);
String descriptionXml = GetterUtil.getString(LocalizationUtil.getLocalizationXmlFromPreferences(portletPreferences, renderRequest, "description"), StringPool.BLANK);
boolean requireCaptcha = GetterUtil.getBoolean(portletPreferences.getValue("requireCaptcha", StringPool.BLANK));
String successURL = portletPreferences.getValue("successURL", StringPool.BLANK);
boolean sendAsEmail = GetterUtil.getBoolean(portletPreferences.getValue("sendAsEmail", StringPool.BLANK));
String emailFromName = WebFormUtil.getEmailFromName(portletPreferences, company.getCompanyId());
String emailFromAddress = WebFormUtil.getEmailFromAddress(portletPreferences, company.getCompanyId());
String emailAddress = portletPreferences.getValue("emailAddress", StringPool.BLANK);
String subject = portletPreferences.getValue("subject", StringPool.BLANK);
boolean saveToDatabase = GetterUtil.getBoolean(portletPreferences.getValue("saveToDatabase", StringPool.BLANK));
String databaseTableName = portletPreferences.getValue("databaseTableName", StringPool.BLANK);
boolean saveToFile = GetterUtil.getBoolean(portletPreferences.getValue("saveToFile", StringPool.BLANK));
String fileName = portletPreferences.getValue("fileName", StringPool.BLANK);
boolean fieldsEditingDisabled = false;
if (WebFormUtil.getTableRowsCount(company.getCompanyId(), databaseTableName) > 0) {
fieldsEditingDisabled = true;
}
%>
<%
String taglibExport = "submitForm(document.hrefFm, '" + exportURL + "', false);";
%>
<%
String taglibDelete = "submitForm(document." + renderResponse.getNamespace() + "fm, '" + deleteURL + "');";
%>
<%
String formFieldsIndexesParam = ParamUtil.getString(renderRequest, "formFieldsIndexes") ;
int[] formFieldsIndexes = null;
if (Validator.isNotNull(formFieldsIndexesParam)) {
formFieldsIndexes = StringUtil.split(formFieldsIndexesParam, 0);
}
else {
formFieldsIndexes = new int[0];
for (int i = 1; true; i++) {
String fieldLabel = PrefsParamUtil.getString(portletPreferences, request, "fieldLabel" + i);
if (Validator.isNull(fieldLabel)) {
break;
}
formFieldsIndexes = ArrayUtil.append(formFieldsIndexes, i);
}
if (formFieldsIndexes.length == 0) {
formFieldsIndexes = ArrayUtil.append(formFieldsIndexes, -1);
}
}
int index = 1;
for (int formFieldsIndex : formFieldsIndexes) {
request.setAttribute("configuration.jsp-index", String.valueOf(index));
request.setAttribute("configuration.jsp-formFieldsIndex", String.valueOf(formFieldsIndex));
request.setAttribute("configuration.jsp-fieldsEditingDisabled", String.valueOf(fieldsEditingDisabled));
%>
<%
index++;
}
%>
var toggleOptions = function(event) {
var select = this;
var formRow = select.ancestor('.lfr-form-row');
var value = select.val();
var optionsDiv = formRow.one('.options');
if ((value == 'options') || (value == 'radio')) {
optionsDiv.all('label').show();
optionsDiv.show();
}
else if (value == 'paragraph') {
// Show just the text field and not the labels since there
// are multiple choice inputs
optionsDiv.all('label').hide();
optionsDiv.show();
}
else {
optionsDiv.hide();
}
var optionalControl = formRow.one('.optional-control').ancestor();
var labelName = formRow.one('.label-name');
if (value == 'paragraph') {
var inputName = labelName.one('input.field');
var formFieldsIndex = select.attr('id').match(/\d+$/);
inputName.val('' + formFieldsIndex);
inputName.fire('change');
labelName.hide();
optionalControl.hide();
optionalControl.all('input[type="checkbox"]').attr('checked', 'true');
optionalControl.all('input[type="hidden"]').attr('value', 'true');
}
else {
optionalControl.show();
labelName.show();
}
};
var webFields = A.one('.webFields');
webFields.all('select').each(toggleOptions);
webFields.delegate(['change', 'click', 'keydown'], toggleOptions, 'select');
var toggleValidationOptions = function(event) {
this.next().toggle();
};
webFields.delegate('click', toggleValidationOptions, '.validation-link');
webFields.delegate(
'change',
function(event) {
var input = event.currentTarget;
var row = input.ancestor('.field-row');
var label = row.one('.field-title');
if (label) {
label.html(input.get('value'));
}
},
'.label-name input'
);
new Liferay.AutoFields(
{
contentBox: webFields,
fieldIndexes: 'formFieldsIndexes',
namespace: '',
sortable: true,
sortableHandle: '.field-label',
url: '<%= editFieldURL %>'
}
).render();