2009-04-17 04:26:40 +02:00
|
|
|
|
/**
|
|
|
|
|
* Javascript required to power the user defined forms.
|
|
|
|
|
*
|
|
|
|
|
* Rewritten and refactored from the prototype version FieldEditor.
|
|
|
|
|
*
|
|
|
|
|
* @todo Upgrade to jQuery 1.3 so we can use live rather
|
|
|
|
|
* then livequery
|
|
|
|
|
*/
|
2009-04-15 06:23:43 +02:00
|
|
|
|
(function($) {
|
|
|
|
|
$(document).ready(function() {
|
2009-04-17 04:26:40 +02:00
|
|
|
|
|
|
|
|
|
/*--------------------- SUBMISSIONS ------------------------ */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete a given Submission from the form, or all submissions
|
|
|
|
|
* we let the href of the delete link to do all the work for us
|
|
|
|
|
*/
|
|
|
|
|
|
2009-04-15 06:23:43 +02:00
|
|
|
|
$("#FormSubmissions .deleteSubmission").click(function() {
|
|
|
|
|
var deletedSubmission = $(this);
|
|
|
|
|
$.post($(this).attr('href'), function(data) {
|
|
|
|
|
deletedSubmission.parents('div.report').fadeOut();
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2009-04-17 04:26:40 +02:00
|
|
|
|
|
|
|
|
|
/*-------------------- FIELD EDITOR ----------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new instance of a field in the current form
|
|
|
|
|
* area. the type information should all be on this object
|
|
|
|
|
*/
|
|
|
|
|
|
2009-04-27 04:30:32 +02:00
|
|
|
|
$("div.FieldEditor .MenuHolder .action").livequery('click',function() {
|
|
|
|
|
|
2009-04-17 04:26:40 +02:00
|
|
|
|
// if this form is readonly...
|
|
|
|
|
if($("#Fields").hasClass('readonly')) return false;
|
|
|
|
|
|
|
|
|
|
// Give the user some feedback
|
|
|
|
|
statusMessage(ss.i18n._t('UserForms.ADDINGNEWFIELD', 'Adding New Field'));
|
|
|
|
|
|
|
|
|
|
// variables
|
|
|
|
|
var action = $("#Form_EditForm").attr("action") + '/field/Fields/addfield';
|
|
|
|
|
var length = $(".FieldInfo").length + 1;
|
2009-04-18 04:49:46 +02:00
|
|
|
|
var securityID = ($("#SecurityID").length > 0) ? '&SecurityID='+$("#SecurityID").attr("value") : '';
|
2009-04-27 02:20:20 +02:00
|
|
|
|
var type = $(this).siblings("select").val();
|
2009-04-27 04:30:32 +02:00
|
|
|
|
|
2009-04-17 04:26:40 +02:00
|
|
|
|
//send ajax request to the page
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "GET",
|
|
|
|
|
url: action,
|
|
|
|
|
data: 'NewID='+ length +"&Type="+ type + securityID,
|
|
|
|
|
|
|
|
|
|
// create a new field
|
|
|
|
|
success: function(msg){
|
|
|
|
|
$('#Fields_fields').append(msg);
|
|
|
|
|
statusMessage(ss.i18n._t('UserForms.ADDEDNEWFIELD', 'Added New Field'));
|
2009-04-24 00:52:08 +02:00
|
|
|
|
|
|
|
|
|
//update the internal lists
|
|
|
|
|
var name = $("#Fields_fields li.EditableFormField:last").attr("id").split(' ');
|
|
|
|
|
|
2009-05-06 05:34:40 +02:00
|
|
|
|
$("#Fields_fields select.fieldOption").each(function(i, domElement) {
|
2009-05-06 06:11:34 +02:00
|
|
|
|
$(domElement).append("<option value='"+ name[2] +"'>New "+ name[2] + "</option>");
|
2009-05-06 05:34:40 +02:00
|
|
|
|
});
|
2009-04-17 04:26:40 +02:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// error creating new field
|
|
|
|
|
error: function(request, text, error) {
|
|
|
|
|
statusMessage(ss.i18n._t('UserForms.ERRORCREATINGFIELD', 'Error Creating Field'));
|
|
|
|
|
}
|
|
|
|
|
});
|
2009-04-27 02:20:20 +02:00
|
|
|
|
return false;
|
2009-04-17 04:26:40 +02:00
|
|
|
|
});
|
2009-04-24 00:52:08 +02:00
|
|
|
|
/**
|
|
|
|
|
* Upon renaming a field we should go through and rename all the
|
|
|
|
|
* fields in the select fields to use this new field title. We can
|
|
|
|
|
* just worry about the title text - don't mess around with the keys
|
|
|
|
|
*/
|
|
|
|
|
$('.EditableFormField .fieldInfo .text').livequery('change', function() {
|
|
|
|
|
var value = $(this).val();
|
|
|
|
|
var name = $(this).parents("li").attr("id").split(' ');
|
|
|
|
|
$("#Fields_fields select.fieldOption option").each(function(i, domElement) {
|
|
|
|
|
if($(domElement).val() == name[2]) {
|
|
|
|
|
$(domElement).text(value);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
2009-04-17 04:26:40 +02:00
|
|
|
|
/**
|
|
|
|
|
* Show the more options popdown. Or hide it if we
|
|
|
|
|
* currently have it open
|
|
|
|
|
*/
|
|
|
|
|
$(".EditableFormField .moreOptions").livequery('click',function() {
|
2009-04-21 07:10:39 +02:00
|
|
|
|
|
2009-04-17 04:26:40 +02:00
|
|
|
|
var parentID = $(this).parents(".EditableFormField");
|
|
|
|
|
if(parentID) {
|
|
|
|
|
var extraOptions = parentID.children(".extraOptions");
|
|
|
|
|
if(extraOptions) {
|
|
|
|
|
if(extraOptions.hasClass('hidden')) {
|
2009-05-06 05:46:12 +02:00
|
|
|
|
$(this).html(ss.i18n._t('UserForms.HIDEOPTIONS', 'Hide Options'));
|
2009-04-21 07:10:39 +02:00
|
|
|
|
$(this).addClass("showing");
|
2009-04-17 04:26:40 +02:00
|
|
|
|
extraOptions.removeClass('hidden').show();
|
|
|
|
|
}
|
|
|
|
|
else {
|
2009-05-06 05:46:12 +02:00
|
|
|
|
$(this).html(ss.i18n._t('UserForms.SHOWOPTIONS', 'Show Options'));
|
2009-04-21 07:10:39 +02:00
|
|
|
|
$(this).removeClass("showing");
|
2009-04-17 04:26:40 +02:00
|
|
|
|
extraOptions.addClass('hidden').hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete a field from the user defined form
|
|
|
|
|
*/
|
|
|
|
|
$(".EditableFormField .delete").livequery('click', function() {
|
2009-04-24 00:52:08 +02:00
|
|
|
|
// remove all the rules with relate to this field
|
|
|
|
|
var text = $(this).parents("li").find(".fieldInfo .text").val();
|
|
|
|
|
$("#Fields_fields .customRules select.fieldOption option").each(function(i, domElement) {
|
|
|
|
|
if($(domElement).text() == text) {
|
|
|
|
|
|
|
|
|
|
// check to see if this is selected. If it is then just remove the whole rule
|
|
|
|
|
if($(domElement).parent('select.customRuleField').val() == $(domElement).val()) {
|
|
|
|
|
$(domElement).parents('li.customRule').remove();
|
|
|
|
|
}
|
|
|
|
|
// otherwise remove the option
|
|
|
|
|
else {
|
|
|
|
|
$(domElement).remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2009-04-17 04:26:40 +02:00
|
|
|
|
$(this).parents(".EditableFormField").remove();
|
2009-04-20 01:22:22 +02:00
|
|
|
|
return false;
|
2009-04-17 04:26:40 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a suboption to a radio field or to a dropdown box
|
|
|
|
|
* for example
|
|
|
|
|
*/
|
|
|
|
|
$(".EditableFormField .addableOption").livequery('click', function() {
|
|
|
|
|
|
|
|
|
|
// Give the user some feedback
|
|
|
|
|
statusMessage(ss.i18n._t('UserForms.ADDINGNEWFIELD', 'Adding New Option'));
|
|
|
|
|
|
|
|
|
|
// variables
|
|
|
|
|
var options = $(this).parent("li");
|
|
|
|
|
var action = $("#Form_EditForm").attr("action") + '/field/Fields/addoptionfield';
|
|
|
|
|
var parent = $(this).attr("rel");
|
|
|
|
|
|
|
|
|
|
//send ajax request to the page
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "GET",
|
|
|
|
|
url: action,
|
2009-05-06 05:34:40 +02:00
|
|
|
|
data: 'Parent='+ parent,
|
2009-04-17 04:26:40 +02:00
|
|
|
|
|
|
|
|
|
// create a new field
|
|
|
|
|
success: function(msg){
|
|
|
|
|
options.before(msg);
|
|
|
|
|
statusMessage(ss.i18n._t('UserForms.ADDEDNEWFIELD', 'Added New Field'));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// error creating new field
|
|
|
|
|
error: function(request, text, error) {
|
|
|
|
|
statusMessage(ss.i18n._t('UserForms.ERRORCREATINGFIELD', 'Error Creating Field'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete a suboption such as an dropdown option or a
|
|
|
|
|
* checkbox field
|
|
|
|
|
*/
|
|
|
|
|
$(".EditableFormField .deleteOption").livequery('click', function() {
|
|
|
|
|
// pass the deleted status onto the element
|
2009-05-06 05:34:40 +02:00
|
|
|
|
$(this).parent("li").children("[type=text]").attr("value", "field-node-deleted");
|
|
|
|
|
$(this).parent("li").hide();
|
2009-04-17 04:26:40 +02:00
|
|
|
|
|
|
|
|
|
// Give the user some feedback
|
|
|
|
|
statusMessage(ss.i18n._t('UserForms.REMOVINGOPTION', 'Removed Option'));
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2009-04-18 04:49:46 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sort Fields in the Field List
|
|
|
|
|
*/
|
2009-04-18 05:08:34 +02:00
|
|
|
|
$("#Fields_fields").livequery(function() {
|
|
|
|
|
$(this).sortable({
|
|
|
|
|
handle : '.fieldHandler',
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
items: 'li.EditableFormField',
|
|
|
|
|
placeholder: 'removed-form-field',
|
|
|
|
|
opacity: 0.6,
|
|
|
|
|
revert: true,
|
|
|
|
|
change : function (event, ui) {
|
|
|
|
|
$("#Fields_fields").sortable('refreshPositions');
|
|
|
|
|
},
|
|
|
|
|
update : function (event, ui) {
|
|
|
|
|
// get all the fields
|
|
|
|
|
var sort = 1;
|
|
|
|
|
$("li.EditableFormField").each(function() {
|
|
|
|
|
$(this).find(".sortHidden").val(sort++);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sort Options in a Field List - Such as options in a
|
|
|
|
|
* dropdown field.
|
|
|
|
|
*/
|
|
|
|
|
$(".editableOptions").livequery(function() {
|
|
|
|
|
$(this).sortable({
|
|
|
|
|
handle : '.handle',
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
items: 'li',
|
|
|
|
|
placeholder: 'removed-form-field',
|
|
|
|
|
opacity: 0.6,
|
|
|
|
|
revert: true,
|
|
|
|
|
change : function (event, ui) {
|
|
|
|
|
$(this).sortable('refreshPositions');
|
|
|
|
|
},
|
|
|
|
|
update : function (event, ui) {
|
|
|
|
|
// get all the fields
|
|
|
|
|
var sort = 1;
|
|
|
|
|
$(".editableOptions li").each(function() {
|
|
|
|
|
$(this).find(".sortOptionHidden").val(sort++);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2009-04-18 04:49:46 +02:00
|
|
|
|
});
|
2009-04-24 00:52:08 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Custom Rules Interface
|
|
|
|
|
*/
|
|
|
|
|
$(".customRules .conditionOption").livequery('change', function(){
|
|
|
|
|
var valueInput = $(this).siblings(".ruleValue");
|
|
|
|
|
if($(this).val() == "ValueNot" || $(this).val() == "HasValue") {
|
|
|
|
|
valueInput.show();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
valueInput.hide();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
/**
|
|
|
|
|
* Delete a custom rule
|
|
|
|
|
*/
|
|
|
|
|
$(".customRules .deleteCondition").livequery('click', function() {
|
|
|
|
|
$(this).parent("li").fadeOut().remove();
|
|
|
|
|
});
|
|
|
|
|
/**
|
|
|
|
|
* Adding a custom rule to a given form
|
|
|
|
|
*/
|
|
|
|
|
$(".customRules .addCondition").livequery('click', function() {
|
2009-05-06 06:11:34 +02:00
|
|
|
|
|
2009-04-24 00:52:08 +02:00
|
|
|
|
// Give the user some feedback
|
|
|
|
|
statusMessage(ss.i18n._t('UserForms.ADDINGNEWRULE', 'Adding New Rule'));
|
|
|
|
|
|
2009-05-06 05:34:40 +02:00
|
|
|
|
// get the fields li which to duplicate
|
|
|
|
|
var currentRules = $(this).parent("li").parent("ul");
|
|
|
|
|
var defaultRule = currentRules.children("li.hidden:first");
|
|
|
|
|
var newRule = defaultRule.clone();
|
2009-04-24 00:52:08 +02:00
|
|
|
|
|
2009-05-06 05:34:40 +02:00
|
|
|
|
newRule.children(".customRuleField").each(function(i, domElement) {
|
2009-04-24 00:52:08 +02:00
|
|
|
|
var currentName = domElement.name.split("][");
|
|
|
|
|
currentName[3] = currentName[2];
|
2009-05-06 05:34:40 +02:00
|
|
|
|
currentName[2] = currentRules.children().size() + 1;
|
2009-04-24 00:52:08 +02:00
|
|
|
|
domElement.name = currentName.join("][");
|
|
|
|
|
});
|
2009-05-06 06:11:34 +02:00
|
|
|
|
|
2009-05-06 05:34:40 +02:00
|
|
|
|
// remove hidden tag
|
|
|
|
|
newRule.removeClass("hidden");
|
|
|
|
|
|
|
|
|
|
// update the fields dropdown
|
|
|
|
|
newRule.children("select.fieldOption").empty();
|
2009-05-06 06:11:34 +02:00
|
|
|
|
|
2009-05-06 05:34:40 +02:00
|
|
|
|
$("#Fields_fields li.EditableFormField").each(function (i, domElement) {
|
2009-05-06 06:11:34 +02:00
|
|
|
|
var name = $(domElement).attr("id").split(' ');
|
|
|
|
|
newRule.children("select.fieldOption").append("<option value='"+ name[2] + "'>"+ $(domElement).find(".text").val() + "</option>");
|
2009-04-24 00:52:08 +02:00
|
|
|
|
});
|
2009-05-06 05:34:40 +02:00
|
|
|
|
|
|
|
|
|
// append to the list
|
|
|
|
|
currentRules.append(newRule);
|
|
|
|
|
|
2009-04-24 00:52:08 +02:00
|
|
|
|
return false;
|
|
|
|
|
});
|
2009-04-17 04:26:40 +02:00
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
(jQuery);
|