XAO-Web
view release on metacpan or search on metacpan
lib/XAO/DO/Web/FS.pm view on Meta::CPAN
=head1 NAME
XAO::DO::Web::FS - XAO::Web front end object for XAO::FS
=head1 SYNOPSIS
<%FS uri="/Categories/123/description"%>
<%FS mode="show-list"
base.clipboard="cached-list"
base.database="/Foo/test/Bars"
fields="*"
header.path="/bits/foo-list-header"
path="/bits/foo-list-row"
default.path="/bits/foo-list-default"
%>
<%FS mode="search"
uri="/Orders"
index_1="status"
value_1="submitted"
compare_1="wq"
expression="1"
orderby="place_time"
fields="*"
header.path="/bits/admin/order/list-header"
path="/bits/admin/order/list-row"
footer.path="/bits/admin/order/list-footer"
default.path="/bits/foo-list-default"
%>
=head1 DESCRIPTION
Web::FS allows web site developer to directly access XAO Foundation
Server from templates without implementing specific objects.
=head1 SEARCH MODE
Accepts the following arguments:
=over
=item uri => '/Customers'
Database object path.
=item index_1..N => 'first_name|last_name'
Name of database field(s) to perform search on.
Multiple field names are separated by | (pipe character)
and treated as a logical 'or'.
=item value_1..N => 'Ann|Lonnie'
Keywords you want to search for in field(s) of corresponding index.
Multiple sets of keywords are separated by | (pipe character)
and treated as a logical 'or'.
=item compare_1..N => 'ws'
Comparison operator to be used in matching index to value.
Supported comparison operators are:
eq True if equal.
ge True if greater or equal.
gt True if greater.
le True if less or equal.
lib/XAO/DO/Web/FS.pm view on Meta::CPAN
compare_1="wq"
index_2="gender"
value_2="female"
compare_2="wq"
index_3="age"
value_3="21|30"
compare_3="gelt"
expression="[ [ 1 and 2 ] and 3 ]"
orderby="age|first_name+desc"
start_item="40"
items_per_page="20"
header.path="/bits/admin/order/list-header"
path="/bits/admin/order/list-row"
footer.path="/bits/admin/order/list-footer"
default.template="No matches found."
%>
=head2 CONFIGURATION VALUES SUPPORTED IN SEARCH MODE
=over
=item default_search_args
The value of this configuration value is a reference to a hash.
In this hash each key is a database (object) path (name) whose
corresponding value is a reference to a hash containing the
default arguments for searching on the specified of data.
These default arguments are added unless they are specified by
input arguments.
=back
=head1 METHODS
FS provides a useful base for other displayable object that work with
XAO::FS data.
=over
=cut
###############################################################################
package XAO::DO::Web::FS;
use strict;
use Digest::MD5 qw(md5_base64);
use XAO::Utils;
use XAO::Errors qw(XAO::DO::Web::FS);
use XAO::Objects;
use base XAO::Objects->load(objname => 'Web::Action');
our $VERSION='2.004';
###############################################################################
=item get_object (%)
Returns an object retrieved from either clipboard or the database.
Accepts the following arguments:
base.clipboard clipboard uri
base.database XAO::FS object uri
uri XAO::FS object URI relative to `base' object
or root if no base.* is given
If both base.clipboard and base.database are set then first attempt is
made to get object from the clipboard and then from the database. If the
object is retrieved from the database then it is stored in clipboard.
Next call with the same arguments will get the object from clipboard.
=cut
sub get_object ($%) {
my $self=shift;
my $args=get_args(\@_);
my $object;
my $cb_base=$args->{'base.clipboard'};
my $db_base=$args->{'base.database'};
$object=$self->clipboard->get($cb_base) if $cb_base;
!$object || ref($object) ||
throw $self "get_object - garbage in clipboard at '$cb_base'";
my $got_from_cb=$object;
$object=$self->odb->fetch($db_base) if $db_base && !$object;
if($cb_base) {
$db_base || $object ||
throw $self "get_object - no object in clipboard and" .
" no base.database to retrieve it";
##
# Caching object in clipboard if we have both base.clipboard and
# base.database.
#
if($object && !$got_from_cb) {
$self->clipboard->put($cb_base => $object);
}
}
my $uri=$args->{uri};
if($object && $uri && $uri !~ /^\//) {
##
# XXX - This should be done in FS
#
foreach my $name (split(/\/+/,$uri)) { $object=$object->get($name); }
}
elsif(defined($uri) && length($uri)) {
$object=$self->odb->fetch($uri);
}
$cb_base || $db_base || $uri ||
throw $self "get_object - at least one location parameter must present";
$object;
}
###############################################################################
=back
Here is the list of accepted 'mode' arguments and corresponding method
names. The default mode is 'show-property'.
=over
=cut
###############################################################################
sub check_mode ($%) {
my $self=shift;
my $args=get_args(\@_);
my $mode=$args->{mode} || 'show-property';
if ($mode eq 'search') { $self->search($args); }
elsif($mode eq 'delete-property') { $self->delete_property($args); }
elsif($mode eq 'show-hash') { $self->show_hash($args); }
elsif($mode eq 'show-list') { $self->show_list($args); }
elsif($mode eq 'show-property') { $self->show_property($args); }
elsif($mode eq 'delete-object') { $self->delete_object($args); }
elsif($mode eq 'edit-object') { $self->edit_object($args); }
else {
throw $self "check_mode - unknown mode '$mode'";
}
}
###############################################################################
=item delete-property => delete_property (%)
Deletes an object or property pointed to by `name' argument.
Example of deleting an entry from Addresses list by ID:
<%FS
mode="delete-property"
base.clipboard="/IdentifyUser/customer/object"
uri="Addresses"
name="<%ID/f%>"
%>
=cut
sub delete_property ($%) {
my $self=shift;
my $args=get_args(\@_);
my $object=$self->get_object($args);
my $name=$args->{name} ||
throw $self "delete_property - no 'name'";
if($object->objtype eq 'List') {
$object->check_name($name) ||
throw $self "delete_property - bad name '$name'";
}
else {
$self->odb->check_name($name) ||
throw $self "delete_property - bad name '$name'";
}
$object->delete($name);
}
###############################################################################
=item show-hash => show_hash (%)
Displays a XAO::FS hash derived object. Object location is the same as
described in get_object() method. Additional arguments are:
fields comma or space separated list of fields that are
to be retrieved from each object in the list and
passed to the template. Field names are converted
to all uppercase when passed to template. For
convenience '*' means to pass all
property names (lists be passed as empty strings).
path path to the template that gets displayed with the
given fields passed in all uppercase.
extra_sub reference to a subroutine that creates additional
parameters for the template and returns them in
a hash reference. For use in derived class
methods.
Example:
<%FS mode="show-hash" uri="/Customers/c123" fields="firstname,lastname"
path="/bits/customer-name"%>
Where /bits/customer-name should be something like:
Customer Name: <%FIRSTNAME/h%> <%LASTNAME/h%>
=cut
( run in 0.899 second using v1.01-cache-2.11-cpan-81fc1098f69 )