Jump to content

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?

Share this post


Link to post
Share on other sites

Adam: all the better :) Downloading now and I start to implement it right a way!

With Base url I meant this: $this->config->urls->root (so I found it)

Share this post


Link to post
Share on other sites

@apeisa: I may have to finish tooltips later on and test/debug IE6-8.

Also note: it is also no-JS working. if no JS is present, it just stays fixed & extended at [0;100], but links and all data work :)

Share this post


Link to post
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?

Share this post


Link to post
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!!

Share this post


Link to post
Share on other sites
Someone wants to teach me a lesson how I create settings for this module?

Let me know what settings you want to start with, and I'll paste in an example for your settings.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
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).

Share this post


Link to post
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).

Share this post


Link to post
Share on other sites

Ryan: no worries. Localization is important thing and it would be nice to have clean and simple solution to that also.

Question: module settings worked nicely, but how I read those values? :)

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites

Hmm... $this->showModal returns 1, no matter if it is checked or not?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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).

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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)?

Share this post


Link to post
Share on other sites

Me neither – I've installed it, but it doesn't show anything. The reason, however, is in this line:

 $event->return = str_ireplace('</body>', $out, $event->return);

$event->return is empty in my case.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By eelkenet
      Hi! I've created a small Inputfield module called InputfieldFloatRange which allows you to use an HTML5 <input type="range" ../> slider as an InputField. I needed something like this for a project where the client needs to be able to tweak this value more based on 'a feeling' than just entering a boring old number. Maybe more people can use this so I'm hereby releasing it into the wild.  
       
      What is it?
      The missing range slider Inputfield for Processwire. 
      What does it do?
      This module extends InputfieldFloat and allows you to use HTML5 range sliders for number fields in your templates.
      It includes a visible and editable value field, to override/tweak the value if required.  
      Features
      Min/max values Precision (number of decimals) Steps (Read more) Manual override of the selected value (will still adhere to the rules above) Usage
      Clone / zip repo Install FieldtypeFloatRange, this automatically installs the Inputfield Create new field of type `Float (range)` or convert an existing `Float`, `Integer` or `Text` field. To render the field's value simply echo `$page->field` Demo
      A field with Min=0, Max=1, Step=0.2, Precision=2

      Field with settings Min=0, Max=200, Step=0.25, Precision=2

       
      Todo
      Make the display-field's size configurable (will use the Input Size field setting)  Hopefully become redundant If it's usable for others I'll add it to the Modules list  
      Changelog
      v002
      - Fix issue where setting the step value to an empty value created problem with validation
      - Make the display-field optional 
      v001
      - Initial release
       
      Thanks!
       
       
    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
    • By adrian
      This module allows you to automatically rename file (including image) uploads according to a configurable format
      This module lets you define as many rules as you need to determine how uploaded files will be named and you can have different rules for different pages, templates, fields, and file extensions, or one rule for all uploads. Renaming works for files uploaded via the admin interface and also via the API, including images added from remote URLs.   Github: https://github.com/adrianbj/CustomUploadNames
      Modules Directory: http://modules.processwire.com/modules/process-custom-upload-names/
      Renaming Rules
      The module config allows you to set an unlimited number of Rename Rules. You can define rules to specific fields, templates, pages, and file extensions. If a rule option is left blank, the rule with be applied to all fields/templates/pages/extensions. Leave Filename Format blank to prevent renaming for a specific field/template/page combo, overriding a more general rule. Rules are processed in order, so put more specific rules before more general ones. You can drag to change the order of rules as needed. The following variables can be used in the filename format: $page, $template, $field, and $file. For some of these (eg. $field->description), if they haven't been filled out and saved prior to uploading the image, renaming won't occur on upload, but will happen on page save (could be an issue if image has already been inserted into RTE/HTML field before page save). Some examples: $page->title mysite-{$template->name}-images $field->label $file->description {$page->name}-{$file->filesize}-kb prefix-[Y-m-d_H-i-s]-suffix (anything inside square brackets is is considered to be a PHP date format for the current date/time) randstring[n] (where n is the number of characters you want in the string) ### (custom number mask, eg. 001 if more than one image with same name on a page. This is an enhanced version of the automatic addition of numbers if required) If 'Rename on Save' is checked files will be renamed again each time a page is saved (admin or front-end via API). WARNING: this setting will break any direct links to the old filename, which is particularly relevant for images inserted into RTE/HTML fields. The Filename Format can be defined using plain text and PW $page variable, for example: mysite-{$page->path} You can preserve the uploaded filename for certain rules. This will allow you to set a general renaming rule for your entire site, but then add a rule for a specific page/template/field that does not rename the uploaded file. Just simply build the rule, but leave the Filename Format field empty. You can specify an optional character limit (to nearest whole word) for the length of the filename - useful if you are using $page->path, $path->name etc and have very long page names - eg. news articles, publication titles etc. NOTE - if you are using ProcessWire's webp features, be sure to use the useSrcExt because if you have jpg and png files on the same page and your rename rules result in the same name, you need to maintain the src extension so they are kept as separate files.
      $config->webpOptions = array(     'useSrcExt' => false, // Use source file extension in webp filename? (file.jpg.webp rather than file.webp) ); Acknowledgments
      The module config settings make use of code from Pete's EmailToPage module and the renaming function is based on this code from Ryan: http://processwire.com/talk/topic/3299-ability-to-define-convention-for-image-and-file-upload-names/?p=32623 (also see this post for his thoughts on file renaming and why it is the lazy way out - worth a read before deciding to use this module). 
       
       
      NOTE:
      This should not be needed on most sites, but I work with lots of sites that host PDFs and photos/vectors that are available for download and I have always renamed the files on upload because clients will often upload files with horrible meaningless filenames like:
      Final ReportV6 web version for John Feb 23.PDF

×
×
  • Create New...