X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FClientJS.pm;h=d58905e75986cb90178a56a7f3a6a30d3164dc0e;hb=2f6e7625957d22de1008f2c6828835295b468fb7;hp=6a458be1a4ed97e507c549f335b10399567f5d4b;hpb=b9740e8a9a77eafcaf7aacd530af23fa8dbcb9f9;p=kivitendo-erp.git diff --git a/SL/ClientJS.pm b/SL/ClientJS.pm index 6a458be1a..d58905e75 100644 --- a/SL/ClientJS.pm +++ b/SL/ClientJS.pm @@ -58,6 +58,11 @@ my %supported_methods = ( removeProp => 2, val => 2, + # Class attribute + addClass => 2, + removeClass => 2, + toggleClass => 2, + # Data storage data => 3, removeData => 2, @@ -81,6 +86,7 @@ my %supported_methods = ( 'jstree:reopen' => 1, # Modifying nodes + 'jstree:create_node' => 4, 'jstree:rename_node' => 3, 'jstree:delete_node' => 2, 'jstree:move_node' => 5, @@ -89,6 +95,9 @@ my %supported_methods = ( 'jstree:select_node' => 2, # $.jstree._reference($()).(, true) 'jstree:deselect_node' => 2, 'jstree:deselect_all' => 1, + + # ## other stuff ## + redirect_to => 1, # window.location.href = ); sub AUTOLOAD { @@ -122,6 +131,12 @@ sub action { return $self; } +sub action_if { + my ($self, $condition, @args) = @_; + + return $condition ? $self->action(@args) : $self; +} + sub init__actions { return []; } @@ -337,7 +352,38 @@ Instead of: The first variation is obviously better suited for chaining. -Additional functions: +=over 4 + +=item C + +Call the function with the name C<$method> on C<$self> with arguments +C<@args>. Returns the return value of the actual function +called. Useful for chaining (see above). + +=item C + +Call the function with the name C<$method> on C<$self> with arguments +C<@args> if C<$condition> is trueish. Does nothing otherwise. + +Returns the return value of the actual function called if +C<$condition> is trueish and C<$self> otherwise. Useful for chaining +(see above). + +This function is equivalent to the following: + + if ($condition) { + $obj->$method(@args); + } + +But it is easier to integrate into a method call chain, e.g.: + + $js->html('#content', $html) + ->action_if($item->is_flagged, 'toggleClass', '#marker', 'flagged') + ->render($self); + +=back + +=head2 ADDITIONAL FUNCTIONS =over 4 @@ -358,6 +404,14 @@ client will then show the message in the 'error' flash. The messages of multiple calls of C on the same C<$self> will be merged. +=item C + +Redirects the browser window to the new URL by setting the JavaScript +property C. Note that +L is AJAX aware and uses this +function if the current request is an AJAX request as determined by +L. + =back =head2 JQUERY FUNCTIONS