Posted on 01/12/2014 16:28:16
Right after asking you for further details I got an idea for how to do something like what you're trying to do (I think).
Create a custom item field editor like this:
using Dynamicweb.Content.Items.Annotations;
using Dynamicweb.Content.Items.Editors;
using System;
using System.Web;
namespace CustomHead.ItemFieldEditors
{
[Editor("Forum thread 38790")]
public class ForumThread_38790 : Editor
{
public override Type DataType
{
get { return typeof(string); }
}
public override void BeginEdit(EditorContext context)
{
if (context != null && context.Output != null)
{
var value = context.Value != null ? context.Value.ToString() : string.Empty;
var content = new System.Text.StringBuilder();
content.AppendFormat(@"<textarea id='{0}' name='{0}' rows='20' cols='80'>{1}</textarea>", System.Net.WebUtility.HtmlEncode(Key), System.Net.WebUtility.HtmlEncode(value));
content.AppendFormat("<script src='/Files/System/ItemFieldEditors/{0}.js'></script>", GetType().Name);
content.AppendFormat("<script>try {{ new {0}({1}) }} catch (ex) {{}}</script>", GetType().Name, Newtonsoft.Json.JsonConvert.SerializeObject(new
{
id = Key
}));
context.Output.Write(content);
}
}
public override object EndEdit()
{
return HttpContext.Request[Key];
}
}
}
Then in /Files/System/ItemFieldEditors/ForumThread_38790.js, i.e. the JavaScript library included by the this field editor, you can add something like
if (typeof ForumThread_38790 == 'undefined') {
var parentData = (function() {
var parentData = null;
if (parent != self) {
parentData = {
page: parent.Dynamicweb.Items.ItemEdit.get_current().get_page(),
item: parent.Dynamicweb.Items.ItemEdit.get_current().get_item()
};
var i, el, elements = parent.document.querySelectorAll('.item-field');
for (i = 0; el = elements[i]; i++) {
parentData[el.name] = el.value;
}
}
return parentData;
}()),
ForumThread_38790 = function(config) {
config || (config = {});
var el, data = {}, id = config.id;
if (id) {
el = document.getElementById(id);
if (el) {
try {
data = JSON.parse(el.value);
} catch (ex) {}
el.value = JSON.stringify({ id : id, parentData: parentData }, null, 2);
// @TODO Build UI for editing data and put it back into el.value
alert(JSON.stringify({
id: id,
value: el.value,
data: data
}, null, 2));
}
}
};
}
Then you just – and that's the tricky part – have to create the UI for adding/editing an image map area and serialize the data back into the actual control.
This is just a sketch, but I hope it makes sense and is useful.
Best regards,
Mikkel