Add event question JS to app.js

This commit is contained in:
Dave 2016-03-27 21:12:44 +01:00
parent e7b29cf6d8
commit a8aa0e64b4
1 changed files with 80 additions and 32 deletions

View File

@ -1,5 +1,3 @@
window.Attendize = {
DateFormat: 'dd-MM-yyyy',
DateTimeFormat: 'dd-MM-yyyy hh:mm',
@ -76,6 +74,12 @@ $(function () {
},
error: function (data, statusText, xhr, $form) {
// Form validation error.
if (422 == data.status) {
processFormErrors($form, $.parseJSON(data.responseText));
return;
}
showMessage('Whoops!, it looks like something went wrong on our servers.\n\
Please try again, or contact support if the problem persists.');
@ -115,24 +119,7 @@ $(function () {
break;
case 'error':
$.each(data.messages, function (index, error) {
var $input = $(':input[name=' + index + ']', $form);
if ($input.prop('type') === 'file') {
$('#input-' + $input.prop('name')).append('<div class="help-block error">' + error + '</div>')
.parent()
.addClass('has-error');
} else {
$input.after('<div class="help-block error">' + error + '</div>')
.parent()
.addClass('has-error');
}
});
var $submitButton = $form.find('input[type=submit]');
toggleSubmitDisabled($submitButton);
processFormErrors($form, data.messages);
break;
default:
@ -309,10 +296,6 @@ $(function () {
/**
* Toggle checkboxes
*/
$(document.body).on('click', '.check-all', function (e) {
var toggleClass = $(this).data('check-class');
$('.' + toggleClass).each(function () {
@ -395,6 +378,71 @@ $(function () {
});
function changeQuestionType(select)
{
var select = $(select);
var selected = select.find(':selected');
if (selected.data('has-options') == '1') {
$('#question-options').removeClass('hide');
} else {
$('#question-options').addClass('hide');
}
}
function submitQuestionForm()
{
$('#edit-question-form').submit();
}
function addQuestionOption()
{
var tbody = $('#question-options tbody');
var questionOption = $('#question-option-template').html();
tbody.append(questionOption);
}
function removeQuestionOption(removeBtn)
{
var removeBtn = $(removeBtn);
var tbody = removeBtn.parents('tbody');
if (tbody.find('tr').length > 1) {
removeBtn.parents('tr').remove();
} else {
alert('You must have at least one option.');
}
}
function processFormErrors($form, errors)
{
$.each(errors, function (index, error)
{
var $input = $(':input[name=' + index + ']', $form);
if ($input.prop('type') === 'file') {
$('#input-' + $input.prop('name')).append('<div class="help-block error">' + error + '</div>')
.parent()
.addClass('has-error');
} else {
$input.after('<div class="help-block error">' + error + '</div>')
.parent()
.addClass('has-error');
}
});
var $submitButton = $form.find('input[type=submit]');
toggleSubmitDisabled($submitButton);
}
function reloadPageDelayed()
{
setTimeout(function () {
location.reload();
}, 2000);
}
/**
*