Jump to content

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! :)

Link to comment
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
Link to comment
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 :)

Link to comment
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
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
  • 4 weeks later...

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

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

Link to comment
Share on other sites

  • 4 weeks later...

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.

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

Link to comment
Share on other sites

  • 1 month later...

@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
Link to comment
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.

Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
Share on other sites

  • 1 month later...

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?

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

Link to comment
Share on other sites

  • 2 months later...

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