Skip to content

Commit

Permalink
Added permission_url_prefix helper and use it on custom.js and User.vue
Browse files Browse the repository at this point in the history
  • Loading branch information
maab16 committed Sep 11, 2019
1 parent 97891e6 commit 78bb94c
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 94 deletions.
2 changes: 1 addition & 1 deletion config/permission.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
'prefix' => 'admin',
'prefix' => '/admin',
'namespace' => '\CodexShaper\Permission',
'controller_namespace' => '\CodexShaper\Permission\Http\Controllers',
'models' => [
Expand Down
73 changes: 42 additions & 31 deletions resources/assets/dashboard/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,7 @@ __webpack_require__.r(__webpack_exports__);
//
//
/* harmony default export */ __webpack_exports__["default"] = ({
props: ['addAction', 'editAction'],
props: ['addAction', 'editAction', 'prefix'],
data: function data() {
return {
users: [],
Expand All @@ -2060,7 +2060,8 @@ __webpack_require__.r(__webpack_exports__);
var _this = this;

var parent = this;
fetch('/admin/users/all').then(function (res) {
var url = this.prefix + '/users/all';
fetch(url).then(function (res) {
return res.json();
}).then(function (res) {
_this.destroyDataTables();
Expand All @@ -2075,7 +2076,8 @@ __webpack_require__.r(__webpack_exports__);
fetchRoles: function fetchRoles() {
var _this2 = this;

fetch('/admin/roles/all').then(function (res) {
var url = this.prefix + '/roles/all';
fetch(url).then(function (res) {
return res.json();
}).then(function (res) {
_this2.destroyDataTables();
Expand All @@ -2085,6 +2087,9 @@ __webpack_require__.r(__webpack_exports__);
return console.log(err);
});
},
showAddUserModal: function showAddUserModal(event) {
this.resetForm();
},
addUser: function addUser(event) {
var self = this;
axios({
Expand All @@ -2101,14 +2106,15 @@ __webpack_require__.r(__webpack_exports__);
editUser: function editUser(event) {
var id = event.target.getAttribute('data-id');
var self = this;
var url = this.prefix + '/user/' + id;
axios({
method: 'get',
url: '/admin/user/edit/' + id,
url: url,
responseType: 'json'
}).then(function (response) {
// console.log( response.data );
self.user = response.data.user;
self.user.checkedRoles = response.data.userRoles;
self.user.checkedRoles = response.data.checkedRoles;
});
},
updateUser: function updateUser(event) {
Expand All @@ -2127,9 +2133,10 @@ __webpack_require__.r(__webpack_exports__);
viewUser: function viewUser(event) {
var id = event.target.getAttribute('data-id');
var parent = this;
var url = this.prefix + '/user/' + id;
axios({
method: 'get',
url: '/admin/user/' + id,
url: url,
responseType: 'json'
}).then(function (response) {
// console.log( response.data );
Expand All @@ -2138,6 +2145,8 @@ __webpack_require__.r(__webpack_exports__);
});
},
deleteUser: function deleteUser(event) {
var _this3 = this;

event.preventDefault();
var id = event.target.getAttribute('data-id');
var self = this;
Expand All @@ -2150,9 +2159,10 @@ __webpack_require__.r(__webpack_exports__);
cancelButtonText: 'No, keep it'
}).then(function (result) {
if (result.value) {
var url = _this3.prefix + '/user/' + id;
axios({
method: 'delete',
url: '/admin/user/delete/' + id
url: url
}).then(function (response) {
// console.log( response.data );
// self.resetForm();
Expand Down Expand Up @@ -40454,7 +40464,27 @@ var render = function() {
var _c = _vm._self._c || _h
return _c("div", { staticClass: "users-container" }, [
_c("div", { staticClass: "card shadow mb-4" }, [
_vm._m(0),
_c("div", { staticClass: "card-header py-3" }, [
_c("h6", { staticClass: "m-0 font-weight-bold text-primary" }, [
_c(
"a",
{
staticClass: "btn btn-success btn-icon-split",
attrs: {
href: "#",
"data-toggle": "modal",
"data-target": "#addUserModal"
},
on: { click: _vm.showAddUserModal }
},
[
_vm._m(0),
_vm._v(" "),
_c("span", { staticClass: "text" }, [_vm._v("Add User")])
]
)
])
]),
_vm._v(" "),
_c("div", { staticClass: "card-body" }, [
_c("div", { staticClass: "table-responsive" }, [
Expand Down Expand Up @@ -41146,27 +41176,8 @@ var staticRenderFns = [
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c("div", { staticClass: "card-header py-3" }, [
_c("h6", { staticClass: "m-0 font-weight-bold text-primary" }, [
_c(
"a",
{
staticClass: "btn btn-success btn-icon-split",
attrs: {
href: "#",
"data-toggle": "modal",
"data-target": "#addUserModal"
}
},
[
_c("span", { staticClass: "icon text-white-50" }, [
_c("i", { staticClass: "fas fa-plus" })
]),
_vm._v(" "),
_c("span", { staticClass: "text" }, [_vm._v("Add User")])
]
)
])
return _c("span", { staticClass: "icon text-white-50" }, [
_c("i", { staticClass: "fas fa-plus" })
])
},
function() {
Expand Down Expand Up @@ -53697,8 +53708,8 @@ __webpack_require__.r(__webpack_exports__);
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! G:\laravel\dashboard\packages\package\laravel-permission\resources\assets\js\app.js */"./resources/assets/js/app.js");
module.exports = __webpack_require__(/*! G:\laravel\dashboard\packages\package\laravel-permission\resources\assets\sass\app.scss */"./resources/assets/sass/app.scss");
__webpack_require__(/*! G:\laravel\packages\package\laravel-permission\resources\assets\js\app.js */"./resources/assets/js/app.js");
module.exports = __webpack_require__(/*! G:\laravel\packages\package\laravel-permission\resources\assets\sass\app.scss */"./resources/assets/sass/app.scss");


/***/ })
Expand Down
50 changes: 25 additions & 25 deletions resources/assets/dashboard/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
if( result.success == true ) {

var viewBtn = '<a href="#" class="view_role btn btn-warning" title="View" data-id="'+result.role.id+'" data-toggle="modal" data-target="#viewRoleModal">View</a> ';
var editBtn = '<a href="#" class="edit_role btn btn-info" data-id="'+result.role.id+'" data-action="/admin/role/'+result.role.id+'" title="Edit" data-toggle="modal" data-target="#editRoleModal">Edit</a> ';
var editBtn = '<a href="#" class="edit_role btn btn-info" data-id="'+result.role.id+'" data-action="'+permission_prefix+'/role/'+result.role.id+'" title="Edit" data-toggle="modal" data-target="#editRoleModal">Edit</a> ';
var deleteBtn = '<a href="#" class="delete_role btn btn-danger" title="Delete" data-id="'+result.role.id+'">Delete</a> ';

$('#role_table').DataTable().row.add([
Expand All @@ -36,7 +36,7 @@
}
},
error: function(err){
console.log( err );
// console.log( err );
}
});
});
Expand All @@ -48,7 +48,7 @@
// var action = $(this).data('action');

$.ajax({
url: '/admin/role/'+id,
url: permission_prefix+'/role/'+id,
method: 'GET',
dataType: 'json',
data: {
Expand Down Expand Up @@ -76,7 +76,7 @@
}
},
error: function( err ){
console.log(err);
// console.log(err);
}
});
});
Expand All @@ -95,7 +95,7 @@
'id' : id
},
success: function(result){
console.log( result );
// console.log( result );
if( result.success == true ){
document.getElementById("edit_role_form").reset();
var form = $('#edit_role_form');
Expand All @@ -119,7 +119,7 @@
}
},
error: function( err ){
console.log(err);
// console.log(err);
}
});
});
Expand Down Expand Up @@ -147,7 +147,7 @@
var row_id = $('#row_'+result.role.id).data("row");

var viewBtn = '<a href="#" class="view_role btn btn-warning" title="View" data-id="'+result.role.id+'" data-toggle="modal" data-target="#viewRoleModal">View</a> ';
var editBtn = '<a href="#" class="edit_role btn btn-info" data-id="'+result.role.id+'" data-action="/admin/role/'+result.role.id+'" title="Edit" data-toggle="modal" data-target="#editRoleModal">Edit</a> ';
var editBtn = '<a href="#" class="edit_role btn btn-info" data-id="'+result.role.id+'" data-action="'+permission_prefix+'/role/'+result.role.id+'" title="Edit" data-toggle="modal" data-target="#editRoleModal">Edit</a> ';
var deleteBtn = '<a href="#" class="delete_role btn btn-danger" title="Delete" data-id="'+result.role.id+'">Delete</a> ';

$('#role_table').DataTable().row(row_id).data([
Expand All @@ -162,7 +162,7 @@
}
},
error: function( err ) {
console.log( err );
// console.log( err );
}
});
});
Expand All @@ -179,7 +179,7 @@
}).then((result) => {
if (result.value) {
$.ajax({
url: '/admin/role/delete',
url: permission_prefix+'/role',
method: 'POST',
dataType: 'json',
data: {
Expand All @@ -188,7 +188,7 @@
'role_id': $(this).data('id'),
},
success: function(result){
console.log( result );
// console.log( result );
if( result.success == true ) {
// console.log( data );
Swal.fire(
Expand All @@ -207,7 +207,7 @@
}
},
error: function(err){
console.log( err );
// console.log( err );
}
});
} else if (result.dismiss === Swal.DismissReason.cancel) {
Expand Down Expand Up @@ -242,11 +242,11 @@
cache: false,
processData: false,
success: function(result){
console.log( result );
// console.log( result );
if( result.success == true ) {

var viewBtn = '<a href="#" class="view_permission btn btn-warning" title="View" data-id="'+result.permission.id+'" data-toggle="modal" data-target="#viewPermissionModal">View</a> ';
var editBtn = '<a href="#" class="edit_permission btn btn-info" data-id="'+result.permission.id+'" data-action="/admin/permission/'+result.permission.id+'" title="Edit" data-toggle="modal" data-target="#editPermissionModal">Edit</a> ';
var editBtn = '<a href="#" class="edit_permission btn btn-info" data-id="'+result.permission.id+'" data-action="'+permission_prefix+'/permission/'+result.permission.id+'" title="Edit" data-toggle="modal" data-target="#editPermissionModal">Edit</a> ';
var deleteBtn = '<a href="#" class="delete_permission btn btn-danger" title="Delete" data-id="'+result.permission.id+'">Delete</a> ';

$('#permission_table').DataTable().row.add([
Expand All @@ -261,7 +261,7 @@
}
},
error: function(err){
console.log( err );
// console.log( err );
}
});
});
Expand All @@ -273,14 +273,14 @@
// var action = $(this).data('action');

$.ajax({
url: '/admin/permission/'+id,
url: permission_prefix+'/permission/'+id,
method: 'GET',
dataType: 'json',
data: {
'id' : id
},
success: function(result){
console.log( result );
// console.log( result );
if( result.success == true ){
var form = $('#edit_permission_form');
$("#permission_id").val(id);
Expand All @@ -291,7 +291,7 @@
}
},
error: function( err ){
console.log(err);
// console.log(err);
}
});
});
Expand All @@ -310,7 +310,7 @@
'id' : id
},
success: function(result){
console.log( result );
// console.log( result );
if( result.success == true ){

document.getElementById("edit_permission_form").reset();
Expand All @@ -335,7 +335,7 @@
}
},
error: function( err ){
console.log(err);
// console.log(err);
}
});
});
Expand All @@ -358,12 +358,12 @@
cache: false,
processData: false,
success: function( result ){
console.log( result );
// console.log( result );
if( result.success == true ) {
var row_id = $('#row_'+result.permission.id).data("row");

var viewBtn = '<a href="#" class="view_permission btn btn-warning" title="View" data-id="'+result.permission.id+'" data-toggle="modal" data-target="#viewPermissionModal">View</a> ';
var editBtn = '<a href="#" class="edit_permission btn btn-info" data-id="'+result.permission.id+'" data-action="/admin/permission/'+result.permission.id+'" title="Edit" data-toggle="modal" data-target="#editPermissionModal">Edit</a> ';
var editBtn = '<a href="#" class="edit_permission btn btn-info" data-id="'+result.permission.id+'" data-action="'+permission_prefix+'/permission/'+result.permission.id+'" title="Edit" data-toggle="modal" data-target="#editPermissionModal">Edit</a> ';
var deleteBtn = '<a href="#" class="delete_permission btn btn-danger" title="Delete" data-id="'+result.permission.id+'">Delete</a> ';

$('#permission_table').DataTable().row(row_id).data([
Expand All @@ -378,7 +378,7 @@
}
},
error: function( err ) {
console.log( err );
// console.log( err );
}
});
});
Expand All @@ -395,7 +395,7 @@
}).then((result) => {
if (result.value) {
$.ajax({
url: '/admin/permission/delete',
url: permission_prefix+'/permission',
method: 'POST',
dataType: 'json',
data: {
Expand All @@ -404,7 +404,7 @@
'permission_id': $(this).data('id'),
},
success: function(result){
console.log( result );
// console.log( result );
if( result.success == true ) {
// console.log( data );
Swal.fire(
Expand All @@ -423,7 +423,7 @@
}
},
error: function(err){
console.log( err );
// console.log( err );
}
});
} else if (result.dismiss === Swal.DismissReason.cancel) {
Expand Down
Loading

0 comments on commit 78bb94c

Please sign in to comment.