mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-28 02:58:18 +08:00
Visualizations API: properly return visualization model id from update; Visualizations MVC: bring setConfig into line with Backbone API
This commit is contained in:
@@ -1,24 +1,6 @@
|
||||
//define([
|
||||
//], function(){
|
||||
|
||||
//function saveVis( title, config ){
|
||||
// var xhr = jQuery.ajax( '/api/visualizations', {
|
||||
// type : 'POST',
|
||||
// data : {
|
||||
// type : 'scatterplot',
|
||||
// title : title,
|
||||
// config : JSON.stringify( config )
|
||||
// }
|
||||
// });
|
||||
// xhr.fail( function( xhr, status, message ){
|
||||
// console.debug( jQuery.makeArray( arguments ) );
|
||||
// console.error( 'Error saving visualization:', xhr.responseJSON.error );
|
||||
// });
|
||||
// return xhr.then( function( saveInfo ){
|
||||
// return saveInfo;
|
||||
// });
|
||||
//}
|
||||
|
||||
//==============================================================================
|
||||
/** @class Model for a saved Galaxy visualization.
|
||||
*
|
||||
@@ -36,21 +18,13 @@ var Visualization = Backbone.Model.extend( LoggableMixin ).extend(
|
||||
|
||||
/** default attributes for a model */
|
||||
defaults : {
|
||||
//id : null,
|
||||
//type : null,
|
||||
//title : null,
|
||||
//dbkey : null,
|
||||
//user_id : null,
|
||||
//slug : null,
|
||||
//revisions : [],
|
||||
//latest_revision : null
|
||||
|
||||
//(this is unusual in that visualizations don't have configs, revisions do)
|
||||
//config : {}
|
||||
config : {}
|
||||
},
|
||||
|
||||
url : function(){
|
||||
return galaxy_config.root + 'api/visualizations';
|
||||
/** override urlRoot to handle presence/absence of galaxy_config */
|
||||
urlRoot : function(){
|
||||
var apiUrl = '/api/visualizations';
|
||||
return (( window.galaxy_config && galaxy_config.root )?( galaxy_config.root + apiUrl ):( apiUrl ));
|
||||
},
|
||||
|
||||
/** Set up the model, determine if accessible, bind listeners
|
||||
@@ -58,27 +32,39 @@ var Visualization = Backbone.Model.extend( LoggableMixin ).extend(
|
||||
*/
|
||||
initialize : function( data ){
|
||||
this.log( this + '.initialize', data, this.attributes );
|
||||
|
||||
// munge config sub-object here since bbone won't handle defaults with this
|
||||
if( _.isObject( data.config ) && _.isObject( this.defaults.config ) ){
|
||||
_.defaults( data.config, this.defaults.config );
|
||||
}
|
||||
|
||||
this._setUpListeners();
|
||||
},
|
||||
|
||||
/** set up any event listeners
|
||||
*/
|
||||
_setUpListeners : function(){
|
||||
//this.on( 'change', function(){
|
||||
// console.info( 'change:', arguments );
|
||||
//});
|
||||
},
|
||||
|
||||
// ........................................................................ config
|
||||
setConfig: function( config ){
|
||||
var oldConfig = this.get( 'config' );
|
||||
// extend if already exists (and clone in order to trigger change)
|
||||
if( _.isObject( oldConfig ) ){
|
||||
config = _.extend( _.clone( oldConfig ), config );
|
||||
/** override set to properly allow update and trigger change when setting the sub-obj 'config' */
|
||||
set: function( key, val ){
|
||||
//TODO: validate config is object
|
||||
if( key === 'config' ){
|
||||
var oldConfig = this.get( 'config' );
|
||||
// extend if already exists (is this correct behavior? no way to eliminate keys or reset entirely)
|
||||
// clone in order to trigger change (diff. obj ref)
|
||||
if( _.isObject( oldConfig ) ){
|
||||
val = _.extend( _.clone( oldConfig ), val );
|
||||
}
|
||||
}
|
||||
this.set( 'config', config );
|
||||
Backbone.Model.prototype.set.call( this, key, val );
|
||||
return this;
|
||||
},
|
||||
|
||||
// ........................................................................ common queries
|
||||
// ........................................................................ ajax
|
||||
// ........................................................................ misc
|
||||
/** String representation */
|
||||
toString : function(){
|
||||
|
||||
@@ -1 +1 @@
|
||||
var Visualization=Backbone.Model.extend(LoggableMixin).extend({defaults:{},url:function(){return galaxy_config.root+"api/visualizations"},initialize:function(a){this.log(this+".initialize",a,this.attributes);this._setUpListeners()},_setUpListeners:function(){},setConfig:function(b){var a=this.get("config");if(_.isObject(a)){b=_.extend(_.clone(a),b)}this.set("config",b);return this},toString:function(){var a=this.get("id")||"";if(this.get("title")){a+=":"+this.get("title")}return"Visualization("+a+")"}});var VisualizationCollection=Backbone.Collection.extend(LoggableMixin).extend({model:Visualization,url:function(){return galaxy_config.root+"api/visualizations"},initialize:function(b,a){a=a||{}},set:function(c,a){var b=this;c=_.map(c,function(e){var f=b.get(e.id);if(!f){return e}var d=f.toJSON();_.extend(d,e);return d});Backbone.Collection.prototype.set.call(this,c,a)},toString:function(){return(["VisualizationCollection(",[this.historyId,this.length].join(),")"].join(""))}});
|
||||
var Visualization=Backbone.Model.extend(LoggableMixin).extend({defaults:{config:{}},urlRoot:function(){var a="/api/visualizations";return((window.galaxy_config&&galaxy_config.root)?(galaxy_config.root+a):(a))},initialize:function(a){this.log(this+".initialize",a,this.attributes);if(_.isObject(a.config)&&_.isObject(this.defaults.config)){_.defaults(a.config,this.defaults.config)}this._setUpListeners()},_setUpListeners:function(){},set:function(b,c){if(b==="config"){var a=this.get("config");if(_.isObject(a)){c=_.extend(_.clone(a),c)}}Backbone.Model.prototype.set.call(this,b,c);return this},toString:function(){var a=this.get("id")||"";if(this.get("title")){a+=":"+this.get("title")}return"Visualization("+a+")"}});var VisualizationCollection=Backbone.Collection.extend(LoggableMixin).extend({model:Visualization,url:function(){return galaxy_config.root+"api/visualizations"},initialize:function(b,a){a=a||{}},set:function(c,a){var b=this;c=_.map(c,function(e){var f=b.get(e.id);if(!f){return e}var d=f.toJSON();_.extend(d,e);return d});Backbone.Collection.prototype.set.call(this,c,a)},toString:function(){return(["VisualizationCollection(",[this.historyId,this.length].join(),")"].join(""))}});
|
||||
Reference in New Issue
Block a user