From 766fe4425d71e510978d63572ae00afe8d8833c2 Mon Sep 17 00:00:00 2001 From: Gregorio Chiko Putra Date: Fri, 27 Oct 2017 14:34:55 +0700 Subject: [PATCH] Fixed edit entry post issue --- App/Controllers/Api.php | 4 ++-- App/Controllers/Home.php | 2 +- App/Controllers/Posts.php | 8 ++++++-- assets/js/components/createPost.js | 4 ++-- assets/js/components/editPost.js | 28 +++++++++++++++++----------- assets/js/components/listAdmin.js | 8 ++++---- assets/js/models/post.js | 4 ++-- 7 files changed, 34 insertions(+), 24 deletions(-) diff --git a/App/Controllers/Api.php b/App/Controllers/Api.php index 77da252..7bea2fa 100644 --- a/App/Controllers/Api.php +++ b/App/Controllers/Api.php @@ -83,7 +83,7 @@ class Api $put['status'] = true; $put['data'] = $update; $put['count'] = count($put['data']); - $put['message'] = ucfirst($table) . ' berhasil diubah'; + $put['message'] = 'Proses berhasil'; } header('Content-Type: application/json'); @@ -107,7 +107,7 @@ class Api $post['status'] = true; $post['data'] = $entry; $post['count'] = count($post['data']); - $post['message'] = ucfirst($table) . ' berhasil ditambahkan'; + $post['message'] = 'Proses berhasil'; } header('Content-Type: application/json'); diff --git a/App/Controllers/Home.php b/App/Controllers/Home.php index a7c127e..00dff65 100644 --- a/App/Controllers/Home.php +++ b/App/Controllers/Home.php @@ -192,7 +192,7 @@ class Home echo json_encode([ 'status' => true, 'route_to' => '', - 'message' => 'User berhasil ditambahkan' + 'message' => 'Proses berhasil' ]);die(); } Session::flash('info', 'Registrasi berhasil'); diff --git a/App/Controllers/Posts.php b/App/Controllers/Posts.php index 05af765..9538140 100644 --- a/App/Controllers/Posts.php +++ b/App/Controllers/Posts.php @@ -338,7 +338,7 @@ class Posts } $post['status'] = true; $post['route_to'] = ''; - $post['message'] = 'Pengumuman berhasil ditambahkan'; + $post['message'] = 'Proses berhasil'; if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') { echo json_encode($post); die(); @@ -412,10 +412,14 @@ class Posts $length = strlen($args['content']); $args['delay'] = $length * 84; + $d = new \DateTime(); + $d = $d->format('Y-m-d H:i:s'); + $args['edited_at'] = $d; + if ($this->model->update($args, $id)) { $update['status'] = true; $update['route_to'] = ''; - $update['message'] = 'Pengumuman berhasil diubah'; + $update['message'] = 'Proses berhasil'; if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') { echo json_encode($update); die(); diff --git a/assets/js/components/createPost.js b/assets/js/components/createPost.js index 3c83132..c9dc837 100644 --- a/assets/js/components/createPost.js +++ b/assets/js/components/createPost.js @@ -15,13 +15,13 @@ var createPost = { var valid_at = rome(left, { dateValidator: rome.val.beforeEq(right), time: false, - inputFormat: 'YYYY/MM/DD', + inputFormat: 'YYYY-MM-DD', required: true }) var expired_at = rome(right, { dateValidator: rome.val.afterEq(left), time: false, - inputFormat: 'YYYY/MM/DD', + inputFormat: 'YYYY-MM-DD', required: true }) var simplemde = new SimpleMDE({ element: document.getElementById("smde") }); diff --git a/assets/js/components/editPost.js b/assets/js/components/editPost.js index 90a1ece..d3a11b0 100644 --- a/assets/js/components/editPost.js +++ b/assets/js/components/editPost.js @@ -7,20 +7,22 @@ let post = require('../models/post') var createPost = { oninit: function(vnode) { + post.current = {} post.loadCurrent(vnode.attrs.id) category.loadList(1) }, oncreate: function() { + clearInterval(window.intv) var valid_at = rome(left, { dateValidator: rome.val.beforeEq(right), time: false, - inputFormat: 'YYYY/MM/DD', + inputFormat: 'YYYY-MM-DD', required: true }) var expired_at = rome(right, { dateValidator: rome.val.afterEq(left), time: false, - inputFormat: 'YYYY/MM/DD', + inputFormat: 'YYYY-MM-DD', required: true }) var simplemde = new SimpleMDE({ element: document.getElementById("smde") }); @@ -35,7 +37,7 @@ var createPost = { }, view: function() { return m('main.documentation', m('section', [ - m('h2', 'Tambah Pengumuman'), + m('h2', 'Ubah Pengumuman'), m('form', { onsubmit: function(e) { e.preventDefault() @@ -73,10 +75,12 @@ var createPost = { onfocusout: m.withAttr('value', function(value) { post.current.valid_at = value }), - value: fecha.format( - post.current.valid_at ? new Date(post.current.valid_at) - : new Date(), - 'YYYY/MM/DD') + value: post.current.valid_at ? + fecha.format( + fecha.parse(post.current.valid_at, 'YYYY-MM-DD HH:mm:ss'), + 'YYYY-MM-DD' + ) + : '' }), m('br'), m('label', {for: 'expired_at'}, 'Berlaku sampai: '), @@ -85,10 +89,12 @@ var createPost = { onfocusout: m.withAttr('value', function(value) { post.current.expired_at = value }), - value: fecha.format( - post.current.expired_at ? new Date(post.current.expired_at) - : new Date(), - 'YYYY/MM/DD') + value: post.current.expired_at ? + fecha.format( + fecha.parse(post.current.expired_at, 'YYYY-MM-DD HH:mm:ss'), + 'YYYY-MM-DD' + ) + : '' }) ]), m('.full.two-third-600', [ diff --git a/assets/js/components/listAdmin.js b/assets/js/components/listAdmin.js index 65a6af5..e7a017f 100644 --- a/assets/js/components/listAdmin.js +++ b/assets/js/components/listAdmin.js @@ -22,19 +22,19 @@ var listAdmin = { 'data-tooltip': pengumuman.categoryName + "\nAktif: " - + fecha.format(fecha.parse(pengumuman.valid_at, 'YYYY-MM-DD H:i:s'), 'DD/MM/YYYY') + + fecha.format(fecha.parse(pengumuman.valid_at, 'YYYY-MM-DD HH:mm:ss'), 'YYYY-MM-DD') + ' - ' - + fecha.format(fecha.parse(pengumuman.expired_at, 'YYYY-MM-DD H:i:s'), 'DD/MM/YYYY') + + fecha.format(fecha.parse(pengumuman.expired_at, 'YYYY-MM-DD HH:mm:ss'), 'YYYY-MM-DD') + "\n" + 'Diubah: ' - + fecha.format(fecha.parse(pengumuman.edited_at, 'YYYY-MM-DD H:i:s'), 'DD/MM/YYYY') + + fecha.format(fecha.parse(pengumuman.edited_at, 'YYYY-MM-DD HH:mm:ss'), 'YYYY-MM-DD') }, [ m('em', { style: 'color: ' + pengumuman.foreground }, [ pengumuman.creatorName, ' - ', - fecha.format(fecha.parse(pengumuman.created_at, 'YYYY-MM-DD H:i:s'), 'DD/MM/YYYY') + fecha.format(fecha.parse(pengumuman.created_at, 'YYYY-MM-DD HH:mm:ss'), 'YYYY-MM-DD') ]) ]), m('span.stack', {style:'color:' + pengumuman.foreground + '; overflow-y: auto;'}, m.trust(marked(pengumuman.content))), diff --git a/assets/js/models/post.js b/assets/js/models/post.js index c4c766e..e7f2681 100644 --- a/assets/js/models/post.js +++ b/assets/js/models/post.js @@ -75,12 +75,12 @@ var post = { post.current = _.find(post.list, function(o) { return o.id == id }) if (post.current.status == 2) { post.current.status = 1 - post.current.valid_at = fecha.format(new Date(), 'YYYY/MM/DD') + var d = new Date(); + post.current.valid_at = fecha.format(new Date(), 'YYYY-MM-DD H:mm:s') } else if (post.current.status == 1) { post.current.status = 0 } post.save() - // console.log(post.current); }, validateStatus: function(id) {