')
+ .addClass('OxFormSectionTitle')
+ .css({
+ height: '16px',
+ padding: '16px 16px 8px 16px',
+ fontWeight: 'bold'
+ })
+ .html(title)
+ );
+ self.$sections.forEach(function($section, i) {
+ // jQuery bug: textarea html/val does not survive cloning
+ // http://bugs.jquery.com/ticket/3016
+ var $clone = $section.clone(true),
+ textareas = {
+ section: $section.find('textarea'),
+ clone: $clone.find('textarea')
+ };
+ textareas.section.each(function(i) {
+ $(textareas.clone[i]).val($(this).val());
+ });
+ $printVersion
+ .append(
+ $('
').css({
+ height: '1px',
+ margin: '8px 0 8px 0',
+ background: 'rgb(128, 128, 128)'
+ })
+ )
+ .append(
+ $clone.show()
+ );
+ });
+ return $printVersion;
+ };
+
that.values = function() {
var values = {};
self.options.form.forEach(function(section, i) {
diff --git a/source/Ox.UI/js/Form/Ox.ObjectArrayInput.js b/source/Ox.UI/js/Form/Ox.ObjectArrayInput.js
index 6c04d593..0f5664fc 100644
--- a/source/Ox.UI/js/Form/Ox.ObjectArrayInput.js
+++ b/source/Ox.UI/js/Form/Ox.ObjectArrayInput.js
@@ -15,11 +15,8 @@ Ox.ObjectArrayInput = function(options, self) {
.options(options || {})
.addClass('OxObjectArrayInput');
- if (self.options.value.length == 0) {
- self.options.value = [{}];
- self.options.inputs.forEach(function(input) {
- self.options.value[0][input.options.id] = '';
- });
+ if (Ox.isEmpty(self.options.value)) {
+ self.options.value = [getDefaultValue()];
}
self.$element = [];
@@ -28,11 +25,10 @@ Ox.ObjectArrayInput = function(options, self) {
self.$addButton = [];
self.buttonWidth = self.options.width / 2 - 4;
- self.options.value.forEach(function(value, i) {
- addInput(i, value);
- });
+ 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',
@@ -50,11 +46,16 @@ Ox.ObjectArrayInput = function(options, self) {
.bindEvent(input.events || {});
}),
labelWidth: self.options.labelWidth,
+ value: value,
width: self.options.width
})
.bindEvent({
change: function(data) {
- // ...
+ var index = $(this).parent().data('index');
+ self.options.value[index] = self.$input[index].value();
+ that.triggerEvent('change', {
+ value: self.options.value
+ });
}
})
.appendTo(self.$element[index])
@@ -70,6 +71,10 @@ Ox.ObjectArrayInput = function(options, self) {
var index = $(this).parent().data('index');
if (self.$input.length > 1) {
removeInput(index);
+ self.options.value = getValue();
+ that.triggerEvent('change', {
+ value: self.options.value
+ });
}
}
})
@@ -84,7 +89,11 @@ Ox.ObjectArrayInput = function(options, self) {
.bind({
click: function() {
var index = $(this).parent().data('index');
- addInput(index + 1);
+ addInput(index + 1, getDefaultValue());
+ self.options.value = getValue();
+ that.triggerEvent('change', {
+ value: self.options.value
+ });
}
})
.appendTo(self.$element[index])
@@ -92,6 +101,20 @@ Ox.ObjectArrayInput = function(options, self) {
updateInputs();
}
+ function getDefaultValue() {
+ var value = {};
+ self.options.inputs.forEach(function(input) {
+ value[input.options.id] = '';
+ });
+ return value;
+ }
+
+ function getValue() {
+ return self.$input.map(function($input) {
+ return $input.value();
+ });
+ }
+
function removeInput(index) {
[
'input', 'removeButton', 'addButton', 'element'
@@ -103,6 +126,16 @@ Ox.ObjectArrayInput = function(options, self) {
updateInputs();
}
+ function setValue(value) {
+ while (self.$element.length) {
+ removeInput(0);
+ }
+ value.forEach(function(value, i) {
+ addInput(i, value);
+ });
+
+ }
+
function updateInputs() {
var length = self.$element.length;
self.$element.forEach(function($element, i) {
@@ -121,17 +154,10 @@ Ox.ObjectArrayInput = function(options, self) {
self.setOption = function(key, value) {
if (key == 'value') {
- // ...
+ setValue(value);
}
};
- // FIXME: remove
- that.value = function() {
- return self.$input.map(function($input) {
- return $input.value();
- });
- };
-
return that;
};
\ No newline at end of file
diff --git a/source/Ox.UI/js/Form/Ox.ObjectInput.js b/source/Ox.UI/js/Form/Ox.ObjectInput.js
index 51c19970..47f009da 100644
--- a/source/Ox.UI/js/Form/Ox.ObjectInput.js
+++ b/source/Ox.UI/js/Form/Ox.ObjectInput.js
@@ -7,6 +7,7 @@ Ox.ObjectInput = function(options, self) {
.defaults({
elements: [],
labelWidth: 128,
+ value: {},
width: 256
})
.options(options || {})
@@ -16,6 +17,12 @@ Ox.ObjectInput = function(options, self) {
height: self.options.elements.length * 24 - 8 + 'px'
});
+ if (Ox.isEmpty(self.options.value)) {
+ self.options.value = getValue();
+ } else {
+ setValue(self.options.value);
+ }
+
self.options.elements.forEach(function($element) {
$element.options({
labelWidth: self.options.labelWidth,
@@ -23,10 +30,7 @@ Ox.ObjectInput = function(options, self) {
})
.bindEvent({
change: function(data) {
- self.options.value = {};
- self.options.elements.forEach(function(element) {
- self.options.value[element.options('id')] = element.value();
- });
+ self.options.value = getValue();
that.triggerEvent('change', {
value: self.options.value
});
@@ -35,9 +39,23 @@ Ox.ObjectInput = function(options, self) {
.appendTo(that);
});
+ function getValue() {
+ var value = {};
+ self.options.elements.forEach(function(element) {
+ value[element.options('id')] = element.value();
+ });
+ return value;
+ }
+
+ function setValue(value) {
+ self.options.elements.forEach(function(element) {
+ element.value(value[element.options('id')]);
+ });
+ }
+
self.setOption = function(key, value) {
if (key == 'value') {
- // ...
+ setValue(value);
}
};
diff --git a/source/Ox.UI/js/Form/Ox.Select.js b/source/Ox.UI/js/Form/Ox.Select.js
index 42bd5a17..d0806a14 100644
--- a/source/Ox.UI/js/Form/Ox.Select.js
+++ b/source/Ox.UI/js/Form/Ox.Select.js
@@ -110,8 +110,7 @@ Ox.Select = function(options, self) {
width: getTitleWidth() + 'px'
})
.html(
- self.options.title
- || getItem(self.options.value).title
+ self.options.title || getItem(self.options.value).title
)
.appendTo(that);
}
@@ -153,14 +152,15 @@ Ox.Select = function(options, self) {
function changeMenu(data) {
self.options.value = self.optionGroup.value();
self.$title && self.$title.html(
- self.options.title ? self.options.title : getItem(self.options.value).title
+ self.options.title || getItem(self.options.value).title
);
that.triggerEvent('change', {
- title: Ox.isArray(self.options.value)
- ? self.options.value.map(function(value) {
- return getItem(value).title;
- })
- : getItem(self.options.value).title,
+ title: Ox.isEmpty(self.options.value) ? ''
+ : Ox.isArray(self.options.value)
+ ? self.options.value.map(function(value) {
+ return getItem(value).title;
+ })
+ : getItem(self.options.value).title,
value: self.options.value
});
}
@@ -207,15 +207,13 @@ Ox.Select = function(options, self) {
self.$button.options({title: value});
}
} else if (key == 'width') {
- Ox.Log('Form', 'SETTING WIDTH OPTION', value);
that.css({width: value - 2 + 'px'});
self.$title.css({width: getTitleWidth() + 'px'});
} else if (key == 'value') {
- Ox.Log('Form', 'SETTING VALUE OPTION', value);
if (self.options.type == 'text' && !self.options.title) {
self.$title.html(getItem(value).title);
}
- Ox.toArray(value).forEach(function(value) {
+ value !== '' && Ox.toArray(value).forEach(function(value) {
self.$menu.checkItem(value);
});
self.options.value = self.optionGroup.value();
diff --git a/source/Ox.UI/js/Form/Ox.SelectInput.js b/source/Ox.UI/js/Form/Ox.SelectInput.js
index b1b8b9d0..195dc31c 100644
--- a/source/Ox.UI/js/Form/Ox.SelectInput.js
+++ b/source/Ox.UI/js/Form/Ox.SelectInput.js
@@ -10,7 +10,7 @@ Ox.SelectInput = function(options, self) {
label: '',
labelWidth: 128,
max: 1,
- min: 1,
+ min: 0,
placeholder: '',
title: '',
value: options.max == 1 ? '' : [],
@@ -27,28 +27,14 @@ Ox.SelectInput = function(options, self) {
labelWidth: self.options.labelWidth,
max: self.options.max,
min: self.options.min,
- title: self.options.title,
+ title: getTitle(),
value: self.options.value,
width: self.options.width
})
.bindEvent({
change: function(data) {
- if (self.options.title) {
- self.$select.options({
- title: Ox.getObjectById(self.options.items, data.value).title
- });
- }
- if (data.value != self.other) {
- self.$select.options({width: self.options.width})
- .removeClass('OxOverlapRight')
- self.$input.hide();
- self.options.value = data.value
- } else {
- self.$select.options({width: self.otherWidth})
- .addClass('OxOverlapRight');
- self.$input.show().focusInput(true);
- self.options.value = self.$input.value();
- }
+ self.options.value = getValue();
+ setValue(self.isOther);
}
});
@@ -63,11 +49,14 @@ Ox.SelectInput = function(options, self) {
})
.hide();
+ setValue();
+
that = Ox.FormElementGroup({
elements: [
self.$select,
self.$input
],
+ id: self.options.id,
join: function(value) {
return value[value[0] == self.other ? 1 : 0]
},
@@ -79,8 +68,62 @@ Ox.SelectInput = function(options, self) {
width: self.options.width
});
+ function getTitle() {
+ var value = self.$select ? self.$select.value() : self.options.value;
+ return Ox.isEmpty(value)
+ ? self.options.title
+ : Ox.getObjectById(self.options.items, value).title;
+ }
+
+ function getValue() {
+ self.isOther = self.$select.value() == self.other;
+ return !self.isOther ? self.$select.value() : self.$input.value();
+ }
+
+ function setValue(isOther) {
+ Ox.print('SET VALUE', isOther)
+ if (
+ (!self.options.value && isOther !== true)
+ || Ox.map(self.options.items, function(item) {
+ return item.id != self.other ? item.id : null;
+ }).indexOf(self.options.value) > -1
+ ) {
+ self.$select.options({
+ title: !self.options.value
+ ? self.options.title
+ : Ox.getObjectById(self.options.items, self.options.value).title,
+ value: self.options.value,
+ width: self.options.width
+ })
+ .removeClass('OxOverlapRight');
+ self.$input.hide().value('');
+ } else {
+ self.$select.options({
+ title: Ox.getObjectById(self.options.items, self.other).title,
+ value: self.other,
+ width: self.otherWidth
+ })
+ .addClass('OxOverlapRight');
+ self.$input.show().value(self.options.value);
+ }
+ self.$select.options({title: getTitle()});
+ }
+
self.setOption = function(key, value) {
- // ...
+ if (key == 'value') {
+ setValue();
+ }
+ };
+
+ that.value = function() {
+ if (arguments.length == 0) {
+ return getValue();
+ } else {
+ self.options.value = arguments[0];
+ Ox.print('SOV:::', self.options.value)
+ setValue();
+ return that;
+ }
};
return that;
diff --git a/source/Ox.UI/js/Form/Ox.Spreadsheet.js b/source/Ox.UI/js/Form/Ox.Spreadsheet.js
index fe9e10cf..7e97615b 100644
--- a/source/Ox.UI/js/Form/Ox.Spreadsheet.js
+++ b/source/Ox.UI/js/Form/Ox.Spreadsheet.js
@@ -14,33 +14,46 @@ Ox.Spreadsheet = function(options, self) {
rowTitleType: 'str',
rowTitleWidth: 128,
title: '',
- value: []
+ value: {}
})
.options(options || {})
.addClass('OxSpreadsheet');
- self.values = [];
- self.options.rows.forEach(function(row, r) {
- self.values.push([]);
- self.options.columns.forEach(function(column, c) {
- self.values[r].push(0);
+ if (Ox.isEmpty(self.options.value)) {
+ self.options.value = {
+ columns: [],
+ rows: [],
+ values: []
+ }
+ Ox.loop(4, function(i) {
+ self.options.value.columns.push('');
+ self.options.value.rows.push('');
+ self.options.value.values.push([0, 0, 0, 0]);
});
- });
- self.sums = getSums();
+ } else if (Ox.isEmpty(self.options.value.values)) {
+ self.options.value.rows.forEach(function(row, r) {
+ self.options.value.values.push([]);
+ self.options.value.columns.forEach(function(column, c) {
+ self.options.value.values[r].push(0);
+ });
+ });
+ }
+
+ Ox.print('Ss ----', self.options)
renderSpreadsheet();
function addColumn(index) {
- self.options.columns.splice(index, 0, '');
- self.values.forEach(function(columns) {
+ self.options.value.columns.splice(index, 0, '');
+ self.options.value.values.forEach(function(columns) {
columns.splice(index, 0, 0);
});
renderSpreadsheet();
}
function addRow(index) {
- self.options.rows.splice(index, 0, '');
- self.values.splice(index, 0, Ox.repeat([0], self.columns));
+ self.options.value.rows.splice(index, 0, '');
+ self.options.value.values.splice(index, 0, Ox.repeat([0], self.columns));
renderSpreadsheet();
}
@@ -50,7 +63,7 @@ Ox.Spreadsheet = function(options, self) {
row: Ox.repeat([0], self.rows),
sheet: 0
};
- self.values.forEach(function(columns, r) {
+ self.options.value.values.forEach(function(columns, r) {
columns.forEach(function(value, c) {
sums.column[c] += value;
sums.row[r] += value;
@@ -61,23 +74,23 @@ Ox.Spreadsheet = function(options, self) {
}
function removeColumn(index) {
- self.options.columns.splice(index, 1);
- self.values.forEach(function(columns) {
+ self.options.value.columns.splice(index, 1);
+ self.options.value.values.forEach(function(columns) {
columns.splice(index, 1);
});
renderSpreadsheet();
}
function removeRow(index) {
- self.options.rows.splice(index, 1);
- self.values.splice(index, 1);
+ self.options.value.rows.splice(index, 1);
+ self.options.value.values.splice(index, 1);
renderSpreadsheet();
}
function renderSpreadsheet() {
- self.columns = self.options.columns.length;
- self.rows = self.options.rows.length;
+ self.columns = self.options.value.columns.length;
+ self.rows = self.options.value.rows.length;
self.sums = getSums();
self.$input = {};
@@ -88,9 +101,9 @@ Ox.Spreadsheet = function(options, self) {
height: 16 * (self.rows + 2) + 'px'
});
- Ox.merge([self.options.title], Ox.clone(self.options.rows), ['Total']).forEach(function(row, r) {
+ Ox.merge([self.options.title], Ox.clone(self.options.value.rows), ['Total']).forEach(function(row, r) {
r--;
- Ox.merge([''], Ox.clone(self.options.columns), ['Total']).forEach(function(column, c) {
+ Ox.merge([''], Ox.clone(self.options.value.columns), ['Total']).forEach(function(column, c) {
c--;
if (r == -1) {
if (c == -1 || c == self.columns) {
@@ -131,7 +144,7 @@ Ox.Spreadsheet = function(options, self) {
})
.bindEvent({
change: function(data) {
- self.options.columns[c] = data.value;
+ self.options.value.columns[c] = data.value;
triggerChangeEvent();
}
})
@@ -169,7 +182,7 @@ Ox.Spreadsheet = function(options, self) {
})
.bindEvent({
change: function(data) {
- self.options.rows[r] = data.value;
+ self.options.value.rows[r] = data.value;
triggerChangeEvent();
}
})
@@ -197,13 +210,13 @@ Ox.Spreadsheet = function(options, self) {
value: isSheetSum ? self.sums.sheet
: isColumnSum ? self.sums.column[c]
: isRowSum ? self.sums.row[r]
- : self.values[r][c],
+ : self.options.value.values[r][c],
width: self.options.columnWidth
})
.appendTo(that);
!isSum && self.$input[id].bindEvent({
change: function(data) {
- self.values[r][c] = parseInt(data.value);
+ self.options.value.values[r][c] = parseInt(data.value);
self.sums = getSums();
self.$input[c + ',' + self.rows].value(self.sums.column[c]);
self.$input[self.columns + ',' + r].value(self.sums.row[r]);
@@ -220,18 +233,10 @@ Ox.Spreadsheet = function(options, self) {
function triggerChangeEvent() {
that.triggerEvent('change', {
- value: that.value()
+ value: self.options.value
});
}
- that.value = function() {
- return {
- columns: self.options.columns,
- rows: self.options.rows,
- values: self.values
- };
- };
-
return that;
};
\ No newline at end of file
diff --git a/source/Ox.UI/themes/classic/_index.html b/source/Ox.UI/themes/classic/_index.html
index c78dc6b8..d73da148 100644
--- a/source/Ox.UI/themes/classic/_index.html
+++ b/source/Ox.UI/themes/classic/_index.html
@@ -65,6 +65,7 @@
'Check', 'Embed', 'Bracket',
'Upload', 'Download',
'Copyright', 'NoCopyright',
+ 'List', 'Grid', 'Map', 'Calendar',
'Click', 'Delete', 'Edit', 'Find', 'Flag', 'Icon', 'Like',
'Mail', 'Publish', 'Set', 'Star', 'User', 'View', 'Loading'
].forEach(function(symbol) {
diff --git a/source/Ox/js/Collection.js b/source/Ox/js/Collection.js
index 9544e4a6..4a208393 100644
--- a/source/Ox/js/Collection.js
+++ b/source/Ox/js/Collection.js
@@ -643,7 +643,9 @@ Ox.some Tests if one or more elements of a collection satisfy a given condit
true
@*/
Ox.some = function(obj, fn) {
- return Ox.filter(Ox.values(obj), fn).length > 0;
+ return Ox.filter(Ox.values(obj), fn || function(v) {
+ return v;
+ }).length > 0;
};
/*@
diff --git a/source/Ox/js/Type.js b/source/Ox/js/Type.js
index 28cdd39d..d9bb0a2a 100644
--- a/source/Ox/js/Type.js
+++ b/source/Ox/js/Type.js
@@ -137,6 +137,36 @@ Ox.isEqual = function(a, b) {
return isEqual;
};
+/*@
+Ox.isFalsy Returns true for undefined, null, false, 0, '', [], {}
+ (value) -> True if the value is falsy
+ value <*> Any value
+ > Ox.isFalsy(void 0)
+ true
+ > Ox.isFalsy(null)
+ true
+ > Ox.isFalsy(false)
+ true
+ > Ox.isFalsy(0)
+ true
+ > Ox.isFalsy('')
+ true
+ > Ox.isFalsy([])
+ true
+ > Ox.isFalsy({})
+ true
+ > Ox.isFalsy(NaN)
+ false
+ > Ox.isFalsy(function() {})
+ false
+ > Ox.isFalsy(/ /)
+ false
+@*/
+Ox.isFalsy = function(val) {
+ return (!val && !Ox.isNaN(val))
+ || (Ox.isEmpty(val) && !Ox.isFunction(val));
+};
+
/*@
Ox.isFunction Tests if a value is a function
(value) -> True if the value is a function