module_files_act_list.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package modules
  2. import (
  3. "html"
  4. "os"
  5. "path/filepath"
  6. "strings"
  7. "golang-fave/engine/assets"
  8. "golang-fave/engine/builder"
  9. "golang-fave/engine/utils"
  10. "golang-fave/engine/wrapper"
  11. )
  12. func (this *Modules) RegisterAction_FilesList() *Action {
  13. return this.newAction(AInfo{
  14. Mount: "files-list",
  15. WantAdmin: true,
  16. }, func(wrap *wrapper.Wrapper) {
  17. pf_path := utils.SafeFilePath(utils.Trim(wrap.R.FormValue("path")))
  18. // Set path
  19. wrap.Write(`fave.FilesManagerSetPath('` + pf_path + `');`)
  20. // Render table
  21. start_dir := strings.Join([]string{wrap.DHtdocs, "public"}, string(os.PathSeparator)) + pf_path + "*"
  22. str_dirs := ""
  23. str_files := ""
  24. if files, err := filepath.Glob(start_dir); err == nil {
  25. for _, file := range files {
  26. file_name := file
  27. i := strings.LastIndex(file_name, string(os.PathSeparator))
  28. if i != -1 {
  29. file_name = file_name[i+1:]
  30. }
  31. if utils.IsDir(file) {
  32. actions := builder.DataTableAction(&[]builder.DataTableActionRow{
  33. {
  34. Icon: assets.SysSvgIconView,
  35. Href: "/public" + pf_path + file_name + "/",
  36. Hint: "View",
  37. Target: "_blank",
  38. },
  39. {
  40. Icon: assets.SysSvgIconRemove,
  41. Href: "javascript:fave.FilesManagerRemoveFolder(\\'" + pf_path + file_name + "\\',\\'Are you sure want to delete folder?\\');",
  42. Hint: "Delete",
  43. Classes: "delete",
  44. },
  45. })
  46. str_dirs += `<tr class="dir"><td class="col_name"><a href="javascript:fave.FilesManagerLoadData(\'` + pf_path + file_name + `/` + `\');"><span class="text-dotted">` + html.EscapeString(file_name) + `</span></a></td><td class="col_type"><b>DIR</b></td><td class="col_action">` + actions + `</td></tr>`
  47. } else {
  48. actions := builder.DataTableAction(&[]builder.DataTableActionRow{
  49. {
  50. Icon: assets.SysSvgIconView,
  51. Href: "/public" + pf_path + file_name,
  52. Hint: "View",
  53. Target: "_blank",
  54. },
  55. {
  56. Icon: assets.SysSvgIconRemove,
  57. Href: "javascript:fave.FilesManagerRemoveFile(\\'" + pf_path + file_name + "\\',\\'Are you sure want to delete file?\\');",
  58. Hint: "Delete",
  59. Classes: "delete",
  60. },
  61. })
  62. str_files += `<tr class="file"><td class="col_name"><span class="text-dotted">` + html.EscapeString(file_name) + `</span></td><td class="col_type">` + utils.Int64ToStr(utils.GetFileSize(file)) + `</td><td class="col_action">` + actions + `</td></tr>`
  63. }
  64. }
  65. }
  66. if pf_path != "/" {
  67. str_dirs = `<tr class="dir"><td class="col_name"><a href="javascript:fave.FilesManagerLoadDataUp(\'` + pf_path + `\');">..</a></td><td class="col_type">&nbsp;</td><td class="col_action">&nbsp;</td></tr>` + str_dirs
  68. }
  69. table := `<table class="table data-table table-striped table-bordered table-hover table_fm_files"><thead><tr><th class="col_name">File name</th><th class="col_type">Size</th><th class="col_action">Action</th></tr></thead><tbody>` + str_dirs + str_files + `</tbody></table>`
  70. wrap.Write(`$('#sys-modal-files-manager .dialog-data').html('` + table + `');`)
  71. // Enable buttons
  72. wrap.Write(`fave.FilesManagerEnableDisableButtons(false);`)
  73. })
  74. }