Skip to content

Commit

Permalink
converted ContactEdit ViewController
Browse files Browse the repository at this point in the history
  • Loading branch information
timuber committed Jan 6, 2016
1 parent ac32cff commit 3563eee
Show file tree
Hide file tree
Showing 11 changed files with 605 additions and 41 deletions.
8 changes: 7 additions & 1 deletion SampleAppSwift/API/NIKFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ import UIKit
in as the body of the request to ensure that the file is built
and sent up properly, especially with images.
*/
struct NIKFile {
class NIKFile {
let name: String
let mimeType: String
let data: NSData

init(name: String, mimeType: String, data: NSData) {
self.name = name
self.mimeType = mimeType
self.data = data
}
}
Binary file not shown.
4 changes: 2 additions & 2 deletions SampleAppSwift/SampleAppSwift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="ChooseLocalActionEvent:" destination="AVr-4i-Laq" eventType="touchUpInside" id="WHX-It-Ocf"/>
<action selector="onChooseImageClick" destination="AVr-4i-Laq" eventType="touchUpInside" id="7TE-pm-glw"/>
</connections>
</button>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Image Name" textAlignment="center" minimumFontSize="17" id="i8R-x9-EpP">
Expand All @@ -365,8 +365,8 @@
<color key="backgroundColor" red="0.99607843137254903" green="0.99607843137254903" blue="0.99607843137254903" alpha="1" colorSpace="calibratedRGB"/>
</view>
<connections>
<outlet property="imageListTableView" destination="6r1-Mc-bNJ" id="pr7-PR-2wU"/>
<outlet property="imageNameTextField" destination="i8R-x9-EpP" id="ea8-NM-iVJ"/>
<outlet property="tableView" destination="6r1-Mc-bNJ" id="pkd-EW-pKQ"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="g0q-Hs-ADL" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ class ContactViewController: UIViewController {
NSLog("\nAPI path: \(restApiPath)\n")

// request a download from the file
let queryParams: [String: AnyObject] = ["include_properties": "true",
"content": "true",
"download": "true"]
let queryParams: [String: AnyObject] = ["include_properties": "1",
"content": "1",
"download": "1"]

let headerParams = ["X-DreamFactory-Api-Key": kApiKey,
"X-DreamFactory-Session-Token": swgSessionToken!]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class MasterViewController: UIViewController {
})
} else {
let alert = UIAlertController(title: nil, message: "Error, invalid password", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "ok", style: .Default, handler: nil))
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(alert, animated: true, completion: nil)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@

import UIKit

class ProfileImagePickerViewController: UIViewController {
protocol ProfileImagePickerDelegate: class {

}

class ProfileImagePickerViewController: UIViewController {
@IBOutlet var tableView: UITableView!
@IBOutlet var imageNameTextField: UITextField!

// set only when editing an existing contact
// the contact we are choosing a profile image for
var record: ContactRecord!

weak var delegate: ProfileImagePickerDelegate?

override func viewDidLoad() {
super.viewDidLoad()

}

@IBAction func onChooseImageClick() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class RegisterViewController: UIViewController {
})
} else {
let alert = UIAlertController(title: nil, message: "Error, invalid password", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "ok", style: .Default, handler: nil))
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(alert, animated: true, completion: nil)
}
}
Expand Down
23 changes: 13 additions & 10 deletions SampleAppSwift/SampleAppSwift/Model/ContactDetailRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ import UIKit
Contact info model
*/
class ContactDetailRecord {
let id: NSNumber
var type: String
var phone: String
var email: String
var state: String
var zipCode: String
var country: String
var city: String
var address: String
let contactId: NSNumber
var id: NSNumber!
var type: String!
var phone: String!
var email: String!
var state: String!
var zipCode: String!
var country: String!
var city: String!
var address: String!
var contactId: NSNumber!

init() {
}

init(json: JSON) {
id = json["id"] as! NSNumber
Expand Down
10 changes: 7 additions & 3 deletions SampleAppSwift/SampleAppSwift/Model/ContactRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ extension Dictionary {
Contact model
*/
class ContactRecord: Equatable {
let id: NSNumber
var firstName: String
var lastName: String
var id: NSNumber!
var firstName: String!
var lastName: String!
var notes: String!
var skype: String!
var twitter: String!
Expand All @@ -36,6 +36,10 @@ class ContactRecord: Equatable {
return "\(firstName) \(lastName)"
}

init() {

}

init(json: JSON) {
id = json["id"] as! NSNumber
firstName = json.nonNull("first_name")
Expand Down
36 changes: 20 additions & 16 deletions SampleAppSwift/SampleAppSwift/View/ContactInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import UIKit

class ContactInfoView: UIView {
var record: ContactDetailRecord!
var record: ContactDetailRecord! {
didSet {
updateFields()
}
}
private var textFields: [String: UITextField]!

override init(frame: CGRect) {
Expand All @@ -31,20 +35,6 @@ class ContactInfoView: UIView {
fatalError("init(coder:) has not been implemented")
}

func updateFields() {
putFieldIn(record.type, key: "Type")
putFieldIn(record.phone, key: "Phone")
putFieldIn(record.email, key: "Email")
putFieldIn(record.address, key: "Address")
putFieldIn(record.city, key: "City")
putFieldIn(record.state, key: "State")
putFieldIn(record.zipCode, key: "Zip")
putFieldIn(record.country, key: "Country")

reloadInputViews()
setNeedsDisplay()
}

func updateRecord() {
record.type = textValueForKey("Type")
record.phone = textValueForKey("Phone")
Expand All @@ -60,6 +50,20 @@ class ContactInfoView: UIView {
return [:]
}

private func updateFields() {
putFieldIn(record.type, key: "Type")
putFieldIn(record.phone, key: "Phone")
putFieldIn(record.email, key: "Email")
putFieldIn(record.address, key: "Address")
putFieldIn(record.city, key: "City")
putFieldIn(record.state, key: "State")
putFieldIn(record.zipCode, key: "Zip")
putFieldIn(record.country, key: "Country")

reloadInputViews()
setNeedsDisplay()
}

private func textValueForKey(key: String) -> String {
return textFields[key]!.text!
}
Expand All @@ -80,7 +84,7 @@ class ContactInfoView: UIView {
for field in names {
let textField = UITextField(frame: CGRectMake(frame.size.width * 0.05, y, frame.size.width * 0.9, 35))
textField.placeholder = field
textField.font = UIFont(name: "HelveticaNeue-Regular", size: 20.0)
textField.font = UIFont(name: "Helvetica Neue", size: 20.0)
textField.backgroundColor = UIColor.whiteColor()
textField.layer.cornerRadius = 5
addSubview(textField)
Expand Down

0 comments on commit 3563eee

Please sign in to comment.