1
0
Fork 0
forked from 0x2620/oxjs

- remove editItem from Ox.List

- use ArrayEditable for text too
This commit is contained in:
j 2012-01-04 22:57:32 +05:30
commit 093edd57d0
12 changed files with 180 additions and 403 deletions

View file

@ -26,7 +26,7 @@ Ox.AnnotationPanel = function(options, self) {
id: '',
items: [],
range: 'all',
selected: -1,
selected: '',
sort: 'position',
title: '',
type: 'text',
@ -78,12 +78,13 @@ Ox.AnnotationPanel = function(options, self) {
self.$annotations = Ox.Element();
} else if (self.options.type == 'place') {
self.$annotations = Ox.Element();
} else if (self.options.type == 'string') {
} else if (['string', 'text'].indexOf(self.options.type) > -1) {
self.$annotations = Ox.ArrayEditable({
editable: self.options.editable,
items: getAnnotations(),
sort: self.sort,
width: pandora.user.ui.annotationsSize - Ox.UI.SCROLLBAR_SIZE
width: self.options.width,
type: self.options.type == 'text' ? 'textarea' : 'input'
})
.bindEvent({
add: function(data) {
@ -94,63 +95,11 @@ Ox.AnnotationPanel = function(options, self) {
'delete': function(data) {
that.triggerEvent('remove', {id: data.id});
},
select: function(data) {
selectAnnotation({ids: [data.id]});
},
submit: updateAnnotation
});
} else if (self.options.type == 'text') {
self.$annotations = Ox.List({
construct: function(data) {
var $item = Ox.Element()
.addClass('OxAnnotation OxTarget')
.css({padding: '4px 4px 0 4px'})
.append(
Ox.Editable({
type: 'textarea',
width: self.options.width - 8,
value: data.value
})
.bindEvent({
edit: function() {
$item.removeClass('OxTarget');
},
submit: function(newData) {
$item.addClass('OxTarget');
updateAnnotation({
id: data.id,
value: newData.value
});
}
})
)
.append($('<div>').css({height: '4px'}));
return $item;
},
items: getAnnotations(),
max: 1,
min: 0,
sort: self.sort,
type: 'none', // fixme
unique: 'id'
})
.bindEvent({
cancel: function(item) {
//reset in/out points
selectAnnotation({ids: [item.id]});
},
open: function(data) {
return;
if (data.ids.length == 1) {
var pos = Ox.getIndexById(self.$annotations.options('items'), data.ids[0]);
self.$annotations.editItem(pos);
}
},
'delete': function(data) {
that.triggerEvent('remove', {id: data.ids[0]});
edit: function(data) {
that.triggerEvent('edit', data);
},
select: selectAnnotation,
submit: updateAnnotation
submit: editAnnotation
});
}
self.$annotations.appendTo(that.$content);
@ -185,15 +134,17 @@ Ox.AnnotationPanel = function(options, self) {
}
function selectAnnotation(data) {
var item = Ox.getObjectById(self.options.items, data.ids[0]);
item && that.triggerEvent('select', {
var item = Ox.getObjectById(self.options.items, data.id);
that.triggerEvent('select', Ox.extend({
id: data.id
}, item ? {
'in': item['in'],
'out': item.out,
'layer': self.options.id
});
out: item.out,
layer: self.options.id
} : {}));
}
function updateAnnotation(data) {
function editAnnotation(data) {
var item = Ox.getObjectById(self.options.items, data.id);
item.value = data.value;
that.triggerEvent('submit', item);
@ -221,7 +172,7 @@ Ox.AnnotationPanel = function(options, self) {
items: getAnnotations()
});
} else if (key == 'sort') {
self.$annotations.options({sort: value});
self.$annotations.options('sort', value);
}
};
@ -231,11 +182,7 @@ Ox.AnnotationPanel = function(options, self) {
that.addItem = function(item) {
var pos = 0;
self.options.items.splice(pos, 0, item);
if (self.$annotations.addItem) {
self.$annotations.addItem(pos, item);
} else {
self.$annotations.addItems(pos, [item]);
}
self.$annotations.addItem(pos, item);
self.$annotations.editItem(pos);
};
@ -243,7 +190,7 @@ Ox.AnnotationPanel = function(options, self) {
deselectItems <f> deselectItems
@*/
that.deselectItems = function() {
self.$annotations.options('selected', []);
self.$annotations.options('selected', '');
};
/*@