TearSheetParamViewController.m 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. //
  2. // TearSeetParamViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 11/11/15.
  6. // Copyright © 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "TearSheetParamViewController.h"
  9. #import "RANetwork.h"
  10. #import "RAPDFViewController.h"
  11. #import "MainViewController.h"
  12. #import "RASingleton.h"
  13. #import "TextUtils.h"
  14. #import "JKTimerManager.h"
  15. @interface TearSheetParamViewController ()
  16. @end
  17. @implementation TearSheetParamViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  22. style:UIBarButtonItemStylePlain
  23. target:self
  24. action:@selector(onCloseClick:)];
  25. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  26. // closeButton.title = @"Close";
  27. // closeButton.tintColor = UIColorFromRGB(0x996633);
  28. self.navigationItem.leftBarButtonItem = closeButton;
  29. UIBarButtonItem *previewbtn = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
  30. previewbtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"preview"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  31. style:UIBarButtonItemStylePlain
  32. target:self
  33. action:@selector(onPreviewClick:)];
  34. // previewbtn.tintColor = UIColorFromRGB(0x996633);
  35. UIBarButtonItem *savebtn = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
  36. savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  37. style:UIBarButtonItemStylePlain
  38. target:self
  39. action:@selector(onSaveClick:)];
  40. // savebtn.tintColor = UIColorFromRGB(0x996633);
  41. _savebtn = savebtn;
  42. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  43. fixedItem.width = 0.0f;
  44. NSMutableArray * items = [[NSMutableArray alloc]init];
  45. [items addObject:previewbtn];
  46. [items addObject:fixedItem];
  47. [items addObject:savebtn];
  48. // [items addObject:item2];
  49. self.navigationItem.rightBarButtonItems=items;
  50. // self.navigationItem.rightBarButtonItem = previewbtn;
  51. }
  52. - (void)didReceiveMemoryWarning {
  53. [super didReceiveMemoryWarning];
  54. // Dispose of any resources that can be recreated.
  55. }
  56. - (void)onCloseClick:(UIButton *)sender {
  57. [self.navigationController dismissViewControllerAnimated:true completion:^{
  58. ;
  59. }];
  60. }
  61. - (void)onPreviewClick:(UIButton *)sender {
  62. // add params check here.
  63. [self.lastedit endEditing:true];
  64. [self.lasttextview endEditing:true];
  65. // self.cancommit=true;
  66. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  67. // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  68. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  69. // for(int i=0;i<section_count;i++)
  70. // {
  71. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  72. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  73. // for(int j=0;j<item_count;j++)
  74. // {
  75. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  76. // NSString* key = [itemjson valueForKey:@"name"];
  77. // if(key==nil || key.length==0)
  78. // continue;
  79. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  80. // {
  81. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  82. // if([single_select isEqualToString:@"true"])
  83. // {
  84. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  85. // int count = [[cadejson valueForKey:@"count"] intValue];
  86. // bool setvalue = false;
  87. // for(int cc=0;cc<count;cc++)
  88. // {
  89. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  90. // if([[valjson valueForKey:@"check"]intValue]==1)
  91. // {
  92. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  93. // setvalue=true;
  94. // break;
  95. // }
  96. // }
  97. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  98. // {
  99. // self.cancommit = false;
  100. // }
  101. // }
  102. // else
  103. // {
  104. // //not support multi select for now;
  105. // }
  106. // /*
  107. // upparams setValue:itemjson forKey:<#(NSString *)#>
  108. //
  109. // */
  110. // }else
  111. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  112. // {
  113. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  114. // self.cancommit = false;
  115. // }
  116. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  117. // {
  118. // NSString* valuestr = [itemjson valueForKey:@"value"];
  119. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  120. //
  121. // NSString* value = [itemjson valueForKey:@"value"];
  122. // NSMutableDictionary* boolitem=nil;
  123. // NSMutableDictionary* subjson=nil;
  124. // if([value isEqualToString:@"true"])
  125. // {
  126. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  127. //
  128. // }
  129. // else
  130. // {
  131. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  132. //
  133. // }
  134. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  135. // if( subjson!=nil /*&& !active*/)
  136. // {
  137. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  138. // for(int l=0;l<sub_count;l++)
  139. // {
  140. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  141. //
  142. //
  143. //
  144. //
  145. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  146. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  147. // else
  148. // {
  149. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  150. // self.cancommit = false;
  151. // }
  152. // }
  153. //
  154. //
  155. //
  156. // }
  157. // }
  158. // else
  159. // {
  160. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  161. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  162. // else
  163. // {
  164. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  165. // self.cancommit = false;
  166. // }
  167. // }
  168. // upparams= [self subitem_param:itemjson addto:upparams ];
  169. // }
  170. // }
  171. // if(self.cancommit==false)
  172. // {
  173. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Some requried field is missing" message:@"Fields with * mark cannot be empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  174. //// //UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  175. //// [alert show];
  176. //
  177. //
  178. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  179. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  180. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  181. // //[self.editorTable reloadData ];
  182. // [self.editorTable reloadData];
  183. // return;
  184. // }
  185. NSMutableDictionary* upparams = [self check_cancommit:true];
  186. if(self.cancommit==false)
  187. return;
  188. NSMutableString* pdf_url = [[self.content_data_download valueForKey:@"pdf_url"] mutableCopy];
  189. // DebugLog([RAUtils dict2string:self.content_data_download]);
  190. bool bremove=false;
  191. NSString* catelog_name= nil;
  192. NSString* internal_note= nil;
  193. NSArray *keys= [upparams allKeys];
  194. //遍历keys
  195. for(int i=0;i<[keys count];i++)
  196. {
  197. //得到当前key
  198. NSString *key=[keys objectAtIndex:i];
  199. if([key isEqualToString:@"remove_item"])
  200. {
  201. bremove=[[upparams valueForKey:key]boolValue];
  202. continue;
  203. }
  204. if([key isEqualToString:@"catalog_name"])
  205. {
  206. catelog_name=[upparams valueForKey:key];
  207. }
  208. if([key isEqualToString:@"internal_note"])
  209. {
  210. internal_note=[upparams valueForKey:key];
  211. }
  212. [pdf_url appendString:@"&"];
  213. [pdf_url appendString:key];
  214. //如果key不是pic,说明value是字符类型,比如name:Boris
  215. NSString* valuefrom = [upparams valueForKey:key];
  216. valuefrom = [NSString stringWithFormat:@"%@",valuefrom];
  217. [pdf_url appendString:@"="];
  218. // [pdf_url appendString:[valuefrom stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  219. // [pdf_url appendString:[valuefrom stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"`#%^{}\"[]|\\<> "]]];
  220. [pdf_url appendString:[valuefrom stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
  221. // NSString* value=[self getValue:valuefrom];
  222. // [ret setValue:value forKey:valuefrom];
  223. }
  224. upparams[@"pdfUrl"]=pdf_url;
  225. upparams[@"product_ids"]=self.product_ids;
  226. upparams[@"item_ids"]=self.item_ids;
  227. // pdf_url=[pdf_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  228. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
  229. [RANetwork request_portfoliopreview:upparams completionHandler:^(NSMutableDictionary *result) {
  230. NSDictionary* editor_json = result;
  231. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  232. [waitalert dismissViewControllerAnimated:YES completion:^{
  233. if([[editor_json valueForKey:@"result"] intValue]==2)
  234. {
  235. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  236. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  237. NSString* url = [editor_json valueForKey:@"pdf_path"];
  238. NSString* path = [editor_json valueForKey:@"pdf_real_path"];
  239. bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
  240. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  241. ViewController.url = url;
  242. ViewController.canSave = true;
  243. ViewController.isLocalfile=isLocalFile;
  244. // ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
  245. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
  246. ViewController.save_name =catelog_name;
  247. ViewController.save_note =internal_note;
  248. //ViewController.filename = catelog_name;
  249. NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
  250. if(company==nil)
  251. company=@"";
  252. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  253. // NSMutableArray* send_to = [[NSMutableArray alloc]init];
  254. // if(customer_email.length>0)
  255. // [send_to addObject:customer_email];
  256. // ViewController.mail_to = send_to;
  257. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  258. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  259. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  260. if(customer_email.length>0)
  261. {
  262. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  263. // customer_email compo
  264. // [send_to addObject:customer_email];
  265. }
  266. ViewController.mail_to = send_to;
  267. NSString* subject;
  268. // if (company.length==0) {
  269. // NSString* cur_time =[RAUtils current_date];
  270. subject =catelog_name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  271. // }
  272. // else
  273. // {
  274. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  275. // }
  276. // ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",catelog_name];//[NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  277. ViewController.mail_subject = subject;
  278. // ViewController.onLoadSuccess =^(NSString* url)
  279. // {
  280. //
  281. // };
  282. ViewController.onSavePDF=^(NSString* name,NSString* file)
  283. {
  284. NSString* del_ids = nil;
  285. if(bremove)
  286. del_ids=[self.params valueForKey:@"item_ids"];
  287. #ifdef OFFLINE_MODE
  288. if (appDelegate.offline_mode)
  289. {
  290. [upparams setValue:url forKey:@"pdfPath"];
  291. }
  292. else
  293. #endif
  294. {
  295. [upparams setValue:path forKey:@"pdfPath"];
  296. }
  297. [upparams setValue:name forKey:@"pdfName"];
  298. [upparams setValue:internal_note forKey:@"pdfNote"];
  299. [upparams setValue:del_ids forKey:@"itemIds"];
  300. [upparams setValue:pdf_url forKey:@"configureParams"];
  301. __block UIAlertController * waitalert_save = [RAUtils waiting_alert:self title:@"Saving..." completion:^{
  302. [RANetwork request_save_portfolio:upparams completionHandler:^(NSMutableDictionary *result) {
  303. NSDictionary* json =result;
  304. [waitalert_save dismissViewControllerAnimated:YES completion:^{
  305. if([[json valueForKey:@"result"] intValue]==2)
  306. {
  307. [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
  308. // [RAUtils alert_view:nil title: ] ;
  309. [self.navigationController dismissViewControllerAnimated:true completion:^{
  310. #ifdef RA_NOTIFICATION
  311. [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  312. #else
  313. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  314. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  315. #endif
  316. // if(self.onDismiss)
  317. // self.onDismiss(catelog_name);
  318. }];
  319. }
  320. else
  321. {
  322. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
  323. }
  324. }];
  325. }];
  326. }];
  327. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  328. //
  329. //
  330. //#ifdef OFFLINE_MODE
  331. // if (appDelegate.offline_mode)
  332. // {
  333. // [upparams setValue:url forKey:@"pdfPath"];
  334. // }
  335. // else
  336. //#endif
  337. // {
  338. // [upparams setValue:path forKey:@"pdfPath"];
  339. // }
  340. // [upparams setValue:name forKey:@"pdfName"];
  341. // [upparams setValue:internal_note forKey:@"pdfNote"];
  342. // [upparams setValue:del_ids forKey:@"itemIds"];
  343. // [upparams setValue:pdf_url forKey:@"configureParams"];
  344. //
  345. //
  346. //
  347. // NSDictionary* json = [RANetwork save_TearSheet:upparams];
  348. //
  349. // dispatch_async(dispatch_get_main_queue(), ^{
  350. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  351. //
  352. //
  353. // if([[json valueForKey:@"result"] intValue]==2)
  354. // {
  355. // [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
  356. //// [RAUtils alert_view:nil title: ] ;
  357. //
  358. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  359. //
  360. //
  361. //
  362. //#ifdef RA_NOTIFICATION
  363. // [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  364. //#else
  365. // [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  366. // [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  367. //#endif
  368. // // if(self.onDismiss)
  369. // // self.onDismiss(catelog_name);
  370. // }];
  371. // }
  372. // else
  373. // {
  374. // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
  375. // }
  376. //
  377. // });
  378. // });
  379. };
  380. // ViewController. = self.function_name;
  381. // ViewController.behavior =BEHAVIOR_SEARCH;
  382. ViewController.hidenavi = false;
  383. [self.navigationController pushViewController:ViewController animated:YES];
  384. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  385. /*
  386. if(self.return_url)
  387. self.return_url(url,path,bremove);
  388. [self.navigationController dismissViewControllerAnimated:true completion:^{
  389. if(self.onDismiss)
  390. self.onDismiss(catelog_name);
  391. }];
  392. */
  393. }
  394. else
  395. {
  396. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
  397. }
  398. }];
  399. }];
  400. }];
  401. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  402. //
  403. // NSDictionary* editor_json = [RANetwork request_TearSheet:upparams];
  404. //
  405. // dispatch_async(dispatch_get_main_queue(), ^{
  406. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  407. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  408. //
  409. //
  410. //
  411. // if([[editor_json valueForKey:@"result"] intValue]==2)
  412. // {
  413. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  414. //
  415. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  416. //
  417. // NSString* url = [editor_json valueForKey:@"pdf_path"];
  418. // NSString* path = [editor_json valueForKey:@"pdf_real_path"];
  419. // bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
  420. // RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  421. // ViewController.url = url;
  422. // ViewController.canSave = true;
  423. // ViewController.isLocalfile=isLocalFile;
  424. // // ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
  425. // ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
  426. // ViewController.save_name =catelog_name;
  427. // ViewController.save_note =internal_note;
  428. // //ViewController.filename = catelog_name;
  429. // NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
  430. //
  431. // if(company==nil)
  432. // company=@"";
  433. // // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  434. //
  435. //
  436. // // NSMutableArray* send_to = [[NSMutableArray alloc]init];
  437. // // if(customer_email.length>0)
  438. // // [send_to addObject:customer_email];
  439. // // ViewController.mail_to = send_to;
  440. //
  441. //
  442. //
  443. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  444. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  445. //
  446. //
  447. // NSMutableArray* send_to = [[NSMutableArray alloc]init];
  448. // if(customer_email.length>0)
  449. // {
  450. // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  451. // // customer_email compo
  452. // // [send_to addObject:customer_email];
  453. // }
  454. // ViewController.mail_to = send_to;
  455. //
  456. // NSString* subject;
  457. // // if (company.length==0) {
  458. //
  459. // // NSString* cur_time =[RAUtils current_date];
  460. // subject =catelog_name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  461. //
  462. //
  463. //
  464. // // }
  465. // // else
  466. // // {
  467. // // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  468. // // }
  469. //// ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",catelog_name];//[NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  470. // ViewController.mail_subject = subject;
  471. //
  472. // // ViewController.onLoadSuccess =^(NSString* url)
  473. // // {
  474. // //
  475. // // };
  476. //
  477. //
  478. // ViewController.onSavePDF=^(NSString* name,NSString* file)
  479. // {
  480. //
  481. //
  482. // NSString* del_ids = nil;
  483. // if(bremove)
  484. // del_ids=[self.params valueForKey:@"item_ids"];
  485. //
  486. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving..."];
  487. //
  488. //
  489. // #ifdef OFFLINE_MODE
  490. // if (appDelegate.offline_mode)
  491. // {
  492. // [upparams setValue:url forKey:@"pdfPath"];
  493. // }
  494. // else
  495. // #endif
  496. // {
  497. // [upparams setValue:path forKey:@"pdfPath"];
  498. // }
  499. // [upparams setValue:name forKey:@"pdfName"];
  500. // [upparams setValue:internal_note forKey:@"pdfNote"];
  501. // [upparams setValue:del_ids forKey:@"itemIds"];
  502. // [upparams setValue:pdf_url forKey:@"configureParams"];
  503. //
  504. // [RANetwork request_save_portfolio:upparams completionHandler:^(NSMutableDictionary *result) {
  505. //
  506. // NSDictionary* json =result;
  507. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  508. //
  509. //
  510. // if([[json valueForKey:@"result"] intValue]==2)
  511. // {
  512. // [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
  513. // // [RAUtils alert_view:nil title: ] ;
  514. //
  515. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  516. //
  517. //
  518. //
  519. //#ifdef RA_NOTIFICATION
  520. // [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  521. //#else
  522. // [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  523. // [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  524. //#endif
  525. // // if(self.onDismiss)
  526. // // self.onDismiss(catelog_name);
  527. // }];
  528. // }
  529. // else
  530. // {
  531. // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
  532. // }
  533. //
  534. // }];
  535. //
  536. //
  537. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  538. ////
  539. ////
  540. ////#ifdef OFFLINE_MODE
  541. //// if (appDelegate.offline_mode)
  542. //// {
  543. //// [upparams setValue:url forKey:@"pdfPath"];
  544. //// }
  545. //// else
  546. ////#endif
  547. //// {
  548. //// [upparams setValue:path forKey:@"pdfPath"];
  549. //// }
  550. //// [upparams setValue:name forKey:@"pdfName"];
  551. //// [upparams setValue:internal_note forKey:@"pdfNote"];
  552. //// [upparams setValue:del_ids forKey:@"itemIds"];
  553. //// [upparams setValue:pdf_url forKey:@"configureParams"];
  554. ////
  555. ////
  556. ////
  557. //// NSDictionary* json = [RANetwork save_TearSheet:upparams];
  558. ////
  559. //// dispatch_async(dispatch_get_main_queue(), ^{
  560. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  561. ////
  562. ////
  563. //// if([[json valueForKey:@"result"] intValue]==2)
  564. //// {
  565. //// [RAUtils message_alert:@"Portfolio saved. You can find it from View Portfolios" title:@"Portfolio" controller:self];
  566. ////// [RAUtils alert_view:nil title: ] ;
  567. ////
  568. //// [self.navigationController dismissViewControllerAnimated:true completion:^{
  569. ////
  570. ////
  571. ////
  572. ////#ifdef RA_NOTIFICATION
  573. //// [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  574. ////#else
  575. //// [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  576. //// [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  577. ////#endif
  578. //// // if(self.onDismiss)
  579. //// // self.onDismiss(catelog_name);
  580. //// }];
  581. //// }
  582. //// else
  583. //// {
  584. //// [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
  585. //// }
  586. ////
  587. //// });
  588. //// });
  589. //
  590. //
  591. //
  592. // };
  593. //
  594. // // ViewController. = self.function_name;
  595. // // ViewController.behavior =BEHAVIOR_SEARCH;
  596. // ViewController.hidenavi = false;
  597. // [self.navigationController pushViewController:ViewController animated:YES];
  598. // // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  599. //
  600. //
  601. // /*
  602. // if(self.return_url)
  603. // self.return_url(url,path,bremove);
  604. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  605. // if(self.onDismiss)
  606. // self.onDismiss(catelog_name);
  607. // }];
  608. // */
  609. //
  610. // }
  611. // else
  612. // {
  613. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
  614. // }
  615. //
  616. //
  617. //
  618. //
  619. // });
  620. // });
  621. }
  622. - (void)onSaveClick:(UIButton *)sender {
  623. // add params check here.
  624. [self.lastedit endEditing:true];
  625. [self.lasttextview endEditing:true];
  626. // self.cancommit=true;
  627. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  628. // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  629. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  630. // for(int i=0;i<section_count;i++)
  631. // {
  632. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  633. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  634. // for(int j=0;j<item_count;j++)
  635. // {
  636. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  637. // NSString* key = [itemjson valueForKey:@"name"];
  638. // if(key==nil || key.length==0)
  639. // continue;
  640. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  641. // {
  642. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  643. // if([single_select isEqualToString:@"true"])
  644. // {
  645. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  646. // int count = [[cadejson valueForKey:@"count"] intValue];
  647. // bool setvalue = false;
  648. // for(int cc=0;cc<count;cc++)
  649. // {
  650. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  651. // if([[valjson valueForKey:@"check"]intValue]==1)
  652. // {
  653. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  654. // setvalue=true;
  655. // break;
  656. // }
  657. // }
  658. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  659. // {
  660. // self.cancommit = false;
  661. // }
  662. // }
  663. // else
  664. // {
  665. // //not support multi select for now;
  666. // }
  667. // /*
  668. // upparams setValue:itemjson forKey:<#(NSString *)#>
  669. //
  670. // */
  671. // }else
  672. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  673. // {
  674. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  675. // self.cancommit = false;
  676. // }
  677. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  678. // {
  679. // NSString* valuestr = [itemjson valueForKey:@"value"];
  680. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  681. //
  682. // NSString* value = [itemjson valueForKey:@"value"];
  683. // NSMutableDictionary* boolitem=nil;
  684. // NSMutableDictionary* subjson=nil;
  685. // if([value isEqualToString:@"true"])
  686. // {
  687. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  688. //
  689. // }
  690. // else
  691. // {
  692. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  693. //
  694. // }
  695. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  696. // if( subjson!=nil /*&& !active*/)
  697. // {
  698. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  699. // for(int l=0;l<sub_count;l++)
  700. // {
  701. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  702. //
  703. //
  704. //
  705. //
  706. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  707. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  708. // else
  709. // {
  710. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  711. // self.cancommit = false;
  712. // }
  713. // }
  714. //
  715. //
  716. //
  717. // }
  718. // }
  719. // else
  720. // {
  721. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  722. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  723. // else
  724. // {
  725. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  726. // self.cancommit = false;
  727. // }
  728. // }
  729. // upparams= [self subitem_param:itemjson addto:upparams ];
  730. // }
  731. // }
  732. // if(self.cancommit==false)
  733. // {
  734. //// 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];
  735. //// //UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  736. //// [alert show];
  737. //
  738. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  739. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  740. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  741. // //[self.editorTable reloadData ];
  742. // [self.editorTable reloadData];
  743. // return;
  744. // }
  745. NSMutableDictionary* upparams = [self check_cancommit:true];
  746. if(self.cancommit==false)
  747. return;
  748. NSMutableString* pdf_url = [[self.content_data_download valueForKey:@"pdf_url"] mutableCopy];
  749. // DebugLog([RAUtils dict2string:self.content_data_download]);
  750. bool bremove=false;
  751. NSString* catelog_name= nil;
  752. NSString* internal_note = nil;
  753. NSArray *keys= [upparams allKeys];
  754. //遍历keys
  755. for(int i=0;i<[keys count];i++)
  756. {
  757. //得到当前key
  758. NSString *key=[keys objectAtIndex:i];
  759. if([key isEqualToString:@"remove_item"])
  760. {
  761. bremove=[[upparams valueForKey:key]boolValue];
  762. continue;
  763. }
  764. if([key isEqualToString:@"catalog_name"])
  765. {
  766. catelog_name=[upparams valueForKey:key];
  767. }
  768. if([key isEqualToString:@"internal_note"])
  769. {
  770. internal_note=[upparams valueForKey:key];
  771. }
  772. [pdf_url appendString:@"&"];
  773. [pdf_url appendString:key];
  774. //如果key不是pic,说明value是字符类型,比如name:Boris
  775. NSString* valuefrom = [upparams valueForKey:key];
  776. valuefrom = [NSString stringWithFormat:@"%@",valuefrom];
  777. [pdf_url appendString:@"="];
  778. // [pdf_url appendString:[valuefrom stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  779. //
  780. [pdf_url appendString:[valuefrom stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
  781. // NSString* value=[self getValue:valuefrom];
  782. // [ret setValue:value forKey:valuefrom];
  783. }
  784. upparams[@"product_ids"]=self.product_ids;
  785. upparams[@"item_ids"]=self.item_ids;
  786. __block NSString* saveName = catelog_name;
  787. __block NSString* saveNote = internal_note;
  788. NSString* del_ids = nil;
  789. if(bremove)
  790. del_ids=[self.params valueForKey:@"item_ids"];
  791. // pdf_url=[pdf_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  792. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Save pdf" message:nil preferredStyle:UIAlertControllerStyleAlert];
  793. //block代码块取代了delegate
  794. [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  795. textField.text = saveName;
  796. }];
  797. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  798. UITextField *name = alertControl.textFields.firstObject;
  799. if(name.text.length==0)
  800. {
  801. [RAUtils message_alert:@"Cannot save without name. Save canceled." title:@"Name is missing" controller:self];
  802. }
  803. else
  804. {
  805. saveName = name.text;
  806. self.savebtn.enabled =false;
  807. [upparams setValue:pdf_url forKey:@"pdfUrl"];
  808. [upparams setValue:saveName forKey:@"pdfName"];
  809. [upparams setValue:del_ids forKey:@"itemIds"];
  810. [upparams setValue:saveNote forKey:@"pdfNote"];
  811. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
  812. [RANetwork request_save_portfoliodirectly:upparams completionHandler:^(NSMutableDictionary *result) {
  813. NSDictionary* editor_json =result;
  814. [waitalert dismissViewControllerAnimated:YES completion:^{
  815. if([[editor_json valueForKey:@"result"] intValue]==2)
  816. {
  817. // [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
  818. NSString* url = [editor_json valueForKey:@"pdf_path"];
  819. bool isLocalFile = [editor_json valueForKey:@"isLocalFile"];
  820. [self.navigationController dismissViewControllerAnimated:true completion:^{
  821. #ifdef RA_NOTIFICATION
  822. [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  823. #else
  824. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  825. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  826. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  827. #endif
  828. if(self.onSaved)
  829. self.onSaved(url,saveName,isLocalFile);
  830. }];
  831. }
  832. else
  833. {
  834. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
  835. }
  836. }];
  837. }];
  838. }];
  839. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  840. //
  841. //
  842. // [upparams setValue:pdf_url forKey:@"pdfUrl"];
  843. // [upparams setValue:saveName forKey:@"pdfName"];
  844. // [upparams setValue:del_ids forKey:@"itemIds"];
  845. // [upparams setValue:saveNote forKey:@"pdfNote"];
  846. //
  847. // NSDictionary* editor_json = [RANetwork direct_save_TearSheet:upparams];
  848. //
  849. // dispatch_async(dispatch_get_main_queue(), ^{
  850. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  851. //
  852. //
  853. // if([[editor_json valueForKey:@"result"] intValue]==2)
  854. // {
  855. //
  856. //
  857. //
  858. //
  859. // // [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
  860. // NSString* url = [editor_json valueForKey:@"pdf_path"];
  861. // bool isLocalFile = [editor_json valueForKey:@"isLocalFile"];
  862. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  863. //
  864. //
  865. //
  866. //#ifdef RA_NOTIFICATION
  867. // [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  868. //#else
  869. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  870. // [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  871. // [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  872. //
  873. //#endif
  874. //
  875. // if(self.onSaved)
  876. // self.onSaved(url,saveName,isLocalFile);
  877. // }];
  878. //
  879. // }
  880. // else
  881. // {
  882. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
  883. // }
  884. //
  885. //
  886. //
  887. //
  888. // });
  889. // });
  890. }
  891. }];
  892. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  893. DebugLog(@"Cancel");
  894. }];
  895. [alertControl addAction:actionOne];
  896. [alertControl addAction:alertthree];
  897. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  898. [self presentViewController:alertControl animated:YES completion:nil];
  899. }
  900. /*
  901. #pragma mark - Navigation
  902. // In a storyboard-based application, you will often want to do a little preparation before navigation
  903. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  904. // Get the new view controller using [segue destinationViewController].
  905. // Pass the selected object to the new view controller.
  906. }
  907. */
  908. #pragma mark - Urgency
  909. - (void)viewWillAppear:(BOOL)animated {
  910. [super viewWillAppear:animated];
  911. [self start_urgency_timer];
  912. }
  913. -(void) viewWillDisappear:(BOOL)animated
  914. {
  915. [super viewWillDisappear:animated];
  916. [self cancel_urgency_timer];
  917. }
  918. - (void)dealloc {
  919. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  920. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  921. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  922. }
  923. - (void)start_urgency_timer {
  924. if (!self.editable) {
  925. return;
  926. }
  927. __weak typeof(self) weakSelf = self;
  928. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  929. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  930. #ifdef OFFLINE_MODE
  931. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  932. #endif
  933. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  934. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  935. // DebugLog(@"timer start....");
  936. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  937. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  938. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  939. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  940. }];
  941. }
  942. - (void)cancel_urgency_timer {
  943. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  944. }
  945. @end