Giter Club home page Giter Club logo

yii2-toastr's Introduction

Yii2 - Javascript Toast Notifications

Simple javascript toast notifications - Javascript library for non-blocking notifications. jQuery is required. The goal is to create a simple core library that can be customized and extended.

Latest Stable Version Total Downloads Latest Unstable Version License

Установка

Расширение устанавливается с помощью Composer интсрукция по установке Composer

Установка расширения через Composer, выполнить следующую команду:

composer require --prefer-dist lavrentiev/yii2-toastr

или (master)

composer require --prefer-dist lavrentiev/yii2-toastr "dev-master"

или внести изменения в секцию require в composer.json и выполнить composer update

"lavrentiev/yii2-toastr": "^2.0"

или (master)

"lavrentiev/yii2-toastr": "dev-master"

Уведомления Notification::widget()

alt text

use lavrentiev\widgets\toastr\Notification;

Notification::widget([
    'type' => 'info',
    'title' => 'Toast Notifications',
    'message' => 'Simple javascript toast notifications'
]);

Notification::widget([
    'type' => 'error',
    'title' => 'Toast Notifications',
    'message' => 'Simple javascript toast notifications'
]);

Notification::widget([
    'type' => 'success',
    'title' => 'Toast Notifications',
    'message' => 'Simple javascript toast notifications'
]);

Notification::widget([
    'type' => 'warning',
    'title' => 'Toast Notifications',
    'message' => 'Simple javascript toast notifications'
]);

Notification::widget([
    'type' => 'info',
    'message' => 'Simple javascript toast notifications'
]);

Notification::widget([
    'type' => 'error',
    'message' => 'Simple javascript toast notifications'
]);

Notification::widget([
    'type' => 'success',
    'message' => 'Simple javascript toast notifications'
]);

Notification::widget([
    'type' => 'warning',
    'message' => 'Simple javascript toast notifications'
]);

Также присутствует возможность настройки произвольного уведомления, по параметрам предусмотренным разработчиками Toastr by CodeSeven

alt text

Notification::widget([
    'type' => Notification::TYPE_ERROR,
    'title' => 'Toast Notifications',
    'message' => 'Simple javascript toast notifications',
    'options' => [
        "closeButton" => false,
        "debug" => false,
        "newestOnTop" => false,
        "progressBar" => false,
        "positionClass" => Notification::POSITION_TOP_RIGHT,
        "preventDuplicates" => false,
        "onclick" => null,
        "showDuration" => "300",
        "hideDuration" => "1000",
        "timeOut" => "5000",
        "extendedTimeOut" => "1000",
        "showEasing" => "swing",
        "hideEasing" => "linear",
        "showMethod" => "fadeIn",
        "hideMethod" => "fadeOut"
    ]
]);

Уведомления NotificationFlash::widget()

Подключение осуществляеться глобально допустим в layouts проекта.

<?= \lavrentiev\widgets\toastr\NotificationFlash::widget() ?>

Также присутствует возможность настройки уведомлений, по параметрам предусмотренным разработчиками Toastr by CodeSeven

<?= \lavrentiev\widgets\toastr\NotificationFlash::widget([
    'options' => [
        "closeButton" => true,
        "debug" => false,
        "newestOnTop" => false,
        "progressBar" => false,
        "positionClass" => \lavrentiev\widgets\toastr\NotificationFlash::POSITION_TOP_RIGHT,
        "preventDuplicates" => false,
        "onclick" => null,
        "showDuration" => "300",
        "hideDuration" => "1000",
        "timeOut" => "5000",
        "extendedTimeOut" => "1000",
        "showEasing" => "swing",
        "hideEasing" => "linear",
        "showMethod" => "fadeIn",
        "hideMethod" => "fadeOut"
    ]
]) ?>

alt text

\Yii::$app->session->setFlash('error', 'This is the message');
\Yii::$app->session->setFlash('success', 'This is the message');
\Yii::$app->session->setFlash('info', 'This is the message');
\Yii::$app->session->setFlash('warning', 'This is the message');

alt text

\Yii::$app->session->setFlash('warning', ['Error 1', 'Error 2', 'Error 3']);
\Yii::$app->session->setFlash('success', ['Error 1', 'Error 2', 'Error 3']);

Допустимые параметры

Параметр Значение по умолчанию Допустимые значения Описание
type info info, error, success, warning Тип уведомления
title --- --- Заголовок уведомления
message Simple javascript toast notifications --- Текст уведомления
options [] Подробней... Дополнительные опции

Допустимые константы типов:

TYPE_INFO = 'info'
TYPE_ERROR = 'error'
TYPE_SUCCESS = 'success'
TYPE_WARNING = 'warning'

Допустимые константы положения:

POSITION_TOP_RIGHT = 'toast-top-right';
POSITION_TOP_LEFT = 'toast-top-left';
POSITION_TOP_CENTER = 'toast-top-center';
POSITION_TOP_FULL_WIDTH = 'toast-top-full-width';

POSITION_BOTTOM_RIGHT = 'toast-bottom-right';
POSITION_BOTTOM_LEFT = 'toast-bottom-left';
POSITION_BOTTOM_CENTER = 'toast-bottom-center';
POSITION_BOTTOM_FULL_WIDTH = 'toast-bottom-full-width';

Демонстрация

Дополнительно

yii2-toastr's People

Contributors

gitter-badger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

yii2-toastr's Issues

Change opactiy

Default opacity of message is less than 1. How to change to 1

Set Both Title and Message

I can't see that how to set both title and message from controller in documentation.
\Yii::$app->session->setFlash('error', 'This is the title'); // This is title only
#Thankx

Виджет для отображения после Ajax (pjax) action

Подскажите, как можно отобразить сообщение после ajax (pjax) запроса?
Не хочется в каждом ajax - success прописывать js функции с toastr (вдруг захочу сменить на другой виджет jNoty например).

Может написать отдельный виджет, который будет глобально отлавливать события Ajax
http://api.jquery.com/category/ajax/global-ajax-event-handlers/

после чего получать yii-флеш сообщения, переводить их в toastr и отображать.

Error: yii\i18n\PhpMessageSource::loadFallbackMessages

Дебагер валит ошибку.

The message file for category 'app' does not exist: /home/_/www/messages/ru-RU/app.php Fallback file does not exist as well: /home/__/www/messages/ru/app.php
/home/
__/www/vendor/lavrentiev/yii2-toastr/src/Notification.php (49)
/home/
__/www/widgets/Alert.php (13)
/home/
_**/www/views/layouts/main.php (14)

Ошибка в NotificationFlash::widget()

При вызове метода \Yii::$app->session->setFlash('error', 'This is the message'); срабатывает исключение, поскольку в классе lavrentiev\widgets\toastr\NotificationFlash при вызове статического метода Notification::widget(['type' => $type, 'message' => $message, 'options' => ($this->options) ? Json::decode($this->options) : []]); если $this->options пустой, то третьим параметром передается тип данных array, а не string
Чтобы исключение не срабатывало, необходимо третьим параметром передавать по умолчанию пустой массив данных в формате JSON, например:

Notification::widget(['type' => $type, 'message' => $message, 'options' => ($this->options) ? Json::decode($this->options) : '[]']);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.