CCPassaporto.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // CCPassaporto.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 "CCPassaporto.h"
  24. #import "AppDelegate.h"
  25. @interface CCPassaporto()
  26. {
  27. XLFormDescriptor *form ;
  28. NSTimer* myTimer;
  29. NSMutableDictionary *field;
  30. CCTemplates *templates;
  31. }
  32. @end
  33. @implementation CCPassaporto
  34. - (id)initWithDelegate:(id <CCPassaportoDelegate>)delegate fileName:(NSString *)fileName uuid:(NSString *)uuid rev:(NSString *)rev fileID:(NSString *)fileID modelReadOnly:(BOOL)modelReadOnly isLocal:(BOOL)isLocal
  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. CCCrypto *crypto = [[CCCrypto alloc] init];
  45. // if fileName read Crypto File
  46. if (fileName)
  47. field = [crypto getDictionaryEncrypted:fileName uuid:uuid isLocal:isLocal directoryUser:app.directoryUser];
  48. //XLFormDescriptor * form ;
  49. XLFormSectionDescriptor * section;
  50. XLFormRowDescriptor * row;
  51. // Information - Section
  52. form = [XLFormDescriptor formDescriptor];
  53. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_title_", nil)];
  54. [form addFormSection:section];
  55. if (!fileName) form.assignFirstResponderOnShow = YES;
  56. // Title
  57. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"titolo" rowType:XLFormRowDescriptorTypeText];
  58. [row.cellConfig setObject:COLOR_ENCRYPTED forKey:@"textField.textColor"];
  59. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  60. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  61. row.value = [field objectForKey:@"titolo"];
  62. row.required = YES;
  63. [section addFormRow:row];
  64. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_passport_", nil)];
  65. [form addFormSection:section];
  66. // Nome Cognome
  67. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"comecognome" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_name_surname:_", nil)];
  68. [row.cellConfig setObject:COLOR_GRAY forKey:@"textField.textColor"];
  69. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  70. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  71. row.value = [field objectForKey:@"comecognome"];
  72. if (modelReadOnly) row.disabled = @YES;
  73. [section addFormRow:row];
  74. // Numero
  75. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"numero" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_number:_", nil)];
  76. [row.cellConfig setObject:COLOR_GRAY 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. if (modelReadOnly) row.disabled = @YES;
  81. [section addFormRow:row];
  82. // Luogo di nascita
  83. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"luogonascita" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_place_of_birth:_", nil)];
  84. [row.cellConfig setObject:COLOR_GRAY forKey:@"textField.textColor"];
  85. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  86. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  87. row.value = [field objectForKey:@"luogonascita"];
  88. if (modelReadOnly) row.disabled = @YES;
  89. [section addFormRow:row];
  90. // Data di nascita
  91. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"datanascita" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_date_of_birth:_", nil)];
  92. [row.cellConfig setObject:COLOR_GRAY forKey:@"textField.textColor"];
  93. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  94. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  95. row.value = [field objectForKey:@"datanascita"];
  96. if (modelReadOnly) row.disabled = @YES;
  97. [section addFormRow:row];
  98. // Data di rilascio
  99. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"datarilascio" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_date_of_issue:_", nil)];
  100. [row.cellConfig setObject:COLOR_GRAY forKey:@"textField.textColor"];
  101. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  102. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  103. row.value = [field objectForKey:@"datarilascio"];
  104. if (modelReadOnly) row.disabled = @YES;
  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:COLOR_GRAY 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. if (modelReadOnly) row.disabled = @YES;
  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:COLOR_GRAY 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. if (modelReadOnly) self.navigationItem.rightBarButtonItem = nil;
  125. else self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(savePressed:)];
  126. }
  127. return self;
  128. }
  129. - (void)viewDidLoad
  130. {
  131. [super viewDidLoad];
  132. templates = [[CCTemplates alloc] init];
  133. [templates setImageTitle:NSLocalizedString(@"_passport_", nil) conNavigationItem:self.navigationItem reachability:[app.reachability isReachable]];
  134. // Color
  135. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  136. }
  137. - (void)viewDidAppear:(BOOL)animated
  138. {
  139. [super viewDidAppear:animated];
  140. if (self.fileName && !field) [self performSelector:@selector(cancelPressed:) withObject:nil afterDelay:0.5];
  141. }
  142. - (void)didSelectFormRow:(XLFormRowDescriptor *)formRow
  143. {
  144. [super didSelectFormRow:formRow];
  145. if ([formRow.tag isEqual:@"mytag"]) {
  146. // do your thing for your row.
  147. }
  148. }
  149. #pragma --------------------------------------------------------------------------------------------
  150. #pragma mark - ==== IBAction ====
  151. #pragma --------------------------------------------------------------------------------------------
  152. - (IBAction)cancelPressed:(UIBarButtonItem * __unused)button
  153. {
  154. [self dismissViewControllerAnimated:YES completion:nil];
  155. }
  156. - (IBAction)savePressed:(UIBarButtonItem * __unused)button
  157. {
  158. NSString *fileNameModel;
  159. NSArray *validationErrors = [self formValidationErrors];
  160. if (validationErrors.count > 0){
  161. //NSError *error = [validationErrors firstObject];
  162. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_enter_title_", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_ok_", nil) otherButtonTitles:nil];
  163. [alertView show];
  164. return;
  165. }
  166. [self.tableView endEditing:YES];
  167. fileNameModel = [templates salvaForm:form fileName:self.fileName uuid:self.uuid modello:@"passaporto" icona:@"passaporto"];
  168. if (fileNameModel) {
  169. XLFormRowDescriptor *titolo = [self.form formRowWithTag:@"titolo"];
  170. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  171. metadataNet.action = actionUploadTemplate;
  172. metadataNet.serverUrl = app.serverUrl;
  173. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  174. metadataNet.fileNamePrint = titolo.value;
  175. metadataNet.pathFolder = NSTemporaryDirectory();
  176. metadataNet.rev = self.rev;
  177. metadataNet.session = upload_session_foreground;
  178. metadataNet.taskStatus = taskStatusResume;
  179. [app addNetworkingOperationQueue:app.netQueue delegate:self.delegate metadataNet:metadataNet];
  180. [self dismissViewControllerAnimated:YES completion:nil];
  181. }
  182. }
  183. @end