89 lines
3.1 KiB
JavaScript
89 lines
3.1 KiB
JavaScript
let m = require('mithril')
|
|
let fecha = require('fecha')
|
|
let category = require('../models/category')
|
|
let rome = require('../vendor/rome')
|
|
let SimpleMDE = require('../vendor/simplemde.min')
|
|
let post = require('../models/post')
|
|
|
|
var createPost = {
|
|
oninit: function() {
|
|
category.loadList()
|
|
post.current = {}
|
|
},
|
|
oncreate: function() {
|
|
clearInterval(window.intv)
|
|
var valid_at = rome(left, {
|
|
dateValidator: rome.val.beforeEq(right),
|
|
time: false,
|
|
inputFormat: 'YYYY/MM/DD',
|
|
required: true
|
|
})
|
|
var expired_at = rome(right, {
|
|
dateValidator: rome.val.afterEq(left),
|
|
time: false,
|
|
inputFormat: 'YYYY/MM/DD',
|
|
required: true
|
|
})
|
|
var simplemde = new SimpleMDE({ element: document.getElementById("smde") });
|
|
|
|
simplemde.codemirror.on('change', function() {
|
|
post.current.content = simplemde.value();
|
|
});
|
|
},
|
|
view: function() {
|
|
return m('main.documentation', m('section', [
|
|
m('h2', 'Tambah Pengumuman'),
|
|
m('form', {
|
|
onsubmit: function(e) {
|
|
e.preventDefault()
|
|
// do things
|
|
// console.log(post.current);
|
|
post.upload()
|
|
}
|
|
}, m('.flex.three.grow', [
|
|
m('.full.third-600', [
|
|
m('label', {for: 'category'}, 'Kategori:'),
|
|
m('select', {
|
|
name: 'category',
|
|
oninput: m.withAttr('value', function(value) {
|
|
post.current.category = value
|
|
})
|
|
}, [
|
|
m('option'),
|
|
category.list.map(function(cat) {
|
|
return m('option', {value: cat.id}, cat.category)
|
|
})
|
|
]),
|
|
m('br'),
|
|
m('label', {for: 'valid_at'}, 'Berlaku dari: '),
|
|
m('input#left', {
|
|
name: 'valid_at',
|
|
onfocusout: m.withAttr('value', function(value) {
|
|
post.current.valid_at = value
|
|
})
|
|
}),
|
|
m('br'),
|
|
m('label', {for: 'expired_at'}, 'Berlaku sampai: '),
|
|
m('input#right', {
|
|
name: 'expired_at',
|
|
onfocusout: m.withAttr('value', function(value) {
|
|
post.current.expired_at = value
|
|
})
|
|
})
|
|
]),
|
|
m('.full.two-third-600', [
|
|
m('label', {for: 'content'}, 'Konten: '),
|
|
m('textarea#smde', {name: 'content'})
|
|
]),
|
|
m('br'),
|
|
m('button.pseudo', {type: 'submit'}, [
|
|
m('i.fa.fa-check.fa-fw'),
|
|
m('span', {style: 'font-size: smaller'}, 'Unggah')
|
|
])
|
|
]))
|
|
]))
|
|
}
|
|
}
|
|
|
|
module.exports = createPost
|