Skip to content

Commit

Permalink
Let user choose base map on client side
Browse files Browse the repository at this point in the history
This is link to #436
  • Loading branch information
pierre committed Dec 10, 2018
1 parent 5337630 commit 1fde173
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 107 deletions.
238 changes: 141 additions & 97 deletions addons/cadastrapp/js/printBordereauParcellaire.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@ Ext.namespace("GEOR.Addons.Cadastre");
* @returns Ext.Window
*/
GEOR.Addons.Cadastre.onClickPrintBordereauParcellaireWindow = function(parcelleId) {

if (GEOR.Addons.Cadastre.printBordereauParcellaireWindow != null) {
GEOR.Addons.Cadastre.printBordereauParcellaireWindow.close();
}

//TODO add verification to limite bordereau parcellairenumber

// Test if user have CNIL level 1 or 2
// ask if user want with or without personnal data
if (GEOR.Addons.Cadastre.isCNIL1() || GEOR.Addons.Cadastre.isCNIL2()){
// If more than one basemap available propose them
if (GEOR.Addons.Cadastre.isCNIL1() || GEOR.Addons.Cadastre.isCNIL2() || GEOR.Addons.Cadastre.pdfbasemaptitles.length>1){
GEOR.Addons.Cadastre.initPrintBordereauParcellaireWindow(parcelleId);
GEOR.Addons.Cadastre.printBordereauParcellaireWindow.show();
}else{
// PARAMS
var params = {
parcelle : parcelleId,
personaldata:0,
fillcolor:GEOR.Addons.Cadastre.styles.selected.fillColor,
opacity:GEOR.Addons.Cadastre.styles.selected.opacity,
strokecolor:GEOR.Addons.Cadastre.styles.selected.strokeColor,
strokewidth:GEOR.Addons.Cadastre.styles.selected.strokeWidth,
parcelle: parcelleId,
personaldata: 0,
fillcolor: GEOR.Addons.Cadastre.styles.selected.fillColor,
opacity: GEOR.Addons.Cadastre.styles.selected.opacity,
strokecolor: GEOR.Addons.Cadastre.styles.selected.strokeColor,
strokewidth: GEOR.Addons.Cadastre.styles.selected.strokeWidth,
}
var url = GEOR.Addons.Cadastre.cadastrappWebappUrl + 'createBordereauParcellaire?' + Ext.urlEncode(params);

Ext.DomHelper.useDom = true;

// Directly download file, without and call service without ogcproxy
Ext.DomHelper.append(document.body, {
tag : 'iframe',
id : 'downloadIframe',
frameBorder : 0,
width : 0,
height : 0,
css : 'display:none;visibility:hidden;height:0px;',
src : url
tag: 'iframe',
id: 'downloadIframe',
frameBorder: 0,
width: 0,
height: 0,
css: 'display:none;visibility:hidden;height:0px;',
src: url
});

// windows might not have been open
Expand All @@ -58,92 +58,135 @@ GEOR.Addons.Cadastre.onClickPrintBordereauParcellaireWindow = function(parcelleI
*/
GEOR.Addons.Cadastre.initPrintBordereauParcellaireWindow = function(parcelleId) {

var comboBaseMap = new Ext.form.ComboBox({
width : 230,
mode : 'local',
forceSelection : true,
displayField : 'basemapindex',
valueField : 'basemapindex',
store : GEOR.Addons.Cadastre.pdfbasemaptitles,
value : GEOR.Addons.Cadastre.pdfbasemaptitles[0],
listeners : {
expand : function() {
this.store.removeAll();
this.store.loadData(GEOR.Addons.Cadastre.pdfbasemaptitles);
this.show();
}
}
});
var itemsInPanel = [];

// Show only personaldata information if user have the goog Cnil level
if (GEOR.Addons.Cadastre.isCNIL1() || GEOR.Addons.Cadastre.isCNIL2()){
var fiedSetPersonnalData = new Ext.form.FieldSet({
title: OpenLayers.i18n('cadastrapp.bordereauparcellaire.data'),
autoHeight: true,
hide: true,
items: [ {
xtype: 'hidden',
name: 'parcelle',
value: parcelleId
}, {
xtype: 'radio',
boxLabel: OpenLayers.i18n('cadastrapp.bordereauparcellaire.data.without'),
checked: true,
name: 'personaldata',
inputValue: 0

}, {
xtype: 'radio',
boxLabel: OpenLayers.i18n('cadastrapp.bordereauparcellaire.data.with'),
name: 'personaldata',
inputValue: 1
} ]
});

itemsInPanel.push(fiedSetPersonnalData);
}

// Show only base map combobox if there is more than one option
if (GEOR.Addons.Cadastre.pdfbasemaptitles.length>1){

var storeBaseMap = new Ext.data.JsonStore({
storeId: 'cadstorebasemap',
fields: [{
// keep only index from key information
// Key is formatted like pdf.baseMap.0.title
// We want only index
name: 'index',
convert: function(v, rec) {
// Split in array
var data = rec.key.split(".");
// remove element title
data.pop();
// get index information
return data.pop();
}}, 'value'],
sortInfo:{
field: 'value',
direction: "ASC"
}
});

var comboBaseMap = new Ext.form.ComboBox({
id: 'cadbasemapindex',
hiddenName: 'basemapindex',
width: 230,
displayField: 'value',
valueField: 'index',
store: storeBaseMap,
mode: 'local',
allowBlank: false,
selectOnFocus: true,
typeAhead: true,
forceSelection: true,
triggerAction: 'all',
editable: false,
});

// Load first value
comboBaseMap.store.on('load', function(ds,records,o){
comboBaseMap.setValue(records[0].data.value);
});

storeBaseMap.loadData(GEOR.Addons.Cadastre.pdfbasemaptitles);

var fiedSetBaseMap = new Ext.form.FieldSet({
title: OpenLayers.i18n('cadastrapp.bordereauparcellaire.basemap'),
autoHeight: true,
hide: true,
items: [comboBaseMap]
});

itemsInPanel.push(fiedSetBaseMap);
}


// fenêtre principale
GEOR.Addons.Cadastre.printBordereauParcellaireWindow = new Ext.Window({
title : OpenLayers.i18n('cadastrapp.bordereauparcellaire.title') + ' - ' + parcelleId,
frame : true,
autoScroll : true,
minimizable : false,
closable : true,
resizable : false,
draggable : true,
constrainHeader : true,
border : false,
width : 300,
defaults : {
autoHeight : true,
bodyStyle : 'padding:10px',
flex : 1
title: OpenLayers.i18n('cadastrapp.bordereauparcellaire.title') + ' - ' + parcelleId,
frame: true,
autoScroll: true,
minimizable: false,
closable: true,
resizable: false,
draggable: true,
constrainHeader: true,
border: false,
width: 300,
defaults: {
autoHeight: true,
bodyStyle: 'padding:10px',
flex: 1
},

listeners : {
close : function(window) {
listeners: {
close: function(window) {
GEOR.Addons.Cadastre.printBordereauParcellaireWindow = null;
}
},

items : [ {
xtype : 'form',
id : 'bordereauForm',
height : 200,
labelWidth : 1,
autoHeight : true,

items : [ {
xtype : 'fieldset',
title : OpenLayers.i18n('cadastrapp.bordereauparcellaire.data'),
autoHeight : true,

items : [ {
xtype : 'hidden',
name : 'parcelle',
value : parcelleId
}, {
xtype : 'radio',
boxLabel : OpenLayers.i18n('cadastrapp.bordereauparcellaire.data.without'),
checked : true,
name : 'personaldata',
inputValue : 0

}, {
xtype : 'radio',
boxLabel : OpenLayers.i18n('cadastrapp.bordereauparcellaire.data.with'),
name : 'personaldata',
inputValue : 1
} ]
} , {
xtype : 'fieldset',
title : OpenLayers.i18n('cadastrapp.bordereauparcellaire.basemap'),
autoHeight : true,
items : [comboBaseMap]
}
]
items: [ {
xtype: 'form',
id: 'bordereauForm',
height: 200,
labelWidth: 1,
autoHeight: true,
items: itemsInPanel
} ],

buttons : [ {
text : OpenLayers.i18n('cadastrapp.generate'),
listeners : {
click : function(b, e) {
buttons: [ {
text: OpenLayers.i18n('cadastrapp.generate'),
listeners: {
click: function(b, e) {

// PARAMS
var params = GEOR.Addons.Cadastre.printBordereauParcellaireWindow.items.items[0].getForm().getValues();
if(Ext.getCmp("cadbasemapindex")){
params.basemapindex = Ext.getCmp("cadbasemapindex").getValue();
}
// Add style information
// remove # to avoid URL problems on server side (XSL template doesnot manage url-encode)
params.fillcolor=GEOR.Addons.Cadastre.styles.selected.fillColor.substring(1);;
Expand All @@ -158,16 +201,17 @@ GEOR.Addons.Cadastre.initPrintBordereauParcellaireWindow = function(parcelleId)

// Directly download file, without and call service without ogcproxy
Ext.DomHelper.append(document.body, {
tag : 'iframe',
id : 'downloadIframe',
frameBorder : 0,
width : 0,
height : 0,
css : 'display:none;visibility:hidden;height:0px;',
src : url
tag: 'iframe',
id: 'downloadIframe',
frameBorder: 0,
width: 0,
height: 0,
css: 'display:none;visibility:hidden;height:0px;',
src: url
});

//TODO add waiting panel
// Cannot not manage to stop waiting panel in every case, Ext.js does not see end of Iframe loading in specific case
GEOR.Addons.Cadastre.printBordereauParcellaireWindow.close();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.georchestra.cadastrapp.configuration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
Expand Down Expand Up @@ -52,17 +52,18 @@ public static String getProperty(String name) {
* @param regexkey
* @return all value where key like regexKey, null if no key matches
*/
public static Map<Integer, String> getPropertiesLike(String regexKey){
public static List<Object> getPropertiesLike(String regexKey){

Map<Integer, String> result = new HashMap<Integer, String>();
int index = 0;
List<Object> result = new ArrayList<Object>();
for (Entry<String, String> entry : propertiesMap.entrySet()) {
Map<String, Object> information = new HashMap<String, Object>();

if (entry.getKey().matches(regexKey)) {
result.put(index, entry.getValue());
index++;
}
}
if (entry.getKey().matches(regexKey)) {
information.put("key", entry.getKey());
information.put("value", entry.getValue());
result.add(information);
}
}
return result;
}

Expand Down

0 comments on commit 1fde173

Please sign in to comment.