-4

In a page inside the insert component popup window. When a user is trying to Select a component and a Template then how to *restrict them to select the same combination of component and template * that is already present in the component list.

I thought of writing a javascript on insert button.Please suggest if i am going in right way.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

2 Answers2

11

As Bart says above your question is amazingly vague, but here is an attempt at an answer as i've just done something similar. Given the vagueness, i'm assuming that you're knee deep in JS code and what I'm putting here will make sense to you :)

In your javascript you'll likely store the selected component presentation in a property as your user clicks on a given cp in the list, for example:

// keeps stock of the current selected component presentation
p.selectedComponentPresentation; 

to use simply:

var componentPresentation = p.selectedComponentPresentation;

and to set you can see i get the tab control first, store the component presentationTab and from there call the getSelectedComponentPresentation():

var masterTabControl = $controls.getControl($("#MasterTabControl"), 
                                            "Tridion.Controls.TabControl");
p.compPresTab = masterTabControl.getPage("ComponentPresentationsTab");
p.selectedComponentPresentation 
                       = p.compPresTab.getSelectedComponentPresentation();

Again I do hope this makes sense, I'm also assuming by now you'll know how to get the pageId

Dominic Cronin
  • 6,062
  • 2
  • 23
  • 56
johnwinter
  • 3,624
  • 15
  • 24
  • thank you very much john, i was trying to convey this only, and what you suggested i was trying in the same way, but after clicking the button i am getting in popup box [object, object]. not getting the selected component. and do i need to store pageid before calling the selectedcomponentPresentation?because i dont know how to do that. – user1518281 Jul 12 '12 at 12:38
  • selectedComponentPresentation is an object. If you are only interested in the Component ID, you can call p.selectedComponentPresentation.getComponentId() and pass that to your popup. Similarly, you can use the code Frank posted to pass the Page ID to the popup. – Peter Kjaer Jul 12 '12 at 12:48
  • Hi user1518281 :) yes the code i've posted is ONLY for the Page dialog in the SDL Tridion GUI. When you say 'selected component presentation' (CP) I assume you're in the Page dialog. As Frank also shows below, when in the page dialog you can use $display.getItem() to give you the page object from there you can get to your CP objects. For context the code which I've pasted above I have pasted is ran alongside the 'ComponentPresentations' tab. In the ribbon you might need to find another way to the 'selected' CP. – johnwinter Jul 12 '12 at 14:28
  • Thanks to everyone for replying me.. special thanks to john.. :) i got my answers. – user1518281 Jul 12 '12 at 15:40
1

If you're in a Component popup window, you can get the ID of the Component through

$display.getItem().getId()

This will actually work in any Item edit popup (so Pages and other item types too).

It will not work in the main Dashboard view (so where you see the tree on the left and the list on the right), since there you don't have a single "current item".

You will have to update your question with information as to where your code is running, because that is unclear to me now. As far as I know there is no place in the Web GUI where you have both a "current Component" and a "current Page".

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807