From fc2fa3dc0456b19adb95e383c1da89d3979a01b3 Mon Sep 17 00:00:00 2001 From: Omer Date: Wed, 24 Jun 2015 00:14:07 +0300 Subject: [PATCH 1/2] Added AJAX get and pushed new fields to marker --- main.py | 3 -- static/js/marker.js | 91 +++++++++++++++++++++++--------------------- templates/index.html | 6 ++- 3 files changed, 51 insertions(+), 49 deletions(-) diff --git a/main.py b/main.py index 4a547169..b7893c2c 100755 --- a/main.py +++ b/main.py @@ -135,7 +135,6 @@ def marker(marker_id): involved = db_session.query(Involved).filter(Involved.accident_id == marker_id) vehicles = db_session.query(Vehicle).filter(Vehicle.accident_id == marker_id) list_to_return = list() - list_to_return.append("Involved: ") for inv in involved: obj = inv.serialize() if (92,obj["age_group"]) in lmsDictionary: @@ -153,8 +152,6 @@ def marker(marker_id): if (81,obj["home_residence_type"]) in lmsDictionary: obj["home_residence_type"] = lmsDictionary[81,obj["home_residence_type"]] list_to_return.append(obj) - list_to_return.append("]") - list_to_return.append("Vehicles: ") for veh in vehicles: obj = veh.serialize() if (111,obj["engine_volume"]) in lmsDictionary: diff --git a/static/js/marker.js b/static/js/marker.js index f23246f8..3fe86d5a 100644 --- a/static/js/marker.js +++ b/static/js/marker.js @@ -15,27 +15,6 @@ var MarkerView = Backbone.View.extend({ this.$el.find("." + value).text(fields[field] + ": " + localization[field][this.model.get(value)]); } }, - localize_inv : function(field,value) { - // localizes involved data - if (this.model.has(value) && this.model.get(value)!="" && - inv_dict[field][this.model.get(value)]!=undefined) { - this.$el.find("." + value).text(fields[field] + ": " + inv_dict[field][this.model.get(value)]); - } - }, - localize_veh : function(field,value) { - // localizes vehicles data - if (this.model.has(value) && this.model.get(value)!="" && - veh_dict[field][this.model.get(value)]!=undefined) { - this.$el.find("." + value).text(fields[field] + ": " + veh_dict[field][this.model.get(value)]); - } - }, - localize_num : function(field,value) { - // localizes interger data values - if (this.model.has(value) && this.model.get(value)!="" && - fields[field]!=undefined) { - this.$el.find("." + value).text(fields[field] + ": " + this.model.get(value)); - } - }, render : function() { @@ -101,28 +80,6 @@ var MarkerView = Backbone.View.extend({ this.localize("OFEN_HAZIYA","cross_mode"); this.localize("MEKOM_HAZIYA","cross_location"); this.localize("KIVUN_HAZIYA","cross_direction"); - // Involved fields: TODO: add AJAX calls to get dictionary required fields (INVOLVED + VEHICLES) - this.localize_inv("SUG_MEORAV","involved_type"); - this.localize_num("SHNAT_HOZAA","license_aquiring_date"); - this.localize_num("KVUZA_GIL","age_group"); // Dictionary.csv - Table 92 - this.localize_inv("MIN","sex"); - this.localize_inv("SUG_REHEV_NASA_LMS","car_type"); - this.localize_inv("EMZAE_BETIHUT","safety_measures"); - this.localize_num("SEMEL_YISHUV_MEGURIM","home_city"); // Cities.csv - "SEMEL" - this.localize_inv("HUMRAT_PGIA","injured_severity"); - this.localize_inv("SUG_NIFGA_LMS","injured_type"); - this.localize_inv("PEULAT_NIFGA_LMS","injured_position"); - this.localize_num("KVUTZAT_OHLUSIYA_LMS","population_type"); // Dictionary.csv - Table 66 - // Vehicles fields: - this.localize_num("NEFAH","engine_volume"); // Dictionary.csv - Table 111 - this.localize_num("SHNAT_YITZUR","manufacturing_year"); - this.localize_num("KIVUNE_NESIA","driving_directions"); // Dictionary.csv - Table 28 - this.localize_veh("MATZAV_REHEV","vehicle_status"); - this.localize_veh("SHIYUH_REHEV_LMS","vehicle_attribution"); - this.localize_veh("SUG_REHEV_LMS","vehicle_type"); - this.localize_num("MEKOMOT_YESHIVA_LMS","seats"); // Dictionary.csv - Table 112 - this.localize_num("MISHKAL_KOLEL_LMS","total_weight"); - this.$el.find(".creation-date").text("תאריך: " + moment(this.model.get("created")).format("LLLL")); @@ -154,8 +111,54 @@ var MarkerView = Backbone.View.extend({ return "/?marker=" + this.model.get("id") + "&" + app.getCurrentUrlParams(); }, clickMarker : function() { + that = this; $.get("/markers/" + this.model.get("id"), function (data) { - //alert(data); + data = JSON.parse(data); + + var localize_invs = function(field,value) { + // Localizing fields which have values in inv_dict + if (inv_dict[field] != undefined && inv_dict[field][data[i][value]] != undefined) { + that.$el.find("." + value).text(fields[field] + ": " + inv_dict[field][data[i][value]]); + } + } + var localize_nums = function(field,value) { + // Localizing fields which do not have values in the dictionaries (strings and integers) + if ([data[i][value]] != 0) { + that.$el.find("." + value).text(fields[field] + ": " + [data[i][value]]); + } + } + var localize_vehs = function(field,value) { + // Localizing fields which have values in veh_dict + if (veh_dict[field] != undefined && veh_dict[field][data[i][value]] != undefined) { + that.$el.find("." + value).text(fields[field] + ": " + veh_dict[field][data[i][value]]); + } + } + + // TODO: create new HTML fields with every iteration on data to present multiple invs & vehs + + for (i in data) { + if (data[i]["sex"] != undefined) { + localize_invs("SUG_MEORAV","involved_type"); + localize_nums("SHNAT_HOZAA","license_acquiring_date"); + localize_nums("KVUZA_GIL","age_group"); + localize_invs("MIN","sex"); + localize_invs("SUG_REHEV_NASA_LMS","car_type"); + localize_invs("EMZAE_BETIHUT","safety_measures"); + localize_invs("HUMRAT_PGIA","injured_severity"); + localize_invs("SUG_NIFGA_LMS","injured_type"); + localize_invs("PEULAT_NIFGA_LMS","injured_position"); + localize_nums("KVUTZAT_OHLUSIYA_LMS","population_type"); + }else{ + localize_vehs("SUG_REHEV_LMS","vehicle_type"); + localize_nums("NEFAH","engine_volume"); + localize_nums("SHNAT_YITZUR","manufacturing_year"); + localize_nums("KIVUNE_NESIA","driving_directions"); + localize_vehs("MATZAV_REHEV","vehicle_status"); + localize_vehs("SHIYUH_REHEV_LMS","vehicle_attribution"); + localize_nums("MEKOMOT_YESHIVA_LMS","seats"); + localize_nums("MISHKAL_KOLEL_LMS","total_weight"); + } + } }); this.highlight(); app.closeInfoWindow(); diff --git a/templates/index.html b/templates/index.html index 226f9dbc..d1cd266c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -272,8 +272,9 @@

+

-

+

@@ -283,12 +284,13 @@

+

+

-

From 1b000d764ca46e6982c3cfe68a8b03d859a23628 Mon Sep 17 00:00:00 2001 From: Omer Date: Thu, 25 Jun 2015 00:19:12 +0300 Subject: [PATCH 2/2] Added multiple vehicles and involved to the marker --- static/js/marker.js | 87 +++++++++++++++++++++++++------------------- templates/index.html | 21 ----------- 2 files changed, 50 insertions(+), 58 deletions(-) diff --git a/static/js/marker.js b/static/js/marker.js index 3fe86d5a..0cbae945 100644 --- a/static/js/marker.js +++ b/static/js/marker.js @@ -115,50 +115,63 @@ var MarkerView = Backbone.View.extend({ $.get("/markers/" + this.model.get("id"), function (data) { data = JSON.parse(data); - var localize_invs = function(field,value) { - // Localizing fields which have values in inv_dict - if (inv_dict[field] != undefined && inv_dict[field][data[i][value]] != undefined) { - that.$el.find("." + value).text(fields[field] + ": " + inv_dict[field][data[i][value]]); + var localize_data = function(field,value,dataType) { + if (dataType === "invs") { + if (inv_dict[field] != undefined && inv_dict[field][data[i][value]] != undefined) { + text_line = "

" + fields[field] + ": " + inv_dict[field][data[i][value]] + "

"; + that.$el.append(text_line); + } + }else if (dataType === "vehs"){ + if (veh_dict[field] != undefined && veh_dict[field][data[i][value]] != undefined) { + text_line = "

" + fields[field] + ": " + veh_dict[field][data[i][value]] + "

"; + that.$el.append(text_line); + } + }else if (dataType === "nums") { + if ([data[i][value]] != 0) { + text_line = "

" + fields[field] + ": " + data[i][value] + "

"; + that.$el.append(text_line); + } } } - var localize_nums = function(field,value) { - // Localizing fields which do not have values in the dictionaries (strings and integers) - if ([data[i][value]] != 0) { - that.$el.find("." + value).text(fields[field] + ": " + [data[i][value]]); - } - } - var localize_vehs = function(field,value) { - // Localizing fields which have values in veh_dict - if (veh_dict[field] != undefined && veh_dict[field][data[i][value]] != undefined) { - that.$el.find("." + value).text(fields[field] + ": " + veh_dict[field][data[i][value]]); - } - } - - // TODO: create new HTML fields with every iteration on data to present multiple invs & vehs - + // TODO: Workout the table issues to present the marker in a more decent way + var j = 1; + that.$el.append(""); for (i in data) { if (data[i]["sex"] != undefined) { - localize_invs("SUG_MEORAV","involved_type"); - localize_nums("SHNAT_HOZAA","license_acquiring_date"); - localize_nums("KVUZA_GIL","age_group"); - localize_invs("MIN","sex"); - localize_invs("SUG_REHEV_NASA_LMS","car_type"); - localize_invs("EMZAE_BETIHUT","safety_measures"); - localize_invs("HUMRAT_PGIA","injured_severity"); - localize_invs("SUG_NIFGA_LMS","injured_type"); - localize_invs("PEULAT_NIFGA_LMS","injured_position"); - localize_nums("KVUTZAT_OHLUSIYA_LMS","population_type"); + that.$el.append(""); }else{ - localize_vehs("SUG_REHEV_LMS","vehicle_type"); - localize_nums("NEFAH","engine_volume"); - localize_nums("SHNAT_YITZUR","manufacturing_year"); - localize_nums("KIVUNE_NESIA","driving_directions"); - localize_vehs("MATZAV_REHEV","vehicle_status"); - localize_vehs("SHIYUH_REHEV_LMS","vehicle_attribution"); - localize_nums("MEKOMOT_YESHIVA_LMS","seats"); - localize_nums("MISHKAL_KOLEL_LMS","total_weight"); + if (j===1){ + that.$el.append(""); + } + that.$el.append(""); + j++; } } + that.$el.append("
"); + text_line = "

פרטי אדם מעורב" + " " + (i*1+1) + "

" + that.$el.append(text_line); + localize_data("SUG_MEORAV","involved_type","invs"); + localize_data("SHNAT_HOZAA","license_acquiring_date","nums"); + localize_data("KVUZA_GIL","age_group","nums"); + localize_data("MIN","sex","invs"); + localize_data("SUG_REHEV_NASA_LMS","car_type","invs"); + localize_data("EMZAE_BETIHUT","safety_measures","invs"); + localize_data("HUMRAT_PGIA","injured_severity","invs"); + localize_data("SUG_NIFGA_LMS","injured_type","invs"); + localize_data("PEULAT_NIFGA_LMS","injured_position","invs"); + localize_data("KVUTZAT_OHLUSIYA_LMS","population_type","nums"); + that.$el.append("

"); + text_line = "

פרטי רכב מעורב" + " " + (j) + "

" + that.$el.append(text_line); + localize_data("SUG_REHEV_LMS","vehicle_type","vehs"); + localize_data("NEFAH","engine_volume","nums"); + localize_data("SHNAT_YITZUR","manufacturing_year","nums"); + localize_data("KIVUNE_NESIA","driving_directions","nums"); + localize_data("MATZAV_REHEV","vehicle_status","vehs"); + localize_data("SHIYUH_REHEV_LMS","vehicle_attribution","vehs"); + localize_data("MEKOMOT_YESHIVA_LMS","seats","nums"); + localize_data("MISHKAL_KOLEL_LMS","total_weight","nums"); + that.$el.append("

"); }); this.highlight(); app.closeInfoWindow(); diff --git a/templates/index.html b/templates/index.html index d1cd266c..0909e4eb 100644 --- a/templates/index.html +++ b/templates/index.html @@ -273,27 +273,6 @@

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-