CCCartaIdentita.m 10 KB

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