Member
Member
the_voder   20-10-2014, 09:33
#1

Hi,

I'm making a plugin to customise the Admin UI of ZenPhoto. I'm wondering if it would be possible for my plugin to automatically name new albums that are created. Our users will be saving photos into albums on a week-by-week basis, and I want to automate the naming of albums to maintain the same naming format each week.

My plugin would need to either:

  1. Automatically insert the generated album name into the alert that pops up when the 'New Album' button is pressed, or

  2. Replace the 'New Album' button with a similar button that automatically creates the required album with the correct name.

Can either of these things be achieved using the ZenPhoto API?

Cheers,

a|x

Administrator
Administrator
acrylian   20-10-2014, 10:47
#2

The new album button cannot be changed via filters. You would have to modify the backend itself which for hopefully obvious reasons is not really a good idea.

It should possible to use jQuery to insert a new album name instead of "new album" as it is used now using the admin_head()filter.

All available filters are listed here:
http://www.zenphoto.org/news/zenphoto-plugin-architecture#zenphoto-filters

Member
Member
the_voder   20-10-2014, 11:01
#3

Thanks for the quick reply, acrylic.

I was starting to think that was probably the case. I'm already using a linked js file inserted using the admin_head() filter to hide un-needed fields on various edit pages, so I'll look into using jQuery to achieve this.

Incidentally, is it likely that a future release of ZenPhoto will use more unique identifiers for admin UI elements? I've had to jump through some rather tortuous hoops in order to target various form fields and table rows with jQuery, and in the process, created a completely non-futureproof plugin. I'm sure it's not a priority for you, but it might make it easier for your own future development of the platform if the various form fields had unique ID or title attributes, as well as making it easier for 3rd-party plugin developers to tweak the UI in various ways.

Cheers,

a|x

Member
Member
the_voder   20-10-2014, 11:16
#4

@acrylian,

I think it won't be possible to modify the content of the browser prompt once it has been created, unfortunately.

I could use jQuery to remove the inline 'onClick' attribute from the New Album button, and write my own JS function to handle new album creation (overriding the script in the head of the document). However, I think this would fail due to the presence of the XSRFToken argument being sent to launchScript, which presumably is written into the document head by PHP at page load, and is there to stop exactly the kind of thing I'd trying to do…

Hmmm. Maybe I'm missing something…

a|x

Administrator
Administrator
acrylian   20-10-2014, 11:23
#5

Yes, it is planned for the next major release to make all non main form fields (like title or content) more modular and allow adding custom fields to any item more easy. Without using jQuery to hide. That major release will take some more time though.

There are already filters to add custom fields (for all items). There is also a plugin named userAddress fields that can be adapted to add extra fields to items programmatically. However how it does it is technically will probably not be the way we will follow in the future.

Member
Member
the_voder   20-10-2014, 11:46
#6

I see, that makes a lot of sense. I'm only doing this with jQuery because it seemed to be the only way to do it. It it can be done via the filters API in the future, then obviously that will be the way to go.

I'll have a look at userAddressFields, but at the moment, I'm more interested in removing fields, than adding them. A selection of the existing default fields will fit our needs, I think.

The background is that I'm setting up an image library for a collaborative student journalism project. Because the role of Picture Editor is typically assigned to a new person each week, it's not possible to give everyone who will be using ZenPhoto detailed training, so I've found it necessary to strip all non-essential fields from the various album and picture-edit pages.

a|x

Administrator
Administrator
acrylian   20-10-2014, 12:14
#7

I do understand your purpose very well. Just quickly looked at the new album button. I see what you mean, seems this is complicated to change that. Since that is a native browser dialog I am not sure if you can change itse content after creation at all.

These onClick usages are sort of legacy anyway and will be removed on that major release as well…

You maybe could replace the onClick() via jQuery and attach a new call to the js function newAlbum and set your preferred folder name then. Or you indeed hack the file to do so directly…

Member
Member
the_voder   20-10-2014, 12:50
#8

Re. replacing the onClick handler, I'm ahead of you there (see my earlier post).

As I said, I can remove the onClick with jQuery, and replace it with my own slightly tweaked version of the newAlbum function, but the problem would then be the XSRFToken argument that gets sent to launchScript when it's called by newAlbum(). I presume this is generated and written into the document head by PHP at runtime, and my newAlbum replacement isn't going to be able to get hold of this string, unless I find some way of parsing the raw page source for the value of XSRFToken or some similarly horrible hack…

I thought about trying to override the value of the album var that receives the result of the prompt, but it's scoped inside the newAlbum() function, so this isn't going to work, I think.

a|x

Administrator
Administrator
acrylian   20-10-2014, 13:24
#9

Ah, I see, I missed that somehow… The XSRF token is created by the PHP function ``. I think that should work within your function as well.

Member
Member
the_voder   20-10-2014, 15:27
#10

Ah, so I could have my plugin write my new function into the head of the document, as presumably you do, rather than linking to a static JS file. That might work, though. Will give it a go.

a|x

Member
Member
the_voder   20-10-2014, 20:41
#11

Hi again acrylian,

would I need to declare some globals if I wanted to place my new newAlbum function in a linked php-generated javascript file within my plugin folder?

I tried doing that, and adding at the relevant point

but got an 'Internal server error 500'.

a|x

Administrator
Administrator
acrylian   21-10-2014, 08:17
#12

I cannot answer off hand. Best probably would be you add your new function into the head directly.

Member
Member
the_voder   21-10-2014, 13:49
#13

It's working now, thanks very much.

a|x

Administrator
Administrator
acrylian   21-10-2014, 15:57
#14

Great!

  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.