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,19 +279,28 @@ 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 ()
{
this.selectors.state.select2();
this.selectors.cities.select2();
if(this.selectors.state!=null){
this.selectors.state.select2();
}
if(this.selectors.cities!=null){
this.selectors.cities.select2();
}
}
},
......
......@@ -68,80 +68,96 @@
{{-- For DataTables --}}
{{ Html::script(mix('js/dataTable.js')) }}
<script>
$(function() {
var dataTable = $('#users-table').dataTable({
processing: true,
serverSide: true,
ajax: {
url: '{{ route("admin.access.user.get") }}',
type: 'post',
data: {status: false, trashed: true}
},
columns: [
{data: 'first_name', name: '{{config('access.users_table')}}.first_name'},
{data: 'last_name', name: '{{config('access.users_table')}}.last_name'},
{data: 'email', name: '{{config('access.users_table')}}.email'},
{data: 'confirmed', name: '{{config('access.users_table')}}.confirmed'},
{data: 'roles', name: '{{config('access.roles_table')}}.name', sortable: false},
{data: 'created_at', name: '{{config('access.users_table')}}.created_at'},
{data: 'updated_at', name: '{{config('access.users_table')}}.updated_at'},
{data: 'actions', name: 'actions', searchable: false, sortable: false}
],
order: [[0, "asc"]],
searchDelay: 500,
dom: 'lBfrtip',
buttons: {
buttons: [
{ extend: 'copy', className: 'copyButton', exportOptions: {columns: [ 0, 1, 2, 3, 4, 5, 6 ] }},
{ extend: 'csv', className: 'csvButton', exportOptions: {columns: [ 0, 1, 2, 3, 4, 5, 6 ] }},
{ extend: 'excel', className: 'excelButton', exportOptions: {columns: [ 0, 1, 2, 3, 4, 5, 6 ] }},
{ extend: 'pdf', className: 'pdfButton', exportOptions: {columns: [ 0, 1, 2, 3, 4, 5, 6 ] }},
{ extend: 'print', className: 'printButton', exportOptions: {columns: [ 0, 1, 2, 3, 4, 5, 6 ] }}
]
}
});
Backend.DataTableSearch.init(dataTable);
$("body").on("click", "a[name='delete_user_perm']", function(e) {
e.preventDefault();
var linkURL = $(this).attr("href");
swal({
title: "{{ trans('strings.backend.general.are_you_sure') }}",
text: "{{ trans('strings.backend.access.users.delete_user_confirm') }}",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "{{ trans('strings.backend.general.continue') }}",
cancelButtonText: "{{ trans('buttons.general.cancel') }}",
closeOnConfirm: false
}, function(isConfirmed){
if (isConfirmed){
window.location.href = linkURL;
(function () {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
});
$("body").on("click", "a[name='restore_user']", function(e) {
e.preventDefault();
var linkURL = $(this).attr("href");
swal({
title: "{{ trans('strings.backend.general.are_you_sure') }}",
text: "{{ trans('strings.backend.access.users.restore_user_confirm') }}",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "{{ trans('strings.backend.general.continue') }}",
cancelButtonText: "{{ trans('buttons.general.cancel') }}",
closeOnConfirm: false
}, function(isConfirmed){
if (isConfirmed){
window.location.href = linkURL;
var dataTable = $('#users-table').dataTable({
processing: true,
serverSide: true,
ajax: {
url: '{{ route("admin.access.user.get") }}',
type: 'post',
data: {status: false, trashed: true}
},
columns: [
{data: 'first_name', name: '{{config('access.users_table')}}.first_name'},
{data: 'last_name', name: '{{config('access.users_table')}}.last_name'},
{data: 'email', name: '{{config('access.users_table')}}.email'},
{data: 'confirmed', name: '{{config('access.users_table')}}.confirmed'},
{data: 'roles', name: '{{config('access.roles_table')}}.name', sortable: false},
{data: 'created_at', name: '{{config('access.users_table')}}.created_at'},
{data: 'updated_at', name: '{{config('access.users_table')}}.updated_at'},
{data: 'actions', name: 'actions', searchable: false, sortable: false}
],
order: [[0, "asc"]],
searchDelay: 500,
dom: 'lBfrtip',
buttons: {
buttons: [
{ extend: 'copy', className: 'copyButton', exportOptions: {columns: [ 0, 1, 2, 3, 4, 5, 6 ] }},
{ extend: 'csv', className: 'csvButton', exportOptions: {columns: [ 0, 1, 2, 3, 4, 5, 6 ] }},
{ extend: 'excel', className: 'excelButton', exportOptions: {columns: [ 0, 1, 2, 3, 4, 5, 6 ] }},
{ extend: 'pdf', className: 'pdfButton', exportOptions: {columns: [ 0, 1, 2, 3, 4, 5, 6 ] }},
{ extend: 'print', className: 'printButton', exportOptions: {columns: [ 0, 1, 2, 3, 4, 5, 6 ] }}
]
}
});
});
});
Backend.DataTableSearch.init(dataTable);
})();
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') }}",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "{{ trans('strings.backend.general.continue') }}",
cancelButtonText: "{{ trans('buttons.general.cancel') }}",
closeOnConfirm: false
}, function(isConfirmed){
if (isConfirmed){
window.location.href = linkURL;
}
});
}
})
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') }}",
text: "{{ trans('strings.backend.access.users.restore_user_confirm') }}",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "{{ trans('strings.backend.general.continue') }}",
cancelButtonText: "{{ trans('buttons.general.cancel') }}",
closeOnConfirm: false
}, function(isConfirmed){
if (isConfirmed){
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