Jump to content
thetuningspoon

Page Field Edit Links

Recommended Posts

Awesome!! It's already installed and working great on my personal invoicing system :) thank you, that's a great addition to PW and i think i will need this quite often!

One question: What do you think about an even more flexible way of defining the parent like i stated in my posting above. For example when i have a site for a sports club with different sections (soccer, tennis etc) and all of them manage their own chunk of persons.

tennis/data/john-doe

soccer/data/max-muster

now if i had a template "team" and wanted a pagefield to select the coach from the /data-children it should choose the corresponding page (/tennis or /soccer, depending on where the "team" page lives under). would a textarea like the "Custom PHP code to find selectable pages" be hard to implement?

oh, one more: as you seem to be a pagefield expert now, what would you think about an additional "unselect" button for the pagefield? https://processwire.com/talk/topic/9677-unselectclear-button-for-pagelistselect/

i think that would also be a great addition and would not harm anybody if you did it the same way like you are doing it with the view and add buttons (having to check the checkbox).

thank's for your great work! :)

Share this post


Link to post
Share on other sites

Hi BernhardB, glad you like it! This feature has been indispensable on my own projects as well.

If I understand correctly, it sounds like you need the ability to alter the parent page of new items based on the location of the current field in the page tree. Right now if you leave the parent option blank it should give you the option of where you want to add the page each time you create a new one. But I know this isn't ideal for what you want to do. I'll look into creating a Custom PHP field for that. I'm not completely sure if it's even possible, but my guess is that it shouldn't be too hard if I can look at how Ryan did it.

I agree that an unselect button would be nice. I haven't looked into how the page list select works under the hood, but it sounds like that might be a fun challenge if I can find the time to look into it. It might be as simple as adding a button and overlaying a bit of javascript to trigger the other button that's hidden in the list.

  • Like 1

Share this post


Link to post
Share on other sites

But I know this isn't ideal for what you want to do

jep ;)

unselect would be great - i tried it but i failed  :-X still have to learn a lot :)

custom php code would be the most flexible solution! it would even make the page select unnecessary ( return $page->get(/somepage); ) - but of course the page select you implemented now is much more user friendly, especially for non-coders :)

Share this post


Link to post
Share on other sites

Any opinion on the "View" vs. "Edit" link label?  Originally I had just changed it to "View" for one of my projects, but then I realized this might be clearer for the majority of applications, since "Edit" could imply editing the field itself rather than the selected page(s).

  • Like 1

Share this post


Link to post
Share on other sites

Thanks BernhardB. Have you had a chance to test the module with the new asmselect, and does it still work okay? I haven't had a chance to test the latest dev yet.

Share this post


Link to post
Share on other sites

Hi,

Today I had an issue with this module: I use it to create kind of library. All stored under "globals". There I can categorize things further like /globals/html and /globals/JavaScript... parent of selectable pages is set to "globals" and therefore this is used as parent for newly created pages. So every new page is stored under globals but it would be better to be able to choose the exact parent further down the tree under "globals"

Clear what I mean? :) don't know how that could be solved

Share this post


Link to post
Share on other sites

I think I know what you mean. Try changing line 119 in AdminPageFieldEditLinks.module from this:

$newPageParent = $event->object->newPageParent ?: $event->object->parent_id;

to this:

$newPageParent = $event->object->newPageParent;

Now just make sure that you are specifying a particular template and don't select a parent for new pages. Now when you click "New" it should now ask you where you want to put the new page, based on the template's family settings.

I haven't tested, so let me know if that works.

  • Like 2

Share this post


Link to post
Share on other sites

hi tuningspoon,

sorry can't test it because i was only working on this intranet project for the last week and had more important issues to deal with. it's ok to create pages under globals, link them and afterwards move them to their right location. the pagefield will keep the right reference.

thanks anyhow for your help i just wanted to mention this usecase maybe to keep it in mind for further updates. but i also think that this is a quite special one.

Share this post


Link to post
Share on other sites

I have an idea for an enhancement: for the "Enable + New link?" option it would be great if the newly added page was automatically selected in the Page field. Ideally it would show as selected immediately after closing the modal window (reload the Page field via AJAX?), or otherwise show as selected after saving/refreshing Page Edit. If a person is adding a new page from within Page Edit I think it's likely they want to select that option also.

I also noticed a quirk in that the "+ New" link is not rendered unless the "Enable view/edit link(s)?" option is also selected.

Share this post


Link to post
Share on other sites

I have an idea for an enhancement: for the "Enable + New link?" option it would be great if the newly added page was automatically selected in the Page field. Ideally it would show as selected immediately after closing the modal window (reload the Page field via AJAX?), or otherwise show as selected after saving/refreshing Page Edit. If a person is adding a new page from within Page Edit I think it's likely they want to select that option also.

Hi Cerulean. I definitely agree with your suggestion that the new page should be automatically selected when created. Unfortunately there isn't a straightforward way that I know of to do this, which is why I haven't done it yet. I am sure that it can be done (PageTable does something like it), but it will take me a while to figure out. Hopefully I will get some time to look at this soon since it is a feature I would like as well, and the "+New" link is a bit confusing without it.

I also noticed a quirk in that the "+ New" link is not rendered unless the "Enable view/edit link(s)?" option is also selected.

Thanks for the bug report. I'll look into this as well.

Share this post


Link to post
Share on other sites

Adding the new page to the inputfield is not trivial as the actual code does completely depend on the used inputfield. With a few 3rd party inputfields this will be quite some work if all of them should be covered.

  • Like 1

Share this post


Link to post
Share on other sites

@BernhardB - AJAX reload of the field sounds like a promising idea. I have not looked into how that works yet, but I will as soon as I get a chance!  

At this point I recommend only using the Add New feature if you're using the autocomplete field, since that doesn't require a page refresh to select the new item.

I saw your unselect module and it looks great :)

  • Like 1

Share this post


Link to post
Share on other sites

Could you implement a translation option for the javascript? (buttons ' New' and ' View'). I am really looking forward for the Ajax Solution to provide the new created page immediately.

Share this post


Link to post
Share on other sites

Currently working on an update with bug fixes, translatable links, and (hopefully) ajax refresh when new pages are added. I should have something ready tomorrow.

Edit: Made a lot of progress this weekend but will need a bit more time to iron things out. I was able to get the field to refresh when the Add New modal dialog is closed, which works great for single item selects and allows you to select the new item without refreshing the page. However, for asm-style multi-selects, the refresh wipes out your existing selection when it reloads. Because of this I think that another approach will be required.

  • Like 5

Share this post


Link to post
Share on other sites

I'm close to the finish line on this latest update. I've added support for ALL types of inputfields as well as automatic selection of a new page when it's added. I'm still working on the autocomplete inputfield and a few optimizations and then I will push the changes to GitHub.

  • Like 2

Share this post


Link to post
Share on other sites

New in version 3.0

Removes the limitations of the previous releases!

  • Now compatible with all Inputfield types including Select, SelectMultiple, Checkboxes, Radios, AsmSelect, PageListSelect, PageListSelectMultiple, and PageAutocomplete.

  • When using the create new page feature, new pages are added to the field and selected automatically as soon as the modal is closed. No further input is required from the user.

  • The "View" and "+ New" strings are now translatable

  • The add new page links may be enabled independent of the view/edit links

  • Code performance improvements

GitHub: https://github.com/thetuningspoon/AdminPageFieldEditLinks

Direct Download: https://github.com/thetuningspoon/AdminPageFieldEditLinks/archive/master.zip

I ended up using a combination of different methods for populating the field with the new page once it's created. Some of the input types were fairly easy and could be updated without reloading the field, while others required some pretty wild code acrobatics, taking advantage of Ryan's new AJAX reload and repopulating the input with pages that were already selected but not yet saved. Please let me know if you run into any bugs. This was built mainly in Chrome with limited testing outside of it so far, so I expect some issues.

I hope you guys enjoy the new features! Let me know if you have other suggestions for further enhancements.

  • Like 11

Share this post


Link to post
Share on other sites

If 'View/ Edit links on selected pages' is enabled this option should be hidden in case user has no edit permission for the selected page. Now an ugly error message is shown in the modal. Would be nice to not provide the link in this case.

Apart from this module is working properly under 3.0.8. Thumbs up and many thanks for the last fixes. :)

  • Like 2

Share this post


Link to post
Share on other sites

Ah, great point, kixe. I hadn't even considered permissions since it hasn't been an issue in any of my use cases yet. If you have a github account, would you mind adding this as an issue? Thanks.

Share this post


Link to post
Share on other sites

The latest update to this module is really great.

I notice that when adding a new page in the modal window the "Save" button does not close the modal like it does when using the native modal page edit feature (for AsmSelect). Could the Save button action be consistent with the native modal edit Save action, or do you think it's better to keep the modal open after save for newly added pages?

Share this post


Link to post
Share on other sites

Hi Robin, glad you are finding this module useful!

The reason why the modal stays open is that there are several scenarios in which I think this would be desirable. One is when you're creating a new page and it is a 2-step process. The modal needs to stay open after the initial page creation so that you can then edit the new page. The second is when there is an error on the page. I wanted the user to be able to see the error and make any corrections before closing.

Ideally, I would just have the modal stay open only in those scenarios, but accomplishing that in the PW admin isn't straightforward at this point. It is something that I would like to look into, though right now I'm pretty swamped with other projects.

  • Like 1

Share this post


Link to post
Share on other sites

Fair enough. Looking a bit closer at the native edit modal I see that the normal Save button is hidden and a replacement Save button is rendered as part of the modal frame. I don't see how that could work with a 2-step page creation process.

And keeping the modal open for errors is something I hadn't considered - it's actually a bit of a shortcoming of the native edit modal, which closes without displaying required field warnings, etc.

Share this post


Link to post
Share on other sites

The module is not compatible with PW 3.0.22. Please check. Module configuration is not loaded properly. If I can figure out details I will post here.

 

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...