forked from 0x2620/oxjs
use new form element syntax, continued
This commit is contained in:
parent
e47305c93f
commit
02f53a57c1
15 changed files with 107 additions and 88 deletions
|
|
@ -47,10 +47,9 @@ Ox.Button = function(options, self) {
|
|||
values: [],
|
||||
width: 'auto'
|
||||
})
|
||||
.options(options ? Ox.extend(Ox.clone(options), {
|
||||
// tooltip may be an array, so we can't pass it yet
|
||||
tooltip: ''
|
||||
}) : {})
|
||||
.options(Ox.isArray(options.tooltip) ? Ox.extend(Ox.clone(options), {
|
||||
tooltip: options.tooltip[0]
|
||||
}) : options || {})
|
||||
.attr({
|
||||
disabled: self.options.disabled,
|
||||
type: self.options.type == 'text' ? 'button' : 'image'
|
||||
|
|
@ -87,19 +86,20 @@ Ox.Button = function(options, self) {
|
|||
|
||||
setTitle();
|
||||
|
||||
options.tooltip && that.options({
|
||||
tooltip: Ox.isArray(options.tooltip)
|
||||
? options.tooltip[self.value]
|
||||
: options.tooltip
|
||||
});
|
||||
if (Ox.isArray(options.tooltip)) {
|
||||
self.options.tooltip = options.tooltip;
|
||||
Ox.print('TOOLTIP', self.options.tooltip);
|
||||
that.$tooltip.options({
|
||||
title: self.options.tooltip[self.value]
|
||||
});
|
||||
}
|
||||
|
||||
function click() {
|
||||
if (!self.options.disabled) {
|
||||
that.triggerEvent('click');
|
||||
if (self.options.values.length || self.options.selectable) {
|
||||
that.toggle();
|
||||
that.triggerEvent('change', {value: self.options.value});
|
||||
} else {
|
||||
that.triggerEvent('click');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -143,16 +143,16 @@ Ox.Button = function(options, self) {
|
|||
};
|
||||
|
||||
that.toggle = function() {
|
||||
var index;
|
||||
if (self.options.values.length) {
|
||||
index = 1 - Ox.getPositionById(self.options.values, self.options.value);
|
||||
self.options.title = self.options.values[index].title;
|
||||
self.options.value = self.options.values[index].id;
|
||||
self.value = 1 - Ox.getPositionById(self.options.values, self.options.value);
|
||||
Ox.print('S:O:', self.options, self.value)
|
||||
self.options.title = self.options.values[self.value].title;
|
||||
self.options.value = self.options.values[self.value].id;
|
||||
setTitle();
|
||||
// fixme: if the tooltip is visible
|
||||
// we also need to call show()
|
||||
that.$tooltip && that.$tooltip.options({
|
||||
title: self.options.tooltips[index]
|
||||
title: self.options.tooltip[self.value]
|
||||
});
|
||||
} else {
|
||||
self.options.value = !self.options.value;
|
||||
|
|
|
|||
|
|
@ -113,11 +113,6 @@ Ox.Checkbox = function(options, self) {
|
|||
}
|
||||
};
|
||||
|
||||
// fixme: added for forms, duplicated, checked() shouldn't be neccessary
|
||||
that.value = function() {
|
||||
return self.options.checked;
|
||||
}
|
||||
|
||||
return that;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ Ox.Form = function(options, self) {
|
|||
self.itemIsValid[i] = data.valid;
|
||||
});
|
||||
} else {
|
||||
self.itemIsValid[i] = item.value().length > 0;
|
||||
self.itemIsValid[i] = item.value !== '';
|
||||
}
|
||||
self.itemIds[i] = item.options('id') || item.id;
|
||||
self.$items[i] = Ox.FormItem({element: item}).appendTo(that);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ Ox.OptionGroup = function(items, min, max, property) {
|
|||
function getNumber() {
|
||||
// returns the number of checked items
|
||||
return items.reduce(function(prev, curr) {
|
||||
return prev + curr[property];
|
||||
return prev + !!curr[property];
|
||||
}, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,13 +75,15 @@ Ox.Select = function(options, self) {
|
|||
Ox.Log('Form', 'Ox.Select', self.options);
|
||||
|
||||
self.options.items = self.options.items.map(function(item) {
|
||||
return {
|
||||
return Ox.isEmpty(item) ? item : {
|
||||
id: item.id || item,
|
||||
title: item.title || item,
|
||||
checked: Ox.toArray(self.options.value).indexOf(item.id || item) > -1
|
||||
};
|
||||
});
|
||||
|
||||
Ox.Log('Form', 'S.O.V.', '"'+self.options.value+'"', JSON.stringify(self.options.items))
|
||||
|
||||
self.optionGroup = new Ox.OptionGroup(
|
||||
self.options.items,
|
||||
self.options.min,
|
||||
|
|
@ -91,6 +93,8 @@ Ox.Select = function(options, self) {
|
|||
self.options.items = self.optionGroup.init();
|
||||
self.options.value = self.optionGroup.value();
|
||||
|
||||
Ox.Log('Form', 'S.O.V.', '"'+self.options.value+'"', JSON.stringify(self.options.items))
|
||||
|
||||
if (self.options.label) {
|
||||
self.$label = Ox.Label({
|
||||
overlap: 'right',
|
||||
|
|
@ -102,7 +106,6 @@ Ox.Select = function(options, self) {
|
|||
}
|
||||
|
||||
if (self.options.type == 'text') {
|
||||
Ox.Log('Form', 'S.O.V.', self.options.value)
|
||||
self.$title = $('<div>')
|
||||
.addClass('OxTitle')
|
||||
.css({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue