1 namespace("kivi", function(ns) {
4 ns.t8 = function(text, params) {
5 var text = ns._locale[text] || text;
7 if( Object.prototype.toString.call( params ) === '[object Array]' ) {
8 var len = params.length;
10 for(var i=0; i<len; ++i) {
12 var value = params[i];
13 text = text.split("#"+ key).join(value);
16 else if( typeof params == 'object' ) {
17 for(var key in params) {
18 var value = params[key];
19 text = text.split("#{"+ key +"}").join(value);
26 ns.setupLocale = function(locale) {
30 ns.reinit_widgets = function() {
31 $('.datepicker').each(function() {
36 $('input.part_autocomplete').each(function(idx, elt){
37 kivi.PartPicker($(elt));
41 ns.submit_ajax_form = function(url, form_selector, additional_data) {
42 $(form_selector).ajaxSubmit({
44 data: additional_data,
45 success: ns.eval_json_result
51 // Return a function object by its name (a string). Works both with
52 // global functions (e.g. "check_right_date_format") and those in
53 // namespaces (e.g. "kivi.t8").
54 // Returns null if the object is not found.
55 ns.get_function_by_name = function(name) {
56 var parts = name.match("(.+)\\.([^\\.]+)$");
59 return namespace(parts[1])[ parts[2] ];
62 // Open a modal jQuery UI popup dialog. The content is loaded via AJAX.
65 // - id: dialog DIV ID (optional; defaults to 'jqueryui_popup_dialog')
66 // - url, data, type: passed as the first three arguments to the $.ajax() call
67 // - dialog: an optional object of options passed to the $.dialog() call
68 ns.popup_dialog = function(params) {
71 params = params || { };
72 var id = params.id || 'jqueryui_popup_dialog';
73 var dialog_params = $.extend(
74 { // kivitendo default parameters:
79 // User supplied options:
81 { // Options that must not be changed:
82 close: function(event, ui) { dialog.remove(); }
87 dialog = $('<div style="display:none" class="loading" id="' + id + '"></div>').appendTo('body');
88 dialog.dialog(dialog_params);
94 success: function(new_html) {
95 dialog.html(new_html);
96 dialog.removeClass('loading');
104 kivi = namespace('kivi');