【问题标题】:Closing Liferay dialog box programmatically以编程方式关闭 Liferay 对话框
【发布时间】:2013-06-24 15:12:15
【问题描述】:

我有 Liferay 对话框,我想关闭此对话框并希望将我的 url 重定向到一个页面。

我就是这样做的。

<aui:column columnWidth="16" >

<%if(UserGroupRoleLocalServiceUtil.hasUserGroupRole(u.getUserId(), groupId, role.getRoleId())){ %>

<input value="delete" type="button"  onclick="document.location.href='
<portlet:actionURL name="deleteUserRole"><portlet:param name="memberId" value="<%= memberIdStr %>"/>
<portlet:param name="organization" value="<%=  Long.toString(organizationID) %>"/></portlet:actionURL>'"  />
    <%} %>
            </aui:column>


public void deleteUserRole(ActionRequest actionRequest,ActionResponse actionResponse){

// process to delete user role

    Role r = RoleLocalServiceUtil.getRole(org.getCompanyId(),
                    "Power User");


    UserGroupRoleLocalServiceUtil.deleteUserGroupRoles(userID, groupId, new long[] { r.getRoleId() });

        actionResponse.sendRedirect("/group/employee/empHome");                 


}

通过使用这种方式,当我单击删除按钮时,此方法会被调用,执行处理并重定向到此 url,但会弹出窗口。

我想重定向到 actionResponse.sendRedirect 页面中的给定页面,但不是在对话框中,它不应该在 dailog 框中打开。

如何先关闭此对话框,然后将我的页面重定向到给定的 url?

我通过在链接上调用此类来打开对话框 下面是我的js文件

/test.js/

 var myPopup;
AUI().ready( function() {

    if (AUI().one('#testing-menu')) {

    AUI().one('.extendClick').on(
        'mouseenter',
        function(event){
            AUI().one('.navi-type').setStyles({'display': 'none'});
            AUI().one('.extendClick').setStyles({'display': 'none'});
            AUI().one('.collapseArrow').setStyles({'display': 'block'});
        }
      );


   AUI().all('.employee-dialog').on(
        'click',
        function(event){
          var url = event.currentTarget.get('href');
          event.preventDefault();
          //console.info(url);

        window.myPopup= Liferay.Util.openWindow(
              {
                dialog: {
                  align: { points: ['tc', 'tc'] },
                  width: 960
                },
                title: 'Settings',
                uri: url
              }
            );
        }
      );


  }
});

【问题讨论】:

  • 如何打开对话框弹出窗口?请出示该代码。
  • @GaborSch 我为弹出对话框添加了代码

标签: javascript dialog liferay-6


【解决方案1】:

保存弹出窗口引用,稍后使用它关闭弹出窗口:

var myPopup;
AUI().all('.employee-dialog').on(
    'click',
    function(event){
      [..]
      myPopup = Liferay.Util.openWindow([...]);
    }
  );

使用onclick中保存的弹出窗口引用:

<input value="delete" type="button" onclick="myPopup.close();document.location.href='
    [...]

【讨论】:

  • 我在我的 js 文件中添加了变量 myPopup,就在员工对话框函数上方,然后尝试按照所示在 onclick 上调用它,但它既没有关闭弹出窗口,也没有调用我的 @987654325此 onclick 按钮上的 @ 方法
  • 这可能是可见性问题。在顶层声明 myPopup,这样您就可以在 onclick 匿名块中访问它。
  • 是的,我已经在文件顶部添加了这个变量,但是当我点击按钮时,它没有调用我的
  • 实际上它在萤火虫错误模式下给了我错误,因为 ReferenceError:myPopup 没有定义。我在另一个 portlet 中定义了 js 文件,我从另一个 portlet 中调用它,这是我们收到此错误的原因吗?
  • @Ran 也许。尝试在窗口级别定义:window.myPopup = ...window.myPopup.close()
【解决方案2】:

我终于可以用这种方式关闭这个对话框了。

<input value="delete" type="button"  onclick="javascript:closePopUp;document.location.href='
<portlet:actionURL name="deleteUserRole"><portlet:param name="memberId" value="<%= memberIdStr %>"/>
<portlet:param name="organization" value="<%=  Long.toString(organizationID) %>"/></portlet:actionURL>'"  />





<script type="text/javascript">
function closePopUp(){
top.document.getElementById('closethick').click();
}
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-01
    • 2021-02-25
    • 2018-07-19
    • 2014-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多