]> wagnertech.de Git - mfinanz.git/blobdiff - js/kivi.js
kivi.js: Funktion zum Auffinden von Funktionen über ihren Namen
[mfinanz.git] / js / kivi.js
index db9904b53acc076aa3f2895fd3126a8f5a6b4668..5901c89a1aae3397f307a571d3115d47811b0bc3 100644 (file)
@@ -1,26 +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] ) {
-        jQuery.ajax({
-          url: "locale/"+ ns._localeLang +"/js.js",
-          async: false,
-          dataType: "json",
-          success: function(res) {
-            ns._locales[ns._localeLang] = res;
-          },
-          error: function(xhr, textStatus, errorThrown) {
-            alert(textStatus +": "+ errorThrown);
-          },
-        });
-      }
-
-      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;
@@ -41,8 +23,31 @@ 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] ];
+  };
 });
+
+kivi = namespace('kivi');