TearSheetParamViewController.m 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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 "Singleton.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. // NSString* value=[self getValue:valuefrom];
  220. // [ret setValue:value forKey:valuefrom];
  221. }
  222. upparams[@"pdfUrl"]=pdf_url;
  223. upparams[@"product_ids"]=self.product_ids;
  224. upparams[@"item_ids"]=self.item_ids;
  225. // pdf_url=[pdf_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  226. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Processing"];
  227. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  228. NSDictionary* editor_json = [RANetwork request_TearSheet:upparams];
  229. dispatch_async(dispatch_get_main_queue(), ^{
  230. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  231. if([[editor_json valueForKey:@"result"] intValue]==2)
  232. {
  233. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  234. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  235. NSString* url = [editor_json valueForKey:@"pdf_path"];
  236. NSString* path = [editor_json valueForKey:@"pdf_real_path"];
  237. bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
  238. RAPDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  239. ViewController.url = url;
  240. ViewController.canSave = true;
  241. ViewController.isLocalfile=isLocalFile;
  242. // ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
  243. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
  244. ViewController.save_name =catelog_name;
  245. ViewController.save_note =internal_note;
  246. //ViewController.filename = catelog_name;
  247. NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
  248. if(company==nil)
  249. company=@"";
  250. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  251. // NSMutableArray* send_to = [[NSMutableArray alloc]init];
  252. // if(customer_email.length>0)
  253. // [send_to addObject:customer_email];
  254. // ViewController.mail_to = send_to;
  255. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  256. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  257. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  258. if(customer_email.length>0)
  259. {
  260. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  261. // customer_email compo
  262. // [send_to addObject:customer_email];
  263. }
  264. ViewController.mail_to = send_to;
  265. NSString* subject;
  266. // if (company.length==0) {
  267. // NSString* cur_time =[RAUtils current_date];
  268. subject =catelog_name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  269. // }
  270. // else
  271. // {
  272. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  273. // }
  274. // ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",catelog_name];//[NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  275. ViewController.mail_subject = subject;
  276. // ViewController.onLoadSuccess =^(NSString* url)
  277. // {
  278. //
  279. // };
  280. ViewController.onSavePDF=^(NSString* name,NSString* file)
  281. {
  282. NSString* del_ids = nil;
  283. if(bremove)
  284. del_ids=[self.params valueForKey:@"item_ids"];
  285. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Saving..."];
  286. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  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. NSDictionary* json = [RANetwork save_TearSheet:upparams];
  302. dispatch_async(dispatch_get_main_queue(), ^{
  303. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  304. if([[json valueForKey:@"result"] intValue]==2)
  305. {
  306. [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
  307. [self.navigationController dismissViewControllerAnimated:true completion:^{
  308. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  309. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  310. // if(self.onDismiss)
  311. // self.onDismiss(catelog_name);
  312. }];
  313. }
  314. else
  315. {
  316. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save Portfolio" controller:self] ;
  317. }
  318. });
  319. });
  320. };
  321. // ViewController. = self.function_name;
  322. // ViewController.behavior =BEHAVIOR_SEARCH;
  323. ViewController.hidenavi = false;
  324. [self.navigationController pushViewController:ViewController animated:YES];
  325. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  326. /*
  327. if(self.return_url)
  328. self.return_url(url,path,bremove);
  329. [self.navigationController dismissViewControllerAnimated:true completion:^{
  330. if(self.onDismiss)
  331. self.onDismiss(catelog_name);
  332. }];
  333. */
  334. }
  335. else
  336. {
  337. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
  338. }
  339. });
  340. });
  341. }
  342. - (void)onSaveClick:(UIButton *)sender {
  343. // add params check here.
  344. [self.lastedit endEditing:true];
  345. [self.lasttextview endEditing:true];
  346. // self.cancommit=true;
  347. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  348. // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  349. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  350. // for(int i=0;i<section_count;i++)
  351. // {
  352. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  353. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  354. // for(int j=0;j<item_count;j++)
  355. // {
  356. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  357. // NSString* key = [itemjson valueForKey:@"name"];
  358. // if(key==nil || key.length==0)
  359. // continue;
  360. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  361. // {
  362. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  363. // if([single_select isEqualToString:@"true"])
  364. // {
  365. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  366. // int count = [[cadejson valueForKey:@"count"] intValue];
  367. // bool setvalue = false;
  368. // for(int cc=0;cc<count;cc++)
  369. // {
  370. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  371. // if([[valjson valueForKey:@"check"]intValue]==1)
  372. // {
  373. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  374. // setvalue=true;
  375. // break;
  376. // }
  377. // }
  378. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  379. // {
  380. // self.cancommit = false;
  381. // }
  382. // }
  383. // else
  384. // {
  385. // //not support multi select for now;
  386. // }
  387. // /*
  388. // upparams setValue:itemjson forKey:<#(NSString *)#>
  389. //
  390. // */
  391. // }else
  392. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  393. // {
  394. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  395. // self.cancommit = false;
  396. // }
  397. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  398. // {
  399. // NSString* valuestr = [itemjson valueForKey:@"value"];
  400. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  401. //
  402. // NSString* value = [itemjson valueForKey:@"value"];
  403. // NSMutableDictionary* boolitem=nil;
  404. // NSMutableDictionary* subjson=nil;
  405. // if([value isEqualToString:@"true"])
  406. // {
  407. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  408. //
  409. // }
  410. // else
  411. // {
  412. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  413. //
  414. // }
  415. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  416. // if( subjson!=nil /*&& !active*/)
  417. // {
  418. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  419. // for(int l=0;l<sub_count;l++)
  420. // {
  421. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  422. //
  423. //
  424. //
  425. //
  426. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  427. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  428. // else
  429. // {
  430. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  431. // self.cancommit = false;
  432. // }
  433. // }
  434. //
  435. //
  436. //
  437. // }
  438. // }
  439. // else
  440. // {
  441. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  442. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  443. // else
  444. // {
  445. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  446. // self.cancommit = false;
  447. // }
  448. // }
  449. // upparams= [self subitem_param:itemjson addto:upparams ];
  450. // }
  451. // }
  452. // if(self.cancommit==false)
  453. // {
  454. //// 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];
  455. //// //UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  456. //// [alert show];
  457. //
  458. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  459. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  460. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  461. // //[self.editorTable reloadData ];
  462. // [self.editorTable reloadData];
  463. // return;
  464. // }
  465. NSMutableDictionary* upparams = [self check_cancommit:true];
  466. if(self.cancommit==false)
  467. return;
  468. NSMutableString* pdf_url = [[self.content_data_download valueForKey:@"pdf_url"] mutableCopy];
  469. // DebugLog([RAUtils dict2string:self.content_data_download]);
  470. bool bremove=false;
  471. NSString* catelog_name= nil;
  472. NSString* internal_note = nil;
  473. NSArray *keys= [upparams allKeys];
  474. //遍历keys
  475. for(int i=0;i<[keys count];i++)
  476. {
  477. //得到当前key
  478. NSString *key=[keys objectAtIndex:i];
  479. if([key isEqualToString:@"remove_item"])
  480. {
  481. bremove=[[upparams valueForKey:key]boolValue];
  482. continue;
  483. }
  484. if([key isEqualToString:@"catalog_name"])
  485. {
  486. catelog_name=[upparams valueForKey:key];
  487. }
  488. if([key isEqualToString:@"internal_note"])
  489. {
  490. internal_note=[upparams valueForKey:key];
  491. }
  492. [pdf_url appendString:@"&"];
  493. [pdf_url appendString:key];
  494. //如果key不是pic,说明value是字符类型,比如name:Boris
  495. NSString* valuefrom = [upparams valueForKey:key];
  496. valuefrom = [NSString stringWithFormat:@"%@",valuefrom];
  497. [pdf_url appendString:@"="];
  498. [pdf_url appendString:[valuefrom stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  499. // NSString* value=[self getValue:valuefrom];
  500. // [ret setValue:value forKey:valuefrom];
  501. }
  502. upparams[@"product_ids"]=self.product_ids;
  503. upparams[@"item_ids"]=self.item_ids;
  504. __block NSString* saveName = catelog_name;
  505. __block NSString* saveNote = internal_note;
  506. NSString* del_ids = nil;
  507. if(bremove)
  508. del_ids=[self.params valueForKey:@"item_ids"];
  509. // pdf_url=[pdf_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  510. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Save pdf" message:nil preferredStyle:UIAlertControllerStyleAlert];
  511. //block代码块取代了delegate
  512. [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  513. textField.text = saveName;
  514. }];
  515. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  516. UITextField *name = alertControl.textFields.firstObject;
  517. if(name.text.length==0)
  518. {
  519. [RAUtils message_alert:@"Cannot save without name. Save canceled." title:@"Name is missing" controller:self];
  520. }
  521. else
  522. {
  523. saveName = name.text;
  524. _savebtn.enabled =false;
  525. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Processing"];
  526. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  527. [upparams setValue:pdf_url forKey:@"pdfUrl"];
  528. [upparams setValue:saveName forKey:@"pdfName"];
  529. [upparams setValue:del_ids forKey:@"itemIds"];
  530. [upparams setValue:saveNote forKey:@"pdfNote"];
  531. NSDictionary* editor_json = [RANetwork direct_save_TearSheet:upparams];
  532. dispatch_async(dispatch_get_main_queue(), ^{
  533. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  534. if([[editor_json valueForKey:@"result"] intValue]==2)
  535. {
  536. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  537. // [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
  538. NSString* url = [editor_json valueForKey:@"pdf_path"];
  539. bool isLocalFile = [editor_json valueForKey:@"isLocalFile"];
  540. [self.navigationController dismissViewControllerAnimated:true completion:^{
  541. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  542. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  543. if(self.onSaved)
  544. self.onSaved(url,saveName,isLocalFile);
  545. }];
  546. }
  547. else
  548. {
  549. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Portfolio" controller:self] ;
  550. }
  551. });
  552. });
  553. }
  554. }];
  555. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  556. DebugLog(@"Cancel");
  557. }];
  558. [alertControl addAction:actionOne];
  559. [alertControl addAction:alertthree];
  560. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  561. [self presentViewController:alertControl animated:YES completion:nil];
  562. }
  563. /*
  564. #pragma mark - Navigation
  565. // In a storyboard-based application, you will often want to do a little preparation before navigation
  566. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  567. // Get the new view controller using [segue destinationViewController].
  568. // Pass the selected object to the new view controller.
  569. }
  570. */
  571. #pragma mark - Urgency
  572. - (void)viewWillAppear:(BOOL)animated {
  573. [super viewWillAppear:animated];
  574. [self start_urgency_timer];
  575. }
  576. -(void) viewWillDisappear:(BOOL)animated
  577. {
  578. [super viewWillDisappear:animated];
  579. [self cancel_urgency_timer];
  580. }
  581. - (void)dealloc {
  582. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  583. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  584. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  585. }
  586. - (void)start_urgency_timer {
  587. if (!self.editable) {
  588. return;
  589. }
  590. __weak typeof(self) weakSelf = self;
  591. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  592. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  593. #ifdef OFFLINE_MODE
  594. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  595. #endif
  596. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  597. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  598. // DebugLog(@"timer start....");
  599. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  600. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  601. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  602. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  603. }];
  604. }
  605. - (void)cancel_urgency_timer {
  606. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  607. }
  608. @end