PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.84
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.84
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 5.5.42 All 160 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.84, at assets/js/wpda_dashboard.js

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