Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Ti.include('../database/ListsDAO.js');
  2.  
  3. // window settings
  4. var currentWindow = Ti.UI.currentWindow;
  5. currentWindow.title = 'Grocery List';
  6. currentWindow.barColor = '#C73B46';
  7. currentWindow.backgroundColor = '#DEEEF0';
  8.  
  9. // assets
  10. var createButton = Ti.UI.createButton({
  11.     title: 'Create'
  12. });
  13.  
  14. var listView = Ti.UI.createView({
  15.     height: Ti.Platform.displayCaps.platformHeight - 160,
  16.     width: Ti.Platform.displayCaps.platformWidth - 40
  17. });
  18.  
  19. var nameLabel = Ti.UI.createLabel({
  20.     text: 'Name:',
  21.     height: 'auto',
  22.     width: 'auto',
  23.     font: {fontSize: 15},
  24.     top: 10,
  25.     left: 10
  26. });
  27.  
  28. var nameTextField = Ti.UI.createTextField({
  29.     color: '#336699',
  30.     height: 35,
  31.     top: 30,
  32.     left: 10,
  33.     width: 250,
  34.     borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED
  35. });
  36.  
  37. var priceLabel = Ti.UI.createLabel({
  38.     text: 'Your Budget:',
  39.     height: 'auto',
  40.     width: 'auto',
  41.     font: {fontSize: 15},
  42.     top: 100,
  43.     left: 10
  44. });
  45.  
  46. var priceSlider = Ti.UI.createSlider({
  47.     left: 10,
  48.     min: 1,
  49.     max: 250,
  50.     width: 250,
  51.     top: 125
  52. });
  53.  
  54.  
  55. var createListButton = Ti.UI.createButton({
  56.     title: 'Create List',
  57.     height: 30,
  58.     width: 120,
  59.     top: 300
  60. });
  61.  
  62. var alertDialog = Ti.UI.createAlertDialog({
  63.     title: "Sorry",
  64.     message: "There are no lists in the database.",
  65.     buttonNames: ['Ok']
  66. });
  67.  
  68. var listsDAO = new ListsDAO();
  69.  
  70. // create button toevoegen aan de top bar
  71. currentWindow.rightNavButton = createButton;
  72.  
  73.  
  74. // functions
  75. function loadLists() {
  76.    
  77.     listsDAO.initDatabase();
  78.    
  79.     var lists = listsDAO.getLists();
  80.    
  81.     if (lists.length > 0) {
  82.         for (var i = 0; i < lists.length; i++) {
  83.             var listVO = lists[i];
  84.             Ti.API.info(listVO.getName());
  85.         }
  86.     } else {
  87.         alertDialog.show();
  88.     }
  89. }
  90.  
  91. function showCreateListView() {
  92.    
  93.     Ti.API.info('show create list view');
  94.    
  95.     createButton.enabled = false;
  96.    
  97.     listView.add(nameLabel);
  98.     listView.add(nameTextField);
  99.     listView.add(priceLabel);
  100.     listView.add(priceSlider);
  101.     listView.add(createListButton);
  102.    
  103.     currentWindow.add(listView);
  104. }
  105.  
  106.  
  107. // events
  108. currentWindow.addEventListener('open', function(e) {
  109.     Ti.API.info('lijsten ophalen');
  110.     loadLists();
  111. });
  112.  
  113. createButton.addEventListener('click', function(e) {
  114.     Ti.API.info('create button clicked');
  115.     showCreateListView();
  116. });
  117.  
  118. priceSlider.addEventListener('change', function(e) {
  119.     priceLabel.text = "Your Budget: € " + Math.round(priceSlider.value);
  120. });
  121.  
  122. createListButton.addEventListener('click', function(e) {
  123.     listsDAO.addList(nameTextField.value, Math.round(priceSlider.value));
  124.    
  125.     currentWindow.remove(listView);
  126. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement