require(['jquery', 'Noty'], function($, Noty) {
$(function() {
window.alert = {
show: function (message, type = "success", layout = "topRight", theme = "sunset") {
new Noty({
type: type,
layout: layout,
text: message,
theme: theme,
timeout: 2500,
closeWith: ["click", "button"]
}).show();
}
};
});
});
require(['jquery', 'datatables.net', 'datatables.net-bs4', 'selectize'], function($, DataTable) {
$(function() {
$(".transferPostsAndDelete").click(function() {
$(".deleteUser").modal("show");
$(".deleteUser").find("input[name='from']").val($(this).data("from"));
})
$(".triggerPhaseModal").click(function() {
if($(this).data("phase-id")) {
$(".phaseModal").find("input[name='phase_id']").val($(this).data("phase-id"));
$(".phaseModal").find("input[name='name']").val($(this).data("phase-name"));
$(".phaseModal").find("select[name='reviewer_role_id']")[0].selectize.setValue($(this).data("phase-reviewer"));
} else {
$(".phaseModal").find("form")[0].reset();
$(".phaseModal").find("select")[0].selectize.clear();
}
$(".phaseModal").modal("show");
})
$(".triggerPostSecurityModal").click(function() {
if($(this).data("post-security-id")) {
var phaseIds = $(this).data("post-security-phase-ids");
phaseIds = typeof phaseIds == "string" ? phaseIds.split(",") : phaseIds;
$(".postSecurityModal").find("input[name='post_security_id']").val($(this).data("post-security-id"));
$(".postSecurityModal").find("select[name='role_id_to_be_reviewed']")[0].selectize.setValue($(this).data("post-security-role"));
$(".postSecurityModal").find(".phasesSelect")[0].selectize.setValue(phaseIds);
} else {
$(".postSecurityModal").find("select").each(function(i, item) {
$(item)[0].selectize.clear();
});
}
$(".postSecurityModal").modal("show");
});
if ($(".phasesSelect").length) {
$('#phasesSelect').selectize({
persist: false,
maxItems: null,
});
}
$(".postSecurityStore").submit(function() {
var selectedPhases = $(".phasesSelect")[0].selectize.items;
$(this).find("input[name='phase_ids']").val(selectedPhases);
})
var selectedCountry = [null];
if($("#selectWithContent").length > 0) {
$("#selectWithContent option").each(function() {
if($(this).is(":selected")) {
selectedCountry = [];
selectedCountry.push($(this).val());
}
});
}
$("#selectWithContent").selectize({
persist: false,
// items: selectedCountry,
render: {
option: function (data, escape) {
return '
' +
'
' +
'
' + escape(data.text) + '' +
'
';
},
item: function (data, escape) {
return '' +
'
' +
escape(data.text) +
'
';
}
}
});
var tags = [];
var tempTags = [];
if($("#postEditor").length > 0) {
var oldTags = $("input[name='tags']").val().split(",");
if(oldTags.length > 0) {
for(var i=0; i");
var action = $(this).data("action");
var method = $(this).data("method");
var token = $("meta[name='csrf-token']").attr("content");
form.attr("action", action);
form.attr("method", "post");
form.append("");
form.append("");
$(this).append(form);
if(method == "delete") {
if(confirm("Are you sure you want to delete?")) {
return $(this).find(form).submit();
}
$(this).find(form).remove();
return false;
}
return $(this).find(form).submit();
});
$(".actionForm").submit(function(e) {
if($(".postContent").length > 0) {
$(".postContent").val($(".ql-editor").html());
$("input[name='tags']").val(tags.join(","));
}
var inputs = this.querySelectorAll("input[required]");
if(inputs.length == 0) {
$(this).find(".submitBtn").prop("disabled", true);
$(this).find(".submitBtn").val("Processing...");
return;
}
for(var i=0; i 0) {
$(this).find(".submitBtn").prop("disabled", true);
$(this).find(".submitBtn").val("Processing...");
}
}
});
$("#dttable, .dttable").DataTable({
"processing": true,
"language": {
"lengthMenu": "",
"search": "",
"searchPlaceholder": "Search in records"
},
'aoColumnDefs': [{
'bSortable': false,
'aTargets': [-1],
}],
});
$("select").not("select[class^='ql-']").selectize();
$("input[type='file']").on("change",function() {
let fileName = $(this).val().split("\\").pop();
$(this).next(".custom-file-label").html(fileName);
});
$(".dropdown-notifications-unread .nav-unread").hide();
notifications();
setInterval(function() { notifications(); }, 20000);
$(".dropdown-notifications-wrapper").click(function() {
$(".dropdown-notifications-unread .nav-unread").hide();
});
});
function notifications() {
var url = "/dashboard/get-notifications";
var _token = $("meta[name='csrf-token']").attr("content");
$.ajax({
url: url,
type: "post",
dataType: "json",
data: {
_token : _token,
},
success: function(response) {
$(".dropdown-notifications a:not(:last)").remove();
$(".dropdown-notifications-unread .nav-unread").hide();
var l = response.length;
if(hasNew(response)) {
$(".dropdown-notifications .unreadNotificationsInfo").hide();
$(".dropdown-notifications-unread .nav-unread").show();
}
if(l == 0) {
$(".dropdown-notifications .unreadNotificationsInfo").show();
}
if(l > 0) {
$(".dropdown-notifications .unreadNotificationsInfo").hide();
}
for(var i=0; i
` + response[i].message + `
` + response[i].ago + `
`;
$(".dropdown-notifications").prepend(notificationItem);
}
},
error: function(response) {
console.log(response);
}
});
}
function hasNew(response) {
for(var i=0; i 0) {
quill.clipboard.dangerouslyPasteHTML($(".postContent").val());
}
}
if($(".categoryColor").length) {
$(".categoryColor").colorpickle({
clickToggle: true,
theme: "engineer",
showOk: true,
showCancel: true,
onTop: true,
visible: false,
closeOnOk: true,
closeOnCancel: true,
width: "500px",
modal: true
});
if ($(".categoryColor").val().length) {
$(".categoryColor").colorpickle("setHex", $(".categoryColor").val());
$(".colorPickerIcon").css("background-color", $(".categoryColor").val());
}
}
});
});