Jump to content
Spica

Preconfigured Lister in Custom Admin Page

Recommended Posts

Just moved to Processwire. I wonder, how to customize the lister of the core with a customadminpage. Id like to filter a pagelist by creator-id. Lister does that job perfect. But what I need is a custom admin page with the list, but no lister configuration/dropdowns. So the user just gets a predefined list of certain pages.

So far I managed two basic things in the custom admin template

$pl = $this->modules->get("ProcessPageList");
$pl->set('id',1001);
echo $pl->execute();

processes me a tree, but I cant figure out how to filter for creationid

        $items = $pages->find("created_users_id=".$user->id );

        $out = "<table width='100%'>";
        $out .= "<thead>";
            $out .= "<th>Title</th>";
            $out .= "<th>Date Created</th>";
            $out .= "<th>User</th>";
        $out .= "<thead>";
        $out .= "<tbody>";

        if ($items != ""){

            foreach ($items as $item) {
                $out .= "<tr>";
                $out .= "<td><a href=". $config->urls->admin . "page/edit/?id=" . $item->id .">" .$item->title . "</a></td>"; // title
                $out .= "<td>" . date("F j, Y", $item->created) . "</td>"; // date created
                $out .= "<td>" . $item->createdUser->name. "</td>"; // user that created
                $out .= "</tr>";
            }

        } else {
            
            // empty pageArray message
            $out = "<tr><td>No pages matching your criteria were found.</td></tr>";

        }

        $out .= "</tbody>";
        $out .= "</table>";
        
        echo $out;

This gives me nearly the list I want. But its generated with the pages object and a more static result list.

What would you recommend, what is the best way to follow.

Share this post


Link to post
Share on other sites

Ryan stated in the ListerPro Forum, that Lister is not intended to be used in "no-filters" mode, as it's overkill to load the thing for a "static" list. But you can use MarkupAdminDataTable.module, which is quite easy to use and generates the table you see in lister. You only need to fill it with data you'd define. These tables can be made sortable. For filters you would need to have custom javascript or some kind of form, to limit the displayed sites.

Share this post


Link to post
Share on other sites

Thanx. Have already searched for MarkupAdminDataTable but could not find any good starting point. Is it documented somewhere?

Share this post


Link to post
Share on other sites

Nope, but it's kinda easy.

// module context

$table = $this->modules->get("MarkupAdminDataTable");

$table->headerRow( ["Title", "ID", "Created"] );

foreach($this->pages->find("some=pages") as $page){
  $data = array(
    // Values with a sting key are converter to a link: title => link
    $page->title => $this->config->urls->admin."page/edit/?id=".$page->id,
    $page->id,
    $page->created
  );
  $table->row($data);
}

// $table->footerRow( $someArray );

echo $table->render();
  • Like 4

Share this post


Link to post
Share on other sites

Great.

To use it in a AdminTemplate I had to change it to

$table = $modules->get("MarkupAdminDataTable");

$table->headerRow( ["Title", "ID", "Created", "User"] );

foreach($pages->find("created_users_id=".$user->id) as $page){
  $data = array(
    // Values with a sting key are converter to a link: title => link
    $page->title => $config->urls->admin."page/edit/?id=".$page->id,
    $page->id,
    date("F j, Y", $page->created),
    $page->createdUser->name
  );
  $table->row($data);
}

// $table->footerRow( $someArray );

echo $table->render();

and ad a missing $

Or would you recommend to use it as a modul over a custom admin template?

And how to integrate the view/edit etc Buttons as in the tree view?

  • Like 1

Share this post


Link to post
Share on other sites

There are different options for the table. By default all fields are entity encoded, but you could change this do insert own html code in the table fields.

$table->setEncodeEntities(true|false);
$table->setSortable(true|false);
$table->setCaption("");
$table->setClass("");
// Add buttons after the table
// same as for rows "label" => href
$table->action($array);

As for the best way to integrate this: Modules are more way more flexible and process modules are there for exactly that reason.

Share this post


Link to post
Share on other sites

Did something like

$table->action(array(
	'New' => $this->config->urls->admin . 'page/add/?parent_id=1021',
));

Which is ok for me now.

Originaly I wondered how to get the edit/view/new/edit template Buttons after a click on a line. Isn't it a build in and reusable function. Would be good to know for the future.

Share this post


Link to post
Share on other sites

It seems it's not a reusable function. The pagetree and lister variations do have completely different markup, only a class for the styling is the same. 

Share this post


Link to post
Share on other sites
On 20-2-2015 at 4:51 PM, LostKobrakai said:

Nope, but it's kinda easy.


 // Values with a sting key are converter to a link: title => link
 $page->title => $this->config->urls->admin."page/edit/?id=".$page->id,
    

 

I've tested this in the multi-language profile , but I got an error: "Warning: Illegal offset type" caused by $page->title.  That is because 'title' is not a string, but an object in the multi-language profile.

With following modification it works (if you want to see the default lang):

$pg->title->getLanguageValue('default') => $this->config->urls->admin."page/edit/?id=".$pg->id,

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...