CCAccountWeb.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // CCAccountWeb.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/11/14.
  6. // Copyright (c) 2014 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCAccountWeb.h"
  24. #import "AppDelegate.h"
  25. @interface CCAccountWeb()
  26. {
  27. XLFormDescriptor *form ;
  28. NSTimer* myTimer;
  29. NSMutableDictionary *field;
  30. CCTemplates *templates;
  31. NSString *_saveFileID;
  32. }
  33. @end
  34. @implementation CCAccountWeb
  35. - (id)initWithDelegate:(id <CCAccountWebDelegate>)delegate fileName:(NSString *)fileName uuid:(NSString *)uuid fileID:(NSString *)fileID isLocal:(BOOL)isLocal serverUrl:(NSString *)serverUrl
  36. {
  37. self = [super init];
  38. if (self){
  39. self.delegate = delegate;
  40. self.fileName = fileName;
  41. self.isLocal = isLocal;
  42. self.fileID = fileID;
  43. self.uuid = uuid;
  44. self.serverUrl = serverUrl;
  45. // if fileName read Crypto File
  46. if (fileName)
  47. field = [[CCCrypto sharedManager] getDictionaryEncrypted:fileName uuid:uuid isLocal:isLocal directoryUser:app.directoryUser];
  48. XLFormSectionDescriptor *section;
  49. XLFormRowDescriptor *row;
  50. // Information - Section
  51. form = [XLFormDescriptor formDescriptor];
  52. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_title_", nil)];
  53. [form addFormSection:section];
  54. if (!fileName) form.assignFirstResponderOnShow = YES;
  55. // Title
  56. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"titolo" rowType:XLFormRowDescriptorTypeText];
  57. [row.cellConfig setObject:COLOR_CRYPTOCLOUD forKey:@"textField.textColor"];
  58. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  59. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  60. row.value = [field objectForKey:@"titolo"];
  61. row.required = YES;
  62. [section addFormRow:row];
  63. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_web_account_data_", nil)];
  64. [form addFormSection:section];
  65. // url
  66. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"url" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_url:_", nil)];
  67. [row.cellConfig setObject:COLOR_TEXT_ANTHRACITE forKey:@"textField.textColor"];
  68. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  69. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  70. row.value = [field objectForKey:@"url"];
  71. [section addFormRow:row];
  72. // Login
  73. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"login" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_login:_", nil)];
  74. [row.cellConfig setObject:COLOR_TEXT_ANTHRACITE forKey:@"textField.textColor"];
  75. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  76. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  77. row.value = [field objectForKey:@"login"];
  78. [section addFormRow:row];
  79. // Password
  80. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"password" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_password:_", nil)];
  81. [row.cellConfig setObject:COLOR_TEXT_ANTHRACITE forKey:@"textField.textColor"];
  82. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  83. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  84. row.value = [field objectForKey:@"password"];
  85. [section addFormRow:row];
  86. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_notes_", nil)];
  87. [form addFormSection:section];
  88. // Note
  89. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"note" rowType:XLFormRowDescriptorTypeTextView];
  90. row.value = [field objectForKey:@"note"];
  91. [row.cellConfig setObject:COLOR_TEXT_ANTHRACITE forKey:@"textView.textColor"];
  92. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textView.font"];
  93. [section addFormRow:row];
  94. self.form = form;
  95. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPressed:)];
  96. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(savePressed:)];
  97. }
  98. return self;
  99. }
  100. - (void)viewDidLoad
  101. {
  102. [super viewDidLoad];
  103. templates = [[CCTemplates alloc] init];
  104. [templates setImageTitle:NSLocalizedString(@"_web_account_", nil) conNavigationItem:self.navigationItem reachability:[app.reachability isReachable]];
  105. // Color
  106. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  107. }
  108. - (void)viewDidAppear:(BOOL)animated
  109. {
  110. [super viewDidAppear:animated];
  111. if (self.fileName && !field) [self performSelector:@selector(cancelPressed:) withObject:nil afterDelay:0.5];
  112. }
  113. - (void)didSelectFormRow:(XLFormRowDescriptor *)formRow
  114. {
  115. [super didSelectFormRow:formRow];
  116. if ([formRow.tag isEqual:@"mytag"]) {
  117. // do your thing for your row.
  118. }
  119. }
  120. #pragma --------------------------------------------------------------------------------------------
  121. #pragma mark - ==== IBAction ====
  122. #pragma --------------------------------------------------------------------------------------------
  123. - (IBAction)cancelPressed:(UIBarButtonItem * __unused)button
  124. {
  125. [self dismissViewControllerAnimated:YES completion:nil];
  126. }
  127. - (IBAction)savePressed:(UIBarButtonItem * __unused)button
  128. {
  129. NSString *fileNameModel;
  130. NSArray *validationErrors = [self formValidationErrors];
  131. if (validationErrors.count > 0){
  132. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_enter_title_", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_ok_", nil) otherButtonTitles:nil];
  133. [alertView show];
  134. return;
  135. }
  136. [self.tableView endEditing:YES];
  137. fileNameModel = [templates salvaForm:form fileName:self.fileName uuid:self.uuid modello:@"accountweb" icona:@"accountweb"];
  138. if (fileNameModel) {
  139. XLFormRowDescriptor *titolo = [self.form formRowWithTag:@"titolo"];
  140. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  141. metadataNet.action = actionUploadTemplate;
  142. metadataNet.serverUrl = self.serverUrl;
  143. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  144. metadataNet.fileNamePrint = titolo.value;
  145. metadataNet.pathFolder = NSTemporaryDirectory();
  146. metadataNet.session = k_upload_session_foreground;
  147. metadataNet.taskStatus = k_taskStatusResume;
  148. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  149. }
  150. }
  151. - (void)uploadFileFailure:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  152. {
  153. if (![_saveFileID isEqualToString:fileID]) {
  154. _saveFileID = fileID;
  155. [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  156. // remove the file
  157. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount]];
  158. [self.delegate readFolderWithForced:YES serverUrl:self.serverUrl];
  159. }
  160. }
  161. - (void)uploadFileSuccess:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  162. {
  163. [self dismissViewControllerAnimated:YES completion:nil];
  164. }
  165. @end