Blame view

App/createNew/VCNhapMucChup.swift 4.8 KB
d774f0637   Trịnh Văn Quân   fisrt comit
1
  import UIKit
1341bf603   Trịnh Văn Quân   version 1.1
2
  import GeneralUtils
d774f0637   Trịnh Văn Quân   fisrt comit
3
4
5
6
7
  
  class VCNhapMucChup: UIViewController, IVCLoadDataTableViewUIThread {
      @IBOutlet weak var edtTitle: UITextField!
      @IBOutlet weak var topMargin: NSLayoutConstraint!
      @IBOutlet weak var tableView: UITableViewLoadDataFromUIThread!
1341bf603   Trịnh Văn Quân   version 1.1
8
      @IBOutlet weak var vTopLogo: VTopLogo!
fbd62afcf   Trịnh Văn Quân   version 1.2.2
9
10
11
      @IBOutlet weak var btnNext: UIButtonCustomGradientBg!
  
      var cTruong: CongTruong?
d774f0637   Trịnh Văn Quân   fisrt comit
12
13
14
15
16
17
  
      static func getInstance() -> VCNhapMucChup {
          let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
          let vcOpen = storyboard.instantiateViewController(withIdentifier: "VCNhapMucChup") as! VCNhapMucChup
          return vcOpen
      }
fbd62afcf   Trịnh Văn Quân   version 1.2.2
18
19
20
21
22
      static func openControllerFromEdit(_ viewController: UIViewController, cTruong: CongTruong?) {
          let vcOpen = getInstance()
          vcOpen.cTruong = cTruong;
          viewController.present(vcOpen, animated: true, completion: nil)
      }
d774f0637   Trịnh Văn Quân   fisrt comit
23
24
      override func viewDidLoad() {
          super.viewDidLoad()
1341bf603   Trịnh Văn Quân   version 1.1
25
26
27
          vTopLogo.leftBtnClick = {
              self.btnLeftClick(self.vTopLogo)
          }
454c1bb6f   Trịnh Văn Quân   version 1.2.1
28
          tableView.emptyText = LocalizedString("list_empty")
d774f0637   Trịnh Văn Quân   fisrt comit
29
30
31
32
          CellMucChupWithDelete.registerClass(tableView: tableView, forCellReuseIdentifier: "CellMucChupWithDelete")
          self.tableView.separatorStyle = UITableViewCellSeparatorStyle.singleLine
          self.tableView.rowHeight = UITableViewAutomaticDimension
          self.tableView.estimatedRowHeight = 150
fbd62afcf   Trịnh Văn Quân   version 1.2.2
33
34
35
          if self.cTruong != nil {
              btnNext.isHidden = true;
          }
d774f0637   Trịnh Văn Quân   fisrt comit
36
37
38
39
40
41
42
43
44
45
      }
  
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
          tableView.initAndLoadData(self)
      }
  
      @IBAction func btnAddClick(_ sender: Any) {
          if let title = edtTitle.text?.trimAndReturn(), title.length > 0 {
              for item in tableView.itemsData {
1341bf603   Trịnh Văn Quân   version 1.1
46
                  if let mc = item as? ShootItem, mc.name == title {
d774f0637   Trịnh Văn Quân   fisrt comit
47
48
49
50
                      CommonUtils.showToastLong(text: LocalizedString("muc_chup_da_ton_tai"))
                      return
                  }
              }
1341bf603   Trịnh Văn Quân   version 1.1
51
              tableView.itemsData.insert(ShootItem(name: title), at: 0)
d774f0637   Trịnh Văn Quân   fisrt comit
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
              tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)
              tableView.removeAllLoaddingEmpty()
              edtTitle.text = ""
          } else {
              CommonUtils.showToastLong(text: LocalizedString("khong_de_trong"))
          }
      }
  
      @IBAction func btnRightClick(_ sender: Any) {
          saveMucChup()
          _ = getVcRoot()?.changeCurrentController(VCChonMucChup.getInstance())
      }
  
      @IBAction func btnLeftClick(_ sender: Any) {
          saveMucChup()
fbd62afcf   Trịnh Văn Quân   version 1.2.2
67
68
69
70
71
          if self.cTruong != nil {
              dismiss(animated: true)
          } else {
              _ = getVcRoot()?.changeCurrentController(VCNhapTenCtruong.getInstance())
          }
d774f0637   Trịnh Văn Quân   fisrt comit
72
73
74
      }
  
      private func saveMucChup() {
1341bf603   Trịnh Văn Quân   version 1.1
75
          var mucChups = [ShootItem]()
d774f0637   Trịnh Văn Quân   fisrt comit
76
          for item in tableView.itemsData {
1341bf603   Trịnh Văn Quân   version 1.1
77
              if let mucChup = item as? ShootItem {
d774f0637   Trịnh Văn Quân   fisrt comit
78
79
80
                  mucChups.append(mucChup)
              }
          }
fbd62afcf   Trịnh Văn Quân   version 1.2.2
81
82
83
84
85
          if let cTruong = self.cTruong {
              cTruong.shootItems = mucChups;
          } else {
              getVcRoot()?.mucChups = mucChups
          }
d774f0637   Trịnh Văn Quân   fisrt comit
86
87
88
89
      }
      //region ============== TableView Data =========
  
      func loadDataOnUI(complete: @escaping ([Any]?) -> ()) {
fbd62afcf   Trịnh Văn Quân   version 1.2.2
90
91
92
93
94
          if let cTruong = self.cTruong {
              complete(cTruong.shootItems);
          } else {
              complete(getVcRoot()?.mucChups)
          }
d774f0637   Trịnh Văn Quân   fisrt comit
95
96
97
98
99
100
101
102
103
104
105
106
107
      }
  
      func getAllCell() -> [BaseCell] {
          var baseCells: [BaseCell] = [BaseCell]();
          baseCells.append(BaseCell(type: 0, identifier: "CellMucChupWithDelete"))
          return baseCells
      }
  
      func getTypeOfData(baseobj: Any) -> Int {
          return 0
      }
  
      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
1341bf603   Trịnh Văn Quân   version 1.1
108
          if let mucChup = self.tableView.getItem(indexPath) as? ShootItem {
d774f0637   Trịnh Văn Quân   fisrt comit
109
110
111
              edtTitle.text = mucChup.name
          }
      }
1341bf603   Trịnh Văn Quân   version 1.1
112
      func deleteMucChup(_ mucChupParam: ShootItem) {
d774f0637   Trịnh Văn Quân   fisrt comit
113
114
115
          var indexFind = -1, index = -1
          for item in self.tableView.itemsData {
              index += 1
1341bf603   Trịnh Văn Quân   version 1.1
116
              if let mucChup = item as? ShootItem, mucChup.name == mucChupParam.name {
d774f0637   Trịnh Văn Quân   fisrt comit
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
                  indexFind = index
                  break
              }
          }
          if indexFind >= 0 {
              tableView.itemsData.remove(at: indexFind)
              tableView.deleteRows(at: [IndexPath(row: indexFind, section: 0)], with: .automatic)
          }
      }
      //endregion
  
  
      @IBAction func edtActionTrigerClick(_ sender: Any) {
          edtTitle.endEditing(true)
      }
  
      func getVcRoot() -> VCRootCreateNew? {
          return self.parent as? VCRootCreateNew
      }
fbd62afcf   Trịnh Văn Quân   version 1.2.2
136
137
138
139
140
141
142
      override var prefersStatusBarHidden: Bool {
          return true
      }
  
      override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
          return UIInterfaceOrientationMask.portrait
      }
d774f0637   Trịnh Văn Quân   fisrt comit
143
  }