CCAccountWeb.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // CCAccountWeb.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/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 "CCAccountWeb.h"
  24. #import "AppDelegate.h"
  25. @interface CCAccountWeb()
  26. {
  27. XLFormDescriptor *form ;
  28. NSTimer* myTimer;
  29. NSMutableDictionary *field;
  30. CCTemplates *templates;
  31. }
  32. @end
  33. @implementation CCAccountWeb
  34. - (id)initWithDelegate:(id <CCAccountWebDelegate>)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. XLFormSectionDescriptor *section;
  49. XLFormRowDescriptor *row;
  50. // Information - Section
  51. form = [XLFormDescriptor formDescriptor];
  52. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_title_", nil)];
  53. [form addFormSection:section];
  54. if (!fileName) form.assignFirstResponderOnShow = YES;
  55. // Title
  56. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"titolo" rowType:XLFormRowDescriptorTypeText];
  57. [row.cellConfig setObject:COLOR_ENCRYPTED forKey:@"textField.textColor"];
  58. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  59. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  60. row.value = [field objectForKey:@"titolo"];
  61. if (modelReadOnly) row.disabled = @YES;
  62. row.required = YES;
  63. [section addFormRow:row];
  64. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_web_account_data_", nil)];
  65. [form addFormSection:section];
  66. // url
  67. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"url" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_url:_", 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:@"url"];
  72. if (modelReadOnly) row.disabled = @YES;
  73. [section addFormRow:row];
  74. // Login
  75. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"login" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_login:_", 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:@"login"];
  80. if (modelReadOnly) row.disabled = @YES;
  81. [section addFormRow:row];
  82. // Password
  83. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"password" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_password:_", 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:@"password"];
  88. if (modelReadOnly) row.disabled = @YES;
  89. [section addFormRow:row];
  90. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_notes_", nil)];
  91. [form addFormSection:section];
  92. // Note
  93. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"note" rowType:XLFormRowDescriptorTypeTextView];
  94. row.value = [field objectForKey:@"note"];
  95. [row.cellConfig setObject:COLOR_GRAY forKey:@"textView.textColor"];
  96. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textView.font"];
  97. [section addFormRow:row];
  98. self.form = form;
  99. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPressed:)];
  100. if (modelReadOnly) self.navigationItem.rightBarButtonItem = nil;
  101. else self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(savePressed:)];
  102. }
  103. return self;
  104. }
  105. - (void)viewDidLoad
  106. {
  107. [super viewDidLoad];
  108. templates = [[CCTemplates alloc] init];
  109. [templates setImageTitle:NSLocalizedString(@"_web_account_", nil) conNavigationItem:self.navigationItem reachability:[app.reachability isReachable]];
  110. // Color
  111. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  112. }
  113. - (void)viewDidAppear:(BOOL)animated
  114. {
  115. [super viewDidAppear:animated];
  116. if (self.fileName && !field) [self performSelector:@selector(cancelPressed:) withObject:nil afterDelay:0.5];
  117. }
  118. - (void)didSelectFormRow:(XLFormRowDescriptor *)formRow
  119. {
  120. [super didSelectFormRow:formRow];
  121. if ([formRow.tag isEqual:@"mytag"]) {
  122. // do your thing for your row.
  123. }
  124. }
  125. #pragma --------------------------------------------------------------------------------------------
  126. #pragma mark - ==== IBAction ====
  127. #pragma --------------------------------------------------------------------------------------------
  128. - (IBAction)cancelPressed:(UIBarButtonItem * __unused)button
  129. {
  130. [self dismissViewControllerAnimated:YES completion:nil];
  131. }
  132. - (IBAction)savePressed:(UIBarButtonItem * __unused)button
  133. {
  134. NSString *fileNameModel;
  135. NSArray *validationErrors = [self formValidationErrors];
  136. if (validationErrors.count > 0){
  137. //NSError *error = [validationErrors firstObject];
  138. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_enter_title_", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_ok_", nil) otherButtonTitles:nil];
  139. [alertView show];
  140. return;
  141. }
  142. [self.tableView endEditing:YES];
  143. fileNameModel = [templates salvaForm:form fileName:self.fileName uuid:self.uuid modello:@"accountweb" icona:@"accountweb"];
  144. if (fileNameModel) {
  145. XLFormRowDescriptor *titolo = [self.form formRowWithTag:@"titolo"];
  146. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  147. metadataNet.action = actionUploadTemplate;
  148. metadataNet.serverUrl = app.serverUrl;
  149. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  150. metadataNet.fileNamePrint = titolo.value;
  151. metadataNet.pathFolder = NSTemporaryDirectory();
  152. metadataNet.rev = self.rev;
  153. metadataNet.session = upload_session_foreground;
  154. metadataNet.taskStatus = taskStatusResume;
  155. [app addNetworkingOperationQueue:app.netQueue delegate:self.delegate metadataNet:metadataNet];
  156. [self dismissViewControllerAnimated:YES completion:nil];
  157. }
  158. }
  159. @end