|
|
@@ -57,15 +57,19 @@ static const NSInteger detal = 20;
|
|
|
|
|
|
#pragma mark - Data
|
|
|
|
|
|
-- (void)loadDataFailed {
|
|
|
+- (void)loadDataFailed:(NSString*)msg {
|
|
|
|
|
|
+ if(msg.length==0)
|
|
|
+ {
|
|
|
+ msg=@"Sorry, can not connect to the server, please try again later.";
|
|
|
+ }
|
|
|
__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, can not connect to the server, please try again later."];
|
|
|
+ [strongSelf.delegate onFailed:msg];
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -183,95 +187,97 @@ static const NSInteger detal = 20;
|
|
|
[strongSelf loadDataSuccessWithTitle:title itemsArray:modelsArr itemCount:items.count];
|
|
|
|
|
|
} else {
|
|
|
- [strongSelf loadDataFailed];
|
|
|
+
|
|
|
+ NSString *msg = [json objectForKey:@"err_msg"];
|
|
|
+ [strongSelf loadDataFailed:msg];
|
|
|
}
|
|
|
|
|
|
}];
|
|
|
|
|
|
return;
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
-
|
|
|
- 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];
|
|
|
- if (weakSelf) {
|
|
|
- __strong typeof(weakSelf) strongSelf = weakSelf;
|
|
|
-
|
|
|
- int result = [[json objectForKey:@"result"] intValue];
|
|
|
- if (result == RESULT_TRUE) {
|
|
|
-
|
|
|
- NSMutableArray *modelsArr = [NSMutableArray array];
|
|
|
- if (option == ApexResultFetchDataTypeLoadMore && strongSelf.dataArray != nil && strongSelf.dataArray.count > 0) {
|
|
|
- [modelsArr addObjectsFromArray:strongSelf.dataArray];
|
|
|
- }
|
|
|
-
|
|
|
- NSArray *items = [json objectForKey:@"items"];
|
|
|
- for (NSDictionary *item in items) {
|
|
|
-
|
|
|
- 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;
|
|
|
-
|
|
|
- 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];
|
|
|
- }
|
|
|
-
|
|
|
- // refresh UI
|
|
|
- [strongSelf loadDataSuccessWithTitle:title itemsArray:modelsArr itemCount:items.count];
|
|
|
-
|
|
|
- } else {
|
|
|
- [strongSelf loadDataFailed];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
+//
|
|
|
+// dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
+//
|
|
|
+// 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];
|
|
|
+// if (weakSelf) {
|
|
|
+// __strong typeof(weakSelf) strongSelf = weakSelf;
|
|
|
+//
|
|
|
+// int result = [[json objectForKey:@"result"] intValue];
|
|
|
+// if (result == RESULT_TRUE) {
|
|
|
+//
|
|
|
+// NSMutableArray *modelsArr = [NSMutableArray array];
|
|
|
+// if (option == ApexResultFetchDataTypeLoadMore && strongSelf.dataArray != nil && strongSelf.dataArray.count > 0) {
|
|
|
+// [modelsArr addObjectsFromArray:strongSelf.dataArray];
|
|
|
+// }
|
|
|
+//
|
|
|
+// NSArray *items = [json objectForKey:@"items"];
|
|
|
+// for (NSDictionary *item in items) {
|
|
|
+//
|
|
|
+// 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;
|
|
|
+//
|
|
|
+// 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];
|
|
|
+// }
|
|
|
+//
|
|
|
+// // refresh UI
|
|
|
+// [strongSelf loadDataSuccessWithTitle:title itemsArray:modelsArr itemCount:items.count];
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// [strongSelf loadDataFailed];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// });
|
|
|
}
|
|
|
|
|
|
- (void)loadData {
|