Added custom notification
This commit is contained in:
23
assets/js/components/label.js
Normal file
23
assets/js/components/label.js
Normal file
@@ -0,0 +1,23 @@
|
||||
let m = require('mithril')
|
||||
let fadeOutEffect = require('../others/fadeOutEffect')
|
||||
|
||||
module.exports = {
|
||||
view: function() {
|
||||
return m('.label.top', {
|
||||
style: {
|
||||
position: 'fixed',
|
||||
top: '15px',
|
||||
fontSize: 'small',
|
||||
margin: '0 35%',
|
||||
left: '0',
|
||||
right: '0',
|
||||
overflowY: 'auto',
|
||||
maxWidth: '100%',
|
||||
maxHeight: '100%'
|
||||
},
|
||||
onclick: function() {
|
||||
fadeOutEffect.fade(this)
|
||||
}
|
||||
}, window.message)
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ var listAdmin = {
|
||||
m('em', [
|
||||
pengumuman.creatorName,
|
||||
' - ',
|
||||
fecha.format(fecha.parse(pengumuman.valid_at, 'YYYY-MM-DD H:i:s'), 'DD/MM/YYYY')
|
||||
fecha.format(fecha.parse(pengumuman.created_at, 'YYYY-MM-DD H:i:s'), 'DD/MM/YYYY')
|
||||
])
|
||||
]),
|
||||
m('span.stack', {style:'color:' + pengumuman.foreground + '; overflow-y: auto;'}, m.trust(marked(pengumuman.content))),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
let m = require('mithril')
|
||||
let _ = require('lodash')
|
||||
let user = require('../models/user')
|
||||
let fadeOutEffect = require('../others/fadeOutEffect')
|
||||
|
||||
var login = {
|
||||
view: function() {
|
||||
@@ -18,7 +20,8 @@ var login = {
|
||||
maxlength: '25',
|
||||
autocomplete: 'off',
|
||||
oninput: m.withAttr('value', function(value) {user.current.username = value}),
|
||||
value: user.current.username
|
||||
value: user.current.username,
|
||||
required: 'required'
|
||||
})),
|
||||
m('.fourth-600.full', m('input', {
|
||||
type: 'password',
|
||||
@@ -27,18 +30,32 @@ var login = {
|
||||
oninput: m.withAttr('value', function(value) {
|
||||
user.current.password = value
|
||||
}),
|
||||
value: user.current.password
|
||||
value: user.current.password,
|
||||
required: 'required'
|
||||
})),
|
||||
m('.fourth-600.none'),
|
||||
m('.fourth-600.none'),
|
||||
m('div', m('button.half-600.full.pseudo', {
|
||||
m('.half-600.full', m('button.full.pseudo', {
|
||||
type: 'submit'
|
||||
}, [
|
||||
m('i.fa.fa-check.fa-fw'),
|
||||
m('span', {
|
||||
style: 'font-size:smaller;'
|
||||
}, 'Masuk')
|
||||
]))
|
||||
])),
|
||||
m('.fourth-600.none'),
|
||||
m('.fourth-600.none'),
|
||||
_.isNil(window.message) == false ? [
|
||||
m('.half-600.full.label.error', {
|
||||
style: 'margin: 0; font-size: smaller;',
|
||||
onclick: function() {
|
||||
window.message = null
|
||||
}
|
||||
}, window.message),
|
||||
m('.fourth-600.none'),
|
||||
m('.fourth-600.none')
|
||||
]
|
||||
: null
|
||||
])
|
||||
]))
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ var registerUser = {
|
||||
autocomplete: 'off',
|
||||
oninput: m.withAttr('value', function(value) {
|
||||
user.current.full_name = value
|
||||
})
|
||||
}),
|
||||
required: 'required'
|
||||
})),
|
||||
m('.fourth-600.full', m('input', {
|
||||
type: 'text',
|
||||
@@ -28,7 +29,8 @@ var registerUser = {
|
||||
autocomplete: 'off',
|
||||
oninput: m.withAttr('value', function(value) {
|
||||
user.current.username = value
|
||||
})
|
||||
}),
|
||||
required: 'required'
|
||||
})),
|
||||
m('.fourth-600.full', m('input', {
|
||||
type: 'password',
|
||||
@@ -36,7 +38,8 @@ var registerUser = {
|
||||
placeholder: 'Password',
|
||||
oninput: m.withAttr('value', function(value) {
|
||||
user.current.password = value
|
||||
})
|
||||
}),
|
||||
required: 'required'
|
||||
})),
|
||||
m('.fourth-600.none'),
|
||||
m('div', m('button.pseudo.three-fourth-600.full', {
|
||||
|
||||
@@ -10,6 +10,7 @@ let createPost = require('./components/createPost')
|
||||
let editPost = require('./components/editPost')
|
||||
let cookie = require('./others/cookie')
|
||||
let idleTimeout = require('./others/idleTimeout')
|
||||
let label = require('./components/label')
|
||||
|
||||
require('../css/index.css')
|
||||
|
||||
@@ -24,13 +25,19 @@ if (page == '') {
|
||||
})
|
||||
} else {
|
||||
m.route(root, '', {
|
||||
'': { view: function() { return m('span', [
|
||||
'': { view: function() { return m('span',
|
||||
window.message || window.message != null ?
|
||||
m(label) : null,
|
||||
[
|
||||
m(nav),
|
||||
m(showPost, { 'status': 3 })
|
||||
]) } },
|
||||
'/kategori': {
|
||||
view: function() {
|
||||
return m('span', [
|
||||
return m('span',
|
||||
window.message || window.message != null ?
|
||||
m(label) : null,
|
||||
[
|
||||
m(nav),
|
||||
m(createCategory, { 'id': 0 })
|
||||
])
|
||||
@@ -38,44 +45,86 @@ if (page == '') {
|
||||
},
|
||||
'/kategori/:id': {
|
||||
view: function(vnode) {
|
||||
return m('span', [
|
||||
return m('span',
|
||||
window.message || window.message != null ?
|
||||
m(label) : null,
|
||||
[
|
||||
m(nav),
|
||||
m(editCategory, { 'id': vnode.attrs.id })
|
||||
])
|
||||
}
|
||||
},
|
||||
'/register': { view: function() { return m('span'), [
|
||||
m(nav),
|
||||
cookie.get('signal') == 1 ? m(registerUser) : null
|
||||
] }},
|
||||
'/posts': { view: function() { return m('span', [
|
||||
m(nav),
|
||||
m(showPost, { 'status': 3 })
|
||||
]) } },
|
||||
'/register': { view: function() {
|
||||
return m('span',
|
||||
window.message || window.message != null ?
|
||||
m(label) : null,
|
||||
[
|
||||
m(nav),
|
||||
cookie.get('signal') == 1 ? m(registerUser) : null
|
||||
])
|
||||
}
|
||||
},
|
||||
'/posts': { view: function() {
|
||||
return m('span',
|
||||
window.message || window.message != null ?
|
||||
m(label) : null,
|
||||
[
|
||||
m(nav),
|
||||
m(showPost, { 'status': 3 })
|
||||
])
|
||||
}
|
||||
},
|
||||
'/posts/edit/:id': {
|
||||
view: function(vnode) {
|
||||
return m('span', [
|
||||
return m('span',
|
||||
window.message || window.message != null ?
|
||||
m(label) : null,
|
||||
[
|
||||
m(nav),
|
||||
m(editPost, { 'id': vnode.attrs.id })
|
||||
])
|
||||
}
|
||||
},
|
||||
'/posts/active': { view: function() { return m('span', [
|
||||
m(nav),
|
||||
m(showPost, { 'status': 1 })
|
||||
]) } },
|
||||
'/posts/soon': { view: function() { return m('span', [
|
||||
m(nav),
|
||||
m(showPost, { 'status': 2 })
|
||||
]) } },
|
||||
'/posts/inactive': { view: function() { return m('span', [
|
||||
m(nav),
|
||||
m(showPost, { 'status': 0 })
|
||||
]) } },
|
||||
'/posts/entry': { view: function() { return m('span', [
|
||||
m(nav),
|
||||
m(createPost)
|
||||
])} }
|
||||
'/posts/active': { view: function() {
|
||||
return m('span',
|
||||
window.message || window.message != null ?
|
||||
m(label) : null,
|
||||
[
|
||||
m(nav),
|
||||
m(showPost, { 'status': 1 })
|
||||
])
|
||||
}
|
||||
},
|
||||
'/posts/soon': { view: function() {
|
||||
return m('span',
|
||||
window.message || window.message != null ?
|
||||
m(label) : null,
|
||||
[
|
||||
m(nav),
|
||||
m(showPost, { 'status': 2 })
|
||||
])
|
||||
}
|
||||
},
|
||||
'/posts/inactive': { view: function() {
|
||||
return m('span',
|
||||
window.message || window.message != null ?
|
||||
m(label) : null,
|
||||
[
|
||||
m(nav),
|
||||
m(showPost, { 'status': 0 })
|
||||
])
|
||||
}
|
||||
},
|
||||
'/posts/entry': { view: function() {
|
||||
return m('span',
|
||||
window.message || window.message != null ?
|
||||
m(label) : null,
|
||||
[
|
||||
m(nav),
|
||||
m(createPost)
|
||||
])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
idleTimeout.setup();
|
||||
|
||||
@@ -41,13 +41,13 @@ var category = {
|
||||
headers: {'x-query': window.location.search}
|
||||
})
|
||||
.then(function(result) {
|
||||
console.log(result)
|
||||
category.current = {}
|
||||
if (result.status == true) {
|
||||
m.route.set('/kategori')
|
||||
} else if (result.status == 401) {
|
||||
user.logout();
|
||||
}
|
||||
window.message = result.message
|
||||
})
|
||||
},
|
||||
entry: function() {
|
||||
@@ -59,20 +59,24 @@ var category = {
|
||||
headers: {'x-query': window.location.search}
|
||||
})
|
||||
.then(function(result) {
|
||||
console.log(result);
|
||||
if (result.status == true) {
|
||||
category.loadList()
|
||||
} else if (result.status == 401) {
|
||||
user.logout()
|
||||
}
|
||||
window.message = result.message
|
||||
})
|
||||
},
|
||||
toggleStatus: function(id){
|
||||
category.current = _.find(category.list, function(o) { return o.id == id })
|
||||
if (category.current.posts == 0) {
|
||||
category.current.status == 1 ? category.current.status = 0 : category.current.status = 1
|
||||
category.save()
|
||||
} else {
|
||||
category.current = {}
|
||||
m.redraw()
|
||||
window.message = 'Kategori memiliki pengumuman aktif'
|
||||
}
|
||||
category.save()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,11 +47,10 @@ var post = {
|
||||
.then(function(response) {
|
||||
if (response.status) {
|
||||
m.route.set(response.route_to)
|
||||
} else {
|
||||
console.log(response);
|
||||
}
|
||||
post.current = {}
|
||||
post.loading = false
|
||||
window.message = response.message
|
||||
})
|
||||
},
|
||||
save: function() {
|
||||
@@ -61,16 +60,15 @@ var post = {
|
||||
url: '/posts/put/' + window.location.search,
|
||||
data: post.current,
|
||||
withCredentials: true,
|
||||
headers: {client: 'api'}
|
||||
headers: {client: 'api', 'x-query': window.location.search}
|
||||
})
|
||||
.then(function(response) {
|
||||
post.current = {}
|
||||
if (response.status) {
|
||||
m.route.set(response.route_to)
|
||||
} else {
|
||||
console.log(response);
|
||||
}
|
||||
post.loading = false;
|
||||
window.message = response.message
|
||||
})
|
||||
},
|
||||
toggleStatus: function(id) {
|
||||
@@ -88,21 +86,23 @@ var post = {
|
||||
|
||||
post.current = _.find(post.list, function(o) { return o.id == id })
|
||||
// console.log(new Date(post.current.valid_at) > new Date());
|
||||
if (new Date(post.current.valid_at) > new Date()) {
|
||||
status = 2
|
||||
// console.log(post.current.id, 'soon');
|
||||
} else if (new Date(post.current.valid_at) <= new Date()) {
|
||||
if (new Date(post.current.expired_at) < new Date()) {
|
||||
status = 0
|
||||
// console.log(post.current.id, 'expired');
|
||||
} else {
|
||||
status = 1
|
||||
// console.log(post.current.id, 'active');
|
||||
if (post.current.status != 0) {
|
||||
if (new Date(post.current.valid_at) > new Date()) {
|
||||
status = 2
|
||||
// console.log(post.current.id, 'soon');
|
||||
} else if (new Date(post.current.valid_at) <= new Date()) {
|
||||
if (new Date(post.current.expired_at) < new Date()) {
|
||||
status = 0
|
||||
// console.log(post.current.id, 'expired');
|
||||
} else {
|
||||
status = 1
|
||||
// console.log(post.current.id, 'active');
|
||||
}
|
||||
}
|
||||
if (post.current.status != status) {
|
||||
post.current.status = status
|
||||
post.save()
|
||||
}
|
||||
}
|
||||
if (post.current.status != status) {
|
||||
post.current.status = status
|
||||
post.save()
|
||||
}
|
||||
// console.log(post.current);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,8 @@ var user = {
|
||||
.then(function(response) {
|
||||
if (response.status == true) {
|
||||
window.location = response.redirect_to
|
||||
} else {
|
||||
console.log(response.status);
|
||||
}
|
||||
window.message = response.message
|
||||
})
|
||||
},
|
||||
logout: function() {
|
||||
@@ -26,26 +25,26 @@ var user = {
|
||||
headers: {client: 'api', 'x-query': window.location.search}
|
||||
})
|
||||
.then(function(response) {
|
||||
console.log(response);
|
||||
if (response.status) {
|
||||
window.location = response.redirect_to
|
||||
}
|
||||
window.message = response.message
|
||||
})
|
||||
},
|
||||
register: function() {
|
||||
return m.request({
|
||||
method: 'POST',
|
||||
url: '/post',
|
||||
url: '/post/' + window.location.search,
|
||||
data: user.current,
|
||||
withCredentials: true,
|
||||
headers: {client: 'api', 'x-query': window.location.search}
|
||||
})
|
||||
.then(function(response) {
|
||||
console.log(response);
|
||||
if (response.status == true) {
|
||||
m.route.set(response.route_to)
|
||||
} else {
|
||||
console.log(response);
|
||||
}
|
||||
window.message = response.message
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
18
assets/js/others/fadeOutEffect.js
Normal file
18
assets/js/others/fadeOutEffect.js
Normal file
@@ -0,0 +1,18 @@
|
||||
module.exports = {
|
||||
fade: function(target) {
|
||||
// var fadeTarget = document.getElementById(target);
|
||||
var fadeTarget = target
|
||||
var fadeEffect = setInterval(function () {
|
||||
if (!fadeTarget.style.opacity) {
|
||||
fadeTarget.style.opacity = 1;
|
||||
}
|
||||
if (fadeTarget.style.opacity < 0.1) {
|
||||
clearInterval(fadeEffect);
|
||||
fadeTarget.remove();
|
||||
window.message = null;
|
||||
} else {
|
||||
fadeTarget.style.opacity -= 0.1;
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user