Browse Source

move date to the top, populate via JS

pull/10/head
Aaron Parecki 9 years ago
parent
commit
4abacf5e84
2 changed files with 29 additions and 33 deletions
  1. +1
    -23
      controllers/controllers.php
  2. +28
    -10
      views/new-post.php

+ 1
- 23
controllers/controllers.php View File

@ -270,31 +270,9 @@ $app->get('/options.json', function() use($app) {
$options = get_entry_options($user->id, k($params,'latitude'), k($params,'longitude'));
$html = partial('partials/entry-buttons', ['options'=>$options]);
$tz_offset = '+0000';
$date_str = date('Y-m-d');
$time_str = date('H:i:s');
if(k($params,'latitude')) {
if($timezone=get_timezone($params['latitude'], $params['longitude'])) {
$seconds = $timezone->getOffset(new DateTime());
$tz_offset = tz_seconds_to_offset($seconds);
// Create a date object in the local timezone given the offset
$date = new DateTime();
if($seconds > 0)
$date->add(new DateInterval('PT'.$seconds.'S'));
elseif($seconds < 0)
$date->sub(new DateInterval('PT'.abs($seconds).'S'));
$date_str = $date->format('Y-m-d');
$time_str = $date->format('H:i:s');
}
}
$app->response()['Content-type'] = 'application/json';
$app->response()->body(json_encode([
'buttons'=>$html,
'tz_offset'=>$tz_offset,
'date_str'=>$date_str,
'time_str'=>$time_str
'buttons'=>$html
]));
}
});

+ 28
- 10
views/new-post.php View File

@ -3,6 +3,14 @@
<form role="form" style="margin-top: 20px;" id="note_form" action="/post" method="post">
<div class="form-group">
<h3>Date</h3>
<input type="date" class="form-control" style="max-width:160px; float:left; margin-right: 4px;" id="note_date" name="note_date" value="">
<input type="text" class="form-control" style="max-width:90px; float:left; margin-right: 4px;" id="note_time" name="note_time" value="">
<input type="text" class="form-control" style="max-width:90px;" id="note_tzoffset" name="note_tzoffset" value="">
</div>
<div id="entry-buttons">
<?= partial('partials/entry-buttons', ['options'=>$this->default_options]) ?>
</div>
@ -20,13 +28,6 @@
</div>
</div>
<div class="form-group">
<h3>Date</h3>
<input type="date" id="note_date" name="note_date" value="<?= $this->date_str ?>">
<input type="text" id="note_time" name="note_time" value="<?= $this->time_str ?>">
<input type="text" id="note_tzoffset" name="note_tzoffset" value="<?= $this->tz_offset ?>">
</div>
</form>
<?php if($this->micropub_endpoint): ?>
@ -69,6 +70,26 @@
<script>
$(function(){
function tz_seconds_to_offset(seconds) {
var tz_offset = '';
var hours = zero_pad(Math.abs(seconds / 60 / 60));
var minutes = zero_pad(Math.floor(seconds / 60) % 60);
return (seconds < 0 ? '-' : '+') + hours + ":" + minutes;
}
function zero_pad(num) {
num = "" + num;
if(num.length == 1) {
num = "0" + num;
}
return num;
}
// Set the date from JS
var d = new Date();
$("#note_date").val(d.getFullYear()+"-"+zero_pad(d.getMonth()+1)+"-"+zero_pad(d.getDate()));
$("#note_time").val(zero_pad(d.getHours())+":"+zero_pad(d.getMinutes())+":"+zero_pad(d.getSeconds()));
$("#note_tzoffset").val(tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1));
function bind_keyboard_shortcuts() {
$(".text-custom-eat").keydown(function(e){
if(e.keyCode == 13) {
@ -119,9 +140,6 @@ $(function(){
}
$("#entry-buttons").html(response.buttons);
$("#note_tzoffset").val(response.tz_offset);
$("#note_date").val(response.date_str);
$("#note_time").val(response.time_str);
// restore the custom values entered
$('#custom_eat').val(custom_eat);

Loading…
Cancel
Save