|
|
@@ -15,7 +15,11 @@
|
|
|
#import "SignatureViewController.h"
|
|
|
#import "PDFUtils.h"
|
|
|
#import "ImageUtils.h"
|
|
|
+#import "TextUtils.h"
|
|
|
+
|
|
|
#import "CheckSelectorViewController.h"
|
|
|
+#import "DatePickerViewController.h"
|
|
|
+
|
|
|
|
|
|
|
|
|
//#import "TouchImageView.h"
|
|
|
@@ -97,10 +101,38 @@
|
|
|
[self addLabel:control destView:self.editControlView index:i];
|
|
|
|
|
|
}
|
|
|
+ else if([control[@"type"] isEqualToString:@"DatePicker"])
|
|
|
+ {
|
|
|
+ [self addDatePicker:control destView:self.editControlView index:i];
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
#pragma mark add controls
|
|
|
+-(bool) checkActionCondition:(NSString*) condition
|
|
|
+{
|
|
|
+ if([condition isEqualToString:@"true"])
|
|
|
+ return true;
|
|
|
+ if([condition isEqualToString:@"control_18:[value]==0"])
|
|
|
+ {
|
|
|
+ NSArray* arr= self.controlTemplate[@"control_18"][@"value"];
|
|
|
+ if(arr.count==0)
|
|
|
+ return false;
|
|
|
+ else
|
|
|
+ return [arr[0] intValue]==0;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+-(UIView*) findControl:(NSString*)controlName
|
|
|
+{
|
|
|
+
|
|
|
+ controlName=[controlName stringByReplacingOccurrencesOfString:@"control_" withString:@""];
|
|
|
+ int d_idx = [controlName intValue];
|
|
|
+ return [self.view viewWithTag:d_idx+CONTROL_BASE];
|
|
|
+}
|
|
|
-(void) addTextView:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
|
|
|
{
|
|
|
UITextView* tv = [[UITextView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
|
|
|
@@ -108,7 +140,9 @@
|
|
|
if(fontsize==0)
|
|
|
fontsize=10;
|
|
|
[tv setFont:[UIFont systemFontOfSize:fontsize]];
|
|
|
+ bool isdisable = [template[@"disable"] boolValue];
|
|
|
|
|
|
+ tv.editable = !isdisable;
|
|
|
tv.text =template[@"value"];
|
|
|
|
|
|
tv.tag = index+ CONTROL_BASE;
|
|
|
@@ -183,6 +217,29 @@
|
|
|
}
|
|
|
[destView addSubview:btn];
|
|
|
}
|
|
|
+-(void) addDatePicker:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
|
|
|
+{
|
|
|
+ UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
|
|
|
+
|
|
|
+
|
|
|
+ [btn setTitle:template[@"value"] forState:UIControlStateNormal];
|
|
|
+ float fontsize = [template[@"size"] floatValue];
|
|
|
+ if(fontsize==0)
|
|
|
+ fontsize=10;
|
|
|
+ btn.titleLabel.font = [UIFont systemFontOfSize: fontsize];
|
|
|
+ btn.tag = index+ CONTROL_BASE;
|
|
|
+ [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
|
|
+ // ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
|
|
|
+ btn.backgroundColor = UIColorFromRGB(BT_BG);
|
|
|
+ [btn addTarget:self action:@selector(ControlDatePickerClicked:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ if(DEBUG_PDFSIG)
|
|
|
+ {
|
|
|
+ // btn.backgroundColor = [UIColor lightGrayColor];
|
|
|
+
|
|
|
+ // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
|
|
|
+ }
|
|
|
+ [destView addSubview:btn];
|
|
|
+}
|
|
|
-(UIView*) createMarker:(int)size x:(int)x y:(int)y
|
|
|
{
|
|
|
UIView* v=[[UIView alloc] initWithFrame:CGRectMake(x, y, size, size)];
|
|
|
@@ -210,7 +267,9 @@
|
|
|
NSArray* cadedate = template[@"cadedate"];
|
|
|
|
|
|
NSArray* checkedData = self.controlTemplate [[NSString stringWithFormat:@"control_%d",index] ][@"value"];
|
|
|
-
|
|
|
+ float fontsize = [template[@"size"] floatValue];
|
|
|
+ if(fontsize==0)
|
|
|
+ fontsize=10;
|
|
|
|
|
|
// if(checkedData.count>0)
|
|
|
// marker_bg = [UIColor clearColor];
|
|
|
@@ -220,7 +279,23 @@
|
|
|
for(int i=0;i<cadedate.count;i++)
|
|
|
{
|
|
|
NSArray* item = cadedate[i];
|
|
|
-
|
|
|
+ NSArray* checkmarker = item[1];
|
|
|
+ if(checkmarker.count==0)
|
|
|
+ {
|
|
|
+ [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
|
|
+ btn.titleLabel.font = [UIFont systemFontOfSize: fontsize];
|
|
|
+ btn.backgroundColor = UIColorFromRGB(CK_BG);
|
|
|
+ if([checkedData containsObject:[NSNumber numberWithLong:i]])
|
|
|
+ {
|
|
|
+ [btn setTitle:item[0][0] forState:UIControlStateNormal];
|
|
|
+
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [btn setTitle:@"" forState:UIControlStateNormal];
|
|
|
+ }
|
|
|
UIView* marker=[self createMarker:[template[@"marker_size"] intValue] x:[item[1][0] intValue] y:[item[1][1] intValue]];
|
|
|
|
|
|
marker.backgroundColor = marker_bg;
|
|
|
@@ -324,6 +399,43 @@
|
|
|
//
|
|
|
//}
|
|
|
#pragma mark Button Click
|
|
|
+- (void)ControlDatePickerClicked:(UIButton *)sender {
|
|
|
+
|
|
|
+
|
|
|
+ long index = sender.tag - CONTROL_BASE;
|
|
|
+
|
|
|
+ __weak __typeof(self)weakSelf = self;
|
|
|
+ NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
|
|
|
+ [formatter setDateFormat:@"MM/dd/yyyy"];
|
|
|
+ NSString* date = @"";
|
|
|
+
|
|
|
+ NSDate* currentDate =nil;
|
|
|
+ if(date.length==0)
|
|
|
+ currentDate=[NSDate date];
|
|
|
+ else
|
|
|
+ currentDate=[formatter dateFromString:date];
|
|
|
+
|
|
|
+ DatePickerViewController* dpvc =[ [UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"DatePickerViewController"];
|
|
|
+
|
|
|
+ dpvc.pickerMode = UIDatePickerModeDate;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ dpvc.date = currentDate;
|
|
|
+ dpvc.formatter = formatter;
|
|
|
+ dpvc.labelTime.text = [formatter stringFromDate:currentDate];
|
|
|
+
|
|
|
+ dpvc.blk_Set = ^(NSString* strdate)
|
|
|
+ {
|
|
|
+// weakSelf.labelSignDate.text = strdate;
|
|
|
+
|
|
|
+ [sender setTitle:strdate forState:UIControlStateNormal];
|
|
|
+
|
|
|
+ weakSelf.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = strdate;
|
|
|
+ };
|
|
|
+ dpvc.title=@"Please choose a date";
|
|
|
+ [self.navigationController pushViewController:dpvc animated:true];
|
|
|
+}
|
|
|
- (void)ControlButtonClicked:(UIButton *)sender {
|
|
|
// DebugLog(@"cart sort button clicked");
|
|
|
|
|
|
@@ -345,9 +457,86 @@
|
|
|
CheckSelectorViewController *checkVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"CheckSelectorViewController"];
|
|
|
|
|
|
checkVC.blk_OK = ^(NSArray* checkedData){
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
for(int i=0;i<rowData.count;i++)
|
|
|
{
|
|
|
long tag=CHECK_BASE+index*1000+i;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ NSArray* item = rowData[i];
|
|
|
+ NSArray* checkmarker = item[1];
|
|
|
+ if(checkmarker.count==0)
|
|
|
+ {
|
|
|
+ sender.backgroundColor = UIColorFromRGB(CK_BG);
|
|
|
+ if([checkedData containsObject:[NSNumber numberWithLong:i]])
|
|
|
+ {
|
|
|
+ [sender setTitle:item[0][0] forState:UIControlStateNormal];
|
|
|
+ if(item.count>=3)
|
|
|
+ {
|
|
|
+ NSMutableDictionary* action = item[2];
|
|
|
+ NSArray* disable_arr = action[@"disable"] ;
|
|
|
+ for(int d = 0 ; d<disable_arr.count;d++)
|
|
|
+ {
|
|
|
+ self.controlTemplate [disable_arr[d] ] [@"disable"] = [NSNumber numberWithBool:true];
|
|
|
+ NSString* s_idx =disable_arr[d];
|
|
|
+ s_idx=[s_idx stringByReplacingOccurrencesOfString:@"control_" withString:@""];
|
|
|
+ int d_idx = [s_idx intValue];
|
|
|
+ ((UITextView*)[sender.superview viewWithTag:d_idx+CONTROL_BASE]).editable = false;
|
|
|
+ }
|
|
|
+ NSArray* enable_arr = action[@"enable"] ;
|
|
|
+ for(int e = 0 ; e<enable_arr.count;e++)
|
|
|
+ {
|
|
|
+ self.controlTemplate [enable_arr[e] ] [@"disable"] = [NSNumber numberWithBool:false];
|
|
|
+
|
|
|
+ NSString* s_idx =enable_arr[e];
|
|
|
+ s_idx=[s_idx stringByReplacingOccurrencesOfString:@"control_" withString:@""];
|
|
|
+ int d_idx = [s_idx intValue];
|
|
|
+
|
|
|
+ ((UITextView*)[sender.superview viewWithTag:d_idx+CONTROL_BASE]).editable = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ NSMutableDictionary* json_setval=action[@"set_val"] ;
|
|
|
+ for(int i=0;i<[json_setval[@"count"] intValue];i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ NSMutableDictionary * control = json_setval [[NSString stringWithFormat:@"item_%d",i] ];
|
|
|
+ UITextView* tv = (UITextView*) [self findControl:control[@"control"]];
|
|
|
+ NSString* value = control[@"value"];
|
|
|
+
|
|
|
+ UITextView* tv6 = (UITextView*) [self findControl:@"control_6"];
|
|
|
+ NSString* text = tv6.text;
|
|
|
+ NSString* newvalue = nil;
|
|
|
+ if([value isEqualToString:@"*0.1"])
|
|
|
+ {
|
|
|
+ float f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue]*0.1;
|
|
|
+ newvalue = [NSString stringWithFormat:@"$ %.2f",f];
|
|
|
+ self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
|
|
|
+ }
|
|
|
+ else if([value isEqualToString:@"*0.9"])
|
|
|
+ {
|
|
|
+ float f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue]*0.9;
|
|
|
+ newvalue = [NSString stringWithFormat:@"$ %.2f",f];
|
|
|
+ self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tv.text = newvalue;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [sender setTitle:@"" forState:UIControlStateNormal];
|
|
|
+ }
|
|
|
+
|
|
|
// UIView* v= sender;
|
|
|
if([checkedData containsObject:[NSNumber numberWithLong:i]])
|
|
|
{
|
|
|
@@ -361,9 +550,10 @@
|
|
|
// [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
|
|
|
[sender.superview viewWithTag:tag].backgroundColor= [UIColor clearColor];
|
|
|
}
|
|
|
- self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"]=checkedData;
|
|
|
+
|
|
|
|
|
|
}
|
|
|
+ self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"]=checkedData;
|
|
|
};
|
|
|
checkVC.rowData = rowData;
|
|
|
checkVC.checkedData = [checkedData mutableCopy];
|
|
|
@@ -377,16 +567,112 @@
|
|
|
}
|
|
|
|
|
|
#pragma mark TextViewDelegate
|
|
|
+- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ long index = textView.tag - CONTROL_BASE;
|
|
|
+
|
|
|
+ NSString* oldtext =textView.text;
|
|
|
+ if(oldtext==nil)
|
|
|
+ oldtext=@"";
|
|
|
+
|
|
|
+ bool canChange=true;
|
|
|
+
|
|
|
+ int max_line = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"lines"] intValue];
|
|
|
+ if(max_line==0)//默认只能有一行
|
|
|
+ max_line=1;
|
|
|
+ long linecount=[TextUtils countOccurencesOfString:oldtext find:@"\n"];
|
|
|
+ if(max_line!=-1) //maxline -1表示不限制行数。
|
|
|
+ {
|
|
|
+ if(linecount<=max_line-1&& [text isEqualToString:@"\n"])
|
|
|
+ {
|
|
|
+ canChange = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int lenth = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"length"] intValue];
|
|
|
+ if(lenth==0)
|
|
|
+ return canChange;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return canChange&& (lenth>textView.text.length ||[text isEqualToString:@""]);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
- (void)textViewDidEndEditing:(UITextView *)textView
|
|
|
{
|
|
|
|
|
|
long index = textView.tag - CONTROL_BASE;
|
|
|
|
|
|
- NSString* text =textView.text;
|
|
|
+
|
|
|
+ //处理 prefix 和 浮点格式化
|
|
|
+ NSString* prefix_str= self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"prefix_str"];
|
|
|
+ if(prefix_str.length==0)
|
|
|
+ prefix_str = @"";
|
|
|
+ NSString* text = [textView.text stringByReplacingOccurrencesOfString:prefix_str withString:@""];
|
|
|
+
|
|
|
+ NSString* value_type= self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value_type"];
|
|
|
+ if([value_type isEqualToString:@"float"])
|
|
|
+ text=[NSString stringWithFormat:@"%.2f",[text floatValue] ];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ text =[NSString stringWithFormat:@"%@%@",prefix_str,text] ;
|
|
|
+
|
|
|
+ textView.text = text;
|
|
|
+
|
|
|
if(text==nil)
|
|
|
text=@"";
|
|
|
self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = text;
|
|
|
|
|
|
+ NSDictionary* action = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"action"];
|
|
|
+ NSArray* keys=[action allKeys];
|
|
|
+ for(int k=0;k<keys.count;k++)
|
|
|
+ {
|
|
|
+ NSMutableDictionary* act_k = action[keys[k] ];
|
|
|
+
|
|
|
+
|
|
|
+ if (![self checkActionCondition:act_k[@"condition"]])
|
|
|
+ continue;
|
|
|
+ for(int i=0;i<[act_k[@"count"] intValue];i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ NSMutableDictionary * control = act_k [[NSString stringWithFormat:@"item_%d",i] ];
|
|
|
+ UITextView* tv = (UITextView*) [self findControl:control[@"control"]];
|
|
|
+ NSString* value = control[@"value"];
|
|
|
+
|
|
|
+ NSString* newvalue = nil;
|
|
|
+ if([value isEqualToString:@"*0.1"])
|
|
|
+ {
|
|
|
+ float f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue]*0.1;
|
|
|
+ newvalue = [NSString stringWithFormat:@"$ %.2f",f];
|
|
|
+
|
|
|
+ self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
|
|
|
+ }
|
|
|
+ else if([value isEqualToString:@"*0.9"])
|
|
|
+ {
|
|
|
+ float f= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue]*0.9;
|
|
|
+ newvalue = [NSString stringWithFormat:@"$ %.2f",f];
|
|
|
+ self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
|
|
|
+ }
|
|
|
+ else if([value isEqualToString:@"control_6-control_7"])
|
|
|
+ {
|
|
|
+
|
|
|
+ UITextView* tv6 = (UITextView*) [self findControl:@"control_6"];
|
|
|
+ float f6= [[tv6.text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue];
|
|
|
+
|
|
|
+ float f7= [[text stringByReplacingOccurrencesOfString:@"$" withString:@"" ] floatValue];
|
|
|
+ newvalue = [NSString stringWithFormat:@"$ %.2f",f6-f7];
|
|
|
+ self.controlTemplate [control[@"control"] ][@"value"] = newvalue;
|
|
|
+ }
|
|
|
+
|
|
|
+ tv.text = newvalue;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// int count = [self.controlTemplate[@"count"] intValue];
|
|
|
// for(int i=0;i<count;i++)
|
|
|
// {
|
|
|
@@ -444,6 +730,27 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+ };
|
|
|
+ signatureVC.blk_Fill =^(NSString* file)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// // NSString* file_name=[file lastPathComponent];
|
|
|
+//
|
|
|
+// NSData* img_data=[ImageUtils load_img:file];
|
|
|
+//
|
|
|
+// if(img_data!=nil)
|
|
|
+// {
|
|
|
+//
|
|
|
+// UIImage* image=[UIImage imageWithData:img_data];
|
|
|
+// touchImageView.image = image;
|
|
|
+//
|
|
|
+// long index = touchImageView.tag - CONTROL_BASE;
|
|
|
+// self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
};
|
|
|
signatureVC.blk_Add = ^()
|
|
|
{
|