Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8c6871be

Von Moritz Bunkus vor fast 12 Jahren hinzugefügt

  • ID 8c6871bed016edac152019db5a7f88136bf9457b
  • Vorgänger 5f68c975
  • Nachfolger 4f70967e

$::request: Funktionen "is_ajax()" und "type()"

Unterschiede anzeigen:

SL/Request.pm
2 2

  
3 3
use strict;
4 4

  
5
use SL::Common;
6
use SL::MoreCommon qw(uri_encode uri_decode);
5
use parent qw(Rose::Object);
6

  
7
use CGI qw(-no_xhtml);
7 8
use List::Util qw(first max min sum);
8 9
use List::MoreUtils qw(all any apply);
9 10
use Exporter qw(import);
10 11

  
12
use SL::Common;
13
use SL::MoreCommon qw(uri_encode uri_decode);
14
use SL::Layout::None;
15
use SL::Presenter;
16

  
11 17
our @EXPORT_OK = qw(flatten unflatten read_cgi_input);
12 18

  
19
use Rose::Object::MakeMethods::Generic
20
(
21
  'scalar --get_set_init' => [ qw(cgi layout presenter is_ajax type) ],
22
);
23

  
24
sub init_cgi {
25
  return CGI->new({});
26
}
27

  
28
sub init_layout {
29
  return SL::Layout::None->new;
30
}
31

  
32
sub init_presenter {
33
  return SL::Presenter->new;
34
}
35

  
36
sub init_is_ajax {
37
  return ($ENV{HTTP_X_REQUESTED_WITH} || '') eq 'XMLHttpRequest' ? 1 : 0;
38
}
39

  
40
sub init_type {
41
  return 'html';
42
}
43

  
13 44
sub _store_value {
14 45
  my ($target, $key, $value) = @_;
15 46
  my @tokens = split /((?:\[\+?\])?(?:\.)|(?:\[\+?\]))/, $key;
......
322 353

  
323 354
=head1 NAME
324 355

  
325
SL::Request.pm - request parsing and data serialization
356
SL::Request.pm - request parsing, data serialization, request information
326 357

  
327 358
=head1 SYNOPSIS
328 359

  
329
This module handles unpacking of cgi parameters. usually you don't want to call
330
anything in here directly.
360
This module handles unpacking of CGI parameters. It also gives
361
information about the request like whether or not it was done via AJAX
362
or the requested content type.
331 363

  
332 364
  use SL::Request qw(read_cgi_input);
333 365

  
......
338 370
  my $new_arrayref = flatten($hashref);
339 371
  my $new_hashref  = unflatten($new_arrayref);
340 372

  
373
  # Handle AJAX requests differently than normal requests:
374
  if ($::request->is_ajax) {
375
    $controller->render('json-mask', { type => 'json' });
376
  } else {
377
    $controller->render('full-mask');
378
  }
341 379

  
342 380
=head1 DESCRIPTION
343 381

  
344
This module handles flattening and unflattening of data for request
382
This module provides information about the request made by the
383
browser.
384

  
385
It also handles flattening and unflattening of data for request
345 386
roundtrip purposes. kivitendo uses the format as described below:
346 387

  
347 388
=over 4
......
472 513

  
473 514
This function will parse the array ref, and will store the contents into the hash ref. The hash ref may be non empty, in this case any new keys will override the old ones only on leafs with same type. Type changes on a node will die.
474 515

  
516
=item C<is_ajax>
517

  
518
Returns trueish if the request is an XML HTTP request, also known as
519
an 'AJAX' request.
520

  
521
=item C<type>
522

  
523
Returns the requested content type (either C<html>, C<js> or C<json>).
524

  
475 525
=back
476 526

  
477 527
=head1 SPECIAL FUNCTIONS

Auch abrufbar als: Unified diff