| Cheng Tang | 697ce24 | 2014-04-27 16:18:17 +0800 | [diff] [blame] | 1 | <%-- |
| 2 | /** |
| 3 | * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or modify it under |
| 6 | * the terms of the GNU Lesser General Public License as published by the Free |
| 7 | * Software Foundation; either version 2.1 of the License, or (at your option) |
| 8 | * any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 12 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 13 | * details. |
| 14 | */ |
| 15 | --%> |
| 16 | |
| 17 | <%@ include file="/html/portlet/users_admin/init.jsp" %> |
| 18 | |
| 19 | <% |
| 20 | String toolbarItem = ParamUtil.getString(request, "toolbarItem", "browse"); |
| 21 | |
| 22 | String viewUsersRedirect = ParamUtil.getString(request, "viewUsersRedirect"); |
| 23 | String backURL = ParamUtil.getString(request, "backURL", viewUsersRedirect); |
| 24 | |
| 25 | int status = ParamUtil.getInteger(request, "status", WorkflowConstants.STATUS_APPROVED); |
| 26 | |
| 27 | String usersListView = ParamUtil.get(request, "usersListView", UserConstants.LIST_VIEW_TREE); |
| 28 | |
| 29 | PortletURL portletURL = renderResponse.createRenderURL(); |
| 30 | |
| 31 | portletURL.setParameter("struts_action", "/users_admin/view_users"); |
| 32 | portletURL.setParameter("usersListView", usersListView); |
| 33 | |
| 34 | if (Validator.isNotNull(viewUsersRedirect)) { |
| 35 | portletURL.setParameter("viewUsersRedirect", viewUsersRedirect); |
| 36 | } |
| 37 | |
| 38 | String portletURLString = portletURL.toString(); |
| 39 | |
| 40 | request.setAttribute("view.jsp-usersListView", usersListView); |
| 41 | |
| 42 | request.setAttribute("view.jsp-portletURL", portletURL); |
| 43 | %> |
| 44 | |
| 45 | <liferay-ui:error exception="<%= CompanyMaxUsersException.class %>" message="unable-to-activate-user-because-that-would-exceed-the-maximum-number-of-users-allowed" /> |
| 46 | <liferay-ui:error exception="<%= RequiredOrganizationException.class %>" message="you-cannot-delete-organizations-that-have-suborganizations-or-users" /> |
| 47 | <liferay-ui:error exception="<%= RequiredUserException.class %>" message="you-cannot-delete-or-deactivate-yourself" /> |
| 48 | |
| 49 | <aui:form action="<%= portletURLString %>" method="post" name="fm"> |
| 50 | <liferay-portlet:renderURLParams varImpl="portletURL" /> |
| 51 | <aui:input name="<%= Constants.CMD %>" type="hidden" /> |
| 52 | <aui:input name="toolbarItem" type="hidden" value="<%= toolbarItem %>" /> |
| 53 | <aui:input name="redirect" type="hidden" value="<%= portletURLString %>" /> |
| 54 | |
| 55 | <% |
| 56 | long organizationGroupId = 0; |
| 57 | |
| 58 | int inactiveUsersCount = 0; |
| 59 | int usersCount = 0; |
| 60 | |
| 61 | long organizationId = ParamUtil.getLong(request, "organizationId", OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID); |
| 62 | |
| 63 | Organization organization = null; |
| 64 | |
| 65 | if (organizationId != 0) { |
| 66 | organization = OrganizationServiceUtil.getOrganization(organizationId); |
| 67 | } |
| 68 | |
| 69 | if (organization != null) { |
| 70 | inactiveUsersCount = UserLocalServiceUtil.getOrganizationUsersCount(organizationId, WorkflowConstants.STATUS_INACTIVE); |
| 71 | usersCount = UserLocalServiceUtil.getOrganizationUsersCount(organizationId, WorkflowConstants.STATUS_APPROVED); |
| 72 | } |
| 73 | else { |
| 74 | LinkedHashMap<String, Object> userParams = new LinkedHashMap<String, Object>(); |
| 75 | |
| 76 | if (!usersListView.equals(UserConstants.LIST_VIEW_FLAT_USERS)) { |
| 77 | userParams.put("noOrganizations", Boolean.TRUE); |
| 78 | userParams.put("usersOrgsCount", 0); |
| 79 | } |
| 80 | |
| 81 | inactiveUsersCount = UserLocalServiceUtil.searchCount(company.getCompanyId(), null, WorkflowConstants.STATUS_INACTIVE, userParams); |
| 82 | usersCount = UserLocalServiceUtil.searchCount(company.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED, userParams); |
| 83 | } |
| 84 | %> |
| 85 | |
| 86 | <c:choose> |
| 87 | <c:when test="<%= usersListView.equals(UserConstants.LIST_VIEW_FLAT_ORGANIZATIONS) %>"> |
| 88 | <liferay-util:include page="/html/portlet/users_admin/view_flat_organizations.jsp" /> |
| 89 | </c:when> |
| 90 | <c:when test="<%= usersListView.equals(UserConstants.LIST_VIEW_FLAT_USERS) %>"> |
| 91 | |
| 92 | <% |
| 93 | boolean organizationContextView = false; |
| 94 | %> |
| 95 | |
| 96 | <%@ include file="/html/portlet/users_admin/view_flat_users.jspf" %> |
| 97 | </c:when> |
| 98 | <c:otherwise> |
| 99 | |
| 100 | <% |
| 101 | request.setAttribute("view.jsp-backURL", backURL); |
| 102 | request.setAttribute("view.jsp-inactiveUsersCount", inactiveUsersCount); |
| 103 | request.setAttribute("view.jsp-organization", organization); |
| 104 | request.setAttribute("view.jsp-organizationGroupId", organizationGroupId); |
| 105 | request.setAttribute("view.jsp-organizationId", organizationId); |
| 106 | request.setAttribute("view.jsp-portletURL", portletURL); |
| 107 | request.setAttribute("view.jsp-status", status); |
| 108 | request.setAttribute("view.jsp-toolbarItem", toolbarItem); |
| 109 | request.setAttribute("view.jsp-usersCount", usersCount); |
| 110 | request.setAttribute("view.jsp-usersListView", usersListView); |
| 111 | request.setAttribute("view.jsp-viewUsersRedirect", viewUsersRedirect); |
| 112 | %> |
| 113 | |
| 114 | <liferay-util:include page="/html/portlet/users_admin/view_tree.jsp" /> |
| 115 | </c:otherwise> |
| 116 | </c:choose> |
| 117 | </aui:form> |
| 118 | |
| 119 | <aui:script> |
| 120 | function <portlet:namespace />deleteOrganization(organizationId) { |
| 121 | <portlet:namespace />doDeleteOrganization('<%= Organization.class.getName() %>', organizationId); |
| 122 | } |
| 123 | |
| 124 | function <portlet:namespace />doDeleteOrganization(className, id) { |
| 125 | var ids = id; |
| 126 | |
| 127 | var status = <%= WorkflowConstants.STATUS_INACTIVE %>; |
| 128 | |
| 129 | <portlet:namespace />getUsersCount( |
| 130 | className, ids, status, |
| 131 | function(event, id, obj) { |
| 132 | var responseData = this.get('responseData'); |
| 133 | var count = parseInt(responseData); |
| 134 | |
| 135 | if (count > 0) { |
| 136 | status = <%= WorkflowConstants.STATUS_APPROVED %> |
| 137 | |
| 138 | <portlet:namespace />getUsersCount( |
| 139 | className, ids, status, |
| 140 | function(event, id, obj) { |
| 141 | responseData = this.get('responseData') |
| 142 | count = parseInt(responseData); |
| 143 | |
| 144 | if (count > 0) { |
| 145 | if (confirm('<%= UnicodeLanguageUtil.get(pageContext, "are-you-sure-you-want-to-delete-this") %>')) { |
| 146 | <portlet:namespace />doDeleteOrganizations(ids); |
| 147 | } |
| 148 | } |
| 149 | else { |
| 150 | var message = null; |
| 151 | |
| 152 | if (id && (id.toString().split(",").length > 1)) { |
| 153 | message = '<%= UnicodeLanguageUtil.get(pageContext, "one-or-more-organizations-are-associated-with-deactivated-users.-do-you-want-to-proceed-with-deleting-the-selected-organizations-by-automatically-unassociating-the-deactivated-users") %>'; |
| 154 | } |
| 155 | else { |
| 156 | message = '<%= UnicodeLanguageUtil.get(pageContext, "the-selected-organization-is-associated-with-deactivated-users.-do-you-want-to-proceed-with-deleting-the-selected-organization-by-automatically-unassociating-the-deactivated-users") %>'; |
| 157 | } |
| 158 | |
| 159 | if (confirm(message)) { |
| 160 | <portlet:namespace />doDeleteOrganizations(ids); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | ); |
| 165 | } |
| 166 | else { |
| 167 | if (confirm('<%= UnicodeLanguageUtil.get(pageContext, "are-you-sure-you-want-to-delete-this") %>')) { |
| 168 | <portlet:namespace />doDeleteOrganizations(ids); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | ); |
| 173 | } |
| 174 | |
| 175 | function <portlet:namespace />doDeleteOrganizations(organizationIds) { |
| 176 | document.<portlet:namespace />fm.method = "post"; |
| 177 | document.<portlet:namespace />fm.<portlet:namespace /><%= Constants.CMD %>.value = "<%= Constants.DELETE %>"; |
| 178 | document.<portlet:namespace />fm.<portlet:namespace />redirect.value = document.<portlet:namespace />fm.<portlet:namespace />organizationsRedirect.value; |
| 179 | document.<portlet:namespace />fm.<portlet:namespace />deleteOrganizationIds.value = organizationIds; |
| 180 | |
| 181 | submitForm(document.<portlet:namespace />fm, "<portlet:actionURL><portlet:param name="struts_action" value="/users_admin/edit_organization" /></portlet:actionURL>"); |
| 182 | } |
| 183 | |
| 184 | function <portlet:namespace />search() { |
| 185 | document.<portlet:namespace />fm.method = "post"; |
| 186 | document.<portlet:namespace />fm.<portlet:namespace /><%= Constants.CMD %>.value = ""; |
| 187 | |
| 188 | submitForm(document.<portlet:namespace />fm, '<%= portletURLString %>'); |
| 189 | } |
| 190 | |
| 191 | function <portlet:namespace />showUsers(status) { |
| 192 | |
| 193 | <% |
| 194 | PortletURL showUsersURL = renderResponse.createRenderURL(); |
| 195 | |
| 196 | showUsersURL.setParameter("struts_action", "/users_admin/view_users"); |
| 197 | showUsersURL.setParameter("usersListView", usersListView); |
| 198 | |
| 199 | long organizationId = ParamUtil.getLong(request, "organizationId", OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID); |
| 200 | |
| 201 | if (organizationId != OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID) { |
| 202 | showUsersURL.setParameter("organizationId", String.valueOf(organizationId)); |
| 203 | } |
| 204 | |
| 205 | if (Validator.isNotNull(viewUsersRedirect)) { |
| 206 | showUsersURL.setParameter("viewUsersRedirect", viewUsersRedirect); |
| 207 | } |
| 208 | %> |
| 209 | |
| 210 | location.href = Liferay.Util.addParams('<portlet:namespace />status=' + status.value, '<%= showUsersURL.toString() %>'); |
| 211 | } |
| 212 | |
| 213 | Liferay.provide( |
| 214 | window, |
| 215 | '<portlet:namespace />deleteOrganizations', |
| 216 | function() { |
| 217 | <portlet:namespace />doDeleteOrganization( |
| 218 | '<%= Organization.class.getName() %>', |
| 219 | Liferay.Util.listCheckedExcept(document.<portlet:namespace />fm, '<portlet:namespace />allRowIds') |
| 220 | ); |
| 221 | }, |
| 222 | ['liferay-util-list-fields'] |
| 223 | ); |
| 224 | |
| 225 | Liferay.provide( |
| 226 | window, |
| 227 | '<portlet:namespace />deleteUsers', |
| 228 | function(cmd) { |
| 229 | if (((cmd == "<%= Constants.DEACTIVATE %>") && confirm('<%= UnicodeLanguageUtil.get(pageContext, "are-you-sure-you-want-to-deactivate-the-selected-users") %>')) || ((cmd == "<%= Constants.DELETE %>") && confirm('<%= UnicodeLanguageUtil.get(pageContext, "are-you-sure-you-want-to-permanently-delete-the-selected-users") %>')) || (cmd == "<%= Constants.RESTORE %>")) { |
| 230 | document.<portlet:namespace />fm.method = "post"; |
| 231 | document.<portlet:namespace />fm.<portlet:namespace /><%= Constants.CMD %>.value = cmd; |
| 232 | document.<portlet:namespace />fm.<portlet:namespace />redirect.value = document.<portlet:namespace />fm.<portlet:namespace />usersRedirect.value; |
| 233 | document.<portlet:namespace />fm.<portlet:namespace />deleteUserIds.value = Liferay.Util.listCheckedExcept(document.<portlet:namespace />fm, '<portlet:namespace />allRowIds'); |
| 234 | |
| 235 | submitForm(document.<portlet:namespace />fm, "<portlet:actionURL><portlet:param name="struts_action" value="/users_admin/edit_user" /></portlet:actionURL>"); |
| 236 | } |
| 237 | }, |
| 238 | ['liferay-util-list-fields'] |
| 239 | ); |
| 240 | |
| 241 | Liferay.provide( |
| 242 | window, |
| 243 | '<portlet:namespace />getUsersCount', |
| 244 | function(className, ids, status, callback) { |
| 245 | var A = AUI(); |
| 246 | |
| 247 | A.io.request( |
| 248 | '<%= themeDisplay.getPathMain() %>/users_admin/get_users_count', |
| 249 | { |
| 250 | data: { |
| 251 | className: className, |
| 252 | ids: ids, |
| 253 | status: status |
| 254 | }, |
| 255 | on: { |
| 256 | success: callback |
| 257 | } |
| 258 | } |
| 259 | ); |
| 260 | }, |
| 261 | ['aui-io'] |
| 262 | ); |
| 263 | </aui:script> |