| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162 |
- //
- // 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 "RANetwork.h"
- #import "RAPDFViewController.h"
- #import "MainViewController.h"
- #import "RASingleton.h"
- #import "TextUtils.h"
- #import "JKTimerManager.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];
- // //DebugLog(@"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];
-
- // DebugLog([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]];
-
-
- // [pdf_url appendString:[valuefrom stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"`#%^{}\"[]|\\<> "]]];
-
- [pdf_url appendString:[valuefrom stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
-
- // 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];
-
-
-
-
- __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
- [RANetwork request_portfoliopreview:upparams completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* editor_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- [waitalert dismissViewControllerAnimated:YES completion:^{
- 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];
- RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
- ViewController.url = url;
- ViewController.canSave = true;
- ViewController.isLocalfile=isLocalFile;
- // ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
- ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
- 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"];
-
- #ifdef OFFLINE_MODE
- if (appDelegate.offline_mode)
- {
- [upparams setValue:url forKey:@"pdfPath"];
- }
- else
- #endif
- {
- [upparams setValue:path forKey:@"pdfPath"];
- }
- [upparams setValue:name forKey:@"pdfName"];
- [upparams setValue:internal_note forKey:@"pdfNote"];
- [upparams setValue:del_ids forKey:@"itemIds"];
- [upparams setValue:pdf_url forKey:@"configureParams"];
- __block UIAlertController * waitalert_save = [RAUtils waiting_alert:self title:@"Saving..." completion:^{
- [RANetwork request_save_portfolio:upparams completionHandler:^(NSMutableDictionary *result) {
-
- NSDictionary* json =result;
- [waitalert_save dismissViewControllerAnimated:YES completion:^{
- if([[json valueForKey:@"result"] intValue]==2)
- {
- [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
- // [RAUtils alert_view:nil title: ] ;
-
- [self.navigationController dismissViewControllerAnimated:true completion:^{
-
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
- [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- #endif
- // if(self.onDismiss)
- // self.onDismiss(catelog_name);
- }];
- }
- else
- {
- [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
- }
- }];
-
-
-
-
- }];
- }];
-
-
-
-
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- //
- //#ifdef OFFLINE_MODE
- // if (appDelegate.offline_mode)
- // {
- // [upparams setValue:url forKey:@"pdfPath"];
- // }
- // else
- //#endif
- // {
- // [upparams setValue:path forKey:@"pdfPath"];
- // }
- // [upparams setValue:name forKey:@"pdfName"];
- // [upparams setValue:internal_note forKey:@"pdfNote"];
- // [upparams setValue:del_ids forKey:@"itemIds"];
- // [upparams setValue:pdf_url forKey:@"configureParams"];
- //
- //
- //
- // NSDictionary* json = [RANetwork save_TearSheet:upparams];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- //
- // if([[json valueForKey:@"result"] intValue]==2)
- // {
- // [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
- //// [RAUtils alert_view:nil title: ] ;
- //
- // [self.navigationController dismissViewControllerAnimated:true completion:^{
- //
- //
- //
- //#ifdef RA_NOTIFICATION
- // [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- //#else
- // [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
- // [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- //#endif
- // // 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] ;
- }
- }];
-
-
- }];
- }];
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* editor_json = [RANetwork request_TearSheet:upparams];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //// [waitalert dismissViewControllerAnimated:YES completion:nil];
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- //
- //
- // 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];
- // RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
- // ViewController.url = url;
- // ViewController.canSave = true;
- // ViewController.isLocalfile=isLocalFile;
- // // ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
- // ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
- // 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"];
- //
- // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving..."];
- //
- //
- // #ifdef OFFLINE_MODE
- // if (appDelegate.offline_mode)
- // {
- // [upparams setValue:url forKey:@"pdfPath"];
- // }
- // else
- // #endif
- // {
- // [upparams setValue:path forKey:@"pdfPath"];
- // }
- // [upparams setValue:name forKey:@"pdfName"];
- // [upparams setValue:internal_note forKey:@"pdfNote"];
- // [upparams setValue:del_ids forKey:@"itemIds"];
- // [upparams setValue:pdf_url forKey:@"configureParams"];
- //
- // [RANetwork request_save_portfolio:upparams completionHandler:^(NSMutableDictionary *result) {
- //
- // NSDictionary* json =result;
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- //
- // if([[json valueForKey:@"result"] intValue]==2)
- // {
- // [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
- // // [RAUtils alert_view:nil title: ] ;
- //
- // [self.navigationController dismissViewControllerAnimated:true completion:^{
- //
- //
- //
- //#ifdef RA_NOTIFICATION
- // [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- //#else
- // [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
- // [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- //#endif
- // // if(self.onDismiss)
- // // self.onDismiss(catelog_name);
- // }];
- // }
- // else
- // {
- // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
- // }
- //
- // }];
- //
- //
- //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- ////
- ////
- ////#ifdef OFFLINE_MODE
- //// if (appDelegate.offline_mode)
- //// {
- //// [upparams setValue:url forKey:@"pdfPath"];
- //// }
- //// else
- ////#endif
- //// {
- //// [upparams setValue:path forKey:@"pdfPath"];
- //// }
- //// [upparams setValue:name forKey:@"pdfName"];
- //// [upparams setValue:internal_note forKey:@"pdfNote"];
- //// [upparams setValue:del_ids forKey:@"itemIds"];
- //// [upparams setValue:pdf_url forKey:@"configureParams"];
- ////
- ////
- ////
- //// NSDictionary* json = [RANetwork save_TearSheet:upparams];
- ////
- //// dispatch_async(dispatch_get_main_queue(), ^{
- //// [waitalert dismissViewControllerAnimated:YES completion:nil];
- ////
- ////
- //// if([[json valueForKey:@"result"] intValue]==2)
- //// {
- //// [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
- ////// [RAUtils alert_view:nil title: ] ;
- ////
- //// [self.navigationController dismissViewControllerAnimated:true completion:^{
- ////
- ////
- ////
- ////#ifdef RA_NOTIFICATION
- //// [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- ////#else
- //// [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
- //// [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- ////#endif
- //// // 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];
- // //DebugLog(@"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];
-
- // DebugLog([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]];
- //
- [pdf_url appendString:[valuefrom stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
-
-
-
- // 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;
- self.savebtn.enabled =false;
- [upparams setValue:pdf_url forKey:@"pdfUrl"];
- [upparams setValue:saveName forKey:@"pdfName"];
- [upparams setValue:del_ids forKey:@"itemIds"];
- [upparams setValue:saveNote forKey:@"pdfNote"];
-
- __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
- [RANetwork request_save_portfoliodirectly:upparams completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* editor_json =result;
- [waitalert dismissViewControllerAnimated:YES completion:^{
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
-
-
-
- // [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
- NSString* url = [editor_json valueForKey:@"pdf_path"];
- bool isLocalFile = [editor_json valueForKey:@"isLocalFile"];
- [self.navigationController dismissViewControllerAnimated:true completion:^{
-
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
- [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
-
- #endif
-
- if(self.onSaved)
- self.onSaved(url,saveName,isLocalFile);
- }];
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
- }
- }];
-
-
-
-
-
-
-
- }];
- }];
-
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- //
- // [upparams setValue:pdf_url forKey:@"pdfUrl"];
- // [upparams setValue:saveName forKey:@"pdfName"];
- // [upparams setValue:del_ids forKey:@"itemIds"];
- // [upparams setValue:saveNote forKey:@"pdfNote"];
- //
- // NSDictionary* editor_json = [RANetwork direct_save_TearSheet:upparams];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- //
- //
- //
- //
- // // [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
- // NSString* url = [editor_json valueForKey:@"pdf_path"];
- // bool isLocalFile = [editor_json valueForKey:@"isLocalFile"];
- // [self.navigationController dismissViewControllerAnimated:true completion:^{
- //
- //
- //
- //#ifdef RA_NOTIFICATION
- // [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- //#else
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
- // [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- //
- //#endif
- //
- // if(self.onSaved)
- // self.onSaved(url,saveName,isLocalFile);
- // }];
- //
- // }
- // else
- // {
- // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
- // }
- //
- //
- //
- //
- // });
- // });
- }
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- DebugLog(@"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.
- }
- */
- #pragma mark - Urgency
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self start_urgency_timer];
- }
- -(void) viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self cancel_urgency_timer];
- }
- - (void)dealloc {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
- [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
-
- }
- - (void)start_urgency_timer {
-
- if (!self.editable) {
- return;
- }
-
- __weak typeof(self) weakSelf = self;
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
- #ifdef OFFLINE_MODE
- [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
- #endif
- [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
-
- NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
-
- // DebugLog(@"timer start....");
-
- [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
-
- [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
-
-
- [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
- [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
-
- }];
- }
- - (void)cancel_urgency_timer {
- [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
- }
- @end
|