Browse Source

new Rename file View

marinofaggiana 4 years ago
parent
commit
2f5d9d8e24

+ 2 - 2
iOSClient/Main/Rename file/NCRenameFile.storyboard

@@ -52,8 +52,8 @@
                     </view>
                     <navigationItem key="navigationItem" id="Zon-2j-rsc"/>
                     <connections>
-                        <outlet property="fileExtension" destination="Q9G-gl-Fkc" id="PDH-Jp-0B7"/>
-                        <outlet property="fileName" destination="Ny2-wR-rxo" id="Eja-cc-9hM"/>
+                        <outlet property="ext" destination="Q9G-gl-Fkc" id="YeW-bU-cMx"/>
+                        <outlet property="fileNameWithoutExt" destination="Ny2-wR-rxo" id="2Wq-hO-cwc"/>
                         <outlet property="image" destination="t26-3S-4T4" id="h7s-v9-829"/>
                     </connections>
                 </viewController>

+ 32 - 4
iOSClient/Main/Rename file/NCRenameFile.swift

@@ -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)
+            }
+        }
     }
 }

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -35,6 +35,7 @@
 "_delete_"                  = "Delete";
 "_delete_file_n_"           = "Delete file %i of %i";
 "_rename_"                  = "Rename";
+"_rename_file_"             = "Rename file";
 "_move_"                    = "Move";
 "_move_file_n_"             = "Move file %i of %i";
 "_creating_sharing_"        = "Creating share";