CCCartaIdentita.m 11 KB

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