diff --git a/frappe/public/js/frappe/dom.js b/frappe/public/js/frappe/dom.js index df3f7a00d1..719f9c2ddb 100644 --- a/frappe/public/js/frappe/dom.js +++ b/frappe/public/js/frappe/dom.js @@ -11,9 +11,12 @@ frappe.dom = { return document.getElementById(id); }, set_unique_id: function(ele) { + var $ele = $(ele); + if($ele.attr('id')) { + return $ele.attr('id'); + } var id = 'unique-' + frappe.dom.id_count; - if(ele) - ele.setAttribute('id', id); + $ele.attr('id', id); frappe.dom.id_count++; return id; }, diff --git a/frappe/public/js/frappe/form/dashboard.js b/frappe/public/js/frappe/form/dashboard.js index 4876c6841b..1a75bdc5a6 100644 --- a/frappe/public/js/frappe/form/dashboard.js +++ b/frappe/public/js/frappe/form/dashboard.js @@ -354,8 +354,7 @@ frappe.ui.form.Dashboard = Class.extend({ this.chart_area.removeClass('hidden'); $.extend(opts, { - wrapper: me.wrapper, - bind_to: ".form-chart", + wrapper: me.wrapper.find('.form-chart'), padding: { right: 30, bottom: 30 diff --git a/frappe/public/js/frappe/ui/charts.js b/frappe/public/js/frappe/ui/charts.js index 5f010fa552..21c4539a27 100644 --- a/frappe/public/js/frappe/ui/charts.js +++ b/frappe/public/js/frappe/ui/charts.js @@ -6,6 +6,8 @@ frappe.ui.Chart = Class.extend({ $.extend(this.opts, opts); this.show_chart(false); + this.opts.bind_to = frappe.dom.set_unique_id(this.opts.wrapper); + if(this.opts.data && ((this.opts.data.columns && this.opts.data.columns.length >= 1) || (this.opts.data.rows && this.opts.data.rows.length >= 1))) { this.chart = this.render_chart(); @@ -17,7 +19,7 @@ frappe.ui.Chart = Class.extend({ render_chart: function() { var chart_dict = { - bindto: this.opts.bind_to, + bindto: '#' + this.opts.bind_to, data: {}, axis: { x: { @@ -49,7 +51,7 @@ frappe.ui.Chart = Class.extend({ }, show_chart: function(show) { - this.opts.wrapper.find(this.opts.bind_to).toggle(show); + this.opts.wrapper.toggle(show); }, set_chart_size: function(width, height) { diff --git a/frappe/public/js/frappe/views/reports/grid_report.js b/frappe/public/js/frappe/views/reports/grid_report.js index 26ba609c35..47a807e6f0 100644 --- a/frappe/public/js/frappe/views/reports/grid_report.js +++ b/frappe/public/js/frappe/views/reports/grid_report.js @@ -366,10 +366,9 @@ frappe.views.GridReport = Class.extend({ }, make: function() { var me = this; - this.chart_id = 'chart-' + cstr(cint(Math.random() * 10000000000)); // chart wrapper - this.chart_area = $('
').appendTo(this.wrapper); + this.chart_area = $('').appendTo(this.wrapper); this.page.add_menu_item(__("Export"), function() { return me.export(); }, true); @@ -664,14 +663,13 @@ frappe.views.GridReportWithPlot = frappe.views.GridReport.extend({ setup_chart: function() { var me = this; if (in_list(["Daily", "Weekly"], this.filter_inputs.range.val())) { - this.wrapper.find("#" + me.chart_id).toggle(false); + this.chart_area.toggle(false); return; } var chart_data = this.get_chart_data ? this.get_chart_data() : null; - + this.chart = new frappe.ui.Chart({ - wrapper: me.wrapper, - bind_to: "#" + me.chart_id, + wrapper: this.chart_area, data: chart_data }); }, @@ -698,19 +696,19 @@ frappe.views.GridReportWithPlot = frappe.views.GridReport.extend({ get_chart_data: function() { var me = this; - + var plottable_cols = []; $.each(me.columns, function(idx, col) { if(col.formatter==me.currency_formatter && !col.hidden && col.plot!==false) { plottable_cols.push(col.field); } }) - + var data = { x: 'x', 'columns': [['x'].concat(plottable_cols)] }; - + $.each(this.data, function(i, item) { if (item.checked) { var data_points = [item.name]; diff --git a/frappe/public/js/frappe/views/reports/query_report.js b/frappe/public/js/frappe/views/reports/query_report.js index 8d65e7e232..d2791dc2b8 100644 --- a/frappe/public/js/frappe/views/reports/query_report.js +++ b/frappe/public/js/frappe/views/reports/query_report.js @@ -41,9 +41,7 @@ frappe.views.QueryReport = Class.extend({ this.wrapper = $("