File: D:/HostingSpaces/SBogers96/smilefotografie.nl/wwwroot/packages/komma/kms/js/kms.confirm.js
/**
* Created by Komma on 09/03/15.
*/
(function($){
$.confirm = function(params){
if($('#confirmOverlay').length){
// A confirmbox is already open
return false;
}
var buttonHtml = '';
$.each(params.buttons, function(name, obj){
console.log(obj.action);
// Generate the html for the buttons
buttonHtml += '<a href="#" class="button '+ obj['class'] +'">'+name+'<span></span></a>';
if(!obj.action){
obj.action = function(){};
}
});
var markup = [
'<div id="confirmOverlay">',
'<div id="confirmBox">',
'<h1>', params.title, '</h1>',
'<p>', params.message, '</p>',
'<div id="confirmButtons">',
buttonHtml,
'</div></div></div>'
].join('');
$(markup).hide().appendTo('body').fadeIn();
var buttons = $('#confirmBox .button');
var i = 0;
$.each(params.buttons, function(name, obj){
buttons.eq(i++).on('click', function(){
$.confirm.hide();
return obj.action();
//return false;
});
});
};
$.confirm.hide = function(){
$('#confirmOverlay').fadeOut(function(){
$(this).remove();
});
};
$('[kms-confirm]').click(function(e){
e.preventDefault();
$this = $(this);
$.confirm({
'title': $this.attr('kms-confirm'),
'message': $this.attr('kms-confirm-message'),
'buttons': {
'Yes': {
'class': 'btn btn-error-glow',
'action': function(){
$this.closest('form').submit();
}
},
'No': {
'class': 'btn btn-brand-glow',
'action': function(){
return false;
}
}
}
});
return false;
});
var initExitWithoutSave = function(e) {
//e.preventDefault();
//alert('test');
$("#entities a, #sidebar a, #tree-root li.entities-list-item").click(function (e) {
$this = $(this);
if ($this.is('[href^="#"]')) {
return;
}
// Beter checking is required, v2 in angular?
if ($('#entity .ng-dirty, #entity .error').length > 0) {
e.preventDefault();
$.confirm({
'title': 'Not saved',
'message': 'There are changes that has not been saved yet, are you sure you want to leave this page?',
'buttons': {
'Yes': {
'class': 'btn btn-error-glow',
'action': function () {
window.location = $this.attr('href');
}
},
'No': {
'class': 'btn btn-brand-glow',
'action': function () {
return false;
}
}
}
});
}
});
};
$("#entities .entities-list").mousedown(initExitWithoutSave);
initExitWithoutSave();
})(jQuery);