CCPatenteGuida.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // CCPatenteGuida.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 "CCPatenteGuida.h"
  24. #import "XLFormViewController.h"
  25. #import "XLForm.h"
  26. #import "AppDelegate.h"
  27. @interface CCPatenteGuida()
  28. {
  29. XLFormDescriptor *form ;
  30. NSTimer* myTimer;
  31. NSMutableDictionary *field;
  32. CCTemplates *templates;
  33. }
  34. @end
  35. @implementation CCPatenteGuida
  36. - (id)initWithDelegate:(id <CCPatenteGuidaDelegate>)delegate fileName:(NSString *)fileName uuid:(NSString *)uuid rev:(NSString *)rev fileID:(NSString *)fileID modelReadOnly:(BOOL)modelReadOnly isLocal:(BOOL)isLocal
  37. {
  38. self = [super init];
  39. if (self){
  40. self.delegate = delegate;
  41. self.fileName = fileName;
  42. self.isLocal = isLocal;
  43. self.rev = rev;
  44. self.fileID = fileID;
  45. self.uuid = uuid;
  46. CCCrypto *crypto = [[CCCrypto alloc] init];
  47. // if fileName read Crypto File
  48. if (fileName)
  49. field = [crypto getDictionaryEncrypted:fileName uuid:uuid isLocal:isLocal directoryUser:app.directoryUser];
  50. //XLFormDescriptor * form ;
  51. XLFormSectionDescriptor * section;
  52. XLFormRowDescriptor * row;
  53. // Information - Section
  54. form = [XLFormDescriptor formDescriptor];
  55. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_title_", nil)];
  56. [form addFormSection:section];
  57. if (!fileName) form.assignFirstResponderOnShow = YES;
  58. // Titolo
  59. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"titolo" rowType:XLFormRowDescriptorTypeText];
  60. [row.cellConfig setObject:COLOR_ENCRYPTED forKey:@"textField.textColor"];
  61. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  62. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  63. row.value = [field objectForKey:@"titolo"];
  64. row.required = YES;
  65. [section addFormRow:row];
  66. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_driving_license_", nil)];
  67. [form addFormSection:section];
  68. // Nome Cognome
  69. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"comecognome" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_name_surname:_", nil)];
  70. [row.cellConfig setObject:COLOR_GRAY forKey:@"textField.textColor"];
  71. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  72. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  73. row.value = [field objectForKey:@"comecognome"];
  74. if (modelReadOnly) row.disabled = @YES;
  75. [section addFormRow:row];
  76. // Numero
  77. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"numero" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_license_number:_", nil)];
  78. [row.cellConfig setObject:COLOR_GRAY forKey:@"textField.textColor"];
  79. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  81. row.value = [field objectForKey:@"numero"];
  82. if (modelReadOnly) row.disabled = @YES;
  83. [section addFormRow:row];
  84. // Data di rilascio
  85. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"datarilascio" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_date_of_issue:_", nil)];
  86. [row.cellConfig setObject:COLOR_GRAY forKey:@"textField.textColor"];
  87. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  88. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  89. row.value = [field objectForKey:@"datarilascio"];
  90. if (modelReadOnly) row.disabled = @YES;
  91. [section addFormRow:row];
  92. // Data di scadenza
  93. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"datascadenza" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_date_of_expiry:_", nil)];
  94. [row.cellConfig setObject:COLOR_GRAY 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:@"datascadenza"];
  98. if (modelReadOnly) row.disabled = @YES;
  99. [section addFormRow:row];
  100. // Tipi di veicolo
  101. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"tipiveicolo" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_vehicle_types:_", nil)];
  102. [row.cellConfig setObject:COLOR_GRAY 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:@"tipiveicolo"];
  106. if (modelReadOnly) row.disabled = @YES;
  107. [section addFormRow:row];
  108. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_notes_", nil)];
  109. [form addFormSection:section];
  110. // Note
  111. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"note" rowType:XLFormRowDescriptorTypeTextView];
  112. row.value = [field objectForKey:@"note"];
  113. [row.cellConfig setObject:COLOR_GRAY forKey:@"textView.textColor"];
  114. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textView.font"];
  115. [section addFormRow:row];
  116. self.form = form;
  117. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPressed:)];
  118. if (modelReadOnly) self.navigationItem.rightBarButtonItem = nil;
  119. else 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(@"_driving_license_", nil) conNavigationItem:self.navigationItem reachability:[app.reachability isReachable]];
  128. // Color
  129. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar 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. //NSError *error = [validationErrors firstObject];
  156. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_enter_title_", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_ok_", nil) otherButtonTitles:nil];
  157. [alertView show];
  158. return;
  159. }
  160. [self.tableView endEditing:YES];
  161. fileNameModel = [templates salvaForm:form fileName:self.fileName uuid:self.uuid modello:@"patenteguida" icona:@"patenteguida"];
  162. if (fileNameModel) {
  163. XLFormRowDescriptor *titolo = [self.form formRowWithTag:@"titolo"];
  164. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  165. metadataNet.action = actionUploadTemplate;
  166. metadataNet.serverUrl = app.serverUrl;
  167. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  168. metadataNet.fileNamePrint = titolo.value;
  169. metadataNet.pathFolder = NSTemporaryDirectory();
  170. metadataNet.rev = self.rev;
  171. metadataNet.session = upload_session_foreground;
  172. metadataNet.taskStatus = taskStatusResume;
  173. [app addNetworkingOperationQueue:app.netQueue delegate:self.delegate metadataNet:metadataNet];
  174. [self dismissViewControllerAnimated:YES completion:nil];
  175. }
  176. }
  177. @end