Skip to content

Commit 1183c09

Browse files
author
Gaurav SinghaRoy
committed
added action for close button in filter
1 parent 291f6a4 commit 1183c09

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

app/assets/javascripts/resources/querybuilder.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ QueryBuilder = {
262262
},
263263
filter : {
264264
add_objects : function(property_uri, property_name, data){
265+
var identifier = QueryBuilder.properties.filter.get_new_list_identifier();
265266
$("#qb_properties_properties_selected_filters_header").show();
266267
$("#qb_properties_properties_selected_filters_list").show();
267268
var uris = "";
@@ -274,14 +275,31 @@ QueryBuilder = {
274275
uris += data[i].uri;
275276
names += "'"+data[i].name+"'";
276277
}
277-
var div_html = "<div class=\"alert alert-warning list-items\" property-uri=\""+property_uri+"\" filter-value=\""+uris+"\">";
278+
var div_html = "<div id='qb_properties_properties_selected_filters_list_item_"+identifier+"' class=\"alert alert-warning list-item\" property-uri=\""+property_uri+"\" filter-value=\""+uris+"\" identifier=\""+identifier+"\">";
278279
div_html += "<div class='row'><div class='col-md-10'>";
279280
div_html += "<strong>"+property_name+"</strong> "+names;
280281
div_html += "</div>";
281-
div_html += "<div class='col-md-2'><span class=\"glyphicon glyphicon-remove clickable pull-right\"></span></div>"
282+
div_html += "<div class='col-md-2'><span class=\"glyphicon glyphicon-remove clickable pull-right\" onclick=\"QueryBuilder.properties.filter.remove('"+identifier+"')\"></span></div>"
282283
div_html += "</div></div>";
283284
$("#qb_properties_properties_selected_filters_list").append(div_html);
284285
Utils.flash.success("Added objects "+names+" to filter for "+property_name);
286+
},
287+
//removes the filter
288+
remove : function(identifier){
289+
var list_item = $("#qb_properties_properties_selected_filters_list_item_"+identifier);
290+
list_item.remove();
291+
if($("#qb_properties_properties_selected_filters_list").find(".list-item").length <= 0){
292+
$("#qb_properties_properties_selected_filters_header").hide("fast");
293+
$("#qb_properties_properties_selected_filters_list").hide("fast");
294+
}
295+
},
296+
get_new_list_identifier : function(){
297+
var max_id=0;
298+
$("#qb_properties_properties_selected_filters_list").find(".list-item").each(function(index){
299+
if(parseInt($(this).attr("identifier")) > max_id)
300+
max_id = parseInt($(this).attr("identifier"));
301+
});
302+
return (max_id+1).toString();
285303
}
286304
}
287305
},

0 commit comments

Comments
 (0)