Skip to content

Commit

Permalink
add default location to post form
Browse files Browse the repository at this point in the history
  • Loading branch information
nstjean committed Dec 10, 2019
1 parent 6824509 commit 4fa9c8d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/controllers/editor_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def rich
x.include? "lon:" and (@lon = x.split(':')[1])
end
end

# if user has a location, set the @lat and @lon
if (@lat.nil? && @lon.nil?) && (current_user&.has_power_tag("lat") && current_user&.has_power_tag("lon"))
@lat = current_user.get_value_of_power_tag("lat").to_f
@lon = current_user.get_value_of_power_tag("lon").to_f
@map_blurred = current_user.has_tag('location:blurred')
end

template if params[:n] && !params[:body] # use another node body as a template
image if params[:i]
end
Expand Down
33 changes: 31 additions & 2 deletions app/views/editor/rich.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
class="leaflet-map"
style="width: 100% ; height: 300px; margin-bottom:8px;">
</div>


</div>

<div class="col-lg-6">
Expand Down Expand Up @@ -199,8 +201,7 @@
</div>
</div>
</div>
<!-- Map Module end -->

<!-- Map Module end -->

<!-- body module -->
<div class="ple-module-body ple-module row">
Expand Down Expand Up @@ -307,6 +308,7 @@

</div>
<script>

var editor;

(function() {
Expand Down Expand Up @@ -404,6 +406,30 @@
}
});

$(function() {
var target = document.querySelector('#map_content');
var observer = new MutationObserver(function(mutations) {
setLocationButtonText();
});
observer.observe(target, {
attributes: true
});
});

function setLocationButtonText() {
console.log('set it!!!');
if ($('#map_content').is(':hidden')) {
console.log('hidden');
$('#location_button').html('<i class="fa fa-map-marker" aria-hidden="true"></i> Add a location');
} else {
console.log('visible');
$('#location_button').html('<i class="fa fa-minus-circle"></i> Remove location');
}
}
setLocationButtonText();
$("#obscureLocation").prop('checked', <%= @map_blurred %>);
editor.mapModule.blurredLocation.setBlurred(<%= @map_blurred %>);

// upload via posting "posted_main_image"
function dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
Expand Down Expand Up @@ -448,4 +474,7 @@
}
console.log("Draft:", editor.data.draft);
}


</script>

0 comments on commit 4fa9c8d

Please sign in to comment.