X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=js%2Fkivi.js;h=4448921178dd20dfc5a4961d3416854433e23cf5;hb=c092c963921436b418f42ed73bece53878a61bf0;hp=3ee73a7085d648b3540e27d7bfc21159b7dbd51f;hpb=25b6e6a881fe0faf7f85b81c6eb6ee25a835b542;p=kivitendo-erp.git diff --git a/js/kivi.js b/js/kivi.js index 3ee73a708..444892117 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -8,6 +8,11 @@ namespace("kivi", function(ns) { m: 1, d: 0 }; + ns._time_format = { + sep: ':', + h: 0, + m: 1, + }; ns._number_format = { decimalSep: ',', thousandSep: '.' @@ -22,6 +27,13 @@ namespace("kivi", function(ns) { ns._date_format[res[4].substr(0, 1)] = 2; } + res = (params.times || "").match(/^([hm]+)([^a-z])([hm]+)$/); + if (res) { + ns._time_format = { sep: res[2] }; + ns._time_format[res[1].substr(0, 1)] = 0; + ns._time_format[res[3].substr(0, 1)] = 1; + } + res = (params.numbers || "").match(/^\d*([^\d]?)\d+([^\d])\d+$/); if (res) ns._number_format = { @@ -101,6 +113,51 @@ namespace("kivi", function(ns) { return parts.join(ns._date_format.sep); }; + ns.parse_time = function(time) { + var now = new Date(); + + if (time === undefined) + return undefined; + + if (time === '') + return null; + + if (time === '0') + return now; + + // special case 1: military time in fixed "hhmm" format + if (time.length == 4) { + var res = time.match(/(\d\d)(\d\d)/); + if (res) { + now.setHours(res[1], res[2]); + return now; + } else { + return undefined; + } + } + + var parts = time.replace(/\s+/g, "").split(ns._time_format.sep); + if (parts.length == 2) { + for (var idx in parts) { + if (Number.isNaN(Number.parseInt(parts[idx]))) + return undefined; + } + now.setHours(parts[ns._time_format.h], parts[ns._time_format.m]); + return now; + } else + return undefined; + } + + ns.format_time = function(date) { + if (isNaN(date.getTime())) + return undefined; + + var parts = [ "", "" ] + parts[ ns._time_format.h ] = date.getHours().toString().padStart(2, '0'); + parts[ ns._time_format.m ] = date.getMinutes().toString().padStart(2, '0'); + return parts.join(ns._time_format.sep); + }; + ns.parse_amount = function(amount) { if (amount === undefined) return undefined; @@ -252,7 +309,10 @@ namespace("kivi", function(ns) { if (elementId) { var cookieName = 'jquery_ui_tab_'+ elementId; - tabsParams.active = $.cookie(cookieName); + if (!window.location.hash) { + // only activate if there's no hash to overwrite it + tabsParams.active = $.cookie(cookieName); + } tabsParams.activate = function(event, ui) { var i = ui.newTab.parent().children().index(ui.newTab); $.cookie(cookieName, i);