The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
% layout 'standard';
% title 'Administration: Pages';
% content_for banner => 'Administration: Pages';

% content_for header => begin
  %= javascript '/galileo-edit.js'
% end

% my $pages = schema->resultset('Page')->search(undef, {order_by => { -asc => 'page_id' }, prefetch => 'author'});

%= modal 'page-delete-modal' => begin
  Are you sure that you want to delete the page?
% end

%= tag table => class => "table table-striped table-bordered table-condensed" => begin
  %= tag tr => begin
    %= tag th => "page_id"
    %= tag th => "Name"
    %= tag th => "Title"
    %= tag th => "Author"
    %= tag th => "Actions"
  % end
  % while (my $page = $pages->next) {
    % my $name = $page->name;
    % my $id = $page->page_id;
    %= tag tr => id => "row-$id" => begin
      %= tag td => $id
      %= tag td => $name
      %= tag td => $page->title
      % my $author = $page->author->name;
      %= tag td => begin
        %= tag a => href => "/admin/user/$author" => "$author"
      % end
      %= tag td => begin
        <div class="btn-group">
          <a class="btn" href="<%= url_for 'show_page', name => $name %>"><i class="icon-eye-open"></i></a>
          <a class="btn" href="<%= url_for 'edit_page', name => $name %>"><i class="icon-pencil"></i></a>
          <a class="btn" href="#" onclick="confirm_delete('<%= $id %>')">
            <i class="icon-trash"></i>
          </a>
        </div>
      % end
    % end
  % }
% end

%= javascript begin
function confirm_delete(id) {
  show_modal(
    '#page-delete-modal',
    function(){ delete_page(id) }
  );
}

function delete_page(id) {
  sendViaWS(
    '<%= url_for("removepage")->to_abs %>',
    { "id" : id },
    function(){ $( '#row-' + id ).remove(); }
  );
}
% end