Commit 619fd806 authored by d.arizona's avatar d.arizona

update again

parent 6030f5e0
......@@ -152,7 +152,7 @@ class UserRole extends Component {
handleChange(e) {
let data = this.state
window.requestIdleCallback((e) => this.setState({ ...data, [e.target.name]: e.target.value }, () => {
alert('asdk')
// alert('asdk')
}))
}
......
......@@ -324,23 +324,9 @@ export default class AddRole extends Component {
let indexButtonID = this.state.privileges[indexID].button_id.findIndex((val) => val === index)
let privileges = this.state.privileges
let button_id = privileges[indexID].button_id
// const handlePushChild = (item) => {
// let indexIDzz = company.findIndex((val) => val === item.id)
// if (indexIDzz === -1) {
// company.push(item.id)
// }
// if (item.children !== null) {
// if (item.children.length > 0) {
// item.children.map((items,indexs) => {
// handlePushChild(items)
// })
// }
// }
// }
if (indexButtonID === -1) {
button_id.push(index)
// console.log(item)
if (item.sub_menu.length > 0) {
item.sub_menu.map((items,indexs) => {
let subIndexID = privileges.findIndex((val) => val.menu_id === items.menu_id)
......@@ -356,8 +342,6 @@ export default class AddRole extends Component {
if(subIndexButtonID === -1) {
subButton_id.push(index)
}
// privileges[subIndexID].button_id = subButton_id
// console.log(subButton_id)
}
})
}
......@@ -381,7 +365,6 @@ export default class AddRole extends Component {
let subIndexButtonID = privileges[subIndexID].button_id.findIndex((val) => val === index)
let subButton_id = privileges[subIndexID].button_id
if (subIndexButtonID !== -1) {
// console.log('masuk pa eko', subIndexID)
subButton_id.splice(subIndexButtonID, 1)
privileges[subIndexID].button_id = subButton_id
if (privileges[subIndexID].button_id.length < 1) {
......@@ -421,9 +404,7 @@ export default class AddRole extends Component {
if (button_id.length === 0) {
privileges.splice(indexID, 1)
}
this.setState({ privileges: privileges.sort((a,b) => a.menu_id-b.menu_id) }, () => {
console.log(this.state.privileges)
})
this.setState({ privileges: privileges.sort((a,b) => a.menu_id-b.menu_id) })
}
handleDate(item) {
......
......@@ -299,16 +299,87 @@ export default class EditRole extends Component {
let indexButtonID = this.state.privileges[indexID].button_id.findIndex((val) => val === index)
let privileges = this.state.privileges
let button_id = privileges[indexID].button_id
if (indexButtonID === -1) {
button_id.push(index)
if (item.sub_menu.length > 0) {
item.sub_menu.map((items,indexs) => {
let subIndexID = privileges.findIndex((val) => val.menu_id === items.menu_id)
if (subIndexID === -1) {
console.log('masuk pa eko', subIndexID)
privileges.push({
menu_id: items.menu_id,
button_id: [index]
})
} else {
let subIndexButtonID = privileges[subIndexID].button_id.findIndex((val) => val === index)
let subButton_id = privileges[subIndexID].button_id
if(subIndexButtonID === -1) {
subButton_id.push(index)
}
}
})
}
if (item.reference !== null && item.reference !== 13 && item.reference !== 1) {
let refIndexID = privileges.findIndex((val) => val.menu_id === item.reference)
if (refIndexID !== -1) {
let refIndexButtonID = privileges[refIndexID].button_id.findIndex((val) => val === index)
let refButton_id = privileges[refIndexID].button_id
if (refIndexButtonID === -1) {
refButton_id.push(index)
}
privileges[refIndexID].button_id = refButton_id
}
}
} else {
button_id.splice(indexButtonID, 1)
if (item.sub_menu.length > 0) {
item.sub_menu.map((items,indexs) => {
let subIndexID = privileges.findIndex((val) => val.menu_id === items.menu_id)
if (subIndexID !== -1) {
let subIndexButtonID = privileges[subIndexID].button_id.findIndex((val) => val === index)
let subButton_id = privileges[subIndexID].button_id
if (subIndexButtonID !== -1) {
subButton_id.splice(subIndexButtonID, 1)
privileges[subIndexID].button_id = subButton_id
if (privileges[subIndexID].button_id.length < 1) {
privileges.splice(subIndexID, 1)
}
}
}
})
}
if (item.reference !== null && item.reference !== 13 && item.reference !== 1) {
let refIndexID = privileges.findIndex((val) => val.menu_id === item.reference)
if (refIndexID !== -1) {
let refIndexButtonID = privileges[refIndexID].button_id.findIndex((val) => val === index)
let refButton_id = privileges[refIndexID].button_id
let indexIDapp = this.state.application.findIndex((val) => val.menu_id === item.reference)
let indexIDset = this.state.setting.findIndex((val) => val.menu_id === item.reference)
let indexIDs = indexIDapp == -1? indexIDset : indexIDapp
let array = indexIDapp == -1? this.state.setting : this.state.application
let splicer = 0
array[indexIDs].sub_menu.map((refItem, refIndex) => {
let subIndexID = privileges.findIndex((val) => val.menu_id === refItem.menu_id)
if (subIndexID !== -1) {
let subIndexButtonID = privileges[subIndexID].button_id.findIndex((val) => val === index)
if (subIndexButtonID !== -1) {
splicer += 1
}
privileges[indexID].button_id = button_id
}
})
if (refIndexButtonID !== -1 && splicer < 1) {
refButton_id.splice(refIndexButtonID, 1)
}
privileges[refIndexID].button_id = refButton_id
}
}
}
privileges[indexID].button_id = button_id.sort((a,b) => a-b)
if (button_id.length === 0) {
privileges.splice(indexID, 1)
}
this.setState({ privileges })
this.setState({ privileges: privileges.sort((a,b) => a.menu_id-b.menu_id) })
}
handleCollapse(item) {
......
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