diff --git a/source/Ox.UI/js/Core/Ox.API.js b/source/Ox.UI/js/Core/Ox.API.js index 3f2b7301..7ee69967 100644 --- a/source/Ox.UI/js/Core/Ox.API.js +++ b/source/Ox.UI/js/Core/Ox.API.js @@ -22,9 +22,7 @@ Ox.API = function(options, callback) { api: function(callback) { Ox.Request.send({ url: self.options.url, - data: { - action: 'api' - }, + data: {action: 'api'}, callback: callback }); }, diff --git a/source/Ox.UI/js/Form/Ox.CheckboxGroup.js b/source/Ox.UI/js/Form/Ox.CheckboxGroup.js index 837f94f2..0bb51af9 100644 --- a/source/Ox.UI/js/Form/Ox.CheckboxGroup.js +++ b/source/Ox.UI/js/Form/Ox.CheckboxGroup.js @@ -88,7 +88,11 @@ Ox.CheckboxGroup = function(options, self) { self.options.value = self.optionGroup.value(); that.triggerEvent('change', { title: Ox.isString(self.options.value) - ? Ox.getObjectById(self.options.checkboxes, self.options.value).title + ? ( + self.options.value + ? Ox.getObjectById(self.options.checkboxes, self.options.value).title + : '' + ) : self.options.value.map(function(value) { return Ox.getObjectById(self.options.checkboxes, value).title; }), diff --git a/source/Ox.UI/js/Form/Ox.Form.js b/source/Ox.UI/js/Form/Ox.Form.js index 33a22f33..fb7a5e21 100644 --- a/source/Ox.UI/js/Form/Ox.Form.js +++ b/source/Ox.UI/js/Form/Ox.Form.js @@ -25,7 +25,10 @@ Ox.Form = function(options, self) { items: [], // FIXME: don't pass function, // listen to event instead! - submit: null + submit: null, + validate: function(valid) { + return Ox.every(valid); + } }) .options(options || {}) // fixme: the || {} can be done once, in the options function .addClass('OxForm'); @@ -33,20 +36,14 @@ Ox.Form = function(options, self) { Ox.extend(self, { $items: [], $messages: [], - formIsValid: false, itemIds: [], itemIsValid: [] }); self.options.items.forEach(function(item, i) { - var validateItem = item.options('validate'); - if (validateItem) { - validateItem(item.value(), function(data) { - self.itemIsValid[i] = data.valid; - }); - } else { - self.itemIsValid[i] = item.value !== ''; - } + validateItem(i, function(valid) { + self.itemIsValid[i] = valid; + }); self.itemIds[i] = item.options('id') || item.id; self.$items[i] = Ox.FormItem({element: item}).appendTo(that); item.bindEvent({ @@ -79,6 +76,9 @@ Ox.Form = function(options, self) { id: self.itemIds[i], data: data }); + validateItem(i, function(valid) { + validateForm(i, valid); + }); }, submit: function(data) { self.formIsValid && that.submit(); @@ -95,6 +95,8 @@ Ox.Form = function(options, self) { }); }); + self.formIsValid = self.options.validate(self.itemIsValid); + function getItemIndexById(id) { return self.itemIds.indexOf(id); } @@ -107,8 +109,7 @@ Ox.Form = function(options, self) { function validateForm(pos, valid) { self.itemIsValid[pos] = valid; - Ox.Log('Form', 'VALID???', self.itemIsValid) - if (Ox.every(self.itemIsValid) != self.formIsValid) { + if (self.options.validate(self.itemIsValid) != self.formIsValid) { self.formIsValid = !self.formIsValid; that.triggerEvent('validate', { valid: self.formIsValid @@ -116,6 +117,18 @@ Ox.Form = function(options, self) { } } + function validateItem(pos, callback) { + var item = self.options.items[pos], + validate = item.options('validate'); + if (validate) { + validate(item.value(), function(data) { + callback(data.valid); + }); + } else { + callback(item.value && !Ox.isEmpty(item.value)); + } + } + that.addItem = function(pos, item) { Ox.Log('Form', 'addItem', pos) self.options.items.splice(pos, 0, item); @@ -138,6 +151,10 @@ Ox.Form = function(options, self) { self.options.submit(that.values(), submitCallback); }; + that.valid = function() { + return self.formIsValid; + }; + that.values = function() { // fixme: can this be private? /* get/set form values @@ -147,9 +164,8 @@ 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(); - //fixme: make the following work - //values[self.itemIds[i]] = self.$items[i].value(); }); //Ox.Log('Form', 'VALUES', values) return values; @@ -157,7 +173,7 @@ Ox.Form = function(options, self) { Ox.Log('Form', 'SET FORM VALUES', arguments[0]) Ox.forEach(arguments[0], function(value, key) { var index = getItemIndexById(key); - //index > -1 && Ox.Log('Form', ':::::::', key, value) + index > -1 && Ox.Log('Form', ':::::::', key, value) index > -1 && self.options.items[index].value(value); }); return that; diff --git a/source/Ox.UI/js/Form/Ox.FormElementGroup.js b/source/Ox.UI/js/Form/Ox.FormElementGroup.js index f5f3f160..6ae827fe 100644 --- a/source/Ox.UI/js/Form/Ox.FormElementGroup.js +++ b/source/Ox.UI/js/Form/Ox.FormElementGroup.js @@ -115,11 +115,7 @@ Ox.FormElementGroup = function(options, self) { that.value = function() { var values = self.options.elements.map(function(element) { - var ret = null; - ['checked', 'selected', 'value'].forEach(function(v) { - element[v] && (ret = element[v]()); - }); - return ret; + return element.value(); }); return self.options.joinValues ? self.options.joinValues(values) diff --git a/source/Ox.UI/js/Form/Ox.FormPanel.js b/source/Ox.UI/js/Form/Ox.FormPanel.js index 3e82dfc5..28893e21 100644 --- a/source/Ox.UI/js/Form/Ox.FormPanel.js +++ b/source/Ox.UI/js/Form/Ox.FormPanel.js @@ -45,19 +45,9 @@ Ox.FormPanel = function(options, self) { width: 240 } ], - items: function(data, callback) { - setTimeout(function() { - callback({ - data: { - items: Ox.isEmpty(data) - ? self.sections.length - : self.options.form.map(function(section) { - return {title: section.title, valid: section.valid}; - }) - } - }); - }, 250); - }, + items: self.options.form.map(function(section) { + return {title: section.title, valid: false}; + }), max: 1, min: 1, selected: [self.sections[0].id], @@ -90,7 +80,7 @@ Ox.FormPanel = function(options, self) { .append( $('
') .css({marginBottom: '8px', fontWeight: 'bold'}) - .html(section.title) + .html((i + 1) + '. ' + section.title) ) .append( $('
') @@ -99,27 +89,22 @@ Ox.FormPanel = function(options, self) { ) .append( self.$forms[i] = Ox.Form({ - items: section.items + items: section.items, + validate: section.validate }) .bindEvent({ change: function(data) { - var valid; - if (section.validate) { - valid = section.validate(section.title, data); - self.$list.value(section.title, 'valid', valid); - that.triggerEvent('validate', { - title: section.title, - data: {valid: valid} - }); - } - //var valid = section.validate(section.title, data); - //self.$list.value(section.title, 'valid', valid); - //that.triggerEvent('change', data); + Ox.Log('FORM', '---CHANGE---', data, self.$forms[i].valid()) + self.$list.value(section.title, 'valid', self.$forms[i].valid()); + that.triggerEvent('change', { + section: section.title, + data: data + }); }, validate: function(data) { self.$list.value(section.title, 'valid', data.valid); that.triggerEvent('validate', { - title: section.title, + section: section.title, data: data }); } @@ -129,6 +114,11 @@ Ox.FormPanel = function(options, self) { .appendTo(self.$section); }); + self.$forms.forEach(function($form, i) { + Ox.print(self.sections[i], 'valid', $form.valid()); + self.$list.value(self.sections[i], 'valid', $form.valid()); + }); + self.$sections[0].show(); that.$element = Ox.SplitPanel({ @@ -157,6 +147,44 @@ Ox.FormPanel = function(options, self) { return index; } + that.renderPrintVersion = function(title) { + var $printVersion = $('
').css({overflowY: 'auto'}); + $printVersion.append( + $('
') + .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