716 lines
18 KiB
JavaScript
716 lines
18 KiB
JavaScript
/*
|
|
* audaris Tools - jQuery plug-in
|
|
*
|
|
* Copyright 2010, Darius Zylka
|
|
*
|
|
* Depends: jQuery 1.4.2+
|
|
*/
|
|
(function($) {
|
|
var methods = {
|
|
transformULLITables: function(options) {
|
|
var defaults = {
|
|
};
|
|
|
|
$.extend(defaults, options);
|
|
|
|
return this.each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
var $thisParent = $(this).parent();
|
|
|
|
var props = {display: 'block'};
|
|
$.swap($thisParent[0], props, function(){
|
|
$this.children('li').each(function() {
|
|
var $curLiItem = $(this);
|
|
|
|
var padding = 25;
|
|
var nestedULs = $('ul', this).size();
|
|
var thisWidth = $curLiItem.width();
|
|
|
|
if (nestedULs > 0) {
|
|
|
|
$('ul[title^=span]', this).each(function() {
|
|
nestedULs += parseInt($(this).attr('title').replace(/span:/, '')) - 1;
|
|
});
|
|
|
|
var elementWidth = (thisWidth - (nestedULs - 1) * padding) / nestedULs;
|
|
|
|
$('ul', this).css({
|
|
width: elementWidth + 'px',
|
|
paddingLeft: padding + 'px'
|
|
});
|
|
$('ul:first', this).css({
|
|
paddingLeft: '0px'
|
|
});
|
|
|
|
$('ul[title^=span]', this).each(function() {
|
|
var spanWidth = parseInt($(this).attr('title').replace(/span:/, ''));
|
|
var newWidth = elementWidth * spanWidth;
|
|
newWidth += padding * (spanWidth - 1);
|
|
|
|
$(this).css({
|
|
width: newWidth + 'px'
|
|
});
|
|
});
|
|
|
|
$('<br />').addClass('clear').appendTo(this);
|
|
}
|
|
});
|
|
});
|
|
|
|
$('li.title', $this).prev('li').css({
|
|
borderBottomWidth: '0px'
|
|
});
|
|
|
|
});
|
|
},
|
|
|
|
makeToolTips: function(options) {
|
|
var defaults = {
|
|
elements: 'input',
|
|
tipArea: 'tooltip:'
|
|
};
|
|
|
|
$.extend(defaults, options);
|
|
|
|
return this.each(function() {
|
|
|
|
var $this = $(this);
|
|
var tipReplaceRegExp = new RegExp(defaults.tipArea);
|
|
|
|
$(defaults.elements + '[title*=' + defaults.tipArea + ']', $this).each(function() {
|
|
var $curElement = $(this);
|
|
var tipText = $curElement.attr('title').replace(tipReplaceRegExp, '');
|
|
|
|
$curElement.attr({
|
|
title: ''
|
|
});
|
|
|
|
$curElement.focus(function() {
|
|
var curPos = $curElement.offset();
|
|
|
|
var $toolTip = $('<div class="rsToolsToolTip"><div class="rsToolsToolTipHeader"></div><div class="rsToolsToolTipContent"></div><div class="rsToolsToolTipFooter"></div></div>')
|
|
.css({
|
|
top: (curPos.top + $curElement.outerHeight()) + 'px',
|
|
left: (curPos.left - 60) + 'px'
|
|
})
|
|
.attr({
|
|
id: 'audarisToolsToolTipContainer'
|
|
})
|
|
.appendTo('body')
|
|
;
|
|
|
|
$('div.rsToolsToolTipContent', $toolTip).html(tipText);
|
|
}).blur(function() {
|
|
$('#audarisToolsToolTipContainer').remove();
|
|
});
|
|
});
|
|
});
|
|
},
|
|
|
|
makePasswordField: function(options) {
|
|
var defaults = {
|
|
minLength: 8,
|
|
width: '440px',
|
|
height: '350px'
|
|
};
|
|
|
|
$.extend(defaults, options);
|
|
|
|
return this.each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
$this.click(function() {
|
|
$.fn.audarisTools('makeModal');
|
|
|
|
$container = $('<div />').css({
|
|
position: 'absolute',
|
|
width: defaults.width,
|
|
height: defaults.height,
|
|
background: '#ffffff',
|
|
padding: '20px',
|
|
textAlign: 'left',
|
|
left: (($(window).width() - parseInt(defaults.width)) / 2) + 'px',
|
|
top: (($(window).height() - parseInt(defaults.height)) / 2 + $(window).scrollTop()) + 'px',
|
|
zIndex: 100000
|
|
}).attr({
|
|
id: 'audarisToolsPasswordContainer'
|
|
}).appendTo('body');
|
|
|
|
|
|
|
|
$('<h2>Passwort-Helfer</h2>').appendTo($container);
|
|
$('<label>Wunsch-Passwort eingeben</label>').appendTo($container);
|
|
|
|
$passfield1 = $('<input />').attr({
|
|
type: 'text'
|
|
}).css({
|
|
fontWeight: 'bold'
|
|
}).appendTo($container);
|
|
|
|
$passfield1.focus();
|
|
|
|
$passButton = $('<button>Passwort übernehmen</button>').attr({
|
|
disabled: 'disabled'
|
|
}).click(function() {
|
|
$this.val($passfield1.val());
|
|
|
|
$container.empty().remove();
|
|
$.fn.audarisTools('hideModal');
|
|
}).appendTo($container);
|
|
|
|
$('<button>abbrechen</button>').click(function() {
|
|
$container.empty().remove();
|
|
$.fn.audarisTools('hideModal');
|
|
}).appendTo($container);
|
|
|
|
$passSecurity = $('<p />').css({
|
|
color: '#009900',
|
|
fontWeight: 'bold'
|
|
}).appendTo($container);
|
|
|
|
$('<p />').html('\
|
|
<br />\
|
|
<strong>Thema Sicherheit</strong><br />\
|
|
Achten Sie bitte auf die Sicherheit Ihres\
|
|
gewählten Passwortes.\
|
|
Ein sicheres Passwort besteht aus einer\
|
|
Kombination aus Klein- und Großbuchstaben,\
|
|
Ziffern und Sonderzeichen.\
|
|
Ein sicheres Passwort lautet z. B.\
|
|
<strong>aH3-G7$.8cD</strong>. Unsicher hingegen ist\
|
|
bspw. maxMustermann oder meinpasswort.<br /><br />\
|
|
Zu Ihrer eigenen Sicherheit und zur Sicherheit\
|
|
anderer Kunden setzen wir daher eine\
|
|
Mindest-Passwortlänge von 8 Zeichen und eine \
|
|
50%-ige Sicherheit voraus (diese wird Ihnen angezeigt).\
|
|
').css({
|
|
textAlign: 'justify'
|
|
}).appendTo($container);
|
|
|
|
$('<button>Sicheres Passwort generieren</button>').click(function() {
|
|
var chars = 'abcdefghjkmnpqrstuvwxyz'.split("");
|
|
var special = '!@#$%*?_~-+§"'.split("");
|
|
|
|
var newPass = new Array();
|
|
|
|
for (i = 1; i <= 2; ++i) {
|
|
newPass.push(
|
|
chars[Math.floor(Math.random() * chars.length)],
|
|
chars[Math.floor(Math.random() * chars.length)].toUpperCase(),
|
|
special[Math.floor(Math.random() * special.length)],
|
|
Math.floor(Math.random() * 10)
|
|
);
|
|
}
|
|
|
|
newPass.sort(function() {return 0.5 - Math.random()});
|
|
$passfield1.val(newPass.join("")).trigger('change');
|
|
}).appendTo($container);
|
|
|
|
$passfield1.change(function() {
|
|
var points = 0;
|
|
var password = $(this).val();
|
|
|
|
var lower = password.match(/[a-z]/g);
|
|
if (lower) {
|
|
points += 2;
|
|
|
|
if (lower.length >= 2) {
|
|
points += 2;
|
|
}
|
|
}
|
|
|
|
var upper = password.match(/[A-Z]/g);
|
|
if (upper) {
|
|
points += 2;
|
|
|
|
if (upper.length >= 2) {
|
|
points += 2;
|
|
}
|
|
}
|
|
|
|
var numbers = password.match(/[0-9]/g);
|
|
if (numbers) {
|
|
points += 2;
|
|
|
|
if (numbers.length >= 2) {
|
|
points += 2;
|
|
}
|
|
}
|
|
|
|
var special = password.match(/[!,@,#,$,%,*,?,_,~,\-,\€,\+,§,",']/g);
|
|
if (special) {
|
|
points += 2;
|
|
|
|
if (special.length >= 2) {
|
|
points += 2;
|
|
}
|
|
}
|
|
|
|
var security = Math.round((100 / 16) * points);
|
|
$passSecurity.html('Sicherheit: ' + security + ' %');
|
|
|
|
if (password.length < 8) {
|
|
$passButton.attr({
|
|
'disabled': true
|
|
}).html('Passwort zu kurz');
|
|
} else if (points < 8) {
|
|
$passButton.attr({
|
|
'disabled': true
|
|
}).html('Passwort unsicher');
|
|
} else if (password.toLowerCase().indexOf('ah3-g7$.8cd') >= 0 || password.toLowerCase().indexOf('password') >= 0 || password.toLowerCase().indexOf('passwort') >= 0) {
|
|
$passButton.attr({
|
|
'disabled': true
|
|
}).html('Passwort nicht erlaubt');
|
|
} else if (password.toLowerCase().indexOf('hallo') >= 0 || 'hallo'.toLowerCase().indexOf(password.toLowerCase()) >= 0) {
|
|
$passButton.attr({
|
|
'disabled': true
|
|
}).html('Passwort ungültig');
|
|
} else {
|
|
$passButton.attr({
|
|
'disabled': false
|
|
}).html('Passwort übernehmen');
|
|
}
|
|
}).keyup(function() {
|
|
$(this).trigger('change');
|
|
});
|
|
});
|
|
});
|
|
},
|
|
|
|
makeModal: function(options) {
|
|
var defaults = {
|
|
opacity: 1
|
|
};
|
|
|
|
$.extend(defaults, options);
|
|
|
|
$this = $(this);
|
|
|
|
$('<div />').css({
|
|
position: 'absolute',
|
|
top: '0px',
|
|
left: '0px',
|
|
opacity: defaults.opacity,
|
|
width: '100%',
|
|
height: $(document).height() + 'px',
|
|
zIndex: 99999
|
|
}).attr({
|
|
id: 'audarisToolsModal'
|
|
}).appendTo('body');
|
|
},
|
|
|
|
hideModal: function(options) {
|
|
var defaults = {
|
|
opacity: 0.8
|
|
};
|
|
|
|
$.extend(defaults, options);
|
|
|
|
$this = $(this);
|
|
|
|
$('#audarisToolsModal').empty().remove();
|
|
},
|
|
|
|
makeTable: function(options) {
|
|
var defaults = {
|
|
align: null,
|
|
onRowClick: null,
|
|
rowIdentifier: null,
|
|
getData: {
|
|
data: {
|
|
sortIndex: 0,
|
|
sortOrder: 'desc'
|
|
}
|
|
}
|
|
};
|
|
|
|
$.extend(defaults, options);
|
|
|
|
return this.each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
$this.addClass('audarisToolsTable');
|
|
|
|
|
|
// Get ajax data
|
|
var getData = function() {
|
|
$.ajax({
|
|
url: defaults.getData.source,
|
|
dataType: defaults.getData.format,
|
|
data: defaults.getData.data,
|
|
type: defaults.getData.type,
|
|
success: function(data) {
|
|
// Remove all children (rows) of tbody
|
|
$('tbody', $this).empty();
|
|
|
|
if (typeof data == 'object' && typeof data.results == 'object') {
|
|
|
|
$.each(data.results, function(key, row) {
|
|
|
|
var $newRow = $('<tr />').appendTo('tbody', $this);
|
|
|
|
var index = 0;
|
|
|
|
while (index < 7) {
|
|
var $cell = $('<td />').appendTo($newRow);
|
|
|
|
var value = row[defaults.getData.colAssign[index]];
|
|
|
|
if (defaults.types[index] == 'bool') {
|
|
$cell.addClass('boolean_' + ((value) ? 'true' : 'false'));
|
|
} else if (defaults.types[index] == 'cur') {
|
|
$cell.html(methods.makeCurrency(value));
|
|
} else {
|
|
$cell.html(value);
|
|
}
|
|
|
|
if (defaults.rowIdentifier == key) {
|
|
$newRow.data('rowIdentifier', value);
|
|
}
|
|
|
|
++index;
|
|
}
|
|
});
|
|
|
|
initialize(data.sum);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
|
|
// Get size (cols)
|
|
var cols = $('thead>tr>th', $this).size();
|
|
|
|
|
|
// Make header
|
|
if (defaults.align) {
|
|
$('thead>tr>th', $this).each(function(index, tdThElement) {
|
|
$(tdThElement).addClass(defaults.align[index]);
|
|
|
|
if (defaults.sortables[index]) {
|
|
var text = $(this).html();
|
|
$(this).html('<div class="sortables">' + text + '</div>').css({
|
|
cursor: 'pointer'
|
|
}).click(function() {
|
|
defaults.getData.data.sortIndex = index;
|
|
|
|
if ($('.sortables', this).hasClass('desc')) {
|
|
defaults.getData.data.sortOrder = 'asc';
|
|
} else {
|
|
defaults.getData.data.sortOrder = 'desc';
|
|
}
|
|
|
|
$('thead>tr>th>.sortables', $this).removeClass('asc desc');
|
|
|
|
$('.sortables', this).addClass(defaults.getData.data.sortOrder);
|
|
|
|
defaults.getData.data.page = 1;
|
|
|
|
getData();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
// Re-/Init function
|
|
var initialize = function(resultsCount) {
|
|
|
|
// Apply aligns
|
|
if (defaults.align) {
|
|
$('tbody>tr', $this).each(function(index, trElement) {
|
|
$('td', $(trElement)).each(function(index, tdThElement) {
|
|
$(tdThElement).addClass(defaults.align[index]);
|
|
});
|
|
});
|
|
}
|
|
|
|
// Style last tbody>tr element
|
|
$('tbody>tr:last', $this).addClass('lastChild');
|
|
|
|
// Style even rows
|
|
$('tbody>tr:even', $this).addClass('evenRow');
|
|
|
|
// Row click event (callback function)
|
|
// callbackFunction(clickedRowsChildrenCount, clickedRowElement)
|
|
// If callback function returns some data, it'll be appended after the clicked row
|
|
if (typeof defaults.onRowClick == 'function') {
|
|
$('tbody>tr').click(function() {
|
|
|
|
if ($(this).hasClass('active')) {
|
|
$(this).next('.rowDetails').remove();
|
|
|
|
$(this).removeClass('active');
|
|
} else {
|
|
var $thisRow = this;
|
|
|
|
defaults.onRowClick(function(data) {
|
|
return $('<tr class="rowDetails"><td colspan="' + cols + '">' + data + '</td></tr>').insertAfter($thisRow);
|
|
}, $($thisRow).data('rowIdentifier'));
|
|
|
|
$(this).addClass('active');
|
|
}
|
|
}).hover(function() {
|
|
$(this).addClass('hover');
|
|
}, function() {
|
|
$(this).removeClass('hover');
|
|
}).attr({
|
|
title: 'Klick = Details'
|
|
});
|
|
}
|
|
|
|
// Apply footer
|
|
$('tfoot', $this).empty();
|
|
$('<tr><td colspan="' + cols + '"></td></tr>').appendTo('tfoot', $this);
|
|
|
|
var $footerLeft = $('<div />').addClass('left').appendTo('tfoot>tr>td', $this);
|
|
var $footerRight = $('<div />').addClass('right').appendTo('tfoot>tr>td', $this);
|
|
|
|
$('<br class="clear" />').appendTo('tfoot>tr>td', $this);
|
|
|
|
if (typeof resultsCount == 'number') {
|
|
var currentRangeStart = (defaults.getData.data.page - 1) * defaults.getData.data.limit + 1;
|
|
var currentRangeEnd = defaults.getData.data.page * defaults.getData.data.limit;
|
|
|
|
currentRangeEnd = (currentRangeEnd <= resultsCount) ? currentRangeEnd : resultsCount;
|
|
|
|
$footerLeft.html('Anzeige ' + currentRangeStart + ' bis ' + currentRangeEnd + ' von ' + resultsCount);
|
|
|
|
// Append backward button
|
|
$('<div class="audarisToolsButton">zurück</div>').click(function() {
|
|
if (currentRangeStart > 1) {
|
|
defaults.getData.data.page -= 1;
|
|
getData();
|
|
}
|
|
}).addClass((currentRangeStart <= 1) ? 'disabled' : '').appendTo($footerRight);
|
|
|
|
// Append pagination
|
|
if (resultsCount > defaults.getData.data.limit) {
|
|
var pages = Math.round(resultsCount / defaults.getData.data.limit);
|
|
pages += (resultsCount % defaults.getData.data.limit) ? 1 : 0;
|
|
|
|
for (var p = 1; p < pages; ++p) (function(curP) {
|
|
|
|
if (pages < 9 || (curP >= defaults.getData.data.page - 2 && curP <= defaults.getData.data.page + 2) || curP == 1 || curP == pages - 1) {
|
|
$('<div class="audarisToolsButton">' + curP + '</div>').click(function() {
|
|
if (curP != defaults.getData.data.page) {
|
|
defaults.getData.data.page = curP;
|
|
getData();
|
|
}
|
|
}).addClass((curP == defaults.getData.data.page) ? 'disabled' : '').appendTo($footerRight);
|
|
} else if (curP == 2 || curP == pages - 2) {
|
|
$('<span>...</span>').appendTo($footerRight);
|
|
}
|
|
})(p);
|
|
}
|
|
|
|
// Append forward button
|
|
$('<div class="audarisToolsButton">weiter</div>').click(function() {
|
|
if (currentRangeEnd < resultsCount) {
|
|
defaults.getData.data.page += 1;
|
|
getData();
|
|
}
|
|
}).addClass((currentRangeEnd >= resultsCount) ? 'disabled' : '').appendTo($footerRight);
|
|
}
|
|
};
|
|
|
|
|
|
// Default run
|
|
if (typeof defaults.getData == 'object' && defaults.getData.source && defaults.getData.format) {
|
|
getData();
|
|
} else {
|
|
initialize();
|
|
}
|
|
|
|
});
|
|
},
|
|
|
|
numberFormat: function(number, decimals, dec_point, thousands_sep) {
|
|
/* Formats a number with grouped thousands
|
|
* version: 1009.820
|
|
* original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
|
|
* discuss at: http://phpjs.org/functions/number_format
|
|
*/
|
|
number = (number + '').replace(',', '').replace(' ', '');
|
|
var n = !isFinite(+number) ? 0 : +number;
|
|
var prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
|
|
var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
|
|
var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
|
|
var s = '';
|
|
|
|
var toFixedFix = function (n, prec) {
|
|
var k = Math.pow(10, prec);
|
|
|
|
return '' + Math.round(n * k) / k;
|
|
};
|
|
|
|
// Fix for IE parseFloat(0.55).toFixed(0) = 0;
|
|
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
|
|
if (s[0].length > 3) {
|
|
s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
|
|
}
|
|
if ((s[1] || '').length < prec) {
|
|
s[1] = s[1] || '';
|
|
s[1] += new Array(prec - s[1].length + 1).join('0');
|
|
}
|
|
|
|
return s.join(dec);
|
|
},
|
|
|
|
makeCurrency: function(value) {
|
|
return methods.numberFormat(value, 2, ',', '.') + ' €';
|
|
},
|
|
|
|
addButtons: function(options) {
|
|
var defaults = {
|
|
};
|
|
|
|
$.extend(defaults, options);
|
|
|
|
return this.each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
if (typeof defaults.buttons == 'object' && defaults.buttons.length > 0) {
|
|
$.each(defaults.buttons, function(index, buttonData) {
|
|
|
|
var $newButton = $('<div />').addClass('audarisToolsButton').appendTo($this);
|
|
|
|
if (buttonData.icon) {
|
|
var $buttonIcon = $('<div class="buttonIcon" />').addClass('ui-icon ui-icon-' + buttonData.icon).appendTo($newButton);
|
|
}
|
|
|
|
$('<div class="buttonText" />').html(buttonData.text).appendTo($newButton);
|
|
$('<br class="buttonClear" />').appendTo($newButton);
|
|
|
|
|
|
if (buttonData.disabled) {
|
|
$newButton.addClass('disabled');
|
|
|
|
if ($buttonIcon) {
|
|
$buttonIcon.css({
|
|
opacity: 0.3
|
|
});
|
|
}
|
|
} else if (typeof buttonData.onClick == 'function') {
|
|
$newButton.click(buttonData.onClick);
|
|
}
|
|
|
|
});
|
|
}
|
|
});
|
|
},
|
|
|
|
dottedList: function(options) {
|
|
var defaults = {
|
|
};
|
|
|
|
$.extend(defaults, options);
|
|
|
|
return this.each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
$('ul>li:even', $this).addClass('leftElement');
|
|
$('ul>li:odd', $this).addClass('rightElement');
|
|
|
|
$this.children('ul').addClass('dottedList').append('<li class="clear" />');
|
|
});
|
|
},
|
|
|
|
showSwitcher: function(options) {
|
|
var defaults = {
|
|
};
|
|
|
|
$.extend(defaults, options);
|
|
|
|
return this.each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
var thisId = $(this).attr('id');
|
|
|
|
$('[class^=showSwitcher:' + thisId + ']').each(function() {
|
|
var curDisp = $(this).css('display');
|
|
|
|
$(this).data('oldCSSDisplay', curDisp).mouseover(function(e) {
|
|
return false;
|
|
});
|
|
});
|
|
|
|
$this.change(function() {
|
|
$('[class^=showSwitcher:' + thisId + ']').css({
|
|
display: 'none'
|
|
});
|
|
|
|
var oldDisp = $('[class^=showSwitcher:' + thisId + ':' + $this.val() + ']').data('oldCSSDisplay');
|
|
$('[class^=showSwitcher:' + thisId + ':' + $this.val() + ']').css({
|
|
display: oldDisp
|
|
});
|
|
}).trigger('change');
|
|
});
|
|
},
|
|
|
|
/*loadModule: function(options) {
|
|
var defaults = {
|
|
module: false
|
|
};
|
|
|
|
$.extend(defaults, options);
|
|
|
|
if (defaults.module) {
|
|
$.get('/ui.php', {
|
|
ajaxModule: defaults.module
|
|
}, function(data) {
|
|
$('#contentContainer').empty().html(data);
|
|
|
|
eval(defaults.module.replace(/\./, '') + 'Init();');
|
|
});
|
|
} else {
|
|
alert('No module requested');
|
|
}
|
|
},*/
|
|
|
|
showLoader: function(options) {
|
|
var defaults = {
|
|
infoText: 'Daten werden verarbeitet. Bitte warten.',
|
|
hide: false
|
|
};
|
|
|
|
$.extend(defaults, options);
|
|
|
|
var $this = $(this);
|
|
|
|
var $loaderElement = $('<div />').addClass('audarisToolsLoader').html(defaults.infoText).appendTo($this);
|
|
|
|
if (defaults.hide) {
|
|
defaults.hide.hide();
|
|
}
|
|
|
|
$this.bind('close', function() {
|
|
$loaderElement.empty().remove();
|
|
|
|
if (defaults.hide) {
|
|
defaults.hide.show();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
|
|
$.fn.audarisTools = function(method) {
|
|
|
|
if (methods[method]) {
|
|
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
|
} else {
|
|
$.error('Method ' + method + ' does not exist on jQuery.audarisTools');
|
|
return false;
|
|
}
|
|
};
|
|
|
|
})(jQuery);
|
|
|