Browse Source

dev new share

marinofaggiana 5 năm trước cách đây
mục cha
commit
9fe47394e8

+ 36 - 11
iOSClient/Share/NCShareUserMenuView.swift

@@ -83,23 +83,25 @@ class NCShareUserMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
     
     func reloadData(idRemoteShared: Int) {
         tableShare = NCManageDatabase.sharedInstance.getTableShare(account: metadata!.account, idRemoteShared: idRemoteShared)
-        
+        guard let tableShare = self.tableShare else { return }
+
         // Can reshare
-        if tableShare != nil && tableShare!.permissions > Int(k_read_share_permission) {
-            //switchAllowEditing.setOn(true, animated: false)
+        let canReshare = UtilsFramework.isPermission(toCanShare: tableShare.permissions)
+        if canReshare {
+            switchCanReshare.setOn(true, animated: false)
         } else {
-            //switchAllowEditing.setOn(false, animated: false)
+            switchCanReshare.setOn(false, animated: false)
         }
         
         // Set expiration date
-        if tableShare != nil && tableShare!.expirationDate != nil {
+        if tableShare.expirationDate != nil {
             switchSetExpirationDate.setOn(true, animated: false)
             fieldSetExpirationDate.isEnabled = true
             
             let dateFormatter = DateFormatter()
             dateFormatter.formatterBehavior = .behavior10_4
             dateFormatter.dateStyle = .medium
-            fieldSetExpirationDate.text = dateFormatter.string(from: tableShare!.expirationDate! as Date)
+            fieldSetExpirationDate.text = dateFormatter.string(from: tableShare.expirationDate! as Date)
         } else {
             switchSetExpirationDate.setOn(false, animated: false)
             fieldSetExpirationDate.isEnabled = false
@@ -107,15 +109,38 @@ class NCShareUserMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
         }
         
         // Note to recipient
-        if tableShare != nil {
-            fieldNoteToRecipient.text = tableShare!.note
-        } else {
-            fieldNoteToRecipient.text = ""
-        }
+        fieldNoteToRecipient.text = tableShare.note
     }
     
     // MARK: - IBAction
 
+    // Can reshare
+    @IBAction func switchCanReshareChanged(sender: UISwitch) {
+        
+        guard let tableShare = self.tableShare else { return }
+        
+        let canEdit = UtilsFramework.isAnyPermission(toEdit: tableShare.permissions)
+        var permission: Int = 0
+        
+        if sender.isOn {
+            if canEdit {
+                permission = UtilsFramework.getPermissionsValue(byCanEdit: true, andCanCreate: true, andCanChange: true, andCanDelete: true, andCanShare: true, andIsFolder: metadata!.directory)
+            } else {
+                permission = UtilsFramework.getPermissionsValue(byCanEdit: false, andCanCreate: false, andCanChange: false, andCanDelete: false, andCanShare: true, andIsFolder: metadata!.directory)
+            }
+        } else {
+            if canEdit {
+                permission = UtilsFramework.getPermissionsValue(byCanEdit: true, andCanCreate: true, andCanChange: true, andCanDelete: true, andCanShare: false, andIsFolder: metadata!.directory)
+            } else {
+                permission = UtilsFramework.getPermissionsValue(byCanEdit: false, andCanCreate: false, andCanChange: false, andCanDelete: false, andCanShare: false, andIsFolder: metadata!.directory)
+
+            }
+        }
+    
+        let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl,  view: self, delegate: self)
+        networking.updateShare(idRemoteShared: tableShare.idRemoteShared, password: nil, permission: permission, note: nil, expirationTime: nil, hideDownload: tableShare.hideDownload)
+    }
+    
     // Set expiration date
     @IBAction func switchSetExpirationDate(sender: UISwitch) {
         

+ 3 - 0
iOSClient/Share/NCShareUserMenuView.xib

@@ -17,6 +17,9 @@
             <subviews>
                 <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="sjf-wF-y07">
                     <rect key="frame" x="10" y="10" width="51" height="31"/>
+                    <connections>
+                        <action selector="switchCanReshareChangedWithSender:" destination="iN0-l3-epB" eventType="valueChanged" id="Ezn-AP-uEh"/>
+                    </connections>
                 </switch>
                 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Can reshare" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IHP-P8-rm2">
                     <rect key="frame" x="70" y="18" width="240" height="15"/>