001/* 002 * Copyright 2010 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.cms.clientsideelement; 017 018import java.util.ArrayList; 019import java.util.List; 020import java.util.Map; 021 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024 025import org.ametys.cms.repository.Content; 026import org.ametys.core.right.RightManager.RightResult; 027import org.ametys.core.ui.ClientSideElementHelper; 028import org.ametys.plugins.repository.AmetysObjectResolver; 029 030/** 031 * This element creates a toggle button representing the lock state. 032 */ 033public class LockedContentClientSideElement extends AbstractContentClientSideElement 034{ 035 /** Repository content */ 036 protected AmetysObjectResolver _resolver; 037 038 @Override 039 public void service(ServiceManager smanager) throws ServiceException 040 { 041 super.service(smanager); 042 _resolver = (AmetysObjectResolver) smanager.lookup(AmetysObjectResolver.ROLE); 043 } 044 045 /** 046 * Get the context to check rights 047 * @param content The content 048 * @return the right context 049 */ 050 protected String getRightContext (Content content) 051 { 052 return "/cms"; 053 } 054 055 @Override 056 public List<Script> getScripts(boolean ignoreRights, Map<String, Object> contextParameters) 057 { 058 List<Script> scripts = super.getScripts(ignoreRights, contextParameters); 059 List<Script> clonedScripts = new ArrayList<>(); 060 boolean canUnlockAll = _rightManager.hasRight(_currentUserProvider.getUser(), "CMS_Rights_UnlockAll", "/cms") == RightResult.RIGHT_ALLOW; 061 for (Script script : scripts) 062 { 063 Script scriptClone = ClientSideElementHelper.cloneScript(script); 064 065 scriptClone.getParameters().put("canUnlockAll", canUnlockAll); 066 clonedScripts.add(scriptClone); 067 } 068 return clonedScripts; 069 } 070}