Highlight product when coming from details page
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 30 Apr 2016 15:39:13 +0000 (16:39 +0100)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 30 Apr 2016 15:41:21 +0000 (16:41 +0100)
lib/App/Web/Oof.pm
static/style.css
tmpl/form.html

index c2344c65aa28a0386c59cec3c48ebcc8e4710b67..d74eca7b7ba727d3016bc7c67b0c240fb91152e8 100644 (file)
@@ -62,8 +62,10 @@ sub make_slug {
        $slug
 }
 
+our %highlight;
 sub form_table_row {
        my ($data, $tr) = @_;
+       $tr->attr(class => 'highlight') if $highlight{$data->{product}};
        $tr->fclass($_)->replace_content($data->{$_}) for qw/title subtitle stock/;
        $tr->fclass('price')->replace_content(stringify_money $data->{price});
        $tr->fclass('freepost')->detach unless $data->{freepost};
@@ -77,7 +79,9 @@ sub form_table_row {
 sub form_app {
        my ($env) = @_;
        $db{$$} //= DBIx::Simple->connect($ENV{OOF_DSN} // 'dbi:Pg:');
+       my $req = Plack::Request->new($env);
 
+       local %highlight = map { $_ => 1 } $req->param('highlight');
        my $data = $db{$$}->select(products => '*', {}, 'product')->hashes;
        my $tree = $form->clone;
        $tree->find('tbody')->find('tr')->iter3($data, \&form_table_row);
@@ -235,6 +239,10 @@ sub details_app {
        $tree->look_down(rel => 'canonical')->attr(href => "/details/$id/$slug");
        $tree->fid('pictures')->find('li')->iter3(\@pics, \&details_list_element);
 
+       for my $ahref ($tree->find('a')) {
+               $ahref->attr(href => "/form?highlight=$id") if $ahref->attr('href') eq '/';
+       }
+
        [200, ['Content-type' => 'text/html; charset=utf-8'], [$tree->as_HTML]]
 }
 
index 7ac0c8f5637f299856760edb2b07640eabe83431..0c289f1962cce6b2258ee5e4b7835b3d29e3a5db 100644 (file)
@@ -73,6 +73,10 @@ table,th,td {
        border-collapse: collapse;
 }
 
+tr.highlight {
+       background-color: rgba(255,240,0,0.5);
+}
+
 th,td {
        padding: 0.2em;
 }
index 0b8e35c41f61aa6753fbcf499bb99ba391b78674..74925c3af408e4447c805dcce14eb2c0e71e010a 100644 (file)
@@ -1,6 +1,7 @@
 <!DOCTYPE html>
 <meta charset="utf-8">
 <link rel="stylesheet" href="/static/style.css">
+<link rel="canonical" href="/form">
 <title>Order LED TV parts | ledparts4you</title>
 
 <h1 id="title">ledparts4you</h1>
This page took 0.013069 seconds and 4 git commands to generate.