marinofaggiana 6 жил өмнө
parent
commit
56450d85fb

+ 1 - 1
iOSClient/Networking/NCService.swift

@@ -321,7 +321,7 @@ class NCService: NSObject {
         
         let professions = CCUtility.getHCBusinessType()
         if professions != nil && professions!.count > 0 {
-            OCNetworking.sharedManager()?.putHCUserProfile(withAccount: appDelegate.activeAccount, serverUrl: appDelegate.activeUrl, professions: professions, completion: { (account, message, errorCode) in
+            OCNetworking.sharedManager()?.putHCUserProfile(withAccount: appDelegate.activeAccount, serverUrl: appDelegate.activeUrl, address: nil, businesssize: nil, businesstype: professions, city: nil, company: nil, country: nil, displayname: nil, email: nil, phone: nil, role_: nil, twitter: nil, website: nil, zip: nil, completion: { (account, message, errorCode) in
                 if errorCode == 0 && account == self.appDelegate.activeAccount {
                     CCUtility.setHCBusinessType(nil)
                     OCNetworking.sharedManager()?.getHCUserProfile(withAccount: self.appDelegate.activeAccount, serverUrl: self.appDelegate.activeUrl, completion: { (account, userProfile, message, errorCode) in

+ 1 - 1
iOSClient/Networking/OCNetworking.h

@@ -105,7 +105,7 @@
 #pragma mark ===== Third Parts =====
 
 - (void)getHCUserProfileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl completion:(void (^)(NSString *account, OCUserProfile *userProfile, NSString *message, NSInteger errorCode))completion;
-- (void)putHCUserProfileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl professions:(NSString *)professions completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
+- (void)putHCUserProfileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl address:(NSString *)address businesssize:(NSString *)businesssize businesstype:(NSString *)businesstype city:(NSString *)city company:(NSString *)company  country:(NSString *)country displayname:(NSString *)displayname email:(NSString *)email phone:(NSString *)phone role_:(NSString *)role_ twitter:(NSString *)twitter website:(NSString *)website zip:(NSString *)zip completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
 - (void)getHCFeaturesWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl completion:(void (^)(NSString *account, HCFeatures *features, NSString *message, NSInteger errorCode))completion;
 
 @end

+ 15 - 2
iOSClient/Networking/OCNetworking.m

@@ -1992,7 +1992,7 @@
     }];
 }
 
-- (void)putHCUserProfileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl professions:(NSString *)professions completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
+- (void)putHCUserProfileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl address:(NSString *)address businesssize:(NSString *)businesssize businesstype:(NSString *)businesstype city:(NSString *)city company:(NSString *)company  country:(NSString *)country displayname:(NSString *)displayname email:(NSString *)email phone:(NSString *)phone role_:(NSString *)role_ twitter:(NSString *)twitter website:(NSString *)website zip:(NSString *)zip completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -2000,7 +2000,20 @@
     }
     
     // Create JSON
-    NSDictionary *dataDic = @{@"businesstype": professions};
+    NSMutableDictionary *dataDic = [NSMutableDictionary new];
+    if (address) [dataDic setValue:address forKey:@"address"];
+    if (businesssize) [dataDic setValue:businesssize forKey:@"businesssize"];
+    if (businesstype) [dataDic setValue:businesstype forKey:@"businesstype"];
+    if (city) [dataDic setValue:city forKey:@"city"];
+    if (company) [dataDic setValue:company forKey:@"company"];
+    if (country) [dataDic setValue:country forKey:@"country"];
+    if (displayname) [dataDic setValue:displayname forKey:@"displayname"];
+    if (email) [dataDic setValue:email forKey:@"email"];
+    if (phone) [dataDic setValue:phone forKey:@"phone"];
+    if (role_) [dataDic setValue:role_ forKey:@"role"];
+    if (twitter) [dataDic setValue:twitter forKey:@"twitter"];
+    if (website) [dataDic setValue:website forKey:@"website"];
+    if (zip) [dataDic setValue:zip forKey:@"zip"];
     NSString *data = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dataDic options:0 error:nil] encoding:NSUTF8StringEncoding];
 
     NSString *serverPath = [NSString stringWithFormat:@"%@/ocs/v2.php/apps/handwerkcloud/api/v1/settings/%@", serverUrl, tableAccount.userID];

+ 62 - 7
iOSClient/Settings/HCEditProfile.swift

@@ -26,7 +26,8 @@ import Foundation
 class HCEditProfile: XLFormViewController {
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
-    
+    var backButton : UIBarButtonItem!
+
     required init(coder aDecoder: NSCoder) {
         super.init(coder: aDecoder)
     }
@@ -54,6 +55,7 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "user"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.value = tableAccount?.displayName
+        if row.value == nil { row.value = "" }
         section.addFormRow(row)
 
         row = XLFormRowDescriptor(tag: "useraddress", rowType: XLFormRowDescriptorTypeText, title: NSLocalizedString("_user_address_", comment: ""))
@@ -62,6 +64,7 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "address"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.value = tableAccount?.address
+        if row.value == nil { row.value = "" }
         section.addFormRow(row)
         
         row = XLFormRowDescriptor(tag: "usercity", rowType: XLFormRowDescriptorTypeText, title: NSLocalizedString("_user_city_", comment: ""))
@@ -70,6 +73,7 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "city"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.value = tableAccount?.city
+        if row.value == nil { row.value = "" }
         section.addFormRow(row)
         
         row = XLFormRowDescriptor(tag: "userzip", rowType: XLFormRowDescriptorTypeZipCode, title: NSLocalizedString("_user_zip_", comment: ""))
@@ -78,6 +82,7 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "cityzip"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.value = tableAccount?.zip
+        if row.value == nil { row.value = "" }
         section.addFormRow(row)
         
         row = XLFormRowDescriptor(tag: "usercountry", rowType: XLFormRowDescriptorTypeSelectorPickerView, title: NSLocalizedString("_user_country_", comment: ""))
@@ -93,6 +98,7 @@ class HCEditProfile: XLFormViewController {
             locales.append(countryName)
         }
         row.selectorOptions = locales.sorted()
+        if row.value == nil { row.value = "" }
         section.addFormRow(row)
         
         row = XLFormRowDescriptor(tag: "userphone", rowType: XLFormRowDescriptorTypePhone, title: NSLocalizedString("_user_phone_", comment: ""))
@@ -101,6 +107,7 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "phone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.value = tableAccount?.phone
+        if row.value == nil { row.value = "" }
         section.addFormRow(row)
         
         row = XLFormRowDescriptor(tag: "useremail", rowType: XLFormRowDescriptorTypeEmail, title: NSLocalizedString("_user_email_", comment: ""))
@@ -109,6 +116,7 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "email"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.value = tableAccount?.email
+        if row.value == nil { row.value = "" }
         section.addFormRow(row)
         
         row = XLFormRowDescriptor(tag: "userweb", rowType: XLFormRowDescriptorTypeEmail, title: NSLocalizedString("_user_web_", comment: ""))
@@ -117,6 +125,7 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "web"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.value = tableAccount?.webpage
+        if row.value == nil { row.value = "" }
         section.addFormRow(row)
         
         row = XLFormRowDescriptor(tag: "usertwitter", rowType: XLFormRowDescriptorTypeTwitter, title: NSLocalizedString("_user_twitter_", comment: ""))
@@ -125,6 +134,7 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "twitter"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.value = tableAccount?.twitter
+        if row.value == nil { row.value = "" }
         section.addFormRow(row)
         
         row = XLFormRowDescriptor(tag: "userbusinesstype", rowType: XLFormRowDescriptorTypeMultipleSelector, title: NSLocalizedString("_user_businesstype_", comment: ""))
@@ -133,6 +143,7 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "businesstype"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.selectorOptions = ["ARCHITECT","BRICKLAYER","CARPENTER","ELECTRICIAN","INSTALLER","PAINTER","PLUMBER","ROOFER","STOVEBUILDER","STUCCOER","WINDOWBUILDER","OTHER"]
         row.value = tableAccount?.businessType.components(separatedBy: ",")
+        if row.value == nil { row.value = "" }
         section.addFormRow(row)
         
         row = XLFormRowDescriptor(tag: "userbusinesssize", rowType: XLFormRowDescriptorTypeSelectorPickerView, title: NSLocalizedString("_user_businesssize_", comment: ""))
@@ -150,7 +161,7 @@ class HCEditProfile: XLFormViewController {
         case 250: row.value = "250-499"
         case 500: row.value = "500-999"
         case 1000: row.value = "1000+"
-        default: break
+        default: row.value = ""
         }
         section.addFormRow(row)
         
@@ -159,9 +170,10 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["detailTextLabel.font"] = UIFont.systemFont(ofSize: 15.0)
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "role"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.selectorOptions = [NSLocalizedString("_user_owner_", comment: ""),NSLocalizedString("_user_employee_", comment: ""),NSLocalizedString("_user_contractor_", comment: "")];
-        if tableAccount?.role == "owner"      { row.value = NSLocalizedString("_user_owner_", comment: "") }
-        if tableAccount?.role == "employee"   { row.value = NSLocalizedString("_user_employee_", comment: "") }
-        if tableAccount?.role == "contractor" { row.value = NSLocalizedString("_user_contractor_", comment: "") }
+        if tableAccount?.role == "owner" { row.value = NSLocalizedString("_user_owner_", comment: "") }
+        else if tableAccount?.role == "employee" { row.value = NSLocalizedString("_user_employee_", comment: "") }
+        else if tableAccount?.role == "contractor" { row.value = NSLocalizedString("_user_contractor_", comment: "") }
+        else { row.value = "" }
         section.addFormRow(row)
         
         row = XLFormRowDescriptor(tag: "usercompany", rowType: XLFormRowDescriptorTypeText, title: NSLocalizedString("_user_company_", comment: ""))
@@ -170,20 +182,19 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "company"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.value = tableAccount?.company
+        if row.value == nil { row.value = "" }
         section.addFormRow(row)
         
         self.form = form
     }
     
     override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) {
-        
         super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue)
     }
     
     // MARK: - View Life Cycle
     
     override func viewDidLoad() {
-        
         super.viewDidLoad()
         
         self.navigationItem.title = NSLocalizedString("_user_editprofile_", comment: "")
@@ -193,9 +204,53 @@ class HCEditProfile: XLFormViewController {
         self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.brandText
         self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: NCBrandColor.sharedInstance.brandText]
         
+        // Replace the default back button
+        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
+        self.navigationItem.setHidesBackButton(true, animated: false)
+        self.backButton = UIBarButtonItem(title: NSLocalizedString("_manage_account_", comment: ""), style: UIBarButtonItem.Style.plain, target: self, action: #selector(goBack))
+        self.navigationItem.leftBarButtonItem = backButton
+        
         self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
     
         initializeForm()
     }
     
+    @objc func goBack() {
+        
+        NCUtility.sharedInstance.startActivityIndicator(view: self.view, bottom: 0)
+        
+        let displayname = self.form.formRow(withTag: "userfullname")!.value as! String
+        let address = self.form.formRow(withTag: "useraddress")!.value as! String
+        let city = self.form.formRow(withTag: "usercity")!.value as! String
+        let zip = self.form.formRow(withTag: "userzip")!.value as! String
+        
+        var country = ""
+        let countryNameRow = self.form.formRow(withTag: "usercountry")!.value as? String
+        for localeCode in NSLocale.isoCountryCodes {
+            let countryName = (Locale.current as NSLocale).displayName(forKey: .countryCode, value: localeCode) ?? ""
+            if countryNameRow == countryName {
+                country = localeCode
+                break
+            }
+        }
+        let phone = self.form.formRow(withTag: "userphone")!.value as! String
+        let email = self.form.formRow(withTag: "useremail")!.value as! String
+        let website = self.form.formRow(withTag: "userweb")!.value as! String
+        let twitter = self.form.formRow(withTag: "usertwitter")!.value as! String
+        let company = self.form.formRow(withTag: "usercompany")!.value as! String
+        let businesssize = self.form.formRow(withTag: "userbusinesssize")!.value as! String
+        let role_ = self.form.formRow(withTag: "userrole")!.value as! String
+        let businesstypeArray = self.form.formRow(withTag: "userbusinesstype")!.value
+        let businesstype =  (businesstypeArray as! [String]).joined(separator: ",")
+        
+        OCNetworking.sharedManager()?.putHCUserProfile(withAccount: appDelegate.activeAccount, serverUrl: appDelegate.activeUrl, address: address, businesssize: businesssize, businesstype: businesstype, city: city, company: company, country: country, displayname: displayname, email: email, phone: phone, role_: role_, twitter: twitter, website: website, zip: zip, completion: { (account, message, errorCode) in
+            if errorCode == 0 && account == self.appDelegate.activeAccount {
+                self.navigationController?.popViewController(animated: true)
+                self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true
+            } else if errorCode != 0 {
+                self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+            }
+            NCUtility.sharedInstance.stopActivityIndicator()
+        })
+    }
 }