227 lines
8.0 KiB
JavaScript
Executable File
227 lines
8.0 KiB
JavaScript
Executable File
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
var global_load = null;
|
|
!function($) {
|
|
$(function() {
|
|
$body = $("body");
|
|
$(document).on({
|
|
ajaxStart: function() { $body.addClass("loading"); },
|
|
ajaxStop: function() { $body.removeClass("loading"); }
|
|
});
|
|
$(window).bind('popstate',function(evt){
|
|
console.log(evt.target.pageurl);
|
|
console.log(evt);
|
|
if(evt.originalEvent.state !== null) {
|
|
load(location.href,{'history':false},false);
|
|
}
|
|
});
|
|
$("#popup").modal({'remote':false,'show':false});
|
|
$("#popup").on('show.bs.modal',function(e){
|
|
$.ajax({url:$(e.relatedTarget).attr("href"),success:function(data){
|
|
$("#popup .modal-title").html($(e.relatedTarget).attr("title"));
|
|
$("#popup .modal-body").html($("#container div.box",data).html());
|
|
} ,error:function(data){}});
|
|
});
|
|
function stopLoad(e){
|
|
if (!e)
|
|
e = window.event;
|
|
if (e.preventDefault)
|
|
e.preventDefault();
|
|
if (e.stopPropagation) {
|
|
e.stopPropagation();
|
|
}else{
|
|
e.cancelBubble = true;
|
|
}
|
|
}
|
|
function event(where){
|
|
/* Hotfix Ticket: 215*/
|
|
$(where+' img').each(function(){ $(this).attr('src',$(this).attr('src')+ '?' + (new Date()).getTime()); });
|
|
|
|
$("#alert .alert").alert();
|
|
$(where+' textarea').wysihtml5();
|
|
$(where+' .dropdown-toggle').dropdown();
|
|
|
|
$(where+" a").each(function(that){
|
|
if($(this).attr("rel")!=="external" && $(this).attr("ref")!=="eventOff" && !$(this).parents('ul').hasClass("wysihtml5-toolbar"))
|
|
$(this).click(function(e){
|
|
load($(this).attr('href'),{},($(this).attr('rel')=="tab"));
|
|
return false;
|
|
});
|
|
});
|
|
|
|
$(where+" form").submit(function(e){
|
|
if(!$(this).hasClass("hide-form") && $(this).attr('enctype')!='multipart/form-data' ){
|
|
$(":input[ name *= '_wysihtml5_mod' ]",this).remove();
|
|
//stopLoad(e);
|
|
if($(this).attr("back"))
|
|
back=window.location.href;
|
|
else
|
|
back=null;
|
|
load($(this).attr("action"),{data:$(this).serialize(), type:$(this).attr("method"),back:back},($(this).attr('rel')=="tab"));
|
|
return false;
|
|
}
|
|
});
|
|
|
|
$(where+" form[ enctype *= 'multipart/form-data' ]").each(function(evt){
|
|
if (!$('#fileUpload').length)
|
|
$('body').append('<iframe id="fileUpload" name="fileUpload" style="display:none" />');
|
|
$(this).attr('target','fileUpload');
|
|
$(":input[ name *= '_wysihtml5_mod' ]",this).remove();
|
|
$(this).submit(function(){
|
|
frame = $('#fileUpload').load(function(){
|
|
setContent(frame.contents().find('body').html());
|
|
frame.unbind('load');
|
|
setTimeout(function (){frame.html('');}, 1);
|
|
});
|
|
});
|
|
});
|
|
|
|
$(where+" form.tableForm tbody").each(function(evt){
|
|
var that = this;
|
|
newRow = $(".new").html();
|
|
$(that).change(function(){
|
|
tosave = true;
|
|
$("tr",that).each(function(evt){
|
|
see = true;
|
|
$(":input:not([ type = 'hidden' ] )",this).each(function(){
|
|
if(see){
|
|
see = $(this).val()=='';
|
|
}
|
|
});
|
|
if(see && $(this).attr("data")=="set"){
|
|
$(this).attr("data","");
|
|
$(this).remove();
|
|
}
|
|
if(!see && $(this).attr("data")!="set"){
|
|
$(this).attr("data","set");
|
|
$("tr",that).removeClass("new");
|
|
$(that).append("<tr class=\"new\">"+newRow+"</tr>");
|
|
evet();
|
|
}
|
|
|
|
save = true;
|
|
that2=this;
|
|
$(":input:not([ type = 'hidden' ] )",this).each(function(){
|
|
if(save && !$(that2).hasClass("new")){
|
|
save = $(this).val()!='';
|
|
}
|
|
});
|
|
if(tosave && !$(that2).hasClass("new")){
|
|
tosave = save;
|
|
}
|
|
});
|
|
if(tosave)
|
|
//console.log("sendTosave");
|
|
saveForm();
|
|
});
|
|
//ZUOFT WIRD GESPEICHERT
|
|
|
|
function evet(){
|
|
$("tr:not(.new)",that).each(function(){
|
|
var that2 = this;
|
|
$(".btn-del",this).unbind("click").click(function(evt){
|
|
$(that2).remove();
|
|
saveForm();
|
|
});
|
|
});
|
|
}
|
|
evet();
|
|
function saveForm(){
|
|
i = 0;
|
|
$(":input[ name *= '_wysihtml5_mod' ]",$(that).parents('form')).remove();
|
|
$("tbody tr.new",$(that).parents('form')).remove();
|
|
$("tbody tr",$(that).parents('form')).each(function(){
|
|
$(":input",this).each(function(){
|
|
str = $(this).attr("name").replace(/data\[(.*?)\]\[.*?\]\[(.+)\]/g,'data[$1]['+i+'][$2]');
|
|
$(this).attr("name",str);
|
|
});
|
|
i++;
|
|
});
|
|
load($(that).parents("form").attr("action"),{data:$(that).parents("form").serialize(), type:'POST'},false);
|
|
}
|
|
});
|
|
//$(where+" form label.has-error").parent(".form-group").addClass("has-error")
|
|
}
|
|
function setContent(data,back,tab,backignore){
|
|
alert = data.split('<!-- alert -->')[1].split('<!-- /alert -->')[0];
|
|
$('#alert').removeClass('old');
|
|
if( alert.trim().length > 0){
|
|
$('#alert').html(alert);
|
|
}else if(!backignore){
|
|
$('#alert').addClass('old');
|
|
}
|
|
|
|
if(back){
|
|
load(back,{'backignore':true},tab);
|
|
}else if(tab){
|
|
navbar = data.split('<!-- tab -->')[1].split('<!-- /tab -->')[0];
|
|
$('#tab').html(navbar);
|
|
event("#tab");
|
|
}else{
|
|
navbar = data.split('<!-- navbar -->')[1].split('<!-- /navbar -->')[0];
|
|
$('#navbar').html(navbar);
|
|
event("#navbar");
|
|
|
|
container = data.split('<!-- container -->')[1].split('<!-- /container -->')[0];
|
|
$('#container').html(container);
|
|
event("#container");
|
|
|
|
barright = data.split('<!-- barright -->')[1].split('<!-- /barright -->')[0];
|
|
$('#barright').html(barright);
|
|
event("#barright");
|
|
|
|
barleft = data.split('<!-- barleft -->')[1].split('<!-- /barleft -->')[0];
|
|
$('#barleft').html(barleft);
|
|
event("#barleft");
|
|
}
|
|
if(!back){
|
|
navbar = data.split('<!-- extraScript -->')[1].split('<!-- /extraScript -->')[0];
|
|
eval($(navbar).html());
|
|
}
|
|
}
|
|
function setContentError(data,back,tab){
|
|
alert = "<div class=\"alert alert-danger\">"+data.statusText+
|
|
"<button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button>"
|
|
+ "</div>";
|
|
$('#alert').removeClass('old');
|
|
$('#alert').html(alert);
|
|
event("#alert");
|
|
$('#container').html(data.responseText);
|
|
event("#container");
|
|
}
|
|
function load(pageurl,conf,tab){
|
|
data = {};
|
|
typemethode = "GET";
|
|
back = false;
|
|
backignore = false;
|
|
history = true;
|
|
if(conf['data'])
|
|
data = conf['data'];
|
|
if(conf['type'])
|
|
typemethode = conf['type'];
|
|
if(conf['back'] && conf['back'].indexOf("logout")== -1 && conf['back'].indexOf("login")== -1 )
|
|
back = conf['back'];
|
|
if(conf['backignore'])
|
|
backignore = conf['backignore'];
|
|
if(conf['history'])
|
|
history = conf['history'];
|
|
|
|
//e.preventDefault();
|
|
/*
|
|
if uncomment the above line, html5 nonsupported browers won't change the url but will display the ajax content;
|
|
if commented, html5 nonsupported browers will reload the page to the specified link.
|
|
*/
|
|
$.ajax({url:pageurl,data:data,type:typemethode,success:function(data){setContent(data,back,tab,backignore);} ,error:function(data){setContentError(data,back,tab);}});
|
|
if(history && pageurl!=window.location){
|
|
window.history.pushState({path:pageurl},'',pageurl);
|
|
}
|
|
};
|
|
event("");
|
|
global_load = load;
|
|
});
|
|
}(window.jQuery);
|
|
|
|
|