James Moger
2012-10-22 eba89539a29deba954035056437279088c3e047b
commit | author | age
f13c4c 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
bc10f9 16 package com.gitblit.wicket.panels;
JM 17
9adf62 18 import java.util.ResourceBundle;
bc10f9 19 import java.util.TimeZone;
JM 20
8a2e9c 21 import org.apache.wicket.AttributeModifier;
98ce17 22 import org.apache.wicket.Component;
bc10f9 23 import org.apache.wicket.markup.html.panel.Panel;
8a2e9c 24 import org.apache.wicket.model.Model;
bc10f9 25
33d8d8 26 import com.gitblit.Constants;
87cc1e 27 import com.gitblit.GitBlit;
155bf7 28 import com.gitblit.Keys;
9adf62 29 import com.gitblit.utils.TimeUtils;
bc10f9 30 import com.gitblit.wicket.GitBlitWebSession;
98ce17 31 import com.gitblit.wicket.WicketUtils;
bc10f9 32
JM 33 public abstract class BasePanel extends Panel {
34
35     private static final long serialVersionUID = 1L;
9adf62 36     
JM 37     private transient TimeUtils timeUtils;
bc10f9 38
JM 39     public BasePanel(String wicketId) {
40         super(wicketId);
41     }
42
43     protected TimeZone getTimeZone() {
2a7306 44         return GitBlit.getBoolean(Keys.web.useClientTimezone, false) ? GitBlitWebSession.get()
6c6e7d 45                 .getTimezone() : GitBlit.getTimezone();
bc10f9 46     }
9adf62 47     
JM 48     protected TimeUtils getTimeUtils() {
49         if (timeUtils == null) {
50             ResourceBundle bundle;        
51             try {
52                 bundle = ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp", GitBlitWebSession.get().getLocale());
53             } catch (Throwable t) {
54                 bundle = ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp");
55             }
56             timeUtils = new TimeUtils(bundle);
57         }
58         return timeUtils;
59     }
98ce17 60
33d8d8 61     protected void setPersonSearchTooltip(Component component, String value, Constants.SearchType searchType) {
JM 62         if (searchType.equals(Constants.SearchType.AUTHOR)) {
1e8390 63             WicketUtils.setHtmlTooltip(component, getString("gb.searchForAuthor") + " " + value);
33d8d8 64         } else if (searchType.equals(Constants.SearchType.COMMITTER)) {
1e8390 65             WicketUtils.setHtmlTooltip(component, getString("gb.searchForCommitter") + " " + value);
98ce17 66         }
JM 67     }
8a2e9c 68
2a7306 69     public static class JavascriptEventConfirmation extends AttributeModifier {
8a2e9c 70
JM 71         private static final long serialVersionUID = 1L;
72
73         public JavascriptEventConfirmation(String event, String msg) {
74             super(event, true, new Model<String>(msg));
75         }
76
77         protected String newValue(final String currentValue, final String replacementValue) {
2a7306 78             String prefix = "var conf = confirm('" + replacementValue + "'); "
JM 79                     + "if (!conf) return false; ";
8a2e9c 80             String result = prefix;
JM 81             if (currentValue != null) {
82                 result = prefix + currentValue;
83             }
84             return result;
85         }
86     }
831469 87
JM 88     public static class JavascriptTextPrompt extends AttributeModifier {
89
90         private static final long serialVersionUID = 1L;
91
82df52 92         private String initialValue = "";
JM 93         
94         public JavascriptTextPrompt(String event, String msg, String value) {
831469 95             super(event, true, new Model<String>(msg));
82df52 96             initialValue = value;
831469 97         }
JM 98
99         protected String newValue(final String currentValue, final String message) {
100             String result = "var userText = prompt('" + message + "','"
82df52 101                     + (initialValue == null ? "" : initialValue) + "'); " + "return userText; ";
831469 102             return result;
JM 103         }
104     }
bc10f9 105 }