| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
- //
- // AddExtDocumentViewController.m
- // Granite Expo eSign
- //
- // Created by Ray on 01/03/2017.
- // Copyright © 2017 United Software Applications, Inc. All rights reserved.
- //
- #import "AddExtDocumentViewController.h"
- //#import "MenuViewController.h"
- //#import "RAMenu.h"
- #import "ImageUtils.h"
- #import "const.h"
- #import "RAUtils.h"
- #import "ACNetwork.h"
- #import "PDFViewController.h"
- #import "ScannerViewController.h"
- @interface AddExtDocumentViewController ()
- @end
- @implementation AddExtDocumentViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.editDocNumber.text = self.doc_number;
-
-
- if(self.doc_number.length>0)
- {
- self.editDocNumber.enabled = false;
- self.btnScan.enabled = false;
- }
-
-
- self.edgesForExtendedLayout = UIRectEdgeNone;
- if(self.arr_documents==nil)
- self.arr_documents = [[NSMutableArray alloc]init];
-
-
-
- if (self.is_present) {
- UIBarButtonItem *closeButton =nil;
-
-
-
- closeButton=[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector( onCloseClick:)];
-
-
- self.navigationItem.rightBarButtonItem = closeButton;
- }
- // else {
- // [self dismissViewControllerAnimated:YES completion:nil];
- // }
- // {
- //
- //
- //
- // }
- // Do any additional setup after loading the view.
- }
- -(void) refresh_table
- {
- [self.tableView reloadData];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (IBAction)onCloseClick:(id)sender {
-
- [self dismissViewControllerAnimated:false completion:nil];
- }
- - (IBAction)onScanClicked:(id)sender {
-
- __weak typeof(self) weakself = self;
- ScannerViewController * scannerVC =[ [UIStoryboard storyboardWithName:@"cam_scan" bundle:nil] instantiateViewControllerWithIdentifier:@"ScannerViewController"];;
-
- scannerVC.returnCode = ^(NSString* code){
-
- weakself.editDocNumber.text = code;
-
- };
- [self presentViewController:scannerVC animated:false completion:nil];
- }
- - (IBAction)onAddImageClicked:(id)sender {
-
- __weak typeof(self) weakself = self;
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add Image From" message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
- // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- // textField.text = self.save_name;
- //
- //
- // }];
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Album" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- NSUInteger sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
- UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
-
- imagePickerController.delegate = weakself;
-
- imagePickerController.allowsEditing = NO;
-
- imagePickerController.sourceType = sourceType;
-
- [self presentViewController:imagePickerController animated:YES completion:^{}];
- }];
- UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"Take a photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
- {
- return;
- }
-
- NSUInteger sourceType=UIImagePickerControllerSourceTypeCamera;
- UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
-
- imagePickerController.delegate = weakself;
-
- imagePickerController.allowsEditing = YES;
-
- imagePickerController.sourceType = sourceType;
-
- [self presentViewController:imagePickerController animated:YES completion:^{}];
-
- }];
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
-
- }];
- [alertControl addAction:actionOne];
- [alertControl addAction:action2];
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
-
-
-
- return;
- /*
- NSMutableArray* menuItem = [NSArray arrayWithObjects:@"aaa",@"bbb",nil];
-
- UIView* v= sender;
-
- RAMenu * menu= [[RAMenu alloc]initWithFrame:CGRectMake(v.frame.origin.x, v.frame.origin.y, 120, 88)];
- // menu.backgroundColor= [UIColor whiteColor];
- menu.arr_menuItems = menuItem;
- [self.view addSubview:menu];
-
- menu.hidden = false;
-
- return;
-
- MenuViewController *menuVC = [[MenuViewController alloc]init];
- menuVC.arr_menuItems = [menuItem mutableCopy];
-
- */
- //
- // menuVC.title=@"menu";
- // signatureVC.signatureData = self.signatureData;
-
- //
- // signatureVC.blk_Add = ^()
- // {
- //
- // __block UIImage* signimg=nil;
- // SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
- //
- // vc.onReturnImg = ^(UIImage* img)
- // {
- //
- //
- // signimg = img;
- //
- // // if(signimg!=nil)
- // // [PDFUtils addSignature:signimg to:self.signatureData];
- //
- //
- //
- //
- // };
- //
- // // orderinfoVC.url_type = URL_REMOTE;
- // // orderinfoVC.request_url=URL_CARTDELIVERY;
- // //
- // // orderinfoVC.params = params;
- // //
- // // orderinfoVC.delegate=self;
- // //
- // // if(checked.count==count)
- // // {
- // // orderinfoVC.have_tail = true
- // // }
- //
- // [self.navigationController pushViewController:vc animated:true];
- //
- //
- //
- // };
-
- /*
- UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:menuVC];
- navi.modalPresentationStyle=UIModalPresentationPopover;
-
- UIPopoverPresentationController* popPc = navi.popoverPresentationController;
- popPc.permittedArrowDirections = UIPopoverArrowDirectionUp;
- popPc.sourceView = sender;
- popPc.delegate = nil;
-
-
-
- [self presentViewController:navi animated:true completion:nil];
- */
-
- }
- - (IBAction)onAddFileClicked:(id)sender {
- [RAUtils alert_view:@"To upload a file, you must share it from Third Party App." title:@"Upload"];
- return;
- }
- - (IBAction)onUploadClicked:(id)sender {
-
- if(self.arr_documents.count==0)
- {
- [RAUtils alert_view:@"Upload list is empty." title:@"Upload"];
- return;
- }
-
- NSString* docNumber = self.editDocNumber.text;
- if(docNumber.length==0)
- {
- [RAUtils alert_view:@"Document number is empty." title:@"Upload"];
- return;
- }
-
- NSString* zipfile = nil;
- NSMutableArray* arr_files= [[NSMutableArray alloc]init];
-
- for(int i=0;i<self.arr_documents.count;i++)
- {
-
- [arr_files addObject:self.arr_documents[i][@"url"] ];
-
-
-
-
- }
- zipfile =[ACNetwork packfiles2zip:arr_files];
-
-
- __weak typeof(self) weakSelf = self;
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Upload Documents"];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* json = nil;
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- params[@"doc_number"]=docNumber;
- json = [ACNetwork upload_file:zipfile params:params];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
- if([[json valueForKey:@"result"] intValue]==2)
- {
- NSMutableArray* arr = [json[@"documents"] mutableCopy];
- if(self.is_present)
- [weakSelf dismissViewControllerAnimated:false completion:^{
- if(weakSelf.uploadSuccess)
- weakSelf.uploadSuccess(arr);
-
- }];
- else
- {
- if(weakSelf.uploadSuccess)
- weakSelf.uploadSuccess(arr);
- [self.navigationController popViewControllerAnimated:false];
- }
-
- // if(self.uploadSuccess)
- // self.uploadSuccess(self.arr_documents);
-
- }
- else
- {
- [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Documents" controller:self] ;
- }
-
-
- });
- });
-
- }
- #pragma mark - Table view data source
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- {
-
- return 44;
-
-
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- //{
- // return 44;
- //}
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
-
- return self.arr_documents.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
-
-
-
-
-
-
- NSString *CellIdentifier = @"ADTableViewCell";
- UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
-
- if (cell == nil) {
-
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
-
- }
- NSDictionary * item_json = self.arr_documents[indexPath.row];
- NSString* type = item_json[@"type"];
- NSString* file_name = item_json[@"file_name"];
- NSString* upload_date = item_json[@"upload_date"];
- NSString* url = item_json[@"url"];
- if([type isEqualToString:@"file"])
- cell.imageView.image = [UIImage imageNamed:@"file_icon"];
- else
- cell.imageView.image = [UIImage imageNamed:@"picture_icon"];
-
-
-
- cell.textLabel.text = file_name;
- cell.detailTextLabel.text = upload_date;
-
-
-
- return cell;
-
- }
- #pragma mark tableview delegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- NSDictionary * item_json = self.arr_documents[indexPath.row];
-
- NSString* url = item_json[@"url"];
-
-
-
- bool isLocalFile= true;//[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.hidenavi = false;
-
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:ViewController] ;
-
-
-
-
-
-
- navi.modalPresentationStyle = UIModalPresentationFullScreen;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
- }];
-
-
-
-
- }
- - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
-
-
- // NSDictionary * item_json = self.arr_documents[indexPath.row];
-
-
- UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
-
- [self.arr_documents removeObjectAtIndex:indexPath.row];
- [self.tableView reloadData];
-
- }];
-
-
- deleteAction.backgroundColor = UIColorFromRGB(0xff9933);
-
-
-
-
- return @[deleteAction];
-
-
- }
- - (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 - imagePicker delegate
- - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
- {
- // self.dirty = true;
- /*-------------------------------相机拍照--------------------------------------*/
- if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
-
- UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage];
-
- image=[ImageUtils img_compress:image kbsize:1024];
-
-
- NSString *path = NSTemporaryDirectory();
- NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",[[NSUUID UUID] UUIDString]]];
- [UIImageJPEGRepresentation(image, 1.0) writeToFile:filePath atomically:YES];
- NSMutableDictionary* item = [[NSMutableDictionary alloc]init];
- item[@"type"]=@"image";
- item[@"url"]= filePath;
- item[@"file_name"]= [filePath lastPathComponent];
- [self.arr_documents addObject:item];
- [self.tableView reloadData];
- [picker dismissViewControllerAnimated:YES completion:^{
- }];
-
- } else if (picker .sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
-
- /**
- * UIImagePickerControllerEditedImage 取得的是被编辑过的图片,需要allowsEditing设置为YES
- * UIImagePickerControllerOriginalImage 取得的是相册中原始图片
- */
- UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];
-
- image=[ImageUtils img_compress:image kbsize:1024];
-
- NSString *path = NSTemporaryDirectory();
- NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",[[NSUUID UUID] UUIDString]]];
- [UIImageJPEGRepresentation(image, 1.0) writeToFile:filePath atomically:YES];
- NSMutableDictionary* item = [[NSMutableDictionary alloc]init];
- item[@"type"]=@"image";
- item[@"url"]= filePath;
- item[@"file_name"]= [filePath lastPathComponent];
- [self.arr_documents addObject:item];
- [self.tableView reloadData];
-
-
- [picker dismissViewControllerAnimated:YES completion:nil];
- }
-
-
- }
- - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
-
- [picker dismissViewControllerAnimated:YES completion:nil];
- // [picker presentViewController:cameraPicker animated:YES completion:nil];
- // DebugLog(@"%s",__FUNCTION__);
- }
- /*
- #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
|