#!/usr/bin/perl use strict; use warnings; use CGI::Lazy; use JSON; our $q = CGI::Lazy->new({ tmplDir => '/var/templates/lazydemo', jsDir => '/lazydocs/js', cssDir => '/lazydocs/css', imgDir => '/lazydocs/images', buildDir => '/var/build', plugins => { dbh => { dbDatasource => 'dbi:mysql:lazydemo:localhost', dbUser => 'luser', dbPasswd => 'letmein', dbArgs => {RaiseError => 1}, }, }, }); our $widget = $q->widget->dataset({ id => 'contactMulti', type => 'multi', multiType => 'list', template => 'contactMulti.tmpl', headings => 'contactMultiHDR.tmpl', recordset => { table => 'contacts', mysqlAuto => 1, primarykey => 'contact_id', fieldlist => [ {name => 'contact_id', hidden => 1}, {name => 'company_name', label => "Company Name"}, {name => 'name', label => "Name"}, {name => 'state', label => 'State', webcontrol => { type => 'select', # values => { # MN => 'MN', # WI => 'WI', # TX => 'TX', # }, values => ['','MN', 'WI', 'TX'], }, }, {name => 'fax', label => 'Fax', webcontrol => { type => 'checkbox', value => 1, }, }, {name => 'website', label => 'Website', webcontrol => { type => 'radio', values => [qw(good bad ugly)], }, }, ], }, }); #$q->template->boilerplate($widget)->buildTemplates; if ($q->param('POSTDATA') || $q->param('keywords') || $q->param('XForms:Model')) { ajaxHandler(); } else { home(); } #---------------------------------------------------------------------------------------------- sub ajaxHandler { my $incoming= from_json($q->param('POSTDATA') || $q->param('keywords')); if ($incoming->{delete}) { return; #gotta code up the delete } else { print $q->header, $widget->ajaxSelect(incoming => $incoming); return; } } #---------------------------------------------------------------------------------------------- sub home { $widget->dbwrite; #only writes if it's got data for it's recordset print $q->header, $q->start_html({-style => {src => $q->css->file('lazydemo.css')}}), $q->javascript->modules($widget), $q->template('header.tmpl')->process({ mainTitle => 'CGI::Lazy Demo', secondaryTitle => 'Dataset Multiple', versionTitle => $q->lazyversion, messageTitle => 'Nik rocks', }); print $q->start_form({-name => 'mainform'}), $widget->display(), $q->template('formControl.tmpl')->process({ url => $q->url, widgetID => $widget->widgetID, }), $q->end_form; print $q->template('footer.tmpl')->process({version => $q->lazyversion}); return; }