View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.ui.commons;
20  
21  import com.googlecode.wicket.jquery.core.Options;
22  import com.googlecode.wicket.kendo.ui.widget.notification.Notification;
23  import com.googlecode.wicket.kendo.ui.widget.notification.NotificationBehavior;
24  import java.io.Serializable;
25  import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
26  
27  public class StyledNotificationBehavior extends NotificationBehavior {
28  
29      private static final long serialVersionUID = -3985689554352173472L;
30  
31      private static final String AUTOHIDEAFTER_GOOD = "3000";
32  
33      private static final String AUTOHIDEAFTER_BAD = "0";
34  
35      public StyledNotificationBehavior(final String selector, final Options options) {
36          super(selector, options);
37      }
38  
39      @Override
40      public void show(final IPartialPageRequestHandler handler, final Serializable message, final String level) {
41          if (handler != null) {
42              handler.appendJavaScript(jQueryShow(this.format(String.valueOf(message), level), this.widget(), level));
43          }
44      }
45  
46      public static String jQueryShow(final CharSequence message, final String widget, final String level) {
47          return String.format("%s.options.autoHideAfter = %s; %s.show( { message: '%s' } , '%s');",
48                  widget,
49                  Notification.SUCCESS.equalsIgnoreCase(level) || Notification.INFO.equalsIgnoreCase(level)
50                  ? AUTOHIDEAFTER_GOOD : AUTOHIDEAFTER_BAD,
51                  widget,
52                  message,
53                  level.toLowerCase());
54      }
55  }