collective / uwosh.snippets

Adds dynamically-updated rich text snippets to Plone. Update a snippet to display the change everywhere the snippet is used (pages, news items, events, anywhere rich text and TinyMCE appear).
4 stars 3 forks source link

Edit text of inserted snippets #9

Open simahawk opened 9 years ago

simahawk commented 9 years ago

Looks like you can't edit snippet's text after you added it. Whenever you click on it the snippet form pops out. Here's my use case (but I think it's a common one):

Is there a way to achieve this?

djay commented 9 years ago

There's collective.plonetemplates that does this. It doesn't it when you add the content though, not after adding it, inside tinymce.

simahawk commented 9 years ago

@djay I guess you are talking about Products.PloneTemplates but this allows you to use whole contents as new contents template. I just need small text snippets so that you can inject them into any richt text field using a simple plugin in the editor itself. And I need average editors to be able to create them, so no ZPT or advanced HTML knowledge should be required. uwosh.snippets does almost everything, but I (and maybe other ppl) need to edit the content after insertion. A possible solution could be to add a flag (like "drop snippet reference") to the insertion form: if this is activated you won't get the placeholder element and you can edit the text (I just tried by removing it via html editor). Or, maybe better: add a link w/ proper icon to the top right of the snippet box to remove it.

obct537 commented 9 years ago

@simahawk The functionality you described is definitely possible. The snippet form pops up to give you the option to either swap out another snippet, or edit the current one.

To edit the snippet, you have to click the Browse button in the popup form, and then click the edit link. In hindsight, I now realize this isn't a very good UI choice. I'll make a change to display an edit button right on the first page of the pop-up form when you click the snippet.

simahawk commented 9 years ago

I'm talking about "editing the text that has been inserted from the snippet", not the snippet itself ;) I think we need a way for dropping the "contenteditable=false" attribute or remove the snippet tag at all.

obct537 commented 9 years ago

Ah, I see what you mean. Unfortunately, what you're describing isn't what the snippets are intended for. A snippet isn't just a bit of rich text that you paste into a page wherever you need it. Instead, what you paste into the page is just a placeholder. When the page is rendered, the snippet-placeholder (referred to as a "plug" in the documentation), is replaced by the text/content in the snippet definition (this is what is stored in those ATDocuments). In this way, when you make a change to the snippet definition, the changes are reflected everywhere where a snippet plug is inserted. Example, for clarity:

Here on the UW-Oshkosh campus, many pages have the schools current number of students listed. Every semester, the number changes, so every page where the number was listed needed to be updated. Now, the page creators can insert a snippet plug with the current enrollment numbers. Whenever the number changes, one person just needs to edit the snippet definition, and the new number will show up immediately on every page that uses that snippet plug.

simahawk commented 9 years ago

I see, and that's cool! Making this feature "optional" would not hurt your behavior, right? I did a quick test by editing the JS in place and looks like it's working. As soon as I have time I'll submit you a branch to review. Thanks for your support :)