diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 51559764..246f4566 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -49,8 +49,9 @@ def update existing_source = @project.source || {} existing_source["name"] = params.require(:project).require(:name) existing_source["extent"] = params.require(:project).require(:extent).split(",").map(&:to_f) - existing_source["cql"] = params.require(:project).require(:cql) - existing_source["layer"] = params.require(:project).require(:layer) + existing_source["cql"] = params[:project][:cql] if params[:project].key?(:cql) + existing_source["layer"] = params[:project][:layer] if params[:project].key?(:layer) + if @project.update(source: existing_source) if params[:commit] == 'Save and open project' diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 7da31855..533acdd5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -201,6 +201,8 @@ ], ]) ); + + if(fn) fn() }) function updateMap() { diff --git a/app/views/projects/edit.html.erb b/app/views/projects/edit.html.erb index de61f569..e05a980a 100644 --- a/app/views/projects/edit.html.erb +++ b/app/views/projects/edit.html.erb @@ -60,6 +60,15 @@ const projEx = document.getElementById('PROJEDIT303') if(!projEx) return + const fn = () => { + const savedVal = isSavedValue() + document.getElementById('project_value').value = savedVal + if(!savedVal){ + document.getElementById('project_layer').value = null + document.getElementById('project_cql').value = null + } + } + const hardcoded_extents = [ { id: -1, name: "✨Wealden", value: [ -4034.29345383, 6591225.55995304, 44295.78978777, 6647418.730598 ], layer_source: "shapefiles:westminster_const", layer_cql: "Name='Wealden Co Const'" }, { id: -2, name: "✨Brighton Pravilion", value: [ -21125.72504206, 6589221.35051539, -9227.54925854, 6602279.95570845 ], layer_source: "shapefiles:westminster_const", layer_cql: "Name='Brighton, Pavilion Boro Const'" }, @@ -90,7 +99,7 @@ document.getElementById('project_cql').value = cql document.getElementById('project_extent').value = extent.join(', ') - mapUpdate('PROJEDIT303') + mapUpdate('PROJEDIT303', fn) }) function isSavedValue(){ @@ -104,10 +113,7 @@ return id } - mapUpdate('PROJEDIT303', () => { - document.getElementById('project_value').value = isSavedValue() - } - ) + mapUpdate('PROJEDIT303', fn) document.getElementById('project_value').value = isSavedValue()