/
groups.js
79 lines (77 loc) · 4.22 KB
/
groups.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* This class renders the chart configuration form. */
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;
this.app = app;
this.chart = app.chart;
this.group = options.group;
this.setElement( $( '<div/>' ) );
this.chart.on( 'change:dataset_id change:type', function() { self.render() } );
this.render();
},
render: function() {
var self = this;
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;
if ( dataset_id && chart_type ) {
this.chart.state( 'wait', 'Loading metadata...' );
this.app.deferred.execute( function( process ) {
self.app.datasets.request({
id : dataset_id,
success : function( dataset ) {
for ( var id in chart_definition.columns ) {
var columns = [];
var input_def = chart_definition.columns[ id ];
input_def.is_auto && columns.push( { 'label': 'Column: Row Number', 'value': 'auto' } );
input_def.is_zero && columns.push( { 'label' : 'Column: None', 'value' : 'zero' } );
var meta = dataset.metadata_column_types;
for ( var key in meta ) {
var valid = ( [ 'int', 'float' ].indexOf( meta[ key ] ) != -1 && input_def.is_numeric ) || input_def.is_text || input_def.is_label;
valid && columns.push( { 'label' : 'Column: ' + ( parseInt( key ) + 1 ), 'value' : key } );
}
inputs.push( { name: id, label: input_def.title, type: 'select', data: columns } );
}
self.chart.state( 'ok', 'Metadata initialized...' );
self.form = new Form( {
inputs : FormData.populate( inputs, self.group.attributes ),
cls : 'ui-portlet-plain',
onchange: function() {
self.group.set( self.form.data.create() );
self.chart.set( 'modified', true );
}
} );
self.group.set( self.form.data.create() );
self.$el.empty().append( self.form.$el );
process.resolve();
}
});
});
}
}
});
return Backbone.View.extend({
initialize: function( app ) {
var repeat = new Repeat.View({
title : 'Data series',
title_new : 'Data series',
min : 1,
onnew : function() { app.chart.groups.add( { id : Utils.uid() } ) }
});
this.setElement( repeat.$el );
app.chart.groups.on( 'add remove reset', function() { app.chart.set( 'modified', true ) } )
.on( 'remove', function( group ) { repeat.del( group.id ) } )
.on( 'reset', function() { repeat.delAll() } )
.on( 'add', function( group ) {
repeat.add({
id : group.id,
cls : 'ui-portlet-panel',
$el : ( new GroupView( app, { group: group } ) ).$el,
ondel : function() { app.chart.groups.remove( group ) }
});
});
}
});
});