NCShareComments+Menu.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // NCShareComments+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 03/03/2021.
  6. // Copyright © 2021 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import FloatingPanel
  24. import NCCommunication
  25. extension NCShareComments {
  26. func toggleMenu(with tableComments: tableComments?) {
  27. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  28. var actions = [NCMenuAction]()
  29. actions.append(
  30. NCMenuAction(
  31. title: NSLocalizedString("_edit_comment_", comment: ""),
  32. icon: UIImage(named: "edit")!.image(color: NCBrandColor.shared.icon, size: 50),
  33. action: { menuAction in
  34. guard let metadata = self.metadata else { return }
  35. guard let tableComments = tableComments else { return }
  36. let alert = UIAlertController(title: NSLocalizedString("_edit_comment_", comment: ""), message: nil, preferredStyle: .alert)
  37. alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil))
  38. alert.addTextField(configurationHandler: { textField in
  39. textField.placeholder = NSLocalizedString("_new_comment_", comment: "")
  40. })
  41. alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  42. if let message = alert.textFields?.first?.text {
  43. if message != "" {
  44. NCCommunication.shared.updateComments(fileId: metadata.fileId, messageId: tableComments.messageId, message: message) { (account, errorCode, errorDescription) in
  45. if errorCode == 0 {
  46. self.reloadData()
  47. } else {
  48. NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  49. }
  50. }
  51. }
  52. }
  53. }))
  54. self.present(alert, animated: true)
  55. }
  56. )
  57. )
  58. actions.append(
  59. NCMenuAction(
  60. title: NSLocalizedString("_delete_comment_", comment: ""),
  61. icon: UIImage(named: "trash")!.image(color: NCBrandColor.shared.icon, size: 50),
  62. action: { menuAction in
  63. guard let metadata = self.metadata else { return }
  64. guard let tableComments = tableComments else { return }
  65. NCCommunication.shared.deleteComments(fileId: metadata.fileId, messageId: tableComments.messageId) { (account, errorCode, errorDescription) in
  66. if errorCode == 0 {
  67. self.reloadData()
  68. } else {
  69. NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  70. }
  71. }
  72. }
  73. )
  74. )
  75. actions.append(
  76. NCMenuAction(
  77. title: NSLocalizedString("_cancel_", comment: ""),
  78. icon: UIImage(named: "cancel")!.image(color: NCBrandColor.shared.icon, size: 50),
  79. action: { menuAction in
  80. }
  81. )
  82. )
  83. mainMenuViewController.actions = actions
  84. let menuPanelController = NCMenuPanelController()
  85. menuPanelController.parentPresenter = self
  86. menuPanelController.delegate = mainMenuViewController
  87. menuPanelController.set(contentViewController: mainMenuViewController)
  88. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  89. self.present(menuPanelController, animated: true, completion: nil)
  90. }
  91. }