Commit WIP.

agranig/1_0_subfix
Gerhard Jungwirth 12 years ago
parent 7182796216
commit 080feb9c6f

@ -121,6 +121,18 @@ sub delete :Chained('base') :PathPart('delete') :Args(0) {
$c->response->redirect($c->uri_for());
}
sub ajax :Chained('list') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
my $contracts = $c->stash->{contracts};
$c->forward( "/ajax_process", [$contracts,
["id","contact","billing_profile","status"],
[1,2,3]]);
$c->detach( $c->view("JSON") );
}
=head1 AUTHOR

@ -3,9 +3,13 @@ use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Field::Compound';
has_field 'id' => (
type => '+NGCP::Panel::Field::ContractSelect',
type => '+NGCP::Panel::Field::DataTable',
#type => 'Text',
label => 'Contract',
do_label => 1,
required => 1,
#widget => '+NGCP::Panel::Widget::DataTable',
template => 'share/templates/helper/datatables_field.tt',
);
has_field 'create' => (

@ -0,0 +1,50 @@
package NGCP::Panel::Field::DataTable;
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' );
sub render_element {
my ($self) = @_;
my $output;
my $vars = {
# url => $c->uri_for(".."), fields => [qw/id name/]
};
#my $t = new Template({});
use Data::Dumper;
print Dumper $self->template;
#$t->process($self->template, $vars, $output);
return "foo"; #$output;
}
sub render {
my ( $self, $result ) = @_;
$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 );
}
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,28 @@
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,6 +5,8 @@
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;

@ -0,0 +1,112 @@
[% 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,7 @@
<script type="text/javascript" language="javascript" src="[% c.uri_for('/js/libs/jquery.dataTables.min.js') %]"></script>
[% PROCESS "helpers/create_form.tt" %]
[% PROCESS "helpers/defines.tt" %]
[% ifndef_include_dt %]
<script type="text/javascript">
$(document).ready(function() {
@ -83,7 +86,9 @@ $(document).ready(function() {
<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_titles=helper.contract_titles,
cf_contact_titles=helper.contact_titles ) %]
</div>
<script>
$(function () {

@ -0,0 +1,68 @@
<script type="text/javascript" language="javascript" src="http://localhost:5000/js/libs/jquery.dataTables.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#myformtable')
.dataTable( {
"bProcessing": true,
"bServerSide": true,
"bPaginate": true,
"bLengthChange": false,
"bSort": true,
"bInfo": true,
"iDisplayLength": 5,
"sAjaxSource": "http://localhost:5000/reseller/ajax",
"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
}
],
"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;
},
} );
} );
</script>
<table class="table table-bordered table-striped table-highlight table-hover" id="myformtable">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Contract #</th>
<th>Status</th>
<th class="span3"></th>
</tr>
</thead>
<tbody>
<tr class="sw_action_row">
<td>Loading</td>
</tr>
</tbody>
</table>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -0,0 +1,8 @@
[% MACRO ifndef_include_dt BLOCK -%]
[% # UNLESS global.ifndef_include_dt_flag ;
# global.ifndef_include_dt_flag="true" %]
<script type="text/javascript" language="javascript" src="[% c.uri_for('/js/libs/jquery.dataTables.min.js') %]"></script>
[% # END %]
[%- END %]

@ -1,3 +1,6 @@
[% PROCESS "helpers/create_form.tt" %]
[% PROCESS "helpers/defines.tt" %]
<div class="row">
<a class="btn btn-primary btn-large" href="[% c.uri_for(c.action, c.req.captures, 'create') %]"><i class="icon-star"></i> Create [% helper.name %]</a>
<a class="btn btn-primary btn-large" href="[% c.uri_for(c.action, c.req.captures, 'search') %]"><i class="icon-search"></i> Search [% helper.name %]</a>
@ -43,7 +46,10 @@
<button id="mod_close" type="button" class="close">×</button>
<h3>[% helper.create_flag == 1 ? 'Create' : 'Edit' %] [% helper.name %]</h3>
</div>
[% helper.form_object.render %]
[% # helper.form_object.render %]
[% cf_render( cf_form=helper.form_object,
cf_contract_fields=helper.contract_fields,
cf_contact_titles=helper.contact_titles ) %]
</div>
<script>
$(function () {

@ -6,6 +6,8 @@
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;

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