Commit 0241a481 authored by cygnet's avatar cygnet

changes done for deleted user and edit user page to convert them in javascript

parent 97c1c00f
......@@ -279,20 +279,29 @@ var Backend = {}; // common variable used in all the files of the backend
*/
Profile:
{
selectors:{
},
init: function ()
{
this.setSelectors();
this.addHandlers();
},
setSelectors:function(){
this.selectors.state = document.querySelector(".st");
this.selectors.cities = document.querySelector(".ct");
},
addHandlers: function ()
{
if(this.selectors.state!=null){
this.selectors.state.select2();
}
if(this.selectors.cities!=null){
this.selectors.cities.select2();
}
}
},
/**
......
......@@ -68,7 +68,13 @@
{{-- For DataTables --}}
{{ Html::script(mix('js/dataTable.js')) }}
<script>
$(function() {
(function () {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var dataTable = $('#users-table').dataTable({
processing: true,
serverSide: true,
......@@ -103,10 +109,16 @@
Backend.DataTableSearch.init(dataTable);
$("body").on("click", "a[name='delete_user_perm']", function(e) {
e.preventDefault();
var linkURL = $(this).attr("href");
})();
window.onload = function(){
document.querySelectorAll("a[name='delete_user_perm']").forEach(function(element){
element.onclick = function(event){
event.preventDefault();
var linkURL = event.target.getAttribute("href");
swal({
title: "{{ trans('strings.backend.general.are_you_sure') }}",
text: "{{ trans('strings.backend.access.users.delete_user_confirm') }}",
......@@ -121,11 +133,13 @@
window.location.href = linkURL;
}
});
});
}
})
$("body").on("click", "a[name='restore_user']", function(e) {
e.preventDefault();
var linkURL = $(this).attr("href");
document.querySelectorAll("a[name='restore_user']").forEach(function(element){
element.onclick = function(event){
event.preventDefault();
var linkURL = event.target.getAttribute("href");
swal({
title: "{{ trans('strings.backend.general.are_you_sure') }}",
......@@ -141,7 +155,9 @@
window.location.href = linkURL;
}
});
});
});
}
})
};
</script>
@endsection
......@@ -167,12 +167,15 @@
{{ Html::script('js/backend/access/users/script.js') }}
<script type="text/javascript">
/*
jQuery(document).ready(function() {
Backend.Access.init();
/**
* This function is used to get clicked element role id and return required result
*/
jQuery('.get-role-for-permissions').click(function () {
/* jQuery('.get-role-for-permissions').click(function () {
$.ajax({
type: "POST",
url: "{{ route('admin.get.permission') }}",
......@@ -205,5 +208,67 @@
});
});
*/
Backend.Utils.documentReady(function(){
Backend.Access.init();
csrf = $('meta[name="csrf-token"]').attr('content');
/**
* This function is used to get clicked element role id and return required result
*/
document.querySelectorAll(".get-role-for-permissions").forEach(function(element){
element.onclick =function(event){
callback = {
success:function(request){
console.log("request",request,request.status);
if (request.status >= 200 && request.status < 400) {
// Success!
var response = JSON.parse(request.responseText);
var p = response.permissions;
var q = response.rolePermissions;
var qAll = response.allPermissions;
document.querySelector(".get-available-permissions").innerHTML = "";
htmlstring = "";
if (p.length == 0) {
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>';
} else {
for (var key in p) {
var addChecked = '';
if (qAll == 1 && q.length == 0) {
addChecked = 'checked="checked"';
} else {
if (typeof q[key] !== "undefined") {
addChecked = 'checked="checked"';
}
}
htmlstring += '<label class="control control--checkbox"> <input type="checkbox" name="permissions[' + key + ']" value="' + key + '" id="perm_' + key + '" ' + addChecked + ' /> <label for="perm_' + key + '">' + p[key] + '</label> <div class="control__indicator"></div> </label> <br>';
}
}
document.querySelector(".get-available-permissions").innerHTML = htmlstring;
Backend.Utils.removeClass(document.getElementById("available-permissions"),'hidden');
} else {
// We reached our target server, but it returned an error
console.log("errror in request");
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>';
}
},
error:function(){
console.log("errror");
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>';
}
};
Backend.Utils.ajaxrequest("{{ route('admin.get.permission') }}","post",{role_id: event.target.value ,"_tocken":csrf},csrf,callback);
}
});
});
</script>
@endsection
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment