123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import UIKit
- extension UIAlertController {
-
-
-
-
-
-
- static func createFolder(serverUrl: String, urlBase: NCUserBaseUrl, completion: ((_ errorCode: Int, _ errorDescription: String) -> Void)? = nil) -> UIAlertController {
- let alertController = UIAlertController(title: NSLocalizedString("_create_folder_", comment: ""), message: nil, preferredStyle: .alert)
- let okAction = UIAlertAction(title: NSLocalizedString("_save_", comment: ""), style: .default, handler: { _ in
- guard let fileNameFolder = alertController.textFields?.first?.text else { return }
- NCNetworking.shared.createFolder(fileName: fileNameFolder, serverUrl: serverUrl, account: urlBase.account, urlBase: urlBase.urlBase, overwrite: false) { errorCode, errorDescription in
- if let completion = completion {
- completion(errorCode, errorDescription)
- } else if errorCode != 0 {
- NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
- }
- }
- })
-
- okAction.isEnabled = false
- let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel)
- alertController.addTextField { textField in
- textField.autocapitalizationType = .words
- }
-
- NotificationCenter.default.addObserver(
- forName: UITextField.textDidChangeNotification,
- object: alertController.textFields?.first,
- queue: .main) { _ in
- guard let text = alertController.textFields?.first?.text,
- let folderName = CCUtility.removeForbiddenCharactersServer(text)?.trimmingCharacters(in: .whitespaces) else { return }
- okAction.isEnabled = !folderName.isEmpty && folderName != "." && folderName != ".."
- }
- alertController.addAction(cancelAction)
- alertController.addAction(okAction)
- return alertController
- }
- }
|