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 = { window.Attendize = {
DateFormat: 'dd-MM-yyyy', DateFormat: 'dd-MM-yyyy',
DateTimeFormat: 'dd-MM-yyyy hh:mm', DateTimeFormat: 'dd-MM-yyyy hh:mm',
@ -52,9 +50,9 @@ $(function () {
* -------------------- * --------------------
* Ajaxify those forms * Ajaxify those forms
* -------------------- * --------------------
* *
* All forms with the 'ajax' class will automatically handle showing errors etc. * All forms with the 'ajax' class will automatically handle showing errors etc.
* *
*/ */
$('form.ajax').ajaxForm({ $('form.ajax').ajaxForm({
delegation: true, delegation: true,
@ -76,6 +74,12 @@ $(function () {
}, },
error: function (data, statusText, xhr, $form) { 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\ showMessage('Whoops!, it looks like something went wrong on our servers.\n\
Please try again, or contact support if the problem persists.'); Please try again, or contact support if the problem persists.');
@ -115,24 +119,7 @@ $(function () {
break; break;
case 'error': case 'error':
$.each(data.messages, function (index, error) { processFormErrors($form, data.messages);
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);
break; break;
default: default:
@ -149,12 +136,12 @@ $(function () {
* -------------------- * --------------------
* Create a simple way to show remote dynamic modals from the frontend * Create a simple way to show remote dynamic modals from the frontend
* -------------------- * --------------------
* *
* E.g : * E.g :
* <a href='/route/to/modal' class='loadModal'> * <a href='/route/to/modal' class='loadModal'>
* Click For Modal * Click For Modal
* </a> * </a>
* *
*/ */
$(document.body).on('click', '.loadModal, [data-invoke~=modal]', function (e) { $(document.body).on('click', '.loadModal, [data-invoke~=modal]', function (e) {
@ -218,14 +205,14 @@ $(function () {
/* /*
* ------------------------------------------------------------- * -------------------------------------------------------------
* Simple way for any type of object to be deleted. * Simple way for any type of object to be deleted.
* ------------------------------------------------------------- * -------------------------------------------------------------
* *
* E.g markup: * E.g markup:
* <a data-route='/route/to/delete' data-id='123' data-type='objectType'> * <a data-route='/route/to/delete' data-id='123' data-type='objectType'>
* Delete This Object * Delete This Object
* </a> * </a>
* *
*/ */
$('.deleteThis').on('click', function (e) { $('.deleteThis').on('click', function (e) {
@ -309,10 +296,6 @@ $(function () {
/** /**
* Toggle checkboxes * Toggle checkboxes
*/ */
$(document.body).on('click', '.check-all', function (e) { $(document.body).on('click', '.check-all', function (e) {
var toggleClass = $(this).data('check-class'); var toggleClass = $(this).data('check-class');
$('.' + toggleClass).each(function () { $('.' + 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);
}
/** /**
* *