Foren

Document Library Selection

thumbnail
Kamesh Sampath, geändert vor 12 Jahren.

Document Library Selection

Regular Member Beiträge: 158 Beitrittsdatum: 27.05.10 Neueste Beiträge
Hello,

I am trying to use the Document library in one my custom portlets, the scenarios is the user is provided with text-box and select button, when the user clicks the "Select" button it shows a popup for selecting a document form the "Document Library" , something similar to what we do when creating "Web Content", when I tried to do the same way as its done in Journal portlet jsp's am not getting the popup windows emoticon

Can any one if tried or used something like this provide some thoughts on the same ?

Thanks.
Kamesh
thumbnail
Thiago Leão Moreira, geändert vor 12 Jahren.

RE: Document Library Selection

Liferay Legend Beiträge: 1449 Beitrittsdatum: 10.10.07 Neueste Beiträge
This is doable! The key implementation is that you have to create a liferay-portlet:renderURL setting the portletName to the JornaulArticle portlet, something like this
					<liferay-portlet:renderurl portletname="15" windowstate="<%= LiferayWindowState.POP_UP.toString() %>" var="selectDLURL">
						<liferay-portlet:param name="struts_action" value="/journal/select_document_library" />
						<liferay-portlet:param name="groupId" value="<%= String.valueOf(dlScopeGroupId) %>" />
					</liferay-portlet:renderurl>


Keep in mind that I got this code from top of my head and perhaps it needs some adjustments.
thumbnail
Kamesh Sampath, geändert vor 12 Jahren.

RE: Document Library Selection

Regular Member Beiträge: 158 Beitrittsdatum: 27.05.10 Neueste Beiträge
Thanks Thiago, i did the same but how does that get invoked on a click of a button something like "Select", i tried to mimick the code found in the /html/portlet/journal/edit_article_content_xsd_el.jsp which has a quiet similar code of what you had put down, but am not getting the popup window to select a document form the DL Library emoticon

I also have one more complication, I need to call the selection of document happen from the "Configuration Mode" window of the portlet which is again a "pop-up", where is it possible to call a popup form another popup ?

Thanks in advance.

Kamesh
thumbnail
Thiago Leão Moreira, geändert vor 12 Jahren.

RE: Document Library Selection

Liferay Legend Beiträge: 1449 Beitrittsdatum: 10.10.07 Neueste Beiträge
This is easy to call to the following

<a href="<%= selectDLURL%>">select</a>


Yes, you can call a popup from another popup.
thumbnail
Kamesh Sampath, geändert vor 12 Jahren.

RE: Document Library Selection

Regular Member Beiträge: 158 Beitrittsdatum: 27.05.10 Neueste Beiträge
thanks thiago it worked, i guess the same works if i put <%=varURL%> in the aui:button.

But right now i have an issue, after the popup is open i traverse to DLFolder and select the DLdocument i want using the "Choose" button, but then for me nothing happens after I click the "Choose". how do i set the selected DL document URL to the text field I am having on the page ?

Thanks.

Kamesh
thumbnail
Thiago Leão Moreira, geändert vor 12 Jahren.

RE: Document Library Selection

Liferay Legend Beiträge: 1449 Beitrittsdatum: 10.10.07 Neueste Beiträge
Kamesh, give a look at the html generated for you pop up and you will see a call to a javascript function called selectDocumentLibrary. That's the trick!
thumbnail
Kamesh Sampath, geändert vor 12 Jahren.

RE: Document Library Selection

Regular Member Beiträge: 158 Beitrittsdatum: 27.05.10 Neueste Beiträge
Thiago,

finally i was able to crack it emoticon , here is the piece of snippet that solved it


...

<aui:input cssClass="lfr-input-text-container" inlineField="<%= true %>" id="template-name" name="template-name" size="55" type="text" />
			&lt;%
			    long dlScopeGroupId = groupId;
					    
					    if (liveGroup.isStaged()
						    &amp;&amp; !liveGroup.isStagedRemotely()
						    &amp;&amp; !liveGroup
							    .isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) {
						dlScopeGroupId = liveGroup.getGroupId();
					    }
			%&gt;

			<liferay-portlet:renderurl portletname="15" windowstate="<%= LiferayWindowState.POP_UP.toString() %>" var="selectDLURL">
				<liferay-portlet:param name="struts_action" value="/journal/select_document_library" />
				<liferay-portlet:param name="currentURL" value="<%= currentURL%>" />
				<liferay-portlet:param name="groupId" value="<%= String.valueOf(dlScopeGroupId) %>" />
			</liferay-portlet:renderurl>		
			
			&lt;%
			    Map<string, object> data = new HashMap<string, object>();
					    data.put("DocumentlibraryUrl", selectDLURL);
			%&gt;
			
			<aui:button id="<portlet:namespace />cmdLookupTemplate" name="cmdLookupTemplate" cssClass="journal-documentlibrary-button" data="<%= data %>" value="select" />
		  
	

	<aui:button-row>
		<aui:button name="setButton" type="submit" value="set-button" />
	</aui:button-row>


<script type="text/javascript">
var <portlet:namespace/>popup;
var _15_selectDocumentLibrary;
jQuery(document)
		.ready(
				function() {
					
					jQuery('#<portlet:namespace/>cmdLookupTemplate')
							.click(
									function() {
										<portlet:namespace/>popup = window
												.open(
														jQuery("#<portlet:namespace/>cmdLookupTemplate").attr('data-documentlibraryurl'),
														'Select Template',														'directories=no,height=640,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=680');

										<portlet:namespace/>popup.focus();
									});
					
					_15_selectDocumentLibrary=function(url){
						  <portlet:namespace/>popup.close();
						   //alert("Selected document"+url);
						   jQuery("#<portlet:namespace/>template-name").val(url);
						};	
				});
				
			
</script>

...
</string,></string,>


As you said the trick is of having the "_15_selectDocumentLibrary" java script function in our JSP page which is acting as callback when we click the "Choose" button and i placed required code there for completing my action.

But still i have one little question whether the prefix "_15_" is mandatory - i see "15" is the Journal portlet id ? because the from the popup window its looking for a method opener._15_selectDocumentLibrary(url) , wont it be nice to have just "selectDocumentLibrary" without portlet:namespace ?

Thanks.
Kamesh
Jan Rodan, geändert vor 10 Jahren.

RE: Document Library Selection

New Member Beiträge: 7 Beitrittsdatum: 01.06.12 Neueste Beiträge
thank you for this solution!
had problem with the JS callback part.
Ganesh K., geändert vor 8 Jahren.

RE: Document Library Selection

New Member Beiträge: 2 Beitrittsdatum: 14.10.13 Neueste Beiträge
I tried the same image gallery selection in Liferay 6.2 .
The change here is LR 6.2 uses DDM as namespace (PortletKeys.DYNAMIC_DATA_MAPPING) turns out to be "166" from https://docs.liferay.com/portal/6.2/javadocs/src-html/com/liferay/portal/util/PortletKeys.html#line.

and the JSP looks like


function _&lt;%=PortletKeys.DYNAMIC_DATA_MAPPING %&gt;_selectDocumentLibrary(url, hash, name, version)
{ 
...
...
}
thumbnail
Víctor Ponz, geändert vor 8 Jahren.

RE: Document Library Selection

New Member Beiträge: 18 Beitrittsdatum: 29.07.14 Neueste Beiträge
I've used this implementation and it works as user admin, but when I try to use it as a regular user, always says that the user does not have the correct permission.
I have tried to add permissions to portlet 166 by I can't find it.
How can I fix it?
Thanks in advance
thumbnail
Jan Geißler, geändert vor 8 Jahren.

RE: Document Library Selection

Liferay Master Beiträge: 735 Beitrittsdatum: 05.07.11 Neueste Beiträge
First of all you should try to find out what permission exactly is the problem. You could try to tackle it down in the source code, or you can check in the Control Panel. If you go for the control panel, I suggest to take a look at the DDL portlet. You can give permission to the portlet, and the data. Try to increase permissions iteratively to resolve your issue, so you know what permission you needed to set to get it working.
thumbnail
Víctor Ponz, geändert vor 8 Jahren.

RE: Document Library Selection

New Member Beiträge: 18 Beitrittsdatum: 29.07.14 Neueste Beiträge
You are right. I've solved the problem in a fresh installation

Thanks
Angelos Varvitsiotis, geändert vor 8 Jahren.

RE: Document Library Selection

New Member Beiträge: 6 Beitrittsdatum: 26.07.11 Neueste Beiträge
Hi Kamesh,

Thanks for your code. I had to use it multiple times for more than one fields in one form, and it turned out that I had to change it thus:
<script type="text/javascript">
	var <portlet:namespace/>popup;
	var _15_selectDocumentLibrary;
	$(document).ready(function() {
		$('#<portlet:namespace/>tfName').click(function() {
			_15_selectDocumentLibrary=function(url){
				<portlet:namespace/>popup.close();
				url = decodeURIComponent(url);
				// alert("Selected document " + url);
				var parts = url.split('/');
				console.log(parts);
				$('#<portlet:namespace/>tfNameI').val(parts[4]);
				$('#<portlet:namespace/>tfUuidI').val(parts[5]);
			};								
			var documentLibraryUrl = $('#<portlet:namespace/>tfNameI').attr('data-documentlibraryurl');
			var templatesFolderId = $('#<portlet:namespace/>templatesFolderId').val();
			if (templatesFolderId == '-1') {
				alert('Please select a Templates Folder first');
			}
			else {
				documentLibraryUrl = documentLibraryUrl.replace('folderId=-1', 'folderId=' + templatesFolderId);
				<portlet:namespace/>popup = window.open(
					documentLibraryUrl,
						'Select File',
						'directories=no,height=640,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=700');
				<portlet:namespace/>popup.focus();
			}
		});
	});
</script>
, that is, move the assignment to _15_selectDocumentLibrary inside the click() function. The code also processes the URL returned, breaks it into part and stores the file name and the UUID in different form fields. It also checks for a templates folder (see the companion code below), so that the popup starts from a selected folder other than the DL root folder.

By the way, here is the companion code for selecting a folder from the DL (tested in 6.1.30):
<script type="text/javascript">
	var <portlet:namespace/>popup;
	var _20_selectFolder;
	$(document).ready(function() {
		$('#<portlet:namespace/>templatesFolderName').click(function() {
			_20_selectFolder = function(folderId, folderName, isSupportedMetadata, isSupportedSocial){
				<portlet:namespace/>popup.close();
				// alert("Selected folderId: " + folderId + ", folderName: " + folderName);
				$('#<portlet:namespace/>templatesFolderName').val(folderName);
				$('#<portlet:namespace/>templatesFolderId').val(folderId);
			};
			<portlet:namespace/>popup = window.open(
				$('#<portlet:namespace/>templatesFolderName').attr('data-documentlibraryurl'),
					'Select Folder',
					'directories=no,height=640,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=700');
			<portlet:namespace/>popup.focus();
		});
	});
</script>


Regards,

Angelos
Matias Gavinowich, geändert vor 11 Jahren.

RE: Document Library Selection

New Member Beiträge: 3 Beitrittsdatum: 18.09.12 Neueste Beiträge
Hi,

Would it be possible to restrict the selection the user can make only to documents of a certain Document Type (we have created our own, which has more information than Basic Document), building on this solution?

I have researched on the parameters select_document_library.jsp, such as folderId, searchFolderIds and keywords, with no luck.

How could we have this dialog show only documents (images) of our custom type?

Thanks
thumbnail
Víctor Ponz, geändert vor 8 Jahren.

RE: Document Library Selection

New Member Beiträge: 18 Beitrittsdatum: 29.07.14 Neueste Beiträge
Hi
Have you found any solution for selecting a certain Document Type ?

Thanks