Skip to content

Commit 6933959

Browse files
committed
prepare 1.3.0
1 parent 0c88d3e commit 6933959

File tree

6 files changed

+115
-47
lines changed

6 files changed

+115
-47
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jQuery-QueryBuilder",
3-
"version": "1.3.0-SNAPSHOT",
3+
"version": "1.3.0",
44
"authors": [{
55
"name": "Damien \"Mistic\" Sorel",
66
"homepage": "http://www.strangeplanet.fr"

dist/query-builder.css

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery QueryBuilder 1.3.0-SNAPSHOT
2+
* jQuery QueryBuilder 1.3.0
33
* Copyright 2014 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
44
* Licensed under MIT (http://opensource.org/licenses/MIT)
55
*/
@@ -27,38 +27,40 @@
2727
.rules-group-header input[name$=_cond] {
2828
display:none;
2929
}
30+
.rules-list {
31+
list-style:none;
32+
padding:0 0 0 20px;
33+
margin:0;
34+
}
3035

3136
/* RULES */
32-
.rules-list {
33-
list-style:none;
34-
padding:0 0 0 20px;
35-
margin:0;
37+
.rule-container {}
38+
.rule-container>div:not(.rule-header) {
39+
display:inline-block;
40+
margin:0 5px 0 0;
41+
vertical-align:top;
42+
}
43+
.rule-value-container:not(:empty) {
44+
border-left:1px solid #ddd;
45+
padding-left:5px;
46+
}
47+
.rule-value-container label {
48+
margin-bottom:0;
49+
}
50+
.rule-value-container label.block {
51+
display:block;
52+
}
53+
.rule-container select,
54+
.rule-container input[type=text],
55+
.rule-container input[type=number] {
56+
padding:1px;
57+
}
58+
59+
.rules-group-container.has-error,
60+
.rule-container.has-error {
61+
background:#fdd;
62+
border-color:#f99;
3663
}
37-
.rule-container {}
38-
.rule-container.has-error {
39-
background:#fdd;
40-
border-color:#f99;
41-
}
42-
.rule-container>div:not(.rule-header) {
43-
display:inline-block;
44-
margin:0 5px 0 0;
45-
vertical-align:top;
46-
}
47-
.rule-value-container:not(:empty) {
48-
border-left:1px solid #ddd;
49-
padding-left:5px;
50-
}
51-
.rule-value-container label {
52-
margin-bottom:0;
53-
}
54-
.rule-value-container label.block {
55-
display:block;
56-
}
57-
.rule-container select,
58-
.rule-container input[type=text],
59-
.rule-container input[type=number] {
60-
padding:1px;
61-
}
6264

6365
/* TICKS */
6466
.rules-list>* {

dist/query-builder.js

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery QueryBuilder 1.3.0-SNAPSHOT
2+
* jQuery QueryBuilder 1.3.0
33
* Copyright 2014 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
44
* Licensed under MIT (http://opensource.org/licenses/MIT)
55
*/
@@ -39,7 +39,12 @@
3939
this.$el = $el;
4040

4141
this.settings = merge(QueryBuilder.DEFAULTS, options);
42-
this.status = { group_id: 0, rule_id: 0, generatedId: false };
42+
this.status = {
43+
group_id: 0,
44+
rule_id: 0,
45+
generatedId: false,
46+
has_optgroup: false
47+
};
4348

4449
this.filters = this.settings.filters;
4550
this.lang = this.settings.lang;
@@ -280,7 +285,7 @@
280285
* @return {object}
281286
*/
282287
QueryBuilder.prototype.getRules = function() {
283-
this.markRuleAsError(this.$el.find('.rule-container'), false);
288+
this.clearErrorMarks();
284289

285290
var $group = this.$el.find('>.rules-group-container'),
286291
that = this;
@@ -300,7 +305,9 @@
300305
var filterId = that.getRuleFilter($rule);
301306

302307
if (filterId == '-1') {
303-
continue;
308+
that.markRuleAsError($rule, true);
309+
that.triggerValidationError('no_filter', $rule, null, null, null);
310+
return {};
304311
}
305312

306313
var filter = that.getFilterById(filterId),
@@ -344,8 +351,8 @@
344351
}
345352

346353
if (out.rules.length === 0) {
354+
that.markRuleAsError($group, true);
347355
that.triggerValidationError('empty_group', $group, null, null, null);
348-
349356
return {};
350357
}
351358

@@ -462,6 +469,11 @@
462469
filter.label = filter.field;
463470
}
464471

472+
that.status.has_optgroup|= !!filter.optgroup;
473+
if (!filter.optgroup) {
474+
filter.optgroup = null;
475+
}
476+
465477
switch (filter.type) {
466478
case 'string':
467479
filter.internalType = 'string';
@@ -482,6 +494,18 @@
482494
break;
483495
}
484496
});
497+
498+
if (this.status.has_optgroup) {
499+
this.filters.sort(function(a, b) {
500+
if (a.optgroup === null && b.optgroup === null) {
501+
return 0;
502+
}
503+
if (a.optgroup === null) {
504+
return 1;
505+
}
506+
return a.optgroup.localeCompare(b.optgroup);
507+
});
508+
}
485509
};
486510

487511
/**
@@ -823,19 +847,26 @@
823847
};
824848

825849
/**
826-
* Add CSS for rule error
827-
* @param $rule {jQuery} (<li> element)
850+
* Add 'has-error' class for rule/group error
851+
* @param $element {jQuery} (<li> or <dl> element)
828852
* @param status {bool}
829853
*/
830-
QueryBuilder.prototype.markRuleAsError = function($rule, status) {
854+
QueryBuilder.prototype.markRuleAsError = function($element, status) {
831855
if (status) {
832-
$rule.addClass('has-error');
856+
$element.addClass('has-error');
833857
}
834858
else {
835-
$rule.removeClass('has-error');
859+
$element.removeClass('has-error');
836860
}
837861
};
838862

863+
/**
864+
* Remove 'has-error' from everythin
865+
*/
866+
QueryBuilder.prototype.clearErrorMarks = function() {
867+
this.$el.find('.has-error').removeClass('has-error');
868+
};
869+
839870
/**
840871
* Trigger a validation error event with custom params
841872
*/
@@ -868,13 +899,15 @@
868899

869900
var placeholder, src, isHandle = false;
870901

902+
// only init drag from drag handle
871903
this.$el.on('mousedown', '.drag-handle', function(e) {
872904
isHandle = true;
873905
});
874906
this.$el.on('mouseup', '.drag-handle', function(e) {
875907
isHandle = false;
876908
});
877909

910+
// dragstart: create placeholder and hide current element
878911
this.$el.on('dragstart', '[draggable]', function(e) {
879912
e.stopPropagation();
880913

@@ -892,57 +925,81 @@
892925

893926
// Chrome glitch (helper invisible if hidden immediately)
894927
setTimeout(function() {
895-
src.hide();
928+
src.hide();
896929
}, 0);
897930
}
898931
else {
899932
e.preventDefault();
900933
}
901934
});
902935

936+
// dragenter: move the placeholder
903937
this.$el.on('dragenter', '[draggable]', function(e) {
904938
e.preventDefault();
905939
e.stopPropagation();
906940

907941
var target = $(e.target), parent;
908942

943+
// on rule
909944
parent = target.closest('.rule-container');
910945
if (parent.length) {
911946
placeholder.detach().insertAfter(parent);
912947
return;
913948
}
914949

950+
// on group header
951+
parent = target.closest('.rules-group-header');
952+
if (parent.length) {
953+
parent = target.closest('.rules-group-container');
954+
placeholder.detach().prependTo(parent.find('.rules-list').eq(0));
955+
return;
956+
}
957+
958+
// on group
915959
parent = target.closest('.rules-group-container');
916960
if (parent.length) {
917961
placeholder.detach().appendTo(parent.find('.rules-list').eq(0));
918962
return;
919963
}
920964
});
921965

966+
// dragover: prevent glitches
922967
this.$el.on('dragover', '[draggable]', function(e) {
923968
e.preventDefault();
924969
e.stopPropagation();
925970
});
926971

972+
// drop: move current element
927973
this.$el.on('drop', function(e) {
928974
e.preventDefault();
929975
e.stopPropagation();
930976

931977
var target = $(e.target), parent;
932978

979+
// on rule
933980
parent = target.closest('.rule-container');
934981
if (parent.length) {
935982
src.detach().insertAfter(parent);
936983
return;
937984
}
938985

986+
// on group header
987+
parent = target.closest('.rules-group-header');
988+
if (parent.length) {
989+
parent = target.closest('.rules-group-container');
990+
src.detach().prependTo(parent.find('.rules-list').eq(0));
991+
return;
992+
}
993+
994+
// on group
939995
parent = target.closest('.rules-group-container');
940996
if (parent.length) {
941997
src.detach().appendTo(parent.find('.rules-list').eq(0));
942998
return;
943999
}
9441000
});
9451001

1002+
// dragend: show current element and delete placeholder
9461003
this.$el.on('dragend', '[draggable]', function(e) {
9471004
e.preventDefault();
9481005
e.stopPropagation();
@@ -1258,13 +1315,22 @@
12581315
* @return {string}
12591316
*/
12601317
QueryBuilder.prototype.getRuleFilterSelect = function(rule_id) {
1318+
var optgroup = null;
1319+
12611320
var h = '<select name="'+ rule_id +'_filter">';
12621321
h+= '<option value="-1">'+ this.lang.filter_select_placeholder +'</option>';
12631322

12641323
$.each(this.filters, function(i, filter) {
1324+
if (optgroup != filter.optgroup) {
1325+
if (optgroup !== null) h+= '</optgroup>';
1326+
optgroup = filter.optgroup;
1327+
if (optgroup !== null) h+= '<optgroup label="'+ optgroup +'">';
1328+
}
1329+
12651330
h+= '<option value="'+ filter.id +'">'+ filter.label +'</option>';
12661331
});
12671332

1333+
if (optgroup !== null) h+= '</optgroup>';
12681334
h+= '</select>';
12691335
return h;
12701336
};

dist/query-builder.min.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/query-builder.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jQuery-QueryBuilder",
3-
"version": "1.3.0-SNAPSHOT",
3+
"version": "1.3.0",
44
"author": {
55
"name": "Damien \"Mistic\" Sorel",
66
"homepage": "http://www.strangeplanet.fr"

0 commit comments

Comments
 (0)