2012-01-03 10:25:15 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/*@
|
2012-05-31 10:32:54 +00:00
|
|
|
Ox.ArrayEditable <f> Array Editable
|
2012-07-04 11:29:18 +00:00
|
|
|
options <o> Options object
|
|
|
|
self <o> Shared private variable
|
2012-05-31 10:32:54 +00:00
|
|
|
([options[, self]]) -> <o:Ox.Element> Array Editable
|
2012-06-17 22:38:26 +00:00
|
|
|
add <!> add
|
|
|
|
blur <!> blur
|
|
|
|
change <!> change
|
|
|
|
delete <!> delete
|
|
|
|
edit <!> edit
|
|
|
|
insert <!> insert
|
|
|
|
open <!> open
|
2013-05-08 16:53:33 +00:00
|
|
|
selectnext <!> selectnext
|
|
|
|
selectprevious <!> selectprevious
|
2012-06-17 22:38:26 +00:00
|
|
|
selectnone <!> selectnone
|
|
|
|
select <!> select
|
|
|
|
submit <!> submit
|
2012-01-03 10:25:15 +00:00
|
|
|
@*/
|
|
|
|
|
|
|
|
Ox.ArrayEditable = function(options, self) {
|
|
|
|
|
|
|
|
self = self || {};
|
2012-01-27 14:29:11 +00:00
|
|
|
var that = Ox.Element({}, self)
|
2012-01-03 10:25:15 +00:00
|
|
|
.defaults({
|
2012-01-17 15:43:46 +00:00
|
|
|
clickLink: null,
|
2012-01-03 10:25:15 +00:00
|
|
|
editable: true,
|
2014-12-16 20:23:17 +00:00
|
|
|
format: null,
|
2012-03-20 09:34:50 +00:00
|
|
|
getSortValue: null,
|
2013-12-26 16:43:03 +00:00
|
|
|
globalAttributes: [],
|
2012-02-01 05:21:29 +00:00
|
|
|
highlight: '',
|
2018-10-09 16:29:13 +00:00
|
|
|
highlightGroup: false,
|
2012-01-03 10:25:15 +00:00
|
|
|
itemName: 'item',
|
|
|
|
items: [],
|
2012-01-16 07:09:16 +00:00
|
|
|
maxHeight: void 0,
|
|
|
|
placeholder: '',
|
2012-01-03 10:25:15 +00:00
|
|
|
position: -1,
|
2012-01-03 19:41:50 +00:00
|
|
|
selected: '',
|
2012-01-16 07:09:16 +00:00
|
|
|
separator: ',',
|
2012-01-11 11:11:13 +00:00
|
|
|
sort: [],
|
2012-01-09 20:25:38 +00:00
|
|
|
submitOnBlur: true,
|
2012-02-22 10:14:25 +00:00
|
|
|
tooltipText: '',
|
2012-01-04 17:27:32 +00:00
|
|
|
type: 'input',
|
2014-12-16 20:38:41 +00:00
|
|
|
unformat: null,
|
2012-01-03 10:25:15 +00:00
|
|
|
width: 256
|
|
|
|
})
|
|
|
|
.options(options || {})
|
2016-04-29 15:21:38 +00:00
|
|
|
.options({tooltip: tooltip})
|
2012-05-28 19:35:41 +00:00
|
|
|
.update({
|
|
|
|
highlight: function() {
|
|
|
|
self.$items.forEach(function($item) {
|
|
|
|
$item.options({highlight: self.options.highlight})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
items: function() {
|
|
|
|
if (self.options.selected && getSelectedPosition() == -1) {
|
|
|
|
selectNone();
|
|
|
|
}
|
|
|
|
renderItems(true);
|
|
|
|
},
|
2013-03-08 11:12:03 +00:00
|
|
|
placeholder: function() {
|
|
|
|
if (self.options.items.length == 0) {
|
2014-02-04 07:56:36 +00:00
|
|
|
self.$items[0].options({
|
|
|
|
placeholder: self.options.placeholder,
|
|
|
|
value: ''
|
|
|
|
});
|
2013-03-08 11:12:03 +00:00
|
|
|
}
|
|
|
|
},
|
2012-05-28 19:35:41 +00:00
|
|
|
selected: function() {
|
|
|
|
selectItem(self.options.selected);
|
|
|
|
},
|
|
|
|
sort: renderItems,
|
|
|
|
width: function() {
|
|
|
|
var width = self.options.width;
|
|
|
|
that.css({width: width - 8 + 'px'}); // 2 x 4 px padding
|
|
|
|
self.options.type == 'textarea' && self.$items.forEach(function($item) {
|
|
|
|
$item.options({width: width})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
2012-01-10 14:49:28 +00:00
|
|
|
.addClass('OxArrayEditable OxArrayEditable' + Ox.toTitleCase(self.options.type))
|
2012-01-16 07:09:16 +00:00
|
|
|
.css({width: self.options.width - (self.options.type == 'input' ? 8 : 0) + 'px'}) // 2 x 4 px padding
|
2012-01-03 10:25:15 +00:00
|
|
|
.bindEvent({
|
2012-01-03 19:41:50 +00:00
|
|
|
key_delete: deleteItem,
|
2012-01-12 10:39:05 +00:00
|
|
|
key_enter: function() {
|
2012-01-16 11:22:34 +00:00
|
|
|
// make sure the newline does
|
|
|
|
// not end up in the textarea
|
|
|
|
setTimeout(function() {
|
2016-04-29 15:21:38 +00:00
|
|
|
that.editItem();
|
2012-01-16 11:22:34 +00:00
|
|
|
}, 0);
|
2012-01-12 10:39:05 +00:00
|
|
|
},
|
2012-01-03 19:41:50 +00:00
|
|
|
key_escape: selectNone,
|
2018-09-12 17:49:37 +00:00
|
|
|
key_down: self.options.type == 'input'
|
|
|
|
&& !Ox.contains(self.options.separator, '<br')
|
|
|
|
? selectLast : selectNext,
|
|
|
|
key_left: self.options.type == 'input'
|
|
|
|
&& !Ox.contains(self.options.separator, '<br')
|
|
|
|
? selectPrevious : selectFirst,
|
|
|
|
key_right: self.options.type == 'input'
|
|
|
|
&& !Ox.contains(self.options.separator, '<br')
|
|
|
|
? selectNext : selectLast,
|
|
|
|
key_up: self.options.type == 'input'
|
|
|
|
&& !Ox.contains(self.options.separator, '<br')
|
|
|
|
? selectFirst : selectPrevious,
|
2016-07-27 19:13:09 +00:00
|
|
|
singleclick: singleclick,
|
|
|
|
touchstart: singleclick
|
2012-01-03 10:25:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
self.$items = [];
|
2012-01-16 07:09:16 +00:00
|
|
|
self.editing = false;
|
2012-01-03 19:41:50 +00:00
|
|
|
|
|
|
|
renderItems();
|
|
|
|
|
2012-01-11 11:54:58 +00:00
|
|
|
self.selected = getSelectedPosition();
|
|
|
|
|
2012-01-03 19:41:50 +00:00
|
|
|
function deleteItem() {
|
2012-01-12 19:04:32 +00:00
|
|
|
if (self.options.editable) {
|
|
|
|
self.options.items.splice(self.selected, 1);
|
|
|
|
renderItems();
|
|
|
|
that.triggerEvent('delete', {
|
|
|
|
id: self.options.selected
|
|
|
|
});
|
2012-02-16 11:35:03 +00:00
|
|
|
self.editing = false;
|
2012-01-16 07:09:16 +00:00
|
|
|
self.selected = -1;
|
|
|
|
self.options.selected = '';
|
2012-01-12 19:04:32 +00:00
|
|
|
}
|
2012-01-03 19:41:50 +00:00
|
|
|
}
|
2012-01-03 10:25:15 +00:00
|
|
|
|
|
|
|
function doubleclick(e) {
|
2012-01-27 14:29:11 +00:00
|
|
|
// fixme: unused
|
2012-01-04 17:27:32 +00:00
|
|
|
var $target = $(e.target),
|
|
|
|
$parent = $target.parent();
|
2012-01-03 19:41:50 +00:00
|
|
|
if ($parent.is('.OxEditableElement')) {
|
2012-01-12 10:39:05 +00:00
|
|
|
that.editItem();
|
2012-01-12 19:04:32 +00:00
|
|
|
} else if (!$target.is('.OxInput')) {
|
2012-01-03 19:41:50 +00:00
|
|
|
that.triggerEvent('add');
|
2012-01-03 10:25:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-03 19:41:50 +00:00
|
|
|
function getSelectedId() {
|
|
|
|
return self.selected > -1 ? self.options.items[self.selected].id : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSelectedPosition() {
|
2012-01-04 08:11:05 +00:00
|
|
|
return Ox.getIndexById(self.options.items, self.options.selected);
|
2012-01-03 19:41:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 07:09:16 +00:00
|
|
|
function renderItems(blur) {
|
|
|
|
if (self.editing) {
|
|
|
|
self.options.items[getSelectedPosition()].value = that.find(self.options.type + ':visible').val();
|
|
|
|
}
|
2012-01-03 10:25:15 +00:00
|
|
|
that.empty();
|
2012-01-16 07:09:16 +00:00
|
|
|
if (self.options.items.length == 0) {
|
2016-05-04 10:17:56 +00:00
|
|
|
self.$items = [Ox.Editable({
|
2012-01-16 07:09:16 +00:00
|
|
|
editable: false,
|
2014-02-04 07:56:36 +00:00
|
|
|
placeholder: self.options.placeholder,
|
2012-01-27 14:29:11 +00:00
|
|
|
type: self.options.type,
|
2014-02-04 07:56:36 +00:00
|
|
|
value: ''
|
2012-01-16 07:09:16 +00:00
|
|
|
})
|
2016-05-04 10:17:56 +00:00
|
|
|
.appendTo(that)];
|
2012-01-16 07:09:16 +00:00
|
|
|
} else {
|
|
|
|
sortItems();
|
2018-10-09 16:29:13 +00:00
|
|
|
if (self.options.highlightGroup) {
|
|
|
|
var selectedItem = Ox.getObjectById(self.options.items, self.options.selected) || {};
|
|
|
|
}
|
2016-05-04 10:17:56 +00:00
|
|
|
self.$items = self.options.items.map(function appendItem(item, i) {
|
2012-01-16 07:09:16 +00:00
|
|
|
if (i && self.options.type == 'input') {
|
|
|
|
$('<span>')
|
|
|
|
.addClass('OxSeparator')
|
|
|
|
.html(self.options.separator + ' ')
|
|
|
|
.appendTo(that);
|
|
|
|
}
|
2016-05-04 10:17:56 +00:00
|
|
|
return Ox.Editable({
|
2014-12-16 13:02:18 +00:00
|
|
|
autocomplete: self.options.autocomplete,
|
|
|
|
autocompleteReplace: self.options.autocompleteReplace,
|
|
|
|
autocompleteReplaceCorrect: self.options.autocompleteReplaceCorrect,
|
|
|
|
autocompleteSelect: self.options.autocompleteSelect,
|
|
|
|
autocompleteSelectHighlight: self.options.autocompleteSelectHighlight,
|
|
|
|
autocompleteSelectMaxWidth: self.options.autocompleteSelectMaxWidth,
|
2014-12-17 15:38:16 +00:00
|
|
|
autocompleteSelectOffset: self.options.autocompleteSelectOffset,
|
2014-12-16 13:02:18 +00:00
|
|
|
autocompleteSelectSubmit: self.options.autocompleteSelectSubmit,
|
2014-12-17 15:38:16 +00:00
|
|
|
autocompleteSelectUpdate: self.options.autocompleteSelectUpdate,
|
2012-01-16 07:09:16 +00:00
|
|
|
blurred: self.editing && i == self.selected ? blur : false,
|
2012-01-17 15:43:46 +00:00
|
|
|
clickLink: self.options.clickLink,
|
2012-01-16 07:09:16 +00:00
|
|
|
editable: self.options.editable && item.editable,
|
|
|
|
editing: self.editing && i == self.selected,
|
2014-12-16 20:23:17 +00:00
|
|
|
format: self.options.format,
|
2013-12-26 16:43:03 +00:00
|
|
|
globalAttributes: self.options.globalAttributes,
|
2012-02-01 05:21:29 +00:00
|
|
|
highlight: self.options.highlight,
|
2012-01-16 07:09:16 +00:00
|
|
|
maxHeight: self.options.maxHeight,
|
|
|
|
submitOnBlur: self.options.submitOnBlur,
|
|
|
|
type: self.options.type,
|
2014-12-16 20:38:41 +00:00
|
|
|
unformat: self.options.unformat,
|
2012-01-16 07:09:16 +00:00
|
|
|
value: item.value,
|
|
|
|
width: self.options.type == 'input' ? 0 : self.options.width - 9
|
|
|
|
})
|
|
|
|
.addClass(item.id == self.options.selected ? 'OxSelected' : '')
|
2018-10-09 16:29:13 +00:00
|
|
|
.addClass(self.options.highlightGroup && item.group == selectedItem.group ? 'OxGroup' : '')
|
2012-01-17 11:50:31 +00:00
|
|
|
.data({id: item.id, position: i})
|
2012-01-16 07:09:16 +00:00
|
|
|
.bindEvent({
|
|
|
|
blur: function(data) {
|
|
|
|
// fixme: remove data
|
|
|
|
that.gainFocus();
|
|
|
|
that.triggerEvent('blur', {
|
|
|
|
id: item.id,
|
|
|
|
value: data.value
|
|
|
|
});
|
|
|
|
self.blurred = true;
|
|
|
|
setTimeout(function() {
|
|
|
|
self.blurred = false;
|
|
|
|
}, 250);
|
|
|
|
},
|
|
|
|
cancel: function(data) {
|
|
|
|
self.editing = false;
|
|
|
|
that.gainFocus();
|
2012-02-04 11:44:19 +00:00
|
|
|
data.value === ''
|
|
|
|
? submitItem(i, '')
|
|
|
|
: that.triggerEvent('blur', data);
|
2012-01-16 07:09:16 +00:00
|
|
|
},
|
|
|
|
change: function(data) {
|
|
|
|
that.triggerEvent('change', {
|
|
|
|
id: item.id,
|
|
|
|
value: data.value
|
|
|
|
});
|
|
|
|
},
|
2012-02-19 11:06:03 +00:00
|
|
|
edit: function() {
|
2012-01-27 14:29:11 +00:00
|
|
|
if (item.id != self.options.selected) {
|
|
|
|
selectItem(item.id);
|
|
|
|
}
|
2012-01-16 07:09:16 +00:00
|
|
|
self.editing = true;
|
2018-10-09 16:56:30 +00:00
|
|
|
that.$tooltip && that.$tooltip.options({title: ''});
|
2012-02-19 11:06:03 +00:00
|
|
|
that.triggerEvent('edit');
|
2012-01-16 07:09:16 +00:00
|
|
|
},
|
2012-02-16 16:35:59 +00:00
|
|
|
insert: function(data) {
|
|
|
|
that.triggerEvent('insert', data);
|
|
|
|
},
|
2012-02-19 11:06:03 +00:00
|
|
|
open: function(data) {
|
|
|
|
that.triggerEvent('open');
|
|
|
|
},
|
2012-01-16 07:09:16 +00:00
|
|
|
submit: function(data) {
|
|
|
|
self.editing = false;
|
|
|
|
that.gainFocus();
|
|
|
|
submitItem(i, data.value);
|
|
|
|
}
|
|
|
|
})
|
2012-01-04 17:27:32 +00:00
|
|
|
.appendTo(that);
|
2012-01-16 07:09:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
//self.editing && that.editItem(blur);
|
2012-01-03 10:25:15 +00:00
|
|
|
}
|
|
|
|
|
2012-01-03 19:41:50 +00:00
|
|
|
function selectFirst() {
|
2012-02-01 19:33:10 +00:00
|
|
|
if (self.selected > -1) {
|
|
|
|
self.selected > 0
|
|
|
|
? selectItem(0)
|
2013-05-08 16:53:33 +00:00
|
|
|
: that.triggerEvent('selectprevious');
|
2012-02-01 19:33:10 +00:00
|
|
|
}
|
2012-01-03 19:41:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 20:25:38 +00:00
|
|
|
function selectItem(idOrPosition) {
|
2012-01-16 17:51:53 +00:00
|
|
|
if (Ox.isString(idOrPosition)) {
|
|
|
|
self.options.selected = idOrPosition;
|
|
|
|
self.selected = getSelectedPosition();
|
|
|
|
} else {
|
|
|
|
self.selected = idOrPosition;
|
|
|
|
self.options.selected = getSelectedId();
|
|
|
|
}
|
|
|
|
if (/*self.options.selected == '' && */self.editing) {
|
|
|
|
self.editing = false;
|
|
|
|
that.blurItem();
|
2012-01-12 19:04:32 +00:00
|
|
|
}
|
2012-01-16 17:51:53 +00:00
|
|
|
that.find('.OxSelected').removeClass('OxSelected');
|
2018-10-09 16:29:13 +00:00
|
|
|
that.find('.OxGroup').removeClass('OxGroup')
|
|
|
|
if (self.selected > -1) {
|
|
|
|
self.$items[self.selected].addClass('OxSelected');
|
|
|
|
self.options.highlightGroup && that.updateItemGroup()
|
|
|
|
}
|
2012-01-16 17:51:53 +00:00
|
|
|
triggerSelectEvent();
|
2012-01-03 19:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function selectLast() {
|
2012-02-01 19:33:10 +00:00
|
|
|
if (self.selected > -1) {
|
|
|
|
self.selected < self.options.items.length - 1
|
|
|
|
? selectItem(self.options.items.length - 1)
|
2013-05-08 16:53:33 +00:00
|
|
|
: that.triggerEvent('selectnext');
|
2012-02-01 19:33:10 +00:00
|
|
|
}
|
2012-01-03 19:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function selectNext() {
|
2012-02-01 19:33:10 +00:00
|
|
|
if (self.selected > -1) {
|
|
|
|
self.selected < self.options.items.length - 1
|
|
|
|
? selectItem(self.selected + 1)
|
2013-05-08 16:53:33 +00:00
|
|
|
: that.triggerEvent('selectnext');
|
2012-02-01 19:33:10 +00:00
|
|
|
}
|
2012-01-03 19:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function selectNone() {
|
|
|
|
selectItem(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectPrevious() {
|
2012-02-01 19:33:10 +00:00
|
|
|
if (self.selected > -1) {
|
|
|
|
self.selected > 0
|
|
|
|
? selectItem(self.selected - 1)
|
2013-05-08 16:53:33 +00:00
|
|
|
: that.triggerEvent('selectprevious');
|
2012-02-01 19:33:10 +00:00
|
|
|
}
|
2012-01-03 19:41:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-27 14:29:11 +00:00
|
|
|
function singleclick(e) {
|
|
|
|
var $target = $(e.target),
|
2012-01-29 09:29:30 +00:00
|
|
|
$element = $target.is('.OxEditableElement')
|
|
|
|
? $target : $target.parents('.OxEditableElement'),
|
2014-09-22 11:23:42 +00:00
|
|
|
position;
|
2012-01-27 14:29:11 +00:00
|
|
|
if (!$target.is('.OxInput')) {
|
|
|
|
if ($element.length) {
|
2014-09-22 11:23:42 +00:00
|
|
|
position = $element.data('position');
|
2012-02-05 01:56:23 +00:00
|
|
|
// if clicked on an element
|
|
|
|
if (position != self.selected) {
|
2012-01-27 14:29:11 +00:00
|
|
|
// select another item
|
2012-02-05 01:56:23 +00:00
|
|
|
selectItem(position);
|
|
|
|
} else if (e.metaKey) {
|
|
|
|
// or deselect current item
|
|
|
|
selectNone();
|
2012-01-27 14:29:11 +00:00
|
|
|
}
|
|
|
|
} else if (!self.blurred) {
|
2012-02-05 01:56:23 +00:00
|
|
|
// otherwise, if there wasn't an active input element
|
2012-01-27 14:29:11 +00:00
|
|
|
if (self.editing) {
|
|
|
|
// blur if still in editing mode
|
|
|
|
that.blurItem();
|
|
|
|
} else {
|
2012-02-01 19:33:10 +00:00
|
|
|
// otherwise
|
|
|
|
if (self.selected > -1) {
|
|
|
|
// deselect selected
|
|
|
|
selectNone();
|
|
|
|
} else {
|
|
|
|
// or trigger event
|
|
|
|
that.triggerEvent('selectnone');
|
|
|
|
}
|
2012-01-27 14:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
that.gainFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-11 11:54:58 +00:00
|
|
|
function sortItems() {
|
|
|
|
if (!Ox.isEmpty(self.options.sort)) {
|
2012-03-20 09:34:50 +00:00
|
|
|
self.options.items = Ox.sortBy(
|
|
|
|
self.options.items,
|
|
|
|
self.options.sort,
|
|
|
|
self.options.getSortValue
|
|
|
|
? {value: self.options.getSortValue}
|
|
|
|
: {}
|
|
|
|
);
|
2012-01-11 11:54:58 +00:00
|
|
|
self.selected = getSelectedPosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
function submitItem(position, value) {
|
2012-01-03 19:41:50 +00:00
|
|
|
var item = self.options.items[position];
|
2012-01-03 10:25:15 +00:00
|
|
|
if (value === '') {
|
2012-01-03 19:41:50 +00:00
|
|
|
deleteItem();
|
2012-01-12 10:39:05 +00:00
|
|
|
} else {
|
2012-01-16 07:09:16 +00:00
|
|
|
that.triggerEvent(item.value === value ? 'blur' : 'submit', {
|
2012-01-03 19:41:50 +00:00
|
|
|
id: item.id,
|
|
|
|
value: value
|
|
|
|
});
|
|
|
|
item.value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 15:21:38 +00:00
|
|
|
function tooltip(e) {
|
|
|
|
var $target = $(e.target),
|
|
|
|
$element = $target.closest('.OxEditableElement'),
|
|
|
|
position = $element.data('position'),
|
|
|
|
item = self.options.items[position],
|
|
|
|
isLink = $target.closest('a').length,
|
|
|
|
click = isLink ? 'Shift-click' : 'Click',
|
|
|
|
doubleclick = isLink ? 'shift-doubleclick' : 'doubleclick';
|
2018-10-09 16:56:30 +00:00
|
|
|
return item === undefined || self.editing
|
2016-04-29 15:21:38 +00:00
|
|
|
? ''
|
|
|
|
: (
|
|
|
|
self.options.tooltipText
|
|
|
|
? self.options.tooltipText(item) + '<br>'
|
|
|
|
: ''
|
|
|
|
) + (
|
|
|
|
self.options.editable
|
|
|
|
? Ox._(click + ' to select') + (
|
|
|
|
item.editable ? Ox._(', ' + doubleclick + ' to edit') : ''
|
|
|
|
)
|
|
|
|
: ''
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-02-01 19:47:20 +00:00
|
|
|
var triggerSelectEvent = Ox.debounce(function() {
|
|
|
|
that.triggerEvent('select', {
|
|
|
|
id: self.options.selected
|
|
|
|
});
|
|
|
|
}, true);
|
2012-01-10 14:49:28 +00:00
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
addItem <f> addItem
|
|
|
|
(position, item) -> <o> add item at position
|
|
|
|
@*/
|
2012-01-03 19:41:50 +00:00
|
|
|
that.addItem = function(position, item) {
|
2012-01-12 19:04:32 +00:00
|
|
|
if (self.options.editable) {
|
|
|
|
self.options.items.splice(position, 0, item);
|
|
|
|
renderItems();
|
|
|
|
}
|
2012-01-16 07:09:16 +00:00
|
|
|
return that;
|
2012-01-03 19:41:50 +00:00
|
|
|
//that.triggerEvent('add');
|
|
|
|
/*
|
2012-01-03 10:25:15 +00:00
|
|
|
self.values = Ox.filter(values, function(value) {
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
self.values.push('');
|
|
|
|
renderItems();
|
|
|
|
Ox.last(self.$items).triggerEvent('doubleclick');
|
2012-01-03 19:41:50 +00:00
|
|
|
*/
|
2012-01-03 10:25:15 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
blurItem <f> blurItem
|
|
|
|
@*/
|
2012-01-09 20:25:38 +00:00
|
|
|
that.blurItem = function() {
|
2012-01-13 16:25:47 +00:00
|
|
|
/*
|
2012-01-12 19:04:32 +00:00
|
|
|
if (self.options.selected) {
|
|
|
|
self.$items[self.selected].options({editing: false});
|
|
|
|
} else {
|
2012-01-13 16:25:47 +00:00
|
|
|
*/
|
2012-01-16 07:09:16 +00:00
|
|
|
self.editing = false;
|
|
|
|
self.$items.forEach(function($item) {
|
|
|
|
$item.options({editing: false});
|
|
|
|
});
|
2012-01-13 16:25:47 +00:00
|
|
|
//}
|
2012-01-16 07:09:16 +00:00
|
|
|
return that;
|
2012-01-03 19:41:50 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
editItem <f> editItem
|
|
|
|
@*/
|
2012-01-12 10:39:05 +00:00
|
|
|
that.editItem = function() {
|
2012-01-31 10:57:09 +00:00
|
|
|
Ox.Log('AE', 'EDIT ITEM', self.options.editable, self.options.selected);
|
2012-01-12 19:04:32 +00:00
|
|
|
if (self.options.editable && self.options.selected) {
|
2012-01-16 07:09:16 +00:00
|
|
|
self.editing = true;
|
|
|
|
self.$items[self.selected].options({editing: true});
|
2018-10-09 16:56:30 +00:00
|
|
|
that.$tooltip && that.$tooltip.options({title: ''});
|
2012-02-19 11:06:03 +00:00
|
|
|
} else if (!self.options.editable) {
|
|
|
|
that.triggerEvent('open');
|
2012-01-12 10:39:05 +00:00
|
|
|
}
|
2012-01-16 07:09:16 +00:00
|
|
|
return that;
|
2012-01-12 10:39:05 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
reloadItems <f> reloadItems
|
|
|
|
@*/
|
2012-01-12 10:39:05 +00:00
|
|
|
that.reloadItems = function() {
|
|
|
|
renderItems();
|
2012-01-16 07:09:16 +00:00
|
|
|
return that;
|
2012-01-03 10:25:15 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
removeItem <f> removeItem
|
|
|
|
@*/
|
2012-02-16 11:35:03 +00:00
|
|
|
that.removeItem = function() {
|
|
|
|
if (self.options.editable && self.options.selected) {
|
|
|
|
deleteItem();
|
2012-01-12 19:04:32 +00:00
|
|
|
}
|
2012-01-16 07:09:16 +00:00
|
|
|
return that;
|
2012-01-03 10:25:15 +00:00
|
|
|
};
|
|
|
|
|
2012-01-16 07:09:16 +00:00
|
|
|
/*
|
|
|
|
that.submitItem = function() {
|
|
|
|
if (self.editing) {
|
|
|
|
self.editing = false;
|
|
|
|
self.$items[self.selected].options({editing: false});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2014-12-17 19:36:13 +00:00
|
|
|
that.updateItem = function(value) {
|
|
|
|
if (self.options.selected) {
|
|
|
|
self.$items[self.selected].options({value: value});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-09 16:29:13 +00:00
|
|
|
that.updateItemGroup = function() {
|
|
|
|
var group = self.options.items[self.selected].group;
|
|
|
|
self.$items.forEach(function($item, index) {
|
|
|
|
$item[
|
|
|
|
self.options.items[index].group == group ? 'addClass' : 'removeClass'
|
|
|
|
]('OxGroup');
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2012-01-03 10:25:15 +00:00
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|