001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.taglib.ui;
016    
017    import com.liferay.portal.kernel.language.UnicodeLanguageUtil;
018    import com.liferay.portal.kernel.util.Http;
019    import com.liferay.portal.kernel.util.HttpUtil;
020    import com.liferay.portal.kernel.util.StringBundler;
021    import com.liferay.taglib.FileAvailabilityUtil;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Shuyang Zhou
026     */
027    public class IconDeactivateTag extends IconTag {
028    
029            @Override
030            protected String getPage() {
031                    if (FileAvailabilityUtil.isAvailable(servletContext, _PAGE)) {
032                            return _PAGE;
033                    }
034    
035                    String url = getUrl();
036    
037                    if (url.startsWith("javascript:")) {
038                            url = url.substring(11);
039                    }
040    
041                    if (url.startsWith(Http.HTTP_WITH_SLASH) ||
042                            url.startsWith(Http.HTTPS_WITH_SLASH)) {
043    
044                            url = "submitForm(document.hrefFm, '".concat(
045                                    HttpUtil.encodeURL(url)).concat("');");
046                    }
047    
048                    StringBundler sb = new StringBundler(5);
049    
050                    sb.append("javascript:if (confirm('");
051                    sb.append(
052                            UnicodeLanguageUtil.get(
053                                    request, "are-you-sure-you-want-to-deactivate-this"));
054                    sb.append("')) { ");
055                    sb.append(url);
056                    sb.append(" } else { self.focus(); }");
057    
058                    url = sb.toString();
059    
060                    setIconCssClass("icon-ban-circle");
061                    setMessage("deactivate");
062                    setUrl(url);
063    
064                    return super.getPage();
065            }
066    
067            private static final String _PAGE =
068                    "/html/taglib/ui/icon_deactivate/page.jsp";
069    
070    }