CCContoCorrente.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. //
  2. // CCContoCorrente.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 "CCContoCorrente.h"
  24. #import "AppDelegate.h"
  25. @interface CCContoCorrente()
  26. {
  27. XLFormDescriptor *form ;
  28. NSTimer* myTimer;
  29. NSMutableDictionary *field;
  30. CCTemplates *templates;
  31. NSString *_saveFileID;
  32. }
  33. @end
  34. @implementation CCContoCorrente
  35. - (id)initWithDelegate:(id <CCContoCorrenteDelegate>)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(@"_bank_account_data_", nil)];
  64. [form addFormSection:section];
  65. // Nome Banca
  66. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"nomebanca" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_bank_name:_", 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:@"nomebanca"];
  71. [section addFormRow:row];
  72. // Nome Conognome
  73. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"nomecognome" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_name_surname:_", 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:@"nomecognome"];
  78. [section addFormRow:row];
  79. // Numero Conto
  80. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"numeroconto" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_account_n:_", 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:@"numeroconto"];
  85. [section addFormRow:row];
  86. // IBAN
  87. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"iban" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_iban:_", nil)];
  88. [row.cellConfig setObject:COLOR_TEXT_ANTHRACITE forKey:@"textField.textColor"];
  89. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  90. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  91. row.value = [field objectForKey:@"iban"];
  92. [section addFormRow:row];
  93. // SWIFT
  94. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"swift" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_swift:_", nil)];
  95. [row.cellConfig setObject:COLOR_TEXT_ANTHRACITE forKey:@"textField.textColor"];
  96. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  97. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  98. row.value = [field objectForKey:@"swift"];
  99. [section addFormRow:row];
  100. // Filiale
  101. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"filiale" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_agency:_", nil)];
  102. [row.cellConfig setObject:COLOR_TEXT_ANTHRACITE forKey:@"textField.textColor"];
  103. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  104. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  105. row.value = [field objectForKey:@"filiale"];
  106. [section addFormRow:row];
  107. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_notes_", nil)];
  108. [form addFormSection:section];
  109. // Note
  110. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"note" rowType:XLFormRowDescriptorTypeTextView];
  111. row.value = [field objectForKey:@"note"];
  112. [row.cellConfig setObject:COLOR_TEXT_ANTHRACITE forKey:@"textView.textColor"];
  113. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textView.font"];
  114. [section addFormRow:row];
  115. self.form = form;
  116. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPressed:)];
  117. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(savePressed:)];
  118. }
  119. return self;
  120. }
  121. - (void)viewDidLoad
  122. {
  123. [super viewDidLoad];
  124. templates = [[CCTemplates alloc] init];
  125. [templates setImageTitle:NSLocalizedString(@"_bank_account_", nil) conNavigationItem:self.navigationItem reachability:[app.reachability isReachable]];
  126. // Color
  127. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  128. }
  129. - (void)viewDidAppear:(BOOL)animated
  130. {
  131. [super viewDidAppear:animated];
  132. if (self.fileName && !field) [self performSelector:@selector(cancelPressed:) withObject:nil afterDelay:0.5];
  133. }
  134. - (void)didSelectFormRow:(XLFormRowDescriptor *)formRow
  135. {
  136. [super didSelectFormRow:formRow];
  137. if ([formRow.tag isEqual:@"mytag"]) {
  138. // do your thing for your row.
  139. }
  140. }
  141. #pragma --------------------------------------------------------------------------------------------
  142. #pragma mark - ==== IBAction ====
  143. #pragma --------------------------------------------------------------------------------------------
  144. - (IBAction)cancelPressed:(UIBarButtonItem * __unused)button
  145. {
  146. [self dismissViewControllerAnimated:YES completion:nil];
  147. }
  148. - (IBAction)savePressed:(UIBarButtonItem * __unused)button
  149. {
  150. NSString *fileNameModel;
  151. NSArray *validationErrors = [self formValidationErrors];
  152. if (validationErrors.count > 0){
  153. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_enter_title_", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_ok_", nil) otherButtonTitles:nil];
  154. [alertView show];
  155. return;
  156. }
  157. [self.tableView endEditing:YES];
  158. fileNameModel = [templates salvaForm:form fileName:self.fileName uuid:self.uuid modello:@"contocorrente" icona:@"contocorrente"];
  159. if (fileNameModel) {
  160. XLFormRowDescriptor *titolo = [self.form formRowWithTag:@"titolo"];
  161. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  162. metadataNet.action = actionUploadTemplate;
  163. metadataNet.serverUrl = self.serverUrl;
  164. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  165. metadataNet.fileNamePrint = titolo.value;
  166. metadataNet.pathFolder = NSTemporaryDirectory();
  167. metadataNet.session = k_upload_session_foreground;
  168. metadataNet.taskStatus = k_taskStatusResume;
  169. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  170. }
  171. }
  172. - (void)uploadFileFailure:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  173. {
  174. if (![_saveFileID isEqualToString:fileID]) {
  175. _saveFileID = fileID;
  176. [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  177. // remove the file
  178. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount]];
  179. [self.delegate readFolderWithForced:YES serverUrl:self.serverUrl];
  180. }
  181. }
  182. - (void)uploadFileSuccess:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  183. {
  184. [self dismissViewControllerAnimated:YES completion:nil];
  185. }
  186. @end