CCCartaIdentita.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. //
  2. // CCCartaIdentita.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 25/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 "CCCartaIdentita.h"
  24. #import "AppDelegate.h"
  25. #ifdef CUSTOM_BUILD
  26. #import "CustomSwift.h"
  27. #else
  28. #import "Nextcloud-Swift.h"
  29. #endif
  30. @interface CCCartaIdentita()
  31. {
  32. XLFormDescriptor *form ;
  33. NSTimer* myTimer;
  34. NSMutableDictionary *field;
  35. CCTemplates *templates;
  36. NSString *_saveFileID;
  37. }
  38. @end
  39. @implementation CCCartaIdentita
  40. - (id)initWithDelegate:(id <CCCartaIdentitaDelegate>)delegate fileName:(NSString *)fileName uuid:(NSString *)uuid fileID:(NSString *)fileID isLocal:(BOOL)isLocal serverUrl:(NSString *)serverUrl
  41. {
  42. self = [super init];
  43. if (self) {
  44. self.delegate = delegate;
  45. self.fileName = fileName;
  46. self.isLocal = isLocal;
  47. self.fileID = fileID;
  48. self.uuid = uuid;
  49. self.serverUrl = serverUrl;
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  51. // if fileName read Crypto File
  52. if (fileName)
  53. field = [[CCCrypto sharedManager] getDictionaryEncrypted:fileName uuid:uuid isLocal:isLocal directoryUser:app.directoryUser];
  54. //XLFormDescriptor * form ;
  55. XLFormSectionDescriptor * section;
  56. XLFormRowDescriptor * row;
  57. // Information - Section
  58. form = [XLFormDescriptor formDescriptor];
  59. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_title_", nil)];
  60. [form addFormSection:section];
  61. if (!fileName) form.assignFirstResponderOnShow = YES;
  62. // Titolo
  63. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"titolo" rowType:XLFormRowDescriptorTypeText];
  64. [row.cellConfig setObject:[NCBrandColor sharedInstance].cryptocloud forKey:@"textField.textColor"];
  65. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  66. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  67. row.value = [field objectForKey:@"titolo"];
  68. row.required = YES;
  69. [section addFormRow:row];
  70. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_id_card_", nil)];
  71. [form addFormSection:section];
  72. // Nome Cognome
  73. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"comecognome" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_name_surname:_", nil)];
  74. [row.cellConfig setObject:[UIColor blackColor] 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:@"comecognome"];
  78. [section addFormRow:row];
  79. // Numero
  80. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"numero" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_number:_", nil)];
  81. [row.cellConfig setObject:[UIColor blackColor] 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:@"numero"];
  85. [section addFormRow:row];
  86. // Luogo di nascita
  87. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"luogonascita" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_place_of_birth:_", nil)];
  88. [row.cellConfig setObject:[UIColor blackColor] 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:@"luogonascita"];
  92. [section addFormRow:row];
  93. // Data di nascita
  94. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"datanascita" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_date_of_birth:_", nil)];
  95. [row.cellConfig setObject:[UIColor blackColor] 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:@"datanascita"];
  99. [section addFormRow:row];
  100. // Data di rilascio
  101. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"datarilascio" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_date_of_issue:_", nil)];
  102. [row.cellConfig setObject:[UIColor blackColor] 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:@"datarilascio"];
  106. [section addFormRow:row];
  107. // Data di scadenza
  108. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"datascadenza" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_date_of_expiry:_", nil)];
  109. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textField.textColor"];
  110. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  111. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  112. row.value = [field objectForKey:@"datascadenza"];
  113. [section addFormRow:row];
  114. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_notes_", nil)];
  115. [form addFormSection:section];
  116. // Note
  117. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"note" rowType:XLFormRowDescriptorTypeTextView];
  118. row.value = [field objectForKey:@"note"];
  119. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textView.textColor"];
  120. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textView.font"];
  121. [section addFormRow:row];
  122. self.form = form;
  123. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPressed:)];
  124. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(savePressed:)];
  125. }
  126. return self;
  127. }
  128. - (void)viewDidLoad
  129. {
  130. [super viewDidLoad];
  131. templates = [[CCTemplates alloc] init];
  132. [templates setImageTitle:NSLocalizedString(@"_id_card_", nil) conNavigationItem:self.navigationItem reachability:[app.reachability isReachable]];
  133. // Color
  134. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  135. }
  136. - (void)viewDidAppear:(BOOL)animated
  137. {
  138. [super viewDidAppear:animated];
  139. if (self.fileName && !field) [self performSelector:@selector(cancelPressed:) withObject:nil afterDelay:0.5];
  140. }
  141. - (void)changeTheming
  142. {
  143. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  144. }
  145. - (void)didSelectFormRow:(XLFormRowDescriptor *)formRow
  146. {
  147. [super didSelectFormRow:formRow];
  148. if ([formRow.tag isEqual:@"mytag"]) {
  149. // do your thing for your row.
  150. }
  151. }
  152. #pragma --------------------------------------------------------------------------------------------
  153. #pragma mark - ==== IBAction ====
  154. #pragma --------------------------------------------------------------------------------------------
  155. - (IBAction)cancelPressed:(UIBarButtonItem * __unused)button
  156. {
  157. [self dismissViewControllerAnimated:YES completion:nil];
  158. }
  159. - (IBAction)savePressed:(UIBarButtonItem * __unused)button
  160. {
  161. NSString *fileNameModel;
  162. NSArray *validationErrors = [self formValidationErrors];
  163. if (validationErrors.count > 0){
  164. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_enter_title_", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_ok_", nil) otherButtonTitles:nil];
  165. [alertView show];
  166. return;
  167. }
  168. [self.tableView endEditing:YES];
  169. fileNameModel = [templates salvaForm:form fileName:self.fileName uuid:self.uuid modello:@"cartaidentita" icona:@"cartaidentita"];
  170. if (fileNameModel) {
  171. XLFormRowDescriptor *titolo = [self.form formRowWithTag:@"titolo"];
  172. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  173. metadataNet.action = actionUploadTemplate;
  174. metadataNet.serverUrl = self.serverUrl;
  175. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  176. metadataNet.fileNamePrint = titolo.value;
  177. metadataNet.pathFolder = NSTemporaryDirectory();
  178. metadataNet.session = k_upload_session_foreground;
  179. metadataNet.taskStatus = k_taskStatusResume;
  180. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  181. }
  182. }
  183. - (void)uploadFileFailure:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  184. {
  185. if (![_saveFileID isEqualToString:fileID]) {
  186. _saveFileID = fileID;
  187. [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  188. // remove the file
  189. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount]];
  190. [self.delegate readFolderWithForced:YES serverUrl:self.serverUrl];
  191. }
  192. }
  193. - (void)uploadFileSuccess:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  194. {
  195. [self dismissViewControllerAnimated:YES completion:nil];
  196. }
  197. @end