Mercurial > pub > Impl
diff Lib/IMPL/Web/View/TTControl.pm @ 299:bd79145657e5
sync
author | sergey |
---|---|
date | Thu, 21 Mar 2013 16:00:09 +0400 |
parents | 86ff93b34f2a |
children | bf3af33b9003 |
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTControl.pm Tue Mar 19 02:02:37 2013 +0400 +++ b/Lib/IMPL/Web/View/TTControl.pm Thu Mar 21 16:00:09 2013 +0400 @@ -3,7 +3,7 @@ use IMPL::Const qw(:prop); use IMPL::lang qw(:hash); -use Scalar::Util qw(blessed); +use Scalar::Util qw(blessed reftype); use IMPL::declare { require => { TemplateDocument => 'Template::Document', @@ -18,7 +18,6 @@ props => [ id => PROP_RO, attributes => PROP_RW, - name => PROP_RO, context => PROP_RO, template => PROP_RO ] @@ -28,50 +27,28 @@ { my $nextId = 1; sub _GetNextId { - return $nextId++; + return '_' . $nextId++; } } our $AutoloadRegex = qr/^[a-z]/; -our @REFLECT_META = qw(title layout); sub CTOR { - my ($this,$name,$template,$context,$refProps) = @_; + my ($this,$template,$context,$attrs) = @_; - $name ||= "control"; - + $this->template( $template ) or die new IMPL::ArgumentException("A template is required"); $this->context( $context ) or die new IMPL::ArgumentException("A context is required"); - $this->id($name . "-" . _GetNextId()) unless $this->id; - - $this->name($name); $this->attributes({}); - my %attrs; - - foreach my $meta ( @REFLECT_META ) { - next if $meta =~ /^_/; - if( my $value = $template->$meta() ) { - $attrs{$meta} = $value; - } + if(reftype($attrs) eq 'HASH') { + while (my($key,$value) = each %$attrs) { + $this->SetAttribute($key,$value); + } } - hashApply(\%attrs,$refProps) if ref $refProps eq 'HASH'; - - while (my($key,$value) = each %attrs) { - $this->SetAttribute($key,$value); - } -} - -sub InitInstance { - my ($this,$args) = @_; - - $args ||= {}; - - if ( my $ctor = $this->template->blocks->{CTOR} ) { - $this->context->include($ctor, { %$args, this => $this, template => $this->template } ); - } + $this->id(_GetNextId()) unless $this->id; } sub GetAttribute { @@ -97,37 +74,19 @@ } } -sub GetMainBlock { - $_[0]->template->blocks->{RENDER} || $_[0]->template; -} - sub Render { my ($this,$args) = @_; $args = {} unless ref $args eq 'HASH'; - if(my $body = $this->GetMainBlock ) { - return $this->context->include( $body, { %$args, this => $this, template => $this->template } ); - } else { - return ""; - } -} - -sub RenderBlock { - my ($this, $block, $args) = @_; - - $args = {} unless ref $args eq 'HASH'; - - return $block ? $this->context->include( $block, { %$args, this => $this, template => $this->template } ) : undef; -} - -sub ExportBlock { - my ($this,$block) = @_; - - return TemplateDocument->new({ - BLOCK => $this->template->blocks->{$block}, - DEFBLOCKS => $this->template->blocks - }); + return $this->context->include( + $this->template, + { + %$args, + this => $this, + template => $this->template + } + ); } sub AUTOLOAD { @@ -166,29 +125,20 @@ META version = 1; BLOCK INIT; # this is a document scope - dojo.require.push( 'dijit/form/Input' ); + dojo.modules.push( 'dijit/form/Input' ); END; - BLOCK CTOR; - # local to this block - TPreview = require('My/Org/TextPreview'); - - # init control props - this.dojoClass = this.dojoClass || 'dijit.form.Input'; - this.visualClass = this.visualClass || 'classic'; - this.childNodes = []; + + # local to this block + TPreview = require('My/Org/TextPreview'); - # init content - FOREACH text IN this.data; - this.childNodes.push( TPreview.new('preview', nodeValue = text ) ); - END; - - END; -%] - -<div class="$this.visualClass" data-dojo-type="$this.dojoClass"> - [% FOREACH node IN this.childNodes %] - [% node.Render() %] - <hr /> + # init control props + visualClass = this.visualClass || 'classic'; +%] +<div id="$id" class="$visualClass" data-dojo-type="dijit/form/Input"> + [% FOREACH item IN model %] + <div class="itemContainer"> + [% Display(item) %] + </div> [% END %] </div> @@ -196,8 +146,9 @@ =head1 DESCRIPTION -Представляет собой фрагмент документа, который имеет шаблон для отображения, -набор свойств и т.п. +Легкая обертка вокруг шаблона, позволяет изолировать пространство имен шаблона, +а также реализовать собственные методы по представлению данных (в случае если +это проще сделать в виде методов класса). =head2 BLOCKS