From 816730ff659e1338ab3e37a1d45ea337e337b3dd Mon Sep 17 00:00:00 2001 From: Alvin Li Date: Sun, 22 Sep 2013 00:03:36 +0800 Subject: auto redraw chart when: * added new record * modified record data/date * deleted record EditHistoryData page: * added 'delete button' (#delete_btn) * added 'indicator.views.ajax_delete_record()' * updated css style for delete button * updated css style for record 'state' * added check for 'unit' when save 'IndicatorRecord' --- .../templates/indicator/SheetDefault.html | 253 +++++++++++---------- .../templates/indicator/popup/EditHistoryData.html | 1 + 2 files changed, 133 insertions(+), 121 deletions(-) (limited to '97suifangqa/apps/indicator/templates') diff --git a/97suifangqa/apps/indicator/templates/indicator/SheetDefault.html b/97suifangqa/apps/indicator/templates/indicator/SheetDefault.html index 653fde3..07cf2f0 100644 --- a/97suifangqa/apps/indicator/templates/indicator/SheetDefault.html +++ b/97suifangqa/apps/indicator/templates/indicator/SheetDefault.html @@ -109,10 +109,15 @@ dataType: 'json', success: function (dataJson) { //console.log(dataJson); - if (dataJson.failed || dataJson.number_rsp == 0) { + if (dataJson.failed) { // getdata failed or get no data + // XXX: tooltip return false; } + else if (dataJson.number_rsp == 0) { + // show 'edit_hint' + toggle_edit_hint(card_id, "show"); + } else { var begin_dt = moment(dataJson.begin_rsp); var end_dt = moment(dataJson.end_rsp); @@ -132,7 +137,13 @@ window[options_str].xAxis.max = end_dt.valueOf(); window[options_str].series[0].data = dataJson.data; // draw the chart - // given 'chart_str' is the global var name of this chart + // 'chart_str' is the global var name of this chart + // destroy original chart and + // redraw with new options and data + if (window[chart_str] != null) { + window[chart_str].destroy(); + window[chart_str] = null; + } window[chart_str] = new Highcharts.Chart(window[options_str]); } }, @@ -140,134 +151,132 @@ } // }}} {% for ind in indicators %} - {% if not ind|dict_get:"record_empty" %} {# indicator has records #} - {% if ind|dict_get:"dataType" == DATA_TYPES|dict_get:"INTEGER_TYPE" %} - {# INTEGER_TYPE #} - {# TODO #} - {% elif ind|dict_get:"dataType" == DATA_TYPES|dict_get:"FLOAT_TYPE" %} - {# FLOAT_TYPE #} - var chart_{{ ind|dict_get:"id" }}; - // global var name style: 'options_chart_' - // keep the name style, used in 'detail_history' binded functions - var options_chart_{{ ind|dict_get:"id" }} = { // {{{ - chart: { - type: 'areaspline', - renderTo: 'chart_{{ ind|dict_get:"id" }}' - }, + {% if ind|dict_get:"dataType" == DATA_TYPES|dict_get:"INTEGER_TYPE" %} + {# INTEGER_TYPE #} + {# TODO #} + {% elif ind|dict_get:"dataType" == DATA_TYPES|dict_get:"FLOAT_TYPE" %} + {# FLOAT_TYPE #} + var chart_{{ ind|dict_get:"id" }}; + // global var name style: 'options_chart_' + // keep the name style, used in 'detail_history' binded functions + var options_chart_{{ ind|dict_get:"id" }} = { // {{{ + chart: { + type: 'areaspline', + renderTo: 'chart_{{ ind|dict_get:"id" }}' + }, + labels: { + items: [{ // custom label for unit_symbol + html: '{{ ind|dict_get:"std_unit_symbol" }}', + style: { + left: '5px', + top: '0px' + } + }] + }, + series: [{ + data: [] + }], + tooltip: { + formatter: function() { + return '' + Highcharts.dateFormat('%Y-%m-%d', this.x) + '' +'
' + '' + this.y + ' ({{ ind|dict_get:"std_unit_symbol" }})' + ''; + } + }, + xAxis: { + min: null, + max: null + }, + yAxis: { labels: { - items: [{ // custom label for unit_symbol - html: '{{ ind|dict_get:"std_unit_symbol" }}', - style: { - left: '5px', - top: '0px' - } - }] - }, - series: [{ - data: [] - }], - tooltip: { + useHTML: true, formatter: function() { - return '' + Highcharts.dateFormat('%Y-%m-%d', this.x) + '' +'
' + '' + this.y + ' ({{ ind|dict_get:"std_unit_symbol" }})' + ''; - } - }, - xAxis: { - min: null, - max: null - }, - yAxis: { - labels: { - useHTML: true, - formatter: function() { - var value = this.value; - if (value > 9999.0) { - var value_str = value.toExponential(2); - var m = exp_regex.exec(value_str); - var ylabel = m[1] + m[2].replace(/(\.0*|0*)$/, '') + '×10' + m[3]+m[4] + ''; - } - else { - var ylabel = value.toString(); - } - return ylabel; + var value = this.value; + if (value > 9999.0) { + var value_str = value.toExponential(2); + var m = exp_regex.exec(value_str); + var ylabel = m[1] + m[2].replace(/(\.0*|0*)$/, '') + '×10' + m[3]+m[4] + ''; } + else { + var ylabel = value.toString(); + } + return ylabel; } } - }; // }}} - // draw chart - $(document).ready(function() { - chart_getdata_draw("chart_{{ ind|dict_get:"id" }}", - {{ ind|dict_get:"id" }}, - "options_chart_{{ ind|dict_get:"id" }}", - chart_getdata_type, chart_dp_num, - null, null - ); - }); - {% elif ind|dict_get:"dataType" == DATA_TYPES|dict_get:"RANGE_TYPE" %} - {# RANGE_TYPE #} - var chart_{{ ind|dict_get:"id" }}; - var options_chart_{{ ind|dict_get:"id" }} = { // {{{ - chart: { - type: 'areasplinerange', - renderTo: 'chart_{{ ind|dict_get:"id" }}' - }, + } + }; // }}} + // draw chart + $(document).ready(function() { + chart_getdata_draw("chart_{{ ind|dict_get:"id" }}", + {{ ind|dict_get:"id" }}, + "options_chart_{{ ind|dict_get:"id" }}", + chart_getdata_type, chart_dp_num, + null, null + ); + }); + {% elif ind|dict_get:"dataType" == DATA_TYPES|dict_get:"RANGE_TYPE" %} + {# RANGE_TYPE #} + var chart_{{ ind|dict_get:"id" }}; + var options_chart_{{ ind|dict_get:"id" }} = { // {{{ + chart: { + type: 'areasplinerange', + renderTo: 'chart_{{ ind|dict_get:"id" }}' + }, + labels: { + items: [{ // custom label for unit_symbol + html: '{{ ind|dict_get:"std_unit_symbol" }}', + style: { + left: '5px', + top: '0px' + } + }] + }, + series: [{ + data: [] + }], + tooltip: { + formatter: function() { + return '' + Highcharts.dateFormat('%Y-%m-%d', this.x) + '' + '
' + '' + this.point.low + ' ∼ ' + this.point.high + ' ({{ ind|dict_get:"std_unit_symbol" }})' + ''; + } + }, + xAxis: { + min: null, + max: null + }, + yAxis: { labels: { - items: [{ // custom label for unit_symbol - html: '{{ ind|dict_get:"std_unit_symbol" }}', - style: { - left: '5px', - top: '0px' - } - }] - }, - series: [{ - data: [] - }], - tooltip: { + useHTML: true, formatter: function() { - return '' + Highcharts.dateFormat('%Y-%m-%d', this.x) + '' + '
' + '' + this.point.low + ' ∼ ' + this.point.high + ' ({{ ind|dict_get:"std_unit_symbol" }})' + ''; - } - }, - xAxis: { - min: null, - max: null - }, - yAxis: { - labels: { - useHTML: true, - formatter: function() { - var value = this.value; - if (value > 9999.0) { - var value_str = value.toExponential(2); - var m = exp_regex.exec(value_str); - var ylabel = m[1] + m[2].replace(/(\.0*|0*)$/, '') + '×10' + m[3]+m[4] + ''; - } - else { - var ylabel = value.toString(); - } - return ylabel; + var value = this.value; + if (value > 9999.0) { + var value_str = value.toExponential(2); + var m = exp_regex.exec(value_str); + var ylabel = m[1] + m[2].replace(/(\.0*|0*)$/, '') + '×10' + m[3]+m[4] + ''; + } + else { + var ylabel = value.toString(); } + return ylabel; } } - }; // }}} - // draw chart - $(document).ready(function() { - chart_getdata_draw("chart_{{ ind|dict_get:"id" }}", - {{ ind|dict_get:"id" }}, - "options_chart_{{ ind|dict_get:"id" }}", - chart_getdata_type, chart_dp_num, - null, null - ); - }); - {% elif ind|dict_get:"dataType" == DATA_TYPES|dict_get:"FLOAT_RANGE_TYPE" %} - {# FLOAT_RANGE_TYPE #} - {# TODO #} - {% elif ind|dict_get:"dataType" == DATA_TYPES|dict_get:"PM_TYPE" %} - {# PM_TYPE #} - {# TODO #} - {% else %} - {# unknown TYPE #} - {% endif %} {# end: DATA_TYPES #} - {% endif %} {# end: record_empty #} + } + }; // }}} + // draw chart + $(document).ready(function() { + chart_getdata_draw("chart_{{ ind|dict_get:"id" }}", + {{ ind|dict_get:"id" }}, + "options_chart_{{ ind|dict_get:"id" }}", + chart_getdata_type, chart_dp_num, + null, null + ); + }); + {% elif ind|dict_get:"dataType" == DATA_TYPES|dict_get:"FLOAT_RANGE_TYPE" %} + {# FLOAT_RANGE_TYPE #} + {# TODO #} + {% elif ind|dict_get:"dataType" == DATA_TYPES|dict_get:"PM_TYPE" %} + {# PM_TYPE #} + {# TODO #} + {% else %} + {# unknown TYPE #} + {% endif %} {# end: DATA_TYPES #} {% endfor %} {% endblock %} @@ -355,11 +364,13 @@ {{ ind|dict_get:"last_record"|dict_get:"date" }} + {% comment %} {% if ind|dict_get:"record_empty" %} {% else %}
{% endif %} + {% endcomment %}
@@ -469,7 +480,7 @@ 化验日期 数据记录 - 是否正常 + 状态 diff --git a/97suifangqa/apps/indicator/templates/indicator/popup/EditHistoryData.html b/97suifangqa/apps/indicator/templates/indicator/popup/EditHistoryData.html index 7c530ea..efe8588 100644 --- a/97suifangqa/apps/indicator/templates/indicator/popup/EditHistoryData.html +++ b/97suifangqa/apps/indicator/templates/indicator/popup/EditHistoryData.html @@ -90,6 +90,7 @@ {% endif %} +
{% csrf_token %} -- cgit v1.2.2