You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BasePanel.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  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. */
  16. package com.gitblit.wicket.panels;
  17. import java.util.ResourceBundle;
  18. import java.util.TimeZone;
  19. import org.apache.wicket.AttributeModifier;
  20. import org.apache.wicket.Component;
  21. import org.apache.wicket.markup.html.panel.Panel;
  22. import org.apache.wicket.model.Model;
  23. import com.gitblit.Constants;
  24. import com.gitblit.GitBlit;
  25. import com.gitblit.Keys;
  26. import com.gitblit.utils.TimeUtils;
  27. import com.gitblit.wicket.GitBlitWebSession;
  28. import com.gitblit.wicket.WicketUtils;
  29. public abstract class BasePanel extends Panel {
  30. private static final long serialVersionUID = 1L;
  31. private transient TimeUtils timeUtils;
  32. public BasePanel(String wicketId) {
  33. super(wicketId);
  34. }
  35. protected TimeZone getTimeZone() {
  36. return GitBlit.getBoolean(Keys.web.useClientTimezone, false) ? GitBlitWebSession.get()
  37. .getTimezone() : GitBlit.getTimezone();
  38. }
  39. protected TimeUtils getTimeUtils() {
  40. if (timeUtils == null) {
  41. ResourceBundle bundle;
  42. try {
  43. bundle = ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp", GitBlitWebSession.get().getLocale());
  44. } catch (Throwable t) {
  45. bundle = ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp");
  46. }
  47. timeUtils = new TimeUtils(bundle);
  48. }
  49. return timeUtils;
  50. }
  51. protected void setPersonSearchTooltip(Component component, String value, Constants.SearchType searchType) {
  52. if (searchType.equals(Constants.SearchType.AUTHOR)) {
  53. WicketUtils.setHtmlTooltip(component, getString("gb.searchForAuthor") + " " + value);
  54. } else if (searchType.equals(Constants.SearchType.COMMITTER)) {
  55. WicketUtils.setHtmlTooltip(component, getString("gb.searchForCommitter") + " " + value);
  56. }
  57. }
  58. public static class JavascriptEventConfirmation extends AttributeModifier {
  59. private static final long serialVersionUID = 1L;
  60. public JavascriptEventConfirmation(String event, String msg) {
  61. super(event, true, new Model<String>(msg));
  62. }
  63. protected String newValue(final String currentValue, final String replacementValue) {
  64. String prefix = "var conf = confirm('" + replacementValue + "'); "
  65. + "if (!conf) return false; ";
  66. String result = prefix;
  67. if (currentValue != null) {
  68. result = prefix + currentValue;
  69. }
  70. return result;
  71. }
  72. }
  73. public static class JavascriptTextPrompt extends AttributeModifier {
  74. private static final long serialVersionUID = 1L;
  75. private String initialValue = "";
  76. public JavascriptTextPrompt(String event, String msg, String value) {
  77. super(event, true, new Model<String>(msg));
  78. initialValue = value;
  79. }
  80. protected String newValue(final String currentValue, final String message) {
  81. String result = "var userText = prompt('" + message + "','"
  82. + (initialValue == null ? "" : initialValue) + "'); " + "return userText; ";
  83. return result;
  84. }
  85. }
  86. }