CCCartaIdentita.m 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. @interface CCCartaIdentita()
  26. {
  27. XLFormDescriptor *form ;
  28. NSTimer* myTimer;
  29. NSMutableDictionary *field;
  30. CCTemplates *templates;
  31. }
  32. @end
  33. @implementation CCCartaIdentita
  34. - (id)initWithDelegate:(id <CCCartaIdentitaDelegate>)delegate fileName:(NSString *)fileName uuid:(NSString *)uuid rev:(NSString *)rev fileID:(NSString *)fileID modelReadOnly:(BOOL)modelReadOnly isLocal:(BOOL)isLocal serverUrl:(NSString *)serverUrl
  35. {
  36. self = [super init];
  37. if (self){
  38. self.delegate = delegate;
  39. self.fileName = fileName;
  40. self.isLocal = isLocal;
  41. self.rev = rev;
  42. self.fileID = fileID;
  43. self.uuid = uuid;
  44. self.serverUrl = serverUrl;
  45. CCCrypto *crypto = [[CCCrypto alloc] init];
  46. // if fileName read Crypto File
  47. if (fileName)
  48. field = [crypto 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:COLOR_ENCRYPTED 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:COLOR_GRAY 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. if (modelReadOnly) row.disabled = @YES;
  74. [section addFormRow:row];
  75. // Numero
  76. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"numero" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_number:_", nil)];
  77. [row.cellConfig setObject:COLOR_GRAY forKey:@"textField.textColor"];
  78. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  79. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  80. row.value = [field objectForKey:@"numero"];
  81. if (modelReadOnly) row.disabled = @YES;
  82. [section addFormRow:row];
  83. // Luogo di nascita
  84. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"luogonascita" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_place_of_birth:_", nil)];
  85. [row.cellConfig setObject:COLOR_GRAY forKey:@"textField.textColor"];
  86. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  87. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  88. row.value = [field objectForKey:@"luogonascita"];
  89. if (modelReadOnly) row.disabled = @YES;
  90. [section addFormRow:row];
  91. // Data di nascita
  92. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"datanascita" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_date_of_birth:_", nil)];
  93. [row.cellConfig setObject:COLOR_GRAY forKey:@"textField.textColor"];
  94. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  95. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  96. row.value = [field objectForKey:@"datanascita"];
  97. if (modelReadOnly) row.disabled = @YES;
  98. [section addFormRow:row];
  99. // Data di rilascio
  100. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"datarilascio" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_date_of_issue:_", nil)];
  101. [row.cellConfig setObject:COLOR_GRAY forKey:@"textField.textColor"];
  102. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  103. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  104. row.value = [field objectForKey:@"datarilascio"];
  105. if (modelReadOnly) row.disabled = @YES;
  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:COLOR_GRAY 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. if (modelReadOnly) row.disabled = @YES;
  114. [section addFormRow:row];
  115. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_notes_", nil)];
  116. [form addFormSection:section];
  117. // Note
  118. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"note" rowType:XLFormRowDescriptorTypeTextView];
  119. row.value = [field objectForKey:@"note"];
  120. [row.cellConfig setObject:COLOR_GRAY forKey:@"textView.textColor"];
  121. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textView.font"];
  122. [section addFormRow:row];
  123. self.form = form;
  124. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPressed:)];
  125. if (modelReadOnly) self.navigationItem.rightBarButtonItem = nil;
  126. else self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(savePressed:)];
  127. }
  128. return self;
  129. }
  130. - (void)viewDidLoad
  131. {
  132. [super viewDidLoad];
  133. templates = [[CCTemplates alloc] init];
  134. [templates setImageTitle:NSLocalizedString(@"_id_card_", nil) conNavigationItem:self.navigationItem reachability:[app.reachability isReachable]];
  135. // Color
  136. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  137. }
  138. - (void)viewDidAppear:(BOOL)animated
  139. {
  140. [super viewDidAppear:animated];
  141. if (self.fileName && !field) [self performSelector:@selector(cancelPressed:) withObject:nil afterDelay:0.5];
  142. }
  143. - (void)didSelectFormRow:(XLFormRowDescriptor *)formRow
  144. {
  145. [super didSelectFormRow:formRow];
  146. if ([formRow.tag isEqual:@"mytag"]) {
  147. // do your thing for your row.
  148. }
  149. }
  150. #pragma --------------------------------------------------------------------------------------------
  151. #pragma mark - ==== IBAction ====
  152. #pragma --------------------------------------------------------------------------------------------
  153. - (IBAction)cancelPressed:(UIBarButtonItem * __unused)button
  154. {
  155. [self dismissViewControllerAnimated:YES completion:nil];
  156. }
  157. - (IBAction)savePressed:(UIBarButtonItem * __unused)button
  158. {
  159. NSString *fileNameModel;
  160. NSArray *validationErrors = [self formValidationErrors];
  161. if (validationErrors.count > 0){
  162. //NSError *error = [validationErrors firstObject];
  163. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_enter_title_", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_ok_", nil) otherButtonTitles:nil];
  164. [alertView show];
  165. return;
  166. }
  167. [self.tableView endEditing:YES];
  168. fileNameModel = [templates salvaForm:form fileName:self.fileName uuid:self.uuid modello:@"cartaidentita" icona:@"cartaidentita"];
  169. if (fileNameModel) {
  170. XLFormRowDescriptor *titolo = [self.form formRowWithTag:@"titolo"];
  171. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  172. metadataNet.action = actionUploadTemplate;
  173. metadataNet.serverUrl = self.serverUrl;
  174. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  175. metadataNet.fileNamePrint = titolo.value;
  176. metadataNet.pathFolder = NSTemporaryDirectory();
  177. metadataNet.rev = self.rev;
  178. metadataNet.session = upload_session_foreground;
  179. metadataNet.taskStatus = k_taskStatusResume;
  180. [app addNetworkingOperationQueue:app.netQueue delegate:self.delegate metadataNet:metadataNet];
  181. [self dismissViewControllerAnimated:YES completion:nil];
  182. }
  183. }
  184. @end