3 Replies Latest reply on Sep 20, 2012 5:43 AM by Ryan Lunka

    How can I limit the number of items an author can add to a parsys?




      I am trying to customise the parsys component to restrict the number of items that an author can add to it. I want this limit to be controlled via a field in the design dialog.


      Is anybody aware of a way to do this?


      I have been playing around with promoting the parsys component and adding checks around this line:

           <cq:include path="*" resourceType="<%= newType %>"/>


      So it only includes this when there is still space in the parsys, however that only seems to control whether the "Drag new items here" box is displayeds or not, it does nothing to prevent a user from inserting new components.



        • 1. Re: How can I limit the number of items an author can add to a parsys?
          kasq Level 3



          I suppose that you need to create a custom version of standard parsys component from /libs/foundation/components/parsys and there inside parsys.jsp add some condition which will check number of items from dialog property which can be added to the parsys.




          • 2. Re: How can I limit the number of items an author can add to a parsys?
            cowls Level 1

            Hi Kasq, thanks for the response.


            I suppose I am after something a bit more specific. As you can see I tried something like that and managed to hide the "Drag components here" after 3 items were inserted. But it didnt prevent me inserting components to the parsys, it just hid the message. (It also requires a page refresh to actually see the update, but thats another story)


            Are you aware which piece of logic actually handles the inserting of a component, or if this is driven by some action listener or something?



            • 3. Re: How can I limit the number of items an author can add to a parsys?
              Ryan Lunka Level 3

              It sounds like you just updated the JSP that outputs "what is in the parsys".  The drag and drop "adding a component to the parsys" functionality is encapsulated in JavaScript somewhere, probably in a clientlib.  I think there is a listener for the drag and drop that makes a POST using the slingPostServlet to actually "add" the component to the page (i.e. creates a representative node for the component instance), then a page refresh and/or AJAX call updates the visual contents of the parsys.  You'll need to add logic that disables this drag and drop functionality, if the parsys is too full.  That may be difficult - maybe heavy customization.  I'm not sure.


              Another approach you could look at is using a SlingPostProcessor to inspect POSTs to a parsys node and intercept ones that would add too many components.  This is probably not the cleanest of approaches, but an option if you can't manipulate the JS to get it to work.  The trick here is then providing some response to the user that their component wasn't added for a reason.  Again, you're manipulating the JavaScript.

              1 person found this helpful