Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ti.include('../database/ListsDAO.js');
- // window settings
- var currentWindow = Ti.UI.currentWindow;
- currentWindow.title = 'Grocery List';
- currentWindow.barColor = '#C73B46';
- currentWindow.backgroundColor = '#DEEEF0';
- // assets
- var createButton = Ti.UI.createButton({
- title: 'Create'
- });
- var listView = Ti.UI.createView({
- height: Ti.Platform.displayCaps.platformHeight - 160,
- width: Ti.Platform.displayCaps.platformWidth - 40
- });
- var nameLabel = Ti.UI.createLabel({
- text: 'Name:',
- height: 'auto',
- width: 'auto',
- font: {fontSize: 15},
- top: 10,
- left: 10
- });
- var nameTextField = Ti.UI.createTextField({
- color: '#336699',
- height: 35,
- top: 30,
- left: 10,
- width: 250,
- borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED
- });
- var priceLabel = Ti.UI.createLabel({
- text: 'Your Budget:',
- height: 'auto',
- width: 'auto',
- font: {fontSize: 15},
- top: 100,
- left: 10
- });
- var priceSlider = Ti.UI.createSlider({
- left: 10,
- min: 1,
- max: 250,
- width: 250,
- top: 125
- });
- var createListButton = Ti.UI.createButton({
- title: 'Create List',
- height: 30,
- width: 120,
- top: 300
- });
- var alertDialog = Ti.UI.createAlertDialog({
- title: "Sorry",
- message: "There are no lists in the database.",
- buttonNames: ['Ok']
- });
- var listsDAO = new ListsDAO();
- // create button toevoegen aan de top bar
- currentWindow.rightNavButton = createButton;
- // functions
- function loadLists() {
- listsDAO.initDatabase();
- var lists = listsDAO.getLists();
- if (lists.length > 0) {
- for (var i = 0; i < lists.length; i++) {
- var listVO = lists[i];
- Ti.API.info(listVO.getName());
- }
- } else {
- alertDialog.show();
- }
- }
- function showCreateListView() {
- Ti.API.info('show create list view');
- createButton.enabled = false;
- listView.add(nameLabel);
- listView.add(nameTextField);
- listView.add(priceLabel);
- listView.add(priceSlider);
- listView.add(createListButton);
- currentWindow.add(listView);
- }
- // events
- currentWindow.addEventListener('open', function(e) {
- Ti.API.info('lijsten ophalen');
- loadLists();
- });
- createButton.addEventListener('click', function(e) {
- Ti.API.info('create button clicked');
- showCreateListView();
- });
- priceSlider.addEventListener('change', function(e) {
- priceLabel.text = "Your Budget: € " + Math.round(priceSlider.value);
- });
- createListButton.addEventListener('click', function(e) {
- listsDAO.addList(nameTextField.value, Math.round(priceSlider.value));
- currentWindow.remove(listView);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement