diff --git a/src/c3nav/editor/forms.py b/src/c3nav/editor/forms.py index 79954fe8..debc5b3b 100644 --- a/src/c3nav/editor/forms.py +++ b/src/c3nav/editor/forms.py @@ -13,7 +13,7 @@ from c3nav.mapdata.models.geometry import Area, Building, Door, Obstacle from c3nav.mapdata.permissions import get_unlocked_packages -class FeatureFormMixin(ModelForm): +class MapitemFormMixin(ModelForm): def __init__(self, *args, request=None, **kwargs): self.request = request super().__init__(*args, **kwargs) @@ -73,13 +73,13 @@ class FeatureFormMixin(ModelForm): self.titles = titles -def create_editor_form(feature_model, add_fields=None): - class EditorForm(FeatureFormMixin, ModelForm): +def create_editor_form(mapdata_model, add_fields=None): + class EditorForm(MapitemFormMixin, ModelForm): class Meta: - model = feature_model + model = mapdata_model fields = ['name', 'package', 'level', 'geometry'] + (add_fields if add_fields is not None else []) - feature_model.EditorForm = EditorForm + mapdata_model.EditorForm = EditorForm def create_editor_forms(): diff --git a/src/c3nav/editor/static/editor/css/editor.css b/src/c3nav/editor/static/editor/css/editor.css index b0afe7e9..d8c019fd 100644 --- a/src/c3nav/editor/static/editor/css/editor.css +++ b/src/c3nav/editor/static/editor/css/editor.css @@ -30,46 +30,39 @@ body { #mapeditcontrols { - position:absolute; - top:54px; - bottom:0; - padding:0; - width:350px; - right:0; - overflow:hidden; + position: absolute; + top: 54px; + bottom: 0; + width: 350px; + right: 0; + overflow: auto; + padding:8px; +} +#mapeditcontrols.loading { background-image:url('/static/img/loader.gif'); background-repeat:no-repeat; background-position:center; } -#mapeditcontrols > div { - position:absolute; - top:0; - bottom:0; - background-color:white; - padding:8px; - width:350px; - right:0; - transition: right 300ms; - -webkit-transition: right 300ms; - overflow:auto; -} -#mapeditcontrols > #mapeditdetail { - right:-350px; - pointer-events: none; -} -#mapeditcontrols.detail #mapeditdetail { - right:0; - pointer-events: auto; -} -#mapeditcontrols > #mapeditlist { - display:none; -} -#mapeditcontrols.list > #mapeditlist { - display:block; -} -#mapeditdetail h3 { +#mapeditcontrols h3 { margin-top:5px; } +a.list-group-item, a.list-group-item:hover { + color:#158cba; +} +a.list-group-item .badge { + font-size:14px; + font-weight:bold; +} +.itemtable td:last-child { + text-align:right; +} +.itemtable tr.highlight td { + background-color:#FFFFDD; +} +.cancel-btn { + margin-right:8px; +} + #mapeditlist legend .btn { padding-left:5.5px; padding-right:5.5px; @@ -89,36 +82,6 @@ legend { .leaflet-editable-drawing .leaflet-overlay-pane .leaflet-interactive { cursor:crosshair; } -.feature_list { - display:none; -} -.feature_level_list { - list-style-type:none; - display:none; - padding:0; -} -.feature_level_list li { - padding:5px 0 0; - border-style:solid; - border-width:0 0 1px; - border-color:#EEEEEE; -} -.feature_level_list li:hover, .feature_level_list li.hover { - background-color:#FFFFEE; -} -.feature_level_list p { - margin:0 0 5px; - cursor:default; -} -.feature_level_list p:first-child { - font-weight:bold; - font-size:16px; -} -.feature_level_list p:first-child em { - font-weight:normal; - font-size:14px; - padding-left:5px; -} #map .leaflet-overlay-pane .c3nav-highlight { pointer-events:none; } diff --git a/src/c3nav/editor/static/editor/js/editor.js b/src/c3nav/editor/static/editor/js/editor.js index e4afdbc7..ec70e6fd 100644 --- a/src/c3nav/editor/static/editor/js/editor.js +++ b/src/c3nav/editor/static/editor/js/editor.js @@ -13,9 +13,11 @@ editor = { editable: true, closePopupOnClick: false }); + editor.map.on('click', function (e) { + editor.map.doubleClickZoom.enable(); + }); L.control.scale({imperial: false}).addTo(editor.map); - editor._highlight_layer = L.layerGroup().addTo(editor.map); $('#show_map').click(function() { $('body').removeClass('controls'); @@ -24,50 +26,17 @@ editor = { $('body').addClass('controls'); }); - editor.get_feature_types(); + editor.init_geometries(); + editor.init_sidebar(); editor.get_packages(); editor.get_sources(); + editor.get_levels(); }, - _feature_type: null, - get_feature_types: function () { - $.getJSON('/api/featuretypes/', function (feature_types) { - var feature_type; - var listcontainer = $('#mapeditlist fieldset'); - var dropdown = $('#featuretype_dropdown').on('click', 'a', function(e) { - e.preventDefault(); - editor.set_current_feature_type($(this).parent().attr('data-name')); - }); - for (var i = 0; i < feature_types.length; i++) { - feature_type = feature_types[i]; - editor.feature_types[feature_type.name] = feature_type; - feature_type.weight = 0; - feature_type.fillOpacity = 0.6; - feature_type.smoothFactor = 0; - editor.feature_types_order.push(feature_type.name); - listcontainer.append( - $('
').attr('name', feature_type.name) - ); - dropdown.append( - $('
  • ').attr('data-name', feature_type.name).append( - $('').text(feature_type.title_plural) - ) - ); - } - editor.set_current_feature_type(editor.feature_types_order[0]); - editor.get_levels(); - }); - }, - set_current_feature_type: function(feature_type) { - editor._feature_type = feature_type; - $('.feature_list').hide(); - $('.feature_list[name='+feature_type+']').show(); - $('#current_featuretype_title').text(editor.feature_types[feature_type].title_plural); - $('#create_featuretype_title').text(editor.feature_types[feature_type].title); - }, - + // packages packages: {}, get_packages: function () { + // load packages $.getJSON('/api/packages/', function (packages) { var bounds = [[0, 0], [0, 0]]; var pkg; @@ -83,8 +52,10 @@ editor = { }); }, + // sources sources: {}, get_sources: function () { + // load sources $.getJSON('/api/sources/', function (sources) { var layers = {}; var source; @@ -98,10 +69,11 @@ editor = { }); }, + // levels levels: {}, _level: null, - level_feature_layers: {}, get_levels: function () { + // load levels and set the lowest one afterwards $.getJSON('/api/levels/?ordering=-altitude', function (levels) { L.LevelControl = L.Control.extend({ options: { @@ -127,137 +99,122 @@ editor = { editor.set_current_level($(this).attr('name')); }); - var level, feature_type; - for (var i = 0; i < levels.length; i++) { - level = levels[i]; - editor.levels[level.name] = level; - editor.level_feature_layers[level.name] = {}; - for (var j = 0; j < editor.feature_types_order.length; j++) { - feature_type = editor.feature_types_order[j]; - editor.level_feature_layers[level.name][feature_type] = L.layerGroup(); - $('.feature_list[name='+feature_type+']').append( - $('