alchemy-form 0.1.6 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/assets/stylesheets/form/alchemy_select.scss +2 -4
- package/controller/form_api_controller.js +10 -3
- package/element/25_query_builder_data.js +139 -0
- package/element/alchemy_field.js +32 -15
- package/element/alchemy_password_input.js +141 -0
- package/element/alchemy_select.js +136 -38
- package/element/alchemy_table.js +52 -8
- package/element/query_builder.js +1 -1
- package/element/query_builder_group.js +35 -8
- package/element/query_builder_value.js +1 -120
- package/element/query_builder_variable.js +103 -0
- package/helper/query_builder_variable_definition/00_variable_definition.js +24 -4
- package/helper/query_builder_variable_definition/list_variable_definition.js +38 -0
- package/helper/widgets/alchemy_field_widget.js +5 -1
- package/helper_field/query_builder_variable.js +56 -0
- package/package.json +3 -3
- package/view/form/elements/password_input.hwk +36 -0
- package/view/form/elements/query_builder_variable.hwk +6 -0
- package/view/form/inputs/edit/belongs_to.hwk +1 -1
- package/view/form/inputs/edit/html.hwk +5 -0
- package/view/form/inputs/edit/query_builder_variable.hwk +10 -0
- package/view/form/inputs/view/datetime.hwk +1 -0
- package/view/form/inputs/view/string.hwk +1 -0
- package/view/form/inputs/view_inline/datetime.hwk +4 -0
- package/view/form/inputs/view_inline/file.hwk +6 -0
- package/view/form/inputs/view_inline/string.hwk +1 -0
- package/view/form/wrappers/view_inline/default.hwk +1 -0
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
* @since 0.1.0
|
|
6
6
|
* @version 0.1.0
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
Select.super.call(this);
|
|
10
|
-
});
|
|
8
|
+
const AlchemySelect = Function.inherits('Alchemy.Element.Form.Base', 'Select');
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* The remote url attribute
|
|
@@ -389,14 +387,56 @@ AlchemySelect.setProperty(function loading_dropdown() {
|
|
|
389
387
|
*
|
|
390
388
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
391
389
|
* @since 0.1.0
|
|
392
|
-
* @version 0.1.
|
|
390
|
+
* @version 0.1.8
|
|
393
391
|
*/
|
|
394
392
|
AlchemySelect.setProperty(function search_value() {
|
|
395
|
-
|
|
393
|
+
|
|
394
|
+
let type_area = this.type_area,
|
|
395
|
+
result = '';
|
|
396
396
|
|
|
397
397
|
if (type_area) {
|
|
398
|
-
|
|
398
|
+
result = type_area.value;
|
|
399
399
|
}
|
|
400
|
+
|
|
401
|
+
if (this.previous_search_value == null) {
|
|
402
|
+
this.previous_search_value = '';
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// If the search value changed, nullify the last page result
|
|
406
|
+
if (this.previous_search_value != result) {
|
|
407
|
+
this.setLastSuccessfulLoadedPage(null);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
this.previous_search_value = result;
|
|
411
|
+
|
|
412
|
+
return result;
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Make sure the pagination watcher exists
|
|
417
|
+
*
|
|
418
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
419
|
+
* @since 0.1.0
|
|
420
|
+
* @version 0.1.8
|
|
421
|
+
*/
|
|
422
|
+
AlchemySelect.setStatic(function ensurePaginationChecker() {
|
|
423
|
+
|
|
424
|
+
if (AlchemySelect.has_paginator_viewer) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Only ever add 1 viewer per page
|
|
429
|
+
AlchemySelect.has_paginator_viewer = true;
|
|
430
|
+
|
|
431
|
+
hawkejs.scene.appears('js-he-ais-pager', {live: true, padding: 10, throttle: 200}, function onInfinity(el) {
|
|
432
|
+
|
|
433
|
+
if (!el.parentElement || !el.parentElement.parentElement) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const alchemy_select_instance = el.parentElement.parentElement;
|
|
438
|
+
alchemy_select_instance.loadOptions(++alchemy_select_instance.loaded_page);
|
|
439
|
+
});
|
|
400
440
|
});
|
|
401
441
|
|
|
402
442
|
/**
|
|
@@ -420,7 +460,7 @@ AlchemySelect.setMethod(function rendered() {
|
|
|
420
460
|
*
|
|
421
461
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
422
462
|
* @since 0.1.0
|
|
423
|
-
* @version 0.1.
|
|
463
|
+
* @version 0.1.8
|
|
424
464
|
*/
|
|
425
465
|
AlchemySelect.setMethod(function introduced() {
|
|
426
466
|
|
|
@@ -433,14 +473,7 @@ AlchemySelect.setMethod(function introduced() {
|
|
|
433
473
|
this.makeSortable();
|
|
434
474
|
}
|
|
435
475
|
|
|
436
|
-
|
|
437
|
-
AlchemySelect.has_paginator_viewer = true;
|
|
438
|
-
|
|
439
|
-
hawkejs.scene.appears('js-he-ais-pager', {live: true, padding: 10, throttle: 200}, function onInfinity(el) {
|
|
440
|
-
var ais = el.parentElement.parentElement;
|
|
441
|
-
ais.loadOptions(++ais.loaded_page);
|
|
442
|
-
});
|
|
443
|
-
}
|
|
476
|
+
AlchemySelect.ensurePaginationChecker();
|
|
444
477
|
|
|
445
478
|
this.addEventListener('focus-without', function onFocusOut(e) {
|
|
446
479
|
that.type_area.value = '';
|
|
@@ -462,8 +495,6 @@ AlchemySelect.setMethod(function introduced() {
|
|
|
462
495
|
|
|
463
496
|
this.addEventListener('keydown', function onKeydown(e) {
|
|
464
497
|
|
|
465
|
-
console.log('keydown:', e);
|
|
466
|
-
|
|
467
498
|
// Only listen for keydowns on the alchemy-select itself
|
|
468
499
|
if (e.target != that) {
|
|
469
500
|
return;
|
|
@@ -829,11 +860,12 @@ AlchemySelect.setMethod(function _processPreloadedValues() {
|
|
|
829
860
|
*
|
|
830
861
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
831
862
|
* @since 0.1.0
|
|
832
|
-
* @version 0.1.
|
|
863
|
+
* @version 0.1.8
|
|
833
864
|
*
|
|
834
865
|
* @param {Object} response
|
|
866
|
+
* @param {Number} page The page, if it's via pagination
|
|
835
867
|
*/
|
|
836
|
-
AlchemySelect.setMethod(function _processResponseData(response) {
|
|
868
|
+
AlchemySelect.setMethod(function _processResponseData(response, page) {
|
|
837
869
|
|
|
838
870
|
if (!response) {
|
|
839
871
|
response = {};
|
|
@@ -851,14 +883,48 @@ AlchemySelect.setMethod(function _processResponseData(response) {
|
|
|
851
883
|
records = [];
|
|
852
884
|
}
|
|
853
885
|
|
|
854
|
-
|
|
886
|
+
this._processResponseList(records, page);
|
|
887
|
+
|
|
888
|
+
this.refreshResultAmount();
|
|
889
|
+
this._markSelectedItems();
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Process the response list of a certain paige
|
|
894
|
+
*
|
|
895
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
896
|
+
* @since 0.1.8
|
|
897
|
+
* @version 0.1.8
|
|
898
|
+
*
|
|
899
|
+
* @param {Array} list
|
|
900
|
+
* @param {Number} page
|
|
901
|
+
*/
|
|
902
|
+
AlchemySelect.setMethod(function _processResponseList(list, page) {
|
|
903
|
+
|
|
904
|
+
let record,
|
|
905
|
+
item;
|
|
906
|
+
|
|
907
|
+
if (page == 1 && this.current_option && this.current_option.data) {
|
|
908
|
+
record = this.current_option.data;
|
|
909
|
+
item = this._makeOption(record._id || record.id, record);
|
|
910
|
+
this.addToDropdown(item);
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
for (record of list) {
|
|
855
914
|
item = this._makeOption(record._id || record.id, record);
|
|
856
915
|
this.addToDropdown(item);
|
|
857
916
|
}
|
|
858
917
|
|
|
859
918
|
this.loading_dropdown = false;
|
|
860
|
-
|
|
861
|
-
this
|
|
919
|
+
|
|
920
|
+
// If there were values & they come from a page, record this as a succesful page
|
|
921
|
+
if (page != null && list.length) {
|
|
922
|
+
if (!this.last_page_result) {
|
|
923
|
+
this.setLastSuccessfulLoadedPage(page);
|
|
924
|
+
} else if (page > this.last_page_result) {
|
|
925
|
+
this.setLastSuccessfulLoadedPage(page);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
862
928
|
});
|
|
863
929
|
|
|
864
930
|
/**
|
|
@@ -866,7 +932,7 @@ AlchemySelect.setMethod(function _processResponseData(response) {
|
|
|
866
932
|
*
|
|
867
933
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
868
934
|
* @since 0.1.0
|
|
869
|
-
* @version 0.1.
|
|
935
|
+
* @version 0.1.8
|
|
870
936
|
*
|
|
871
937
|
* @param {Number} page
|
|
872
938
|
*
|
|
@@ -887,6 +953,10 @@ AlchemySelect.setMethod(function loadRemote(page) {
|
|
|
887
953
|
return pledge;
|
|
888
954
|
}
|
|
889
955
|
|
|
956
|
+
if (page == null) {
|
|
957
|
+
page = 1;
|
|
958
|
+
}
|
|
959
|
+
|
|
890
960
|
const that = this;
|
|
891
961
|
|
|
892
962
|
this.loading_dropdown = true;
|
|
@@ -906,11 +976,11 @@ AlchemySelect.setMethod(function loadRemote(page) {
|
|
|
906
976
|
throw err;
|
|
907
977
|
}
|
|
908
978
|
|
|
909
|
-
if (page == null) {
|
|
979
|
+
if (page == null || page == 1) {
|
|
910
980
|
Hawkejs.removeChildren(that.dropdown_content);
|
|
911
981
|
}
|
|
912
982
|
|
|
913
|
-
that._processResponseData(data);
|
|
983
|
+
that._processResponseData(data, page);
|
|
914
984
|
|
|
915
985
|
pledge.resolve(true);
|
|
916
986
|
};
|
|
@@ -1001,7 +1071,19 @@ AlchemySelect.setMethod(function _markSelectedItems() {
|
|
|
1001
1071
|
}
|
|
1002
1072
|
}
|
|
1003
1073
|
}
|
|
1074
|
+
});
|
|
1004
1075
|
|
|
1076
|
+
/**
|
|
1077
|
+
* Set the last successful loaded page
|
|
1078
|
+
*
|
|
1079
|
+
* @author Jelle De Loecker <jelle@develry.be>
|
|
1080
|
+
* @since 0.1.8
|
|
1081
|
+
* @version 0.1.8
|
|
1082
|
+
*
|
|
1083
|
+
* @param {Number} page
|
|
1084
|
+
*/
|
|
1085
|
+
AlchemySelect.setMethod(function setLastSuccessfulLoadedPage(page) {
|
|
1086
|
+
this.last_page_result = page;
|
|
1005
1087
|
});
|
|
1006
1088
|
|
|
1007
1089
|
/**
|
|
@@ -1009,15 +1091,13 @@ AlchemySelect.setMethod(function _markSelectedItems() {
|
|
|
1009
1091
|
*
|
|
1010
1092
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
1011
1093
|
* @since 0.1.0
|
|
1012
|
-
* @version 0.1.
|
|
1094
|
+
* @version 0.1.8
|
|
1013
1095
|
*
|
|
1014
1096
|
* @param {Number} page
|
|
1015
1097
|
*/
|
|
1016
1098
|
AlchemySelect.setMethod(function loadOptions(page) {
|
|
1017
1099
|
|
|
1018
|
-
|
|
1019
|
-
model,
|
|
1020
|
-
field;
|
|
1100
|
+
const that = this;
|
|
1021
1101
|
|
|
1022
1102
|
if (this.total_item_count >= this.loaded_item_count) {
|
|
1023
1103
|
if (this.dropdown_content.children.length == 0) {
|
|
@@ -1029,12 +1109,34 @@ AlchemySelect.setMethod(function loadOptions(page) {
|
|
|
1029
1109
|
return;
|
|
1030
1110
|
}
|
|
1031
1111
|
|
|
1112
|
+
// Prevent it from keeping on loading empty pages if the previous page was empty
|
|
1113
|
+
if (page && this.last_page_result) {
|
|
1114
|
+
let next_allowed_page = this.last_page_result + 1;
|
|
1115
|
+
|
|
1116
|
+
if (page > next_allowed_page) {
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// Previous page will only be set to the last page that had items.
|
|
1122
|
+
// So if there are 0 results overall, it won't ever be set.
|
|
1123
|
+
// In that case: ignore any page load over 1.
|
|
1124
|
+
if (page > 1 && !this.last_page_result) {
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// If stuff has already been loaded and this is just re-opening the dropdown,
|
|
1129
|
+
// don't do anything yet
|
|
1130
|
+
if (page == null && this.last_page_result > 0) {
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1032
1134
|
// If an URL is provided, use that
|
|
1033
1135
|
if (this.src || this.dataprovider) {
|
|
1034
1136
|
return this.loadRemote(page);
|
|
1035
1137
|
}
|
|
1036
1138
|
|
|
1037
|
-
field = this.model_field;
|
|
1139
|
+
let field = this.model_field;
|
|
1038
1140
|
|
|
1039
1141
|
if (!field) {
|
|
1040
1142
|
return;
|
|
@@ -1042,7 +1144,7 @@ AlchemySelect.setMethod(function loadOptions(page) {
|
|
|
1042
1144
|
|
|
1043
1145
|
this.loading_dropdown = true;
|
|
1044
1146
|
|
|
1045
|
-
model = this.form.getModel(field.modelName);
|
|
1147
|
+
let model = this.form.getModel(field.modelName);
|
|
1046
1148
|
|
|
1047
1149
|
model.find('all', {
|
|
1048
1150
|
limit : 20,
|
|
@@ -1053,12 +1155,7 @@ AlchemySelect.setMethod(function loadOptions(page) {
|
|
|
1053
1155
|
throw err;
|
|
1054
1156
|
}
|
|
1055
1157
|
|
|
1056
|
-
|
|
1057
|
-
var item = that._makeOption(record._id || record.id, record);
|
|
1058
|
-
that.addToDropdown(item);
|
|
1059
|
-
});
|
|
1060
|
-
|
|
1061
|
-
that.loading_dropdown = false;
|
|
1158
|
+
that._processResponseList(records, page);
|
|
1062
1159
|
});
|
|
1063
1160
|
});
|
|
1064
1161
|
|
|
@@ -1699,9 +1796,10 @@ AlchemySelect.setMethod(function applyLocalFilter(query) {
|
|
|
1699
1796
|
*
|
|
1700
1797
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
1701
1798
|
* @since 0.1.0
|
|
1702
|
-
* @version 0.1.
|
|
1799
|
+
* @version 0.1.8
|
|
1703
1800
|
*/
|
|
1704
1801
|
AlchemySelect.setMethod('refreshRemote', Fn.throttle(function refreshRemote() {
|
|
1802
|
+
this.loaded_page = 0;
|
|
1705
1803
|
this.loadRemote();
|
|
1706
1804
|
}, {
|
|
1707
1805
|
minimum_wait : 350,
|
package/element/alchemy_table.js
CHANGED
|
@@ -589,12 +589,49 @@ Table.setMethod(function showPagination() {
|
|
|
589
589
|
pager.showPage(records.page, Math.ceil(records.available / records.page_size));
|
|
590
590
|
});
|
|
591
591
|
|
|
592
|
+
/**
|
|
593
|
+
* Get a fieldset's preferred content view
|
|
594
|
+
*
|
|
595
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
596
|
+
* @since 0.1.8
|
|
597
|
+
* @version 0.1.8
|
|
598
|
+
*
|
|
599
|
+
* @param {FieldConfig} field_config The config on how to display the field
|
|
600
|
+
* @param {Object} container The container where the field should be in
|
|
601
|
+
*
|
|
602
|
+
* @return
|
|
603
|
+
*/
|
|
604
|
+
Table.setMethod(function getFieldConfigView(field_config, container) {
|
|
605
|
+
|
|
606
|
+
let value = field_config.getValueIn(container),
|
|
607
|
+
field = field_config.getFieldDefinition();
|
|
608
|
+
|
|
609
|
+
if (value == null && !field) {
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// Fallback to simple text view
|
|
614
|
+
if (!field) {
|
|
615
|
+
let text = field_config.getDisplayValueIn(container);
|
|
616
|
+
|
|
617
|
+
return Hawkejs.createText(text);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
let alchemy_field = this.createElement('alchemy-field');
|
|
621
|
+
alchemy_field.view_type = 'view_inline';
|
|
622
|
+
alchemy_field.field_name = field.name;
|
|
623
|
+
alchemy_field.config = field;
|
|
624
|
+
alchemy_field.original_value = value;
|
|
625
|
+
|
|
626
|
+
return alchemy_field;
|
|
627
|
+
});
|
|
628
|
+
|
|
592
629
|
/**
|
|
593
630
|
* Create a datarow
|
|
594
631
|
*
|
|
595
632
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
596
633
|
* @since 0.1.0
|
|
597
|
-
* @version 0.1.
|
|
634
|
+
* @version 0.1.8
|
|
598
635
|
*
|
|
599
636
|
* @param {Object} entry
|
|
600
637
|
*
|
|
@@ -602,7 +639,7 @@ Table.setMethod(function showPagination() {
|
|
|
602
639
|
*/
|
|
603
640
|
Table.setMethod(function createDataRow(entry) {
|
|
604
641
|
|
|
605
|
-
let
|
|
642
|
+
let field_set_config,
|
|
606
643
|
value,
|
|
607
644
|
tr = this.createElement('tr'),
|
|
608
645
|
td,
|
|
@@ -610,13 +647,13 @@ Table.setMethod(function createDataRow(entry) {
|
|
|
610
647
|
|
|
611
648
|
tr.dataset.pk = id;
|
|
612
649
|
|
|
613
|
-
for (
|
|
650
|
+
for (field_set_config of this.fieldset) {
|
|
614
651
|
td = this.createElement('td');
|
|
615
652
|
|
|
616
|
-
|
|
653
|
+
let element = this.getFieldConfigView(field_set_config, entry);
|
|
617
654
|
|
|
618
|
-
if (
|
|
619
|
-
td.
|
|
655
|
+
if (element) {
|
|
656
|
+
td.append(element);
|
|
620
657
|
}
|
|
621
658
|
|
|
622
659
|
tr.append(td);
|
|
@@ -709,7 +746,7 @@ Table.setMethod(function getEntryActions(record, filter) {
|
|
|
709
746
|
*
|
|
710
747
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
711
748
|
* @since 0.1.6
|
|
712
|
-
* @version 0.1.
|
|
749
|
+
* @version 0.1.8
|
|
713
750
|
*
|
|
714
751
|
* @param {Object} entry
|
|
715
752
|
*/
|
|
@@ -728,7 +765,7 @@ Table.setMethod(function attachContextMenus() {
|
|
|
728
765
|
let context_actions = this.getEntryActions(record, 'context');
|
|
729
766
|
|
|
730
767
|
if (!context_actions || !context_actions.length) {
|
|
731
|
-
|
|
768
|
+
continue;
|
|
732
769
|
}
|
|
733
770
|
|
|
734
771
|
let pk = record.$pk || record._id || record.id;
|
|
@@ -745,6 +782,13 @@ Table.setMethod(function attachContextMenus() {
|
|
|
745
782
|
|
|
746
783
|
tr.addEventListener('contextmenu', e => {
|
|
747
784
|
|
|
785
|
+
// Ignore right clicks on certain elements
|
|
786
|
+
if (e && e.target) {
|
|
787
|
+
if (e.target.closest('a')) {
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
748
792
|
this.selectRow(tr);
|
|
749
793
|
|
|
750
794
|
let menu = this.createElement('he-context-menu');
|
package/element/query_builder.js
CHANGED
|
@@ -104,7 +104,7 @@ QueryBuilderGroup.setProperty(function group_type() {
|
|
|
104
104
|
*
|
|
105
105
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
106
106
|
* @since 0.1.6
|
|
107
|
-
* @version 0.1.
|
|
107
|
+
* @version 0.1.7
|
|
108
108
|
*/
|
|
109
109
|
QueryBuilderGroup.setProperty(function inverted() {
|
|
110
110
|
|
|
@@ -116,8 +116,17 @@ QueryBuilderGroup.setProperty(function inverted() {
|
|
|
116
116
|
|
|
117
117
|
return false;
|
|
118
118
|
}, function setInverted(value) {
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
|
|
120
|
+
if (!this.assigned_data.value) {
|
|
121
|
+
this.assigned_data.value = {};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
this.assigned_data.value.inverted = value;
|
|
125
|
+
|
|
126
|
+
if (this.header) {
|
|
127
|
+
let input = this.header.querySelector('.qb-group-invert input');
|
|
128
|
+
input.checked = value;
|
|
129
|
+
}
|
|
121
130
|
});
|
|
122
131
|
|
|
123
132
|
/**
|
|
@@ -125,7 +134,7 @@ QueryBuilderGroup.setProperty(function inverted() {
|
|
|
125
134
|
*
|
|
126
135
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
127
136
|
* @since 0.1.6
|
|
128
|
-
* @version 0.1.
|
|
137
|
+
* @version 0.1.7
|
|
129
138
|
*/
|
|
130
139
|
QueryBuilderGroup.setProperty(function value() {
|
|
131
140
|
|
|
@@ -148,6 +157,13 @@ QueryBuilderGroup.setProperty(function value() {
|
|
|
148
157
|
}
|
|
149
158
|
|
|
150
159
|
return result;
|
|
160
|
+
}, function setValue(value) {
|
|
161
|
+
|
|
162
|
+
this.assigned_data.value = value;
|
|
163
|
+
|
|
164
|
+
if (this.has_rendered) {
|
|
165
|
+
this.applyValue(value);
|
|
166
|
+
}
|
|
151
167
|
});
|
|
152
168
|
|
|
153
169
|
/**
|
|
@@ -155,7 +171,7 @@ QueryBuilderGroup.setProperty(function value() {
|
|
|
155
171
|
*
|
|
156
172
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
157
173
|
* @since 0.1.6
|
|
158
|
-
* @version 0.1.
|
|
174
|
+
* @version 0.1.7
|
|
159
175
|
*/
|
|
160
176
|
QueryBuilderGroup.setMethod(function applyValue(value) {
|
|
161
177
|
|
|
@@ -163,15 +179,25 @@ QueryBuilderGroup.setMethod(function applyValue(value) {
|
|
|
163
179
|
return;
|
|
164
180
|
}
|
|
165
181
|
|
|
182
|
+
// Keep track of how many time a value has been applied
|
|
183
|
+
// (needed for the initial value setter)
|
|
184
|
+
if (!this.applied_value_counter) {
|
|
185
|
+
this.applied_value_counter = 0;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.applied_value_counter++;
|
|
189
|
+
|
|
166
190
|
this.inverted = value.inverted;
|
|
167
191
|
this.group_type = value.condition;
|
|
168
192
|
|
|
193
|
+
Hawkejs.removeChildren(this.rules_list);
|
|
194
|
+
|
|
169
195
|
if (value.rules && value.rules.length) {
|
|
170
196
|
let element,
|
|
171
197
|
rule;
|
|
172
198
|
|
|
173
199
|
for (rule of value.rules) {
|
|
174
|
-
if (rule.type == '
|
|
200
|
+
if (rule.type == 'qb_entry') {
|
|
175
201
|
element = this.createElement('alchemy-query-builder-entry');
|
|
176
202
|
} else {
|
|
177
203
|
element = this.createElement('alchemy-query-builder-group');
|
|
@@ -188,7 +214,7 @@ QueryBuilderGroup.setMethod(function applyValue(value) {
|
|
|
188
214
|
*
|
|
189
215
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
190
216
|
* @since 0.1.6
|
|
191
|
-
* @version 0.1.
|
|
217
|
+
* @version 0.1.7
|
|
192
218
|
*/
|
|
193
219
|
QueryBuilderGroup.setMethod(function introduced() {
|
|
194
220
|
|
|
@@ -215,7 +241,8 @@ QueryBuilderGroup.setMethod(function introduced() {
|
|
|
215
241
|
this.remove();
|
|
216
242
|
});
|
|
217
243
|
|
|
218
|
-
|
|
244
|
+
// Apply the value if it hasn't been done already
|
|
245
|
+
if (this.assigned_data.value && !this.applied_value_counter) {
|
|
219
246
|
this.applyValue(this.assigned_data.value);
|
|
220
247
|
}
|
|
221
248
|
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @since 0.1.6
|
|
6
6
|
* @version 0.1.6
|
|
7
7
|
*/
|
|
8
|
-
const QueryBuilderValue = Function.inherits('Alchemy.Element.Form.
|
|
8
|
+
const QueryBuilderValue = Function.inherits('Alchemy.Element.Form.QueryBuilderData', 'QueryBuilderValue');
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* The template to use for the content of this element
|
|
@@ -124,125 +124,6 @@ QueryBuilderValue.setProperty(function value() {
|
|
|
124
124
|
this.assigned_data.value = value;
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
-
/**
|
|
128
|
-
* Check a filter
|
|
129
|
-
*
|
|
130
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
131
|
-
* @since 0.1.6
|
|
132
|
-
* @version 0.1.6
|
|
133
|
-
*/
|
|
134
|
-
QueryBuilderValue.setMethod(function checkFilterType(filter_type, entry) {
|
|
135
|
-
|
|
136
|
-
if (!entry) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let whitelist = this[filter_type];
|
|
141
|
-
|
|
142
|
-
if (!whitelist) {
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
let type = entry.type_name || entry.type || entry.id || entry.name;
|
|
147
|
-
|
|
148
|
-
if (!type) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
let entries = whitelist.split(',');
|
|
153
|
-
|
|
154
|
-
return entries.indexOf(type) > -1;
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Load data for a specific element
|
|
159
|
-
*
|
|
160
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
161
|
-
* @since 0.1.6
|
|
162
|
-
* @version 0.1.6
|
|
163
|
-
*/
|
|
164
|
-
QueryBuilderValue.setMethod(async function loadData(config, element) {
|
|
165
|
-
|
|
166
|
-
if (!element) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (!config) {
|
|
171
|
-
config = {};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
let filter_type,
|
|
175
|
-
result = [],
|
|
176
|
-
items;
|
|
177
|
-
|
|
178
|
-
if (element.classList.contains('qb-source-type')) {
|
|
179
|
-
items = await this.loadSourceTypeData(config);
|
|
180
|
-
filter_type = 'source-types';
|
|
181
|
-
} else if (element.classList.contains('qb-value-variable')) {
|
|
182
|
-
items = await this.loadVariableData(config);
|
|
183
|
-
filter_type = 'variable-types';
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (items && items.length) {
|
|
187
|
-
|
|
188
|
-
let entry;
|
|
189
|
-
|
|
190
|
-
for (entry of items) {
|
|
191
|
-
if (!entry) {
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (filter_type && !this.checkFilterType(filter_type, entry)) {
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
result.push(entry);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
items: result,
|
|
205
|
-
};
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Load variable data
|
|
210
|
-
*
|
|
211
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
212
|
-
* @since 0.1.6
|
|
213
|
-
* @version 0.1.6
|
|
214
|
-
*/
|
|
215
|
-
QueryBuilderValue.setMethod(async function loadVariableData(config) {
|
|
216
|
-
|
|
217
|
-
let dataprovider = this.dataprovider;
|
|
218
|
-
|
|
219
|
-
if (!config) {
|
|
220
|
-
config = {};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
config.source_type = 'variable';
|
|
224
|
-
|
|
225
|
-
let variables = [];
|
|
226
|
-
|
|
227
|
-
if (dataprovider) {
|
|
228
|
-
variables = await dataprovider.loadData(config, this);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
let result = [];
|
|
232
|
-
|
|
233
|
-
if (variables && variables.length) {
|
|
234
|
-
let entry;
|
|
235
|
-
|
|
236
|
-
for (entry of variables) {
|
|
237
|
-
if (entry) {
|
|
238
|
-
result.push(entry);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return result;
|
|
244
|
-
});
|
|
245
|
-
|
|
246
127
|
/**
|
|
247
128
|
* Load value type data
|
|
248
129
|
*
|