2014-02-18 12:10:29 +01:00
|
|
|
/*
|
|
|
|
* To change this template, choose Tools | Templates
|
|
|
|
* and open the template in the editor.
|
|
|
|
*/
|
2014-05-14 00:06:53 +02:00
|
|
|
var global_load = null;
|
2014-02-18 12:10:29 +01:00
|
|
|
!function($) {
|
2014-05-14 00:06:53 +02:00
|
|
|
$(function() {
|
|
|
|
$body = $("body");
|
|
|
|
$(document).on({
|
|
|
|
ajaxStart: function() {
|
|
|
|
$body.addClass("loading");
|
|
|
|
},
|
|
|
|
ajaxStop: function() {
|
|
|
|
$body.removeClass("loading");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(window).bind('popstate', function(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;
|
2014-05-19 15:38:48 +02:00
|
|
|
if (e) {
|
|
|
|
if (e.preventDefault)
|
|
|
|
e.preventDefault();
|
|
|
|
if (e.stopPropagation) {
|
|
|
|
e.stopPropagation();
|
|
|
|
} else {
|
|
|
|
e.cancelBubble = true;
|
|
|
|
}
|
2014-05-14 00:06:53 +02:00
|
|
|
}
|
2014-02-18 12:10:29 +01:00
|
|
|
}
|
2014-05-14 00:06:53 +02:00
|
|
|
function event(where) {
|
2014-06-10 19:21:34 +02:00
|
|
|
|
|
|
|
$("#alert .alert").alert();
|
|
|
|
$(where + ' textarea').wysihtml5();
|
|
|
|
$(where + ' select').each(function() {
|
|
|
|
$(this).select2({allowClear: true});
|
|
|
|
});
|
|
|
|
$(where + ' .dropdown-toggle').dropdown();
|
2014-06-16 10:00:05 +02:00
|
|
|
$(where + " a").tooltip({'placement':function(e){
|
2014-06-16 10:32:09 +02:00
|
|
|
if($(this)[0].$element.parents("#barleft").length>0)
|
2014-06-16 10:00:05 +02:00
|
|
|
return 'right';
|
2014-06-16 10:32:09 +02:00
|
|
|
return 'bottom';
|
2014-06-16 10:00:05 +02:00
|
|
|
}});
|
2014-06-10 19:21:34 +02:00
|
|
|
|
2014-05-14 07:58:18 +02:00
|
|
|
$(where + " a").not('[href*="mailto:"]').each(function(that) {
|
2014-06-03 16:51:20 +02:00
|
|
|
if ($(this).attr("rel") !== "external" && $(this).attr("ref") !== "eventOff" && !$(this).parents('ul').hasClass("wysihtml5-toolbar") && !$(this).hasClass(".select2-choice"))
|
2014-05-14 00:06:53 +02:00
|
|
|
$(this).click(function(e) {
|
|
|
|
stopLoad(e);
|
|
|
|
load($(this).attr('href'), {}, ($(this).attr('rel') == "tab"));
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(where + " form").submit(function(e) {
|
2014-06-03 16:51:20 +02:00
|
|
|
if ($(this).attr('enctype') != 'multipart/form-data') {
|
2014-05-14 00:06:53 +02:00
|
|
|
stopLoad(e);
|
2014-06-03 16:51:20 +02:00
|
|
|
if ($(this).hasClass('tableForm')) {
|
|
|
|
$("tbody tr.new", $(this)).remove();
|
|
|
|
i=0;
|
|
|
|
$("tbody tr", $(this)).each(function() {
|
|
|
|
$(":input[name]", this).each(function() {
|
|
|
|
str = $(this).attr("name").replace(/data\[(.*?)\]\[.*?\]\[(.+)\]/g, 'data[$1][' + i + '][$2]');
|
|
|
|
$(this).attr("name", str);
|
|
|
|
});
|
|
|
|
i++;
|
|
|
|
});
|
|
|
|
}
|
2014-05-14 00:06:53 +02:00
|
|
|
$(":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;
|
2014-02-18 12:10:29 +01:00
|
|
|
}
|
2014-05-14 00:06:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$(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() {
|
2014-06-10 19:25:56 +02:00
|
|
|
stopLoad(evt);
|
2014-05-14 00:06:53 +02:00
|
|
|
frame = $('#fileUpload').load(function() {
|
2014-06-10 19:40:06 +02:00
|
|
|
setContent($('#fileUpload').contents().find('html').html());
|
2014-06-10 19:25:56 +02:00
|
|
|
$('#fileUpload').unbind('load');
|
2014-05-14 00:06:53 +02:00
|
|
|
setTimeout(function() {
|
2014-06-10 19:25:56 +02:00
|
|
|
$('#fileUpload').html('');
|
2014-06-10 19:26:47 +02:00
|
|
|
}, 10);
|
2014-05-14 00:06:53 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(where + " form.tableForm tbody").each(function(evt) {
|
|
|
|
var that = this;
|
|
|
|
var newRow = $(".new", this).html();
|
2014-06-01 21:32:16 +02:00
|
|
|
$(that).on('change',function(e) {
|
2014-05-14 00:06:53 +02:00
|
|
|
stopLoad(e);
|
|
|
|
$("tr", that).each(function(evt) {
|
|
|
|
see = true;
|
2014-06-01 21:32:16 +02:00
|
|
|
$(":input:not([ type = 'hidden' ] ):not(.select2-focusser):not(.select2-input)", this).each(function() {
|
2014-05-14 00:06:53 +02:00
|
|
|
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");
|
2014-06-04 00:10:58 +02:00
|
|
|
console.log(newRow);
|
2014-05-14 00:06:53 +02:00
|
|
|
$(that).append("<tr class=\"new\">" + newRow + "</tr>");
|
2014-06-04 00:15:03 +02:00
|
|
|
|
2014-06-04 00:19:20 +02:00
|
|
|
$("form.tableForm tbody tr.new select").each(function() {
|
2014-06-04 00:15:03 +02:00
|
|
|
$(this).select2({allowClear: true});
|
|
|
|
});
|
2014-05-14 00:06:53 +02:00
|
|
|
evet();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function evet() {
|
|
|
|
$("tr:not(.new)", that).each(function() {
|
|
|
|
var that2 = this;
|
|
|
|
$(".btn-del", this).unbind("click").click(function(evt) {
|
|
|
|
$(that2).remove();
|
|
|
|
});
|
|
|
|
});
|
2014-03-23 10:16:15 +01:00
|
|
|
}
|
2014-05-14 00:06:53 +02:00
|
|
|
evet();
|
|
|
|
});
|
2014-06-04 00:10:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
$(where + ' img').each(function() {
|
|
|
|
$(this).attr('src', $(this).attr('src') + '?' + (new Date()).getTime());
|
|
|
|
});
|
2014-05-14 00:06:53 +02:00
|
|
|
}
|
|
|
|
function setContent(data, back, tab, backignore) {
|
2014-06-01 21:32:16 +02:00
|
|
|
title = data.split('<title>')[1].split('</title>')[0];
|
|
|
|
if (title.trim().length > 0) {
|
|
|
|
document.title = title.trim();
|
|
|
|
}
|
|
|
|
|
2014-05-14 00:06:53 +02:00
|
|
|
alert = data.split('<!-- alert -->')[1].split('<!-- /alert -->')[0];
|
|
|
|
$('#alert').removeClass('old');
|
|
|
|
if (alert.trim().length > 0) {
|
2014-02-18 12:10:29 +01:00
|
|
|
$('#alert').html(alert);
|
2014-05-14 00:06:53 +02:00
|
|
|
} 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");
|
2014-03-26 09:15:43 +01:00
|
|
|
}
|
2014-05-14 00:06:53 +02:00
|
|
|
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) {
|
2014-03-26 09:15:43 +01:00
|
|
|
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-05-14 00:06:53 +02:00
|
|
|
if (conf['data'])
|
2014-03-26 09:15:43 +01:00
|
|
|
data = conf['data'];
|
2014-05-14 00:06:53 +02:00
|
|
|
if (conf['type'])
|
2014-03-26 09:15:43 +01:00
|
|
|
typemethode = conf['type'];
|
2014-05-14 00:06:53 +02:00
|
|
|
if (conf['back'] && conf['back'].indexOf("logout") == -1 && conf['back'].indexOf("login") == -1)
|
2014-03-26 09:15:43 +01:00
|
|
|
back = conf['back'];
|
2014-05-14 00:06:53 +02:00
|
|
|
if (conf['backignore'])
|
2014-05-07 11:24:31 +02:00
|
|
|
backignore = conf['backignore'];
|
2014-05-14 00:06:53 +02:00
|
|
|
if (conf['history'])
|
2014-04-30 17:17:15 +02:00
|
|
|
history = conf['history'];
|
2014-05-14 00:06:53 +02:00
|
|
|
|
2014-05-25 09:39:28 +02:00
|
|
|
$.ajax({url: pageurl, cache: false, data: data, type: typemethode, success: function(data) {
|
2014-05-14 00:06:53 +02:00
|
|
|
setContent(data, back, tab, backignore);
|
|
|
|
}, error: function(data) {
|
|
|
|
setContentError(data, back, tab);
|
|
|
|
}});
|
|
|
|
if (history && pageurl != window.location) {
|
|
|
|
window.history.pushState({path: pageurl}, '', pageurl);
|
2014-02-18 12:10:29 +01:00
|
|
|
}
|
2014-05-14 00:06:53 +02:00
|
|
|
}
|
|
|
|
;
|
2014-02-18 12:10:29 +01:00
|
|
|
event("");
|
2014-03-23 10:16:15 +01:00
|
|
|
global_load = load;
|
2014-02-18 12:10:29 +01:00
|
|
|
});
|
|
|
|
}(window.jQuery);
|
|
|
|
|
|
|
|
|