PluginProbe
Datafeedr API / 1.4.3
Datafeedr API v1.4.3
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.4.3, at js/searchform.js

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