class ObservableModel {
    constructor() {
        this.observers = [];
    }

    notifyAll() {
        var self = this;
        this.observers.forEach(function(observer) {
            observer.update(self);
        });
        //ToDo: Update field polling
        $(document).trigger('fields-changed');
    }

    persistData() {
        // this.data = { Section: { Key: Value } }
        if (typeof this.data !== 'undefined') {
            var databaseArray = new Array();

            $.each(this.data, function(section, sectionKeys) {
                $.each(sectionKeys, function(key, value) {
                    databaseArray.push(
                        {'section': section, 'key': key, 'value': value}
                    );
                })
            });

            return writeToDatabase(databaseArray, this.category || '');
        } 

        return $.Deferred().resolve();
    }

    registerObserver(observer) {
        this.observers.push(observer);
    }
}