Ox.getPositionById() -> Ox.getIndexById()

This commit is contained in:
rolux 2012-01-04 13:41:05 +05:30
parent 4ca01b2bfa
commit 8097cc7812
19 changed files with 23 additions and 30 deletions

View file

@ -748,7 +748,7 @@ Ox.Calendar = function(options, self) {
function getEventLine(id) {
var line = -1;
Ox.forEach(self.lineEvents, function(events, line_) {
if (Ox.getPositionById(events, id) > -1) {
if (Ox.getIndexById(events, id) > -1) {
line = line_;
return false;
}
@ -1261,7 +1261,7 @@ Ox.Calendar = function(options, self) {
that.removeEvent = function() {
Ox.Log('Calendar', 'REMOVE ... SELF.OPTIONS', self.options)
var index = Ox.getPositionById(self.options.events, self.options.selected);
var index = Ox.getIndexById(self.options.events, self.options.selected);
self.options.events.splice(index, 1);
getLines();
renderCalendar();

View file

@ -495,7 +495,7 @@ Ox.ListCalendar = function(options, self) {
function editEvent(key, value) {
var id = self.selectedEvent,
index = Ox.getPositionById(self.options.events, id),
index = Ox.getIndexById(self.options.events, id),
data = {id: id};
data[key] = value;
self.options.editEvent(data, function(result) {
@ -552,7 +552,7 @@ Ox.ListCalendar = function(options, self) {
function removeEvent() {
var id = self.selectedEvent,
index = Ox.getPositionById(self.options.events, id);
index = Ox.getIndexById(self.options.events, id);
self.options.removeEvent({id: id}, function(result) {
if (result.status.code == '200') {
self.options.events.splice(index, 1);

View file

@ -83,7 +83,7 @@ Ox.DocPanel = function(options, self) {
docItems.forEach(function(docItem) {
var moduleIndex, sectionIndex;
docItem.module = self.options.getModule(docItem);
moduleIndex = Ox.getPositionById(treeItems, '_' + docItem.module);
moduleIndex = Ox.getIndexById(treeItems, '_' + docItem.module);
if (moduleIndex == -1) {
treeItems.push({
id: '_' + docItem.module,
@ -94,7 +94,7 @@ Ox.DocPanel = function(options, self) {
}
docItem.section = self.options.getSection(docItem);
if (docItem.section) {
sectionIndex = Ox.getPositionById(
sectionIndex = Ox.getIndexById(
treeItems[moduleIndex].items,
'_' + docItem.module + '_' + docItem.section
);

View file

@ -338,7 +338,7 @@ Ox.URL = function(options) {
condition.key = condition.key || '*';
if (
!condition.operator
|| Ox.getPositionById(self.options.findKeys, condition.key) == -1
|| Ox.getIndexById(self.options.findKeys, condition.key) == -1
) {
// missing operator or unknown key
condition = {key: '*', value: str, operator: '='};

View file

@ -82,7 +82,7 @@ Ox.ArrayEditable = function(options, self) {
}
function getSelectedPosition() {
return Ox.getPositionById(self.options.items, self.options.selected);
return Ox.getIndexById(self.options.items, self.options.selected);
}
function renderItems() {

View file

@ -74,7 +74,7 @@ Ox.Button = function(options, self) {
title: value.title || value
};
});
self.value = Ox.getPositionById(self.options.values, self.options.value);
self.value = Ox.getIndexById(self.options.values, self.options.value);
if (self.value == -1) {
self.value = 0;
self.options.value = self.options.values[0].id;
@ -144,8 +144,7 @@ Ox.Button = function(options, self) {
that.toggle = function() {
if (self.options.values.length) {
self.value = 1 - Ox.getPositionById(self.options.values, self.options.value);
Ox.print('S:O:', self.options, self.value)
self.value = 1 - Ox.getIndexById(self.options.values, self.options.value);
self.options.title = self.options.values[self.value].title;
self.options.value = self.options.values[self.value].id;
setTitle();

View file

@ -338,7 +338,7 @@ Ox.Filter = function(options, self) {
Ox.Log('Form', 'old new', oldConditionType, newConditionType)
condition.key = key;
if (changeConditionType || changeConditionFormat) {
if (Ox.getPositionById(self.conditionOperators[newConditionType], condition.operator) == -1) {
if (Ox.getIndexById(self.conditionOperators[newConditionType], condition.operator) == -1) {
condition.operator = self.conditionOperators[newConditionType][0].id;
}
if (

View file

@ -164,7 +164,6 @@ Ox.Form = function(options, self) {
var values = {};
if (arguments.length == 0) {
self.$items.forEach(function($item, i) {
//Ox.print('??????-??', self.itemIds[i], self.$items[i].value(), Ox.typeOf(self.$items[i].value()))
values[self.itemIds[i]] = self.$items[i].value();
});
//Ox.Log('Form', 'VALUES', values)

View file

@ -115,7 +115,7 @@ Ox.FormPanel = function(options, self) {
});
self.$forms.forEach(function($form, i) {
Ox.print(self.sections[i], 'valid', $form.valid());
//Ox.print(self.sections[i], 'valid', $form.valid());
self.$list.value(self.sections[i], 'valid', $form.valid());
});

View file

@ -28,7 +28,6 @@ Ox.ObjectArrayInput = function(options, self) {
setValue(self.options.value);
function addInput(index, value) {
Ox.print('ADD INPUT', index, value)
self.$element.splice(index, 0, Ox.Element()
.css({
width: self.options.width + 'px',

View file

@ -81,7 +81,6 @@ Ox.SelectInput = function(options, self) {
}
function setValue(isOther) {
Ox.print('SET VALUE', isOther)
if (
(!self.options.value && isOther !== true)
|| Ox.map(self.options.items, function(item) {
@ -120,7 +119,6 @@ Ox.SelectInput = function(options, self) {
return getValue();
} else {
self.options.value = arguments[0];
Ox.print('SOV:::', self.options.value)
setValue();
return that;
}

View file

@ -605,11 +605,11 @@ Ox.TextList = function(options, self) {
}
function getColumnIndexById(id) {
return Ox.getPositionById(self.options.columns, id);
return Ox.getIndexById(self.options.columns, id);
}
function getColumnPositionById(id) {
return Ox.getPositionById(self.visibleColumns, id);
return Ox.getIndexById(self.visibleColumns, id);
}
function getItem(id) {

View file

@ -770,7 +770,7 @@ Ox.ListMap = function(options, self) {
Ox.Log('Map', 'REMOVE PLACE', self.selectedPlace, index)
if (!self.isAsync) {
// fixme: doesn't call self.options.removePlace!
index = Ox.getPositionById(self.options.places, self.selectedPlace);
index = Ox.getIndexById(self.options.places, self.selectedPlace);
self.options.places.splice(index, 1);
self.$list.options({items: Ox.clone(self.options.places)});
//setStatus();

View file

@ -1104,7 +1104,7 @@ Ox.Map = function(options, self) {
place.id = '_' + place.id;
self.options.selected = place.id;
//Ox.Log('Map', 'removePlace', Ox.getObjectById(self.places, place.id))
self.places.splice(Ox.getPositionById(self.places, place.id), 1);
self.places.splice(Ox.getIndexById(self.places, place.id), 1);
self.resultPlace && self.resultPlace.remove();
self.resultPlace = place;
place.marker.update();

View file

@ -205,7 +205,7 @@ Ox.MainMenu = function(options, self) {
};
that.replaceMenu = function(id, menu) {
var position = Ox.getPositionById(self.options.menus, id);
var position = Ox.getIndexById(self.options.menus, id);
self.options.menus[position] = menu;
removeMenu(position);
addMenu(menu, position);

View file

@ -56,7 +56,7 @@ Ox.TabPanel = function(options, self) {
}
that.select = function(id) {
if (Ox.getPositionById(self.options.tabs, id) > -1) {
if (Ox.getIndexById(self.options.tabs, id) > -1) {
self.$tabs.select(id);
}
};

View file

@ -142,7 +142,7 @@ Ox.AnnotationPanel = function(options, self) {
open: function(data) {
return;
if (data.ids.length == 1) {
var pos = Ox.getPositionById(self.$annotations.options('items'), data.ids[0]);
var pos = Ox.getIndexById(self.$annotations.options('items'), data.ids[0]);
self.$annotations.editItem(pos);
}
},
@ -194,7 +194,6 @@ Ox.AnnotationPanel = function(options, self) {
}
function updateAnnotation(data) {
Ox.print('updateAnnotation', data);
var item = Ox.getObjectById(self.options.items, data.id);
item.value = data.value;
that.triggerEvent('submit', item);
@ -251,7 +250,7 @@ Ox.AnnotationPanel = function(options, self) {
removeItems <f> removeItems
@*/
that.removeItem = function(id) {
var pos = Ox.getPositionById(self.options.items, id);
var pos = Ox.getIndexById(self.options.items, id);
self.options.items.splice(pos, 1);
self.$annotations.removeItems && self.$annotations.removeItems([id]);
};

View file

@ -1079,7 +1079,7 @@ Ox.VideoEditor = function(options, self) {
item <o> annotation to add
@*/
that.addAnnotation = function(layer, item) {
var i = Ox.getPositionById(self.options.layers, layer);
var i = Ox.getIndexById(self.options.layers, layer);
self.$annotationPanel[i].addItem(item);
};
@ -1090,7 +1090,7 @@ Ox.VideoEditor = function(options, self) {
ids <a> array of item ids to remove
@*/
that.removeAnnotation = function(layer, id) {
var i = Ox.getPositionById(self.options.layers, layer);
var i = Ox.getIndexById(self.options.layers, layer);
self.$annotationPanel[i].removeItem(id);
};

View file

@ -212,8 +212,7 @@ Ox.getIndexById <f> Returns the first array index of an object with a given id
> Ox.getIndexById([{id: 'foo', str: 'Foo'}, {id: 'bar', str: 'Bar'}], 'foo')
0
@*/
// FIXME: this should be getIndexById() only
Ox.getIndexById = Ox.getPositionById = function(arr, id) {
Ox.getIndexById = function(arr, id) {
return Ox.getIndex(arr, 'id', id);
};