2025-05-06 06:45:49 +00:00
|
|
|
|
import { Button, Notification, toast } from '@/components/ui'
|
2025-08-12 08:39:06 +00:00
|
|
|
|
import { GridDto, UiCommandButtonPositionTypeEnum } from '@/proxy/form/models'
|
|
|
|
|
|
import { dynamicFetch } from '@/services/form.service'
|
2025-05-06 06:45:49 +00:00
|
|
|
|
import { useLocalization } from '@/utils/hooks/useLocalization'
|
|
|
|
|
|
import { usePermission } from '@/utils/hooks/usePermission'
|
|
|
|
|
|
import { DataGridTypes } from 'devextreme-react/data-grid'
|
|
|
|
|
|
import { ToolbarItem } from 'devextreme/ui/data_grid_types'
|
|
|
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
|
|
import { useDialogContext } from '../shared/DialogContext'
|
|
|
|
|
|
import { usePWA } from '@/utils/hooks/usePWA'
|
2025-11-08 20:22:50 +00:00
|
|
|
|
import { layoutTypes, ListViewLayoutType } from '../admin/listForm/edit/types'
|
2025-05-06 06:45:49 +00:00
|
|
|
|
|
|
|
|
|
|
type ToolbarModalData = {
|
|
|
|
|
|
open: boolean
|
|
|
|
|
|
content?: JSX.Element
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/toolbar/
|
|
|
|
|
|
// item.name > Accepted Values: 'addRowButton', 'applyFilterButton', 'columnChooserButton', 'exportButton', 'groupPanel', 'revertButton', 'saveButton', 'searchPanel'
|
|
|
|
|
|
const useToolbar = ({
|
|
|
|
|
|
gridDto,
|
|
|
|
|
|
listFormCode,
|
|
|
|
|
|
getSelectedRowKeys,
|
|
|
|
|
|
getSelectedRowsData,
|
|
|
|
|
|
refreshData,
|
|
|
|
|
|
getFilter,
|
2025-11-08 20:22:50 +00:00
|
|
|
|
layout,
|
2025-11-08 00:16:55 +00:00
|
|
|
|
expandAll,
|
|
|
|
|
|
collapseAll,
|
2025-05-06 06:45:49 +00:00
|
|
|
|
}: {
|
|
|
|
|
|
gridDto?: GridDto
|
|
|
|
|
|
listFormCode: string
|
|
|
|
|
|
getSelectedRowKeys: () => void
|
|
|
|
|
|
getSelectedRowsData: () => any
|
2025-08-12 08:39:06 +00:00
|
|
|
|
refreshData: () => void
|
|
|
|
|
|
getFilter: () => void
|
2025-11-08 20:22:50 +00:00
|
|
|
|
layout: ListViewLayoutType | string
|
2025-11-08 00:16:55 +00:00
|
|
|
|
expandAll?: () => void
|
|
|
|
|
|
collapseAll?: () => void
|
2025-05-06 06:45:49 +00:00
|
|
|
|
}): {
|
|
|
|
|
|
toolbarData: ToolbarItem[]
|
|
|
|
|
|
toolbarModalData: ToolbarModalData | undefined
|
|
|
|
|
|
setToolbarModalData: (data: ToolbarModalData | undefined) => void
|
|
|
|
|
|
} => {
|
|
|
|
|
|
const dialog: any = useDialogContext()
|
|
|
|
|
|
const { translate } = useLocalization()
|
|
|
|
|
|
const { checkPermission } = usePermission()
|
2025-08-12 08:39:06 +00:00
|
|
|
|
const isPwaMode = usePWA()
|
2025-05-06 06:45:49 +00:00
|
|
|
|
|
|
|
|
|
|
const [toolbarData, setToolbarData] = useState<ToolbarItem[]>([])
|
|
|
|
|
|
const [toolbarModalData, setToolbarModalData] = useState<ToolbarModalData>()
|
|
|
|
|
|
|
|
|
|
|
|
const grdOpt = gridDto?.gridOptions
|
|
|
|
|
|
|
|
|
|
|
|
function getToolbarData() {
|
|
|
|
|
|
const items: ToolbarItem[] = []
|
|
|
|
|
|
|
|
|
|
|
|
if (!gridDto || !grdOpt) {
|
|
|
|
|
|
setToolbarData(items)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-08 00:16:55 +00:00
|
|
|
|
// Add searchPanel
|
2025-10-11 18:04:22 +00:00
|
|
|
|
if (grdOpt.searchPanelDto?.visible) {
|
|
|
|
|
|
items.push({
|
|
|
|
|
|
locateInMenu: 'auto',
|
|
|
|
|
|
showText: 'inMenu',
|
|
|
|
|
|
name: 'searchPanel',
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-11-08 00:16:55 +00:00
|
|
|
|
|
2025-10-11 18:04:22 +00:00
|
|
|
|
items.push({
|
|
|
|
|
|
widget: 'dxButton',
|
|
|
|
|
|
name: 'refreshButton',
|
|
|
|
|
|
options: {
|
|
|
|
|
|
icon: 'refresh',
|
|
|
|
|
|
onClick: refreshData,
|
2025-10-12 18:45:03 +00:00
|
|
|
|
text: translate('::ListForms.ListForm.Refresh'),
|
2025-10-11 18:04:22 +00:00
|
|
|
|
},
|
|
|
|
|
|
location: 'after',
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-11-08 00:16:55 +00:00
|
|
|
|
// Add Expand All button for TreeList
|
2025-11-08 20:22:50 +00:00
|
|
|
|
if (layout === layoutTypes.tree && grdOpt.treeOptionDto?.parentIdExpr) {
|
2025-11-08 00:16:55 +00:00
|
|
|
|
items.push({
|
|
|
|
|
|
widget: 'dxButton',
|
|
|
|
|
|
name: 'expandAllButton',
|
|
|
|
|
|
options: {
|
|
|
|
|
|
icon: 'plus',
|
|
|
|
|
|
text: translate('::ListForms.ListFormEdit.ExpandAll'),
|
|
|
|
|
|
onClick: expandAll,
|
|
|
|
|
|
},
|
|
|
|
|
|
location: 'after',
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Add Collapse All button for TreeList
|
|
|
|
|
|
items.push({
|
|
|
|
|
|
widget: 'dxButton',
|
|
|
|
|
|
name: 'collapseAllButton',
|
|
|
|
|
|
options: {
|
|
|
|
|
|
icon: 'minus',
|
|
|
|
|
|
text: translate('::ListForms.ListFormEdit.CollapseAll'),
|
|
|
|
|
|
onClick: collapseAll,
|
|
|
|
|
|
},
|
|
|
|
|
|
location: 'after',
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-06 06:45:49 +00:00
|
|
|
|
// field chooser panel
|
|
|
|
|
|
if (grdOpt.columnOptionDto?.columnChooserEnabled) {
|
|
|
|
|
|
items.push({
|
2025-09-15 08:15:21 +00:00
|
|
|
|
locateInMenu: 'auto',
|
|
|
|
|
|
showText: 'inMenu',
|
2025-05-06 06:45:49 +00:00
|
|
|
|
name: 'columnChooserButton',
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-11 18:04:22 +00:00
|
|
|
|
// Add InsertNewRecord button
|
|
|
|
|
|
if (grdOpt.editingOptionDto?.allowAdding && checkPermission(grdOpt.permissionDto?.c)) {
|
|
|
|
|
|
items.push({
|
|
|
|
|
|
locateInMenu: 'auto',
|
2025-12-02 21:07:31 +00:00
|
|
|
|
showText: 'always',
|
2025-10-11 18:04:22 +00:00
|
|
|
|
name: 'addRowButton',
|
|
|
|
|
|
location: 'after',
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-06 06:45:49 +00:00
|
|
|
|
// Add group panel
|
|
|
|
|
|
if (grdOpt.groupPanelDto?.visible) {
|
|
|
|
|
|
items.push({
|
2025-09-15 08:15:21 +00:00
|
|
|
|
locateInMenu: 'auto',
|
|
|
|
|
|
showText: 'inMenu',
|
2025-05-06 06:45:49 +00:00
|
|
|
|
name: 'groupPanel',
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Add DeleteSelectedRecords button
|
|
|
|
|
|
// coklu silme icin
|
|
|
|
|
|
if (grdOpt.editingOptionDto?.allowDeleting && checkPermission(grdOpt.permissionDto?.d)) {
|
|
|
|
|
|
items.push({
|
|
|
|
|
|
location: 'after',
|
|
|
|
|
|
widget: 'dxButton',
|
2025-09-15 08:15:21 +00:00
|
|
|
|
locateInMenu: 'auto',
|
|
|
|
|
|
showText: 'inMenu',
|
2025-05-06 06:45:49 +00:00
|
|
|
|
name: 'deleteSelectedRecords',
|
|
|
|
|
|
options: {
|
|
|
|
|
|
text: translate('::ListForms.ListForm.DeleteSelectedRecords'),
|
|
|
|
|
|
icon: 'trash',
|
|
|
|
|
|
visible: false,
|
|
|
|
|
|
onClick() {
|
|
|
|
|
|
if (!grdOpt.deleteServiceAddress) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dynamicFetch(grdOpt.deleteServiceAddress, 'POST', null, {
|
|
|
|
|
|
keys: getSelectedRowKeys(),
|
|
|
|
|
|
listFormCode,
|
|
|
|
|
|
}).then(() => {
|
|
|
|
|
|
refreshData()
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Add DeleteAllRecords button
|
|
|
|
|
|
// butun kayitlari (filtreli) icin
|
|
|
|
|
|
if (grdOpt.editingOptionDto?.allowAllDeleting) {
|
|
|
|
|
|
const buttonDeleteAll: DataGridTypes.ToolbarItem = {
|
|
|
|
|
|
location: 'after',
|
|
|
|
|
|
widget: 'dxButton',
|
|
|
|
|
|
name: 'deleteAllRecords',
|
|
|
|
|
|
options: {
|
|
|
|
|
|
text: translate('::ListForms.ListForm.DeleteAllRecords'),
|
|
|
|
|
|
hint: translate('::ListForms.ListForm.DeleteAllRecords'),
|
|
|
|
|
|
icon: 'trash',
|
|
|
|
|
|
visible: true,
|
|
|
|
|
|
onClick() {
|
|
|
|
|
|
const parameters = {
|
|
|
|
|
|
listFormCode,
|
|
|
|
|
|
filter: JSON.stringify(getFilter()),
|
|
|
|
|
|
onlyTotalCountQuery: true,
|
|
|
|
|
|
createDeleteQuery: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dynamicFetch('list-form-select/select', 'GET', parameters).then((r: any) => {
|
|
|
|
|
|
setToolbarModalData({
|
|
|
|
|
|
open: true,
|
|
|
|
|
|
content: (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<h5 className="mb-4">Delete All Records</h5>
|
|
|
|
|
|
|
|
|
|
|
|
<p>Are you sure to delete all {r.data.totalCount} records?</p>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="text-right mt-6">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
className="ltr:mr-2 rtl:ml-2"
|
|
|
|
|
|
variant="plain"
|
|
|
|
|
|
onClick={() => setToolbarModalData(undefined)}
|
|
|
|
|
|
>
|
|
|
|
|
|
Cancel
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
variant="solid"
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
//delete parameters.onlyTotalCountQuery
|
|
|
|
|
|
parameters.createDeleteQuery = true // tumunu silme islemi parametresi > set
|
|
|
|
|
|
dynamicFetch('list-form-select/select', 'GET', parameters).then(() => {
|
|
|
|
|
|
toast.push(
|
|
|
|
|
|
<Notification type="success" duration={2000}>
|
|
|
|
|
|
{'Tüm kayıtlar silindi.'}
|
|
|
|
|
|
</Notification>,
|
|
|
|
|
|
{
|
2025-09-01 14:07:03 +00:00
|
|
|
|
placement: 'top-end',
|
2025-05-06 06:45:49 +00:00
|
|
|
|
},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
refreshData()
|
|
|
|
|
|
|
|
|
|
|
|
setToolbarModalData(undefined)
|
|
|
|
|
|
})
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Save
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
),
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
items.push(buttonDeleteAll)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// #region Toolbar icin kullanici tanimli dinamik butonlari ekler
|
|
|
|
|
|
for (let i = 0; i < grdOpt.commandColumnDto.length; i++) {
|
|
|
|
|
|
const action = grdOpt.commandColumnDto[i]
|
|
|
|
|
|
|
|
|
|
|
|
// action.buttonPosition == 1 ise Toolbar butonudur, burada sadece Toolbar butonunu eklenir
|
|
|
|
|
|
if (action.buttonPosition !== UiCommandButtonPositionTypeEnum.Toolbar) {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (checkPermission(action.authName)) {
|
|
|
|
|
|
const buttonCustom: DataGridTypes.ToolbarItem = {
|
|
|
|
|
|
location: 'after',
|
|
|
|
|
|
widget: 'dxButton',
|
|
|
|
|
|
name: action.hint,
|
|
|
|
|
|
options: {
|
|
|
|
|
|
hint: action.hint,
|
|
|
|
|
|
text: action.text,
|
|
|
|
|
|
icon: action.icon,
|
|
|
|
|
|
visible: true,
|
|
|
|
|
|
onClick(e: any) {
|
|
|
|
|
|
if (typeof e.event?.preventDefault === 'function') {
|
|
|
|
|
|
e?.event?.preventDefault()
|
|
|
|
|
|
}
|
|
|
|
|
|
if (action.url) {
|
|
|
|
|
|
let url = action.url
|
|
|
|
|
|
// griddeki secili satirlari al
|
|
|
|
|
|
const selectedRowsData = getSelectedRowsData()
|
|
|
|
|
|
// constsa her bir secili satir icin donguye gir
|
|
|
|
|
|
for (let i = 0; i < selectedRowsData.length; i++) {
|
|
|
|
|
|
// secili satirin objesine ait property verilerini al
|
|
|
|
|
|
const keys = Object.keys(selectedRowsData[i])
|
|
|
|
|
|
// secili satirin her bir property si icin donguye gir
|
|
|
|
|
|
for (let j = 0; j < keys.length; j++) {
|
|
|
|
|
|
// secili satirin j indexine sahip property ismini al
|
|
|
|
|
|
const fieldName = keys[j]
|
|
|
|
|
|
// secili satirin j indexine sahip property isminin degerini al
|
|
|
|
|
|
const fieldValue = selectedRowsData[i][fieldName]
|
|
|
|
|
|
// url icerisindeki {PropertyName} seklindeki anahtarlari secili satirdaki uyusan propertyler ile degistir
|
|
|
|
|
|
url = url.replace(`@${fieldName}`, fieldValue)
|
|
|
|
|
|
}
|
|
|
|
|
|
break // Url cagirmak icin kullanilacak parametreler sadece secili olan ilk satirdan alinir!
|
|
|
|
|
|
}
|
|
|
|
|
|
window.open(url, isPwaMode ? '_self' : action.urlTarget)
|
|
|
|
|
|
} else if (action.dialogName) {
|
|
|
|
|
|
if (action.dialogParameters) {
|
|
|
|
|
|
var dynamicMap = JSON.parse(action.dialogParameters)
|
|
|
|
|
|
for (const [key, value] of Object.entries<string>(dynamicMap)) {
|
|
|
|
|
|
dynamicMap[key] = value.startsWith('@')
|
|
|
|
|
|
? e.row.data[value.replace('@', '')]
|
|
|
|
|
|
: value
|
|
|
|
|
|
}
|
|
|
|
|
|
dialog.setConfig({
|
|
|
|
|
|
component: action.dialogName,
|
|
|
|
|
|
props: dynamicMap,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (action.onClick) {
|
|
|
|
|
|
eval(action.onClick)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
items.push(buttonCustom)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
|
|
|
|
// batch editing icin kaydet ve geri al butonu
|
|
|
|
|
|
if (
|
|
|
|
|
|
grdOpt.editingOptionDto?.allowUpdating &&
|
|
|
|
|
|
grdOpt.editingOptionDto?.mode == 'batch' &&
|
|
|
|
|
|
checkPermission(grdOpt.permissionDto?.u)
|
|
|
|
|
|
) {
|
|
|
|
|
|
items.push({
|
2025-09-15 08:15:21 +00:00
|
|
|
|
locateInMenu: 'auto',
|
|
|
|
|
|
showText: 'inMenu',
|
2025-05-06 06:45:49 +00:00
|
|
|
|
name: 'saveButton',
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
items.push({
|
2025-09-15 08:15:21 +00:00
|
|
|
|
locateInMenu: 'auto',
|
|
|
|
|
|
showText: 'inMenu',
|
2025-05-06 06:45:49 +00:00
|
|
|
|
name: 'revertButton',
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
|
|
|
|
setToolbarData(items)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2025-09-22 14:08:42 +00:00
|
|
|
|
if (!gridDto && !listFormCode) return
|
2025-05-06 06:45:49 +00:00
|
|
|
|
|
2025-09-22 14:08:42 +00:00
|
|
|
|
getToolbarData()
|
2025-05-06 06:45:49 +00:00
|
|
|
|
}, [gridDto, listFormCode])
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
toolbarData,
|
|
|
|
|
|
toolbarModalData,
|
|
|
|
|
|
setToolbarModalData,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export { useToolbar }
|