I need to take the Component and Component Template tcm ids from the Component Presentation tab of any Tridion Page.
Scenario:
- On the exisiting page in Tridion.
- Go to "Component Presentation" tab.
- When I click the "Insert" button, I want to iterate the Component and Component Template tcm id and display that in JavaScript alert box.
I am trying to find the exact javascript file/function to accomplish this, I couldn't find the exact one.
I am using SDL Tridion 2011 SP1.
Any help/suggestion would be highly appreciated.
EDIT
I am having this script which will fire when we wil click the Insert button in the "Insert component presentation" window.
Tridion.Cme.Views.InsertCpDialog.prototype.onInsertClick =
function InsertCpDialog$onInsertClick()
{
var p = this.properties;
var c = p.controls;
var templateId = c.templateSelect.getValue();
var components = c.list.getSelection().getItems();
p.componentPresentationsAdded += components.length;
var compId = components[components.length - 1];
var component = $models.getItem(compId);
if (component)
{
var userSettings = Tridion.UI.UserSettings.getInstance();
if (userSettings && userSettings.isLoaded())
{
Tridion.UI.UserSettings.setLastSelectedLocation(
component.getPublicationId(), $const.ItemType.COMPONENT, p.contextUri);
}
}
this.fireEvent("insert", {
components: components,
template: templateId
});
};
So here I will get the tcm id of selected Component and template "compId" & "templateId", which is to be inserted. Now my question is: how can I check whether this component and template is already present on the Component Presentation Tab?
If somehow I will be able to get the id of all component and template already present on the page (from my "Insert" button) then I can compare them. But I am not getting any function which will give me those id. Here I got stuck.
EDIT
I am trying to go inside the page with these codes but i am not able to get the correct function which is getting fired on click of Insert, or which will return me the list of component and template id listed there.
Extensions.Test.prototype.isEnabled = function Test$isEnabled(selection) {
try
{
console.log($controls);
var masterTabControl = $controls.getControl($("#MasterTabControl"),
"Tridion.Controls.TabControl");
console.log(masterTabControl);
alert("Mastercontrol - ComponentpresentationsTab");
console.log(masterTabControl.getPage("ComponentPresentationsTab"));
console.log("list of component presentations");
console.log(masterTabControl.getPage("ComponentPresentationsTab").
getListComponentPresentations().getItems());
console.log("list of get xml");
console.log(masterTabControl.getPage ("ComponentPresentationsTab").
getListComponentPresentations().getItems().getXml);
}
(catch exc)
{
}
return true;
}
EDIT I got all the CP Id listed under CP TAB with this code. Thanks to @Frank van Puffelen
var p = this.properties;
var tgp = this.properties;
var c = p.controls;
var pageId = selection.getItem(0);
var masterTabControl = $controls.getControl($("#MasterTabControl"),
"Tridion.Controls.TabControl");
var compPresTab = masterTabControl.getPage("ComponentPresentationsTab");
var comPresList = p.compPresTab.getListComponentPresentations();
for (var i = 0; i <= myStringArray.length; i++)
{
console.log(comPresList.getItems()[i].getComponentId());
console.log(comPresList.getItems()[i].getComponentTemplateId());
}
InsertCpDialog.onInsertClickmethod. Do you understand what this code does? If not: did you set a breakpoint in it and step through it? You'll see that it gets access to acontrolsarray that contains all the controls in the view (in this case theInsertCpDialogpopup). This logic is applicable in any view, so you can just follow the trail. - Frank van Puffelen