NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

$(() => {
getRoleList();
getRoleDef();
getYetkiList();
$('#btnAddNewRole').click(() => {
$('#KullaniciRolEkleModal').modal('show');
$('#btnUpdateRolGrubu').hide();
$('#btnSaveRolGrubu').show();
clearInput();
getRoleDef();
});
$('#btnSaveRolGrubu').click(() => { addRole(); });
$('#btnUpdateRolGrubu').click(() => { updateRoleGroup(); });
$('#btnUpdateYetki').click(() => { updateYetki(); });
});

/// ===> Rol Grubu Listesi <=== ///
getRoleList = () => {
var rows = "";
showSwal('Lütfen Bekleyin..');
getData('GET','users/role-group-get',{},(response) => {
if (response.status) {
response?.data?.forEach(function (data, index) {
rows += `<tr>
<td>${index + 1}</td>
<td>${data.name}</td>
<td>${data.display_name}</td>
<td>${data.description}</td>
<td class="text-end">
<a href="#" class="btn btn-light btn-active-light-primary btn-sm" data-kt-menu-trigger="click" data-kt-menu-placement="bottom-end">İşlemler
<span class="svg-icon svg-icon-5 m-0">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M11.4343 12.7344L7.25 8.55005C6.83579 8.13583 6.16421 8.13584 5.75 8.55005C5.33579 8.96426 5.33579 9.63583 5.75 10.05L11.2929 15.5929C11.6834 15.9835 12.3166 15.9835 12.7071 15.5929L18.25 10.05C18.6642 9.63584 18.6642 8.96426 18.25 8.55005C17.8358 8.13584 17.1642 8.13584 16.75 8.55005L12.5657 12.7344C12.2533 13.0468 11.7467 13.0468 11.4343 12.7344Z" fill="black" />
</svg>
</span>
</a>
<div class="menu menu-sub menu-sub-dropdown menu-column menu-rounded menu-gray-600 menu-state-bg-light-primary fw-bold fs-7 w-125px py-4" data-kt-menu="true">
<div class="menu-item px-3">
<a onclick="getByID(${data.role_group_id})" class="menu-link px-3">Düzenle</a>
</div>
<div class="menu-item px-3">
<a href="#" class="menu-link px-3" onclick="deleteItem(${data.role_group_id})">Sil</a>
</div>
</div>
</tr>`;
})

$("#dtTable").DataTable().destroy();
$('#dtBody').html(rows);
setTableSearch("dtTable");
//**dropzone butonları için temanın fonksiyonu */
KTMenu.createInstances();

closeSwal();
}
}
)
}

/// ===> Rol Tanımı Listesi <=== ///
getRoleDef = () => {
var rolesItem = "";
getData('GET','users/roles-get/true','',(response) => {
if (response.status) {
response.data.forEach((data) => {
rolesItem += `<optgroup data-parent="${data.group_name}" label="${data.group_display_name}">`;
data.rows.forEach((items) => {
rolesItem += `<option data-group="${data.group_name}" data-group-name="${data.group_display_name}" value="${items.role_id}">${items.display_name}</option>`;
});
rolesItem += `</optgroup>`;
})
}
$('#roleDefination').html(rolesItem);
}
)
}

/// ===> Rol Gurubu Ekleme <=== ///
addRole = () => {
var rol = $('#rolGrupAdi').val();
var ekran = $('#ekranAdi').val();
var aciklama = $('#rolAciklama').val();
var roles = $('#roleList option').toArray().map(i => $(i).val());
var roleArr = []
roles.forEach((data) => {
roleArr.push({ "role_id": data, "display_name": ekran })
})
var _data = {
"name": rol,
"display_name": ekran,
"description": aciklama,
"roles": roleArr
}
getData('POST','users/role-group-add',_data,(response) => {
if (response.status) {
Swal.fire('Başarılı', response.message, 'success');
setTimeout(() => {
getRoleList();
}, 1500);
clearInput();
$('#KullaniciRolEkleModal').modal('hide');
}
}
)
}

/// ===> Rol Grubu Güncelleme <=== ///
updateRoleGroup = () => {
showSwal('Yükleniyor');
var id = $('#RoleId').val();
var rol = $('#rolGrupAdi').val();
var ekran = $('#ekranAdi').val();
var aciklama = $('#rolAciklama').val();
var roles = $('#roleList option').toArray().map(i => $(i).val());
var roleArr = []
roles.forEach((data) => {
roleArr.push({ "role_id": Number(data), "display_name": ekran })
});

_data = {
"role_group_id": id,
"name": rol,
"display_name": ekran,
"description": aciklama,
"roles": roleArr
}
getData('POST','users/role-group-update',_data,function (response) {
if (response.status) {
$('#KullaniciRolEkleModal').modal('hide');
Swal.fire('Başarılı', response.message, 'success');
setTimeout(() => {
getRoleList();
}, 1000);
clearInput();
}
}
)

}

/// ===> Düzenle Butonunun Çağırdığı Fonk. <=== ///
getByID = (id) => {
clearInput();
$('#KullaniciRolEkleModal').modal('show');
$('#btnSaveRolGrubu').hide();
$('#btnUpdateRolGrubu').show();
getData('GET',`users/role-group-update/${id}`,'',(response) => {
clearInput();
var rl = response.data[0].roles
var arry = "";
rl.forEach((i) => {
// gruba gore olustur
var isExistsGroup = $('#roleList optgroup[data-parent="' + i.group_name + '"]');
if (isExistsGroup.length > 0) {
isExistsGroup.append(`<option value="${i.role_id}"> ${i.display_name}</option>`)
}
else {
var op = `<optgroup data-parent="${i.group_name}" label="${i.group_display_name}">`;
op += `<option data-group="${i.group_name}" data-group-name="${i.group_display_name}" value="${i.role_id}">${i.display_name}</option>`;
op += `</optgroup>`;
$('#roleList').append(op);
}

//arry += `<option value="${i.role_id}"> ${i.display_name}</option>`;
$('#roleDefination option[value="' + i.role_id + '"]').remove();
});
if (response.status) {
$('#RoleId').val(response.data[0].role_group_id);
$('#rolGrupAdi').val(response.data[0].name);
$('#ekranAdi').val(response.data[0].display_name);
$('#rolAciklama').val(response.data[0].description);
//$('#roleList').html(arry);

}
}
)



}



/// ===> Rol Grubu Silme <=== ///
deleteItem = (_id) => {
//**swalQuestion fonksiyonun beklediği ilk parametre result confirm callback'i ,ikinci olarak text:bkz:helper.js */
swalQuestion(() => {
showSwal("Lütfen Bekleyiniz...");
var _data = { "role_group_id": _id }
getData("POST","users/role-group-remove",_data,
(response) => {
if (response.status) {
getRoleList();
}
closeSwal();
}
);
}, "");
};


/// ===> Rol Tanımları Ekle Çıkar Butonları <=== ///
$('#roleAddList').click(() => {
const select = $('#roleDefination option:selected');
if ($(select.target).is('optgroup'))
{
$.each(select, function (x, v) {

var si = $(v);
var i = si.data();

// gruba gore olustur
var isExistsGroup = $('#roleList optgroup[data-parent="' + i.group + '"]');
if (isExistsGroup.length > 0) {
isExistsGroup.append(v)
}
else {
var op = `<optgroup data-parent="${i.group}" data-group-name="${i.groupName}" label="${i.groupName}">`;
op += v;
op += `</optgroup>`;
$('#roleList').append(op);
}

if ($('#roleList optgroup[data-parent="' + i.group + '"]').children().length == 0)
$('#roleList').children().remove('optgroup[data-parent="' + i.group + '"]');
});
}else{

let select = $('#roleDefination option:selected');

var si = select;
var i = si.data();

// gruba gore olustur
var isExistsGroup = $('#roleList optgroup[data-parent="' + i.group + '"]');
if (isExistsGroup.length > 0) {
isExistsGroup.append(select)
}
else {
var op = `<optgroup data-parent="${i.group}" data-group-name="${i.groupName}" label="${i.groupName}"></optgroup>`;
$('#roleList').append(op);
isExistsGroup = $('#roleList optgroup[data-parent="' + i.group + '"]');
isExistsGroup.append(select);
}


$('#roleDefination').find(si).remove();
if ($('#roleDefination optgroup[data-parent="' + i.group + '"]').children().length == 0)
$('#roleDefination').children().remove('optgroup[data-parent="' + i.group + '"]');
}



$('#roleDefination').find(select).remove();
});

$('#roleRemoveList').click(() => {
const select = $('#roleList option:selected');
if ($(select.target).is('optgroup'))
{

$.each(select, function (x, v) {
var si = $(v);
var i = si.data();

// gruba gore olustur
var isExistsGroup = $('#roleDefination optgroup[data-parent="' + i.group + '"]');
if (isExistsGroup.length > 0) {
isExistsGroup.append(v)
}
else {
var op = `<optgroup data-parent="${i.group}" data-group-name="${i.groupName}" label="${i.groupName}">`;
op += v;
op += `</optgroup>`;
$('#roleDefination').append(op);
}
if ($('#roleList optgroup[data-parent="' + i.group + '"]').children().length == 0)
$('#roleList').children().remove('optgroup[data-parent="' + i.group + '"]');
});
}else{
const select = $('#roleList option:selected');
var si = select;
var i = si.data();

// gruba gore olustur
var isExistsGroup = $('#roleDefination optgroup[data-parent="' + i.group + '"]');
if (isExistsGroup.length > 0) {
isExistsGroup.append(select);
}
else {
var op = `<optgroup data-parent="${i.group}" data-group-name="${i.groupName}" label="${i.groupName}"></optgroup>`;
$('#roleDefination').append(op);
isExistsGroup = $('#roleDefination optgroup[data-parent="' + i.group + '"]');
isExistsGroup.append(select);
}
$('#roleList').find(select).remove();
if ($('#roleList optgroup[data-parent="' + i.group + '"]').children().length == 0)
$('#roleList').children().remove('optgroup[data-parent="' + i.group + '"]');
}

$('#roleList').find(select).remove();
});

/// ===> Rol Tanımları Ekle Çıkar Çift Tıklama <=== ///
$('#roleDefination').dblclick((e) => {
if ($(e.target).is('optgroup'))
{
// return true;
var sgroup = $(e.target).children()
sgroup.each((a)=>{
var si = $(sgroup[a]);
var i = si.data();

// gruba gore olustur
var isExistsGroup = $('#roleList optgroup[data-parent="' + i.group + '"]');
if (isExistsGroup.length > 0) {
isExistsGroup.append(sgroup)
}
else {
var op = `<optgroup data-parent="${i.group}" data-group-name="${i.groupName}" label="${i.groupName}"></optgroup>`;
$('#roleList').append(op);
isExistsGroup = $('#roleList optgroup[data-parent="' + i.group + '"]');
isExistsGroup.append(sgroup);
}
$('#roleDefination').find(si).remove();
if ($('#roleDefination optgroup[data-parent="' + i.group + '"]').children().length == 0)
$('#roleDefination').children().remove('optgroup[data-parent="' + i.group + '"]');

})


}else{

var select = $('#roleDefination option:selected');

var si = select;
var i = si.data();

// gruba gore olustur
var isExistsGroup = $('#roleList optgroup[data-parent="' + i.group + '"]');
if (isExistsGroup.length > 0) {
isExistsGroup.append(select)
}
else {
var op = `<optgroup data-parent="${i.group}" data-group-name="${i.groupName}" label="${i.groupName}"></optgroup>`;
$('#roleList').append(op);
isExistsGroup = $('#roleList optgroup[data-parent="' + i.group + '"]');
isExistsGroup.append(select);
}


$('#roleDefination').find(si).remove();
if ($('#roleDefination optgroup[data-parent="' + i.group + '"]').children().length == 0)
$('#roleDefination').children().remove('optgroup[data-parent="' + i.group + '"]');
}
});

$('#roleList').dblclick((e) => {
if ($(e.target).is('optgroup'))
{
// return true;
var sgroup = $(e.target).children()
sgroup.each((a)=>{
var si = $(sgroup[a]);
var i = si.data();

// gruba gore olustur
var isExistsGroup = $('#roleDefination optgroup[data-parent="' + i.group + '"]');
if (isExistsGroup.length > 0) {
isExistsGroup.append(sgroup)
}
else {
var op = `<optgroup data-parent="${i.group}" data-group-name="${i.groupName}" label="${i.groupName}"></optgroup>`;
$('#roleDefination').append(op);
isExistsGroup = $('#roleDefination optgroup[data-parent="' + i.group + '"]');
isExistsGroup.append(sgroup);
}
$('#roleList').find(si).remove();
if ($('#roleList optgroup[data-parent="' + i.group + '"]').children().length == 0)
$('#roleList').children().remove('optgroup[data-parent="' + i.group + '"]');

})


}
else{
const select = $('#roleList option:selected');
var si = select;
var i = si.data();

// gruba gore olustur
var isExistsGroup = $('#roleDefination optgroup[data-parent="' + i.group + '"]');
if (isExistsGroup.length > 0) {
isExistsGroup.append(select);
}
else {
var op = `<optgroup data-parent="${i.group}" data-group-name="${i.groupName}" label="${i.groupName}"></optgroup>`;
$('#roleDefination').append(op);
isExistsGroup = $('#roleDefination optgroup[data-parent="' + i.group + '"]');
isExistsGroup.append(select);
}
$('#roleList').find(select).remove();
if ($('#roleList optgroup[data-parent="' + i.group + '"]').children().length == 0)
$('#roleList').children().remove('optgroup[data-parent="' + i.group + '"]');
}




});



$('#btnCreateRoles').click(() => {
showSwal('Lütfen bekleyin...');
getData('POST','users/create-roles/','',(response) => {
if (response.status) {
getYetkiList();
closeSwal();
}
}
)

});

// -------Yetkiler --------- //
// ===> Yetki Alanı Listesi <=== //
getYetkiList = () => {
var rows = "";
showSwal('Yükleniyor...');
getData('GET','users/roles-get',{},(response) => {
if (response.status) {
response.data.forEach((data) => {
rows += `
<tr class="odd gradeX">
<td>${data.group_display_name}</td>
<td>${data.description ?? '---'}</td>
<td class='align-middle text-center'>
<button title='Düzenle' class='btn btn-outline-warning btn-color-edit standard-button' id='guncellebutton' onclick="getYetkiFromId('${data.role_id}')"> <i class='fas fa-edit'></i> </button>
</td>
</tr>
`;

})
$("#dtTable2").DataTable().destroy();
$('#dtBody2').html(rows);
setTableSearch('dtTable2');
closeSwal();
}
}
)
}

/// ===> Yetki Düzenle Butonunun Çağırdığı Fonk. <=== ///
getYetkiFromId = (id) => {
clearInput();
$('#KullaniciYetkiModal').modal('show');
$('#btnSaveYetki').hide();
$('#btnUpdateYetki').show();
getData('GET',`users/role-update/${id}`,'',(response) => {
clearInput();
if (response.status) {
$('#yetkiId').val(response.data[0].role_id);
$('#yetkiAdi').val(response.data[0].display_name);
$('#yetkiAciklama').val(response.data[0].description);
}
}
)
}

/// ===> Yetki Alanı Güncelleme <=== ///
updateYetki = () => {
showSwal('Yükleniyor');
var id = $('#yetkiId').val();
var ekran = $('#yetkiAdi').val();
var aciklama = $('#yetkiAciklama').val();
_data = {
"role_id": id,
"display_name": ekran
}
if (aciklama.length > 0) {
_data['description'] = aciklama;
}

getData('POST','users/role-update',_data,function (response) {
if (response.status) {
$('#KullaniciYetkiModal').modal('hide');
Swal.fire('Başarılı', response.message, 'success');
setTimeout(() => {
getYetkiList();
}, 1000);
clearInput();
closeSwal();
}
}
)
}

/// ===> Inputları Temizleme <=== ///
clearInput = () => {
$('#RoleId, #rolGrupAdi, #ekranAdi, #rolAciklama, #roleDefination, #roleList').val("");
$('#yetkiId, #yetkiAlani, #yetkiAdi, #yetkiAciklama').val("");
$('#roleList').html("");

}


/// ===> DataTable Oluşturma <=== ///
function setDatatable(tblName, exportExcel = false) {

$('#' + tblName + ' tfoot th').each(function () {
var title = $('#' + tblName + ' thead th').eq($(this).index()).text();
$(this).html('<input type="text" placeholder="Ara ' + '" />');
});


// eger export islemlerinde, gosterilmesi istenmeyen ([data-hidden="true"] arar) sutunlar varsa bul
let datatableOption = $('#' + tblName).find('thead > tr:first > th');
var showColumn = [];
datatableOption.each(function (i, d) {
if (!$(this).data().hidden)
showColumn.push(i);
});

// gosterilmesi istenen buttonları olustur
var exportButtons = [];
if (exportExcel) {
exportButtons.push({
pagining: true,
extend: 'excelHtml5',
exportOptions: { columns: showColumn },
text: '<i class="far fa-file-excel mr-1"></i>Excel'e Aktar',
className: 'btn btn-outline-success'
});
}

var table = $('#' + tblName).DataTable({
"columnDefs": [
{ "visible": false, "targets": 0 }
],
"pageLength": 50,
"ordering": true,
"retrieve": true,
"destroy": true,
"deferRender": false,
"dom": 'Bfrtip',
"order": [],
"buttons": exportButtons,
"search": {
"caseInsensitive": false
},
"drawCallback": function ( settings ) {
var api = this.api();
var rows = api.rows( {page:'current'} ).nodes();
var last=null;

api.column(0, {page:'current'} ).data().each( function ( group, i ) {
if ( last !== group ) {
$(rows).eq( i ).before(
'<tr class="group"><td colspan=4" class="role-groups">'+group+'</td></tr>'
);

last = group;
}
} );
}
});
table.columns().every(function () {
var that = this;
$('input', this.footer()).on('keyup change', function () {
that
.search(this.value)
.draw();
});
});
$('#' + tblName + '_filter').css("display", "none");



}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.