1
0
Fork 0

filter widget also parses numbers boolen and null

This commit is contained in:
Thomas Richter 2013-07-19 15:38:17 +02:00
parent 0d3a66704f
commit f9844f1654
3 changed files with 48 additions and 25 deletions

View File

@ -2,6 +2,9 @@
margin-left: 1px !important;
}
#addFilterItem, .removeFilterItem {
cursor: pointer;
}
#transparentHeader .btn-group {
margin-top: 6px !important;
}

View File

@ -101,25 +101,27 @@ window.arangoDocuments = Backbone.Collection.extend({
});
},
getFilteredDocuments: function (colid, currpage, filter) {
getFilteredDocuments: function (colid, currpage, filter, bindValues) {
var self = this;
this.collectionID = colid;
this.currentPage = currpage;
var filterstring;
var filterString;
if(filter.length === 0){
filterstring ="";
filterString ="";
} else {
filterstring = ' FILTER' + filter.join('');
filterString = ' FILTER' + filter.join(' && ');
}
var query =
'{"query":"FOR u in ' + this.collectionID + filterstring + ' RETURN u"}';
console.log(query);
var body = {
query: "FOR u IN " + this.collectionID + filterString + " RETURN u",
bindVars: bindValues
};
console.log(body);
$.ajax({
cache: false,
type: 'POST',
async: false,
url: '/_api/cursor',
data: query,
data: JSON.stringify(body),
contentType: "application/json",
success: function(data) {
self.clearDocuments();

View File

@ -24,6 +24,7 @@ var documentsView = Backbone.View.extend({
"click #filterCollection" : "filterCollection",
"click #filterSend" : "sendFilter",
"click #addFilterItem" : "addFilterItem",
"click .removeFilterItem" : "removeFilterItem",
"click #confirmCreateEdge" : "addEdge",
"click #documentsTableID tr" : "clicked",
"click #deleteDoc" : "remove",
@ -85,22 +86,37 @@ var documentsView = Backbone.View.extend({
},
sendFilter : function () {
this.filter = [];
this.filter = [], bindValues = {};
var filterlength = $('.queryline').length;
var i;
var ii, value;
for(i=1;i<filterlength;i++){
if($('#attribute_name'+i).val()!=''){
this.filter.push(" u."+ $('#attribute_name'+i).val() + $('#operator'+i).val()+ "'" +
$('#attribute_value'+i).val() + "'" + $('#logicaloperator'+i).val());
value = $('#attribute_value'+i).val();
try {
value = JSON.parse(value);
}
catch (err) {
value = String(value);
}
if($('#attribute_name'+i).val()!==''){
this.filter.push(" u.`"+ $('#attribute_name'+i).val() + "`" + $('#operator'+i).val() + "@param" + i);
bindValues["param" + i] = value;
}
}
if($('#attribute_name').val()!==''){
this.filter.push(" u." + $('#attribute_name').val() + $('#operator').val()+ "'" +
$('#attribute_value').val() + "' ");
var value = $('#attribute_value').val();
try {
value = JSON.parse(value);
}
catch (err) {
value = String(value);
}
if ($('#attribute_name').val()!=='') {
this.filter.push(" u.`" + $('#attribute_name').val() + "`" + $('#operator').val() + "@param");
bindValues["param"] = value;
}
console.log(this.filter);
window.documentsView.clearTable();
window.arangoDocumentsStore.getFilteredDocuments(this.colid, 1, this.filter);
window.arangoDocumentsStore.getFilteredDocuments(this.colid, 1, this.filter, bindValues);
},
addFilterItem : function () {
@ -113,21 +129,23 @@ var documentsView = Backbone.View.extend({
'<select name="operator" id="operator'+ num +'">'+
' <option value=" == ">==</option>'+
' <option value=" != ">!=</option>'+
' <option value=" > ">&lt;</option>'+
' <option value=" < ">&gt;</option>'+
' <option value=" < ">&lt;</option>'+
' <option value=" <= ">&lt;=</option>'+
' <option value=" >= ">&gt;=</option>'+
' <option value=" > ">&gt;</option>'+
'</select>'+
'<input id="attribute_value' + num + '" type="text" placeholder="Attribute value">'+
'<select name="logicaloperator" id="logicaloperator'+ num +'">'+
' <option value=" && ">and</option>'+
' <option value=" || ">or</option>'+
'</select>'+
' <a id="femoveFilterItem" data="' + num + '"><i class="icon icon-white icon-minus"></i></a>'+
' <a class="removeFilterItem" data="' + num + '"><i class="icon icon-white icon-minus"></i></a>'+
' </div>');
},
removeFilterItem : function (delline) {
removeFilterItem : function () {
"use strict";
// removes line delline from the filter widget
console.log("remove");
$('.removeFilterItem').click(function(event) {
console.log("hallo"+event.currentTarget);
});
},
addDocument: function () {