NCCreateFormUploadRichdocuments.swift 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // CCCreateCloud.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 14/11/18.
  6. // Copyright © 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  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 Foundation
  24. // MARK: -
  25. class NCCreateFormUploadRichdocuments: XLFormViewController, NCSelectDelegate, UICollectionViewDataSource, UICollectionViewDelegate {
  26. var typeTemplate = ""
  27. var serverUrl = ""
  28. var fileNameFolder = ""
  29. var fileName = ""
  30. var listOfTemplate = [NCRichDocumentTemplate]()
  31. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  32. @IBOutlet weak var collectioView: UICollectionView!
  33. // MARK: - View Life Cycle
  34. override func viewDidLoad() {
  35. super.viewDidLoad()
  36. if serverUrl == CCUtility.getHomeServerUrlActiveUrl(appDelegate.activeUrl) {
  37. fileNameFolder = "/"
  38. } else {
  39. fileNameFolder = (serverUrl as NSString).lastPathComponent
  40. }
  41. self.initializeForm()
  42. collectioView.delegate = self
  43. self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
  44. let cancelButton : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: UIBarButtonItem.Style.plain, target: self, action: #selector(cancel))
  45. let saveButton : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_save_", comment: ""), style: UIBarButtonItem.Style.plain, target: self, action: #selector(save))
  46. self.navigationItem.leftBarButtonItem = cancelButton
  47. self.navigationItem.rightBarButtonItem = saveButton
  48. self.navigationItem.rightBarButtonItem?.isEnabled = false
  49. self.navigationController?.navigationBar.isTranslucent = false
  50. self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand
  51. self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.brandText
  52. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: NCBrandColor.sharedInstance.brandText]
  53. let ocNetworking = OCnetworking.init(delegate: nil, metadataNet: nil, withUser: appDelegate.activeUser, withUserID: appDelegate.activeUserID, withPassword: appDelegate.activePassword, withUrl: appDelegate.activeUrl)
  54. ocNetworking?.createTemplateRichdocuments(withTemplate: typeTemplate, success: { (listOfTemplate) in
  55. self.listOfTemplate = listOfTemplate as! [NCRichDocumentTemplate]
  56. }, failure: { (message, errorCode) in
  57. })
  58. }
  59. // MARK: - Tableview (XLForm)
  60. func initializeForm() {
  61. let form : XLFormDescriptor = XLFormDescriptor(title: NSLocalizedString("_upload_photos_videos_", comment: "")) as XLFormDescriptor
  62. form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow
  63. var section : XLFormSectionDescriptor
  64. var row : XLFormRowDescriptor
  65. // Section: Destination Folder
  66. section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_save_path_", comment: "").uppercased())
  67. form.addFormSection(section)
  68. row = XLFormRowDescriptor(tag: "ButtonDestinationFolder", rowType: XLFormRowDescriptorTypeButton, title: fileNameFolder)
  69. row.action.formSelector = #selector(changeDestinationFolder(_:))
  70. row.value = fileNameFolder
  71. let imageFolder = CCGraphics.changeThemingColorImage(UIImage(named: "folder")!, multiplier:1, color: NCBrandColor.sharedInstance.brandElement) as UIImage
  72. row.cellConfig["imageView.image"] = imageFolder
  73. row.cellConfig["textLabel.textAlignment"] = NSTextAlignment.right.rawValue
  74. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  75. section.addFormRow(row)
  76. // Section: File Name
  77. section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_filename_", comment: "").uppercased())
  78. form.addFormSection(section)
  79. row = XLFormRowDescriptor(tag: "fileName", rowType: XLFormRowDescriptorTypeAccount, title: NSLocalizedString("_filename_", comment: ""))
  80. row.value = fileName
  81. row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
  82. row.cellConfig["textField.font"] = UIFont.systemFont(ofSize: 15.0)
  83. section.addFormRow(row)
  84. self.form = form
  85. }
  86. override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
  87. let header: UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView
  88. header.textLabel?.font = UIFont.systemFont(ofSize: 13.0)
  89. header.textLabel?.textColor = NCBrandColor.sharedInstance.icon //UIColor.lightGray
  90. }
  91. // MARK: - CollectionView
  92. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  93. return 0
  94. }
  95. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  96. return UICollectionViewCell()
  97. }
  98. // MARK: - Action
  99. func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String) {
  100. guard let serverUrl = serverUrl else {
  101. return
  102. }
  103. self.serverUrl = serverUrl
  104. if serverUrl == CCUtility.getHomeServerUrlActiveUrl(appDelegate.activeUrl) {
  105. fileNameFolder = "/"
  106. } else {
  107. fileNameFolder = (serverUrl as NSString).lastPathComponent
  108. }
  109. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  110. buttonDestinationFolder.title = fileNameFolder
  111. self.tableView.reloadData()
  112. }
  113. @objc func changeDestinationFolder(_ sender: XLFormRowDescriptor) {
  114. self.deselectFormRow(sender)
  115. let storyboard = UIStoryboard(name: "NCSelect", bundle: nil)
  116. let navigationController = storyboard.instantiateInitialViewController() as! UINavigationController
  117. let viewController = navigationController.topViewController as! NCSelect
  118. viewController.delegate = self
  119. viewController.hideButtonCreateFolder = false
  120. viewController.includeDirectoryE2EEncryption = false
  121. viewController.includeImages = false
  122. viewController.layoutViewSelect = k_layout_view_move
  123. viewController.selectFile = false
  124. viewController.titleButtonDone = NSLocalizedString("_select_", comment: "")
  125. viewController.type = ""
  126. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  127. self.present(navigationController, animated: true, completion: nil)
  128. }
  129. @objc func save() {
  130. self.dismiss(animated: true, completion: {
  131. //self.appDelegate.activeMain.uploadFileAsset(self.assets, serverUrl: self.serverUrl, useSubFolder: useSubFolder, session: self.session)
  132. })
  133. }
  134. @objc func cancel() {
  135. self.dismiss(animated: true, completion: nil)
  136. }
  137. }