// // CommonEditorViewController.m // RedAnt ERP Mobile // // Created by Ray on 14-7-16. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "CommonEditorViewController.h" #import "CommonEditorCellEdit.h" #import "iSalesNetwork.h" #import "CommonEditorCellEnum.h" #import "CommonEditorCellSwitch.h" #import "CommonEditorCellModel.h" #import "CommonEditorCellAction.h" #import "EnumSelectViewController.h" #import "DatePickerViewController.h" #import "SignatureViewController.h" #import "CommonEditorCellSignature.h" #import "CommonEditorCellLabel.h" #import "AddressEditorViewController.h" #import "CreditCardEditorViewController.h" #import "MonthPickerViewController.h" #import "ContactListViewController.h" #import "CommonEditorCellMAction.h" #import "CommonEditorCellTextView.h" #import "RAUtils.h" #import "CommonEditorCellImg.h" #define NUMBERS @"0123456789\n" @interface CommonEditorViewController () @end @implementation CommonEditorViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } -(void) viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; // 键盘高度变化通知,ios5.0新增的 #ifdef __IPHONE_5_0 float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version >= 5.0) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; } #endif } -(void) viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] removeObserver:self]; } -(void)manually_refresh { UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200]; reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"]; if ([self respondsToSelector:@selector(reload_data)]) [self performSelector:@selector(reload_data) withObject:nil afterDelay:1]; // DebugLog(@"refresh!!!!!!!!"); } -(void)reload_data { [self.lastedit endEditing:true]; [self.lasttextview endEditing:true]; UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200]; [reF endRefreshing]; reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"]; [self refresh:nil]; } - (void)viewDidLoad { [super viewDidLoad]; UIRefreshControl *ref = [[UIRefreshControl alloc]init]; ref.tag = 200 ; ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"]; ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7]; // ref.hidden = true; [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged]; [self.editorTable addSubview:ref]; self.changed_data = [[NSMutableDictionary alloc] init]; // UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)]; // // closeButton.title = @"Close"; // // self.navigationItem.leftBarButtonItem = closeButton; if(self.url_type==URL_REMOTE) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* editor_json = [iSalesNetwork request_Editor:self.request_url params:self.params]; dispatch_async(dispatch_get_main_queue(), ^{ if([[editor_json valueForKey:@"result"] intValue]==2) { self.content_data_download = [editor_json mutableCopy]; self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data]; // self.content_data = [editor_json mutableCopy]; // self.content_data = [self translate_json:editor_json]; // NSMutableDictionary* content_data1 = [self translate_json:self.content_data]; [self download_success]; [self.editorTable reloadData]; // NSString * ttt=[self.content_data valueForKey:@"title"] ; self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ; } else { [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ; } }); }); } else if(self.url_type== URL_LOCAL ) { NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]]; NSError *error=nil; self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy]; self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data]; self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ; [self.editorTable reloadData]; // NSString * ttt=[self.content_data valueForKey:@"title"] ; // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ; } else { self.content_data_control=[self translate_json:self.content_data_download changed: self.changed_data]; [self.editorTable reloadData]; // NSString * ttt=[self.content_data valueForKey:@"title"] ; self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ; } self.requried = [[NSMutableDictionary alloc] init]; self.cancommit = true; } //-(bool) action_btn_passed_check:(NSDictionary* ) data; //{ // if(data == nil) // return false; // int section_count=[[data valueForKey:@"section_count"] intValue]; // // for(int sc=0;sc */ } else { if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""]) [upparam setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]]; else { if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] ) self.cancommit = false; } } upparam= [self subitem_param:itemjson addto:upparam ]; } } } else { if([addjson valueForKey:@"value"]!=nil && ![[addjson valueForKey:@"value"]isEqualToString:@""]) [upparam setValue:[addjson valueForKey:@"value"] forKey:key]; else { if([[addjson valueForKey:@"required"] isEqualToString: @"true"] ) self.cancommit = false; } } upparam=[self subitem_param:addjson addto:upparam]; // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]]; // item_count ++; // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"]; } //break; } } } return upparam; } -(NSMutableArray*) add_subitem:(NSDictionary*) itemjson addto:(NSMutableArray*) sectionarr parent:(NSString*) parent { NSString * control_type = [itemjson valueForKey:@"control"]; bool single_select = [[itemjson valueForKey:@"single_select"] boolValue]; if([control_type isEqual:@"enum"] && single_select) { NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy]; int cade_count = [[cadedatejson valueForKey:@"count"] intValue]; for(int k=0;k)#> // return nil; } /* -(NSMutableDictionary*) translate_json: (NSDictionary*) injson { if(injson == nil) return nil; NSMutableDictionary * retjson= [injson mutableCopy]; int section_count=[[retjson valueForKey:@"section_count"] intValue]; for(int i=0;i)#> return nil; }*/ //- (void)onCloseClick:(UIButton *)sender { // [self.navigationController dismissViewControllerAnimated:true completion:^{ // ; // }]; //} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void) prepareReturn:(NSMutableDictionary*) value { if(value==nil) value=[[NSMutableDictionary alloc]init]; value[@"is_subaction"] = self.params[@"is_subaction"]; value[@"subaction_tag"] = self.params[@"subaction_tag"]; if (self.delegate && [self.delegate respondsToSelector:@selector(returnValue:indexPath:)]) { [self.delegate returnValue:value indexPath:self.from]; } if(self.returnValue) self.returnValue(nil); } -(void) handle_action_return:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath action:(int) action_code { NSLog(@"commoneditor return %ld_%ld",(long)indexPath.section,(long)indexPath.row); NSMutableDictionary* section_json=nil; NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy]; bool is_subaction = [value[@"is_subaction"] boolValue]; int subaction_tag= [value[@"subaction_tag"] intValue]; [value removeObjectForKey:@"is_subaction"]; [value removeObjectForKey:@"subaction_tag"]; if(is_subaction) { NSMutableDictionary* sub_action = [[item_json objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy]; int refresh = [[sub_action valueForKey:@"refresh"] intValue]; NSString* refresh_trigger = [sub_action valueForKey:@"name"]; NSDictionary * restore_json=[sub_action objectForKeyedSubscript:@"restore"]; NSString* subid=[sub_action valueForKey:@"subid"]; UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath]; NSString* required = [sub_action valueForKey:@"required"]; if([required isEqualToString:@"true"] && value.count==0) { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } else { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } if(value.count!=0) { if(action_code==ACTION_SAVE_DATA) { [sub_action setObject:value forKey:@"data"]; if(subid==nil) { [sub_action setValue:@"true" forKey:@"dirty"]; section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy]; int count=0; count=[[section_json valueForKey:@"count"] intValue]; for(int i=0;i=1) { firstname =_arr[0]; if(_arr.count>1) { lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "]; } } } [ret setValue:firstname forKey:@"customer_first_name"]; [ret setValue:lastname forKey:@"customer_last_name"]; // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"]; return ret; } -(NSString* )create_customer_ext:(NSDictionary*)customerinfo { NSString* ret=nil; NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"]; NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"]; NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"]; NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"]; NSMutableArray* arraddr = [[NSMutableArray alloc] init]; if(customer_address1.length>0) [arraddr addObject:customer_address1]; if(customer_address2.length>0) [arraddr addObject:customer_address2]; if(customer_address3.length>0) [arraddr addObject:customer_address3]; if(customer_address4.length>0) [arraddr addObject:customer_address4]; NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"]; NSString* customer_city= [customerinfo valueForKey:@"customer_city"]; NSString* customer_country= [customerinfo valueForKey:@"customer_country"]; NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"]; NSString* customer_state= [customerinfo valueForKey:@"customer_state"]; NSMutableArray* arrcty = [[NSMutableArray alloc] init]; if(customer_city.length>0) [arrcty addObject:customer_city]; if(customer_state.length>0) [arrcty addObject:customer_state]; if(customer_zipcode.length>0) [arrcty addObject:customer_zipcode]; if(customer_country.length>0) [arrcty addObject:customer_country]; NSString *cty_string = [arrcty componentsJoinedByString:@", "]; NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"]; NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"]; NSMutableArray* arrpho = [[NSMutableArray alloc] init]; if(customer_phone.length>0) { customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone]; [arrpho addObject:customer_phone]; } if(customer_fax.length>0) { customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax]; [arrpho addObject:customer_fax]; } NSString *phone_string = [arrpho componentsJoinedByString:@", "]; NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"]; if(customer_contact.length>0) { customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact]; } NSString *contact_string = customer_contact; NSString* customer_email= [customerinfo valueForKey:@"customer_email"]; if(customer_email.length>0) { customer_email = [NSString stringWithFormat:@"Email: %@",customer_email]; } NSString *email_string = customer_email; NSMutableArray* arrext = [[NSMutableArray alloc] init]; if(addr_string.length>0) [arrext addObject:addr_string]; if(cty_string.length>0) [arrext addObject:cty_string]; if(phone_string.length>0) [arrext addObject:phone_string]; if(contact_string.length>0) [arrext addObject:contact_string]; if(email_string.length>0) [arrext addObject:email_string]; ret = [arrext componentsJoinedByString:@"\r\n"]; // NSString *string = [array componentsJoinedByString:@" "]; // NSString* customer_name= [customerinfo valueForKey:@"customer_name"]; return ret; } #pragma mark - hide section button clicked - (void)HideSction:(UIButton *)sender { NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]] mutableCopy]; bool hide = [[section valueForKey:@"hide"]boolValue]; if(hide) { [section setValue:@"false" forKey:@"hide"]; [sender setTitle:@"Show" forState:UIControlStateNormal]; } else{ [section setValue:@"true" forKey:@"hide"]; [sender setTitle:@"Hide" forState:UIControlStateNormal]; } [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]]; self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data]; NSRange range = NSMakeRange(sender.tag, 1); NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range]; [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic]; } #pragma mark - multi_action sub action clicked - (IBAction)MActionClicked:(UIButton *)sender { UITableViewCell *cell = (UITableViewCell *) sender.superview.superview; NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell]; int refresh =0; NSMutableDictionary* section_json=nil; NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy]; NSString* subid=[item_json valueForKey:@"subid"]; NSString* refresh_trigger = [item_json valueForKey:@"name"]; NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]]; NSString* type = [sub_action valueForKey:@"type"]; if([type isEqualToString:@"pull"]) { refresh = [[sub_action valueForKey:@"refresh"] intValue]; NSDictionary* keymap= [sub_action objectForKey:@"key_map"]; NSMutableDictionary* value=[self create_value_map:keymap]; if(subid==nil) { NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"]; section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy]; int icount=[[section_json valueForKey:@"count"] intValue]; for (int ic=0;ic0) [modify_item setValue:valuestr forKey:@"value"]; else [modify_item setValue:@"" forKey:@"value"]; [modify_item setValue:@"true" forKey:@"dirty"]; [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]]; } } } else { NSArray* idarr=[subid componentsSeparatedByString:@"_"]; int section = [(NSString*)idarr[0] intValue]; int item=[(NSString*)idarr[1] intValue]; NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"]; section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy]; NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy]; NSString* control_type = [olditem valueForKey:@"control"]; if([control_type isEqualToString:@"switch"]) olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ]; else if([control_type isEqualToString:@"enum"]) { olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ]; } else { [RAUtils alert_view:@"" title:@"not impl"]; } [olditem setValue:@"true" forKey:@"dirty"]; [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]]; } [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]]; self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data]; if(refresh==1) { // if(restore_json!=nil) // { // int rc=[[restore_json valueForKey:@"count"] intValue]; // for(int ir=0;ir0) // return 1; return self.content_data_control.count; // int section_count =[[self.content_data valueForKey:@"section_count"] intValue]; // return section_count; } //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath //{ // DebugLog(@"canMoveRowAtIndexPath"); // // if([tableView numberOfRowsInSection:indexPath.section]>1) // return true; // else // return false; //} //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath //{ // NSMutableArray * from; // NSMutableArray * to ; // if(fromIndexPath.section==0) // from = self.displayfields; // else // from = self.hidefields; // if(toIndexPath.section==0) // to = self.displayfields; // else // to = self.hidefields; // id content=from[fromIndexPath.row]; // [from removeObjectAtIndex:fromIndexPath.row]; // [to insertObject:content atIndex:toIndexPath.row]; // // [tableView reloadData]; // //} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // if(self.content_data_control.count>0) // return 1; NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy]; bool hide = [[sectionjson valueForKey:@"hide"]boolValue]; if(hide) { return 0; // [sectionjson setValue:@"false" forKey:@"hide"]; // [sender setTitle:@"Show" forState:UIControlStateNormal]; } else{ return ((NSMutableArray*)self.content_data_control[section]).count; // [sectionjson setValue:@"true" forKey:@"hide"]; // [sender setTitle:@"Hide" forState:UIControlStateNormal]; } // return 0; // if(section==4) // return 1; // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]]; // // return [[section_json valueForKey:@"count" ] intValue]; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 33; } //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section //{ // return 0.5; //} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row]; NSString* control = [item_json valueForKey:@"control"]; if([control isEqualToString:@"model"]) return 140; else if([control isEqualToString:@"signature"]) return 140; else if([control isEqualToString:@"text_view"]) return 140; else if([control isEqualToString:@"img"]) return 123; return 44; } // - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // int d=0; // if(indexPath.section==4) // d=0; // NSLog(@"%d,%d",indexPath.section,indexPath.row); // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row]; NSString* control = [item_json valueForKey:@"control"]; NSString* required = [item_json valueForKey:@"required"]; NSString *CellIdentifier = @""; if([control isEqualToString:@"text_view"]) { CellIdentifier = @"CommonEditorCellTextView"; CommonEditorCellTextView * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy]; NSString* value =[item_json valueForKey:@"value"]; NSString* align =[item_json valueForKey:@"align"]; if([align isEqualToString:@"right"]) cell.textview.textAlignment= kCTRightTextAlignment; else cell.textview.textAlignment =kCTLeftTextAlignment; int disable = [[item_json valueForKey:@"disable"] intValue]; if(disable==1) { cell.textview.editable=NO; // cell.textfield.backgroundColor = [UIColor lightGrayColor]; cell.textview.textColor= [UIColor lightGrayColor]; } else { cell.textview.editable=YES; cell.textview.textColor= [UIColor blackColor]; // cell.textfield.backgroundColor = [UIColor whiteColor]; } if([required isEqualToString:@"true"]) { [title appendString:@"*"]; } cell.label_name.text=title; cell.textview.text = value; cell.textview.delegate = self; cell.accessoryType = UITableViewCellAccessoryNone; if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0)) { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } else { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; } cell.backgroundColor = UIColorFromRGB(0xF2EEEA); return cell; }else if([control isEqualToString:@"img"]) { CellIdentifier = @"CommonEditorCellImg"; CommonEditorCellImg * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSString* title = [item_json valueForKey:@"aname"] ; NSString* value =[item_json valueForKey:@"value"]; int disable = [[item_json valueForKey:@"disable"] intValue]; if(disable==1) { cell.editable=false; } else cell.editable=true; cell.labelTitle.text = title; cell.labelDescription.text = value; cell.imgChanged = ^(NSString* url_down,NSString* url_up) { // NSMutableDictionary* editjson = [item_json mutableCopy]; // editjson[@"img_url"]=url; [self imgIsChanged:url_down url_up:url_up indexPath:indexPath]; }; NSString* img_url = [item_json valueForKey:@"img_url"]; NSString* file_name=[img_url lastPathComponent]; NSData* img_data=[iSalesDB load_cached_img:file_name]; if(img_data!=nil) { UIImage * img =[UIImage imageWithData:img_data]; [cell.buttonImg setBackgroundImage:img forState:UIControlStateNormal]; cell.img_validate = true; // [cell.buttonImg setImage:img forState:UIControlStateNormal]; } else { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]]; dispatch_async(dispatch_get_main_queue(), ^{ if(downloadimg_data!=nil) { [iSalesDB cache_img:downloadimg_data :file_name ]; UIImage * img =[UIImage imageWithData:downloadimg_data]; [cell.buttonImg setBackgroundImage:img forState:UIControlStateNormal]; cell.img_validate = true; } else { [cell.buttonImg setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal]; cell.img_validate = false; } }); }); } cell.backgroundColor = UIColorFromRGB(0xF2EEEA); return cell; }else if([control isEqualToString:@"edit"]) { CellIdentifier = @"CommonEditorCellEdit"; CommonEditorCellEdit * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy]; NSString* value =[item_json valueForKey:@"value"]; NSString* align =[item_json valueForKey:@"align"]; if([align isEqualToString:@"right"]) cell.textfield.textAlignment= NSTextAlignmentRight; else cell.textfield.textAlignment =NSTextAlignmentLeft; int disable = [[item_json valueForKey:@"disable"] intValue]; if(disable==1) { cell.textfield.enabled=NO; // cell.textfield.backgroundColor = [UIColor lightGrayColor]; cell.textfield.textColor= [UIColor lightGrayColor]; } else { cell.textfield.enabled=YES; cell.textfield.textColor= [UIColor blackColor]; // cell.textfield.backgroundColor = [UIColor whiteColor]; } if([required isEqualToString:@"true"]) { [title appendString:@"*"]; } NSString* keyboard = [item_json valueForKey:@"keyboard"]; if([keyboard isEqualToString:@"number"]) { // float f = [value floatValue]; // value = [NSString stringWithFormat:@"%.2f",f]; cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation; } else if([keyboard isEqualToString:@"email"]) { cell.textfield.keyboardType=UIKeyboardTypeEmailAddress; } else if([keyboard isEqualToString:@"phone"]) { cell.textfield.keyboardType=UIKeyboardTypePhonePad; } else { cell.textfield.keyboardType=UIKeyboardTypeDefault; } cell.labelTitle.text=title; cell.textfield.text = value; cell.textfield.delegate = self; cell.accessoryType = UITableViewCellAccessoryNone; if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0)) { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } else { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; } cell.backgroundColor = UIColorFromRGB(0xF2EEEA); return cell; } else if([control isEqualToString:@"text"]) { CellIdentifier = @"CommonEditorCellLabel"; CommonEditorCellLabel * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSString* title = [item_json valueForKey:@"aname"] ; NSString* value =[item_json valueForKey:@"value"]; NSString* align =[item_json valueForKey:@"align"]; if([align isEqualToString:@"right"]) cell.labelValue.textAlignment= NSTextAlignmentRight; else cell.labelValue.textAlignment =NSTextAlignmentLeft; NSString* type=[item_json valueForKey:@"type"] ; if([type isEqualToString:@"price"]) { if(appDelegate.can_see_price&&appDelegate.price_hidden==false) { } else { value=nil; } } cell.labelTitle.text=title; cell.labelValue.text = value; cell.backgroundColor = UIColorFromRGB(0xF2EEEA); return cell; } else if([control isEqualToString:@"action"]) { CellIdentifier = @"CommonEditorCellAction"; CommonEditorCellAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy]; NSString* value =[item_json valueForKey:@"value"]; if([required isEqualToString:@"true"]) { [title appendString:@"*"]; } NSDictionary* data = [item_json objectForKey:@"data"]; cell.labelAction.text=title; cell.action_code = value; //cell.labelValue.text = value; if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil)) { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } else { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; } cell.backgroundColor = UIColorFromRGB(0xF2EEEA); return cell; } if([control isEqualToString:@"multi_action"]) { CellIdentifier = @"CommonEditorCellMAction"; CommonEditorCellMAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; int count = [[item_json valueForKey:@"count"]intValue]; for(int i=0;i=1) value=[value substringToIndex:value.length-1]; cell.labelTitle.text=title; cell.labelValue.text = value; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0)) { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } else { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; } cell.backgroundColor = UIColorFromRGB(0xF2EEEA); return cell; } else if([control isEqualToString:@"model"]) { CommonEditorCellModel * cell= [tableView dequeueReusableCellWithIdentifier:@"CommonEditorCellModel" forIndexPath:indexPath]; int count = [[item_json valueForKey:@"count"] intValue]; NSDictionary * combine_json =[item_json objectForKey:@"combine"]; cell.bundle_item=combine_json; double dprice=0.0; if(cell.bundle_item!=nil) { int citem=0; int bcount=[[cell.bundle_item valueForKey:@"count"] intValue]; for(int bc=0;bc0) [modify_item setValue:valuestr forKey:@"value"]; else [modify_item setValue:@"" forKey:@"value"]; [modify_item setValue:@"true" forKey:@"dirty"]; [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]]; } } [boolitem setObject:subjson forKey:@"sub_item"]; if([value isEqualToString:@"true"]) [switch_item setObject:boolitem forKey:@"true"]; else [switch_item setObject:boolitem forKey:@"false"]; } return switch_item; } -(NSMutableDictionary*) fill_enum_subitem:(NSMutableDictionary *) enum_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step { NSMutableDictionary* cadedatejson = [[enum_item objectForKey:@"cadedate"] mutableCopy]; int count = [[cadedatejson valueForKey:@"count"]intValue]; for(int i=0;i0) [modify_item setValue:valuestr forKey:@"value"]; else [modify_item setValue:@"" forKey:@"value"]; //[modify_item setValue:valuestr forKey:@"value"]; [modify_item setValue:@"true" forKey:@"dirty"]; [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]]; } } } [val_json setObject:subjson forKey:@"sub_item"]; } [cadedatejson setObject:val_json forKey:[NSString stringWithFormat:@"val_%d",i]]; } [enum_item setObject:cadedatejson forKey:@"cadedate"]; return enum_item; } -(NSMutableDictionary*) switch_subitem_changed:(NSMutableDictionary *) switch_item subid:(NSArray*) subid value:(NSMutableDictionary*)valuejson step:(int) step { int index = [(NSString*)subid[step] intValue]; NSString* value = [switch_item valueForKey:@"value"]; NSMutableDictionary* boolitem=nil; NSMutableDictionary* subjson=nil; if([value isEqualToString:@"true"]) { boolitem =[[switch_item objectForKey:@"true"] mutableCopy]; } else { boolitem =[[switch_item objectForKey:@"false"] mutableCopy]; } subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy]; if(subjson!=nil) { NSMutableDictionary * itemjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy]; if(step==subid.count-1) { itemjson =valuejson; } [subjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]]; [boolitem setObject:subjson forKey:@"sub_item"]; if([value isEqualToString:@"true"]) [switch_item setObject:boolitem forKey:@"true"]; else [switch_item setObject:boolitem forKey:@"false"]; return switch_item; } return nil; } #pragma mark - #pragma mark Responding to keyboard events - (void)keyboardWillChangeFrame:(NSNotification *)notification { NSLog(@"keyboardWillChangeFrame"); } - (void)keyboardWillShow:(NSNotification *)notification { NSLog(@"keyboardWillShow"); if(self.keyboard_show) return; self.keyboard_show=true; /* Reduce the size of the text view so that it's not obscured by the keyboard. Animate the resize so that it's in sync with the appearance of the keyboard. */ NSDictionary *userInfo = [notification userInfo]; // Get the origin of the keyboard when it's displayed. NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; // Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position. // CGRect keyboardRect = [aValue CGRectValue]; CGSize keyboardSize = [aValue CGRectValue].size; NSLog(@"keyboard height:%f",keyboardSize.height); // Get the duration of the animation. NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; NSTimeInterval animationDuration; [animationDurationValue getValue:&animationDuration]; // if(self.keyboard_h==0) // { self.keyboard_h =keyboardSize.height; CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:self.editingcell]; CGRect rect_screen = [ UIScreen mainScreen ].bounds; // int vpos =self.view.frame.origin.y+self.view.frame.size.height; // int loginpos = self.editingcell.frame.origin.y+self.editingcell.frame.size.height; // int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height; // screen.size.height-keyboardSize.height-(cellpos_screen.origin.x+cellpos_screen.size.height); self.ioffset = cellpos-(rect_screen.size.height-keyboardSize.height);//rect_screen.size.height-keyboardSize.height-(rect_screen.origin.y+rect_screen.size.height);//keyboardSize.height -(self.view.frame.size.height-loginpos); if(self.ioffset>0) { // self.resize = true; CGPoint contentOffsetPoint = self.editorTable.contentOffset; contentOffsetPoint.y+=self.ioffset; self.editorTable.contentOffset=contentOffsetPoint; // NSTimeInterval animationDuration = 0.30f; // CGRect frame = self.view.frame; // frame.origin.y -=self.ioffset;//view的Y轴上移 // frame.size.height +=self.ioffset; //View的高度增加 // self.view.frame = frame; // [UIView beginAnimations:@"ResizeView" context:nil]; // [UIView setAnimationDuration:animationDuration]; // self.view.frame = frame; // [UIView commitAnimations];//设置调整界面的动画效果 } self.editorTable.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-self.keyboard_h); // CGSize tablecontent =self.editorTable.contentSize; // tablecontent.height=tablecontent.height+self.keyboard_h; // self.editorTable.contentSize=tablecontent; // } // Animate the resize of the text view's frame in sync with the keyboard's appearance. // [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration]; } - (void)keyboardWillHide:(NSNotification *)notification { NSLog(@"keyboardWillHide"); self.keyboard_show=false; NSDictionary* userInfo = [notification userInfo]; /* Restore the size of the text view (fill self's view). Animate the resize so that it's in sync with the disappearance of the keyboard. */ NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; NSTimeInterval animationDuration; [animationDurationValue getValue:&animationDuration]; CGSize tablecontent =self.editorTable.contentSize; tablecontent.height=tablecontent.height-self.keyboard_h; // self.editorTable.contentSize=tablecontent; self.editorTable.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); self.keyboard_h= 0; NSLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize)); // if(self.resize) // { // NSTimeInterval animationDuration = 0.30f; // CGRect frame = self.view.frame; // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动 // // { //还原界面 // // moveY = prewMoveY; // frame.origin.y +=self.ioffset; // frame.size. height -=self.ioffset; // self.view.frame = frame; // // } // //self.view移回原位置 // [UIView beginAnimations:@"ResizeView" context:nil]; // [UIView setAnimationDuration:animationDuration]; // self.view.frame = frame; // [UIView commitAnimations]; // //[textField resignFirstResponder]; // self.ioffset=0; // } // [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration]; } @end