Skip to content

Commit

Permalink
Populate input states for settings and group forms
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Aug 19, 2016
1 parent d952e87 commit b23b18c
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 57 deletions.
15 changes: 11 additions & 4 deletions client/galaxy/scripts/mvc/form/form-data.js
@@ -1,6 +1,4 @@
/*
This class maps the form dom to an api compatible javascript dictionary.
*/
/* This class maps the form dom to an api compatible javascript dictionary. */
define([ 'utils/utils' ], function( Utils ) {
var Manager = Backbone.Model.extend({
initialize: function( app ) {
Expand Down Expand Up @@ -234,8 +232,17 @@ define([ 'utils/utils' ], function( Utils ) {
}
};

/** Populate input state */
var populate = function( inputs, state ) {
visitInputs( inputs, function( input, name ) {
state[ name ] !== undefined && ( input.value = state[ name ] );
});
return inputs;
};

return {
Manager : Manager,
visitInputs : visitInputs
visitInputs : visitInputs,
populate : populate
}
});
10 changes: 0 additions & 10 deletions client/galaxy/scripts/mvc/form/form-view.js
Expand Up @@ -10,19 +10,9 @@ function( Utils, Portlet, Ui, FormSection, FormData ) {
cls : 'ui-portlet-limited',
icon : null,
always_refresh : true,
values : null,
inputs : []
});
this.setElement( '<div/>' );
this.options.inputs = $.extend( {}, this.options.inputs, true );
this.options.values ? this.set( this.options.values ) : this.render();
},

/** Set parameter values from value dictionary, needs to be enhanced to support repeats */
set: function( values ) {
FormData.visitInputs( this.options.inputs, function( input, name ) {
input.value = values[ name ] !== undefined ? values[ name ] : input.value;
});
this.render();
},

Expand Down
18 changes: 17 additions & 1 deletion client/galaxy/scripts/utils/utils.js
Expand Up @@ -25,6 +25,21 @@ function deepeach( dict, callback ) {
}
}

/** Clone */
function clone( obj ) {
if ( obj instanceof Array ) {
var copy = [];
for ( var i = 0, len = obj.length; i < len; i++ ) { copy[ i ] = clone( obj[ i ] ) }
return copy;
}
if ( obj instanceof Object ) {
var copy = {};
for ( var attr in obj ) { obj.hasOwnProperty( attr ) && ( copy[ attr ] = clone( obj[ attr ] ) ) }
return copy;
}
return obj;
}

/**
* Check if a string is a json string
* @param{String} text - Content to be validated
Expand Down Expand Up @@ -275,7 +290,8 @@ return {
textify: textify,
isEmpty: isEmpty,
deepeach: deepeach,
isJSON: isJSON
isJSON: isJSON,
clone: clone
};

});
17 changes: 2 additions & 15 deletions config/plugins/visualizations/charts/static/models/chart.js
@@ -1,17 +1,4 @@
define( [ 'utils/utils' ], function( Utils ) {
var Groups = Backbone.Collection.extend({
model: Backbone.Model.extend({
defaults : {
key : 'Data label',
date : ''
},

reset: function(){
this.clear( { silent: true } ).set( this.defaults );
this.trigger( 'reset', this );
}
})
});
return Backbone.Model.extend({
defaults : {
id : null,
Expand All @@ -26,8 +13,8 @@ define( [ 'utils/utils' ], function( Utils ) {
},

initialize: function( options ) {
this.groups = new Groups();
this.settings = new Backbone.Model();
this.groups = new Backbone.Collection();
this.settings = new Backbone.Model();
},

reset: function( options ) {
Expand Down
7 changes: 3 additions & 4 deletions config/plugins/visualizations/charts/static/views/groups.js
@@ -1,5 +1,5 @@
/* This class renders the chart configuration form. */
define( [ 'mvc/form/form-view', 'mvc/form/form-repeat', 'utils/utils' ], function( Form, Repeat, Utils ) {
define( [ 'utils/utils', 'mvc/form/form-view', 'mvc/form/form-repeat', 'mvc/form/form-data' ], function( Utils, Form, Repeat, FormData ) {
var GroupView = Backbone.View.extend({
initialize: function( app, options ) {
var self = this;
Expand All @@ -13,7 +13,7 @@ define( [ 'mvc/form/form-view', 'mvc/form/form-repeat', 'utils/utils' ], functio

render: function() {
var self = this;
var inputs = this.chart.definition.series && this.chart.definition.series.slice() || [];
var inputs = this.chart.definition.series ? Utils.clone( this.chart.definition.series ) : [];
var dataset_id = this.chart.get( 'dataset_id' );
var chart_type = this.chart.get( 'type' );
var chart_definition = this.chart.definition;
Expand All @@ -37,9 +37,8 @@ define( [ 'mvc/form/form-view', 'mvc/form/form-repeat', 'utils/utils' ], functio
}
self.chart.state( 'ok', 'Metadata initialized...' );
self.form = new Form( {
inputs : inputs,
inputs : FormData.populate( inputs, self.group.attributes ),
cls : 'ui-portlet-plain',
values : self.group.attributes,
onchange: function() {
self.group.set( self.form.data.create() );
self.chart.set( 'modified', true );
Expand Down
5 changes: 2 additions & 3 deletions config/plugins/visualizations/charts/static/views/settings.js
@@ -1,5 +1,5 @@
/* This class renders the chart configuration form. */
define( [ 'mvc/form/form-view' ], function( Form ) {
define( [ 'utils/utils', 'mvc/form/form-view', 'mvc/form/form-data' ], function( Utils, Form, FormData ) {
return Backbone.View.extend({
initialize: function( app, options ) {
var self = this;
Expand All @@ -10,8 +10,7 @@ define( [ 'mvc/form/form-view' ], function( Form ) {
render: function() {
var self = this;
this.form = new Form({
inputs : this.chart.definition.settings,
values : this.chart.settings.attributes,
inputs : FormData.populate( Utils.clone( this.chart.definition.settings ), this.chart.settings.attributes ),
cls : 'ui-portlet-plain',
onchange : function() { self.chart.settings.set( self.form.data.create() ); }
});
Expand Down
2 changes: 1 addition & 1 deletion static/maps/mvc/form/form-data.js.map

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

0 comments on commit b23b18c

Please sign in to comment.