diff --git a/config/plugins/visualizations/charts/static/app.js b/config/plugins/visualizations/charts/static/app.js index 7dc9969fe43..3c95349c926 100644 --- a/config/plugins/visualizations/charts/static/app.js +++ b/config/plugins/visualizations/charts/static/app.js @@ -1,10 +1,10 @@ // dependencies define(['library/portlet', 'library/ui', 'library/utils', 'views/charts', 'views/viewport', 'views/chart', 'views/group', - 'models/datasets', 'models/chart', 'models/charts', 'models/types'], + 'models/config', 'models/datasets', 'models/chart', 'models/charts', 'models/group', 'models/types'], function( Portlet, Ui, Utils, ChartsView, ViewportView, ChartView, GroupView, - Datasets, Chart, Charts, Types + Config, Datasets, Chart, Charts, Group, Types ) { // widget @@ -19,10 +19,14 @@ return Backbone.View.extend( // link galaxy this.modal = parent.Galaxy.modal; + // create configuration model + this.config = new Config(); + // create chart models this.types = new Types(); this.chart = new Chart(); this.charts = new Charts(); + this.group = new Group(); // create dataset handler this.datasets = new Datasets(this); diff --git a/config/plugins/visualizations/charts/static/models/chart.js b/config/plugins/visualizations/charts/static/models/chart.js index c729ab4c5a3..67e5c2fc4d5 100644 --- a/config/plugins/visualizations/charts/static/models/chart.js +++ b/config/plugins/visualizations/charts/static/models/chart.js @@ -22,8 +22,9 @@ return Backbone.Model.extend( // reset reset: function() { - this.clear().set(this.defaults); + this.clear({silent: true}).set(this.defaults); this.groups.reset(); + this.trigger('reset', this); }, // copy diff --git a/config/plugins/visualizations/charts/static/models/config.js b/config/plugins/visualizations/charts/static/models/config.js new file mode 100644 index 00000000000..2ac90f096ac --- /dev/null +++ b/config/plugins/visualizations/charts/static/models/config.js @@ -0,0 +1,16 @@ +// dependencies +define([], function() { + + +// model +return Backbone.Model.extend( +{ + // options + defaults : { + query_limit : 20, + query_pace : 1000, + query_max : 5 + } +}); + +}); \ No newline at end of file diff --git a/config/plugins/visualizations/charts/static/models/group.js b/config/plugins/visualizations/charts/static/models/group.js index 6727bbcb815..445e59cae79 100644 --- a/config/plugins/visualizations/charts/static/models/group.js +++ b/config/plugins/visualizations/charts/static/models/group.js @@ -1,23 +1,14 @@ // dependencies -define(['library/utils'], function(Utils) { - +define([], function() { // model return Backbone.Model.extend( { - // defaults - defaults : { - }, - - // initialize - initialize: function(options) - { - }, - // reset reset: function() { - this.clear().set(this.defaults); + this.clear({silent: true}).set(this.defaults); + this.trigger('reset', this); } }); diff --git a/config/plugins/visualizations/charts/static/views/chart.js b/config/plugins/visualizations/charts/static/views/chart.js index 90ed350976e..02a443974d5 100644 --- a/config/plugins/visualizations/charts/static/views/chart.js +++ b/config/plugins/visualizations/charts/static/views/chart.js @@ -125,6 +125,9 @@ return Backbone.View.extend( this.chart.on('change:type', function(chart) { self.table.value(chart.get('type')); }); + this.chart.on('reset', function(chart) { + self._resetChart(); + }); // collection events this.app.charts.on('add', function(chart) { @@ -140,23 +143,17 @@ return Backbone.View.extend( }); // reset - this.reset(); + this._resetChart(); }, // reset - reset: function() { - this.chart.reset(); + _resetChart: function() { this.chart.set('id', Utils.uuid()); this.chart.set('dataset_id', this.app.options.dataset.id); this.chart.set('type', 'bardiagram'); this.chart.set('title', 'Chart title'); }, - // set chart - setChart: function(new_chart) { - this.chart.copy(new_chart); - }, - // create chart _saveChart: function() { // update chart data diff --git a/config/plugins/visualizations/charts/static/views/charts.js b/config/plugins/visualizations/charts/static/views/charts.js index 884e96b60b2..8e5b6b75c59 100644 --- a/config/plugins/visualizations/charts/static/views/charts.js +++ b/config/plugins/visualizations/charts/static/views/charts.js @@ -16,12 +16,12 @@ return Backbone.View.extend( ondblclick : function(chart_id) { // get chart var chart = self.app.charts.get(chart_id); - + self.app.chart.copy(chart); + // show edit self.$el.hide(); // update model and show create - self.app.chart_view.setChart(chart); self.app.chart_view.$el.show(); }, onchange : function(chart_id) { @@ -41,7 +41,7 @@ return Backbone.View.extend( tooltip: 'Create', onclick: function() { self.$el.hide(); - self.app.chart_view.reset(); + self.app.chart.reset(); self.app.chart_view.$el.show(); } }), @@ -57,11 +57,11 @@ return Backbone.View.extend( // get chart var chart = self.app.charts.get(chart_id); + self.app.chart.copy(chart); // show edit self.$el.hide(); self.app.chart_view.$el.show(); - self.app.chart_view.setChart(chart); } }), 'delete' : new Ui.ButtonIcon({ diff --git a/config/plugins/visualizations/charts/static/views/group.js b/config/plugins/visualizations/charts/static/views/group.js index b5ac01b0c71..d4de13ffc9c 100644 --- a/config/plugins/visualizations/charts/static/views/group.js +++ b/config/plugins/visualizations/charts/static/views/group.js @@ -1,13 +1,10 @@ // dependencies -define(['library/portlet', 'library/table', 'library/ui', 'library/utils', 'models/group'], - function(Portlet, Table, Ui, Utils, Group) { +define(['library/portlet', 'library/table', 'library/ui', 'library/utils'], + function(Portlet, Table, Ui, Utils) { // chart config return Backbone.View.extend( { - // model - group: new Group(), - // columns columns: [], @@ -18,6 +15,7 @@ return Backbone.View.extend( // get current chart object this.chart = this.app.chart; + this.group = this.app.group; // ui elements this.message = new Ui.Message(); @@ -69,6 +67,9 @@ return Backbone.View.extend( this.group.on('change', function() { self._refreshGroup(); }); + this.group.on('reset', function() { + self._resetGroup(); + }); }, // show @@ -77,8 +78,7 @@ return Backbone.View.extend( }, // reset - reset: function() { - this.group.reset(); + _resetGroup: function() { this.group.set('id', Utils.uuid()); this.group.set('label', 'Group label'); }, diff --git a/config/plugins/visualizations/charts/static/views/groups.js b/config/plugins/visualizations/charts/static/views/groups.js index 9674edbfc77..bd155c53288 100644 --- a/config/plugins/visualizations/charts/static/views/groups.js +++ b/config/plugins/visualizations/charts/static/views/groups.js @@ -37,9 +37,9 @@ return Backbone.View.extend( icon : 'fa-plus', tooltip: 'Create', onclick: function() { + self.app.group.reset(); self.app.chart_view.$el.hide(); self.app.group_view.show(); - self.app.group_view.reset(); } }), 'edit' : new Ui.ButtonIcon({