Controllers

The final controllers

controllers.js

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
todoApp.controllers = {
    //bind button id to it's corresponding page
    "menuPage": function(page) {
        function bindPage(buttonId, target) {
            document.getElementById(buttonId).onclick = function() {
                var content = document.getElementById('content');
                var menu = document.getElementById('menu');
                content.load(target).then(menu.close.bind(menu));
            };
        }

        bindPage('menu-main', 'html/main.html');
        bindPage('menu-history', 'html/history.html');
    },

    "mainPage": function(page) {
        page.querySelector('#btn-splitter-toggle').onclick = function() {
            document.querySelector('#app-splitter').left.toggle();
        };

        page.querySelector('#btn-create-todo').onclick = function() {
            ons.notification.prompt({message: 'New Todo'})
                .then(function(value) {
                    todoApp.models.todo.add(value);
                    todoApp.views.mainPage(page);
                });
        };

        todoApp.views.mainPage(page);
    },

    "historyPage": function(page) {
        page.querySelector('#btn-splitter-toggle').onclick = function() {
            document.querySelector('#app-splitter').left.toggle();
        };
        todoApp.views.historyPage(page);

    },

    "createPage": function(page) {

    }

};

If you have followed all along, this is the final controllers.js for the app to work. Now you should have a working app!