Spaces:
No application file
No application file
File size: 65,010 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 |
const ckEditors = new Map();
/**
* Takes a given route, retrieves the HTML, and then updates the content
*
* @param route
* @param link
* @param method
* @param target
* @param showPageLoading
* @param callback
* @param data
*/
Mautic.loadContent = function (route, link, method, target, showPageLoading, callback, data) {
if (typeof Mautic.loadContentXhr == 'undefined') {
Mautic.loadContentXhr = {};
} else if (typeof Mautic.loadContentXhr[target] != 'undefined') {
Mautic.loadContentXhr[target].abort();
}
showPageLoading = (typeof showPageLoading == 'undefined' || showPageLoading) ? true : false;
Mautic.loadContentXhr[target] = mQuery.ajax({
showLoadingBar: showPageLoading,
url: route,
type: method,
dataType: "json",
data: data,
success: function (response) {
if (response) {
response.stopPageLoading = showPageLoading;
if (response.callback) {
window["Mautic"][response.callback].apply('window', [response]);
return;
}
if (response.redirect) {
Mautic.redirectWithBackdrop(response.redirect);
} else if (target || response.target) {
if (target) response.target = target;
Mautic.processPageContent(response);
} else {
//clear the live cache
MauticVars.liveCache = new Array();
MauticVars.lastSearchStr = '';
//set route and activeLink if the response didn't override
if (typeof response.route === 'undefined') {
response.route = route;
}
if (typeof response.activeLink === 'undefined' && link) {
response.activeLink = link;
}
Mautic.processPageContent(response);
}
//restore button class if applicable
Mautic.stopIconSpinPostEvent();
}
MauticVars.routeInProgress = '';
},
error: function (request, textStatus, errorThrown) {
Mautic.processAjaxError(request, textStatus, errorThrown, true);
//clear routeInProgress
MauticVars.routeInProgress = '';
//restore button class if applicable
Mautic.stopIconSpinPostEvent();
//stop loading bar
Mautic.stopPageLoadingBar();
},
complete: function () {
if (typeof callback !== 'undefined') {
if (typeof callback == 'function') {
callback();
} else {
window["Mautic"][callback].apply('window', []);
}
}
Mautic.generatePageTitle( route );
delete Mautic.loadContentXhr[target];
}
});
//prevent firing of href link
//mQuery(link).attr("href", "javascript: void(0)");
return false;
};
/**
* Load results with ajax in batch mode
*
* @param elementName
* @param route
* @param callback
*/
Mautic.loadAjaxColumn = function(elementName, route, callback){
var className = '.'+elementName;
if (mQuery(className).length) {
var ids = [];
mQuery(className).each(function () {
if(!mQuery(this).text()) {
var id = mQuery(this).attr('data-value');
ids.push(id);
}
});
var batchIds;
// If not gonna load any data, then just callback
if(ids.length == 0) {
Mautic.getCallback(callback);
}
// Get all stats numbers in batches of 10
while (ids.length > 0) {
batchIds = ids.splice(0, 10);
Mautic.ajaxActionRequest(
route,
{ids: batchIds, entityId: Mautic.getEntityId()},
function (response) {
if (response.success && response.stats) {
for (var i = 0; i < response.stats.length; i++) {
var stat = response.stats[i];
if (mQuery('#' + elementName + '-' + stat.id).length) {
mQuery('#' + elementName + '-' + stat.id).html(stat.data);
}
}
if(batchIds.length < 10) {
Mautic.getCallback(callback);
}
}
},
false,
true,
"GET"
);
}
}
}
/**
* Sort table by column
*
* @param tableId
* @param sortElement
*/
Mautic.sortTableByColumn = function(tableId, sortElement, removeZero){
var tbody = mQuery(tableId).find('tbody');
tbody.find('tr').each(function () {
if(parseInt(mQuery(this).find(sortElement).text()) == 0) {
mQuery(this).remove();
}
})
tbody.find('tr').sort(function(a, b) {
var tda = parseFloat(mQuery(a).find(sortElement).text()); // target order attribute
var tdb = parseFloat(mQuery(b).find(sortElement).text()); // target order attribute
// if a < b return 1
return tda < tdb ? 1
// else if a > b return -1
: tda > tdb ? -1
// else they are equal - return 0
: 0;
}).appendTo(tbody);
}
/**
* @param callback
*/
Mautic.getCallback = function (callback) {
if (callback && typeof callback !== 'undefined') {
if (typeof callback == 'function') {
callback();
} else {
window["Mautic"][callback].apply('window', []);
}
}
}
/**
* Generates the title of the current page
*
* @param route
*/
Mautic.generatePageTitle = function(route){
if (-1 !== route.indexOf('timeline')) {
return
} else if (-1 !== route.indexOf('/view')) {
//loading view of module title
var currentModule = route.split('/')[3];
//check if we find spans
var titleWithHTML = mQuery('.page-header h3').find('span.span-block');
var currentModuleItem = '';
if( 1 < titleWithHTML.length ){
currentModuleItem = titleWithHTML.eq(0).text() + ' - ' + titleWithHTML.eq(1).text();
} else {
currentModuleItem = mQuery('.page-header h3').text();
}
// Encoded entites are decoded by this process and can cause a XSS
currentModuleItem = mQuery('<div>'+currentModuleItem+'</div>').text();
mQuery('title').html( currentModule[0].toUpperCase() + currentModule.slice(1) + ' | ' + currentModuleItem + ' | Mautic' );
} else {
//loading basic title
mQuery('title').html( mQuery('.page-header h3').text() + ' | Mautic' );
}
};
/**
* Updates new content
* @param response
*/
Mautic.processPageContent = function (response) {
if (response) {
Mautic.deactivateBackgroup();
if (response.errors && 'dev' == mauticEnv) {
alert(response.errors[0].message);
console.log(response.errors);
}
if (!response.target) {
response.target = '#app-content';
}
//inactive tooltips, etc
Mautic.onPageUnload(response.target, response);
//set content
if (response.newContent) {
if (response.replaceContent && response.replaceContent == 'true') {
mQuery(response.target).replaceWith(response.newContent);
} else {
mQuery(response.target).html(response.newContent);
}
}
if (response.notifications) {
Mautic.setNotifications(response.notifications);
}
if (response.route) {
//update URL in address bar
history.pushState(null, "Mautic", response.route);
//update Title
Mautic.generatePageTitle( response.route );
}
if (response.target == '#app-content') {
//update type of content displayed
if (response.mauticContent) {
mauticContent = response.mauticContent;
}
if (response.activeLink) {
var link = response.activeLink;
if (link !== undefined && link.charAt(0) != '#') {
link = "#" + link;
}
var parent = mQuery(link).parent();
//remove current classes from menu items
mQuery(".nav-sidebar").find(".active").removeClass("active");
//add current to parent <li>
parent.addClass("active");
//get parent
var openParent = parent.closest('li.open');
//remove ancestor classes
mQuery(".nav-sidebar").find(".open").each(function () {
if (!openParent.hasClass('open') || (openParent.hasClass('open') && openParent[0] !== mQuery(this)[0])) {
mQuery(this).removeClass('open');
}
});
//add current_ancestor classes
//mQuery(parent).parentsUntil(".nav-sidebar", "li").addClass("current_ancestor");
}
mQuery('body').animate({
scrollTop: 0
}, 0);
} else {
var overflow = mQuery(response.target).css('overflow');
var overflowY = mQuery(response.target).css('overflowY');
if (overflow == 'auto' || overflow == 'scroll' || overflowY == 'auto' || overflowY == 'scroll') {
mQuery(response.target).animate({
scrollTop: 0
}, 0);
}
}
if (response.overlayEnabled) {
mQuery(response.overlayTarget + ' .content-overlay').remove();
}
//activate content specific stuff
Mautic.onPageLoad(response.target, response);
}
};
/**
* Initiate various functions on page load, manual or ajax
*/
Mautic.onPageLoad = function (container, response, inModal) {
Mautic.initDateRangePicker(container + ' #daterange_date_from', container + ' #daterange_date_to');
//initiate links
Mautic.makeLinksAlive(mQuery(container + " a[data-toggle='ajax']"));
//initialize forms
mQuery(container + " form[data-toggle='ajax']").each(function (index) {
Mautic.ajaxifyForm(mQuery(this).attr('name'));
});
//initialize ajax'd modals
Mautic.makeModalsAlive(mQuery(container + " *[data-toggle='ajaxmodal']"))
//initialize embedded modal forms
Mautic.activateModalEmbeddedForms(container);
//initalize live search boxes
mQuery(container + " *[data-toggle='livesearch']").each(function (index) {
Mautic.activateLiveSearch(mQuery(this), "lastSearchStr", "liveCache");
});
//initialize list filters
mQuery(container + " *[data-toggle='listfilter']").each(function (index) {
Mautic.activateListFilterSelect(mQuery(this));
});
//initialize tooltips
var pageTooltips = mQuery(container + " *[data-toggle='tooltip']");
pageTooltips.tooltip({html: true, container: 'body'});
// Enable tooltips on checkbox & radio input's to
// show when hovering their parent LABEL element
pageTooltips.each(function(i) {
var thisTooltip = mQuery(pageTooltips.get(i));
var elementParent = thisTooltip.parent();
if (elementParent.get(0).tagName === 'LABEL') {
elementParent.append('<i class="ri-question-line"></i>');
elementParent.hover(function () {
thisTooltip.tooltip('show')
}, function () {
thisTooltip.tooltip('hide');
});
}
});
//initialize sortable lists
mQuery(container + " *[data-toggle='sortablelist']").each(function (index) {
Mautic.activateSortable(this);
});
//downloads
mQuery(container + " a[data-toggle='download']").off('click.download');
mQuery(container + " a[data-toggle='download']").on('click.download', function (event) {
event.preventDefault();
Mautic.initiateFileDownload(mQuery(this).attr('href'));
});
Mautic.makeConfirmationsAlive(mQuery(container + " a[data-toggle='confirmation']"));
//initialize date/time
mQuery(container + " *[data-toggle='datetime']").each(function() {
Mautic.activateDateTimeInputs(this, 'datetime');
});
mQuery(container + " *[data-toggle='date']").each(function() {
Mautic.activateDateTimeInputs(this, 'date');
});
mQuery(container + " *[data-toggle='time']").each(function() {
Mautic.activateDateTimeInputs(this, 'time');
});
// Initialize callback options
mQuery(container + " *[data-onload-callback]").each(function() {
var callback = function(el) {
if (typeof window["Mautic"][mQuery(el).attr('data-onload-callback')] == 'function') {
window["Mautic"][mQuery(el).attr('data-onload-callback')].apply('window', [el]);
}
}
mQuery(document).ready(callback(this));
});
mQuery(container + " input[data-toggle='color']").each(function() {
Mautic.activateColorPicker(this);
});
mQuery(container + " select").not('.multiselect, .not-chosen').each(function() {
Mautic.activateChosenSelect(this);
});
mQuery(container + " select.multiselect").each(function() {
Mautic.activateMultiSelect(this);
});
Mautic.activateLookupTypeahead(mQuery(container));
// Fix dropdowns in responsive tables - https://github.com/twbs/bootstrap/issues/11037#issuecomment-163746965
mQuery(container + " .table-responsive").on('shown.bs.dropdown', function (e) {
var table = mQuery(this),
menu = mQuery(e.target).find(".dropdown-menu"),
tableOffsetHeight = table.offset().top + table.height(),
menuOffsetHeight = menu.offset().top + menu.outerHeight(true);
if (menuOffsetHeight > tableOffsetHeight)
table.css("padding-bottom", menuOffsetHeight - tableOffsetHeight + 16)
});
mQuery(container + " .table-responsive").on("hide.bs.dropdown", function () {
mQuery(this).css("padding-bottom", 0);
})
//initialize tab/hash activation
mQuery(container + " .nav-tabs[data-toggle='tab-hash']").each(function() {
// Show tab based on hash
var hash = document.location.hash;
var prefix = 'tab-';
if (hash) {
var hashPieces = hash.split('?');
hash = hashPieces[0].replace("#", "#" + prefix);
var activeTab = mQuery(this).find('a[href=' + hash + ']').first();
if (mQuery(activeTab).length) {
mQuery('.nav-tabs li').removeClass('active');
mQuery('.tab-pane').removeClass('in active');
mQuery(activeTab).parent().addClass('active');
mQuery(hash).addClass('in active');
}
}
mQuery(this).find('a').on('shown.bs.tab', function (e) {
window.location.hash = e.target.hash.replace("#" + prefix, "#");
});
});
// Initialize tab overflow
mQuery(container + " .nav-overflow-tabs ul").each(function() {
Mautic.activateOverflowTabs(this);
});
mQuery(container + " .nav.sortable").each(function() {
Mautic.activateSortableTabs(this);
});
// Initialize tab delete buttons
Mautic.activateTabDeleteButtons(container);
//spin icons on button click
mQuery(container + ' .btn:not(.btn-nospin)').on('click.spinningicons', function (event) {
Mautic.startIconSpinOnEvent(event);
});
mQuery(container + ' input[class=list-checkbox]').on('change', function () {
var disabled = Mautic.batchActionPrecheck(container) ? false : true;
var color = (disabled) ? 'btn-default' : 'btn-info';
var button = container + ' th.col-actions .input-group-btn button';
mQuery(button).prop('disabled', disabled);
mQuery(button).removeClass('btn-default btn-info').addClass(color);
});
//Copy form buttons to the toolbar
mQuery(container + " .bottom-form-buttons").each(function() {
if (inModal || mQuery(this).closest('.modal').length) {
var modal = (inModal) ? container : mQuery(this).closest('.modal');
if (mQuery(modal).find('.modal-form-buttons').length) {
//hide the bottom buttons
mQuery(modal).find('.bottom-form-buttons').addClass('hide');
var buttons = mQuery(modal).find('.bottom-form-buttons').html();
//make sure working with a clean slate
mQuery(modal).find('.modal-form-buttons').html('');
mQuery(buttons).filter("button").each(function (i, v) {
//get the ID
var id = mQuery(this).attr('id');
var button = mQuery("<button type='button' />")
.addClass(mQuery(this).attr('class'))
.addClass('btn-copy')
.html(mQuery(this).html())
.appendTo(mQuery(modal).find('.modal-form-buttons'))
.on('click.ajaxform', function (event) {
if (mQuery(this).hasClass('disabled')) {
return false;
}
// Disable the form buttons until this action is complete
if (!mQuery(this).hasClass('btn-dnd')) {
mQuery(this).parent().find('button').prop('disabled', true);
}
event.preventDefault();
if (!mQuery(this).hasClass('btn-nospin')) {
Mautic.startIconSpinOnEvent(event);
}
mQuery('#' + id).click();
});
});
}
} else {
//hide the toolbar actions if applicable
mQuery('.toolbar-action-buttons').addClass('hide');
if (mQuery('.toolbar-form-buttons').hasClass('hide')) {
//hide the bottom buttons
mQuery(container + ' .bottom-form-buttons').addClass('hide');
var buttons = mQuery(container + " .bottom-form-buttons").html();
//make sure working with a clean slate
mQuery(container + ' .toolbar-form-buttons .toolbar-standard').html('');
mQuery(container + ' .toolbar-form-buttons .toolbar-dropdown .drop-menu').html('');
var lastIndex = mQuery(buttons).filter("button").length - 1;
mQuery(buttons).filter("button").each(function (i, v) {
//get the ID
var id = mQuery(this).attr('id');
var buttonClick = function (event) {
event.preventDefault();
// Disable the form buttons until this action is complete
if (!mQuery(this).hasClass('btn-dnd')) {
mQuery(this).parent().find('button').prop('disabled', true);
}
Mautic.startIconSpinOnEvent(event);
mQuery('#' + id).click();
};
mQuery("<button type='button' />")
.addClass(mQuery(this).attr('class'))
.addClass('btn-copy')
.attr('id', mQuery(this).attr('id') + '_toolbar')
.html(mQuery(this).html())
.on('click.ajaxform', buttonClick)
.appendTo('.toolbar-form-buttons .toolbar-standard');
if (i === lastIndex) {
mQuery(".toolbar-form-buttons .toolbar-dropdown .btn-main")
.off('.ajaxform')
.attr('id', mQuery(this).attr('id') + '_toolbar_mobile')
.html(mQuery(this).html())
.on('click.ajaxform', buttonClick);
} else {
mQuery("<a />")
.attr('id', mQuery(this).attr('id') + '_toolbar_mobile')
.html(mQuery(this).html())
.on('click.ajaxform', buttonClick)
.appendTo(mQuery('<li />').prependTo('.toolbar-form-buttons .toolbar-dropdown .dropdown-menu'))
}
});
mQuery('.toolbar-form-buttons').removeClass('hide');
}
}
});
Mautic.activateGlobalFroalaOptions();
Mautic.getBuilderContainer = function() {
return container;
}
// This turns all textarea elements with class "editor" into CKEditor ones, except for Dynamic Content elements, which can be initialized with Mautic.setDynamicContentEditors().
if (mauticFroalaEnabled && mQuery(container + ' textarea.editor:not(".editor-dynamic-content")').length && Mautic.getActiveBuilderName() === 'legacy') {
mQuery(container + ' textarea.editor:not(".editor-dynamic-content")').each(function () {
mQuery(this).froalaEditor();
});
} else if (mQuery(container + ' textarea.editor:not(".editor-dynamic-content")').length) {
mQuery(container + ' textarea.editor:not(".editor-dynamic-content")').each(function () {
const textarea = mQuery(this);
const maxButtons = ['undo', 'redo', '|', 'bold', 'italic', 'underline', 'heading', 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'alignment', 'numberedList', 'bulletedList', 'blockQuote', 'TokenPlugin', 'removeFormat', 'link', 'ckfinder', 'mediaEmbed', 'insertTable', 'sourceEditing'];
let minButtons = ['undo', 'redo', '|', 'bold', 'italic', 'underline'];
if (textarea.hasClass('editor-dynamic-content') || textarea.hasClass('editor-basic')) {
minButtons = ['undo', 'redo', '|', 'bold', 'italic', 'underline', 'heading', 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'alignment', 'numberedList', 'bulletedList', 'blockQuote', 'removeFormat', 'link', 'ckfinder', 'mediaEmbed', 'insertTable', 'sourceEditing'];
}
let ckEditorToolbar = minButtons;
if (textarea.hasClass('editor-advanced') || textarea.hasClass('editor-basic-fullpage')) {
ckEditorToolbar = maxButtons;
}
Mautic.ConvertFieldToCkeditor(textarea, ckEditorToolbar);
});
}
//prevent auto closing dropdowns for dropdown forms
if (mQuery(container + ' .dropdown-menu-form').length) {
mQuery(container + ' .dropdown-menu-form').on('click', function (e) {
e.stopPropagation();
});
}
if (response && response.updateSelect && typeof response.id !== 'undefined') {
// An new item is to be injected
Mautic.updateEntitySelect(response);
}
//run specific on loads
var contentSpecific = false;
if (response && response.mauticContent) {
contentSpecific = response.mauticContent;
} else if (container == 'body') {
contentSpecific = mauticContent;
}
if (response && response.sidebar) {
var sidebarContent = mQuery('.app-sidebar.sidebar-left');
var newSidebar = mQuery(response.sidebar);
var nav = sidebarContent.find('li');
if (nav.length) {
var openNavIndex;
nav.each(function(i, el) {
var $el = mQuery(el);
if ($el.hasClass('open')) {
openNavIndex = i;
}
});
var openNav = mQuery(newSidebar.find('li')[openNavIndex]);
openNav.addClass('open');
openNav.find('ul').removeClass('collapse');
}
sidebarContent.html(newSidebar);
}
if (container == '#app-content' || container == 'body') {
//register global keyboard shortcuts
Mautic.bindGlobalKeyboardShortcuts();
mQuery(".sidebar-left a[data-toggle='ajax']").on('click.ajax', function (event) {
mQuery("html").removeClass('sidebar-open-ltr');
});
mQuery('.sidebar-right a[data-toggle="ajax"]').on('click.ajax', function (event) {
mQuery("html").removeClass('sidebar-open-rtl');
});
}
if (contentSpecific && typeof Mautic[contentSpecific + "OnLoad"] == 'function') {
if (inModal || typeof Mautic.loadedContent[contentSpecific] == 'undefined') {
Mautic.loadedContent[contentSpecific] = true;
Mautic[contentSpecific + "OnLoad"](container, response);
}
}
if (!inModal && container == 'body') {
//prevent notification dropdown from closing if clicking an action
mQuery('#notificationsDropdown').on('click', function (e) {
if (mQuery(e.target).hasClass('do-not-close')) {
e.stopPropagation();
}
});
if (mQuery('#globalSearchContainer').length) {
mQuery('#globalSearchContainer .search-button').click(function () {
mQuery('#globalSearchContainer').addClass('active');
if (mQuery('#globalSearchInput').val()) {
mQuery('#globalSearchDropdown').addClass('open');
}
setTimeout(function () {
mQuery('#globalSearchInput').focus();
}, 100);
mQuery('body').on('click.globalsearch', function (event) {
var target = event.target;
if (!mQuery(target).parents('#globalSearchContainer').length && !mQuery(target).parents('#globalSearchDropdown').length) {
Mautic.closeGlobalSearchResults();
}
});
});
mQuery("#globalSearchInput").on('change keyup paste', function () {
if (mQuery(this).val()) {
mQuery('#globalSearchDropdown').addClass('open');
} else {
mQuery('#globalSearchDropdown').removeClass('open');
}
});
Mautic.activateLiveSearch("#globalSearchInput", "lastGlobalSearchStr", "globalLivecache");
}
}
Mautic.renderCharts(container);
Mautic.stopIconSpinPostEvent();
//stop loading bar
if ((response && typeof response.stopPageLoading != 'undefined' && response.stopPageLoading) || container == '#app-content' || container == '.page-list') {
Mautic.stopPageLoadingBar();
}
const maps= mQuery(container).find('[data-load="map"]');
if(maps.length) {
maps.each((index,map) => map.addEventListener('click', () => {
const scopeId = event.target.getAttribute('href');
const scope = mQuery(scopeId);
if (scope.length) {
// Check if map is not already rendered
if (scope.children('.map-rendered').length) {
return;
}
// Loaded via AJAX not to block loading a whole page
const mapUrl = scope.attr('data-map-url');
scope.load(mapUrl, '', () => {
const map = Mautic.initMap(scope, 'regions');
});
}
}, false));
}
};
Mautic.setDynamicContentEditors = function(container) {
// The editor for dynamic content should only be initialized when the modal is opened due to conflicts and not being able to edit content otherwise
if (mauticFroalaEnabled && mQuery(container + ' textarea.editor-dynamic-content').length && Mautic.getActiveBuilderName() === 'legacy') {
console.log('[Builder] Using Froala for the Dynamic Content editor (legacy)');
mQuery(container + ' textarea.editor-dynamic-content').each(function () {
mQuery(this).froalaEditor();
});
} else if (mQuery(container + ' textarea.editor-dynamic-content').length) {
console.log('[Builder] Using CKEditor for the Dynamic Content editor');
mQuery(container + ' textarea.editor-dynamic-content').each(function () {
const textarea = mQuery(this);
const maxButtons = [ 'Undo', 'Redo', '-', 'Bold', 'Italic', 'Underline', 'Format', 'Font', 'FontSize', 'TextColor', 'BGColor', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'NumberedList', 'BulletedList', 'Blockquote', 'RemoveFormat', 'Link', 'Image', 'Table', 'InsertToken', 'Sourcedialog', 'Maximize']
let minButtons = ['Undo', 'Redo', '|', 'Bold', 'Italic', 'Underline'];
if (textarea.hasClass('editor-dynamic-content') || textarea.hasClass('editor-basic')) {
minButtons = ['Undo', 'Redo', '-', 'Bold', 'Italic', 'Underline', 'Format', 'Font', 'FontSize', 'TextColor', 'BGColor', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'NumberedList', 'BulletedList', 'Blockquote', 'RemoveFormat', 'Link', 'Image', 'Table', 'Sourcedialog', 'Maximize'];
}
let ckEditorToolbar = minButtons;
if (textarea.hasClass('editor-advanced') || textarea.hasClass('editor-basic-fullpage')) {
ckEditorToolbar = maxButtons;
}
Mautic.ConvertFieldToCkeditor(textarea, ckEditorToolbar);
});
}
}
/**
* @param jQueryObject
*/
Mautic.activateLookupTypeahead = function(containerEl) {
containerEl.find("*[data-toggle='field-lookup']").each(function () {
var lookup = mQuery(this),
callback = lookup.attr('data-callback') ? lookup.attr('data-callback') : 'activateFieldTypeahead';
Mautic[callback](
lookup.attr('id'),
lookup.attr('data-target'),
lookup.attr('data-options'),
lookup.attr('data-action')
);
});
};
/**
* @param jQueryObject
*/
Mautic.makeConfirmationsAlive = function(jQueryObject) {
jQueryObject.off('click.confirmation');
jQueryObject.on('click.confirmation', function (event) {
event.preventDefault();
MauticVars.ignoreIconSpin = true;
return Mautic.showConfirmation(this);
});
};
/**
*
* @param jQueryObject
*/
Mautic.makeModalsAlive = function(jQueryObject) {
jQueryObject.off('click.ajaxmodal');
jQueryObject.on('click.ajaxmodal', function (event) {
event.preventDefault();
Mautic.ajaxifyModal(this, event);
});
};
/**
*
* @param jQueryObject
*/
Mautic.makeLinksAlive = function(jQueryObject) {
jQueryObject.off('click.ajax');
jQueryObject.on('click.ajax', function (event) {
event.preventDefault();
return Mautic.ajaxifyLink(this, event);
});
};
/**
* Functions to be ran on ajax page unload
*/
Mautic.onPageUnload = function (container, response) {
//unload tooltips so they don't double show
if (typeof container != 'undefined') {
mQuery(container + " *[data-toggle='tooltip']").tooltip('destroy');
//unload lingering modals from body so that there will not be multiple modals generated from new ajaxed content
if (typeof MauticVars.modalsReset == 'undefined') {
MauticVars.modalsReset = {};
}
if (mauticFroalaEnabled && Mautic.getActiveBuilderName() === 'legacy') {
mQuery('textarea').froalaEditor('destroy');
} else {
if (ckEditors.size > 0) {
ckEditors.forEach(function(value, key, map){
map.get(key).destroy()
})
ckEditors.clear();
}
}
//turn off shuffle events
mQuery('html')
.off('fa.sidebar.minimize')
.off('fa.sidebar.maximize');
mQuery(container + " input[data-toggle='color']").each(function() {
mQuery(this).minicolors('destroy');
});
}
//run specific unloads
var contentSpecific = false;
if (container == '#app-content') {
//full page gets precedence
Mousetrap.reset();
contentSpecific = mauticContent;
// trash created chart objects to save some memory
if (typeof Mautic.chartObjects !== 'undefined') {
mQuery.each(Mautic.chartObjects, function (i, chart) {
chart.destroy();
});
Mautic.chartObjects = [];
}
// trash created map objects to save some memory
if (typeof Mautic.mapObjects !== 'undefined') {
mQuery.each(Mautic.mapObjects, (i, map) => {
map.destroyMap();
});
Mautic.mapObjects = [];
}
// trash tokens to save some memory
if (typeof Mautic.builderTokens !== 'undefined') {
Mautic.builderTokens = {};
}
} else if (response && response.mauticContent) {
contentSpecific = response.mauticContent;
}
if (contentSpecific) {
if (typeof Mautic[contentSpecific + "OnUnload"] == 'function') {
Mautic[contentSpecific + "OnUnload"](container, response);
}
if (typeof Mautic.loadedContent[contentSpecific] !== 'undefined') {
delete Mautic.loadedContent[contentSpecific];
}
}
};
/**
* Retrieves content of href via ajax
* @param el
* @param event
* @returns {boolean}
*/
Mautic.ajaxifyLink = function (el, event) {
if (mQuery(el).hasClass('disabled')) {
return false;
}
var route = mQuery(el).attr('href');
if (route.indexOf('javascript') >= 0 || MauticVars.routeInProgress === route) {
return false;
}
if (route.indexOf('batchExport') >= 0) {
Mautic.initiateFileDownload(route);
return true;
}
if (event.ctrlKey || event.metaKey) {
//open the link in a new window
route = route.split("?")[0];
window.open(route, '_blank');
return;
}
//prevent leaving if currently in a form
if (mQuery(".form-exit-unlock-id").length) {
if (mQuery(el).attr('data-ignore-formexit') != 'true') {
var unlockParameter = (mQuery('.form-exit-unlock-parameter').length) ? mQuery('.form-exit-unlock-parameter').val() : '';
Mautic.unlockEntity(mQuery('.form-exit-unlock-model').val(), mQuery('.form-exit-unlock-id').val(), unlockParameter);
}
}
var link = mQuery(el).attr('data-menu-link');
if (link !== undefined && link.charAt(0) != '#') {
link = "#" + link;
}
var method = mQuery(el).attr('data-method');
if (!method) {
method = 'GET'
}
MauticVars.routeInProgress = route;
var target = mQuery(el).attr('data-target');
if (!target) {
target = null;
}
//give an ajaxified link the option of not displaying the global loading bar
var showLoadingBar = (mQuery(el).attr('data-hide-loadingbar')) ? false : true;
//close the global search results if opened
if (mQuery('#globalSearchContainer').length && mQuery('#globalSearchContainer').hasClass('active')) {
Mautic.closeGlobalSearchResults();
}
Mautic.loadContent(route, link, method, target, showLoadingBar);
};
/**
* Convert to chosen select
*
* @param el
*/
Mautic.activateChosenSelect = function(el, ignoreGlobal, jQueryVariant) {
var mQuery = (typeof jQueryVariant != 'undefined') ? jQueryVariant : window.mQuery;
if (mQuery(el).parents('.no-chosen').length && !ignoreGlobal) {
// Globally ignored chosens because they are handled manually due to hidden elements, etc
return;
}
var noResultsText = mQuery(el).data('no-results-text');
if (!noResultsText) {
noResultsText = mauticLang['chosenNoResults'];
}
var isLookup = mQuery(el).attr('data-chosen-lookup');
if (isLookup) {
if (mQuery(el).attr('data-new-route')) {
// Register method to initiate new
mQuery(el).on('change', function () {
var url = mQuery(el).attr('data-new-route');
// If the element is already in a modal then use a popup
if (mQuery(el).val() == 'new' && (mQuery(el).attr('data-popup') == "true" || mQuery(el).closest('.modal').length > 0)) {
var queryGlue = url.indexOf('?') >= 0 ? '&' : '?';
// De-select the new select option
mQuery(el).find('option[value="new"]').prop('selected', false);
mQuery(el).trigger('chosen:updated');
Mautic.loadNewWindow({
"windowUrl": url + queryGlue + "contentOnly=1&updateSelect=" + mQuery(el).attr('id')
});
} else {
Mautic.loadAjaxModalBySelectValue(this, 'new', url, mQuery(el).attr('data-header'));
}
});
}
var multiPlaceholder = mauticLang['mautic.core.lookup.search_options'],
singlePlaceholder = mauticLang['mautic.core.lookup.search_options'];
} else {
var multiPlaceholder = mauticLang['chosenChooseMore'],
singlePlaceholder = mauticLang['chosenChooseOne'];
}
if (typeof mQuery(el).data('chosen-placeholder') !== 'undefined') {
multiPlaceholder = singlePlaceholder = mQuery(el).data('chosen-placeholder');
}
mQuery(el).chosen({
placeholder_text_multiple: multiPlaceholder,
placeholder_text_single: singlePlaceholder,
no_results_text: noResultsText,
width: "100%",
allow_single_deselect: true,
include_group_label_in_selected: true,
search_contains: true
});
if (isLookup) {
var searchTerm = mQuery(el).attr('data-model');
if (searchTerm) {
mQuery(el).ajaxChosen({
type: 'GET',
url: mauticAjaxUrl + '?action=' + mQuery(el).attr('data-chosen-lookup'),
dataType: 'json',
afterTypeDelay: 2,
minTermLength: 2,
jsonTermKey: searchTerm,
keepTypingMsg: "Keep typing...",
lookingForMsg: "Looking for"
});
}
}
};
/**
* Check and destroy chosen select
*
* @param el
*/
Mautic.destroyChosen = function(el) {
if(el.get(0)) {
var eventObject = mQuery._data(el.get(0), 'events');
}
// Check if object has chosen event
if (eventObject !== undefined && eventObject['chosen:activate'] !== undefined) {
el.chosen('destroy');
el.off('chosen:activate chosen:close chosen:open chosen:updated'); //Clear chosen events because chosen('destroy') doesn't
}
};
/**
* Activate a typeahead lookup
*/
Mautic.activateFieldTypeahead = function (field, target, options, action) {
var fieldId = '#' + field;
var fieldEl = mQuery('#' + field);
if (fieldEl.length && fieldEl.parent('.twitter-typeahead').length) {
return; // If the parent exist then the typeahead was already initialized. Abort.
}
if (options && typeof options === 'String') {
var keys = values = [];
options = options.split('||');
if (options.length == 2) {
keys = options[1].split('|');
values = options[0].split('|');
} else {
values = options[0].split('|');
}
var fieldTypeahead = Mautic.activateTypeahead(fieldId, {
dataOptions: values,
dataOptionKeys: keys,
minLength: 0
});
} else {
var typeAheadOptions = {
prefetch: true,
remote: true,
action: action + "&field=" + target
};
if (('undefined' !== typeof options) && ('undefined' !== typeof options.limit)) {
typeAheadOptions.limit = options.limit;
}
if (('undefined' !== typeof options) && ('undefined' !== typeof options.noRrecordMessage)) {
typeAheadOptions.noRrecordMessage = options.noRrecordMessage;
}
var fieldTypeahead = Mautic.activateTypeahead(fieldId, typeAheadOptions);
}
var callback = function (event, datum) {
if (fieldEl.length && datum["value"]) {
fieldEl.val(datum["value"]);
var lookupCallback = mQuery(fieldId).data('lookup-callback');
if (lookupCallback && typeof Mautic[lookupCallback] == 'function') {
Mautic[lookupCallback](field, datum);
}
}
};
mQuery(fieldTypeahead).on('typeahead:selected', callback).on('typeahead:autocompleted', callback);
};
/**
* Convert to multiselect
*
* @param el
*/
Mautic.activateMultiSelect = function(el) {
var moveOption = function(v, prev) {
var theOption = mQuery(el).find('option[value="' + v + '"]').first();
var lastSelected = mQuery(el).find('option:not(:disabled)').filter(function () {
return mQuery(this).prop('selected');
}).last();
if (typeof prev !== 'undefined') {
if (prev) {
var prevOption = mQuery(el).find('option[value="' + prev + '"]').first();
theOption.insertAfter(prevOption);
return;
}
} else if (lastSelected.length) {
theOption.insertAfter(lastSelected);
return;
}
theOption.prependTo(el);
};
mQuery(el).multiSelect({
afterInit: function(container) {
var funcName = mQuery(el).data('afterInit');
if (funcName) {
Mautic[funcName]('init', container);
}
var selectThat = this,
$selectableSearch = this.$selectableUl.prev(),
$selectionSearch = this.$selectionUl.prev(),
selectableSearchString = '#' + this.$container.attr('id') + ' .ms-elem-selectable:not(.ms-selected)',
selectionSearchString = '#' + this.$container.attr('id') + ' .ms-elem-selection.ms-selected';
this.qs1 = $selectableSearch.quicksearch(selectableSearchString)
.on('keydown', function (e) {
if (e.which === 40) {
selectThat.$selectableUl.focus();
return false;
}
});
this.qs2 = $selectionSearch.quicksearch(selectionSearchString)
.on('keydown', function (e) {
if (e.which == 40) {
selectThat.$selectionUl.focus();
return false;
}
});
var selectOrder = mQuery(el).data('order');
if (selectOrder && selectOrder.length > 1) {
this.deselect_all();
mQuery.each(selectOrder, function(k, v) {
selectThat.select(v);
});
}
var isSortable = mQuery(el).data('sortable');
if (isSortable) {
mQuery(el).parent('.choice-wrapper').find('.ms-selection').first().sortable({
items: '.ms-elem-selection',
helper: function (e, ui) {
ui.width(mQuery(el).width());
return ui;
},
axis: 'y',
scroll: false,
update: function(event, ui) {
var prev = ui.item.prev();
var prevValue = (prev.length) ? prev.data('ms-value') : '';
moveOption(ui.item.data('ms-value'), prevValue);
}
});
}
},
afterSelect: function(value) {
var funcName = mQuery(el).data('afterSelect');
if (funcName) {
Mautic[funcName]('select', value);
}
this.qs1.cache();
this.qs2.cache();
moveOption(value);
},
afterDeselect: function(value) {
var funcName = mQuery(el).data('afterDeselect');
if (funcName) {
Mautic[funcName]('deselect', value);
}
this.qs1.cache();
this.qs2.cache();
},
selectableHeader: "<input type='text' class='ms-search form-control' autocomplete='off'>",
selectionHeader: "<input type='text' class='ms-search form-control' autocomplete='off'>",
keepOrder: true
});
};
/**
* Activate modal buttons for embedded forms
*
* @param container
*/
Mautic.activateModalEmbeddedForms = function(container) {
mQuery(container + " *[data-embedded-form='cancel']").off('click.embeddedform');
mQuery(container + " *[data-embedded-form='cancel']").on('click.embeddedform', function (event) {
event.preventDefault();
var modal = mQuery(this).closest('.modal');
mQuery(modal).modal('hide');
if (mQuery(this).attr('data-embedded-form-clear') === 'true') {
Mautic.resetForm(modal);
}
if (typeof mQuery(this).attr('data-embedded-form-callback') != 'undefined') {
if (typeof window["Mautic"][mQuery(this).attr('data-embedded-form-callback')] == 'function') {
window["Mautic"][mQuery(this).attr('data-embedded-form-callback')].apply('window', [this, modal]);
}
}
});
// Configure the modal
mQuery(container + " *[data-embedded-form='add']").each(function() {
var submitButton = this;
var modal = mQuery(this).closest('.modal');
if (typeof mQuery(modal).data('bs.modal') !== 'undefined' && typeof mQuery(modal).data('bs.modal').options !== 'undefined') {
mQuery(modal).data('bs.modal').options.keyboard = false;
mQuery(modal).data('bs.modal').options.backdrop = 'static';
} else {
mQuery(modal).attr('data-keyboard', false);
mQuery(modal).attr('data-backdrop', 'static');
}
mQuery(modal).on('show.bs.modal', function () {
// Don't allow submitting with enter key
mQuery(this).on("keydown.embeddedForm", ":input:not(textarea)", function(event) {
if (event.keyCode == 13) {
event.preventDefault();
if (event.metaKey || event.ctrlKey) {
// Submit the modal
mQuery(submitButton).click();
}
}
});
});
//clean slate upon close
mQuery(modal).on('hidden.bs.modal', function () {
mQuery(this).off("keydown.embeddedForm", ":input:not(textarea)");
});
});
mQuery(container + " *[data-embedded-form='add']").off('click.embeddedform');
mQuery(container + " *[data-embedded-form='add']").on('click.embeddedform', function (event) {
event.preventDefault();
var modal = mQuery(this).closest('.modal');
mQuery(modal).modal('hide');
if (typeof mQuery(this).attr('data-embedded-form-callback') != 'undefined') {
if (typeof window["Mautic"][mQuery(this).attr('data-embedded-form-callback')] == 'function') {
window["Mautic"][mQuery(this).attr('data-embedded-form-callback')].apply('window', [this, modal]);
}
}
});
};
/**
* Activate containers datetime inputs
* @param container
*/
Mautic.activateDateTimeInputs = function(el, type) {
if (typeof type == 'undefined') {
type = 'datetime';
}
var format = mQuery(el).data('format');
if (type == 'datetime') {
mQuery(el).datetimepicker({
format: (format) ? format : 'Y-m-d H:i',
lazyInit: true,
validateOnBlur: false,
allowBlank: true,
scrollMonth: false,
scrollInput: false
});
} else if(type == 'date') {
mQuery(el).datetimepicker({
timepicker: false,
format: (format) ? format : 'Y-m-d',
lazyInit: true,
validateOnBlur: false,
allowBlank: true,
scrollMonth: false,
scrollInput: false,
closeOnDateSelect: true
});
} else if (type == 'time') {
mQuery(el).datetimepicker({
datepicker: false,
format: (format) ? format : 'H:i',
lazyInit: true,
validateOnBlur: false,
allowBlank: true,
scrollMonth: false,
scrollInput: false
});
}
mQuery(el).addClass('calendar-activated');
};
/**
* Activates Typeahead.js command lists for search boxes
* @param elId
* @param modelName
*/
Mautic.activateSearchAutocomplete = function (elId, modelName) {
if (mQuery('#' + elId).length) {
var livesearch = (mQuery('#' + elId).attr("data-toggle=['livesearch']")) ? true : false;
var typeaheadObject = Mautic.activateTypeahead('#' + elId, {
prefetch: true,
remote: false,
limit: 0,
action: 'commandList&model=' + modelName,
multiple: true
});
mQuery(typeaheadObject).on('typeahead:selected', function (event, datum) {
if (livesearch) {
//force live search update,
MauticVars.lastSearchStr = '';
mQuery('#' + elId).keyup();
}
}).on('typeahead:autocompleted', function (event, datum) {
if (livesearch) {
//force live search update
MauticVars.lastSearchStr = '';
mQuery('#' + elId).keyup();
}
});
}
};
/**
* Activate live search feature
*
* @param el
* @param searchStrVar
* @param liveCacheVar
*/
Mautic.activateLiveSearch = function (el, searchStrVar, liveCacheVar) {
if (!mQuery(el).length) {
return;
}
//find associated button
var btn = "button[data-livesearch-parent='" + mQuery(el).attr('id') + "']";
mQuery(el).on('focus', function () {
Mautic.currentSearchString = mQuery(this).val().trim();
});
mQuery(el).on('change keyup paste', {}, function (event) {
var searchStr = mQuery(el).val().trim();
var spaceKeyPressed = (event.which == 32 || event.keyCode == 32);
var enterKeyPressed = (event.which == 13 || event.keyCode == 13);
var deleteKeyPressed = (event.which == 8 || event.keyCode == 8);
if (!enterKeyPressed && Mautic.currentSearchString && Mautic.currentSearchString == searchStr) {
return;
}
var target = mQuery(el).attr('data-target');
var diff = searchStr.length - MauticVars[searchStrVar].length;
if (diff < 0) {
diff = parseInt(diff) * -1;
}
var overlayEnabled = mQuery(el).attr('data-overlay');
if (!overlayEnabled || overlayEnabled == 'false') {
overlayEnabled = false;
} else {
overlayEnabled = true;
}
var overlayTarget = mQuery(el).attr('data-overlay-target');
if (!overlayTarget) overlayTarget = target;
if (overlayEnabled) {
mQuery(el).off('blur.livesearchOverlay');
mQuery(el).on('blur.livesearchOverlay', function() {
mQuery(overlayTarget + ' .content-overlay').remove();
});
}
if (!deleteKeyPressed && overlayEnabled) {
var overlay = mQuery('<div />', {"class": "content-overlay"}).html(mQuery(el).attr('data-overlay-text'));
if (mQuery(el).attr('data-overlay-background')) {
overlay.css('background', mQuery(el).attr('data-overlay-background'));
}
if (mQuery(el).attr('data-overlay-color')) {
overlay.css('color', mQuery(el).attr('data-overlay-color'));
}
}
//searchStr in MauticVars[liveCacheVar] ||
if ((!searchStr && MauticVars[searchStrVar].length) || diff >= 3 || spaceKeyPressed || enterKeyPressed) {
MauticVars[searchStrVar] = searchStr;
event.data.livesearch = true;
Mautic.filterList(event,
mQuery(el).attr('id'),
mQuery(el).attr('data-action'),
target,
liveCacheVar,
overlayEnabled,
overlayTarget
);
} else if (overlayEnabled) {
if (!mQuery(overlayTarget + ' .content-overlay').length) {
mQuery(overlayTarget).prepend(overlay);
}
}
});
if (mQuery(btn).length) {
mQuery(btn).on('click', {'parent': mQuery(el).attr('id')}, function (event) {
var searchStr = mQuery(el).val().trim();
MauticVars[searchStrVar] = searchStr;
Mautic.filterButtonClicked = true;
Mautic.filterList(event,
event.data.parent,
mQuery('#' + event.data.parent).attr('data-action'),
mQuery('#' + event.data.parent).attr('data-target'),
'liveCache',
mQuery(this).attr('data-livesearch-action')
);
});
if (mQuery(el).val()) {
mQuery(btn).attr('data-livesearch-action', 'clear');
mQuery(btn + ' i').removeClass('ri-search-line').addClass('ri-eraser-line');
} else {
mQuery(btn).attr('data-livesearch-action', 'search');
mQuery(btn + ' i').removeClass('ri-eraser-line').addClass('ri-search-line');
}
}
};
/**
* Filters a list based on select value
*
* @param el
*/
Mautic.activateListFilterSelect = function(el) {
var filterName = mQuery(el).attr('name');
var isMultiple = mQuery(el).attr('multiple') ? true : false;
var prefixExceptions = mQuery(el).data('prefix-exceptions');
if (isMultiple && prefixExceptions) {
if (typeof Mautic.listFilterValues == 'undefined') {
Mautic.listFilterValues = {};
}
// Store values for comparison on change
Mautic.listFilterValues[filterName] = mQuery(el).val();
}
mQuery(el).on('change', function() {
var filterVal = mQuery(this).val();
if (filterVal == null) {
filterVal = [];
}
if (prefixExceptions) {
var limited = prefixExceptions.split(',');
if (filterVal.length > 1) {
for (var i=0; i<filterVal.length; i++) {
if (mQuery.inArray(filterVal[i], Mautic.listFilterValues[filterName]) == -1) {
var newOption = mQuery(this).find('option[value="' + filterVal[i] + '"]');
var prefix = mQuery(newOption).parent().data('prefix');
if (mQuery.inArray(prefix, limited) != -1) {
mQuery(newOption).siblings().prop('selected', false);
filterVal = mQuery(this).val();
mQuery(this).trigger('chosen:updated');
}
}
}
}
Mautic.listFilterValues[filterName] = filterVal;
}
var tmpl = mQuery(this).data('tmpl');
if (!tmpl) {
tmpl = 'list';
}
var filters = (isMultiple) ? JSON.stringify(filterVal) : filterVal;
var request = window.location.pathname + '?tmpl=' + tmpl + '&' + filterName + '=' + filters;
Mautic.loadContent(request, '', 'POST', mQuery(this).data('target'));
});
};
/**
* Converts an input to a color picker
* @param el
*/
Mautic.activateColorPicker = function(el, options) {
let input = mQuery(el);
var pickerOptions = input.data('color-options');
if (!pickerOptions) {
pickerOptions = {
theme: 'bootstrap',
change: function (hex) {
input.trigger('change.minicolors', hex);
}
};
}
if (typeof options == 'object') {
pickerOptions = mQuery.extend(pickerOptions, options);
}
input.minicolors(pickerOptions);
// The previous version of the Minicolors library did not use the # in the value. This is for backwards compatibility.
input.val(input.val().replace('#', ''));
input.on('blur', function() {
input.val(input.val().replace('#', ''));
});
};
/**
* Activates typeahead
* @param el
* @param options
* @returns {*}
*/
Mautic.activateTypeahead = function (el, options) {
if (typeof options == 'undefined' || !mQuery(el).length) {
return;
}
if (typeof options.remote == 'undefined') {
options.remote = (options.action) ? true : false;
}
if (typeof options.prefetch == 'undefined') {
options.prefetch = false;
}
if (typeof options.limit == 'undefined') {
options.limit = 5;
}
if (!options.displayKey) {
options.displayKey = 'value';
}
if (typeof options.multiple == 'undefined') {
options.multiple = false;
}
if (typeof options.minLength == 'undefined') {
options.minLength = 2;
}
if (options.prefetch || options.remote) {
if (typeof options.action == 'undefined') {
return;
}
var sourceOptions = {
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(options.displayKey),
queryTokenizer: Bloodhound.tokenizers.whitespace,
dupDetector: function (remoteMatch, localMatch) {
return (remoteMatch[options.displayKey] == localMatch[options.displayKey]);
},
ttl: 15000,
limit: options.limit
};
var filterClosure = function (list) {
if (typeof list.ignore_wdt != 'undefined') {
delete list.ignore_wdt;
}
if (typeof list.success != 'undefined') {
delete list.success;
}
if (typeof list == 'object') {
if (typeof list[0] != 'undefined') {
//meant to be an array and not an object
list = mQuery.map(list, function (el) {
return el;
});
} else {
//empty object so return empty array
list = [];
}
}
return list;
};
if (options.remote) {
sourceOptions.remote = {
url: mauticAjaxUrl + "?action=" + options.action + "&filter=%QUERY",
filter: filterClosure,
wildcard: '%QUERY',
};
}
if (options.prefetch) {
sourceOptions.prefetch = {
url: mauticAjaxUrl + "?action=" + options.action,
filter: filterClosure
};
}
var theBloodhound = new Bloodhound(sourceOptions);
theBloodhound.initialize();
} else {
var substringMatcher = function (strs, strKeys) {
return function findMatches(q, cb) {
var matches, substrRegex;
// an array that will be populated with substring matches
matches = [];
// regex used to determine if a string contains the substring `q`
substrRegex = new RegExp(q, 'i');
// iterate through the pool of strings and for any string that
// contains the substring `q`, add it to the `matches` array
mQuery.each(strs, function (i, str) {
if (typeof str == 'object') {
str = str[options.displayKey];
}
if (substrRegex.test(str)) {
// the typeahead jQuery plugin expects suggestions to a
// JavaScript object, refer to typeahead docs for more info
var match = {};
match[options.displayKey] = str;
if (strKeys.length && typeof strKeys[i] != 'undefined') {
match['id'] = strKeys[i];
}
matches.push(match);
}
});
cb(matches);
};
};
var lookupOptions = (options.dataOptions) ? options.dataOptions : mQuery(el).data('options');
var lookupKeys = (options.dataOptionKeys) ? options.dataOptionKeys : [];
if (!lookupOptions) {
return;
}
}
var noRrecordMessage = (options.noRrecordMessage) ? options.noRrecordMessage : mQuery(el).data('no-record-message');
var theName = el.replace(/[^a-z0-9\s]/gi, '').replace(/[-\s]/g, '_');
var dataset = {
name: theName,
displayKey: options.displayKey,
source: (typeof theBloodhound != 'undefined') ? theBloodhound.ttAdapter() : substringMatcher(lookupOptions, lookupKeys)
};
if (noRrecordMessage) {
dataset.templates = {
empty: "<p>" + noRrecordMessage + "<p>"
}
}
var theTypeahead = mQuery(el).typeahead(
{
hint: true,
highlight: true,
minLength: options.minLength,
multiple: options.multiple
},
dataset
).on('keypress', function (event) {
if ((event.keyCode || event.which) == 13) {
mQuery(el).typeahead('close');
}
}).on('focus', function() {
if(mQuery(el).typeahead('val') === '' && !options.minLength) {
mQuery(el).data('ttTypeahead').input.trigger('queryChanged', '');
}
});
return theTypeahead;
};
/**
* Activate sortable
*
* @param el
*/
Mautic.activateSortable = function(el) {
var prefix = mQuery(el).attr('data-prefix');
if (mQuery('#' + prefix + '_additem').length) {
mQuery('#' + prefix + '_additem').click(function () {
var count = mQuery('#' + prefix + '_itemcount').val();
var prototype = mQuery('#' + prefix + '_additem').attr('data-prototype');
prototype = prototype.replace(/__name__/g, count);
mQuery(prototype).appendTo(mQuery('#' + prefix + '_list div.list-sortable'));
mQuery('#' + prefix + '_list_' + count).focus();
count++;
mQuery('#' + prefix + '_itemcount').val(count);
return false;
});
}
mQuery('#' + prefix + '_list div.list-sortable').sortable({
items: 'div.sortable',
handle: 'span.postaddon',
axis: 'y',
containment: '#' + prefix + '_list',
stop: function (i) {
var order = 0;
mQuery('#' + prefix + '_list div.list-sortable div.input-group input').each(function () {
var name = mQuery(this).attr('name');
if (mQuery(this).hasClass('sortable-label')) {
name = name.replace(/(\[list\]\[[0-9]+\]\[label\])$/g, '') + '[list][' + order + '][label]';
} else if (mQuery(this).hasClass('sortable-value')) {
name = name.replace(/(\[list\]\[[0-9]+\]\[value\])$/g, '') + '[list][' + order + '][value]';
order++;
} else {
name = name.replace(/(\[list\]\[[0-9]+\])$/g, '') + '[list][' + order + ']';
order++;
}
mQuery(this).attr('name', name);
});
}
});
};
/**
* Close global search results
*/
Mautic.closeGlobalSearchResults = function () {
mQuery('#globalSearchContainer').removeClass('active');
mQuery('#globalSearchDropdown').removeClass('open');
mQuery('body').off('click.globalsearch');
};
/**
* Download a link via iframe
*
* @param link
*/
Mautic.initiateFileDownload = function (link) {
if (mauticContactExportInBackground === 1 && link.indexOf('filetype=csv') >= 0) {
Mautic.processCsvContactExport(link);
return;
}
//initialize download links
mQuery("<iframe/>").attr({
src: link,
style: "visibility:hidden;display:none"
}).appendTo(mQuery('body'));
};
Mautic.processCsvContactExport = function (route) {
mQuery.ajax({
showLoadingBar: true,
url: route,
type: "POST",
dataType: "json",
success: function (response) {
Mautic.processPageContent(response);
if (typeof callback == 'function') {
callback(response);
}
},
error: function (request, textStatus, errorThrown) {
Mautic.processAjaxError(request, textStatus, errorThrown);
}
});
};
|