Jump to content

Adminbar


apeisa

Recommended Posts

Ok, I got some nice progress here. After saving it redirects (out of the modal) and displays success message. I used Adam's tip on hooking to save and using sessions. I didn't need to use load hook, because I already had pagerender hook (or maybe it is faster with loaded hook?).

I had to redirect with javascript, because there seems to be no way to redirect out of the iFrame without js or user input. If someone knows please let me know :)

Oh, and how to I get base url? I have pretty ugly hard coding there with this line:

echo("top.location.href = \"http://localhost/processwire2{$this->session->pageSaved}\";");

There is probably something like $config->urls->base or like that?

Link to comment
Share on other sites

I actually just downloaded it, now tested and very smooth work and nice looking also while extended! Also very clean and nice coding here!

Someone wants to teach me a lesson how I create settings for this module?

Link to comment
Share on other sites

(or maybe it is faster with loaded hook?).

Page::loaded isn't what you want. That is called after every page finishes loading it's initial data and is ready for API use. It doesn't mean that the page is loaded in the browser, just that it's loaded in memory on the server. This is what you would use if you wanted to examine or modify some value on every page that gets loaded before anything else accesses it. Maybe I should rename this hook to be "ready" rather than "loaded"?

Very cool!!

Link to comment
Share on other sites

Ryan, as I see it, currently this settings are needed:


  •  
  • boolean showModal: whether edit opens modal box or goes to administration
     
  • boolean initCollapsed: whether to init collapsed or not
     
  • page administration: where to go after clicking on 'administration' (optional, pages makes most sense i think)

OT: Ryan, you as moderator should be the last one to double post :D ;D there is 'modify' button

Link to comment
Share on other sites

Sorry about the double post. This is probably the only forum I've ever used, so I don't know what the etiquette is. Consider me new to this. :)

Okay to make your module configurable, modify the class definition and add "ConfigurableModule" to it:

<?php
class AdminBar extends WireData implements Module, ConfigurableModule {

To implement this interface, we need to add a module configuration function to your AdminBar class. It takes one parameter, which is an array of data (that ProcessWire provides to it). If the module has been configured before, that will contain the settings in simple key = value format. It expects you to return a value of type InputfieldWrapper(). Since that is only documented in the source right now, I wanted to get you started with an example:

<?php

static public function getModuleConfigInputfields(array $data) {

// this is a container for fields, basically like a fieldset
$fields = new InputfieldWrapper();

// since this is a static function, we can't use $this->modules, so get them from the global wire() function
$modules = wire('modules');

// set some defaults if the values aren't already present
if(!isset($data['showModal'])) $data['showModal'] = 1; // default to checked
if(!isset($data['initCollapsed'])) $data['initCollapsed'] = 0; // default to unchecked
if(!isset($data['administration'])) $data['administration'] = wire('config')->adminRootPageID; // default to admin page

// showModal field
$field = $modules->get("InputfieldCheckbox"); 
$field->name = "showModal";
$field->label = "Show modal box?"; 
        $field->value = 1; 
$field->description = "Whether edit opens modal box or goes to administration.";
$field->attr('checked', !empty($data['showModal'])); 
$fields->add($field);

// initCollapsed field
$field = $modules->get("InputfieldCheckbox"); 
$field->name = "initCollapsed";
$field->label = "Init collapsed?"; 
        $field->value = 1; 
$field->attr('checked', !empty($data['initCollapsed'])); 
$fields->add($field);

// administration field
$field = $modules->get("InputfieldPageListSelect"); 
$field->name = "administration";
$field->label = "Where to go after clicking on 'administration'";
$field->value = $data['administration'];
$fields->add($field);

return $fields;
}

Once you've put this in there, you can go configure your module in the admin by clicking "Modules" and then clicking on your AdminBar module. You should now see the fields ready to configure.

Link to comment
Share on other sites

Ryan, Adam: thanks again!

I just implemented Adam's UI and I dive into these settings next.

Few questions (not important at this point, but later):

  • Date formatting - is there global settings for this?
  • Language - best practice to offer different languages for this module?
Link to comment
Share on other sites

  • Date formatting - is there global settings for this?

There isn't. But the current practice is to use either SQL date format in places where the date need to be a fixed length and/or sortable with other dates (like in a table), and to use "January 27, 2011" or "Jan 27, 2011" format anywhere else. I believe these formats are fairly universal, though correct me if I'm wrong.

  • Language - best practice to offer different languages for this module?

This is to be determined, but on the roadmap. I think that Adam is giving this some thought, as am I, and all suggestions are welcome.

Thanks,

Ryan

Link to comment
Share on other sites

There isn't. But the current practice is to use either SQL date format in places where the date need to be a fixed length and/or sortable with other dates (like in a table), and to use "January 27, 2011" or "Jan 27, 2011" format anywhere else. I believe these formats are fairly universal, though correct me if I'm wrong.

In Finland we never use dates like "Tam 27, 2011", it is almost always "27.1.2011" and sometimes "27. tammikuuta 2011" or "Tammikuu 27. 2011". I think there is nothing universal to what comes to localisation :D

Is there any best practice to give some general constants for a whole site? Ie. in AdminBar I could try to read some site wide setting for default date formatting -> if there is none, then use module default. It wouldn't be wise to create date formatting as a module setting, wouldn't it? That would create situations where there is a lot of configuration to be made if site is using many modules (not sure though) - also every module that displays dates (or other local stuff) should provide settings for customizing localisation.

Very interested to hearing Adam's thoughts on languages.

Of course considering the "hands-on" nature of PW this isn't always an issue (easy to format things just the way you like on templates).

Link to comment
Share on other sites

In Finland we never use dates like "Tam 27, 2011", it is almost always "27.1.2011" and sometimes "27. tammikuuta 2011" or "Tammikuu 27. 2011". I think there is nothing universal to what comes to localisation Cheesy

Sorry, my bad. I learn something new every day. I'm admittedly ignorant on this matter (I live in the US, in backwoods Georgia, after all).

Given what you've mentioned, I'm adding a new $config->dateFormat to the PW2 source. What do you suggest would be a good default? Something universal doesn't exist, but what would be the closest to something universal to serve as a default?

I would like to talk more with Adam and you about more localization options for PW2 (maybe we can start a new thread soon).

Link to comment
Share on other sites

It's getting near the end of the work day and I'm forgetting crucial details. :) To read this values, they will be automatically set in your AdminBar instance. So anywhere in that class, you should be able to just reference it like: $this->showModal, and so on. If the value is not set or doesn't exist, it will just be null. If that's the case, then you should use some default value, because it means the module has never been configured. Or you could set them up in a __construct method. The constructor is of course executed before PW2 sets any values to the module. Whereas the init() method is called after PW2 sets values to the module. So you might setup your defaults like this:

public function __construct() {
    $this->showModal = true; 
}

No need to define a separate showModal var in your class, because WireData is already handling that for you behind the scenes...

Link to comment
Share on other sites

You are right. I'm figuring it out now... you the first person to develop a module, and this is only the 3rd or 4th configurable module ever, so I'm getting up to speed myself. :) I'll reply shortly.

Link to comment
Share on other sites

Looks like you've found a bug! I will work to get this fixed for tomorrow. Sorry for the inconvenience. Turns out this is the first configurable module of it's type, so it's not come up before. But I think it will be an easy fix.

Link to comment
Share on other sites

No worries Ryan. This have been so much fun so far and big thanks for all your help! Dunno what my wife thinks about my late night coding after few weeks... :)

There is now first version to try out for you guys! No new features yet (only page editing and link to admin & logout), but this has super nice UI by adamkiss.

http://www.monoliitti.com/misc/AdminBar.zip

Remember: requires latest version from master branch. Installation is super simple: extract files from zip to: /site/modules/AdminBar/ and then through admin -> modules -> install (easy to find, since it will be first module on the list, good name ;))

There are some settings on module admin, but they aren't working yet (as you can read from above).

Link to comment
Share on other sites

Thanks, I can't wait to check this out! We are headed to dinner, so I'm going to check when I get back. If you are still around and want to try it, here is a fixed /wire/core/Modules.php that corrects the bug (attached). I am going to go over it in more detail tomorrow. Also, I may have told you the wrong thing on setting the defaults in the getModuleConfigInputfields... you may be able to remove that part at the top. I'll double check on the proper syntax either tonight or tomorrow, and then get started on the module documentation! :)

Modules_php.zip

Link to comment
Share on other sites

Hello boys,

nice to see this thing rolling' :)

On-topic: I don't know if I'll have time to check the module out right now, but I would love to work on it, so apeisa, please, create github account for it [or I can, if you wish], so we can synchronize better. If you don't have account / haven't work with git before, try some nice GUI for it and just dive in as I did – i still no almost nothing about it and love it already.

Off-topic: I'm currently working on new UX / UI design for PW administration – it's quite well thought out, brings some new stuff, some 'nice-somebody-thought-of-this' moments and nice design too, however, I have so much work [some of it will be brought back to PW though!] that I can't do everything at once!

From the things I would like to introduce [and some already mentioned to ryan]:

  • Text & description of field configurable in template, so you can re-use fields with better description for clients
  • a little better managment of content
  • multilinguality – it's almost finished (how it will work), I have to implement it into design (not finished) and talk to ryan how to do it
  • 'add another' – I would love to have a nice button after you save a page to have quick option of adding another
  • partials/strings system to manage little pieces of text needed anywhere in templates (+1 on multilinguality and convenience)

There is much more in little and big stuff, but basically I'm trying to translate the great PHP workflow into UX/UI.

Link to comment
Share on other sites

Thanks, I can't wait to check this out! We are headed to dinner, so I'm going to check when I get back. If you are still around and want to try it, here is a fixed /wire/core/Modules.php that corrects the bug (attached).

Thanks Ryan. I go to bed now, but I will continue on weekend.

I don't know if I'll have time to check the module out right now, but I would love to work on it, so apeisa, please, create github account for it [or I can, if you wish], so we can synchronize better. If you don't have account / haven't work with git before, try some nice GUI for it and just dive in as I did – i still no almost nothing about it and love it already.

I have used SVN much more than Git. I have tried Git few times, always liked it but never had enough reason to start using it in real project. But maybe now: https://github.com/apeisa/AdminBar

Link to comment
Share on other sites

Not working for me...I've installed it but i cannot see the bar...

Thanks for installing and sorry to hear about problems. Do you have installed latest branch from here: https://github.com/ryancramerdesign/ProcessWire/archives/master

If you do, can you paste source code of your page (some front end page and when admin is logged in)?

Link to comment
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
×
×
  • Create New...