dreamjob/app/webroot/js/dreamjob.js

235 lines
8.7 KiB
JavaScript
Raw Normal View History

2014-02-18 12:10:29 +01:00
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
2014-03-23 10:16:15 +01:00
var global_load = null;
2014-02-18 12:10:29 +01:00
!function($) {
2014-04-02 20:37:38 +02:00
$(function() {
$body = $("body");
$(document).on({
ajaxStart: function() { $body.addClass("loading"); },
ajaxStop: function() { $body.removeClass("loading"); }
});
2014-04-30 17:17:15 +02:00
$(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){}});
});
2014-05-02 11:01:43 +02:00
function stopLoad(e){
if (!e)
e = window.event;
if (e.preventDefault)
e.preventDefault();
if (e.stopPropagation) {
e.stopPropagation();
}else{
e.cancelBubble = true;
}
}
2014-04-02 20:37:38 +02:00
function event(where){
2014-04-22 15:15:32 +02:00
/* Hotfix Ticket: 215*/
$(where+' img').each(function(){ $(this).attr('src',$(this).attr('src')+ '?' + (new Date()).getTime()); });
2014-04-02 20:37:38 +02:00
$("#alert .alert").alert();
2014-04-23 22:08:43 +02:00
$(where+' textarea').wysihtml5();
2014-05-07 19:19:52 +02:00
$(where+' select').each(function(){
$(this).select2({allowClear: true});
});
2014-04-23 22:08:43 +02:00
$(where+' .dropdown-toggle').dropdown();
2014-05-11 09:58:54 +02:00
$(where+" a").tooltip();;
2014-04-02 20:37:38 +02:00
$(where+" a").each(function(that){
2014-05-11 11:13:33 +02:00
if($(this).attr("rel")!=="external" && $(this).attr("ref")!=="eventOff" && !$(this).parents('ul').hasClass("wysihtml5-toolbar") && !$(this).hasClass(".select2-choice") && !$(this).parents('form').hasClass('tableForm'))
2014-04-02 20:37:38 +02:00
$(this).click(function(e){
load($(this).attr('href'),{},($(this).attr('rel')=="tab"));
return false;
});
});
$(where+" form").submit(function(e){
2014-03-26 09:15:43 +01:00
if(!$(this).hasClass("hide-form") && $(this).attr('enctype')!='multipart/form-data' ){
2014-04-23 22:08:43 +02:00
$(":input[ name *= '_wysihtml5_mod' ]",this).remove();
2014-05-02 11:01:43 +02:00
//stopLoad(e);
2014-03-15 01:52:07 +01:00
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;
2014-03-26 09:15:43 +01:00
}
});
2014-04-02 20:37:38 +02:00
$(where+" form[ enctype *= 'multipart/form-data' ]").each(function(evt){
2014-03-26 09:15:43 +01:00
if (!$('#fileUpload').length)
$('body').append('<iframe id="fileUpload" name="fileUpload" style="display:none" />');
$(this).attr('target','fileUpload');
2014-04-23 22:08:43 +02:00
$(":input[ name *= '_wysihtml5_mod' ]",this).remove();
2014-03-26 09:15:43 +01:00
$(this).submit(function(){
frame = $('#fileUpload').load(function(){
setContent(frame.contents().find('body').html());
frame.unbind('load');
setTimeout(function (){frame.html('');}, 1);
});
});
});
2014-04-02 20:37:38 +02:00
2014-03-28 16:22:19 +01:00
$(where+" form.tableForm tbody").each(function(evt){
2014-04-01 20:58:36 +02:00
var that = this;
2014-03-28 16:22:19 +01:00
newRow = $(".new").html();
2014-04-01 20:58:36 +02:00
$(that).change(function(){
2014-03-29 21:09:17 +01:00
tosave = true;
2014-04-01 20:58:36 +02:00
$("tr",that).each(function(evt){
2014-03-28 16:22:19 +01:00
see = true;
2014-04-01 20:58:36 +02:00
$(":input:not([ type = 'hidden' ] )",this).each(function(){
if(see){
2014-03-28 16:22:19 +01:00
see = $(this).val()=='';
2014-04-01 20:58:36 +02:00
}
2014-03-28 16:22:19 +01:00
});
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();
}
2014-03-29 21:09:17 +01:00
save = true;
that2=this;
2014-04-01 20:58:36 +02:00
$(":input:not([ type = 'hidden' ] )",this).each(function(){
2014-03-29 21:09:17 +01:00
if(save && !$(that2).hasClass("new")){
save = $(this).val()!='';
}
});
if(tosave && !$(that2).hasClass("new")){
tosave = save;
}
2014-03-28 16:22:19 +01:00
});
2014-03-29 21:09:17 +01:00
if(tosave)
2014-04-01 20:58:36 +02:00
//console.log("sendTosave");
2014-05-11 11:13:33 +02:00
saveForm(that);
2014-03-28 16:22:19 +01:00
});
//ZUOFT WIRD GESPEICHERT
function evet(){
$("tr:not(.new)",that).each(function(){
var that2 = this;
$(".btn-del",this).unbind("click").click(function(evt){
$(that2).remove();
2014-05-11 11:13:33 +02:00
saveForm(that);
2014-03-28 16:22:19 +01:00
});
});
}
evet();
2014-05-11 11:13:33 +02:00
});
function saveForm(here,back){
2014-03-29 21:09:17 +01:00
i = 0;
2014-05-11 11:13:33 +02:00
$(":input[ name *= '_wysihtml5_mod' ]",$(here).parents('form')).remove();
//$(":input[ class *= 'select2-focusser' ]",$(here).parents('form')).remove();
$("tbody tr.new",$(here).parents('form')).remove();
$("tbody tr",$(here).parents('form')).each(function(){
$(":input[name]",this).each(function(){
2014-04-01 20:58:36 +02:00
str = $(this).attr("name").replace(/data\[(.*?)\]\[.*?\]\[(.+)\]/g,'data[$1]['+i+'][$2]');
2014-03-29 21:09:17 +01:00
$(this).attr("name",str);
});
i++;
});
2014-05-11 11:13:33 +02:00
load($(here).parents("form").attr("action"),{back:back,data:$(here).parents("form").serialize(), type:'POST'},false);
2014-03-28 16:22:19 +01:00
}
2014-05-11 11:13:33 +02:00
$($(where+" form.tableForm .label.edit").parents('form.tableForm a')).click(function(){saveForm('form.tableForm tbody',$(this).attr('href'));return false;});
2014-04-01 20:58:36 +02:00
//$(where+" form label.has-error").parent(".form-group").addClass("has-error")
2014-02-18 12:10:29 +01:00
}
2014-05-07 11:24:31 +02:00
function setContent(data,back,tab,backignore){
2014-03-18 22:48:22 +01:00
alert = data.split('<!-- alert -->')[1].split('<!-- /alert -->')[0];
2014-05-07 11:24:31 +02:00
$('#alert').removeClass('old');
2014-03-23 10:16:15 +01:00
if( alert.trim().length > 0){
$('#alert').html(alert);
2014-05-07 11:24:31 +02:00
}else if(!backignore){
$('#alert').addClass('old');
2014-03-23 10:16:15 +01:00
}
2014-02-18 12:10:29 +01:00
if(back){
2014-05-07 11:24:31 +02:00
load(back,{'backignore':true},tab);
2014-02-18 12:10:29 +01:00
}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");
}
2014-03-23 10:16:15 +01:00
if(!back){
navbar = data.split('<!-- extraScript -->')[1].split('<!-- /extraScript -->')[0];
eval($(navbar).html());
}
2014-03-26 09:15:43 +01:00
}
function setContentError(data,back,tab){
2014-03-23 10:16:15 +01:00
alert = "<div class=\"alert alert-danger\">"+data.statusText+
"<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>"
+ "</div>";
2014-05-07 11:24:31 +02:00
$('#alert').removeClass('old');
2014-02-18 12:10:29 +01:00
$('#alert').html(alert);
2014-03-23 10:16:15 +01:00
event("#alert");
$('#container').html(data.responseText);
2014-02-18 12:10:29 +01:00
event("#container");
2014-03-26 09:15:43 +01:00
}
function load(pageurl,conf,tab){
data = {};
typemethode = "GET";
back = false;
2014-05-07 11:24:31 +02:00
backignore = false;
2014-04-30 17:17:15 +02:00
history = true;
2014-03-26 09:15:43 +01:00
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'];
2014-05-07 11:24:31 +02:00
if(conf['backignore'])
backignore = conf['backignore'];
2014-04-30 17:17:15 +02:00
if(conf['history'])
history = conf['history'];
2014-05-07 11:24:31 +02:00
2014-03-26 09:15:43 +01:00
//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.
*/
2014-05-07 11:24:31 +02:00
$.ajax({url:pageurl,data:data,type:typemethode,success:function(data){setContent(data,back,tab,backignore);} ,error:function(data){setContentError(data,back,tab);}});
2014-04-30 17:17:15 +02:00
if(history && pageurl!=window.location){
2014-02-18 12:10:29 +01:00
window.history.pushState({path:pageurl},'',pageurl);
}
};
event("");
2014-03-23 10:16:15 +01:00
global_load = load;
2014-02-18 12:10:29 +01:00
});
}(window.jQuery);