NCShareComments+Menu.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 UIKit
  24. import FloatingPanel
  25. import NCCommunication
  26. extension NCShareComments {
  27. func toggleMenu(with tableComments: tableComments?) {
  28. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  29. var actions = [NCMenuAction]()
  30. actions.append(
  31. NCMenuAction(
  32. title: NSLocalizedString("_edit_comment_", comment: ""),
  33. icon: UIImage(named: "edit")!.image(color: NCBrandColor.shared.gray, size: 50),
  34. action: { menuAction in
  35. guard let metadata = self.metadata else { return }
  36. guard let tableComments = tableComments else { return }
  37. let alert = UIAlertController(title: NSLocalizedString("_edit_comment_", comment: ""), message: nil, preferredStyle: .alert)
  38. alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil))
  39. alert.addTextField(configurationHandler: { textField in
  40. textField.placeholder = NSLocalizedString("_new_comment_", comment: "")
  41. })
  42. alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  43. if let message = alert.textFields?.first?.text {
  44. if message != "" {
  45. NCCommunication.shared.updateComments(fileId: metadata.fileId, messageId: tableComments.messageId, message: message) { (account, errorCode, errorDescription) in
  46. if errorCode == 0 {
  47. self.reloadData()
  48. } else {
  49. NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  50. }
  51. }
  52. }
  53. }
  54. }))
  55. self.present(alert, animated: true)
  56. }
  57. )
  58. )
  59. actions.append(
  60. NCMenuAction(
  61. title: NSLocalizedString("_delete_comment_", comment: ""),
  62. icon: NCUtility.shared.loadImage(named: "trash"),
  63. action: { menuAction in
  64. guard let metadata = self.metadata else { return }
  65. guard let tableComments = tableComments else { return }
  66. NCCommunication.shared.deleteComments(fileId: metadata.fileId, messageId: tableComments.messageId) { (account, errorCode, errorDescription) in
  67. if errorCode == 0 {
  68. self.reloadData()
  69. } else {
  70. NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  71. }
  72. }
  73. }
  74. )
  75. )
  76. actions.append(
  77. NCMenuAction(
  78. title: NSLocalizedString("_cancel_", comment: ""),
  79. icon: UIImage(named: "cancel")!.image(color: NCBrandColor.shared.gray, size: 50),
  80. action: { menuAction in
  81. }
  82. )
  83. )
  84. menuViewController.actions = actions
  85. let menuPanelController = NCMenuPanelController()
  86. menuPanelController.parentPresenter = self
  87. menuPanelController.delegate = menuViewController
  88. menuPanelController.set(contentViewController: menuViewController)
  89. menuPanelController.track(scrollView: menuViewController.tableView)
  90. self.present(menuPanelController, animated: true, completion: nil)
  91. }
  92. }