|
Lift Framework example source code file (Msgs.scala)
The Lift Framework Msgs.scala source code/* * Copyright 2007-2011 WorldWide Conferencing, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.liftweb package builtin package snippet import net.liftweb.http.{DispatchSnippet,LiftRules,NoticeType,S,SessionVar} import scala.xml._ import net.liftweb.util.Helpers._ import net.liftweb.http.js._ import JsCmds._ import net.liftweb.common.{Box, Full, Empty} /** * This built in snippet renders messages (Errors, Warnings, Notices) in a <i>div. * Typically it is used in templates as a place holder for any messages that are <b>not associated with an ID. * Setting the attribute <i>showAll to true will render all messages, with and without an ID. * This will lead to duplicate messages if additionally the <i>Msg built in snippet is used to show * messages associated with an ID. * * E.g. (child nodes are optional) * <pre name="code" class="xml"> * <lift:Msgs showAll="false"> * <lift:error_msg class="errorBox" >Error! The details are:</lift:error_msg> * <lift:warning_msg>Whoops, I had a problem:</lift:warning_msg> * <lift:warning_class>warningBox</lift:warning_class> * <lift:notice_msg>Note:</lift:notice_msg> * <lift:notice_class>noticeBox</lift:notice_class> * </lift:snippet> * </pre> * * JavaScript fadeout and effects for the three types of notices (Errors, Warnings and Notices) can * be configured via LiftRules.noticesAutoFadeOut and LiftRules.noticesEffects. Notices for individual * elements based on id can be rendered using the <lift:msg/> tag. * * @see net.liftweb.builtin.snippet.Msg * @see net.liftweb.http.LiftRules#noticesAutoFadeOut * @see net.liftweb.http.LiftRules#noticesEffects */ object Msgs extends DispatchSnippet { // Dispatch to the render method no matter how we're called def dispatch: DispatchIt = { case _ => render } /** * This method performs extraction of custom formatting and then * renders the current notices. * * @see #renderNotices() */ def render(styles: NodeSeq): NodeSeq = { // Capture the value for later AJAX updates ShowAll(toBoolean(S.attr("showAll") or S.attr("showall"))) // Extract user-specified titles and CSS classes for later use List((NoticeType.Error, MsgsErrorMeta), (NoticeType.Warning, MsgsWarningMeta), (NoticeType.Notice, MsgsNoticeMeta)).foreach { case (noticeType, ajaxStorage) => { // Extract the title if provided, or default to none. Allow for XML nodes // so that people can localize, etc. val title : NodeSeq = (styles \\ noticeType.titleTag). filter(_.prefix == "lift").flatMap(_.child) // Extract any provided classes for the messages val cssClasses = ((styles \\ noticeType.styleTag) ++ (styles \\ noticeType.titleTag \\ "@class")). toList.map(_.text.trim) match { case Nil => Empty case classes => Full(classes.mkString(" ")) } // Save the settings for AJAX usage ajaxStorage(Full(AjaxMessageMeta(title,cssClasses))) } } // Delegate the actual rendering to a shared method so that we don't // duplicate code for the AJAX pipeline (<div>{renderNotices()}
Other Lift Framework examples (source code examples)Here is a short list of links related to this Lift Framework Msgs.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.