PluginProbe
Datafeedr API / 1.0.24
Datafeedr API v1.0.24
1.4.3 1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 All 182 releases
datafeedr-api / js / searchform.js

searchform.js in Datafeedr API 1.0.24, at js/searchform.js

181 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(function($) {
2
3 // Search form
4
5 function getPopup() {
6 var p = $("#dfrapi_popup");
7 if(p.length)
8 return p;
9 $("body").append($("<div id='dfrapi_popup' class='reveal-modal'><div class='reveal-modal-content'></div><a class='close-reveal-modal'>&#215;</a></div>"));
10 return $("#dfrapi_popup");
11 }
12
13 function searchFormAjax(command, params, fn) {
14 params = $.extend({}, params, {
15 action: 'search_form',
16 command: command,
17 useSelected: $("#dfrapi_useSelected").val()
18 });
19 $.post(ajaxurl, params, fn);
20 }
21
22 function checkSelects(form) {
23 form.find(".value2").each(function() {
24 if($(this).closest(".filter").find(".operator select").val() == "between")
25 $(this).show();
26 else
27 $(this).hide();
28 });
29 }
30
31 function updateSearchForm(form) {
32 var active = 0;
33
34 form.find(".filter").each(function() {
35 var filter = $(this);
36 var fieldName = filter.attr("class").match(/filter_(\w+)/)[1];
37 filter.find(".field select").val(fieldName);
38 if(filter.is(":visible"))
39 active++;
40 });
41
42 $(".dfrapi_choose_box").each(function() {
43 var box = $(this);
44 var kind = box.attr("rel");
45 var value = box.find("input").val();
46 searchFormAjax("names_" + kind, {value: value}, function(s) {
47 box.find(".names").html(s);
48 });
49 });
50
51 checkSelects(form);
52
53 var btns = $("#dfrapi_search_form .filter .minus");
54 if(active == 1)
55 btns.addClass("disabled");
56 else
57 btns.removeClass("disabled");
58 }
59
60 function ajaxPopup(btn, command) {
61 var input = $(btn).closest(".dfrapi_choose_box").find("input");
62 var form = $(btn).closest("form");
63
64 var popup = getPopup();
65 popup.find(".reveal-modal-content").html($("#dfprs_loading_content").html());
66 popup.reveal({
67 animation: 'fade',
68 animationspeed: 100
69 });
70 searchFormAjax(command, {value: input.val()}, function(response) {
71 popup.find(".reveal-modal-content").html(response);
72 popup.find("a.button.reset_search").click(function() {
73 $(this).parent().find("input").val("").change();
74 return false;
75 });
76 popup.find("a.button.submit").click(function() {
77 var value = [];
78 popup.find("input:checked").each(function() {
79 value.push($(this).val());
80 });
81 input.val(value.join(","));
82 popup.trigger("reveal:close");
83 updateSearchForm(form);
84 return false;
85 });
86 popup.find(".filter_action input").searchFilter({
87 element: popup.find(".inline_frame_element"),
88 subject: ".element_name",
89 highlight: "<span style='background: yellow'>"
90 });
91
92 });
93 }
94
95 var fcount = 1000;
96
97 function cloneFilter(flt) {
98 var f = flt.clone(true);
99 fcount++;
100 f.find(":input").each(function() {
101 this.name = this.name.replace(/\[\d+\]/g, "[" + fcount + "]");
102 $(this).val("")
103 });
104 f.find(".names").html("");
105 return f;
106 }
107
108 $("#dfrapi_search_form .filter .minus").click(function() {
109 if($(this).is(".disabled"))
110 return false;
111 var form = $(this).closest("form");
112 if(form.find(".filter:visible").length)
113 $(this).closest(".filter").hide();
114 updateSearchForm(form);
115 return false;
116 });
117
118 $("#dfrapi_search_form_filter").click(function() {
119 var form = $(this).closest("form");
120 var hiddenFilters = form.find(".filter:hidden");
121 var last = form.find(".filter:last");
122 if(hiddenFilters.length) {
123 last.after($(hiddenFilters[0]).show());
124 } else {
125 last.after(cloneFilter(last));
126 }
127 updateSearchForm(form);
128 return false;
129 });
130
131 $("#dfrapi_search_form .filter .field select").change(function() {
132 var form = $(this).closest("form");
133 var fieldName = $(this).val();
134
135 var thisFilter = $(this).closest(".filter"), otherFilter;
136 var others = $(".filter_" + fieldName + ":hidden");
137
138 if(others.length)
139 otherFilter = $(others[0]);
140 else {
141 others = $(".filter_" + fieldName);
142 otherFilter = cloneFilter($(others[0]));
143 }
144
145 otherFilter.insertBefore(thisFilter);
146 thisFilter.hide();
147 otherFilter.show();
148
149 updateSearchForm(form);
150 });
151
152 $("#dfrapi_search_form .filter .operator select").change(function() {
153 checkSelects($(this).closest("form"));
154 });
155
156 $("#dfrapi_search_form").closest("form").submit(function() {
157 $(this).find("#dfrapi_search_form .filter:hidden").remove();
158 });
159
160 $("#dfrapi_search_form .choose_network").click(function() {
161 ajaxPopup(this, "choose_network");
162 });
163
164 $("#dfrapi_search_form .choose_merchant").click(function() {
165 ajaxPopup(this, "choose_merchant");
166 });
167
168 $(".dfrapi_search_help").on('click',function(e) {
169 var classes = $(this).closest('.filter').attr('class').split(' ');
170 for(var i=0; i<classes.length; i++) {
171 if (classes[i].match("^filter_")) {
172 var filter = classes[i];
173 $('.'+filter+' > .help').slideToggle();
174 }
175 }
176 e.preventDefault();
177 });
178
179 updateSearchForm($("#dfrapi_search_form").closest("form"));
180 });
181