|
@@ -566,4 +566,297 @@ class CreateFormUploadAssets: XLFormViewController, CCMoveDelegate {
|
|
|
|
|
|
}
|
|
|
|
|
|
+class CreateFormUploadFile: XLFormViewController, CCMoveDelegate {
|
|
|
+
|
|
|
+ var serverUrl : String = ""
|
|
|
+ var titleServerUrl : String?
|
|
|
+ var assets: NSMutableArray = []
|
|
|
+ var cryptated : Bool = false
|
|
|
+ var session : String = ""
|
|
|
+ weak var delegate: createFormUploadAssetsDelegate?
|
|
|
+
|
|
|
+ let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
+
|
|
|
+ convenience init(_ titleServerUrl : String?, serverUrl : String, assets : NSMutableArray, cryptated : Bool, session : String, delegate: createFormUploadAssetsDelegate) {
|
|
|
+
|
|
|
+ self.init()
|
|
|
+
|
|
|
+ if titleServerUrl == nil || titleServerUrl?.isEmpty == true {
|
|
|
+ self.titleServerUrl = "/"
|
|
|
+ } else {
|
|
|
+ self.titleServerUrl = titleServerUrl
|
|
|
+ }
|
|
|
+
|
|
|
+ self.serverUrl = serverUrl
|
|
|
+ self.session = session
|
|
|
+ self.delegate = delegate
|
|
|
+
|
|
|
+ self.initializeForm()
|
|
|
+ }
|
|
|
+
|
|
|
+ //MARK: XLFormDescriptorDelegate
|
|
|
+
|
|
|
+ func initializeForm() {
|
|
|
+
|
|
|
+ let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor
|
|
|
+ form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow
|
|
|
+
|
|
|
+ var section : XLFormSectionDescriptor
|
|
|
+ var row : XLFormRowDescriptor
|
|
|
+
|
|
|
+ // Section: Destination Folder
|
|
|
+
|
|
|
+ section = XLFormSectionDescriptor.formSection()
|
|
|
+ form.addFormSection(section)
|
|
|
+ row = XLFormRowDescriptor(tag: "ButtonDestinationFolder", rowType: XLFormRowDescriptorTypeButton, title: self.titleServerUrl)
|
|
|
+ let imageFolder = CCGraphics.changeThemingColorImage(UIImage(named: "folder")!, color: NCBrandColor.sharedInstance.brand) as UIImage
|
|
|
+ row.cellConfig.setObject(imageFolder, forKey: "imageView.image" as NSCopying)
|
|
|
+ row.cellConfig.setObject(UIColor.black, forKey: "textLabel.textColor" as NSCopying)
|
|
|
+ row.action.formSelector = #selector(changeDestinationFolder(_:))
|
|
|
+ section.addFormRow(row)
|
|
|
+
|
|
|
+ // Section: Rename File Name
|
|
|
+
|
|
|
+ section = XLFormSectionDescriptor.formSection()
|
|
|
+ form.addFormSection(section)
|
|
|
+
|
|
|
+ row = XLFormRowDescriptor(tag: "fileName", rowType: XLFormRowDescriptorTypeAccount, title: NSLocalizedString("_filename_", comment: ""))
|
|
|
+
|
|
|
+ let fileNameMask : String = CCUtility.getFileNameMask(k_keyFileNameMask)
|
|
|
+ if fileNameMask.characters.count > 0 {
|
|
|
+ row.value = fileNameMask
|
|
|
+ }
|
|
|
+ section.addFormRow(row)
|
|
|
+
|
|
|
+ // Section: Preview File Name
|
|
|
+
|
|
|
+ row = XLFormRowDescriptor(tag: "previewFileName", rowType: XLFormRowDescriptorTypeTextView, title: "")
|
|
|
+ row.height = 180
|
|
|
+ row.cellConfig.setObject(NCBrandColor.sharedInstance.tableBackground, forKey: "backgroundColor" as NSCopying)
|
|
|
+ row.cellConfig.setObject(NCBrandColor.sharedInstance.tableBackground, forKey: "textView.backgroundColor" as NSCopying)
|
|
|
+
|
|
|
+ row.disabled = true
|
|
|
+ section.addFormRow(row)
|
|
|
+
|
|
|
+ self.form = form
|
|
|
+ }
|
|
|
+
|
|
|
+ override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) {
|
|
|
+
|
|
|
+ super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue)
|
|
|
+
|
|
|
+ if formRow.tag == "fileName" {
|
|
|
+
|
|
|
+ let fileName = formRow.value as? String
|
|
|
+
|
|
|
+ self.form.delegate = nil
|
|
|
+
|
|
|
+ if let fileName = fileName {
|
|
|
+ formRow.value = CCUtility.removeForbiddenCharactersServer(fileName)
|
|
|
+ }
|
|
|
+
|
|
|
+ self.form.delegate = self
|
|
|
+
|
|
|
+ let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
|
|
|
+ previewFileName.value = self.previewFileName(valueRename: formRow.value as? String)
|
|
|
+
|
|
|
+ // reload cell
|
|
|
+ if fileName != nil {
|
|
|
+
|
|
|
+ if newValue as! String != formRow.value as! String {
|
|
|
+
|
|
|
+ self.reloadFormRow(formRow)
|
|
|
+
|
|
|
+ appDelegate.messageNotification("_info_", description: "_forbidden_characters_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.info, errorCode: 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.reloadFormRow(previewFileName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: - View Life Cycle
|
|
|
+
|
|
|
+ override func viewDidLoad() {
|
|
|
+
|
|
|
+ super.viewDidLoad()
|
|
|
+
|
|
|
+ let cancelButton : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: UIBarButtonItemStyle.plain, target: self, action: #selector(cancel))
|
|
|
+ let saveButton : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_save_", comment: ""), style: UIBarButtonItemStyle.plain, target: self, action: #selector(save))
|
|
|
+
|
|
|
+ self.navigationItem.leftBarButtonItem = cancelButton
|
|
|
+ self.navigationItem.rightBarButtonItem = saveButton
|
|
|
+
|
|
|
+ self.navigationController?.navigationBar.isTranslucent = false
|
|
|
+ self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand
|
|
|
+ self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.navigationBarText
|
|
|
+ self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: NCBrandColor.sharedInstance.navigationBarText]
|
|
|
+
|
|
|
+ self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none
|
|
|
+
|
|
|
+ self.tableView.backgroundColor = NCBrandColor.sharedInstance.tableBackground
|
|
|
+
|
|
|
+ self.reloadForm()
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewWillDisappear(_ animated: Bool)
|
|
|
+ {
|
|
|
+ super.viewWillDisappear(animated)
|
|
|
+
|
|
|
+ //self.delegate?.dismissFormUploadAssets()
|
|
|
+ }
|
|
|
+
|
|
|
+ func reloadForm() {
|
|
|
+
|
|
|
+ self.form.delegate = nil
|
|
|
+
|
|
|
+ let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
|
|
|
+ buttonDestinationFolder.title = self.titleServerUrl
|
|
|
+
|
|
|
+ let maskFileName : XLFormRowDescriptor = self.form.formRow(withTag: "maskFileName")!
|
|
|
+ let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
|
|
|
+ previewFileName.value = self.previewFileName(valueRename: maskFileName.value as? String)
|
|
|
+
|
|
|
+ self.tableView.reloadData()
|
|
|
+ self.form.delegate = self
|
|
|
+ }
|
|
|
+
|
|
|
+ //MARK: TableView
|
|
|
+
|
|
|
+ override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
|
|
+
|
|
|
+ switch section {
|
|
|
+
|
|
|
+ case 0:
|
|
|
+ let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
|
|
|
+
|
|
|
+ if buttonDestinationFolder.isHidden() {
|
|
|
+ return ""
|
|
|
+ } else {
|
|
|
+ return " " + NSLocalizedString("_destination_folder_", comment: "")
|
|
|
+ }
|
|
|
+ case 1:
|
|
|
+ return " " + NSLocalizedString("_use_folder_photos_", comment: "")
|
|
|
+ case 2:
|
|
|
+ return " " + NSLocalizedString("_add_filenametype_", comment: "")
|
|
|
+ case 3:
|
|
|
+ return " " + NSLocalizedString("_rename_filename_", comment: "")
|
|
|
+ case 4:
|
|
|
+ return NSLocalizedString("_preview_filename_", comment: "")
|
|
|
+ default:
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
|
|
+
|
|
|
+ switch section {
|
|
|
+
|
|
|
+ /*
|
|
|
+ case 2:
|
|
|
+ let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "maskFileName")!
|
|
|
+ let text = self.writePreviewFileName(buttonDestinationFolder)
|
|
|
+ return text
|
|
|
+ */
|
|
|
+
|
|
|
+ default:
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: - Action
|
|
|
+
|
|
|
+ func moveServerUrl(to serverUrlTo: String!, title: String!) {
|
|
|
+
|
|
|
+ self.serverUrl = serverUrlTo
|
|
|
+
|
|
|
+ if let title = title {
|
|
|
+
|
|
|
+ self.titleServerUrl = title
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ self.titleServerUrl = "/"
|
|
|
+ }
|
|
|
+
|
|
|
+ self.reloadForm()
|
|
|
+ }
|
|
|
+
|
|
|
+ func save() {
|
|
|
+
|
|
|
+ self.dismiss(animated: true, completion: {
|
|
|
+
|
|
|
+ let useFolderPhotoRow : XLFormRowDescriptor = self.form.formRow(withTag: "useFolderPhoto")!
|
|
|
+ let useSubFolderRow : XLFormRowDescriptor = self.form.formRow(withTag: "useSubFolder")!
|
|
|
+ var useSubFolder : Bool = false
|
|
|
+
|
|
|
+ if (useFolderPhotoRow.value! as AnyObject).boolValue == true {
|
|
|
+
|
|
|
+ self.serverUrl = NCManageDatabase.sharedInstance.getAccountAutoUploadPath(self.appDelegate.activeUrl)
|
|
|
+ useSubFolder = (useSubFolderRow.value! as AnyObject).boolValue
|
|
|
+ }
|
|
|
+
|
|
|
+ self.appDelegate.activeMain.uploadFileAsset(self.assets, serverUrl: self.serverUrl, cryptated: self.cryptated, useSubFolder: useSubFolder, session: self.session)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ func cancel() {
|
|
|
+
|
|
|
+ self.dismiss(animated: true, completion: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: - Utility
|
|
|
+
|
|
|
+ func previewFileName(valueRename : String?) -> String {
|
|
|
+
|
|
|
+ var returnString : String = ""
|
|
|
+ let asset = assets[0] as! PHAsset
|
|
|
+
|
|
|
+ if let valueRename = valueRename {
|
|
|
+
|
|
|
+ let valueRenameTrimming = valueRename.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
|
|
|
+
|
|
|
+ if valueRenameTrimming.characters.count > 0 {
|
|
|
+
|
|
|
+ self.form.delegate = nil
|
|
|
+ CCUtility.setFileNameMask(valueRenameTrimming, key: k_keyFileNameMask)
|
|
|
+ self.form.delegate = self
|
|
|
+
|
|
|
+ returnString = CCUtility.createFileName(asset.value(forKey: "filename"), fileDate: asset.creationDate, fileType: asset.mediaType, keyFileName: k_keyFileNameMask, keyFileNameType: k_keyFileNameType)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ CCUtility.setFileNameMask("", key: k_keyFileNameMask)
|
|
|
+ returnString = CCUtility.createFileName(asset.value(forKey: "filename"), fileDate: asset.creationDate, fileType: asset.mediaType, keyFileName: nil, keyFileNameType: k_keyFileNameType)
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ CCUtility.setFileNameMask("", key: k_keyFileNameMask)
|
|
|
+ returnString = CCUtility.createFileName(asset.value(forKey: "filename"), fileDate: asset.creationDate, fileType: asset.mediaType, keyFileName: nil, keyFileNameType: k_keyFileNameType)
|
|
|
+ }
|
|
|
+
|
|
|
+ return NSLocalizedString("_preview_filename_", comment: "") + ":" + "\n\n" + returnString
|
|
|
+ }
|
|
|
+
|
|
|
+ func changeDestinationFolder(_ sender: XLFormRowDescriptor) {
|
|
|
+
|
|
|
+ self.deselectFormRow(sender)
|
|
|
+
|
|
|
+ let storyboard : UIStoryboard = UIStoryboard(name: "CCMove", bundle: nil)
|
|
|
+ let navigationController = storyboard.instantiateViewController(withIdentifier: "CCMove") as! UINavigationController
|
|
|
+ let viewController : CCMove = navigationController.topViewController as! CCMove
|
|
|
+
|
|
|
+ viewController.delegate = self;
|
|
|
+ viewController.tintColor = NCBrandColor.sharedInstance.navigationBarText
|
|
|
+ viewController.barTintColor = NCBrandColor.sharedInstance.brand
|
|
|
+ viewController.tintColorTitle = NCBrandColor.sharedInstance.navigationBarText
|
|
|
+ viewController.move.title = NSLocalizedString("_select_", comment: "");
|
|
|
+ viewController.networkingOperationQueue = appDelegate.netQueue
|
|
|
+
|
|
|
+ navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
|
|
|
+ self.present(navigationController, animated: true, completion: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
|