CCShareOC.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. //
  2. // CCShareOC.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 13/11/15.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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 "CCShareOC.h"
  24. #import "AppDelegate.h"
  25. #import "NCBridgeSwift.h"
  26. @interface CCShareOC ()
  27. {
  28. AppDelegate *appDelegate;
  29. }
  30. @end
  31. @implementation CCShareOC
  32. - (instancetype)initWithCoder:(NSCoder *)coder
  33. {
  34. self = [super initWithCoder:coder];
  35. if (self) {
  36. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  37. self.itemsShareWith = [[NSMutableArray alloc] init];
  38. [self initializeForm];
  39. }
  40. return self;
  41. }
  42. - (void)initializeForm
  43. {
  44. XLFormDescriptor *form ;
  45. XLFormSectionDescriptor *section;
  46. XLFormRowDescriptor *row;
  47. form = [XLFormDescriptor formDescriptor];
  48. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  49. // Share Link
  50. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_link_", nil)];
  51. [form addFormSection:section];
  52. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareLinkSwitch" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_link_", nil)];
  53. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  54. [section addFormRow:row];
  55. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareLinkPermission" rowType:XLFormRowDescriptorTypePicker];
  56. row.height = 70;
  57. [section addFormRow:row];
  58. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"password" rowType:XLFormRowDescriptorTypePassword title:NSLocalizedString(@"_password_", nil)];
  59. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  60. [section addFormRow:row];
  61. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:appDelegate.activeAccount];
  62. if (capabilities != nil && capabilities.versionMajor >= k_nextcloud_version_15_0) {
  63. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"hideDownload" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_link_hide_download_", nil)];
  64. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  65. [section addFormRow:row];
  66. }
  67. // Expiration date
  68. section = [XLFormSectionDescriptor formSection];
  69. [form addFormSection:section];
  70. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"expirationDate" rowType:XLFormRowDescriptorTypeDate title:NSLocalizedString(@"_date_", nil)];
  71. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  72. row.value = [self tomorrow];
  73. [row.cellConfigAtConfigure setObject:[self tomorrow] forKey:@"minimumDate"];
  74. [section addFormRow:row];
  75. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"expirationDateSwitch" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_expirationdate_", nil)];
  76. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  77. [section addFormRow:row];
  78. // Send Link To
  79. section = [XLFormSectionDescriptor formSection];
  80. [form addFormSection:section];
  81. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendLinkTo" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_share_link_button_", nil)];
  82. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  83. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  84. row.action.formSelector = @selector(sendLinkTo:);
  85. [section addFormRow:row];
  86. // Sharee
  87. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_title_", nil)];
  88. [form addFormSection:section];
  89. section.footerTitle = NSLocalizedString(@"_add_sharee_footer_", nil);
  90. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"findUser" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_add_sharee_", nil)];
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  92. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  93. row.action.formSelector = @selector(shareUserButton:);
  94. [section addFormRow:row];
  95. section = [XLFormSectionDescriptor formSectionWithTitle:@"" sectionOptions:XLFormSectionOptionCanDelete];
  96. [form addFormSection:section];
  97. self.form = form;
  98. }
  99. - (void)viewDidLoad
  100. {
  101. [super viewDidLoad];
  102. self.view.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  103. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  104. self.endButton.tintColor = [UIColor blackColor];
  105. [self reloadData];
  106. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]]) {
  107. self.fileImageView.image = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]];
  108. } else {
  109. if (self.metadata.directory)
  110. self.fileImageView.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement];
  111. else
  112. self.fileImageView.image = [UIImage imageNamed:self.metadata.iconName];
  113. }
  114. self.labelTitle.text = self.metadata.fileNameView;
  115. self.labelTitle.textColor = [UIColor blackColor];
  116. self.tableView.tableHeaderView = ({UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 0.1 / UIScreen.mainScreen.scale)];
  117. line.backgroundColor = self.tableView.separatorColor;
  118. line;
  119. });
  120. self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  121. }
  122. #pragma --------------------------------------------------------------------------------------------
  123. #pragma mark ===== Reload Data =====
  124. #pragma --------------------------------------------------------------------------------------------
  125. - (void)reloadData
  126. {
  127. // bugfix
  128. if (!self.serverUrl || !self.metadata) {
  129. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  130. [self dismissViewControllerAnimated:YES completion:nil];
  131. });
  132. return;
  133. }
  134. self.shareLink = [appDelegate.sharesLink objectForKey:[self.serverUrl stringByAppendingString:self.metadata.fileName]];
  135. self.shareUserAndGroup = [appDelegate.sharesUserAndGroup objectForKey:[self.serverUrl stringByAppendingString:self.metadata.fileName]];
  136. self.itemShareLink = [appDelegate.sharesID objectForKey:self.shareLink];
  137. if ([self.shareUserAndGroup length] > 0) self.itemsUserAndGroupLink = [self.shareUserAndGroup componentsSeparatedByString:@","];
  138. else self.itemsUserAndGroupLink = nil;
  139. self.form.delegate = nil;
  140. XLFormRowDescriptor *rowShareLinkSwitch = [self.form formRowWithTag:@"shareLinkSwitch"];
  141. XLFormRowDescriptor *rowShareLinkPermission = [self.form formRowWithTag:@"shareLinkPermission"];
  142. XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"];
  143. XLFormRowDescriptor *rowHideDownload = [self.form formRowWithTag:@"hideDownload"];
  144. XLFormRowDescriptor *rowExpirationDate = [self.form formRowWithTag:@"expirationDate"];
  145. XLFormRowDescriptor *rowExpirationDateSwitch = [self.form formRowWithTag:@"expirationDateSwitch"];
  146. XLFormRowDescriptor *rowSendLinkTo = [self.form formRowWithTag:@"sendLinkTo"];
  147. // Share Link
  148. if ([self.shareLink length] > 0) {
  149. [rowShareLinkSwitch setValue:@1];
  150. rowShareLinkPermission.disabled = @NO;
  151. rowPassword.disabled = @NO;
  152. rowHideDownload.disabled = @NO;
  153. rowExpirationDate.disabled = @NO;
  154. rowExpirationDateSwitch.disabled = @NO;
  155. rowSendLinkTo.disabled = @NO;
  156. } else {
  157. [rowShareLinkSwitch setValue:@0];
  158. rowShareLinkPermission.disabled = @YES;
  159. rowPassword.disabled = @YES;
  160. rowHideDownload.disabled = @YES;
  161. rowExpirationDate.disabled = @YES;
  162. rowExpirationDateSwitch.disabled = @YES;
  163. rowSendLinkTo.disabled = @YES;
  164. }
  165. // Permission
  166. if (self.metadata.directory) {
  167. rowShareLinkPermission.selectorOptions = @[NSLocalizedString(@"_share_link_readonly_", nil), NSLocalizedString(@"_share_link_upload_modify_", nil), NSLocalizedString(@"_share_link_upload_", nil)];
  168. } else {
  169. rowShareLinkPermission.selectorOptions = @[NSLocalizedString(@"_share_link_readonly_", nil), NSLocalizedString(@"_share_link_modify_", nil)];
  170. }
  171. if (self.itemShareLink.permissions > 0 && self.itemShareLink.shareType == shareTypeLink) {
  172. switch (self.itemShareLink.permissions) {
  173. case 1:
  174. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_readonly_", nil);
  175. break;
  176. case 3:
  177. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_modify_", nil);
  178. break;
  179. case 4:
  180. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_upload_", nil);
  181. break;
  182. case 15:
  183. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_upload_modify_", nil);
  184. break;
  185. default:
  186. break;
  187. }
  188. } else {
  189. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_readonly_", nil);
  190. }
  191. // Password
  192. if ([[self.itemShareLink shareWith] length] > 0 && self.itemShareLink.shareType == shareTypeLink)
  193. rowPassword.value = [self.itemShareLink shareWith];
  194. else
  195. rowPassword.value = @"";
  196. // Hide Download
  197. if (self.itemShareLink.hideDownload) rowHideDownload.value = @1;
  198. else rowHideDownload.value = @0;
  199. // Expiration Date
  200. if (self.itemShareLink.expirationDate) {
  201. rowExpirationDateSwitch.value = @1;
  202. NSDate *expireDate;
  203. if (self.itemShareLink.expirationDate) expireDate = [NSDate dateWithTimeIntervalSince1970: self.itemShareLink.expirationDate];
  204. else expireDate = [self tomorrow];
  205. rowExpirationDate.value = expireDate;
  206. } else {
  207. rowExpirationDateSwitch.value = @0;
  208. rowExpirationDate.value = [self tomorrow];
  209. }
  210. // User & Group
  211. XLFormSectionDescriptor *section = [self.form formSectionAtIndex:4];
  212. [section.formRows removeAllObjects];
  213. [self.itemsShareWith removeAllObjects];
  214. if ([self.itemsUserAndGroupLink count] > 0) {
  215. for (NSString *idRemoteShared in self.itemsUserAndGroupLink) {
  216. OCSharedDto *item = [appDelegate.sharesID objectForKey:idRemoteShared];
  217. XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:idRemoteShared rowType:XLFormRowDescriptorTypeButton];
  218. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  219. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  220. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"textLabel.textColor"];
  221. row.action.formSelector = @selector(sharePermissionButton:);
  222. if (item.shareType == shareTypeGroup) row.title = [item.shareWithDisplayName stringByAppendingString:NSLocalizedString(@"_user_is_group_", nil)];
  223. else row.title = item.shareWithDisplayName;
  224. [section addFormRow:row];
  225. // add users
  226. [self.itemsShareWith addObject:item];
  227. }
  228. section.footerTitle = NSLocalizedString(@"_user_sharee_footer_", nil);
  229. } else {
  230. section.footerTitle = @"";
  231. }
  232. self.form.disabled = NO;
  233. [self.tableView reloadData];
  234. self.form.delegate = self;
  235. }
  236. #pragma --------------------------------------------------------------------------------------------
  237. #pragma mark ===== Change Value & Button =====
  238. #pragma --------------------------------------------------------------------------------------------
  239. - (void)sendLinkTo:(XLFormRowDescriptor *)sender
  240. {
  241. [self deselectFormRow:sender];
  242. NSString *sharedLink = self.itemShareLink.token;
  243. NSString *url;
  244. if ([sharedLink hasPrefix:@"http://"] || [sharedLink hasPrefix:@"https://"]) {
  245. url = sharedLink;
  246. } else {
  247. url = [NSString stringWithFormat:@"%@/%@%@", appDelegate.activeUrl, k_share_link_middle_part_url_after_version_8, sharedLink];
  248. }
  249. NSArray *activityItems = @[[NSString stringWithFormat:@""], [NSURL URLWithString:url]];
  250. NSArray *applicationActivities = nil;
  251. UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
  252. activityController.popoverPresentationController.sourceView = self.view;
  253. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  254. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  255. activityController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  256. [self presentViewController:activityController animated:YES completion:nil];
  257. }
  258. - (void)shareUserButton:(XLFormRowDescriptor *)rowDescriptor
  259. {
  260. [self deselectFormRow:rowDescriptor];
  261. self.shareUserOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareUserOC"];
  262. self.shareUserOC.delegate = self;
  263. self.shareUserOC.itemsShareWith = self.itemsShareWith;
  264. self.shareUserOC.isDirectory = self.metadata.directory;
  265. [self.shareUserOC setModalPresentationStyle:UIModalPresentationFormSheet];
  266. [self presentViewController:self.shareUserOC animated:YES completion:NULL];
  267. }
  268. - (void)sharePermissionButton:(XLFormRowDescriptor *)rowDescriptor
  269. {
  270. [self deselectFormRow:rowDescriptor];
  271. self.sharePermissionOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCSharePermissionOC"];
  272. self.sharePermissionOC.delegate = self;
  273. self.sharePermissionOC.idRemoteShared = rowDescriptor.tag;
  274. self.sharePermissionOC.metadata = self.metadata;
  275. self.sharePermissionOC.serverUrl = self.serverUrl;
  276. [self.sharePermissionOC setModalPresentationStyle:UIModalPresentationFormSheet];
  277. [self presentViewController:self.sharePermissionOC animated:YES completion:NULL];
  278. }
  279. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  280. {
  281. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  282. //OCSharedDto *shareDto = [appDelegate.sharesID objectForKey:self.shareLink];
  283. if ([rowDescriptor.tag isEqualToString:@"shareLinkSwitch"]) {
  284. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  285. [self.delegate share:self.metadata serverUrl:self.serverUrl password:@"" permission:1 hideDownload:false];
  286. [self disableForm];
  287. } else {
  288. // unshare
  289. [self.delegate unShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl];
  290. [self disableForm];
  291. }
  292. }
  293. if ([rowDescriptor.tag isEqualToString:@"shareLinkPermission"]) {
  294. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:[self getShareLinkPermission:newValue] hideDownload:false];
  295. [self disableForm];
  296. }
  297. if ([rowDescriptor.tag isEqualToString:@"hideDownload"]) {
  298. BOOL hideDownload = [newValue boolValue];
  299. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:0 hideDownload:hideDownload];
  300. [self disableForm];
  301. }
  302. if ([rowDescriptor.tag isEqualToString:@"expirationDateSwitch"]) {
  303. // remove expiration date
  304. if ([[rowDescriptor.value valueData] boolValue] == NO) {
  305. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:@"" permission:0 hideDownload:false];
  306. [self disableForm];
  307. } else {
  308. // new date
  309. XLFormRowDescriptor *rowExpirationDate = [self.form formRowWithTag:@"expirationDate"];
  310. NSString *expirationDate = [self convertDateInServerFormat:rowExpirationDate.value];
  311. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:expirationDate permission:0 hideDownload:false];
  312. [self disableForm];
  313. }
  314. }
  315. }
  316. - (void)formRowHasBeenRemoved:(XLFormRowDescriptor *)formRow atIndexPath:(NSIndexPath *)indexPath
  317. {
  318. long long idRemoteShared = [formRow.tag longLongValue];
  319. if ([formRow.rowType isEqualToString:@"button"] && idRemoteShared > 0) {
  320. [self.delegate unShare:formRow.tag metadata:self.metadata serverUrl:self.serverUrl];
  321. [self disableForm];
  322. }
  323. }
  324. - (void)beginEditing:(XLFormRowDescriptor *)rowDescriptor
  325. {
  326. [super beginEditing:rowDescriptor];
  327. if ([rowDescriptor.tag isEqualToString:@"expirationDate"]) {
  328. self.endButton.enabled = NO;
  329. }
  330. }
  331. - (void)endEditing:(XLFormRowDescriptor *)rowDescriptor
  332. {
  333. [super endEditing:rowDescriptor];
  334. //OCSharedDto *shareDto = [appDelegate.sharesID objectForKey:self.shareLink];
  335. if ([rowDescriptor.tag isEqualToString:@"expirationDate"]) {
  336. NSDate *old = [NSDate dateWithTimeIntervalSince1970: self.itemShareLink.expirationDate];
  337. NSDate *new = rowDescriptor.value;
  338. if ([old compare:new] != NSOrderedSame) {
  339. NSString *expirationDate = [self convertDateInServerFormat:rowDescriptor.value];
  340. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:expirationDate permission:0 hideDownload:false];
  341. [self disableForm];
  342. }
  343. self.endButton.enabled = YES;
  344. }
  345. if ([rowDescriptor.tag isEqualToString:@"password"]) {
  346. NSString *password = rowDescriptor.value;
  347. // if the password is not changed or is 0 lenght
  348. if ([[self.itemShareLink shareWith] isEqualToString:password]) {
  349. [self reloadData];
  350. } else {
  351. if (password == nil)
  352. password = @"";
  353. if (self.shareLink) {
  354. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:password expirationTime:nil permission:0 hideDownload:false];
  355. [self disableForm];
  356. }
  357. }
  358. }
  359. }
  360. #pragma --------------------------------------------------------------------------------------------
  361. #pragma mark ===== Button =====
  362. #pragma --------------------------------------------------------------------------------------------
  363. - (IBAction)endButtonAction:(id)sender
  364. {
  365. [self.tableView endEditing:YES];
  366. // reload delegate
  367. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.metadata.serverUrl fileID:self.metadata.fileID action:k_action_MOD];
  368. [self dismissViewControllerAnimated:YES completion:nil];
  369. }
  370. #pragma --------------------------------------------------------------------------------------------
  371. #pragma mark ===== User & Group =====
  372. #pragma --------------------------------------------------------------------------------------------
  373. - (void)getUserAndGroup:(NSString *)find
  374. {
  375. [self.delegate getUserAndGroup:find];
  376. }
  377. - (void)reloadUserAndGroup:(NSArray *)items
  378. {
  379. if (self.shareUserOC)
  380. [self.shareUserOC reloadUserAndGroup:items];
  381. }
  382. - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission
  383. {
  384. [self.delegate shareUserAndGroup:user shareeType:shareeType permission:permission metadata:self.metadata serverUrl:self.serverUrl];
  385. }
  386. - (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission hideDownload:(BOOL)hideDownload
  387. {
  388. [self.delegate updateShare:share metadata:metadata serverUrl:serverUrl password:password expirationTime:expirationTime permission:permission hideDownload:false];
  389. }
  390. #pragma --------------------------------------------------------------------------------------------
  391. #pragma mark ===== Utility =====
  392. #pragma --------------------------------------------------------------------------------------------
  393. -(void)disableForm
  394. {
  395. self.form.disabled = YES;
  396. [self.tableView endEditing:YES];
  397. [self.tableView reloadData];
  398. }
  399. - (NSString *)convertDateInServerFormat:(NSDate *)date {
  400. NSDateFormatter *dateFormatter = [NSDateFormatter new];
  401. [dateFormatter setDateFormat:@"YYYY-MM-dd"];
  402. return [dateFormatter stringFromDate:date];
  403. }
  404. -(NSDate *)tomorrow
  405. {
  406. NSDate *now = [NSDate date];
  407. int daysToAdd = 1;
  408. return [now dateByAddingTimeInterval:60*60*24*daysToAdd];
  409. }
  410. - (NSInteger)getShareLinkPermission:(NSString *)value
  411. {
  412. if ([value isEqualToString:NSLocalizedString(@"_share_link_readonly_", nil)]) {
  413. return 1;
  414. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_modify_", nil)]) {
  415. return 3;
  416. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_upload_", nil)]) {
  417. return 4;
  418. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_upload_modify_", nil)]) {
  419. return 15;
  420. } else {
  421. return 1;
  422. }
  423. }
  424. @end