<commit_before>// ==========================================================================
// Project:   The M-Project - Mobile HTML5 Application Framework
// Copyright: 2010 M-Way Solutions GmbH. All rights reserved.
// Creator:   Sebastian
// Date:      04.11.2010
// License:   Dual licensed under the MIT or GPL Version 2 licenses.
//            http://github.com/mwaylabs/The-M-Project/blob/master/MIT-LICENSE
//            http://github.com/mwaylabs/The-M-Project/blob/master/GPL-LICENSE
// ==========================================================================

Todos.TodoController = M.Controller.extend({

    notes: M.ModelManager.extend({
        model: Todos.Note
    }),

    todos: null,

    counter: 0,

    init: function() {
        this.notes.find();
        this.set('todos', this.notes.modelList);
        this.calculateCounter();
    },

    addTodo: function() {
        var text = Todos.app.page.content.inputField.value;
        if(!text) {
            return;
        }

        var note = Todos.Note.newRecord( { text: text } );
        this.notes.add(note);
        note.save();
        this.set('todos', this.notes.modelList);

        this.calculateCounter();

        Todos.app.page.content.inputField.setValue('');
    },

    removeTodo: function(domId, modelId) {
        var doDelete = confirm('Do you really want to delete this item?');
        if(doDelete) {
            this.notes.del(modelId);
            this.notes.remove(modelId);
            this.set('todos', this.notes.modelList);
            this.calculateCounter();
        }
    },

    calculateCounter: function() {
        this.set('counter', this.todos.length);
    },

    edit: function() {
        Todos.app.page.content.todoList.toggleRemove({
            target: this,
            action: 'removeTodo',
            disableOnEdit: ['Todos.app.page.content.inputField']
        });
    }

});<commit_msg>changed findAll call in init() to use model's method<commit_after>// ==========================================================================
// Project:   The M-Project - Mobile HTML5 Application Framework
// Copyright: 2010 M-Way Solutions GmbH. All rights reserved.
// Creator:   Sebastian
// Date:      04.11.2010
// License:   Dual licensed under the MIT or GPL Version 2 licenses.
//            http://github.com/mwaylabs/The-M-Project/blob/master/MIT-LICENSE
//            http://github.com/mwaylabs/The-M-Project/blob/master/GPL-LICENSE
// ==========================================================================

Todos.TodoController = M.Controller.extend({

    notes: M.ModelManager.extend({
        model: Todos.Note
    }),

    todos: null,

    counter: 0,

    init: function() {
        Todos.Note.findAll();
        this.set('todos', this.notes.modelList);
        this.calculateCounter();
    },

    addTodo: function() {
        var text = Todos.app.page.content.inputField.value;
        if(!text) {
            return;
        }

        var note = Todos.Note.newRecord( { text: text } );
        this.notes.add(note);
        note.save();
        this.set('todos', this.notes.modelList);

        this.calculateCounter();

        Todos.app.page.content.inputField.setValue('');
    },

    removeTodo: function(domId, modelId) {
        var doDelete = confirm('Do you really want to delete this item?');
        if(doDelete) {
            this.notes.del(modelId);
            this.notes.remove(modelId);
            this.set('todos', this.notes.modelList);
            this.calculateCounter();
        }
    },

    calculateCounter: function() {
        this.set('counter', this.todos.length);
    },

    edit: function() {
        Todos.app.page.content.todoList.toggleRemove({
            target: this,
            action: 'removeTodo',
            disableOnEdit: 'Todos.app.page.content.inputField'
        });
    }

});
{'fraction_non_alphanumeric': 0.20645994832041345, 'fraction_numerical': 0.007751937984496124, 'mean_word_length': 2.3000852514919012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7474592', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1106, 'n_words': 206}