Unverified Commit 2f6984ab authored by Vipul Basapati's avatar Vipul Basapati Committed by GitHub

Merge pull request #198 from bvipul/develop

Vue component for Flash messages
parents 009599af 378a3831
...@@ -735,4 +735,16 @@ function _init() { ...@@ -735,4 +735,16 @@ function _init() {
} }
}); });
}; };
}(jQuery)); }(jQuery));
\ No newline at end of file
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.component('flash', require('../components/backend/Flash.vue'));
const app = new Vue({
el: '#app'
});
\ No newline at end of file
...@@ -50,4 +50,10 @@ window.axios.defaults.headers.common = { ...@@ -50,4 +50,10 @@ window.axios.defaults.headers.common = {
// var glob = require( 'glob' ) // var glob = require( 'glob' )
// , path = require( 'path' ); // , path = require( 'path' );
require('tinymce/tinymce'); require('tinymce/tinymce');
\ No newline at end of file
window.events = new Vue();
window.flash = function(message, type) {
window.events.$emit('flash', message, type);
}
\ No newline at end of file
<template>
<div :class="typeClass" v-show="show">
{{ body }}
</div>
</template>
<script>
export default {
props: ['message' , 'type'],
data() {
return {
body: '',
typeClass: '',
show: false
}
},
created() {
var context = this;
if(this.message && this.type) {
this.flash(this.message, this.type);
}
window.events.$on('flash', function(message, type) {
context.flash(message, type);
});
},
methods: {
flash(message, type) {
this.body = message;
this.typeClass = "alert alert-" + type;
this.show = true;
this.hide();
},
hide() {
setTimeout(() => {
this.show = false;
}, 3000);
}
}
}
</script>
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
<div class="loading" style="display:none"></div> <div class="loading" style="display:none"></div>
@include('includes.partials.logged-in-as') @include('includes.partials.logged-in-as')
<div class="wrapper"> <div class="wrapper" id="app">
@include('backend.includes.header') @include('backend.includes.header')
@include('backend.includes.sidebar-dynamic') @include('backend.includes.sidebar-dynamic')
......
@php
$message = '';
$type = '';
@endphp
@if ($errors->any()) @if ($errors->any())
<div class="alert alert-danger"> @php
@foreach ($errors->all() as $error) $type = 'danger';
{!! $error !!}<br/> @endphp
@endforeach @foreach ($errors->all() as $error)
</div> @php
$message .= $error . '<br/>';
@endphp
@endforeach
@elseif (session()->get('flash_success')) @elseif (session()->get('flash_success'))
<div class="alert alert-success"> @php
@if(is_array(json_decode(session()->get('flash_success'), true))) $type = 'success';
{!! implode('', session()->get('flash_success')->all(':message<br/>')) !!} @endphp
@else @if(is_array(json_decode(session()->get('flash_success'), true)))
{!! session()->get('flash_success') !!} @php
@endif $message = implode('', session()->get('flash_success')->all(':message<br/>'));
</div> @endphp
@else
@php
$message = session()->get('flash_success');
@endphp
@endif
@elseif (session()->get('flash_warning')) @elseif (session()->get('flash_warning'))
<div class="alert alert-warning"> @php
@if(is_array(json_decode(session()->get('flash_warning'), true))) $type = 'warning';
{!! implode('', session()->get('flash_warning')->all(':message<br/>')) !!} @endphp
@else @if(is_array(json_decode(session()->get('flash_warning'), true)))
{!! session()->get('flash_warning') !!} @php
@endif $message = implode('', session()->get('flash_warning')->all(':message<br/>'));
</div> @endphp
@else
@php
$message = session()->get('flash_warning');
@endphp
@endif
@elseif (session()->get('flash_info')) @elseif (session()->get('flash_info'))
<div class="alert alert-info"> @php
@if(is_array(json_decode(session()->get('flash_info'), true))) $type = 'info';
{!! implode('', session()->get('flash_info')->all(':message<br/>')) !!} @endphp
@else @if(is_array(json_decode(session()->get('flash_info'), true)))
{!! session()->get('flash_info') !!} @php
@endif $message = implode('', session()->get('flash_info')->all(':message<br/>'));
</div> @endphp
@else
@php
$message = session()->get('flash_info');
@endphp
@endif
@elseif (session()->get('flash_danger')) @elseif (session()->get('flash_danger'))
<div class="alert alert-danger"> @php
@if(is_array(json_decode(session()->get('flash_danger'), true))) $type = 'danger';
{!! implode('', session()->get('flash_danger')->all(':message<br/>')) !!} @endphp
@else @if(is_array(json_decode(session()->get('flash_danger'), true)))
{!! session()->get('flash_danger') !!} @php
@endif $message = implode('', session()->get('flash_danger')->all(':message<br/>'));
</div> @endphp
@else
@php
$message = session()->get('flash_danger');
@endphp
@endif
@elseif (session()->get('flash_message')) @elseif (session()->get('flash_message'))
<div class="alert alert-info"> @php
@if(is_array(json_decode(session()->get('flash_message'), true))) $type = 'info';
{!! implode('', session()->get('flash_message')->all(':message<br/>')) !!} @endphp
@else @if(is_array(json_decode(session()->get('flash_message'), true)))
{!! session()->get('flash_message') !!} @php
@endif $message = implode('', session()->get('flash_message')->all(':message<br/>'));
</div> @endphp
@endif @else
\ No newline at end of file @php
$message = session()->get('flash_message');
@endphp
@endif
@endif
<!-- Flash Message Vue component -->
<flash message="{!! $message !!}" type="{{ $type }}"></flash>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment