MiniDigger/Hangar

View on GitHub
orePlayCommon/app/views/utils/alert.scala.html

Summary

Maintainability
Test Coverage
@(alertType: String)(implicit flash: Flash, messages: Messages)

@bootstrapNames = @{
    Map(
        "error" -> "alert-danger",
        "success" -> "alert-success",
        "info" -> "alert-info",
        "warning" -> "alert-warning"
    )
}

@normalAlert = {
@flash.get(alertType).map { message =>
    @(messages(message))
}
}

@numAlert = {
@flash.get(s"$alertType-num").map { num =>
    <ul>
        @for(i <- 0 until num.toInt; msg <- flash.get(s"$alertType-$i").toSeq) {
            <li>
                @messages(msg)
            </li>
        }
    </ul>
}
}

@if(flash.get(alertType).isDefined || flash.get(s"$alertType-num").isDefined) {
    <div class="alert alert-fade @bootstrapNames(alertType) alert-dismissable"
    role="alert" style="display: none;">
        <button type="button" class="close" data-dismiss="alert" aria-label="@messages("general.close")">
            <span aria-hidden="true">&times;</span>
        </button>

        @normalAlert
        @numAlert
    </div>
}