File: D:/HostingSpaces/SBogers10/kms.komma.pro/wwwroot/public/js/basic_page_item.js
/**
* Created by mikevandersanden on 27/1/14.
*/
// Save form values in session
initXhrSave();
// Check if page is saved when click on links
initSaveCheck();
// What to do when input changes
var inputChangeIsSet = false;
initInputChange();
// Make sure user has to confirm deleting an item
confirmRemoval();
/*
* Make sure the item is saved in session when switching between tabs
*/
function initXhrSave()
{
$('.tabs li').click(function(e)
{
$.ajax({
url: $('#form_save_link').val(),
type: "post",
data: $("#item_data").serialize() ,
success: function(){},
error:function(){}
});
});
}
/*
* Make sure the item is saved in session when switching between tabs
*/
function confirmRemoval()
{
$('.remove_item').click(function(e)
{
// Stop link
e.preventDefault();
var $link = $(this);
// Pop question
$('body').confirm({
msg : 'removeItem',
onConfirm: function(e){
window.location.href = $link.attr('href');
}
});
});
}
/*
* Check if item is saved before linked to href
*/
function initSaveCheck()
{
/*
* Check before every click
*/
$('a.check').click(function(e)
{
var $link = $(this);
// Stop link
e.preventDefault();
// check if there are unsaved changes
$.ajax({
url: '/lib/js/unsaved_changes.php?check=1',
type: "get",
success: function(success)
{
if(success)
{
// Pop question
$('body').confirm({
msg : 'unsavedData',
onConfirm: function(e){
// Unset unsaved changes
$.ajax({ url: '/lib/js/unsaved_changes.php?unset=1', type: "get",
success: function(){
// Header to href
window.location.href = $link.attr('href');
}
});
}
});
}
else
{
// Header to href
window.location.href = $link.attr('href');
}
}
});
});
}
function initInputChange()
{
// When data is changed
$('#item_data input').change(onInputChange);
// While typing
$('#item_data input').keyup(onInputChange);
}
function onInputChange()
{
if( ! inputChangeIsSet )
{
inputChangeIsSet = true;
// Set unsaved changes
$.ajax({ url: '/lib/js/unsaved_changes.php?set=1', type: "get" });
// Change color submit button
var $save = $('#save');
$save.removeClass('confirmation');
$save.addClass('action');
// Change text submit button
var value = $save.attr('data-save');
$save.children('input').val(value);
}
}