| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718 |
- //
- // TearSeetParamViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 11/11/15.
- // Copyright © 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "TearSheetParamViewController.h"
- #import "iSalesNetwork.h"
- #import "PDFViewController.h"
- #import "MainViewController.h"
- #import "Singleton.h"
- @interface TearSheetParamViewController ()
- @end
- @implementation TearSheetParamViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
-
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onCloseClick:)];
- //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
- // closeButton.title = @"Close";
- // closeButton.tintColor = UIColorFromRGB(0x996633);
- self.navigationItem.leftBarButtonItem = closeButton;
-
-
-
- UIBarButtonItem *previewbtn = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
-
- previewbtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"preview"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onPreviewClick:)];
-
- // previewbtn.tintColor = UIColorFromRGB(0x996633);
-
- UIBarButtonItem *savebtn = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
-
- savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onSaveClick:)];
-
- // savebtn.tintColor = UIColorFromRGB(0x996633);
- _savebtn = savebtn;
-
-
- UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
- fixedItem.width = 0.0f;
-
- NSMutableArray * items = [[NSMutableArray alloc]init];
-
- [items addObject:previewbtn];
- [items addObject:fixedItem];
- [items addObject:savebtn];
-
- // [items addObject:item2];
- self.navigationItem.rightBarButtonItems=items;
-
-
-
- // self.navigationItem.rightBarButtonItem = previewbtn;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)onCloseClick:(UIButton *)sender {
- [self.navigationController dismissViewControllerAnimated:true completion:^{
- ;
- }];
- }
- - (void)onPreviewClick:(UIButton *)sender {
-
- // add params check here.
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
-
- // self.cancommit=true;
- // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
- // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSString* key = [itemjson valueForKey:@"name"];
- // if(key==nil || key.length==0)
- // continue;
- // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
- // {
- // NSString* single_select = [itemjson valueForKey:@"single_select"];
- // if([single_select isEqualToString:@"true"])
- // {
- // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- // int count = [[cadejson valueForKey:@"count"] intValue];
- // bool setvalue = false;
- // for(int cc=0;cc<count;cc++)
- // {
- // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- // if([[valjson valueForKey:@"check"]intValue]==1)
- // {
- // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
- // setvalue=true;
- // break;
- // }
- // }
- // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- // {
- // self.cancommit = false;
- // }
- // }
- // else
- // {
- // //not support multi select for now;
- // }
- // /*
- // upparams setValue:itemjson forKey:<#(NSString *)#>
- //
- // */
- // }else
- // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
- // {
- // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
- // self.cancommit = false;
- // }
- // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
- // {
- // NSString* valuestr = [itemjson valueForKey:@"value"];
- // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
- //
- // NSString* value = [itemjson valueForKey:@"value"];
- // NSMutableDictionary* boolitem=nil;
- // NSMutableDictionary* subjson=nil;
- // if([value isEqualToString:@"true"])
- // {
- // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
- //
- // }
- // else
- // {
- // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
- //
- // }
- // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
- // if( subjson!=nil /*&& !active*/)
- // {
- // int sub_count = [[subjson valueForKey:@"count"] intValue];
- // for(int l=0;l<sub_count;l++)
- // {
- // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
- //
- //
- //
- //
- // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
- // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
- // else
- // {
- // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
- // self.cancommit = false;
- // }
- // }
- //
- //
- //
- // }
- // }
- // else
- // {
- // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
- // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- // else
- // {
- // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- // self.cancommit = false;
- // }
- // }
- // upparams= [self subitem_param:itemjson addto:upparams ];
- // }
- // }
- // if(self.cancommit==false)
- // {
- //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Some requried field is missing" message:@"Fields with * mark cannot be empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
- //// //UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
- //// [alert show];
- //
- //
- // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
- // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- // //NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- // //[self.editorTable reloadData ];
- // [self.editorTable reloadData];
- // return;
- // }
- NSMutableDictionary* upparams = [self check_cancommit:true];
- if(self.cancommit==false)
- return;
-
- NSMutableString* pdf_url = [[self.content_data_download valueForKey:@"pdf_url"] mutableCopy];
-
- // NSLog([RAUtils dict2string:self.content_data_download]);
-
- bool bremove=false;
-
- NSString* catelog_name= nil;
- NSString* internal_note= nil;
- NSArray *keys= [upparams allKeys];
- //遍历keys
- for(int i=0;i<[keys count];i++)
- {
-
- //得到当前key
- NSString *key=[keys objectAtIndex:i];
- if([key isEqualToString:@"remove_item"])
- {
- bremove=[[upparams valueForKey:key]boolValue];
- continue;
- }
-
-
-
- if([key isEqualToString:@"catalog_name"])
- {
- catelog_name=[upparams valueForKey:key];
-
- }
- if([key isEqualToString:@"internal_note"])
- {
- internal_note=[upparams valueForKey:key];
-
- }
-
-
- [pdf_url appendString:@"&"];
-
- [pdf_url appendString:key];
- //如果key不是pic,说明value是字符类型,比如name:Boris
- NSString* valuefrom = [upparams valueForKey:key];
-
- valuefrom = [NSString stringWithFormat:@"%@",valuefrom];
-
- [pdf_url appendString:@"="];
-
-
-
-
- [pdf_url appendString:[valuefrom stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
-
- // NSString* value=[self getValue:valuefrom];
-
- // [ret setValue:value forKey:valuefrom];
- }
-
- upparams[@"pdfUrl"]=pdf_url;
-
- upparams[@"product_ids"]=self.product_ids;
- upparams[@"item_ids"]=self.item_ids;
-
- // pdf_url=[pdf_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
-
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Processing"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* editor_json = [iSalesNetwork request_TearSheet:upparams];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
- // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSString* url = [editor_json valueForKey:@"pdf_path"];
- NSString* path = [editor_json valueForKey:@"pdf_real_path"];
- bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
- PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
- ViewController.url = url;
- ViewController.canSave = true;
- ViewController.isLocalfile=isLocalFile;
- // ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
-
- ViewController.save_name =catelog_name;
- ViewController.save_note =internal_note;
- //ViewController.filename = catelog_name;
- NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
-
- if(company==nil)
- company=@"";
- // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
-
-
- // NSMutableArray* send_to = [[NSMutableArray alloc]init];
- // if(customer_email.length>0)
- // [send_to addObject:customer_email];
- // ViewController.mail_to = send_to;
-
-
-
- // 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;
-
- NSString* subject;
- // if (company.length==0) {
-
- // NSString* cur_time =[RAUtils current_date];
- subject =catelog_name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
-
-
-
- // }
- // else
- // {
- // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
- // }
- ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",catelog_name];//[NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
- ViewController.mail_subject = subject;
-
- // ViewController.onLoadSuccess =^(NSString* url)
- // {
- //
- // };
-
-
- ViewController.onSavePDF=^(NSString* name,NSString* file)
- {
-
-
- NSString* del_ids = nil;
- if(bremove)
- del_ids=[self.params valueForKey:@"item_ids"];
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Saving..."];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* json = [iSalesNetwork save_TearSheet:path name:name delete:del_ids note:internal_note configureParams:pdf_url modelIds:upparams];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[json valueForKey:@"result"] intValue]==2)
- {
- [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
-
- [self.navigationController dismissViewControllerAnimated:true completion:^{
- [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
- // if(self.onDismiss)
- // self.onDismiss(catelog_name);
- }];
- }
- else
- {
- [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
- }
-
- });
- });
-
-
-
- };
-
- // ViewController. = self.function_name;
- // ViewController.behavior =BEHAVIOR_SEARCH;
- ViewController.hidenavi = false;
- [self.navigationController pushViewController:ViewController animated:YES];
- // [[self navigationController] setNavigationBarHidden:NO animated:NO];
-
-
- /*
- if(self.return_url)
- self.return_url(url,path,bremove);
- [self.navigationController dismissViewControllerAnimated:true completion:^{
- if(self.onDismiss)
- self.onDismiss(catelog_name);
- }];
- */
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
- }
-
-
-
-
- });
- });
-
-
-
-
- }
- - (void)onSaveClick:(UIButton *)sender {
-
- // add params check here.
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
- // self.cancommit=true;
- // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
- // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSString* key = [itemjson valueForKey:@"name"];
- // if(key==nil || key.length==0)
- // continue;
- // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
- // {
- // NSString* single_select = [itemjson valueForKey:@"single_select"];
- // if([single_select isEqualToString:@"true"])
- // {
- // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- // int count = [[cadejson valueForKey:@"count"] intValue];
- // bool setvalue = false;
- // for(int cc=0;cc<count;cc++)
- // {
- // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- // if([[valjson valueForKey:@"check"]intValue]==1)
- // {
- // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
- // setvalue=true;
- // break;
- // }
- // }
- // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- // {
- // self.cancommit = false;
- // }
- // }
- // else
- // {
- // //not support multi select for now;
- // }
- // /*
- // upparams setValue:itemjson forKey:<#(NSString *)#>
- //
- // */
- // }else
- // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
- // {
- // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
- // self.cancommit = false;
- // }
- // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
- // {
- // NSString* valuestr = [itemjson valueForKey:@"value"];
- // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
- //
- // NSString* value = [itemjson valueForKey:@"value"];
- // NSMutableDictionary* boolitem=nil;
- // NSMutableDictionary* subjson=nil;
- // if([value isEqualToString:@"true"])
- // {
- // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
- //
- // }
- // else
- // {
- // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
- //
- // }
- // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
- // if( subjson!=nil /*&& !active*/)
- // {
- // int sub_count = [[subjson valueForKey:@"count"] intValue];
- // for(int l=0;l<sub_count;l++)
- // {
- // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
- //
- //
- //
- //
- // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
- // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
- // else
- // {
- // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
- // self.cancommit = false;
- // }
- // }
- //
- //
- //
- // }
- // }
- // else
- // {
- // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
- // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- // else
- // {
- // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- // self.cancommit = false;
- // }
- // }
- // upparams= [self subitem_param:itemjson addto:upparams ];
- // }
- // }
- // if(self.cancommit==false)
- // {
- //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Some requried field is missing" message:@"Fields with * mark can not be empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
- //// //UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
- //// [alert show];
- //
- // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
- // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- // //NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- // //[self.editorTable reloadData ];
- // [self.editorTable reloadData];
- // return;
- // }
-
-
-
- NSMutableDictionary* upparams = [self check_cancommit:true];
- if(self.cancommit==false)
- return;
-
- NSMutableString* pdf_url = [[self.content_data_download valueForKey:@"pdf_url"] mutableCopy];
-
- // NSLog([RAUtils dict2string:self.content_data_download]);
-
- bool bremove=false;
-
- NSString* catelog_name= nil;
- NSString* internal_note = nil;
- NSArray *keys= [upparams allKeys];
- //遍历keys
- for(int i=0;i<[keys count];i++)
- {
-
- //得到当前key
- NSString *key=[keys objectAtIndex:i];
- if([key isEqualToString:@"remove_item"])
- {
- bremove=[[upparams valueForKey:key]boolValue];
- continue;
- }
-
-
-
- if([key isEqualToString:@"catalog_name"])
- {
- catelog_name=[upparams valueForKey:key];
-
- }
-
- if([key isEqualToString:@"internal_note"])
- {
- internal_note=[upparams valueForKey:key];
-
- }
-
- [pdf_url appendString:@"&"];
-
- [pdf_url appendString:key];
- //如果key不是pic,说明value是字符类型,比如name:Boris
- NSString* valuefrom = [upparams valueForKey:key];
-
- valuefrom = [NSString stringWithFormat:@"%@",valuefrom];
-
- [pdf_url appendString:@"="];
-
-
-
-
- [pdf_url appendString:[valuefrom stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
-
- // NSString* value=[self getValue:valuefrom];
-
- // [ret setValue:value forKey:valuefrom];
- }
-
- upparams[@"product_ids"]=self.product_ids;
- upparams[@"item_ids"]=self.item_ids;
-
- __block NSString* saveName = catelog_name;
-
- __block NSString* saveNote = internal_note;
- NSString* del_ids = nil;
- if(bremove)
- del_ids=[self.params valueForKey:@"item_ids"];
-
- // pdf_url=[pdf_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Save pdf" message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
- [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- textField.text = saveName;
-
-
- }];
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-
- UITextField *name = alertControl.textFields.firstObject;
- if(name.text.length==0)
- {
- [RAUtils message_alert:@"Cannot save without name. Save canceled." title:@"Name is missing" controller:self];
- }
- else
- {
- saveName = name.text;
- _savebtn.enabled =false;
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Processing"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* editor_json = [iSalesNetwork direct_save_TearSheet:pdf_url name:saveName delete:del_ids note:saveNote modelIds:upparams];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- // [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
- NSString* url = [editor_json valueForKey:@"pdf_path"];
- [self.navigationController dismissViewControllerAnimated:true completion:^{
- [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
- if(self.onSaved)
- self.onSaved(url,saveName);
- }];
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
- }
-
-
-
-
- });
- });
- }
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSLog(@"Cancel");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
-
-
-
-
-
-
-
-
- }
- /*
- #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
|