add support for data annotations
This commit is contained in:
parent
33a7832d64
commit
8243614546
5 changed files with 77 additions and 34 deletions
|
|
@ -75,7 +75,7 @@ Ox.ArrayEditable = function(options, self) {
|
||||||
width: function() {
|
width: function() {
|
||||||
var width = self.options.width;
|
var width = self.options.width;
|
||||||
that.css({width: width - 8 + 'px'}); // 2 x 4 px padding
|
that.css({width: width - 8 + 'px'}); // 2 x 4 px padding
|
||||||
self.options.type == 'textarea' && self.$items.forEach(function($item) {
|
self.options.type != 'input' && self.$items.forEach(function($item) {
|
||||||
$item.options({width: width})
|
$item.options({width: width})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ Ox.Editable = function(options, self) {
|
||||||
|
|
||||||
self = self || {};
|
self = self || {};
|
||||||
var that = Ox.Element({
|
var that = Ox.Element({
|
||||||
element: options.type == 'textarea' ? '<div>' : '<span>',
|
element: options.type == 'input' ? '<span>' : '<div>',
|
||||||
tooltip: options.tooltip
|
tooltip: options.tooltip
|
||||||
}, self)
|
}, self)
|
||||||
.defaults({
|
.defaults({
|
||||||
|
|
@ -94,7 +94,9 @@ Ox.Editable = function(options, self) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (self.options.type != 'data') {
|
||||||
self.options.value = self.options.value.toString();
|
self.options.value = self.options.value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
self.css = {};
|
self.css = {};
|
||||||
self.$value = Ox.Element(self.options.type == 'input' ? '<span>' : '<div>')
|
self.$value = Ox.Element(self.options.type == 'input' ? '<span>' : '<div>')
|
||||||
|
|
@ -159,7 +161,7 @@ Ox.Editable = function(options, self) {
|
||||||
changeOnKeypress: true,
|
changeOnKeypress: true,
|
||||||
element: self.options.type == 'input' ? '<span>' : '<div>',
|
element: self.options.type == 'input' ? '<span>' : '<div>',
|
||||||
style: 'square',
|
style: 'square',
|
||||||
type: self.options.type,
|
type: getInputType(),
|
||||||
value: formatInputValue()
|
value: formatInputValue()
|
||||||
})
|
})
|
||||||
.css(self.css)
|
.css(self.css)
|
||||||
|
|
@ -203,14 +205,15 @@ Ox.Editable = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatInputValue() {
|
function formatInputValue() {
|
||||||
return self.options.type == 'input'
|
return self.options.unformat
|
||||||
? (self.options.unformat || Ox.decodeHTMLEntities)(self.options.value)
|
? self.options.unformat(self.options.value)
|
||||||
|
: self.options.type == 'input' ? Ox.decodeHTMLEntities(self.options.value)
|
||||||
: self.options.value.replace(/<br\/?><br\/?>/g, '\n\n');
|
: self.options.value.replace(/<br\/?><br\/?>/g, '\n\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatTestValue() {
|
function formatTestValue() {
|
||||||
var value = Ox.encodeHTMLEntities(
|
var value = Ox.encodeHTMLEntities(
|
||||||
(self.options.unformat || Ox.identity)(self.$input.options('value'))
|
(self.options.type != 'data' && self.options.unformat || Ox.identity)(self.$input.options('value'))
|
||||||
);
|
);
|
||||||
return !value ? ' '
|
return !value ? ' '
|
||||||
: self.options.type == 'input'
|
: self.options.type == 'input'
|
||||||
|
|
@ -247,7 +250,9 @@ Ox.Editable = function(options, self) {
|
||||||
self.$input.value().replace(/\n\n+/g, '\0')
|
self.$input.value().replace(/\n\n+/g, '\0')
|
||||||
).replace(/\0/g, '\n\n').trim();
|
).replace(/\0/g, '\n\n').trim();
|
||||||
return (
|
return (
|
||||||
self.options.type == 'input'
|
self.options.type == 'data'
|
||||||
|
? JSON.parse(value)
|
||||||
|
: self.options.type == 'input'
|
||||||
? Ox.encodeHTMLEntities(value)
|
? Ox.encodeHTMLEntities(value)
|
||||||
: Ox.sanitizeHTML(value, self.options.tags, self.options.globalAttributes)
|
: Ox.sanitizeHTML(value, self.options.tags, self.options.globalAttributes)
|
||||||
);
|
);
|
||||||
|
|
@ -265,7 +270,7 @@ Ox.Editable = function(options, self) {
|
||||||
height = self.options.height || Ox.limit(self.$test.height(), self.minHeight, self.maxHeight);
|
height = self.options.height || Ox.limit(self.$test.height(), self.minHeight, self.maxHeight);
|
||||||
width = self.$test.width();
|
width = self.$test.width();
|
||||||
// +Ox.UI.SCROLLBAR_SIZE to prevent scrollbar from showing up
|
// +Ox.UI.SCROLLBAR_SIZE to prevent scrollbar from showing up
|
||||||
if (self.options.type == 'textarea') {
|
if (self.options.type != 'input') {
|
||||||
width += Ox.UI.SCROLLBAR_SIZE;
|
width += Ox.UI.SCROLLBAR_SIZE;
|
||||||
}
|
}
|
||||||
width = self.options.width || Ox.limit(width, self.minWidth, self.maxWidth);
|
width = self.options.width || Ox.limit(width, self.minWidth, self.maxWidth);
|
||||||
|
|
@ -280,12 +285,16 @@ Ox.Editable = function(options, self) {
|
||||||
width: width,
|
width: width,
|
||||||
height: height
|
height: height
|
||||||
});
|
});
|
||||||
self.$input.find(self.options.type).css({
|
self.$input.find(getInputType()).css({
|
||||||
width: width + 'px',
|
width: width + 'px',
|
||||||
height: height + 'px'
|
height: height + 'px'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getInputType() {
|
||||||
|
return self.options.type == 'data' ? 'textarea' : self.options.type
|
||||||
|
}
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
self.options.editing = false;
|
self.options.editing = false;
|
||||||
that.removeClass('OxEditing');
|
that.removeClass('OxEditing');
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
self.$widget.options({width: self.options.width});
|
self.$widget.options({width: self.options.width});
|
||||||
}
|
}
|
||||||
self.$annotations.options({
|
self.$annotations.options({
|
||||||
width: self.options.type == 'text'
|
width: isTextType(self.options.type)
|
||||||
? self.options.width + 8
|
? self.options.width + 8
|
||||||
: self.options.width
|
: self.options.width
|
||||||
});
|
});
|
||||||
|
|
@ -284,7 +284,7 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
clickLink: self.options.clickLink,
|
clickLink: self.options.clickLink,
|
||||||
confirmDeleteDialog: self.options.confirmDeleteDialog,
|
confirmDeleteDialog: self.options.confirmDeleteDialog,
|
||||||
editable: self.options.editable,
|
editable: self.options.editable,
|
||||||
getSortValue: self.options.type == 'text'
|
getSortValue: isTextType(self.options.type)
|
||||||
? function(value) {
|
? function(value) {
|
||||||
return Ox.stripTags(value);
|
return Ox.stripTags(value);
|
||||||
}
|
}
|
||||||
|
|
@ -301,8 +301,24 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
+ Ox.formatDate(item.modified.slice(0, 10), '%B %e, %Y');
|
+ Ox.formatDate(item.modified.slice(0, 10), '%B %e, %Y');
|
||||||
} : '',
|
} : '',
|
||||||
width: self.options.width,
|
width: self.options.width,
|
||||||
maxHeight: self.options.type == 'text' ? Infinity : void 0,
|
maxHeight: isTextType(self.options.type) ? Infinity : void 0,
|
||||||
type: self.options.type == 'text' ? 'textarea' : 'input'
|
type: self.options.type == 'data' ? 'data' : self.options.type == 'text' ? 'textarea' : 'input',
|
||||||
|
format: self.options.type == 'data' ? function(value) {
|
||||||
|
return Ox.TreeList({
|
||||||
|
data: value,
|
||||||
|
width: self.options.width
|
||||||
|
}).css({
|
||||||
|
minHeight: '256px',
|
||||||
|
});
|
||||||
|
} : self.options.translate ? function(value) {
|
||||||
|
return Ox._(value);
|
||||||
|
} : null,
|
||||||
|
unformat: function(value) {
|
||||||
|
if (self.options.type == 'data') {
|
||||||
|
return JSON.stringify(value, null, " ");
|
||||||
|
}
|
||||||
|
return Ox.decodeHTMLEntities(Ox.stripTags(value));
|
||||||
|
}
|
||||||
}, self.options.autocomplete ? {
|
}, self.options.autocomplete ? {
|
||||||
autocomplete: function(value, callback) {
|
autocomplete: function(value, callback) {
|
||||||
self.options.autocomplete(self.options.id, value, callback);
|
self.options.autocomplete(self.options.id, value, callback);
|
||||||
|
|
@ -313,14 +329,9 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
autocompleteSelectHighlight: true,
|
autocompleteSelectHighlight: true,
|
||||||
autocompleteSelectMaxWidth: 256,
|
autocompleteSelectMaxWidth: 256,
|
||||||
autocompleteSelectOffset: {left: 0, top: 0},
|
autocompleteSelectOffset: {left: 0, top: 0},
|
||||||
autocompleteSelectUpdate: true,
|
autocompleteSelectUpdate: true
|
||||||
format: self.options.translate ? function(value) {
|
} : {
|
||||||
return Ox._(value);
|
}))
|
||||||
} : null,
|
|
||||||
unformat: function(value) {
|
|
||||||
return Ox.decodeHTMLEntities(Ox.stripTags(value));
|
|
||||||
}
|
|
||||||
} : {}))
|
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
add: function(data) {
|
add: function(data) {
|
||||||
if (self.editing) {
|
if (self.editing) {
|
||||||
|
|
@ -548,8 +559,8 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
|
|
||||||
function getSort() {
|
function getSort() {
|
||||||
return ({
|
return ({
|
||||||
duration: ['-duration', '+in', self.options.type == 'text' ? '+created' : '+value'],
|
duration: ['-duration', '+in', isTextType(self.options.type) ? '+created' : '+value'],
|
||||||
position: ['+in', '+duration', self.options.type == 'text' ? '+created' : '+value'],
|
position: ['+in', '+duration', isTextType(self.options.type) ? '+created' : '+value'],
|
||||||
text: ['+value', '+in', '+duration'],
|
text: ['+value', '+in', '+duration'],
|
||||||
created: ['+created', '+in', '+duration', '+value']
|
created: ['+created', '+in', '+duration', '+value']
|
||||||
})[self.options.sort];
|
})[self.options.sort];
|
||||||
|
|
@ -560,6 +571,10 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
&& !!item[self.options.type].type;
|
&& !!item[self.options.type].type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isTextType(type) {
|
||||||
|
return ['text', 'data'].includes(type);
|
||||||
|
}
|
||||||
|
|
||||||
function removeAnnotation(data) {
|
function removeAnnotation(data) {
|
||||||
var item;
|
var item;
|
||||||
self.editing = false;
|
self.editing = false;
|
||||||
|
|
|
||||||
|
|
@ -247,13 +247,13 @@ Ox.AnnotationPanel = function(options, self) {
|
||||||
if (annotation && folder) {
|
if (annotation && folder) {
|
||||||
key = folder.options('id');
|
key = folder.options('id');
|
||||||
type = folder.options('type');
|
type = folder.options('type');
|
||||||
value = annotation.entity ? annotation.entity.name : annotation.value;
|
value = type == 'data' ? '' : annotation.entity ? annotation.entity.name : annotation.value;
|
||||||
isEditable = annotation.editable;
|
isEditable = annotation.editable;
|
||||||
isEntity = !!annotation.entity;
|
isEntity = !!annotation.entity;
|
||||||
isEvent = type == 'event';
|
isEvent = type == 'event';
|
||||||
isPlace = type == 'place';
|
isPlace = type == 'place';
|
||||||
isEventOrPlace = isEvent || isPlace;
|
isEventOrPlace = isEvent || isPlace;
|
||||||
isString = type != 'text';
|
isString = type != 'text' && type != 'data';
|
||||||
// fixme: absence of annotation[type] may be an error
|
// fixme: absence of annotation[type] may be an error
|
||||||
isDefined = isEventOrPlace && !!annotation[type] && !!annotation[type].type;
|
isDefined = isEventOrPlace && !!annotation[type] && !!annotation[type].type;
|
||||||
annotationTitle = folder.options('item') + ': "' + Ox.stripTags(value) + '"';
|
annotationTitle = folder.options('item') + ': "' + Ox.stripTags(value) + '"';
|
||||||
|
|
|
||||||
|
|
@ -1069,10 +1069,16 @@ Ox.VideoAnnotationPanel = function(options, self) {
|
||||||
if (query.length) {
|
if (query.length) {
|
||||||
query = query.toLowerCase();
|
query = query.toLowerCase();
|
||||||
results = self.annotations.filter(function(annotation) {
|
results = self.annotations.filter(function(annotation) {
|
||||||
|
let value = annotation.value
|
||||||
|
if (!value.toLowerCase && value.toString) {
|
||||||
|
value = value.toString()
|
||||||
|
}
|
||||||
|
if (value.toLowerCase) {
|
||||||
return Ox.contains(['*', annotation.layer], self.options.findLayer)
|
return Ox.contains(['*', annotation.layer], self.options.findLayer)
|
||||||
&& Ox.decodeHTMLEntities(Ox.stripTags(
|
&& Ox.decodeHTMLEntities(Ox.stripTags(
|
||||||
annotation.value.toLowerCase()
|
value.toLowerCase()
|
||||||
)).indexOf(query) > -1;
|
)).indexOf(query) > -1;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
|
|
@ -1119,6 +1125,9 @@ Ox.VideoAnnotationPanel = function(options, self) {
|
||||||
Ox.forEach(layer.items, function(item) {
|
Ox.forEach(layer.items, function(item) {
|
||||||
if (item.id == annotationId) {
|
if (item.id == annotationId) {
|
||||||
value = item.value;
|
value = item.value;
|
||||||
|
if (!value.toLowerCase && value.toString) {
|
||||||
|
value = value.toString()
|
||||||
|
}
|
||||||
found = true;
|
found = true;
|
||||||
return false; // break
|
return false; // break
|
||||||
}
|
}
|
||||||
|
|
@ -1276,9 +1285,15 @@ Ox.VideoAnnotationPanel = function(options, self) {
|
||||||
var words = [];
|
var words = [];
|
||||||
Ox.forEach(Ox.count(Ox.words(
|
Ox.forEach(Ox.count(Ox.words(
|
||||||
self.annotations.map(function(annotation) {
|
self.annotations.map(function(annotation) {
|
||||||
|
let value = annotation.value
|
||||||
|
if (!value.toLowerCase && value.toString) {
|
||||||
|
value = value.toString()
|
||||||
|
}
|
||||||
|
if (value.toLowerCase) {
|
||||||
return Ox.decodeHTMLEntities(
|
return Ox.decodeHTMLEntities(
|
||||||
Ox.stripTags(annotation.value.toLowerCase())
|
Ox.stripTags(value.toLowerCase())
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}).join(' ')
|
}).join(' ')
|
||||||
)), function(count, value) {
|
)), function(count, value) {
|
||||||
words.push({count: count, value: value});
|
words.push({count: count, value: value});
|
||||||
|
|
@ -1431,11 +1446,12 @@ Ox.VideoAnnotationPanel = function(options, self) {
|
||||||
position: self.options.position
|
position: self.options.position
|
||||||
});
|
});
|
||||||
if (self.editing && self.options.selected.length && self.options.selected[0] != '_') {
|
if (self.editing && self.options.selected.length && self.options.selected[0] != '_') {
|
||||||
|
let value = $('.OxEditableElement input:visible').val()
|
||||||
that.triggerEvent('editannotation', {
|
that.triggerEvent('editannotation', {
|
||||||
id: self.options.selected,
|
id: self.options.selected,
|
||||||
'in': self.options['in'],
|
'in': self.options['in'],
|
||||||
out: self.options.out,
|
out: self.options.out,
|
||||||
value: $('.OxEditableElement input:visible').val()
|
value: value
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1568,6 +1584,9 @@ Ox.VideoAnnotationPanel = function(options, self) {
|
||||||
}
|
}
|
||||||
data['in'] = self.options['in'];
|
data['in'] = self.options['in'];
|
||||||
data.out = self.options.out;
|
data.out = self.options.out;
|
||||||
|
if (data.layer == 'data' && Ox.isString(data.value)) {
|
||||||
|
data.value = JSON.parse(data.value)
|
||||||
|
}
|
||||||
that.triggerEvent('editannotation', data);
|
that.triggerEvent('editannotation', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue