|
|
@@ -56,6 +56,40 @@ static const NSInteger detal = 20;
|
|
|
|
|
|
#pragma mark - Data
|
|
|
|
|
|
+- (void)loadDataFailed {
|
|
|
+
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if (weakSelf) {
|
|
|
+ __strong typeof(weakSelf) strongSelf = weakSelf;
|
|
|
+ if (strongSelf.delegate) {
|
|
|
+ [strongSelf.delegate onStopLoading];
|
|
|
+ [strongSelf.delegate onFailed:@"Sorry, something is wrong"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+- (void)loadDataSuccessWithTitle:(NSString *)title itemsArray:(NSArray *)modelsArr itemCount:(NSInteger)count {
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+
|
|
|
+ if (weakSelf) {
|
|
|
+ __strong typeof(weakSelf) strongSelf = weakSelf;
|
|
|
+
|
|
|
+ strongSelf.dataArray = [modelsArr copy];
|
|
|
+ if (strongSelf.delegate) {
|
|
|
+ [strongSelf.delegate onStopLoading];
|
|
|
+ [strongSelf.delegate onSuccess:title];
|
|
|
+ if (count < detal) {
|
|
|
+ [strongSelf.delegate onNoMoreData];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
- (void)loadData:(ApexResultFetchDataType)option {
|
|
|
|
|
|
NSInteger offset = self.offset;
|
|
|
@@ -67,97 +101,87 @@ static const NSInteger detal = 20;
|
|
|
if (self.delegate) {
|
|
|
[self.delegate onStartLoading];
|
|
|
}
|
|
|
+
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
|
|
|
- NSMutableDictionary *params = [self.params mutableCopy];
|
|
|
+ NSMutableDictionary *params = [weakSelf.params mutableCopy];
|
|
|
[params setObject:[NSNumber numberWithInteger:offset] forKey:@"offset"];
|
|
|
[params setObject:[NSNumber numberWithInteger:detal] forKey:@"limit"];
|
|
|
[params setObject:displayFields forKey:@"columns"];
|
|
|
|
|
|
NSDictionary *json = [RANetwork fetchResultParameters:params];
|
|
|
- int result = [[json objectForKey:@"result"] intValue];
|
|
|
- if (result == RESULT_TRUE) {
|
|
|
+ if (weakSelf) {
|
|
|
+ __strong typeof(weakSelf) strongSelf = weakSelf;
|
|
|
|
|
|
- NSMutableArray *modelsArr = [NSMutableArray array];
|
|
|
- if (option == ApexResultFetchDataTypeLoadMore && self.dataArray != nil && self.dataArray.count > 0) {
|
|
|
- [modelsArr addObjectsFromArray:self.dataArray];
|
|
|
- }
|
|
|
-
|
|
|
- NSArray *items = [json objectForKey:@"items"];
|
|
|
- for (NSDictionary *item in items) {
|
|
|
-
|
|
|
- NSInteger type = [[item objectForKey:@"type"] integerValue];
|
|
|
+ int result = [[json objectForKey:@"result"] intValue];
|
|
|
+ if (result == RESULT_TRUE) {
|
|
|
|
|
|
- switch (type) {
|
|
|
- case ApexResultTypeBooking: {
|
|
|
- ApexResultBookingModel *model = [ApexResultBookingModel new];
|
|
|
- [model setValuesForKeysWithDictionary:item];
|
|
|
- [modelsArr addObject:model];
|
|
|
- }
|
|
|
- break;
|
|
|
- case ApexResultTypeBLInfo: {
|
|
|
- ApexResultBLInfoModel *model = [ApexResultBLInfoModel new];
|
|
|
- [model setValuesForKeysWithDictionary:item];
|
|
|
- [modelsArr addObject:model];
|
|
|
- }
|
|
|
- break;
|
|
|
- case ApexResultTypeContainer: {
|
|
|
- ApexResultContainerModel *model = [ApexResultContainerModel new];
|
|
|
- [model setValuesForKeysWithDictionary:item];
|
|
|
- [modelsArr addObject:model];
|
|
|
- }
|
|
|
- break;
|
|
|
- case ApexResultTypeDocument: {
|
|
|
- ApexResultDocumentModel *model = [ApexResultDocumentModel new];
|
|
|
- [model setValuesForKeysWithDictionary:item];
|
|
|
- [modelsArr addObject:model];
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ NSMutableArray *modelsArr = [NSMutableArray array];
|
|
|
+ if (option == ApexResultFetchDataTypeLoadMore && strongSelf.dataArray != nil && strongSelf.dataArray.count > 0) {
|
|
|
+ [modelsArr addObjectsFromArray:strongSelf.dataArray];
|
|
|
}
|
|
|
|
|
|
- } // for
|
|
|
- self.offset = modelsArr.count;
|
|
|
-
|
|
|
- NSString *title = [json objectForKey:@"title"];
|
|
|
- self.rowActions = [json objectForKey:@"row_actions"];
|
|
|
- self.actions = [json objectForKey:@"actions"];
|
|
|
-
|
|
|
- // menu
|
|
|
- NSArray *menuArr = [json objectForKey:@"menu"];
|
|
|
- if (menuArr) {
|
|
|
- NSMutableArray *tmpArr = [NSMutableArray array];
|
|
|
- for (NSDictionary *item in menuArr) {
|
|
|
+ NSArray *items = [json objectForKey:@"items"];
|
|
|
+ for (NSDictionary *item in items) {
|
|
|
|
|
|
- ApexResultMenuItem *menuItem = [ApexResultMenuItem new];
|
|
|
- [menuItem setValuesForKeysWithDictionary:item];
|
|
|
- [tmpArr addObject:menuItem];
|
|
|
- }
|
|
|
- self.menuItems = [tmpArr copy];
|
|
|
- }
|
|
|
-
|
|
|
- // refresh UI
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ NSInteger type = [[item objectForKey:@"type"] integerValue];
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case ApexResultTypeBooking: {
|
|
|
+ ApexResultBookingModel *model = [ApexResultBookingModel new];
|
|
|
+ [model setValuesForKeysWithDictionary:item];
|
|
|
+ [modelsArr addObject:model];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ApexResultTypeBLInfo: {
|
|
|
+ ApexResultBLInfoModel *model = [ApexResultBLInfoModel new];
|
|
|
+ [model setValuesForKeysWithDictionary:item];
|
|
|
+ [modelsArr addObject:model];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ApexResultTypeContainer: {
|
|
|
+ ApexResultContainerModel *model = [ApexResultContainerModel new];
|
|
|
+ [model setValuesForKeysWithDictionary:item];
|
|
|
+ [modelsArr addObject:model];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ApexResultTypeDocument: {
|
|
|
+ ApexResultDocumentModel *model = [ApexResultDocumentModel new];
|
|
|
+ [model setValuesForKeysWithDictionary:item];
|
|
|
+ [modelsArr addObject:model];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ } // for
|
|
|
+ strongSelf.offset = modelsArr.count;
|
|
|
|
|
|
- self.dataArray = [modelsArr copy];
|
|
|
- if (self.delegate) {
|
|
|
- [self.delegate onStopLoading];
|
|
|
- [self.delegate onSuccess:title];
|
|
|
- if (items.count < detal) {
|
|
|
- [self.delegate onNoMoreData];
|
|
|
+ NSString *title = [json objectForKey:@"title"];
|
|
|
+ strongSelf.rowActions = [json objectForKey:@"row_actions"];
|
|
|
+ strongSelf.actions = [json objectForKey:@"actions"];
|
|
|
+
|
|
|
+ // menu
|
|
|
+ NSArray *menuArr = [json objectForKey:@"menu"];
|
|
|
+ if (menuArr) {
|
|
|
+ NSMutableArray *tmpArr = [NSMutableArray array];
|
|
|
+ for (NSDictionary *item in menuArr) {
|
|
|
+
|
|
|
+ ApexResultMenuItem *menuItem = [ApexResultMenuItem new];
|
|
|
+ [menuItem setValuesForKeysWithDictionary:item];
|
|
|
+ [tmpArr addObject:menuItem];
|
|
|
}
|
|
|
+ strongSelf.menuItems = [tmpArr copy];
|
|
|
}
|
|
|
|
|
|
- });
|
|
|
-
|
|
|
- } else {
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- if (self.delegate) {
|
|
|
- [self.delegate onStopLoading];
|
|
|
- [self.delegate onFailed:@"Sorry, something is wrong"];
|
|
|
- }
|
|
|
- });
|
|
|
+ // refresh UI
|
|
|
+ [strongSelf loadDataSuccessWithTitle:title itemsArray:modelsArr itemCount:items.count];
|
|
|
+
|
|
|
+ } else {
|
|
|
+ [strongSelf loadDataFailed];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
});
|