|
@@ -7,13 +7,14 @@
|
|
|
//
|
|
|
|
|
|
import Foundation
|
|
|
+import NCCommunication
|
|
|
|
|
|
class NCRenameFile: UIViewController {
|
|
|
|
|
|
@IBOutlet weak var image: UIImageView!
|
|
|
|
|
|
- @IBOutlet weak var fileName: UITextField!
|
|
|
- @IBOutlet weak var fileExtension: UITextField!
|
|
|
+ @IBOutlet weak var fileNameWithoutExt: UITextField!
|
|
|
+ @IBOutlet weak var ext: UITextField!
|
|
|
|
|
|
var metadata: tableMetadata?
|
|
|
|
|
@@ -23,8 +24,8 @@ class NCRenameFile: UIViewController {
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
if let metadata = self.metadata {
|
|
|
- fileName.text = metadata.fileNameWithoutExt
|
|
|
- fileExtension.text = metadata.ext
|
|
|
+ fileNameWithoutExt.text = metadata.fileNameWithoutExt
|
|
|
+ ext.text = metadata.ext
|
|
|
}
|
|
|
|
|
|
title = NSLocalizedString("_rename_file_", comment: "")
|
|
@@ -50,5 +51,32 @@ class NCRenameFile: UIViewController {
|
|
|
|
|
|
@objc func rename() {
|
|
|
|
|
|
+ guard let metadata = metadata else { return }
|
|
|
+ var newFileNameWithoutExt = ""
|
|
|
+ var newExt = ""
|
|
|
+
|
|
|
+ if fileNameWithoutExt.text == nil || fileNameWithoutExt.text?.count == 0 {
|
|
|
+ self.fileNameWithoutExt.text = metadata.fileNameWithoutExt
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ newFileNameWithoutExt = fileNameWithoutExt.text!
|
|
|
+ }
|
|
|
+
|
|
|
+ if ext.text == nil || ext.text?.count == 0 {
|
|
|
+ self.ext.text = metadata.ext
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ newExt = ext.text!
|
|
|
+ }
|
|
|
+
|
|
|
+ let fileNameNew = newFileNameWithoutExt + "." + newExt
|
|
|
+
|
|
|
+ NCNetworking.shared.renameMetadata(metadata, fileNameNew: fileNameNew, urlBase: metadata.urlBase, viewController: self) { (errorCode, errorDescription) in
|
|
|
+ if errorCode == 0 {
|
|
|
+ self.dismiss(animated: true)
|
|
|
+ } else {
|
|
|
+ NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|