mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-24 17:14:04 +02:00
Remove old tagging infrastructure
This commit is contained in:
@@ -64,6 +64,6 @@ define(['dojo/_base/declare','iD/actions/UndoableAction'], function(declare){
|
||||
}
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// End of module
|
||||
// ----------------------------------------------------------------------
|
||||
// End of module
|
||||
});
|
||||
|
||||
@@ -2,49 +2,49 @@
|
||||
|
||||
define(['dojo/_base/declare','iD/actions/UndoableAction'], function(declare) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// CreateEntityAction class
|
||||
// ----------------------------------------------------------------------
|
||||
// CreateEntityAction class
|
||||
|
||||
declare("iD.actions.CreateEntityAction", [iD.actions.UndoableEntityAction], {
|
||||
declare("iD.actions.CreateEntityAction", [iD.actions.UndoableEntityAction], {
|
||||
|
||||
setCreate:null,
|
||||
deleteAction:null,
|
||||
setCreate:null,
|
||||
deleteAction:null,
|
||||
|
||||
constructor: function(entity,setCreate) {
|
||||
// summary: Create a new entity - way, node or relation.
|
||||
this.setCreate = setCreate;
|
||||
this.setName("Create " + entity.entityType);
|
||||
},
|
||||
constructor: function(entity,setCreate) {
|
||||
// summary: Create a new entity - way, node or relation.
|
||||
this.setCreate = setCreate;
|
||||
this.setName("Create " + entity.entityType);
|
||||
},
|
||||
|
||||
run: function() {
|
||||
// summary: Call out to the specified method (in the Controller) to create the entity.
|
||||
// See undoAction for explanation of special redo handling.
|
||||
if (this.deleteAction!==null) {
|
||||
this.deleteAction.undoAction(); // redo
|
||||
} else {
|
||||
this.setCreate(this.entity, false); // first time
|
||||
}
|
||||
this.markDirty();
|
||||
return this.SUCCESS;
|
||||
},
|
||||
run: function() {
|
||||
// summary: Call out to the specified method (in the Controller) to create the entity.
|
||||
// See undoAction for explanation of special redo handling.
|
||||
if (this.deleteAction!==null) {
|
||||
this.deleteAction.undoAction(); // redo
|
||||
} else {
|
||||
this.setCreate(this.entity, false); // first time
|
||||
}
|
||||
this.markDirty();
|
||||
return this.SUCCESS;
|
||||
},
|
||||
|
||||
undo: function() {
|
||||
// summary: Special handling for undoing a create. When undo is called, instead
|
||||
// of simply removing the entity, we work through to make a Delete[Entity]Action,
|
||||
// call that, and store it for later. Then, when this action is called again
|
||||
// (i.e. a redo), instead of creating yet another entity, we call the deleteAction.undoAction.
|
||||
if (this.deleteAction===null) { this.entity.remove(this.setAction); }
|
||||
this.deleteAction.doAction();
|
||||
this.markClean();
|
||||
return this.SUCCESS;
|
||||
},
|
||||
undo: function() {
|
||||
// summary: Special handling for undoing a create. When undo is called, instead
|
||||
// of simply removing the entity, we work through to make a Delete[Entity]Action,
|
||||
// call that, and store it for later. Then, when this action is called again
|
||||
// (i.e. a redo), instead of creating yet another entity, we call the deleteAction.undoAction.
|
||||
if (this.deleteAction===null) { this.entity.remove(this.setAction); }
|
||||
this.deleteAction.doAction();
|
||||
this.markClean();
|
||||
return this.SUCCESS;
|
||||
},
|
||||
|
||||
setAction: function(action) {
|
||||
// summary: Set the associated delete action (see undoAction for explanation).
|
||||
deleteAction = action;
|
||||
}
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// End of module
|
||||
setAction: function(action) {
|
||||
// summary: Set the associated delete action (see undoAction for explanation).
|
||||
deleteAction = action;
|
||||
}
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// End of module
|
||||
});
|
||||
|
||||
@@ -3,47 +3,47 @@
|
||||
define(['dojo/_base/declare', 'iD/actions/UndoableAction'],
|
||||
function(declare) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// CreatePOIAction class
|
||||
// ----------------------------------------------------------------------
|
||||
// CreatePOIAction class
|
||||
|
||||
declare("iD.actions.CreatePOIAction", [iD.actions.CompositeUndoableAction], {
|
||||
declare("iD.actions.CreatePOIAction", [iD.actions.CompositeUndoableAction], {
|
||||
|
||||
newNode: null,
|
||||
tags: null,
|
||||
lat: NaN,
|
||||
lon: NaN,
|
||||
connection: null,
|
||||
newNode: null,
|
||||
tags: null,
|
||||
lat: NaN,
|
||||
lon: NaN,
|
||||
connection: null,
|
||||
|
||||
constructor: function(connection, tags, lat, lon) {
|
||||
// summary: Create a new node and set it as a POI. Used by drag-and-drop. Note that the
|
||||
// node is remembered, so that on redo we can just reinstate it.
|
||||
this.setName('Create POI: ' + iD.Util.friendlyName(tags));
|
||||
this.connection = connection;
|
||||
this.tags = tags;
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
},
|
||||
constructor: function(connection, tags, lat, lon) {
|
||||
// summary: Create a new node and set it as a POI. Used by drag-and-drop. Note that the
|
||||
// node is remembered, so that on redo we can just reinstate it.
|
||||
this.setName('Create POI: ' + iD.Util.friendlyName(tags));
|
||||
this.connection = connection;
|
||||
this.tags = tags;
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
},
|
||||
|
||||
run: function() {
|
||||
if (this.newNode === null) {
|
||||
this.newNode = this.connection.doCreateNode(this.tags,
|
||||
this.lat, this.lon,
|
||||
_.bind(this.push, this));
|
||||
}
|
||||
this.connection.registerPOI(this.newNode);
|
||||
return true;
|
||||
},
|
||||
run: function() {
|
||||
if (this.newNode === null) {
|
||||
this.newNode = this.connection.doCreateNode(this.tags,
|
||||
this.lat, this.lon,
|
||||
_.bind(this.push, this));
|
||||
}
|
||||
this.connection.registerPOI(this.newNode);
|
||||
return true;
|
||||
},
|
||||
|
||||
undo: function() {
|
||||
this.connection.unregisterPOI(this.newNode);
|
||||
return true;
|
||||
},
|
||||
undo: function() {
|
||||
this.connection.unregisterPOI(this.newNode);
|
||||
return true;
|
||||
},
|
||||
|
||||
getNode: function() {
|
||||
return this.newNode;
|
||||
}
|
||||
});
|
||||
getNode: function() {
|
||||
return this.newNode;
|
||||
}
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// End of module
|
||||
});
|
||||
// ----------------------------------------------------------------------
|
||||
// End of module
|
||||
});
|
||||
|
||||
@@ -3,60 +3,60 @@
|
||||
define(['dojo/_base/declare','iD/actions/UndoableAction'],
|
||||
function(declare) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// MoveNodeAction class
|
||||
// ----------------------------------------------------------------------
|
||||
// MoveNodeAction class
|
||||
|
||||
declare("iD.actions.MoveNodeAction", [iD.actions.UndoableEntityAction], {
|
||||
declare("iD.actions.MoveNodeAction", [iD.actions.UndoableEntityAction], {
|
||||
|
||||
createTime: NaN,
|
||||
oldLat: NaN,
|
||||
oldLon: NaN,
|
||||
newLat: NaN,
|
||||
newLon: NaN,
|
||||
setLatLon: null,
|
||||
createTime: NaN,
|
||||
oldLat: NaN,
|
||||
oldLon: NaN,
|
||||
newLat: NaN,
|
||||
newLon: NaN,
|
||||
setLatLon: null,
|
||||
|
||||
constructor: function(node, newLat, newLon, setLatLon) {
|
||||
// summary: Move a node to a new position.
|
||||
this.entity = node;
|
||||
this.newLat = newLat;
|
||||
this.newLon = newLon;
|
||||
this.setLatLon = setLatLon;
|
||||
this.createTime = new Date().getTime();
|
||||
},
|
||||
constructor: function(node, newLat, newLon, setLatLon) {
|
||||
// summary: Move a node to a new position.
|
||||
this.entity = node;
|
||||
this.newLat = newLat;
|
||||
this.newLon = newLon;
|
||||
this.setLatLon = setLatLon;
|
||||
this.createTime = new Date().getTime();
|
||||
},
|
||||
|
||||
run: function() {
|
||||
var node = this.entity;
|
||||
this.oldLat = node.lat;
|
||||
this.oldLon = node.lon;
|
||||
if (this.oldLat === this.newLat &&
|
||||
this.oldLon === this.newLon) {
|
||||
return NO_CHANGE;
|
||||
}
|
||||
this.setLatLon(this.newLat, this.newLon);
|
||||
this.markDirty();
|
||||
node.refresh();
|
||||
return true;
|
||||
},
|
||||
run: function() {
|
||||
var node = this.entity;
|
||||
this.oldLat = node.lat;
|
||||
this.oldLon = node.lon;
|
||||
if (this.oldLat === this.newLat &&
|
||||
this.oldLon === this.newLon) {
|
||||
return NO_CHANGE;
|
||||
}
|
||||
this.setLatLon(this.newLat, this.newLon);
|
||||
this.markDirty();
|
||||
node.refresh();
|
||||
return true;
|
||||
},
|
||||
|
||||
undo: function() {
|
||||
this.setLatLon(this.oldLat, this.oldLon);
|
||||
this.markClean();
|
||||
this.refresh();
|
||||
return true;
|
||||
},
|
||||
undo: function() {
|
||||
this.setLatLon(this.oldLat, this.oldLon);
|
||||
this.markClean();
|
||||
this.refresh();
|
||||
return true;
|
||||
},
|
||||
|
||||
mergePrevious: function(prev) {
|
||||
if (prev.declaredClass!=this.declaredClass) { return false; }
|
||||
|
||||
if (prev.entity == this.entity && prev.createTime+1000>this.createTime) {
|
||||
this.oldLat = prev.oldLat;
|
||||
this.oldLon = prev.oldLon;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
mergePrevious: function(prev) {
|
||||
if (prev.declaredClass!=this.declaredClass) { return false; }
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// End of module
|
||||
});
|
||||
if (prev.entity == this.entity && prev.createTime+1000>this.createTime) {
|
||||
this.oldLat = prev.oldLat;
|
||||
this.oldLon = prev.oldLon;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// End of module
|
||||
});
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
// iD/tags/PresetList.js
|
||||
// List of presets for a given type (e.g. nodes, ways)
|
||||
|
||||
define(['dojo/_base/declare'], function(declare) {
|
||||
|
||||
declare("iD.tags.PresetList", null, {
|
||||
|
||||
entityType: null,
|
||||
presets: null,
|
||||
|
||||
constructor:function(type, url) {
|
||||
// summary: List of presets for a given type (e.g. nodes, ways)
|
||||
this.entityType = type;
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: _.bind(this.loaded, this),
|
||||
error: function(err) { console.log("Couldn't load presets for " + type); }
|
||||
});
|
||||
},
|
||||
|
||||
loaded: function(obj) {
|
||||
this.presets = obj;
|
||||
// console.log("Loaded presets for " + this.entityType);
|
||||
},
|
||||
|
||||
// This entity has all of the same tags as props, with all of the same
|
||||
// values. It may have additional tags that are not in props.
|
||||
matchesTags: function(entity, props) {
|
||||
for (var k in props) {
|
||||
if (!entity.tags[k] || entity.tags[k] !== props[k]) return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
assembleEditorsForEntity:function(entity) {
|
||||
if (entity.entityType != this.entityType) return false;
|
||||
|
||||
var presetList = {};
|
||||
var editorList = [];
|
||||
for (var group in this.presets) {
|
||||
for (var preset in this.presets[group]) {
|
||||
var props = this.presets[group][preset];
|
||||
if (this.matchesTags(entity, props.tags)) {
|
||||
presetList[preset] = props;
|
||||
for (var i in props.edtors) {
|
||||
var editor = props.editors[i];
|
||||
if (editorList.indexOf(editor) === -1) {
|
||||
editorList.push(editor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
presets: presetList,
|
||||
editors: editorList
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// End of module
|
||||
});
|
||||
@@ -1,170 +0,0 @@
|
||||
// iD/tags/TagEditor.js
|
||||
|
||||
define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/xhr','dojo/dom-construct',
|
||||
'dijit/Dialog','dijit/form/Form','dijit/form/Button','dijit/form/TextBox'],
|
||||
function(declare,lang,xhr,domConstruct){
|
||||
|
||||
declare("iD.tags.TagEditor", null, {
|
||||
|
||||
entity: null,
|
||||
controller: null,
|
||||
dialog: null,
|
||||
editorContainers: null, // hash of DOM nodes to put editors in
|
||||
|
||||
constructor: function(entity, controller) {
|
||||
// summary: Construct a tag editor dialog box.
|
||||
this.entity = entity;
|
||||
this.controller = controller;
|
||||
this.editorContainers = {};
|
||||
|
||||
// Create the dialog, and the form to put the editors in
|
||||
this.dialog = new dijit.Dialog({
|
||||
title: "Tags",
|
||||
content: "",
|
||||
style: "width: 300px" });
|
||||
|
||||
this.$content = $('<div id="tagform"></div>');
|
||||
this.render();
|
||||
|
||||
this.dialog.set('content', this.$content[0]);
|
||||
this.dialog.show();
|
||||
|
||||
/*
|
||||
// What editors are relevant?
|
||||
var presetList = this.controller.presets[entity.entityType],
|
||||
applicablePresets = presetList.assembleEditorsForEntity(entity),
|
||||
i;
|
||||
|
||||
// Add preset types
|
||||
for (i in applicablePresets.presets) {
|
||||
this.appendPreset(i, applicablePresets.presets[i], form.domNode);
|
||||
}
|
||||
|
||||
// Add each editor
|
||||
for (i in applicablePresets.editors) {
|
||||
this.appendEditor(applicablePresets.editors[i], form.domNode);
|
||||
}
|
||||
*/
|
||||
},
|
||||
|
||||
// ------------
|
||||
// Presets
|
||||
|
||||
render: function() {
|
||||
this.$content.empty();
|
||||
// TODO: optimize
|
||||
if (!$('#datalists').size()) {
|
||||
$(document.body).append('<div id="datalists"></div>');
|
||||
}
|
||||
_.each(this.entity.tags, _.bind(function(value, key) {
|
||||
var row = $('<div></div>'),
|
||||
keyid = 'key-' + key;
|
||||
|
||||
$('<input></input>')
|
||||
.val(key)
|
||||
.attr({
|
||||
'class': 'key'
|
||||
}).appendTo(row);
|
||||
|
||||
$('<input></input>')
|
||||
.val(value)
|
||||
.attr({
|
||||
'list': keyid,
|
||||
'class': 'value'
|
||||
}).appendTo(row);
|
||||
|
||||
// Share datalists between same-keys
|
||||
if (!$('datalist#' + keyid).size()) {
|
||||
iD.Taginfo.values(key, function(values) {
|
||||
|
||||
var $dl = $('<datalist></datalist>')
|
||||
.attr('id', keyid);
|
||||
|
||||
_.each(values, function(v) {
|
||||
$dl.append($('<option></option>')
|
||||
.attr('value', v.value));
|
||||
});
|
||||
|
||||
$('#datalists').append($dl);
|
||||
});
|
||||
}
|
||||
|
||||
this.$content.append(row);
|
||||
}, this));
|
||||
},
|
||||
|
||||
appendPreset:function(name, preset, destination) {
|
||||
var element = domConstruct.create('h2');
|
||||
element.appendChild(domConstruct.create('img', {
|
||||
src: 'presets/' + preset.icon
|
||||
}));
|
||||
element.appendChild(dojo.doc.createTextNode(name));
|
||||
destination.appendChild(element);
|
||||
},
|
||||
|
||||
// ------------
|
||||
// Editors
|
||||
|
||||
appendEditor:function(editor, destination) {
|
||||
// summary: Request an editor (cached if available, XHR if not), and call renderEditor when it's available.
|
||||
if (this.controller.editorCache[editor]) {
|
||||
this.renderEditor(editor, destination);
|
||||
} else {
|
||||
$.ajax({
|
||||
url: "presets/editors/" + editor + ".json",
|
||||
// TODO: eliminate lang.hitch here
|
||||
success: lang.hitch(this, this.loadedEditor, editor, destination),
|
||||
error: function(err) {
|
||||
// console.log("Couldn't load editor");
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
loadedEditor: function(editor, destination, obj) {
|
||||
// summary: Editor has loaded via XHR, so store it in the cache and render it.
|
||||
this.controller.editorCache[editor] = obj;
|
||||
this.renderEditor(editor, destination);
|
||||
},
|
||||
|
||||
renderEditor: function(editor_name, destination) {
|
||||
// summary: Render an editor as a form.
|
||||
editor = this.controller.editorCache[editor_name];
|
||||
|
||||
// Add the subhead
|
||||
var element = domConstruct.create('h3');
|
||||
element.appendChild(dojo.doc.createTextNode(editor));
|
||||
destination.appendChild(element);
|
||||
|
||||
// Add each form element
|
||||
// this.$content
|
||||
for (var label in editor) {
|
||||
var item = editor[label];
|
||||
var value = this.getTagValue(item.key);
|
||||
element = domConstruct.create('div');
|
||||
switch (item.type) {
|
||||
case 'text':
|
||||
var textbox = new dijit.form.TextBox({
|
||||
name: item.key,
|
||||
value: value,
|
||||
type: 'text'
|
||||
}, domConstruct.create('input'));
|
||||
element.appendChild(dojo.doc.createTextNode(label));
|
||||
element.appendChild(textbox.domNode);
|
||||
break;
|
||||
case 'dropdown':
|
||||
case 'relation':
|
||||
case 'hidden':
|
||||
}
|
||||
destination.appendChild(element);
|
||||
}
|
||||
// var submitbtn = new dijit.form.Button({ name: 'submit', type: 'submit', value: 'Submit', label: "Submit" }, dojo.doc.createElement('button'));
|
||||
// var resetbtn = new dijit.form.Button({ type: 'reset', label: 'Reset' }, dojo.doc.createElement('button'));
|
||||
// _destination.appendChild(submitbtn.domNode);
|
||||
// _destination.appendChild(resetbtn.domNode);
|
||||
}
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// End of module
|
||||
});
|
||||
Reference in New Issue
Block a user