Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bendik Engebretsen 105 posts 202 karma points
    Jun 11, 2015 @ 11:56
    Bendik Engebretsen
    0

    Add Image Cropper as a Grid editor

    I really would like to see the Image Cropper added to the list of Grid editors. I prefer the Image Cropper property editor to the plain Image property editor because it makes it so much easier to maintain a consistent responsive design.

    So, I have started fiddling with Config/grid.editors.config.js. Just as a test, I added a 'Heading 2' editor like this:

    {
        "name": "Headline 2",
        "alias": "headline2",
        "view": "textstring",
        "icon": "icon-coin",
        "config": {
            "style": "font-size: 30px; line-height: 38px; font-weight: bold",
            "markup": "<h2>#value#</h2>"
        }
    },
    

    I understand that the "view" parameter is the crucial one that selects the type of editor you want. And I can see that the Richtext Editor is referred to with "view":"rte". I also suspect that there might not be an existing type for the Image Cropper, and that this has to be implemented in code somehow. Or is it? Or has anybody else implemented it?

  • Jamie Pollock 174 posts 853 karma points c-trib
    Jun 11, 2015 @ 12:48
    Jamie Pollock
    0

    Hey Bendik,
    I've tried making using the existing Image Cropper as a view by copying /umbraco/views/imagecropper/imagecropper.html to /umbraco/views/grid/editors/imagecropper.html but it falls over when you upload an image. Clearly it needs a bit more work.

    A quicker alternative might be to use the Nested Content plugin developed by Lee Kelleher & Matt Brailsford.

    This allows you to add document types as grid editors, you can even custom their render output to the grid so that it'll display how you'd expect. They were featured on uHangout a while ago if you need a tutorial of how it works.

    Hope this helps,
    Jamie

  • Bendik Engebretsen 105 posts 202 karma points
    Jun 15, 2015 @ 11:30
    Bendik Engebretsen
    0

    Thanks Jamie!

    I've decided to try to go the custom grid editor route, the general Nested Content Plugin seems a bit too much for my purpose right now. Anyway, I was just wondering what you did with the rendering, did you maybe copy some cshtml from the standard Image Cropper? I'm a newbie, and I can't seem to find the renderer code for this. Any ideas?

    Bendik

  • Jamie Pollock 174 posts 853 karma points c-trib
    Jun 15, 2015 @ 12:02
    Jamie Pollock
    0

    Hey Benedik,
    I took the property editor for the image cropper in the aforementioned first path. Custom grid editors are powered by AngularJS because it's all in the back office.

    It's lifted entirely from one path to the other. I would imagine there needs to be some modification to the controller js file (rather a new one be created - best not modify the existing one!) so that it'd work within the grid or as expected.

    Thanks,
    Jamie

  • Bendik Engebretsen 105 posts 202 karma points
    Jun 16, 2015 @ 10:50
    Bendik Engebretsen
    0

    Hello again Jamie!

    Yes, I think I have kind of figured out the property editor stuff, my question is about the rendering, i.e. the cshtml code for it. In the video "Defining a Grid Editor", it is said that if you use one of the standard views like "textstring", it will automatically use the standard renderer for it and the render code is in /Views/Partials/Grid/Editors/Textstring.cshtml. Since I am specifying a custom editor which is not in this standard collection, there is no ImageCropper.cshtml in that folder. So the question is if it is possible to find this render code somewhere else, or at least an example for how to render it. Surely, since the ImageCropper is part of Umbraco, there must be some kind of render code for it somewhere?

  • Jamie Pollock 174 posts 853 karma points c-trib
    Jun 16, 2015 @ 11:06
    Jamie Pollock
    0

    Hi Bendik,
    Glad to hear you're making some progress!

    I guess you'd need to add in an ImageCropper.cshtml as the image cropper wasn't intended to be used in this way.

    The other stumbling block you might come across is attaining the correct Image Crop Url from the node as grid partials don't seem to have access to the full range of UmbracoHelper class functions.

    Thanks,
    Jamie

  • Bendik Engebretsen 105 posts 202 karma points
    Jun 16, 2015 @ 16:16
    Bendik Engebretsen
    0

    Thanks again Jamie!

    Okay, so here's what I tried now: Specifying a custom editor in the view parameter, like this:

    "view": "/App_Plugins/Grid/editors/imagecropper.html"
    

    then, as said in the video, I looked for some inspiration to write this html in the /Umbraco/Views/grid/editors/, I actually just cloned the media.html there and called it imagecropper.html and put it my folder. "media" is the one used for the standard "Image" grid editor.

    Then I did the same thing to do a custom renderer, i.e. cloned /Views/Partials/Grid/Editors/media.cshtml, called it imagecropper.cshtml and put it in my folder. Finally, I specified the custom renderer in the grid.editors.config.js like this:

    "render": "/App_Plugins/Grid/editors/imagecropper.cshtml"
    

    Now if I add an image cropper to a grid on some page, the following error occurs when rendered:

    System.Web.HttpCompileException (0x80004005): c:\inetpub\PixEditCMS\App_Plugins\Grid\editors\ImageCropper.cshtml(1): error CS0103: The name 'model' does not exist in the current context

    So, the first line of code

    @model dynamic
    

    apparently is not good in this context, allthough as I said, it's a clone of one of the standard renderers.

    It would be really helpful to have some sample code for how to write a custom grid editor renderer. Anyone?

  • Carsten Berggreen 8 posts 28 karma points
    Jul 20, 2015 @ 09:12
    Carsten Berggreen
    0

    Interesting to see that I am not the only one struggling with this.

    I really like the fanoe grid approach, but the support is pretty bad in the documentation.

    Hope to find a solution soon.

  • Alan Mac Kenna 147 posts 405 karma points MVP c-trib
    Jul 20, 2015 @ 20:44
    Alan Mac Kenna
    0

    A suggestion for what might work for this is to use the Doc Type Grid Editor package rather than using Nested Content.

    https://our.umbraco.org/projects/backoffice-extensions/doc-type-grid-editor

    You should be able to define a DocType with a Cropper property and expose that in the Grid Editor config file. It makes wrapping simple/complex properties a breeze if you want to quickly get them into your Grid Editor.

    h5yr to Lee/Matt for a great package!

  • Carsten Berggreen 8 posts 28 karma points
    Jul 30, 2015 @ 15:23
    Carsten Berggreen
    0

    so the Image.GetCropUrl() should not be called upon the actual Media/Image item?

    I was hoping/searching for an approach where we can use the specified named cropsizes in the partial views...?

    like

    <img src="@image.GetCropUrl("image", "banner")" />
    

    this should result in some kinda url looking like:

    /media/oceanview-banner.jpg

    not:

    /media/oceanview.jpg?width=800&height=200&mode=crop

  • Carsten Berggreen 8 posts 28 karma points
    Jul 30, 2015 @ 15:26
    Carsten Berggreen
    0

    I can get the Media ID from the json of the Fanoe/bootstrap grid render, but I cannot figure out how to translate that Media ID into an object where I am allowed to call the GetCropUrl - which contains the short and SEO friendly version of the cropping...

    hench the format:

    [original filename without extension]-[cropsizename].[fileextension]

  • Bendik Engebretsen 105 posts 202 karma points
    Aug 19, 2015 @ 08:00
    Bendik Engebretsen
    0

    Just thought I'd update on my progress with this: I have now dropped the idea of integrating the image cropper in the grid alltogether. Instead, I came up with the idea of creating multiple grid editors, one for each crop type on my site. And, when I recently upgraded to 7.2.8, I discovered that this is exactly what's done in the Fanoe starter kit! Allthough one has to recreate the crops and keep two versions of them, this solution is fine with me for now.

    Still a bit confused about images being inside or outside (somewhere...) the Media Library, but that's another matter.

  • Tajamal 87 posts 175 karma points
    Feb 18, 2016 @ 11:20
    Tajamal
    0

    Can anyone tell, why a "Data Type" is not present in dropdown list when adding a property from "Grid Editors".

    I want to add "Image cropper" and i'm only able to add that from "Document Types" and it's not appearing from Grid Editors.

    I have tried Umbraco versions: 7.3.1, 7.3.7.

  • Bendik Engebretsen 105 posts 202 karma points
    Feb 29, 2016 @ 09:13
    Bendik Engebretsen
    0

    I don't quite understand your question, are you trying to add a property to a Document Type? Anyway, here is my understanding of it:

    First, you add a "Grid layout" property to your Document Type. Then you can configure the "Grid Layouts" and "Row configurations" for this property. Click on a Row configuration, and then on one of the cells in that configuration. You should see the check box "Allow all editors". If you uncheck it, you should see a check list of all editors available. And among these you should see some Image editors (not sure which ones in v 7.3). The grid editors are defined in Config/grid.editors.config.js, so take a look there. (You will see that some editors are accompanied by some Razor code in App_Plugins/Grid/Editors/, so check this out if you are creating your own custom editors)

    I'm using Umbraco 7.4, but I think the principle is the same in 7.3 allthough the UI might be slightly different.

  • Tajamal 87 posts 175 karma points
    Mar 01, 2016 @ 11:19
    Tajamal
    0

    My apologies, i wasn't clear enough. It is when you add "LeBlender Editor" package to umbraco. This post should have been posted to them.

    1. From Developer -> Grid Editors
    2. Propertis -> Add property

    From "Property setting" Image cropper does not appear.

    And yes it works when added as you have explained.

Please Sign in or register to post replies

Write your reply to:

Draft