New datatables based fields.

agranig/1_0_subfix
Gerhard Jungwirth 13 years ago
parent 080feb9c6f
commit 2d7d691de3

@ -4,12 +4,13 @@ extends 'HTML::FormHandler::Field::Compound';
has_field 'id' => (
type => '+NGCP::Panel::Field::DataTable',
#type => 'Text',
label => 'Contract',
do_label => 1,
do_label => 0,
do_wrapper => 0,
required => 1,
#widget => '+NGCP::Panel::Widget::DataTable',
template => 'share/templates/helper/datatables_field.tt',
template => 'share/templates/helpers/datatables_field.tt',
ajax_src => '/contract/ajax',
table_fields => ['#', 'Contact #', 'Billing Profile #', 'Status'],
);
has_field 'create' => (

@ -3,37 +3,29 @@ use Moose;
use Template;
extends 'HTML::FormHandler::Field';
sub build_options {
my ($self) = @_;
return [
{ label => 'Select...', value => '' },
{ label => '1', value => 1 },
{ label => '2', value => 2 },
{ label => '3', value => 3 },
{ label => '4', value => 4 },
{ label => '5', value => 5 },
#{ label => '6', value => 6 },
];
}
has 'template' => ( isa => 'Str', is => 'rw' );
has 'ajax_src' => ( isa => 'Str', is => 'rw' );
has 'table_fields' => ( isa => 'ArrayRef', is => 'rw' );
sub render_element {
my ($self) = @_;
my $output;
my $output = '';
(my $tablename = $self->html_name) =~ s!\.!!g;
my $vars = {
# url => $c->uri_for(".."), fields => [qw/id name/]
my $vars = {
checkbox_name => $self->html_name,
table_id => $tablename . "table",
value => $self->value,
ajax_src => $self->ajax_src,
table_fields => $self->table_fields,
};
#my $t = new Template({});
my $t = new Template({});
$t->process($self->template, $vars, \$output) ||
print ">>>>>>>>>>>>>>>>> failed to process tt: ".$t->error()."\n";
use Data::Dumper;
print Dumper $self->template;
#$t->process($self->template, $vars, $output);
return "foo"; #$output;
return $output;
}
sub render {
@ -41,7 +33,7 @@ sub render {
$result ||= $self->result;
die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result;
my $output = $self->render_element( $result );
return $output; #$self->wrap_field( $result, $output );
return $self->wrap_field( $result, $output );
}

@ -1,28 +0,0 @@
package NGCP::Panel::Widget::DataTable;
use Moose::Role;
has 'template' => (
is => 'ro',
isa => 'Str',
default => 'widgets/data_table.tt'
);
#around handle => sub {
# my ($foo, $self, $c) = @_;
#
# print "++++ AdminBillingOverview::handle\n";
# return;
#};
#around filter => sub {
# my ($foo, $self, $c) = @_;
# return $self if(
# $c->check_user_roles(qw/administrator/) &&
# ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
# );
# return;
#};
1;
# vim: set tabstop=4 expandtab:

@ -5,8 +5,6 @@
helper.messages = messages;
helper.column_titles = [ '#', 'Contact #', 'Billing Profile #', 'Status' ];
helper.column_fields = [ 'id', 'contact_id', 'billing_profile_id', 'status' ];
helper.contact_titles = [ '#', 'First Name', 'Last Name', 'Email' ];
helper.close_target = close_target;
helper.create_flag = create_flag;

@ -1,112 +0,0 @@
[% MACRO cf_render BLOCK %]
[% FOREACH this_field IN cf_form.sorted_fields -%]
[% IF this_field.id == "contract" -%]
[% cf_new_table_html( cf_table="cf_table",
cf_table_fields=cf_contract_titles ) %]
[% cf_new_table_definition( cf_table="cf_table",
cf_table_src='/contract/ajax',
cf_update_field='contract\\\\.id' ) %]
[% END %]
[% IF this_field.id == "contact" -%]
[% cf_new_table_html( cf_table="cf_table",
cf_table_fields=cf_contact_titles ) %]
[% cf_new_table_definition( cf_table="cf_table",
cf_table_src='/contact/ajax',
cf_update_field='contact\\\\.contact' ) %]
[%- END %]
[%- END %]
[% cf_form.render %]
[% END %]
[% MACRO cf_new_table_html BLOCK %]
<table class="table table-bordered table-striped table-highlight table-hover" id="[% cf_table %]">
<thead>
<tr>
[% FOREACH t IN cf_table_fields -%]
<th>[% t %]</th>
[% END -%]
[% # one for actions -%]
<th class="span2"></th>
</tr>
</thead>
<tbody>
<tr class="sw_action_row">
<td>Loading</td>
</tr>
</tbody>
</table>
[% END %]
[% MACRO cf_new_table_definition BLOCK %]
[% PROCESS "helpers/defines.tt" %]
[% ifndef_include_dt %]
<script type="text/javascript">
$(document).ready(function() {
$('#[% cf_table %]')
.dataTable( {
"bProcessing": true,
"bServerSide": true,
"bPaginate": true,
"bLengthChange": false,
"bSort": true,
"bInfo": true,
"iDisplayLength": 4,
"sAjaxSource": "[% c.uri_for( cf_table_src ) %]",
"aoColumns": [
[% FOREACH f IN helper.column_fields -%]
{ "sName": "[% f %]" },
[% END -%]
{ "mRender": function ( data, type, full ) {
return '' +
'<input type="checkbox"></input>' +
'<div class="sw_actions pull-right">' +
'<a style="display:inline;line-height:16px;" class="btn btn-small btn-primary">' +
'<i class="icon-check" style="line-height:1em;margin-top:2px"></i> Select' +
'</a>' +
'</div>';
},
"mData": null,
"bSortable": false
}
],
"fnDrawCallback": function( oSettings ) {
$('.sw_actions').hide();
$('.sw_action_row').hover(
function() { $(this).find('.sw_actions').show(); },
function() { $(this).find('.sw_actions').hide(); }
);
},
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
nRow.className = "sw_action_row";
return nRow;
},
} );
$('#[% cf_table %] tbody tr').live('click', function () {
var id = $(this).find("td:first").text();
//alert(".."+id+"..");
$("input#[% cf_update_field %]").val(id);
$(this).addClass('highlight').siblings().removeClass('highlight');
$(this).find("td:eq(4) input[type='checkbox']").attr("checked", true);
$(this).siblings().find("td:eq(4) input[type='checkbox']").attr("checked", false);
});
} );
</script>
[% END %]
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -1,4 +1,3 @@
[% PROCESS "helpers/create_form.tt" %]
[% PROCESS "helpers/defines.tt" %]
[% ifndef_include_dt %]
@ -86,9 +85,7 @@ $(document).ready(function() {
<button id="mod_close" type="button" class="close">×</button>
<h3>[% helper.create_flag == 1 ? 'Create' : 'Edit' %] [% helper.name %]</h3>
</div>
[% cf_render( cf_form=helper.form_object,
cf_contract_titles=helper.contract_titles,
cf_contact_titles=helper.contact_titles ) %]
[% helper.form_object.render -%]
</div>
<script>
$(function () {

@ -2,7 +2,18 @@
<script type="text/javascript">
$(document).ready(function() {
$('#myformtable')
var selectedRow = [% value or 0 %];
$('#[% table_id %] tr td input[type="checkbox"]').live( "click", function() {
selectedRow = $(this).parents("tr").find("td:first").text();
if($(this).attr("checked") == "checked") {
$(this).parents("tr").siblings().find("td input[type='checkbox']").attr("checked", false);
}
});
$('#[% table_id %]')
.dataTable( {
"bProcessing": true,
"bServerSide": true,
@ -10,38 +21,27 @@ $(document).ready(function() {
"bLengthChange": false,
"bSort": true,
"bInfo": true,
"iDisplayLength": 5,
"sAjaxSource": "http://localhost:5000/reseller/ajax",
"iDisplayLength": 4,
"sAjaxSource": "[% ajax_src %]",
"aoColumns": [
{ "sName": "id" },
{ "sName": "name" },
{ "sName": "contract.id" },
{ "sName": "status" },
{ "mRender": function ( data, type, full ) {
return '' +
'<div class="sw_actions pull-right">' +
'<a style="display:inline;line-height:16px;" class="btn btn-small btn-primary" href="http://localhost:5000/reseller/' + full[0] + '/edit">' +
'<i class="icon-edit" style="line-height:1em;margin-top:2px"></i> Edit' +
'</a>' +
'<a style="display:inline;line-height:16px;margin-left:5px;" class="btn btn-small btn-secondary" href="http://localhost:5000/reseller/' + full[0] + '/delete">' +
'<i class="icon-trash" style="line-height:1em;margin-top:2px"></i> Delete' +
'</a>' +
'</div>';
},
"mData": null,
"bSortable": false
}
{ "mRender": function ( data, type, full ) {
return '<input type="checkbox" name="[% checkbox_name %]" value="' + full[0] + '"></input>';
},
"mData": null,
"bSortable": false
}
],
"fnDrawCallback": function( oSettings ) {
$('.sw_actions').hide();
$('.sw_action_row').hover(
function() { $(this).find('.sw_actions').show(); },
function() { $(this).find('.sw_actions').hide(); }
);
},
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
nRow.className = "sw_action_row";
if($(nRow).find("td:first").text() == selectedRow)
{
$(nRow).find("td input[type='checkbox']").attr("checked", "checked");
}
return nRow;
},
} );
@ -49,14 +49,13 @@ $(document).ready(function() {
} );
</script>
<table class="table table-bordered table-striped table-highlight table-hover" id="myformtable">
<table class="table table-bordered table-striped table-highlight table-hover" id="[% table_id %]">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Contract #</th>
<th>Status</th>
<th class="span3"></th>
[% FOREACH t IN table_fields %]
<th>[% t %]</th>
[% END %]
<th class="span"></th>
</tr>
</thead>
<tbody>

@ -1,4 +1,3 @@
[% PROCESS "helpers/create_form.tt" %]
[% PROCESS "helpers/defines.tt" %]
<div class="row">
@ -46,10 +45,7 @@
<button id="mod_close" type="button" class="close">×</button>
<h3>[% helper.create_flag == 1 ? 'Create' : 'Edit' %] [% helper.name %]</h3>
</div>
[% # helper.form_object.render %]
[% cf_render( cf_form=helper.form_object,
cf_contract_fields=helper.contract_fields,
cf_contact_titles=helper.contact_titles ) %]
[% helper.form_object.render -%]
</div>
<script>
$(function () {

@ -6,8 +6,6 @@
helper.column_titles = [ '#', 'Name', 'Contract #', 'Status' ];
helper.column_fields = [ 'id', 'name', 'contract.id', 'status' ];
helper.contract_titles = [ '#', 'Contact #', 'Billing Profile #', 'Status' ];
helper.close_target = close_target;
helper.create_flag = create_flag;
helper.edit_object = reseller;

@ -1,2 +0,0 @@
Yeah!
[% c.log.debug("****** am in widgets/data_table.tt now ****** ") %]
Loading…
Cancel
Save