PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.23
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.23
5.5.85 5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 All 161 releases
wp-data-access / assets / js / wpda_dashboard.js

wpda_dashboard.js in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.23, at assets/js/wpda_dashboard.js

550 lines 17.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var widgetSequenceNr = 0;
2 var dashboardWidgets = {};
3 var dashboardWidgetPosition = {};
4 var dashboardWidgetDeleted = [];
5
6 function increaseWidgetSequenceNr() {
7 widgetSequenceNr++;
8 }
9
10 function addDashboardWidget(widgetId, widgetName, widgetType, widgetShare, obj = {}, save = true) {
11 // Create widget with default properties
12 dashboardWidgets[widgetId] = {};
13 dashboardWidgets[widgetId].widgetName = widgetName;
14 dashboardWidgets[widgetId].widgetType = widgetType;
15 dashboardWidgets[widgetId].widgetShare = widgetShare;
16
17 for (var prop in obj) {
18 // Add custom properties
19 dashboardWidgets[widgetId][prop] = obj[prop];
20 }
21
22 // Update dashboard
23 if (save) {
24 saveDashBoard();
25 } else {
26 if (typeof saveWidgetPositions === 'function') {
27 saveWidgetPositions();
28 }
29 }
30 }
31
32 function delDashboardWidget(widgetId) {
33 delete dashboardWidgets[widgetId];
34 }
35
36 function toggleDashboard() {
37 if (jQuery("#screen-meta").css("display")==="block") {
38 jQuery("#wpda-dashboard").hide();
39 jQuery("#wpda-dashboard-mobile").hide();
40 } else {
41 showMenu();
42 }
43 }
44
45 function toggleMenu() {
46 if (jQuery("#wpda-dashboard-mobile ul").is(":visible")) {
47 jQuery("#wpda-dashboard-mobile ul").hide();
48 } else {
49 jQuery("#wpda-dashboard-mobile ul").show();
50 }
51 }
52
53 function showMenu() {
54 if (jQuery("#wpcontent").width()<800) {
55 jQuery("#wpda-dashboard").hide();
56 jQuery("#wpda-dashboard-mobile").fadeIn(400);
57 } else {
58 if (jQuery("#wpcontent").width()<900) {
59 wd = 38;
60 fs = 17;
61 tx = 6;
62 } else if (jQuery("#wpcontent").width()<1020) {
63 wd = 44;
64 fs = 22;
65 tx = 7;
66 } else if (jQuery("#wpcontent").width()<1180) {
67 wd = 52;
68 fs = 24;
69 tx = 8;
70 } else {
71 wd = 62;
72 fs = 28;
73 tx = 9;
74 }
75
76 jQuery("#wpda-dashboard .wpda-dashboard .wpda-dashboard-group .wpda-dashboard-item").css("width", wd + "px");
77 jQuery("#wpda-dashboard .wpda-dashboard .wpda-dashboard-group .wpda-dashboard-item .label").css("font-size", tx + "px");
78 jQuery("#wpda-dashboard .wpda-dashboard .wpda-dashboard-group .wpda-dashboard-item .fas").css("font-size", fs + "px");
79 jQuery("#wpda-dashboard .wpda-dashboard .wpda-dashboard-group .wpda-dashboard-item .fa-solid").css("font-size", fs + "px").css("height", fs + "px");
80 jQuery("#wpda-dashboard .wpda-dashboard .wpda-dashboard-group .wpda-dashboard-item svg").css("width", fs + "px").css("height", fs + "px");
81 jQuery("#wpda-dashboard .wpda-dashboard .wpda-dashboard-group .subject").css("font-size", tx + "px");
82
83 jQuery("#wpda-dashboard-toolbar div a i.fas").css("font-size", fs + "px");
84
85 jQuery("#wpda-dashboard-mobile").hide();
86 jQuery("#wpda-dashboard").fadeIn(1000);
87 jQuery("#wpda-dashboard-toolbar").fadeIn(2000);
88
89 jQuery(".wpda_tooltip").tooltip({
90 tooltipClass: "wpda_tooltip_css",
91 });
92 jQuery(".wpda_tooltip_icons").tooltip({
93 tooltipClass: "wpda_tooltip_icons_css",
94 position: {
95 my: "center bottom-24",
96 at: "center top",
97 using: function (position, feedback) {
98 jQuery(this).css(position);
99 jQuery("<div>")
100 .addClass("arrow")
101 .addClass(feedback.vertical)
102 .addClass(feedback.horizontal)
103 .appendTo(this);
104 }
105 }
106 });
107 }
108 }
109
110 function setDashboardWidth() {
111 showMenu();
112 refreshAllPanels();
113 }
114
115 function resizeFont(fontSize) {
116 jQuery(".wpda-widget").css("font-size", fontSize + "px");
117 }
118
119 function addPanelCodeToDashboard(wp_nonce, panel_name, panel_code_id, panel_column, column_position) {
120 increaseWidgetSequenceNr();
121 jQuery.ajax({
122 type: "POST",
123 url: wpda_dashboard_vars.wpda_ajaxurl + "?action=wpda_widget_code_add",
124 data: {
125 wp_nonce: wp_nonce,
126 wpda_panel_name: panel_name,
127 wpda_panel_code_id: panel_code_id,
128 wpda_panel_column: panel_column,
129 wpda_column_position: column_position,
130 wpda_widget_sequence_nr: widgetSequenceNr,
131 }
132 }).done(
133 function(data) {
134 jQuery("#wpbody-content").append(data);
135 closePanel();
136
137 setTimeout(function() {
138 obj = {};
139 obj.codeId = panel_code_id;
140 addDashboardWidget(
141 widgetSequenceNr,
142 panel_name,
143 'code',
144 null,
145 obj
146 );
147 }, 2000);
148 }
149 );
150 }
151
152 function addPanelPublicationToDashboard(wp_nonce, panel_name, panel_pub_id, panel_column, column_position) {
153 increaseWidgetSequenceNr();
154 jQuery.ajax({
155 type: "POST",
156 url: wpda_dashboard_vars.wpda_ajaxurl + "?action=wpda_widget_pub_add",
157 data: {
158 wp_nonce: wp_nonce,
159 wpda_panel_name: panel_name,
160 wpda_panel_pub_id: panel_pub_id,
161 wpda_panel_column: panel_column,
162 wpda_column_position: column_position,
163 wpda_widget_sequence_nr: widgetSequenceNr,
164 }
165 }).done(
166 function(data) {
167 jQuery("#wpbody-content").append(data);
168 closePanel();
169
170 setTimeout(function() {
171 obj = {};
172 obj.pubId = panel_pub_id;
173 addDashboardWidget(
174 widgetSequenceNr,
175 panel_name,
176 'pub',
177 null,
178 obj
179 );
180 }, 2000);
181 }
182 );
183 }
184
185 function addPanelDbmsToDashboard(wp_nonce, panel_name, panel_dbms, panel_column, column_position) {
186 increaseWidgetSequenceNr();
187 jQuery.ajax({
188 type: "POST",
189 url: wpda_dashboard_vars.wpda_ajaxurl + "?action=wpda_widget_dbms_add",
190 data: {
191 wp_nonce: wp_nonce,
192 wpda_panel_name: panel_name,
193 wpda_panel_dbms: panel_dbms,
194 wpda_panel_column: panel_column,
195 wpda_column_position: column_position,
196 wpda_widget_sequence_nr: widgetSequenceNr,
197 }
198 }).done(
199 function(data) {
200 jQuery("#wpbody-content").append(data);
201 closePanel();
202
203 setTimeout(function() {
204 obj = {};
205 obj.dbsDbms = panel_dbms;
206 addDashboardWidget(
207 widgetSequenceNr,
208 panel_name,
209 'dbs',
210 null,
211 obj
212 );
213 }, 500);
214 }
215 );
216 }
217
218 function addPanelChartToDashboard(wp_nonce, panel_name, panel_dbs, panel_query, panel_column, column_position) {
219 increaseWidgetSequenceNr();
220 jQuery.ajax({
221 type: "POST",
222 url: wpda_dashboard_vars.wpda_ajaxurl + "?action=wpda_widget_chart_add",
223 data: {
224 wp_nonce: wp_nonce,
225 wpda_panel_name: panel_name,
226 wpda_panel_dbs: panel_dbs,
227 wpda_panel_query: panel_query,
228 wpda_panel_column: panel_column,
229 wpda_column_position: column_position,
230 wpda_widget_sequence_nr: widgetSequenceNr,
231 }
232 }).done(
233 function(data) {
234 jQuery("#wpbody-content").append(data);
235 closePanel();
236 }
237 );
238 }
239
240 function addPanelProjectToDashboard(wp_nonce, panel_name, panel_project_id, panel_column, column_position) {
241 increaseWidgetSequenceNr();
242 jQuery.ajax({
243 type: "POST",
244 url: wpda_dashboard_vars.wpda_ajaxurl + "?action=wpda_widget_project_add",
245 data: {
246 wp_nonce: wp_nonce,
247 wpda_panel_name: panel_name,
248 wpda_panel_project_id: panel_project_id,
249 wpda_panel_column: panel_column,
250 wpda_column_position: column_position,
251 wpda_widget_sequence_nr: widgetSequenceNr,
252 }
253 }).done(
254 function(data) {
255 jQuery("#wpbody-content").append(data);
256 closePanel();
257
258 setTimeout(function() {
259 obj = {};
260 obj.projectId = panel_project_id;
261 addDashboardWidget(
262 widgetSequenceNr,
263 panel_name,
264 'project',
265 null,
266 obj
267 );
268 }, 2000);
269 }
270 );
271 }
272
273 function removePanelFromDashboard(e) {
274 var dialogHtml = " \
275 <p><strong>Remove widget from dashboard?</strong></p> \
276 <div><span style='display:inline-block;width:55px'><strong>Delete</strong> </span>= Remove widget from dashboard and database </div> \
277 <div><span style='display:inline-block;width:55px'><strong>Keep</strong> </span>= Remove widget from dashboard and keep in database </div> \
278 <div><span style='display:inline-block;width:55px'><strong>Cancel</strong> </span>= Cancel action </div> \
279 ";
280
281 var dialog = jQuery("<div/>").html(dialogHtml).dialog({
282 title: "Remove widget",
283 width: "max-content",
284 buttons: {
285 "Delete": function() {
286 delDashboardWidget(jQuery(e).data('id'));
287 dashboardWidgetDeleted.push(jQuery(e).data("name"));
288 removePanelFromDashboardAction(e);
289 dialog.dialog("close");
290 },
291 "Keep": function() {
292 delDashboardWidget(jQuery(e).data('id'));
293 removePanelFromDashboardAction(e);
294 dialog.dialog("close");
295 },
296 "Cancel": function() {
297 dialog.dialog("close");
298 }
299 }
300 });
301
302 wpda_add_icons_to_dialog_buttons();
303 }
304
305 function loadPanel() {
306 if (jQuery("#wpda-open-panel-column").val()===null) {
307 alert("Invalid column selection");
308 return;
309 }
310
311 increaseWidgetSequenceNr();
312 jQuery.ajax({
313 type: "POST",
314 url: wpda_dashboard_vars.wpda_ajaxurl + "?action=wpda_widget_load_panel",
315 data: {
316 wpda_wpnonce: wpda_wpnonce_refresh,
317 wpda_panel_name: jQuery("#wpda-open-panel-name").val(),
318 wpda_panel_column: jQuery("#wpda-open-panel-column").val(),
319 wpda_panel_position: jQuery("#wpda-open-panel-position").val(),
320 wpda_widget_id: widgetSequenceNr,
321 }
322 }).done(
323 function(msg) {
324 if (typeof msg === 'string') {
325 jQuery("#wpbody-content").append(msg);
326 setTimeout( function() {
327 saveDashBoard();
328 }, 500);
329 } else {
330 if (msg.status==="ERROR" && msg.msg!==undefined) {
331 alert(msg.msg);
332 }
333 }
334
335 closePanel();
336 }
337 ).fail(
338 function (msg) {
339 console.log("WP Data Access error (loadPanel):", msg);
340 }
341 );
342 }
343
344 function refreshAllPanels() {
345 for (var prop in dashboardWidgets) {
346 jQuery("#wpda-widget-" + prop).find(".wpda-widget-refresh").trigger("click", ["refresh"]);
347 }
348 }
349
350 function removePanelFromDashboardAction(e) {
351 id = jQuery(e).attr('id');
352 jQuery(e).remove(); // Remove widget
353 jQuery("." + id).remove(); // Remove widget script blocks
354 saveDashBoard();
355 }
356
357 function addPanel() {
358 closePanel();
359 jQuery("#wpda-add-panel-name").val("");
360 jQuery("#wpda-select-panel-type").show();
361 }
362
363 function closePanel() {
364 jQuery("#wpda-add-panel").hide();
365 jQuery("#wpda-select-panel-type").hide();
366 jQuery("#wpda-open-panel").hide();
367 jQuery("#wpda-manage-tabs").hide();
368 }
369
370 function openPanel() {
371 closePanel();
372
373 var exclude = [];
374 for (var position in dashboardWidgetPosition) {
375 for (var i=0; i<dashboardWidgetPosition[position].length; i++) {
376 exclude.push(dashboardWidgetPosition[position][i]);
377 }
378 }
379
380 resetColumnSelection();
381
382 // Update listbox
383 jQuery.ajax({
384 method: 'POST',
385 url: wpda_dashboard_vars.wpda_ajaxurl + "?action=wpda_dashboard_list",
386 data: {
387 wpda_wpnonce: wpda_wpnonce_refresh,
388 wpda_exclude: exclude
389 }
390 }).done(
391 function(msg) {
392 if (typeof msg === 'string') {
393 if (msg.startsWith("<option")) {
394 jQuery("#wpda-open-panel-name option").remove();
395 jQuery("#wpda-open-panel-name").append(msg);
396
397 jQuery("#wpda-open-panel").show();
398 } else {
399 alert("No widgets found");
400 }
401 } else {
402 if (msg.status==="ERROR" && msg.msg!==undefined) {
403 alert(msg.msg);
404 }
405 }
406 }
407 ).fail(
408 function (msg) {
409 console.log("WP Data Access error (openPanel):", msg);
410 }
411 );
412 }
413
414 function resetColumnSelection() {
415 for (var i=1; i<=4; i++) {
416 jQuery("#wpda-open-panel-column option[value='" + i + "']").removeAttr("disabled");
417 }
418
419 for (var i=jQuery(".wpda-dashboard-column").length+1; i<=4; i++) {
420 jQuery("#wpda-open-panel-column option[value='" + i + "']").attr("disabled", true);
421 }
422 }
423
424 function deletePanel() {
425 panelName = jQuery("#wpda-open-panel-name").val();
426 if (confirm('Delete panel "' + panelName + '"? This cannot be undone!')) {
427 jQuery.ajax({
428 method: 'POST',
429 url: wpda_dashboard_vars.wpda_ajaxurl + "?action=wpda_widget_delete",
430 data: {
431 wpda_wpnonce: wpda_wpnonce_save,
432 wpda_widget_name: panelName
433 }
434 }).done(
435 function(msg) {
436 if (msg.status===undefined) {
437 alert("Error deleting panel. Please refresh page and try again...");
438 } else {
439 alert(msg.msg);
440 if (msg.status==="SUCCESS") {
441 jQuery("#wpda-open-panel-name option[value='" + panelName + "']").remove();
442 if (jQuery("#wpda-open-panel-name option").length===0) {
443 closePanel();
444 }
445 }
446 }
447 }
448 ).fail(
449 function (msg) {
450 console.log("WP Data Access error (deletePanel):", msg);
451 }
452 );
453 }
454 }
455
456 function getSQLFromQueryBuilder(wpnonce, widget_id) {
457 url = location.pathname + '?action=wpda_query_builder_open_sql';
458 jQuery.ajax({
459 method: 'POST',
460 url: url,
461 data: {
462 wpda_wpnonce: wpnonce,
463 wpda_exclude: ""
464 }
465 }).done(
466 function (msg) {
467 if (!Array.isArray(msg.data)) {
468 // Show queries
469 list = jQuery("<ul/>");
470 for (var queryName in msg.data) {
471 dbs = msg.data[queryName].schema_name;
472 qry = msg.data[queryName].query;
473
474 query = jQuery(`
475 <div class="wpda-query-select">
476 <div class="wpda-query-select-title ui-widget-header">
477 ${queryName}
478 <span class="fas fa-copy wpda-query-select-title-copy wpda_tooltip_left" title="Copy SQL"></span>
479 </div>
480 <div class="wpda-query-select-content">
481 <textarea>${qry}</textarea>
482 </div>
483 </div>
484 `);
485 listitem = jQuery("<li/>").attr("data-dbs", dbs);
486 listitem.append(query);
487
488 list.append(listitem);
489 }
490 dialog = jQuery("<div class='wpda-query'/>").attr("title", "Select from Query Builder");
491 dialog.append(list);
492 dialog.dialog({
493 modal: true,
494 resizable: false,
495 width: "700px"
496 });
497 jQuery(".wpda_tooltip_left").tooltip({
498 tooltipClass: "wpda_tooltip_dashboard",
499 position: { my: "right top", at: "right bottom" }
500 });
501
502 jQuery(".wpda-query-select-title-copy").on("click", function() {
503 selectedQuery = jQuery(this).closest("li").find("textarea").val();
504 selectedDbs = jQuery(this).closest("li").data("dbs");
505
506 jQuery("#wpda_chart_dbs_" + widget_id).val(selectedDbs);
507 jQuery("#wpda_chart_sql_" + widget_id).val(selectedQuery);
508
509 jQuery(this).closest('.ui-dialog-content').dialog('close');
510 });
511 } else {
512 // No queries found
513 }
514 }
515 ).fail(
516 function (msg) {
517 console.log("WP Data Access error (getSQLFromQueryBuilder):", msg);
518 }
519 );
520 }
521
522 function copyTexToClipboard(text) {
523 var tempTextarea = jQuery("<textarea></textarea>");
524 jQuery("body").append(tempTextarea);
525 tempTextarea.val(text).select();
526 document.execCommand("copy");
527 tempTextarea.remove();
528 }
529
530 function makeSortable() {
531 jQuery('.wpda-dashboard-column').sortable({
532 connectWith: '.wpda-dashboard-column',
533 cursor: 'move',
534 opacity: 0.4,
535 change: function(event, ui) {
536 ui.placeholder.css({visibility: 'visible', background : '#ccc'});
537 },
538 update: function(event, ui) {
539 saveDashBoard();
540 }
541 });
542 }
543
544 jQuery(function() {
545 jQuery(window).on("resize", function() { setDashboardWidth() });
546 setDashboardWidth();
547
548 makeSortable();
549 });
550