Skip to content

Commit

Permalink
Merge pull request #2239 from guerler/rename_jsvalidate_000
Browse files Browse the repository at this point in the history
Rename/refactor Utils.validate() to Utils.isEmpty()
  • Loading branch information
dannon committed Apr 27, 2016
2 parents 01472fd + faa2e69 commit d7031d9
Show file tree
Hide file tree
Showing 24 changed files with 59 additions and 31 deletions.
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/form/form-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ define(['utils/utils',
// field replaces e.g. a select field
if ( input_def.options ) {
input_def.area = input_def.multiple;
if ( !Utils.validate( input_def.value ) ) {
if ( Utils.isEmpty( input_def.value ) ) {
input_def.value = null;
} else {
if ( $.isArray( input_def.value ) ) {
Expand Down
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/tool/tool-form-composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ define([ 'utils/utils', 'mvc/ui/ui-misc', 'mvc/form/form-view', 'mvc/form/form-d
input.options && ( ( input.options.length == 0 && !data_resolved ) || is_workflow_parameter ) && ( input.is_workflow = true );
input.value && input.value.__class__ == 'RuntimeValue' && ( input.value = null );
if ( !is_data_input && input.type !== 'hidden' && !is_workflow_parameter ) {
if ( input.optional || ( Utils.validate( input.value ) && input.value !== '' ) ) {
if ( input.optional || ( !Utils.isEmpty( input.value ) && input.value !== '' ) ) {
input.collapsible_value = input.value;
input.collapsible_preview = true;
}
Expand Down
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/ui/ui-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var View = Backbone.View.extend({
add: function(options) {
var self = this;
if (this.$('[id="' + options.id + '"]').length === 0) {
if (Utils.validate(options.id)) {
if (!Utils.isEmpty(options.id)) {
var $el = $(this._templateRow({
id : options.id,
name : options.name
Expand Down
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/ui/ui-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ var Base = Backbone.View.extend({
});

// get selected elements
if (!Utils.validate(selected)) {
if (Utils.isEmpty(selected)) {
return null;
}

Expand Down
5 changes: 1 addition & 4 deletions client/galaxy/scripts/mvc/ui/ui-select-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ var View = Backbone.View.extend({
*/
_getValue: function() {
var val = this.$select.val();
if (!Utils.validate(val)) {
return null;
}
return val;
return Utils.isEmpty( val ) ? null : val;
},

/** Returns all currently available options
Expand Down
12 changes: 6 additions & 6 deletions client/galaxy/scripts/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ function sanitize(content) {
};

/**
* Validate atomic values or list of values
* Checks if a value or list of values is `empty`
* usually used for selectable options
* @param{String} value - Value or list to be validated
*/
function validate ( value ) {
function isEmpty ( value ) {
if ( !( value instanceof Array ) ) {
value = [ value ];
}
if ( value.length === 0 ) {
return false;
return true;
}
for( var i in value ) {
if ( [ '__null__', '__undefined__', null, undefined ].indexOf( value[ i ] ) > -1 ) {
return false;
return true;
}
}
return true;
return false;
};

/**
Expand Down Expand Up @@ -272,7 +272,7 @@ return {
request: request,
sanitize: sanitize,
textify: textify,
validate: validate,
isEmpty: isEmpty,
deepeach: deepeach,
isJSON: isJSON
};
Expand Down
2 changes: 1 addition & 1 deletion static/maps/mvc/form/form-parameters.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion static/maps/mvc/tool/tool-form-composite.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/maps/mvc/ui/ui-list.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d7031d9

Please sign in to comment.