shlist

share and manage lists between multiple people
Log | Files | Refs

NewListTableViewController.m (2529B)


      1 #import "NewListTableViewController.h"
      2 #import "EditTableViewController.h"
      3 #import "Network.h"
      4 
      5 @interface NewListTableViewController () {
      6 	Network *network_connection;
      7 }
      8 
      9 @property (weak, nonatomic) IBOutlet UIBarButtonItem	*saveButton;
     10 @property (weak, nonatomic) IBOutlet UISwitch		*deadline_switch;
     11 @property (weak, nonatomic) IBOutlet UILabel		*list_name;
     12 
     13 @property (weak, nonatomic) IBOutlet UIDatePicker	*datePicker;
     14 
     15 @end
     16 
     17 @implementation NewListTableViewController
     18 
     19 - (IBAction)deadline_toggle:(id)sender {
     20 
     21 	// UISwitch *dl_switch = (UISwitch *)sender;
     22 	NSIndexSet *index_set = [NSIndexSet indexSetWithIndex:1];
     23 
     24 	if ([self.tableView numberOfSections] == 1)
     25 		[self.tableView insertSections:index_set withRowAnimation:UITableViewRowAnimationMiddle];
     26 	else
     27 		[self.tableView deleteSections:index_set withRowAnimation:UITableViewRowAnimationMiddle];
     28 }
     29 
     30 - (IBAction) unwindToAddList:(UIStoryboardSegue *)segue
     31 {
     32 	NSLog(@"unwound");
     33 }
     34 
     35 - (void) viewDidLoad {
     36 	[super viewDidLoad];
     37 	// Do any additional setup after loading the view.
     38 
     39 	//_edit_text_field = [[UITextField alloc] init];
     40 	//_edit_text_field.text = @"New Shlist";
     41 
     42 	_list_name.text = @"New Shlist";
     43 	network_connection = [Network shared_network_connection];
     44 }
     45 
     46 - (void) didReceiveMemoryWarning {
     47 	[super didReceiveMemoryWarning];
     48 	// Dispose of any resources that can be recreated.
     49 }
     50 
     51 - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
     52 {
     53 	if (_deadline_switch.isOn)
     54 		return 2;
     55 	else
     56 		return 1;
     57 	return 0;
     58 }
     59 
     60 // preparation before navigation
     61 - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
     62 {
     63 	if ([[segue identifier] isEqualToString:@"add shared list name edit"]) {
     64 		// segue forwards to name editor
     65 		NSLog(@"debug: %@: editing name", _list_name.text);
     66 
     67 		EditTableViewController *edit = [segue destinationViewController];
     68 		edit.list_name = (UITextField *)_list_name;
     69 
     70 		return;
     71 	}
     72 
     73 	// User hit cancel, throw away any changes
     74 	if (sender != self.saveButton)
     75 		return;
     76 
     77 	SharedList *shared_list = [[SharedList alloc] init];
     78 
     79 	// saving, copy form fields into shared list object
     80 	shared_list.name = _list_name.text;
     81 	shared_list.deadline = _deadline_switch.isOn;
     82 
     83 	NSLog(@"new_list: sending list_add request...");
     84 
     85 	NSMutableDictionary *list = [[NSMutableDictionary alloc] init];
     86 	[list setObject:[NSNumber numberWithInt:0] forKey:@"num"];
     87 	[list setObject:shared_list.name forKey:@"name"];
     88 	[list setObject:[NSNumber numberWithInt:0] forKey:@"date"];
     89 
     90 	[network_connection send_message:list_add contents:list];
     91 }
     92 
     93 @end