X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/a6b4b406f0a9db0a1c719f4b7d5eb8265f90bf61..a88e544966ffc9b0d5b2990709fdcb7c4713c1fd:/js/kivi.js diff --git a/js/kivi.js b/js/kivi.js index 77c78a2cc..2be03018b 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -1,25 +1,8 @@ namespace("kivi", function(ns) { - - ns._localeLang = false; - ns._locales = {}; + ns._locale = {}; ns.t8 = function(text, params) { - if( ns._localeLang ) { - if( !ns._locales[ns._localeLang] ) { - ns._locales[ns._localeLang] = {}; - - jQuery.ajax({ - url: "js/locale/"+ ns._localeLang +".js", - async: false, - dataType: "json", - success: function(res) { - ns._locales[ns._localeLang] = res; - }, - }); - } - - text = ns._locales[ns._localeLang][text] || text; - } + var text = ns._locale[text] || text; if( Object.prototype.toString.call( params ) === '[object Array]' ) { var len = params.length; @@ -40,8 +23,72 @@ namespace("kivi", function(ns) { return text; }; - ns.initLocale = function(localeLang) { - ns._localeLang = localeLang; + ns.setupLocale = function(locale) { + ns._locale = locale; + }; + + ns.reinit_widgets = function() { + $('.datepicker').each(function() { + $(this).datepicker(); + }); + + if (ns.PartPicker) + $('input.part_autocomplete').each(function(idx, elt){ + kivi.PartPicker($(elt)); + }); + }; + + // Return a function object by its name (a string). Works both with + // global functions (e.g. "check_right_date_format") and those in + // namespaces (e.g. "kivi.t8"). + // Returns null if the object is not found. + ns.get_function_by_name = function(name) { + var parts = name.match("(.+)\\.([^\\.]+)$"); + if (!parts) + return window[name]; + return namespace(parts[1])[ parts[2] ]; }; + // Open a modal jQuery UI popup dialog. The content is loaded via AJAX. + // + // Parameters: + // - id: dialog DIV ID (optional; defaults to 'jqueryui_popup_dialog') + // - url, data, type: passed as the first three arguments to the $.ajax() call + // - dialog: an optional object of options passed to the $.dialog() call + ns.popup_dialog = function(params) { + var dialog; + + params = params || { }; + var id = params.id || 'jqueryui_popup_dialog'; + var dialog_params = $.extend( + { // kivitendo default parameters: + width: 800 + , height: 500 + , modal: true + }, + // User supplied options: + params.dialog || { }, + { // Options that must not be changed: + close: function(event, ui) { dialog.remove(); } + }); + + $('#' + id).remove(); + + dialog = $('
').appendTo('body'); + dialog.dialog(dialog_params); + + $.ajax({ + url: params.url, + data: params.data, + type: params.type, + success: function(new_html) { + dialog.html(new_html); + dialog.removeClass('loading'); + } + }); + + return true; + }; }); + +kivi = namespace('kivi');