mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 15:05:42 +00:00
BUGFIX: tidied up message output from UDF. MINOR: syntax fixes from JSLint. ENHANCEMENT: introducted the userforms namespace for future abstraction.
This commit is contained in:
parent
d080c15a49
commit
23ba211310
@ -1,15 +1,51 @@
|
||||
/**
|
||||
* Javascript required to power the user defined forms.
|
||||
*
|
||||
* Rewritten and refactored from the prototype version FieldEditor.
|
||||
* Rewritten from the prototype FieldEditor and constantly
|
||||
* being refactored to be be less specific on the UDF dom.
|
||||
*/
|
||||
(function($) {
|
||||
$(document).ready(function() {
|
||||
/**
|
||||
* Update the sortable properties of the form as a function
|
||||
* since the application will need to refresh the UI dynamically
|
||||
* Namespace
|
||||
*/
|
||||
function update_sortable() {
|
||||
var userforms = userforms || {};
|
||||
|
||||
/**
|
||||
* Messages from UserForms are translatable using i18n.
|
||||
*/
|
||||
userforms.messages = {
|
||||
CONFIRM_DELETE_ALL_SUBMISSIONS: 'All submissions will be permanently removed. Continue?',
|
||||
ERROR_CREATING_FIELD: 'Error creating field',
|
||||
ADDING_FIELD: 'Adding new field',
|
||||
ADDED_FIELD: 'Added new field',
|
||||
HIDE_OPTIONS: 'Hide options',
|
||||
SHOW_OPTIONS: 'Show options',
|
||||
ADDING_OPTION: 'Adding option',
|
||||
ADDED_OPTION: 'Added option',
|
||||
ERROR_CREATING_OPTION: 'Error creating option',
|
||||
REMOVED_OPTION: 'Removed option',
|
||||
ADDING_RULE: 'Adding rule'
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a given translatable string from a passed key. Keys
|
||||
* should be all caps without any spaces.
|
||||
*/
|
||||
userforms.message = function() {
|
||||
en = arguments[1] || userforms.messages[arguments[0]];
|
||||
|
||||
return ss.i18n._t("UserForms."+ arguments[0], en);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the sortable properties of the form as a function
|
||||
* since the application will need to refresh the UI dynamically based
|
||||
* on a number of factors including when the user adds a page or
|
||||
* swaps between pages
|
||||
*
|
||||
*/
|
||||
userforms.update = function() {
|
||||
$("#Fields_fields").sortable({
|
||||
handle: '.fieldHandler',
|
||||
cursor: 'pointer',
|
||||
@ -46,23 +82,27 @@
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
update_sortable();
|
||||
};
|
||||
|
||||
/**
|
||||
* Workaround for not refreshing the sort
|
||||
*/
|
||||
$(".fieldHandler").live('hover', function() {
|
||||
update_sortable();
|
||||
})
|
||||
userforms.update();
|
||||
});
|
||||
|
||||
/**
|
||||
* Kick off the UserForms UI
|
||||
*/
|
||||
userforms.update();
|
||||
|
||||
|
||||
/*--------------------- SUBMISSIONS ------------------------ */
|
||||
|
||||
/**
|
||||
* Delete a given Submission from the form
|
||||
*/
|
||||
$("#userforms-submissions .deleteSubmission").live('click',function(event) {
|
||||
$("#userforms-submissions .deleteSubmission").live('click', function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var deletedSubmission = $(this);
|
||||
@ -76,14 +116,16 @@
|
||||
/**
|
||||
* Delete all submissions and fade them out if successful
|
||||
*/
|
||||
$("#userforms-submissions .deleteAllSubmissions").live('click',function(event) {
|
||||
$("#userforms-submissions .deleteAllSubmissions").live('click', function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (!confirm(ss.i18n._t('UserForms.CONFIRMDELETEALLSUBMISSIONS', 'All submissions will be permanently removed. Continue?'))) return false;
|
||||
if(!confirm(userforms.message('CONFIRM_DELETE_ALL_SUBMISSIONS'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var that = this;
|
||||
var self = this;
|
||||
$.post($(this).attr('href'), function(data) {
|
||||
$(that).parents('#userforms-submissions').children().fadeOut();
|
||||
$(self).parents('#userforms-submissions').children().fadeOut();
|
||||
});
|
||||
|
||||
return false;
|
||||
@ -104,7 +146,7 @@
|
||||
}
|
||||
|
||||
// Give the user some feedback
|
||||
statusMessage(ss.i18n._t('UserForms.ADDINGNEWFIELD', 'Adding New Field'));
|
||||
statusMessage(userforms.message('ADDING_FIELD'));
|
||||
|
||||
// variables
|
||||
var action = $("#Form_EditForm").attr("action") + '/field/Fields/addfield';
|
||||
@ -121,7 +163,7 @@
|
||||
// create a new field
|
||||
success: function(msg){
|
||||
$('#Fields_fields').append(msg);
|
||||
statusMessage(ss.i18n._t('UserForms.ADDEDNEWFIELD', 'Added New Field'));
|
||||
statusMessage(userforms.message('ADDED_FIELD'));
|
||||
|
||||
// update the internal lists
|
||||
var name = $("#Fields_fields li.EditableFormField:last").attr("id").split(' ');
|
||||
@ -131,7 +173,7 @@
|
||||
|
||||
// error creating new field
|
||||
error: function(request, text, error) {
|
||||
statusMessage(ss.i18n._t('UserForms.ERRORCREATINGFIELD', 'Error Creating Field'));
|
||||
statusMessage(userforms.message('ERROR_CREATING_FIELD'));
|
||||
}
|
||||
});
|
||||
|
||||
@ -148,8 +190,9 @@
|
||||
$('.EditableFormField .fieldInfo .text').live('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]) {
|
||||
if($(domElement).val() === name[2]) {
|
||||
$(domElement).text(value);
|
||||
}
|
||||
});
|
||||
@ -165,12 +208,12 @@
|
||||
var extraOptions = parentID.children(".extraOptions");
|
||||
if(extraOptions) {
|
||||
if(extraOptions.hasClass('hidden')) {
|
||||
$(this).html(ss.i18n._t('UserForms.HIDEOPTIONS', 'Hide Options'));
|
||||
$(this).html(userforms.message('HIDE_OPTIONS'));
|
||||
$(this).addClass("showing");
|
||||
extraOptions.removeClass('hidden').show();
|
||||
}
|
||||
else {
|
||||
$(this).html(ss.i18n._t('UserForms.SHOWOPTIONS', 'Show Options'));
|
||||
$(this).html(userforms.message('SHOW_OPTIONS'));
|
||||
$(this).removeClass("showing");
|
||||
extraOptions.addClass('hidden').hide();
|
||||
}
|
||||
@ -185,16 +228,17 @@
|
||||
$(".EditableFormField .delete").live('click', function() {
|
||||
// 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) {
|
||||
|
||||
$("#Fields_fields .customRules select.fieldOption option").each(function(i, ele) {
|
||||
if($(ele).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();
|
||||
if($(ele).parent('select.customRuleField').val() === $(ele).val()) {
|
||||
$(ele).parents('li.customRule').remove();
|
||||
}
|
||||
// otherwise remove the option
|
||||
else {
|
||||
$(domElement).remove();
|
||||
// otherwise remove the option
|
||||
$(ele).remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -211,7 +255,7 @@
|
||||
$(".EditableFormField .addableOption").live('click', function() {
|
||||
|
||||
// Give the user some feedback
|
||||
statusMessage(ss.i18n._t('UserForms.ADDINGNEWFIELD', 'Adding New Option'));
|
||||
statusMessage(userforms.message('ADDING_OPTION'));
|
||||
|
||||
// variables
|
||||
var options = $(this).parent("li");
|
||||
@ -227,12 +271,12 @@
|
||||
// create a new field
|
||||
success: function(msg){
|
||||
options.before(msg);
|
||||
statusMessage(ss.i18n._t('UserForms.ADDEDNEWFIELD', 'Added New Field'));
|
||||
statusMessage(userforms.message('ADDED_OPTION'));
|
||||
},
|
||||
|
||||
// error creating new field
|
||||
error: function(request, text, error) {
|
||||
statusMessage(ss.i18n._t('UserForms.ERRORCREATINGFIELD', 'Error Creating Field'));
|
||||
statusMessage(userforms.message('ERROR_CREATING_OPTION'));
|
||||
}
|
||||
});
|
||||
|
||||
@ -249,7 +293,7 @@
|
||||
$(this).parent("li").hide();
|
||||
|
||||
// Give the user some feedback
|
||||
statusMessage(ss.i18n._t('UserForms.REMOVINGOPTION', 'Removed Option'));
|
||||
statusMessage(userforms.message('REMOVED_OPTION'));
|
||||
return false;
|
||||
});
|
||||
|
||||
@ -258,7 +302,8 @@
|
||||
*/
|
||||
$(".customRules .conditionOption").live('change',function(){
|
||||
var valueInput = $(this).siblings(".ruleValue");
|
||||
if($(this).val() != "" && $(this).val() != "IsBlank" && $(this).val() != "IsNotBlank") {
|
||||
|
||||
if($(this).val() && $(this).val() !== "IsBlank" && $(this).val() !== "IsNotBlank") {
|
||||
valueInput.removeClass("hidden");
|
||||
}
|
||||
else {
|
||||
@ -280,7 +325,7 @@
|
||||
*/
|
||||
$(".customRules .addCondition").live('click', function() {
|
||||
// Give the user some feedback
|
||||
statusMessage(ss.i18n._t('UserForms.ADDINGNEWRULE', 'Adding New Rule'));
|
||||
statusMessage(userforms.message('ADDING_RULE'));
|
||||
|
||||
// get the fields li which to duplicate
|
||||
var currentRules = $(this).parent("li").parent("ul");
|
||||
@ -311,5 +356,4 @@
|
||||
return false;
|
||||
});
|
||||
});
|
||||
})
|
||||
(jQuery);
|
||||
})(jQuery);
|
Loading…
x
Reference in New Issue
Block a user