Browse Source

remember if the user checks the "location" checkbox and always find their location in the future if so

pull/5/head
Aaron Parecki 10 years ago
parent
commit
e357730b31
3 changed files with 73 additions and 24 deletions
  1. +22
    -0
      README.md
  2. +13
    -1
      controllers/controllers.php
  3. +38
    -23
      views/dashboard.php

+ 22
- 0
README.md View File

@ -4,3 +4,25 @@ IndiePost
Work in progress. Do not use! Work in progress. Do not use!
https://indiepost.micropub.net/ https://indiepost.micropub.net/
### Contributing
By submitting code to this project, you agree to irrevocably release it under the same license as this project.
### License
Copyright 2013 by Aaron Parecki
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

+ 13
- 1
controllers/controllers.php View File

@ -32,12 +32,24 @@ $app->get('/new', function() use($app) {
'micropub_scope' => $user->micropub_scope, 'micropub_scope' => $user->micropub_scope,
'micropub_access_token' => $user->micropub_access_token, 'micropub_access_token' => $user->micropub_access_token,
'response_date' => $user->last_micropub_response_date, 'response_date' => $user->last_micropub_response_date,
'test_response' => $test_response
'test_response' => $test_response,
'location_enabled' => $user->location_enabled
)); ));
$app->response()->body($html); $app->response()->body($html);
} }
}); });
$app->post('/prefs', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();
$user->location_enabled = $params['enabled'];
$user->save();
}
$app->response()->body(json_encode(array(
'result' => 'ok'
)));
});
$app->get('/creating-a-token-endpoint', function() use($app) { $app->get('/creating-a-token-endpoint', function() use($app) {
$app->redirect('http://indiewebcamp.com/token-endpoint', 301); $app->redirect('http://indiewebcamp.com/token-endpoint', 301);
}); });

+ 38
- 23
views/dashboard.php View File

@ -24,6 +24,7 @@
<input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly"> <input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
<input type="hidden" id="note_location"> <input type="hidden" id="note_location">
<input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
<div id="note_location_img" style="display: none;"> <div id="note_location_img" style="display: none;">
<img src="" height="180" id="note_location_img_wide" class="img-responsive"> <img src="" height="180" id="note_location_img_wide" class="img-responsive">
@ -112,33 +113,38 @@ $(function(){
var map_template_wide = "<?= static_map('{lat}', '{lng}', 180, 700, 15) ?>"; var map_template_wide = "<?= static_map('{lat}', '{lng}', 180, 700, 15) ?>";
var map_template_small = "<?= static_map('{lat}', '{lng}', 320, 480, 15) ?>"; var map_template_small = "<?= static_map('{lat}', '{lng}', 320, 480, 15) ?>";
function fetch_location() {
$("#note_location_loading").show();
navigator.geolocation.getCurrentPosition(function(position){
$("#note_location_loading").hide();
var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
$("#note_location_msg").val(geo);
$("#note_location").val(geo);
$("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
$("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
$("#note_location_img").show();
$("#note_location_msg").addClass("img-visible");
}, function(err){
if(err.code == 1) {
location_error("The website was not able to get permission");
} else if(err.code == 2) {
location_error("Location information was unavailable");
} else if(err.code == 3) {
location_error("Timed out getting location");
}
});
}
$("#note_location_chk").click(function(){ $("#note_location_chk").click(function(){
if($(this).attr("checked") == "checked") { if($(this).attr("checked") == "checked") {
if(navigator.geolocation) { if(navigator.geolocation) {
$("#note_location_loading").show();
navigator.geolocation.getCurrentPosition(function(position){
$("#note_location_loading").hide();
console.log(position);
var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
$("#note_location_msg").val(geo);
$("#note_location").val(geo);
$("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
$("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
$("#note_location_img").show();
$("#note_location_msg").addClass("img-visible");
}, function(err){
if(err.code == 1) {
location_error("The website was not able to get permission");
} else if(err.code == 2) {
location_error("Location information was unavailable");
} else if(err.code == 3) {
location_error("Timed out getting location");
}
$.post("/prefs", {
enabled: 1
}); });
fetch_location();
} else { } else {
location_error("Browser location is not supported"); location_error("Browser location is not supported");
} }
@ -147,9 +153,18 @@ $(function(){
$("#note_location_msg").removeClass("img-visible"); $("#note_location_msg").removeClass("img-visible");
$("#note_location_msg").val(''); $("#note_location_msg").val('');
$("#note_location").val(''); $("#note_location").val('');
$.post("/prefs", {
enabled: 0
});
} }
}); });
if($("#location_enabled").val() == 1) {
$("#note_location_chk").attr("checked","checked");
fetch_location();
}
}); });
</script> </script>
<style type="text/css"> <style type="text/css">

Loading…
Cancel
Save