diff options
-rw-r--r-- | management/manager/manager.go | 23 | ||||
-rw-r--r-- | system/admin/static/common/js/util.js | 32 |
2 files changed, 48 insertions, 7 deletions
diff --git a/management/manager/manager.go b/management/manager/manager.go index 46ee82a..bdad081 100644 --- a/management/manager/manager.go +++ b/management/manager/manager.go @@ -25,13 +25,32 @@ const managerHTML = ` e.target.value = replaceBadChars(val); }); + var setDefaultTimeAndDate = function($pt, $pd, $ts, $up, unix) { + var time = getPartialTime(now), + date = getPartialDate(now); + + $pt.val(time); + $pd.val(date); + $ts.val(unix); + $up.val(unix); + } + // set time time and date inputs using the hidden timestamp input. // if it is empty, set it to now and use that value for time and date var publish_time = $('input.__ponzu.time'), publish_date = $('input.__ponzu.date'), - now = new Date(); + timestamp = $('input.__ponzu.timestamp'), + updated = $('input.__ponzu.updated'), + time; + + if (timestamp.val() !== "") { + time = timestamp.val(); + } else { + time = (new Date()).getTime(); + } - // set updated value to now + setDefaultTimeAndDate(publish_time, publish_date, timestamp, updated, time); + }); </script> </div> diff --git a/system/admin/static/common/js/util.js b/system/admin/static/common/js/util.js index 1e798d6..40c9828 100644 --- a/system/admin/static/common/js/util.js +++ b/system/admin/static/common/js/util.js @@ -23,12 +23,34 @@ function replaceBadChars(text) { } -// Returns a local partial time based on unix timestamp -function getPartialTime(date) { +// Returns a local partial time based on unix timestamp (i.e. HH:MM:SS) +function getPartialTime(unix) { + var date = new Date(unix); var parts = []; - parts.push(date.getHours()) - parts.push(date.getMinutes()) - parts.push(date.getSeconds()) + parts.push(date.getHours()); + parts.push(date.getMinutes()); + parts.push(date.getSeconds()); return parts.join(":"); +} + +// Returns a local partial date based on unix timestamp (YYYY-MM-DD) +function getPartialDate(unix) { + var date = new Date(unix); + var parts = []; + parts.push(date.getFullYear()); + + var month = date.getMonth()+1; + if (month < 10) { + month = "0" + String(month); + } + parts.push(month); + + var day = date.getDate(); + if (day < 10) { + day = "0" + String(day); + } + parts.push(day); + + return parts.join("-"); }
\ No newline at end of file |