Mojolicious-Plugin-DevexpressHelpers
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/DevexpressHelpers/Helpers.pm view on Meta::CPAN
}
}
return \%attrs;
}
sub dxmenu {
my $c = shift;
my $attrs = parse_attributs( $c, [qw(id @items onItemClick)], @_ );
my $id = delete($attrs->{id}) // new_id( $c, $attrs );
dxbind( $c, 'dxMenu' => $id => $attrs);
}
sub dxloadpanel {
my $c = shift;
my $attrs = parse_attributs( $c, [qw(id message)], @_ );
my $id = delete($attrs->{id}) // new_id( $c, $attrs );
dxbind( $c, 'dxLoadPanel' => $id => $attrs);
}
sub dxbutton {
my $c = shift;
my $attrs = parse_attributs( $c, [qw(id text onClick type)], @_ );
my $id = delete($attrs->{id}) // new_id( $c, $attrs );
dxbind( $c, 'dxButton' => $id => $attrs);
}
sub dxdatagrid{
my $c = shift;
my $attrs = parse_attributs( $c, [qw(id dataSource)], @_ );
my $id = delete($attrs->{id}) // new_id( $c, $attrs );
my @extensions;
#dxbind( $c, 'dxDataGrid' => $id => $attrs, [ $dataSource ]);
if ($attrs->{dataSource} && ref($attrs->{dataSource}) eq '') {
my $dataSource = delete $attrs->{dataSource};
#push @extensions, '$.getJSON("' . $dataSource . '",function(data){$("#'.$id.'").dxDataGrid({ dataSource: data });});';
#$attrs->{dataSource} = \'[]'; #protect string to be "stringified" within dxbind
#\"" is to protect string to be "stringified" within dxbind
$attrs->{dataSource} = \"{store:{type:'odata',url:'$dataSource'}}";
}
if (exists $attrs->{options}) {
$attrs = $attrs->{options};
}
dxbind( $c, 'dxDataGrid' => $id => $attrs, \@extensions);
}
sub dxform{
my $c = shift;
my $attrs = parse_attributs( $c, [qw(id %formData @items)], @_ );
my $id = delete($attrs->{id}) // new_id( $c, $attrs );
dxbind( $c, 'dxForm' => $id => $attrs );
}
sub dxpopup{
my $c = shift;
my $attrs = parse_attributs( $c, [qw(id title contentTemplate)], @_ );
my $id = delete($attrs->{id}) // new_id( $c, $attrs );
dxbind( $c, 'dxPopup' => $id => $attrs );
}
sub mk_dxcontrol{
my $dxControl = shift;
my $generic = sub{
my $c = shift;
my $attrs = parse_attributs( $c, [qw(id value label)], @_ );
my $id = delete($attrs->{id});
if (my $name = $id) {
$attrs->{name}=$name;
}
$id //= new_id( $c, $attrs );
my (@before, @after);
if(my $label = delete($attrs->{label})){
push @before, '<div class="dx-field">';
push @before, '<div class="dx-field-label">'.$label.'</div>';
push @before, '<div class="dx-field-value">';
push @after, '</div>';
push @after, '</div>';
}
dxbind( $c, $dxControl => $id => $attrs, undef, \@before, \@after );
};
{
no strict 'refs';
*{__PACKAGE__.'::'.lc $dxControl} = $generic;
}
}
sub dxbuild {
my $c = shift;
my %opts = @_;
my $dxhelper = $c->stash('dxHelper') or return;
if($dxhelper->{bindings}){
out '<script language="javascript">'.
($opts{js_prefix}//'$(window).on("load",function(){') .
"\n".
join("\n",
grep{ ($_//'') ne ''}
@$dxhelper{'before_bindings','bindings','after_bindings'}
).
"\n".
($opts{js_sufix}//'});').'</script>';
}
}
sub require_asset{
my $c = shift;
lib/Mojolicious/Plugin/DevexpressHelpers/Helpers.pm view on Meta::CPAN
=head2 dxbind
Internal usage.
dxbind( $c, 'dxButton' => $id => $attrs, \@extensions);
Produce a div tag with an computed id, which will be binded to
a dxButton with C<$attrs> attributs at call to dxbuild.
=head2 parse_attributs
Internal usage
my $attrs = parse_attributs( $c, \@implicit_arguments, @attributs )
=head2 dxmenu C< $id, \@items ,[ \%options ]>
%= dxmenu mainMenu => [{ id => 1, text => 'Back', iconSrc => '/images/back.png', link => 'javascript:location.back();' }], \q% function(e){return e.itemData.link;} %
=head2 dxloadpanel C<[ $id, [ $message ] ], [ \%options ]>
%= dxloadpanel myLoadPanel => 'Please wait'
=head2 dxbutton C<[ $id, [ $text, [ $onclick ] ] ], [ \%options ]>
%= dxbutton myButtonId => 'My button' => q{ function (){ alert('onClick!'); } }
%= dxbutton undef, 'My button' => '/some/url'
%= dxbutton {
id => myId,
text => 'My button',
onClick => q{ function (){ alert('onClick!'); } },
type => 'danger',
icon => 'user'
};
=head2 dxdatagrid C<[ $id, [ $datasource, ] ] [ \%opts ]>
%= dxdatagrid 'myID' => '/products.json', { columns => [qw( name description price )] }
%= dxdatagrid undef, '/products.json'
%= dxdatagrid { id => myId, dataSource => '/products.json' }
The following syntaxe allow to specify all options from a javascript object.
B<Note: It will ignore all other options specified in the hash reference.>
%= dxdatagrid myId, { options => 'JSFrameWork.gridsOptions.myResource' }
=head2 dxform C<[ $id, [ $formData, [ \@itemsSpecs ], [ \%opts ] ] ]>
%= dxform myForm => \%formData;
%= dxform myForm => \%formData, { colCount => 2 };
%= dxform myForm => \%formData, \%itemsSpecs;
%= dxform myForm => \%formData, \%itemsSpecs, { colCount => '3' };
=head2 dxpopup C<[ $id, [ $title, [ $contentTemplate, ] ] ], [\%opts]>
%= dxpopup myPopupID => 'Popup Title', \q{function(contentElement){
contentElement.append('<p>Hello!</p>');
}};
=head2 mk_dxcontrol C<$dxControlName>
In this package:
mk_dxcontrol('dxNumberBox');
mk_dxcontrol('dxSwitch');
mk_dxcontrol('dxTextBox');
mk_dxcontrol('dxLookup');
mk_dxcontrol('dxSelectBox');
In your template:
%= dxnumberbox 'age' => $value => 'Age: ', { placeHolder => 'Enter your age' }
%= dxswitch 'mySwitch' => $boolean_value => 'Enabled: '
%= dxtextbox 'name' => $value => 'Name: ', { placeHolder => 'Type a name' }
%= dxlookup 'name' => $value => 'Name: ', { dataSource => $ds, valueExpr=> $ve, displayExpr => $de }
%= dxselectbox 'name' => $value => 'Name: ', { dataSource => $ds, valueExpr=> $ve, displayExpr => $de }
=head2 dxbuild C<[ js_prefix => '$(function(){', js_sufix => '});' ]>
Build the binding between jQuery and divs generated by plugin helpers such as dxbutton.
It is should to be called in your template just before you close the body tag.
Optional named argument C<js_prefix> and C<js_sufix> can be specified to override
standard javascript wrapper.
<body>
...
%= dxbuild
</body>
=head2 require_asset @assets
Used to specify one or more assets dependencies, that will be appended on call to required_assets.
This function need 'AssetPack' plugin to be configurated in your application.
in your template:
<body>
...
%= require_asset 'MyScript.js'
...
</body>
in your layout:
<head>
...
%= required_assets
...
</head>
=head2 required_assets
Add assets that was specified by calls to require_asset.
See require_asset for usage.
=head2 prepend_js
( run in 1.271 second using v1.01-cache-2.11-cpan-364913b4093 )