CCShareOC.m 23 KB

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