Laverna/laverna

View on GitHub
app/scripts/apps/notes/form/app.js

Summary

Maintainability
A
0 mins
Test Coverage
/**
 * Copyright (C) 2015 Laverna project Authors.
 * 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
/* global define */
define([
    'underscore',
    'jquery',
    'app',
    'backbone.radio',
    'marionette',
    'apps/notes/form/controller'
], function(_, $, App, Radio, Marionette, Controller) {
    'use strict';

    /**
     * Form app. Instantiates form controller.
     *
     * Listens to the following events:
     * 1. channel: notesForm, event: stop
     *    stops itself
     */
    var Form = App.module('AppNote.Form', {
        startWithParent: false
    });

    Form.on('before:start', function(options) {
        Form.controller = new Controller(options);
        Radio.on('notesForm', 'stop', Form.stop, Form);
    });

    Form.on('before:stop', function() {
        Radio.off('notesForm', 'stop');
        Form.controller.destroy();
        Form.controller = null;
    });

    return Form;
});