Skip to content

Loading…

Implemented came_from Parameter #19

Closed
wants to merge 1 commit into from

4 participants

@Kosi81

Use Case:

We implemented a direct Link from Overview Views (@the specific cropped Image) to the croppingeditor. Editor should have possibility to go to Imagecropping directly and come back to specific overview page. Therefore we give UUID of Page to croppingeditor and give Link to come back.

@pysailor

Some more background info on this request:
It would allow to offer users a direct access from the context of where an image (with a certain scale is displayed) to the cropping editor and back again.

Example:
A custom BrowserView that aggregates content and displays several images. Users with editor permissions on an image get to see a cropping symbol on mouse-over (the JavaScript code for this is not part of this pull request - but it might make sense to add it to the README as an example). The link to the cropping editor contains the image scale and the context's UID, e.g. http://mysite.com/img-2286.jpg/@@croppingeditor?came_from=4f412b72674a4654be425e7e9ad043d5&scalename=project_mini

UI example:
cropping_overlay

The cropping editor already allows pre-selection of scale via request parameter. We just need to provide way for the user to get back to the original context. Therefore, after a Save or Delete Scale operation, a link back to the original context is provided, if a came_from parameter is present:

cropping_backlink

A click on Cancel causes an immediate redirect back to the original context, if a came_from parameter is present.

This behaviour should be in line with some deliberations in #9: "another possible - and as we think most intuitive - way to access the croppingeditor would be a cropping button displayed over images."

@petschki
Plone Collective member

I'd rather suggest to use the overlay solution as mentioned in the documentation. since cropping only works when javascript is enabled you don't need to load the whole cropping page:

(function($) {
    $(function() {
        $("a[href$='@@croppingeditor']").prepOverlay({
            subtype:'ajax',
            formselector:'#coords',
            closeselector:"input[name='form.button.Cancel']"
        })

        $(document).bind("formOverlayLoadSuccess", function() {
            imagecropping.init_editor();
        })
    })
})(jQuery);

but thats my oppinion ...

@petschki
Plone Collective member

since this is an open discussion in general, i'd like to invite you to post your oppinion/experience on #12

@frisi
Plone Collective member

thanks @Kosi81 for the initiative and @pysailor for the detailed description. as you pointed out we outlined "the crop-link displayed over croppable images" for more usability in #9.

after that we started ticket #12 as a feature request to make this happen.

if i understand correctly, you want to achieve the very same goal with this feature request, don't you?
if yes - let's move the discussion to #12 as suggested by @petschki.

i do share his point of view that it is more elegant/fast(no page reload)/user-friendly to display the croppingeditor in an overlay for this usecase. (after all we just need to display the editor and can skip the left columns for selecting fields and scales.)

thanks for your feedback!

@Kosi81

Hi
Sorry for the late answer. We have now implemented this with the suggested solutions. Works great! Thx, a lot for this tip. So i will clode the pull request!

@Kosi81 Kosi81 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2013
  1. Implementet came_from Parameter for going back

    Martin Kousek committed
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 0 deletions.
  1. +3 −0 CHANGES.txt
  2. +7 −0 src/plone/app/imagecropping/browser/editor.pt
  3. +23 −0 src/plone/app/imagecropping/browser/editor.py
View
3 CHANGES.txt
@@ -20,6 +20,9 @@ Changelog
- Small documentation update
[saily]
+- Implementation came_from Parameter to go back to specific page
+ [Kosi81]
+
0.1rc1 (2013-03-11)
-------------------
View
7 src/plone/app/imagecropping/browser/editor.pt
@@ -7,6 +7,12 @@
<body>
<metal:main fill-slot="main">
+
+ <dl class="portalMessage info" tal:condition="view/go_back_url">
+ <dt>Info:</dt>
+ <dd><a tal:content="view/go_back_title" tal:attributes="href view/go_back_url"></a></dd>
+ </dl>
+
<h1 class="documentFirstHeading"
i18n:translate="">
Image Cropping Editor
@@ -75,6 +81,7 @@
<img class="cropbox" tal:attributes="src current_scale/image_url;" />
<div>
+ <input type="hidden" id="came_from" name="came_from" tal:attributes="value request/came_from|nothing"/>
<input type="hidden" size="4" id="x1" name="x1" />
<input type="hidden" size="4" id="y1" name="y1" />
<input type="hidden" size="4" id="x2" name="x2" />
View
23 src/plone/app/imagecropping/browser/editor.py
@@ -9,6 +9,7 @@
from plone.app.imaging.utils import getAllowedSizes
from plone.registry.interfaces import IRegistry
from zope import component
+from plone.app.uuid.utils import uuidToObject
from zope.component._api import getUtility
import json
@@ -140,6 +141,10 @@ def __call__(self):
cropping_util = self.context.restrictedTraverse('@@crop-image')
if form.get('form.button.Cancel', None) is not None:
+ if self.request.form.get("came_from", None):
+ came_from = self.request.form.get("came_from")
+ return self.request.response.redirect(
+ uuidToObject(came_from).absolute_url())
return self.request.response.redirect(
self.context.absolute_url() + '/view')
if form.get('form.button.Delete', None) is not None:
@@ -165,6 +170,24 @@ def __call__(self):
return self.template()
+ def go_back_url(self):
+ if self.request.form.get('form.button.Save', None) is not None \
+ or self.request.form.get('form.button.Delete', None) \
+ is not None:
+ if self.request.form.get("came_from", None):
+ came_from = self.request.form.get("came_from")
+ if uuidToObject(came_from):
+ return uuidToObject(came_from).absolute_url()
+
+ def go_back_title(self):
+ if self.request.form.get('form.button.Save', None) is not None \
+ or self.request.form.get('form.button.Delete', None) is \
+ not None:
+ if self.request.form.get("came_from", None):
+ came_from = self.request.form.get("came_from")
+ if uuidToObject(came_from):
+ return _(u"Go back to ") + uuidToObject(came_from).title
+
def _min_size(self, image_size, scale_size):
""" we need lower min-sizes if the image is smaller than the scale """
width = scale_size[0]
Something went wrong with that request. Please try again.