留言板

close Liferay Dialog

Morad Ahmad,修改在8 年前。

close Liferay Dialog

Junior Member 帖子: 71 加入日期: 10-6-16 最近的帖子
Hello,

I use a Dialog to write a message within a portlet. The code looks like:


	<aui:script>

						function openPrivatMessageDialog(dialogId, url, title, width, height) {
							 YUI().ready(function(A) {
						     
						        YUI().use('aui-base','liferay-util-window', function(A) {
						     						         
						         var messagingDialog =  Liferay.Util.Window.getWindow (
							                {
							                    title : title,
							                    uri: url,
							                    id: dialogId,
							                    dialog: {
							                        cache: false,
							                        modal: true,
							                        destroyOnClose:true,
							                        width: width,
							                        height: height,
							                        toolbars: {
															footer: [
																{
																	label: '&lt;%= UnicodeLanguageUtil.get(pageContext, "cancel") %&gt;',
																	on: {
																		click: function() {
																			messagingDialog.hide();
																		}
																	}
																}
															]
														}
							                        
							                    }
							                }
							            );
							            
							            messagingDialog.on('hide', function() {
							                  console.log("Modal closed")
							            });
							        
							        	messagingDialog.render();
							        
							        });
						    
						    });
						
						}
						
					</aui:script>

&lt;% String sendMessagePopup = "javascript:openPrivatMessageDialog('portangoPrivateMessageDialog','" + sendMessageURL.toString() + "', '" + LanguageUtil.get(pageContext, "new-message") + "' , 840, 960);"; %&gt; 
			
					<div style="clear: both; height: 1em"></div>
			
					<div class="portango-context-buttons right">
						<div class="btn-group">
							<aui:button cssClass="btn  portango-action-button" value="send-message" onclick="<%=sendMessagePopup%>" />
						</div>
					</div>		


But I can't close the dialog after sending the message. The code to send/close looks like:


A.io.request(
				'<liferay-portlet:resourceurl id="sendMessage"></liferay-portlet:resourceurl>',
				{
					dataType: 'json',
					form: {
						id: form,
						upload: true
					},
					on: {
						complete: function(event, id, obj) {
							loadingMask.hide();

							// $('#portangoPrivateMessageDialog').hide();
							// A.DialogManager.closeByChild('#portangoPrivateMessageDialog');
							// var dialog = Liferay.Util.Window.getById('#portangoPrivateMessageDialog');
				            // dialog.destroy();
							
							var responseText = obj.responseText;
							var responseData = A.JSON.parse(responseText);
							if (responseData.success) {
								console.info("SUCESS");
							}
							else {
								var messageContainer = A.one('#<portlet:namespace />messageContainer');
								if (messageContainer) {
									messageContainer.html('<span class="portlet-msg-error">' + responseData.message + '</span>');
								}
							}
						
							// var messageDialog = A.one('#portangoPrivateMessageDialog');
							var messageDialog = Liferay.Util.Window.getById('#portangoPrivateMessageDialog');
							if(messageDialog) {
								console.info("close message dialog");
								messageDialog.hide();
							} 
							else {
								console.info("couldn't find message dialog!");
							}  
						
						}
					}
				}
			);


I don't understand why "A.one('#portangoPrivateMessageDialog');" or "Liferay.Util.Window.getById('#portangoPrivateMessageDialog');" return "undefined".
I see there is a div element with this id containing the dialog.!!!

Please help:-)!,
Morad.
thumbnail
Andrew Jardine,修改在8 年前。

RE: close Liferay Dialog

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hi Morad,

I used a modal recently to provide users a way to add configurations. I used the code below to launch and kill the modal when done.


	A.one('#<portlet:namespace />save').on('click', function(event) {
		var A = AUI();
		
		var url = '&lt;%= saveActionURL.toString() %&gt;';
		
		A.io.request(url, 
		{
			method : 'POST',
			form : {
				id : '<portlet:namespace />fm'
			},
			on : {
				success : function() {
					Liferay.Util.getOpener().refreshPortlet();
					Liferay.Util.getOpener().closePopup('dialog');
				},
				error : function() {
					alert("Error occurred.");
				}
			}
		});
	});


checkout the success: portion. Perhaps this would work for you as well?