update FormPanel

This commit is contained in:
rolux 2012-06-13 15:56:42 +02:00
parent 889ad7a83a
commit 61e425f64d

View file

@ -15,13 +15,15 @@ Ox.FormPanel = function(options, self) {
}) })
.options(options || {}); .options(options || {});
self.sections = self.options.form.map(function(section) {
return section.title;
});
self.section = 0; self.section = 0;
self.sectionTitle = self.sections[self.section].title; self.sectionTitle = self.options.form[self.section].title;
self.$list = Ox.TextList({ self.$list = Ox.TextList({
columns: [ columns: [
{
id: 'id',
unique: true,
visible: false
},
{ {
format: function(value) { format: function(value) {
return $('<img>') return $('<img>')
@ -42,32 +44,28 @@ Ox.FormPanel = function(options, self) {
}, },
{ {
format: function(value) { format: function(value) {
return (getSectionIndexByTitle(value) + 1) + '. ' + value; return (Ox.indexOf(self.options.form, function(section) {
return section.title == value;
}) + 1) + '. ' + value;
}, },
id: 'title', id: 'title',
title: 'Title', title: 'Title',
unique: true,
visible: true, visible: true,
width: 240 width: 240
} }
], ],
items: self.options.form.map(function(section) { items: self.options.form.map(function(section) {
return {title: section.title, valid: false}; return {id: section.id, title: section.title, valid: false};
}), }),
max: 1, max: 1,
min: 1, min: 1,
selected: [self.sections[0].id], selected: [self.options.form[0].id],
sort: [{key: 'id', operator: '+'}], sort: [{key: 'id', operator: '+'}],
width: 256 width: 256
}).bindEvent({ }).bindEvent({
select: function(data) { select: function(data) {
self.$sections[self.section].hide(); self.$sections[self.section].hide();
Ox.forEach(self.options.form, function(section, i) { self.section = Ox.getIndexById(self.options.form, data.ids[0]);
if (section.title == data.ids[0]) {
self.section = i;
Ox.Break();
}
});
self.$sections[self.section].show(); self.$sections[self.section].show();
} }
}); });
@ -101,16 +99,16 @@ Ox.FormPanel = function(options, self) {
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
Ox.Log('FORM', '---CHANGE---', data, self.$forms[i].valid()) Ox.Log('FORM', '---CHANGE---', data, self.$forms[i].valid())
self.$list.value(section.title, 'valid', self.$forms[i].valid()); self.$list.value(section.id, 'valid', self.$forms[i].valid());
that.triggerEvent('change', { that.triggerEvent('change', {
section: section.title, section: section.id,
data: data data: data
}); });
}, },
validate: function(data) { validate: function(data) {
self.$list.value(section.title, 'valid', data.valid); self.$list.value(section.id, 'valid', data.valid);
that.triggerEvent('validate', { that.triggerEvent('validate', {
section: section.title, section: section.id,
data: data data: data
}); });
} }
@ -121,8 +119,7 @@ Ox.FormPanel = function(options, self) {
}); });
self.$forms.forEach(function($form, i) { self.$forms.forEach(function($form, i) {
//Ox.print(self.sections[i], 'valid', $form.valid()); self.$list.value(self.options.form[i].id, 'valid', $form.valid());
self.$list.value(self.sections[i], 'valid', $form.valid());
}); });
self.$sections[0].show(); self.$sections[0].show();
@ -142,17 +139,6 @@ Ox.FormPanel = function(options, self) {
orientation: 'horizontal' orientation: 'horizontal'
}); });
function getSectionIndexByTitle(title) {
var index = -1;
Ox.forEach(self.options.form, function(section, i) {
if (section.title == title) {
index = i;
Ox.Break();
}
});
return index;
}
/*@ /*@
renderPrintVersion <f> renderPrintVersion renderPrintVersion <f> renderPrintVersion
(title) -> <s> (title) -> <s>