|
|
@ -27,6 +27,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
stateCreate: [], |
|
|
|
stateCreate: [], |
|
|
|
stateUpdate: [], |
|
|
|
stateUpdate: [], |
|
|
|
stateDelete: [], |
|
|
|
stateDelete: [], |
|
|
|
|
|
|
|
role_name: props.role_name || '', |
|
|
|
stateReadAll: false, |
|
|
|
stateReadAll: false, |
|
|
|
stateCreateAll: false, |
|
|
|
stateCreateAll: false, |
|
|
|
stateUpdateAll: false, |
|
|
|
stateUpdateAll: false, |
|
|
@ -35,10 +36,12 @@ export default class DialogMenuRoles extends Component { |
|
|
|
company_id: props.company_id || null, |
|
|
|
company_id: props.company_id || null, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async componentDidMount() { |
|
|
|
async componentDidMount() { |
|
|
|
this.props.showDialog(this.showDialog); |
|
|
|
this.props.showDialog(this.showDialog); |
|
|
|
this.getAllMenu(); |
|
|
|
this.getAllMenu(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async componentDidUpdate() { |
|
|
|
async componentDidUpdate() { |
|
|
|
if (this.state.isParentClick === true) { |
|
|
|
if (this.state.isParentClick === true) { |
|
|
|
const { idRoles } = this.props |
|
|
|
const { idRoles } = this.props |
|
|
@ -50,21 +53,26 @@ export default class DialogMenuRoles extends Component { |
|
|
|
this.setState({ isParentClick: false, id: idRoles }); |
|
|
|
this.setState({ isParentClick: false, id: idRoles }); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
showDialog = () => { |
|
|
|
showDialog = () => { |
|
|
|
this.setState({ isParentClick: true }); |
|
|
|
this.setState({ isParentClick: true }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getAllMenu = async () => { |
|
|
|
getAllMenu = async () => { |
|
|
|
const payload = { |
|
|
|
const payload = { |
|
|
|
"paging": { "start": 0, "length": -1 }, |
|
|
|
"paging": { "start": 0, "length": -1 }, |
|
|
|
"columns": [ |
|
|
|
"columns": [], |
|
|
|
{ "name": "company_id", "logic_operator": "=", "value": this.state.company_id, "operator": "AND" } |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"joins": [ |
|
|
|
"joins": [ |
|
|
|
{ "name": "t_roles_menu", "column_join": "menu_id", "column_results": ["create", "update", "delete", "read"] }, |
|
|
|
{ "name": "t_roles_menu", "column_join": "menu_id", "column_results": ["create", "update", "delete", "read"] }, |
|
|
|
{ "name": "m_menu", "column_join": "menu_id", "column_results": ["name"] } |
|
|
|
{ "name": "m_menu", "column_join": "menu_id", "column_results": ["name"] } |
|
|
|
], |
|
|
|
], |
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (this.state.role_name !== "Super Admin") { |
|
|
|
|
|
|
|
payload.columns.push( |
|
|
|
|
|
|
|
{ "name": "company_id", "logic_operator": "=", "value": this.state.company_id, "operator": "AND" } |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
const result = await axios |
|
|
|
const result = await axios |
|
|
|
.post(MENU_COMPANY_SEARCH, payload, config) |
|
|
|
.post(MENU_COMPANY_SEARCH, payload, config) |
|
|
|
.then(res => res) |
|
|
|
.then(res => res) |
|
|
@ -73,9 +81,9 @@ export default class DialogMenuRoles extends Component { |
|
|
|
this.setState({ menu: result.data.data }, () => { |
|
|
|
this.setState({ menu: result.data.data }, () => { |
|
|
|
this.setStateMenu(false); |
|
|
|
this.setStateMenu(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setStateMenu = edit => { |
|
|
|
setStateMenu = edit => { |
|
|
|
const stateMenu = []; |
|
|
|
const stateMenu = []; |
|
|
|
this.state.menu.map((val) => { |
|
|
|
this.state.menu.map((val) => { |
|
|
@ -89,6 +97,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setStateRead = edit => { |
|
|
|
setStateRead = edit => { |
|
|
|
const stateRead = []; |
|
|
|
const stateRead = []; |
|
|
|
this.state.menu.map((val) => { |
|
|
|
this.state.menu.map((val) => { |
|
|
@ -102,6 +111,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setStateCreate = edit => { |
|
|
|
setStateCreate = edit => { |
|
|
|
const stateCreate = []; |
|
|
|
const stateCreate = []; |
|
|
|
this.state.menu.map((val) => { |
|
|
|
this.state.menu.map((val) => { |
|
|
@ -115,6 +125,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setStateUpdate = edit => { |
|
|
|
setStateUpdate = edit => { |
|
|
|
const stateUpdate = []; |
|
|
|
const stateUpdate = []; |
|
|
|
this.state.menu.map((val) => { |
|
|
|
this.state.menu.map((val) => { |
|
|
@ -128,6 +139,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setStateDelete = edit => { |
|
|
|
setStateDelete = edit => { |
|
|
|
const stateDelete = []; |
|
|
|
const stateDelete = []; |
|
|
|
this.state.menu.map((val) => { |
|
|
|
this.state.menu.map((val) => { |
|
|
@ -141,6 +153,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
checkMenuRoles = () => { |
|
|
|
checkMenuRoles = () => { |
|
|
|
let copyStateMenu = [...this.state.stateMenu]; |
|
|
|
let copyStateMenu = [...this.state.stateMenu]; |
|
|
|
this.props.menuRoles.map((val, indexMenu) => { |
|
|
|
this.props.menuRoles.map((val, indexMenu) => { |
|
|
@ -158,6 +171,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
checkReadRoles = () => { |
|
|
|
checkReadRoles = () => { |
|
|
|
let copyStateRead = [...this.state.stateRead]; |
|
|
|
let copyStateRead = [...this.state.stateRead]; |
|
|
|
this.props.menuRoles.map((val) => { |
|
|
|
this.props.menuRoles.map((val) => { |
|
|
@ -177,6 +191,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
checkCreateRoles = () => { |
|
|
|
checkCreateRoles = () => { |
|
|
|
let copyStateCreate = [...this.state.stateCreate]; |
|
|
|
let copyStateCreate = [...this.state.stateCreate]; |
|
|
|
this.props.menuRoles.map((val) => { |
|
|
|
this.props.menuRoles.map((val) => { |
|
|
@ -196,6 +211,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
checkUpdateRoles = () => { |
|
|
|
checkUpdateRoles = () => { |
|
|
|
let copyStateUpdate = [...this.state.stateUpdate]; |
|
|
|
let copyStateUpdate = [...this.state.stateUpdate]; |
|
|
|
this.props.menuRoles.map((val) => { |
|
|
|
this.props.menuRoles.map((val) => { |
|
|
@ -215,6 +231,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
checkDeleteRoles = () => { |
|
|
|
checkDeleteRoles = () => { |
|
|
|
let copyStateDelete = [...this.state.stateDelete]; |
|
|
|
let copyStateDelete = [...this.state.stateDelete]; |
|
|
|
this.props.menuRoles.map((val) => { |
|
|
|
this.props.menuRoles.map((val) => { |
|
|
@ -234,26 +251,32 @@ export default class DialogMenuRoles extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getIndexDataMenu = (id) => { |
|
|
|
getIndexDataMenu = (id) => { |
|
|
|
let index = this.state.menu.findIndex(obj => obj.id === id); |
|
|
|
let index = this.state.menu.findIndex(obj => obj.id === id); |
|
|
|
return index |
|
|
|
return index |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getIndexDataCreate = (id) => { |
|
|
|
getIndexDataCreate = (id) => { |
|
|
|
let index = this.state.stateCreate.findIndex(obj => obj.id === id); |
|
|
|
let index = this.state.stateCreate.findIndex(obj => obj.id === id); |
|
|
|
return index |
|
|
|
return index |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getIndexDataDelete = (id) => { |
|
|
|
getIndexDataDelete = (id) => { |
|
|
|
let index = this.state.stateDelete.findIndex(obj => obj.id === id); |
|
|
|
let index = this.state.stateDelete.findIndex(obj => obj.id === id); |
|
|
|
return index |
|
|
|
return index |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getIndexDataRead = (id) => { |
|
|
|
getIndexDataRead = (id) => { |
|
|
|
let index = this.state.stateRead.findIndex(obj => obj.id === id); |
|
|
|
let index = this.state.stateRead.findIndex(obj => obj.id === id); |
|
|
|
return index |
|
|
|
return index |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getIndexDataUpdate = (id) => { |
|
|
|
getIndexDataUpdate = (id) => { |
|
|
|
let index = this.state.stateUpdate.findIndex(obj => obj.id === id); |
|
|
|
let index = this.state.stateUpdate.findIndex(obj => obj.id === id); |
|
|
|
return index |
|
|
|
return index |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleSave = () => { |
|
|
|
handleSave = () => { |
|
|
|
const { |
|
|
|
const { |
|
|
|
stateMenu, |
|
|
|
stateMenu, |
|
|
@ -280,14 +303,17 @@ export default class DialogMenuRoles extends Component { |
|
|
|
this.props.closeDialog('save', arrayData); |
|
|
|
this.props.closeDialog('save', arrayData); |
|
|
|
this.setState({ id: 0 }); |
|
|
|
this.setState({ id: 0 }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleCancel = () => { |
|
|
|
handleCancel = () => { |
|
|
|
this.props.closeDialog('cancel', 'none') |
|
|
|
this.props.closeDialog('cancel', 'none') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleChangeCheckbox = (checked, index) => { |
|
|
|
handleChangeCheckbox = (checked, index) => { |
|
|
|
let copyStateMenu = [...this.state.stateMenu]; |
|
|
|
let copyStateMenu = [...this.state.stateMenu]; |
|
|
|
copyStateMenu[index] = checked; |
|
|
|
copyStateMenu[index] = checked; |
|
|
|
this.setState({ stateMenu: copyStateMenu }) |
|
|
|
this.setState({ stateMenu: copyStateMenu }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleChangeCheckboxRead = (checked, index, menuItem = null, menuIdxList = []) => { |
|
|
|
handleChangeCheckboxRead = (checked, index, menuItem = null, menuIdxList = []) => { |
|
|
|
let copyStateRead = [...this.state.stateRead]; |
|
|
|
let copyStateRead = [...this.state.stateRead]; |
|
|
|
copyStateRead[index] = checked; |
|
|
|
copyStateRead[index] = checked; |
|
|
@ -312,6 +338,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setState({ stateRead: copyStateRead }) |
|
|
|
this.setState({ stateRead: copyStateRead }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleChangeCheckboxCreate = (checked, index, menuItem = null, menuIdxList = []) => { |
|
|
|
handleChangeCheckboxCreate = (checked, index, menuItem = null, menuIdxList = []) => { |
|
|
|
let copyStateCreate = [...this.state.stateCreate]; |
|
|
|
let copyStateCreate = [...this.state.stateCreate]; |
|
|
|
copyStateCreate[index] = checked; |
|
|
|
copyStateCreate[index] = checked; |
|
|
@ -336,6 +363,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setState({ stateCreate: copyStateCreate }) |
|
|
|
this.setState({ stateCreate: copyStateCreate }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleChangeCheckboxEdit = (checked, index, menuItem = null, menuIdxList = []) => { |
|
|
|
handleChangeCheckboxEdit = (checked, index, menuItem = null, menuIdxList = []) => { |
|
|
|
let copyStateEdit = [...this.state.stateUpdate]; |
|
|
|
let copyStateEdit = [...this.state.stateUpdate]; |
|
|
|
copyStateEdit[index] = checked; |
|
|
|
copyStateEdit[index] = checked; |
|
|
@ -360,6 +388,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setState({ stateUpdate: copyStateEdit }) |
|
|
|
this.setState({ stateUpdate: copyStateEdit }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleChangeCheckboxDelete = (checked, index, menuItem = null, menuIdxList = []) => { |
|
|
|
handleChangeCheckboxDelete = (checked, index, menuItem = null, menuIdxList = []) => { |
|
|
|
let copyStateDelete = [...this.state.stateDelete]; |
|
|
|
let copyStateDelete = [...this.state.stateDelete]; |
|
|
|
copyStateDelete[index] = checked; |
|
|
|
copyStateDelete[index] = checked; |
|
|
@ -384,6 +413,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setState({ stateDelete: copyStateDelete }) |
|
|
|
this.setState({ stateDelete: copyStateDelete }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleChangeCheckboxReadAll = (checked) => { |
|
|
|
handleChangeCheckboxReadAll = (checked) => { |
|
|
|
let copyStateRead = [...this.state.stateRead]; |
|
|
|
let copyStateRead = [...this.state.stateRead]; |
|
|
|
copyStateRead.map((val, index) => { |
|
|
|
copyStateRead.map((val, index) => { |
|
|
@ -391,6 +421,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setState({ stateRead: copyStateRead }) |
|
|
|
this.setState({ stateRead: copyStateRead }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleChangeCheckboxCreateAll = (checked, index) => { |
|
|
|
handleChangeCheckboxCreateAll = (checked, index) => { |
|
|
|
let copyStateCreate = [...this.state.stateCreate]; |
|
|
|
let copyStateCreate = [...this.state.stateCreate]; |
|
|
|
copyStateCreate.map((val, index) => { |
|
|
|
copyStateCreate.map((val, index) => { |
|
|
@ -398,6 +429,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setState({ stateCreate: copyStateCreate }) |
|
|
|
this.setState({ stateCreate: copyStateCreate }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleChangeCheckboxEditAll = (checked, index) => { |
|
|
|
handleChangeCheckboxEditAll = (checked, index) => { |
|
|
|
let copyStateEdit = [...this.state.stateUpdate]; |
|
|
|
let copyStateEdit = [...this.state.stateUpdate]; |
|
|
|
copyStateEdit.map((val, index) => { |
|
|
|
copyStateEdit.map((val, index) => { |
|
|
@ -405,6 +437,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setState({ stateUpdate: copyStateEdit }) |
|
|
|
this.setState({ stateUpdate: copyStateEdit }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleChangeCheckboxDeleteAll = (checked, index) => { |
|
|
|
handleChangeCheckboxDeleteAll = (checked, index) => { |
|
|
|
let copyStateDelete = [...this.state.stateDelete]; |
|
|
|
let copyStateDelete = [...this.state.stateDelete]; |
|
|
|
copyStateDelete.map((val, index) => { |
|
|
|
copyStateDelete.map((val, index) => { |
|
|
@ -412,6 +445,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setState({ stateDelete: copyStateDelete }) |
|
|
|
this.setState({ stateDelete: copyStateDelete }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
renderForm = () => { |
|
|
|
renderForm = () => { |
|
|
|
const { menu, stateRead, stateCreate, stateUpdate, stateDelete } = this.state; |
|
|
|
const { menu, stateRead, stateCreate, stateUpdate, stateDelete } = this.state; |
|
|
|
let menuIdxList = [] |
|
|
|
let menuIdxList = [] |
|
|
@ -449,6 +483,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
</React.Fragment> |
|
|
|
</React.Fragment> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
renderAll = () => { |
|
|
|
renderAll = () => { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<tr> |
|
|
|
<tr> |
|
|
@ -460,9 +495,11 @@ export default class DialogMenuRoles extends Component { |
|
|
|
</tr> |
|
|
|
</tr> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
checkArray = (val) => { |
|
|
|
checkArray = (val) => { |
|
|
|
return val === false; |
|
|
|
return val === false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleAllChecked = (checked) => { |
|
|
|
handleAllChecked = (checked) => { |
|
|
|
this.setState({ allChecked: !this.state.allChecked }); |
|
|
|
this.setState({ allChecked: !this.state.allChecked }); |
|
|
|
if (checked === true) { |
|
|
|
if (checked === true) { |
|
|
@ -486,6 +523,7 @@ export default class DialogMenuRoles extends Component { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
render() { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<Modal size="xl" scrollable={true} isOpen={this.props.openDialog} toggle={this.props.toggleDialog}> |
|
|
|
<Modal size="xl" scrollable={true} isOpen={this.props.openDialog} toggle={this.props.toggleDialog}> |
|
|
|