package WebGUI::Asset::Wobject::DataTable; $VERSION = "1.0.0"; #------------------------------------------------------------------- # WebGUI is Copyright 2001-2009 Plain Black Corporation. #------------------------------------------------------------------- # Please read the legal notices (docs/legal.txt) and the license # (docs/license.txt) that came with this distribution before using # this software. #------------------------------------------------------------------- # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- use strict; use Moose; use WebGUI::Definition::Asset; extends 'WebGUI::Asset::Wobject'; define assetName => ['assetName', 'Asset_DataTable']; define icon => 'DataTable.gif'; define tableName => 'DataTable'; property data => ( fieldType => 'DataTable', default => undef, label => '', ); property templateId => ( tab => "display", fieldType => "template", namespace => "DataTable", default => "3rjnBVJRO6ZSkxlFkYh_ug", label => ["editForm templateId label", 'Asset_DataTable'], hoverHelp => ["editForm templateId description", 'Asset_DataTable'], ); use WebGUI::International; use WebGUI::Form::DataTable; #---------------------------------------------------------------------------- =head2 getDataJson ( ) Get the data as a JSON object with the following structure: { columns => [ { key => "Column Key", formatter => "Column Format", }, ... ], rows => [ { "Column Key" => "Column Value", ... }, ... ], } =cut sub getDataJson { my $self = shift; return $self->data; } #---------------------------------------------------------------------------- =head2 getDataTable ( ) Get the YUI DataTable markup and script for this DataTable. =cut # TODO Have this method get from a WebGUI::DataSource object sub getDataTable { my $self = shift; if ( !$self->{_datatable} ) { $self->prepareView; } return $self->{_datatable}->getValueAsHtml; } #---------------------------------------------------------------------------- =head2 getDataTemplateVars ( ) Get the template variables for the raw data. Returns a hash reference with "rows" and "columns" keys. =cut # TODO Have this method get from a WebGUI::DataSource object sub getDataTemplateVars { my $self = shift; my $json = $self->getDataJson; my $dt = eval { JSON->new->decode($json) }; # Make row data more friendly to templates my %cols = map { $_->{key} => $_ } @{ $dt->{columns} }; for my $row ( @{ $dt->{rows} } ) { # Create the column loop for the row for my $col ( @{ $dt->{columns} } ) { push @{ $row->{row_columns} }, { %{$col}, value => $row->{ $col->{key} }, }; } } return $dt; } ## end sub getDataTemplateVars #---------------------------------------------------------------------------- =head2 getEditForm ( ) Add the data table to the edit form. =cut # TODO Get the DataSource's edit form override getEditForm => sub { my $self = shift; my $tabform = super(); $tabform->getTab("data")->raw( q{