From 3ac83c6134a876990a2b5e26075e4304b3ce1cae Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 12 Jul 2013 16:06:07 +0200 Subject: [PATCH] ClientJS: automatisch Date- und Partpicker nach AJAX-Request initialisieren --- SL/ClientJS.pm | 3 +++ SL/Presenter.pm | 4 ++++ SL/Presenter/Part.pm | 2 ++ SL/Template/Plugin/L.pm | 2 ++ js/client_js.js | 1 + js/kivi.js | 11 +++++++++++ 6 files changed, 23 insertions(+) diff --git a/SL/ClientJS.pm b/SL/ClientJS.pm index 96132cfb3..7eb092c47 100644 --- a/SL/ClientJS.pm +++ b/SL/ClientJS.pm @@ -103,6 +103,8 @@ my %supported_methods = ( # ## other stuff ## redirect_to => 1, # window.location.href = + + reinit_widgets => 0, # kivi.reinit_widgets() ); sub AUTOLOAD { @@ -168,6 +170,7 @@ sub to_array { sub render { my ($self, $controller) = @_; + $self->reinit_widgets if $::request->presenter->need_reinit_widgets; return $controller->render(\$self->to_json, { type => 'json' }); } diff --git a/SL/Presenter.pm b/SL/Presenter.pm index e7ad00976..4ea5b261f 100644 --- a/SL/Presenter.pm +++ b/SL/Presenter.pm @@ -19,6 +19,10 @@ use SL::Presenter::SepaExport; use SL::Presenter::Text; use SL::Presenter::Tag; +use Rose::Object::MakeMethods::Generic ( + scalar => [ qw(need_reinit_widgets) ], +); + sub get { return $::request->presenter; } diff --git a/SL/Presenter/Part.pm b/SL/Presenter/Part.pm index fff9f5ee7..332d5dbe7 100644 --- a/SL/Presenter/Part.pm +++ b/SL/Presenter/Part.pm @@ -18,6 +18,8 @@ sub part_picker { join('', map { $params{$_} ? $self->input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(column type unit convertible_unit)) . $self->input_tag("", (ref $value && $value->can('description')) ? $value->description : '', id => "${id}_name", %params); + $::request->presenter->need_reinit_widgets($id); + $self->html_tag('span', $ret, class => 'part_picker'); } diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index 78efe642a..c072d08e1 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -226,6 +226,8 @@ sub date_tag { push @classes, delete($params{class}) if $params{class}; my %class = @classes ? (class => join(' ', @classes)) : (); + $::request->presenter->need_reinit_widgets($params{id}); + return $self->input_tag( $name, blessed($value) ? $value->to_lxoffice : $value, size => 11, diff --git a/js/client_js.js b/js/client_js.js index 0477715a8..e096d5236 100644 --- a/js/client_js.js +++ b/js/client_js.js @@ -119,6 +119,7 @@ ns.eval_json_result = function(data) { // ## other stuff ## else if (action[0] == 'redirect_to') window.location.href = action[1]; + else if (action[0] == 'reinit_widgets') kivi.reinit_widgets(); else console.log('Unknown action: ' + action[0]); diff --git a/js/kivi.js b/js/kivi.js index bd169b231..ea892f521 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -26,6 +26,17 @@ namespace("kivi", function(ns) { 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)); + }); + }; }); kivi = namespace('kivi'); -- 2.20.1