add api_carto on back office and recapitulative page

This commit is contained in:
Xavier J 2015-11-19 16:47:56 +01:00
parent ce6af625d2
commit 61b126b0f9
8 changed files with 74 additions and 27 deletions

View file

@ -3,41 +3,52 @@ function initCarto() {
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
position = get_position();
var LON = '2.428462';
var LAT = '46.538192';
position = get_position() || {lon: LON, lat: LAT, zoom: 13};
if (typeof position.zoom == 'undefined')
position.zoom = 13;
var map = L.map("map", {
center: new L.LatLng(position.lat, position.lon),
zoom: 13,
zoom: position.zoom,
layers: [OSM]
});
var freeDraw = new L.FreeDraw({
mode: L.FreeDraw.MODES.CREATE
//mode: L.FreeDraw.MODES.CREATE
});
map.addLayer(freeDraw);
$.each($.parseJSON($("#json_latlngs").val()), function(i, val){
freeDraw.createPolygon(val);
});
if ($("#json_latlngs").val() != '' && $("#json_latlngs").val() != '[]') {
$.each($.parseJSON($("#json_latlngs").val()), function (i, val) {
freeDraw.createPolygon(val);
});
map.setView(freeDraw.polygons[0].getBounds().getCenter(), position.zoom);
}
else if (position.lat == LAT && position.lon == LON)
map.setView(new L.LatLng(position.lat, position.lon), 5);
add_event_freeDraw(freeDraw);
}
function add_event_freeDraw(freeDraw){
freeDraw.on('markers', function (e){
function add_event_freeDraw(freeDraw) {
freeDraw.on('markers', function (e) {
$("#json_latlngs").val(JSON.stringify(e.latLngs));
});
$("#new").on('click', function (e){
$("#new").on('click', function (e) {
freeDraw.setMode(L.FreeDraw.MODES.CREATE);
});
$("#edit").on('click', function (e){
$("#edit").on('click', function (e) {
freeDraw.setMode(L.FreeDraw.MODES.EDIT);
});
$("#delete").on('click', function (e){
$("#delete").on('click', function (e) {
freeDraw.setMode(L.FreeDraw.MODES.DELETE);
});
}

View file

@ -6,6 +6,14 @@ table {
font-size: 13;
}
#map{
height:600px;
width: 100%;
}
#map.mini{
height:300px;
}
#map section.overlay {
position: absolute;

View file

@ -8,6 +8,7 @@ class Users::CarteController < UsersController
redirect_to url_for(root_path)
end
#TODO change name funtion
def save_ref_api_carto
dossier = current_user_dossier
dossier.update_attributes(json_latlngs: params[:json_latlngs])

View file

@ -13,23 +13,36 @@
%br
- rescue
=''
.col-lg-6.col-md-6
=render partial: '/dossiers/pieces_justificatives'
- if @dossier.procedure.use_api_carto
.col-lg-6.col-md-6
#map.mini
%input{id: 'json_latlngs', type:'hidden', value: "#{@dossier.json_latlngs}"}
%script{type: 'text/javascript'}
= "var dossier_id =#{@dossier.id}"
initCarto();
%br
-unless @champs.nil?
%table.table#liste_champs
-@champs.each do |champ|
%tr
%th{ style: 'width:25%' }
=champ.libelle
%td
=champ.value
-unless @champs.nil?
.row
.col-lg-6.col-md-6
%table.table#liste_champs
-@champs.each do |champ|
%tr
%th{ style: 'width:25%' }
=champ.libelle
%td
=champ.value
.col-lg-6.col-md-6
=render partial: '/dossiers/pieces_justificatives'
%br
%div.row{style: 'text-align:right'}
-unless gestionnaire_signed_in?
-if !@dossier.validated? && !@dossier.submitted? && !@dossier.closed?
%a#maj_infos.btn.btn-info{href: "/users/dossiers/#{@dossier.id}/description?back_url=recapitulatif"}
-if @dossier.procedure.use_api_carto
%a#maj_carte.btn.btn-primary{href: "/users/dossiers/#{@dossier.id}/carte"}
= 'Editer ma carte'
%a#maj_infos.btn.btn-info{href: "/users/dossiers/#{@dossier.id}/description"}
= 'Editer mon dossier'
-unless user_signed_in?

View file

@ -1,6 +1,6 @@
#pieces_justificatives
%h3.text-info Liste des pièces justificatives
%br
-#%h3.text-info Liste des pièces justificatives
-#%br
%table.table
-if @procedure.lien_demarche != nil
%tr{id: "piece_justificative_0"}

View file

@ -2,7 +2,7 @@
%div#commentaire_new{style: 'width:80%; margin-left:auto; margin-right:auto'}
= form_tag(url_for({ controller: :commentaires, action: :create, dossier_id: @dossier.id }), class: 'form-inline', method: 'POST') do
%textarea.form-control{id: 'texte_commentaire', name: 'texte_commentaire', style: 'width: 100%; margin-bottom:2%', rows: '5', maxlength: '255', placeholder:"Dialoguer avec votre interlocuteur privilégié en charge de votre dossier."}
%input.form-control.btn.btn-primary{:type => 'submit', :value => 'Poster', style: 'float:right'}
%input.form-control.btn.btn-success{:type => 'submit', :value => 'Poster', style: 'float:right'}
%br
%br

View file

@ -4,6 +4,10 @@ FactoryGirl.define do
libelle 'Demande de subvention'
description "Demande de subvention à l'intention des associations"
trait :with_api_carto do
use_api_carto true
end
trait :with_type_de_champ do
after(:build) do |procedure, _evaluator|
type_de_champ = create(:type_de_champ)

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'users/recapitulatif/show.html.haml', type: :view do
let(:dossier) { create(:dossier, :with_user, :with_entreprise, :with_procedure) }
let(:dossier) { create(:dossier, :with_user, :with_entreprise, procedure: create(:procedure, :with_api_carto)) }
let(:dossier_id) { dossier.id }
before do
@ -36,7 +36,17 @@ describe 'users/recapitulatif/show.html.haml', type: :view do
end
it 'le lien vers description est correct' do
expect(rendered).to have_selector("a[id=maj_infos][href='/users/dossiers/#{dossier_id}/description?back_url=recapitulatif']")
expect(rendered).to have_selector("a[id=maj_infos][href='/users/dossiers/#{dossier_id}/description']")
end
end
context 'lien carte' do
it 'le lien vers carte est présent' do
expect(rendered).to have_css('#maj_carte')
end
it 'le lien vers description est correct' do
expect(rendered).to have_selector("a[id=maj_carte][href='/users/dossiers/#{dossier_id}/carte']")
end
end
end