+ ns.setupLocale = function(locale) {
+ ns._locale = locale;
+ };
+
+ ns.reinit_widgets = function() {
+ ns.run_once_for('.datepicker', 'datepicker', function(elt) {
+ $(elt).datepicker();
+ });
+
+ if (ns.PartPicker)
+ ns.run_once_for('input.part_autocomplete', 'part_picker', function(elt) {
+ kivi.PartPicker($(elt));
+ });
+
+ var func = kivi.get_function_by_name('local_reinit_widgets');
+ if (func)
+ func();
+ };
+
+ ns.submit_ajax_form = function(url, form_selector, additional_data) {
+ $(form_selector).ajaxSubmit({
+ url: url,
+ data: additional_data,
+ success: ns.eval_json_result
+ });
+
+ return true;
+ };
+
+ // 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 can be either
+ // loaded via AJAX (if the parameter 'url' is given) or simply
+ // displayed if it exists in the DOM already (referenced via
+ // 'id'). If an existing DOM div should be used then the element
+ // won't be removed upon closing the dialog which allows re-opening
+ // it later on.
+ //
+ // Parameters:
+ // - id: dialog DIV ID (optional; defaults to 'jqueryui_popup_dialog')
+ // - url, data, type: passed as the first three arguments to the $.ajax() call if an AJAX call is made, otherwise ignored.
+ // - 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) { if (params.url) dialog.remove(); else dialog.dialog('close'); }
+ });
+
+ if (!params.url) {
+ // Use existing DOM element and show it. No AJAX call.
+ dialog = $('#' + id).dialog(dialog_params);
+ return true;
+ }
+
+ $('#' + id).remove();
+
+ dialog = $('<div style="display:none" class="loading" id="' + id + '"></div>').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;