// // PendingDocumentsViewController.m // Granite Expo eSign // // Created by Ray on 11/04/2017. // Copyright © 2017 United Software Applications, Inc. All rights reserved. // #import "PendingDocumentsViewController.h" #import "ACNetwork.h" #import "PendingDocumentsTableViewCell.h" #import "RAUtils.h" #import "GEContractFilterViewController.h" #import "PDFViewController.h" #import "AppDelegate.h" #import "ExtDocumentsViewController.h" #import "DocnotesViewController.h" #import "DocumentPageViewController.h" #import "AddExtDocumentViewController.h" @interface PendingDocumentsViewController () @end @implementation PendingDocumentsViewController - (void)viewDidLoad { [super viewDidLoad]; self.offset = 0; self.limit = 20; self.table_data = [[NSMutableArray alloc] init]; self.filterparams = [[NSMutableDictionary alloc]init]; UIRefreshControl *ref = [[UIRefreshControl alloc]init]; ref.tag = 201 ; ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"]; ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7]; // ref.hidden = true; [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged]; [self.tableView addSubview:ref]; // NSMutableArray * arr = [[NSMutableArray alloc] init]; // for(int i=0;i<100;i++) // { // [arr addObject:[NSNumber numberWithInt:i]]; // } // NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; // dict[@"arr"] = arr; // DebugLog([RAUtils dict2string:dict]); [self loadpage]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)onAddClick:(id)sender { __weak typeof(self) weakself = self; { AddExtDocumentViewController * addVC; addVC = [ [UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AddExtDocumentViewController"]; addVC.is_present = true; addVC.doc_number = nil; addVC.uploadSuccess = ^(NSMutableArray* arr_upload){ if(arr_upload.count>0) [weakself loadpage]; }; //addVC.arr_documents = [NSMutableArray arrayWithObjects:appDelegate.shareFile, nil]; //appDelegate.shareFile=nil; // notesVC.docNotes = notes; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:addVC] ; navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); DebugLog(@"filter present........."); // self.btop = false; // <#code#> }]; } } - (IBAction)onFilterClick:(id)sender { GEContractFilterViewController * filterVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"GEContractFilterViewController"]; filterVC.filterparams = self.filterparams; filterVC.OnSearch = ^(NSMutableDictionary* params) { // [self reload_container_getdata:true]; self.reset_result=true; // self.norefresh=true; [self loadpage]; }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:filterVC] ; navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); DebugLog(@"filter present........."); // self.btop = false; // <#code#> }]; } -(void) previewPDF:(NSString*)url title:(NSString*)title subject:(NSString*)subject { NSString* name=@"";//[self.content_data[indexPath.row] valueForKey:@"tear_name"]; // NSString* url= file;//[self.content_data[indexPath.row] valueForKey:@"pdf_path"]; bool isLocalFile= false;//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"]; PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"]; ViewController.url = url; ViewController.canSave = false; ViewController.isLocalfile=isLocalFile; ViewController.defaultStyle = true; ViewController.save_name = title; // NSString* subject; // if (company.length==0) { // NSString* cur_time =[RAUtils current_date]; // subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time]; // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"]; NSMutableArray* send_to = [[NSMutableArray alloc]init]; // if(customer_email.length>0) // { // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy]; // // customer_email compo // // [send_to addObject:customer_email]; // } ViewController.mail_to = send_to; // } // else // { // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ]; // } // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time]; ViewController.mail_subject = subject; ViewController.hidenavi = false; [self.navigationController pushViewController:ViewController animated:YES]; } #pragma mark - OperationQueue request page data -(void) loadpage { NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults]; self.table_data = [[defaults arrayForKey:@"pending_doc"] mutableCopy]; } - (void)loadmore { // self.btnrefresh.enabled = NO; // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil); // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal]; [self loadpage]; } -(void)manually_refresh { UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201]; // if(self.isrefreshing) // { // [reF endRefreshing]; // return; // } reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"]; if ([self respondsToSelector:@selector(ReloadData)]) [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1]; } -(void)ReloadData { // [self.content_data removeAllObjects]; // [self.table_order reloadData]; // self.table_order.hidden = true; UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201]; [reF endRefreshing]; reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"]; // self.keywords=self.searchbar.text; // // self.offset = 0; self.reset_result=true; // [self.content_data removeAllObjects]; // [self.table_order reloadData]; [self loadpage]; // [self loadpage]; } -(void)refresh_btn_click:(UILongPressGestureRecognizer*)gestureRecognizer { // [self reload_container_getdata:true]; self.reset_result=true; // self.norefresh=true; [self loadpage]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ #pragma mark - Table view data source - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { return 44; } //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section //{ // return 0; //} //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section //{ // return 0; //} //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section //{ // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)]; // return myView; // //} - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { NSString* value =nil;//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"]; if(value==nil) value=@""; unsigned long color = strtoul([value UTF8String],0,16); UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)]; myView.backgroundColor = UIColorFromRGB(0xf7f7f7); myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath; myView.layer.shadowColor = [UIColor blackColor].CGColor; myView.layer.shadowOffset = CGSizeMake(0, 0); myView.layer.shadowOpacity = 0.5; myView.layer.shadowRadius = 2.0; UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 2, 130, 22)]; statuslabel.textColor=UIColorFromRGB(color); statuslabel.backgroundColor = [UIColor clearColor]; statuslabel.text=NSLocalizedString(@"Document #", nil); [statuslabel sizeToFit]; [myView addSubview:statuslabel]; UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(143, 2, 135, 22)]; userlabel.textColor=UIColorFromRGB(color); userlabel.backgroundColor = [UIColor clearColor]; userlabel.text=NSLocalizedString(@"Customer", nil); [userlabel sizeToFit]; [myView addSubview:userlabel]; // UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(155, 21, 135, 22)]; // creatorlabel.textColor=UIColorFromRGB(color); // creatorlabel.backgroundColor = [UIColor clearColor]; // creatorlabel.text=NSLocalizedString(@"Create by", nil); // [creatorlabel sizeToFit]; // [myView addSubview:creatorlabel]; UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(345, 2, 150, 22)]; contactlabel.textColor=UIColorFromRGB(color); contactlabel.backgroundColor = [UIColor clearColor]; contactlabel.text=NSLocalizedString(@"Job Date", nil); [contactlabel sizeToFit]; [myView addSubview:contactlabel]; // // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)]; // modellabel.textColor=[UIColor whiteColor]; // modellabel.backgroundColor = [UIColor clearColor]; // modellabel.text=NSLocalizedString(@"Model", nil); // [modellabel sizeToFit]; // [myView addSubview:modellabel]; // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)]; // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin; // modellabel.textColor=[UIColor whiteColor]; // modellabel.backgroundColor = [UIColor clearColor]; // modellabel.text=NSLocalizedString(@"Items/QTY", nil); // [modellabel sizeToFit]; // [myView addSubview:modellabel]; UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.tableView.frame.size.width-313, 2, 100, 22)]; pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin; pricelabel.textColor=UIColorFromRGB(color); pricelabel.backgroundColor = [UIColor clearColor]; pricelabel.text=NSLocalizedString(@"Agent Name", nil); [pricelabel sizeToFit]; [myView addSubview:pricelabel]; UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.tableView.frame.size.width-131/*605*/,2, 148, 22)]; timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin; timelabel.textColor=UIColorFromRGB(color); timelabel.backgroundColor = [UIColor clearColor]; // if(self.time_zone==nil) timelabel.text=@"Create by"; // else // timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone]; [timelabel sizeToFit]; [myView addSubview:timelabel]; myView.autoresizesSubviews=true; // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin]; // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; myView.autoresizingMask = UIViewAutoresizingFlexibleWidth; // return myView; } //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section //{ // // // NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"]; // // if(value==nil) // value=@""; // unsigned long color = strtoul([value UTF8String],0,16); // // // DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)]; // // myView.backgroundColor = UIColorFromRGB(0x996633);; // // // myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath; // // myView.layer.masksToBounds = false; // //添加四个边阴影 // // myView.layer.shadowColor = [UIColor blackColor].CGColor; // myView.layer.shadowOffset = CGSizeMake(0, 0); // myView.layer.shadowOpacity = 0.5; // myView.layer.shadowRadius = 2.0; // // // NSString*labeltitle = nil; // switch (section) { // case 0: // labeltitle= @"Order Info"; // break; // case 1: // { // labeltitle= @"More Info"; // // NSString* btntitle=nil ; // if(self.showMore) // { // btntitle=@"Hide"; // // [section setValue:@"false" forKey:@"hide"]; // // [sender setTitle:@"Show" forState:UIControlStateNormal]; // } // else{ // btntitle=@"Show"; // } // // // UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)]; // btn.tag=section; // [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside]; // [btn setTitle:btntitle forState:UIControlStateNormal]; // [myView addSubview:btn]; // // } // break; // case 2:{ // labeltitle= @"Models"; // // NSString* btntitle=nil ; // if(self.showModels) // { // btntitle=@"Hide"; // } // else{ // btntitle=@"Show"; // } // // // UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)]; // btn.tag=section; // // [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside]; // // [btn setTitle:btntitle forState:UIControlStateNormal]; // [myView addSubview:btn]; // // } // break; // case 3: // labeltitle= @"Price Info"; // default: // break; // } // // // // UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)]; // titlelabel.textColor=UIColorFromRGB(color);; // titlelabel.backgroundColor = [UIColor clearColor]; // titlelabel.text=NSLocalizedString(labeltitle, nil); // [titlelabel sizeToFit]; // [myView addSubview:titlelabel]; // // // // return myView; //} //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { // // return [NSString stringWithFormat:@"Signature%ld",(long)section+1]; // //} - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 22; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.table_data.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = @"PendingDocumentsTableViewCell"; PendingDocumentsTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSDictionary * item_json = self.table_data[indexPath.row]; cell.labelAgent.text = item_json[@"agent_name"]; // if(sss.length==0) // sss=@""; cell.labelDocID.text = item_json[@"doc_number"];// cell.labelJobDate.text =item_json[@"job_date"]; cell.labelCustomer.text =item_json[@"customer_name"]; cell.labelSignDate.text =item_json[@"signed_date"]; cell.labelCreateby.text =item_json[@"create_by"]; return cell; } #pragma mark tableview delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary * item_json = self.table_data[indexPath.row]; DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ]; // dvc.templateName = @"debug.json"; dvc.templatePath = [ACNetwork getjsonPath:item_json[@"serial"]]; dvc.pdfPath = [ACNetwork getPDFPath:item_json[@"pdf"]] ; dvc.hide_control =true; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; dvc.no_save = appDelegate.accessMode==AppAccessModeOffline; dvc.docment_id = item_json[@"doc_number"]; dvc.OnSave=^(NSString* file, NSString* subject) { [self.table_data removeObjectAtIndex:indexPath.row]; NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults]; [defaults setObject:self.table_data forKey:@"pending_doc"]; [defaults synchronize]; [self.tableView reloadData]; }; [self.navigationController pushViewController:dvc animated:true]; } - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { // __weak typeof (self) weekself=self; // __weak NSIndexPath* weekindex = indexPath; // NSDictionary * item_json = self.table_data[indexPath.row]; // // NSString* notes = item_json[@"notes"]; // NSString* doc_number = item_json[@"doc_number"]; // // NSMutableArray* arr_doc = [item_json[@"documents"] mutableCopy]; // // UITableViewRowAction *docAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Documents"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { // // DebugLog(@"Documents click"); // // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle]; // // // ExtDocumentsViewController * docVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"ExtDocumentsViewController"]; // // docVC.docNumber = doc_number; // docVC.arr_documents =arr_doc; // // docVC.closeExtDoc=^(bool refresh){ // // if(refresh) // { // // self.reset_result=true; // // self.norefresh=true; // [self loadpage]; // } // // [weekself.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:weekindex, nil] withRowAnimation:UITableViewRowAnimationAutomatic]; // // }; // // notesVC.docNotes = notes; // // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:docVC] ; // // // // // // // navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 // [self presentViewController:navi animated:YES completion:^{ // // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); // // DebugLog(@"filter present........."); // // // self.btop = false; // // <#code#> // }]; // // }]; // // // docAction.backgroundColor = UIColorFromRGB(0xff9933); // // // UITableViewRowAction *modifyAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" Modify " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { // // DebugLog(@"modify click"); // // // // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle]; // // DocnotesViewController * notesVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"DocnotesViewController"]; // // // // notesVC.docNumber = doc_number; // // notesVC.docNotes = notes; // // // // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:notesVC] ; // // // // // // // // // // // // // // navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 // // [self presentViewController:navi animated:YES completion:^{ // // // // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); // // // // DebugLog(@"filter present........."); // // // // // self.btop = false; // // // <#code#> // // }]; // // }]; // // modifyAction.backgroundColor = UIColorFromRGB(0x9BBF5A); // UITableViewRowAction *delAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Delete pending document" message:@"Are you sure?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self.table_data removeObjectAtIndex:indexPath.row]; NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults]; [defaults setObject:self.table_data forKey:@"pending_doc"]; [defaults synchronize]; [self.tableView reloadData]; }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) [self presentViewController:alertControl animated:YES completion:nil]; }]; delAction.backgroundColor = UIColorFromRGB(0x336699); return @[delAction]; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { } - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end