mirror of
https://github.com/nasa/openmct.git
synced 2024-12-23 23:12:23 +00:00
[API] Update view API
This commit is contained in:
parent
2240a87ddc
commit
96316de6e4
@ -21,9 +21,7 @@ define(['angular'], function (angular) {
|
||||
}
|
||||
|
||||
var view = factories[key](mctObject);
|
||||
var elements = view.elements();
|
||||
element.empty();
|
||||
element.append(elements);
|
||||
view.show(element[0]);
|
||||
}
|
||||
|
||||
function setKey(k) {
|
||||
|
@ -1,21 +1,24 @@
|
||||
define(['EventEmitter'], function (EventEmitter) {
|
||||
define(function () {
|
||||
function View() {
|
||||
EventEmitter.call(this);
|
||||
}
|
||||
|
||||
View.prototype = Object.create(EventEmitter.prototype);
|
||||
/**
|
||||
* Show this view in the specified container. If this view is already
|
||||
* showing elsewhere, it will be removed from that location.
|
||||
*
|
||||
* @param {HTMLElement} container the element to populate
|
||||
*/
|
||||
View.prototype.show = function (container) {
|
||||
};
|
||||
|
||||
['elements', 'model'].forEach(function (method) {
|
||||
View.prototype[method] = function (value) {
|
||||
this.viewState =
|
||||
this.viewState || { elements: [], model: undefined };
|
||||
if (arguments.length > 0) {
|
||||
this.viewState[method] = value;
|
||||
this.emit(method, value);
|
||||
}
|
||||
return this.viewState[method];
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Release any resources associated with this view.
|
||||
*
|
||||
* Subclasses should override this method to release any resources
|
||||
* they obtained during a `show` call.
|
||||
*/
|
||||
View.prototype.destroy = function () {
|
||||
};
|
||||
|
||||
return View;
|
||||
});
|
||||
|
@ -22,23 +22,26 @@ define([
|
||||
});
|
||||
|
||||
function TodoView(domainObject) {
|
||||
mct.View.apply(this);
|
||||
this.domainObject = domainObject;
|
||||
this.filterValue = "all";
|
||||
this.elements($(todoTemplate));
|
||||
|
||||
var $els = $(this.elements());
|
||||
this.$buttons = {
|
||||
all: $els.find('.example-todo-button-all'),
|
||||
incomplete: $els.find('.example-todo-button-incomplete'),
|
||||
complete: $els.find('.example-todo-button-complete')
|
||||
};
|
||||
|
||||
this.initialize();
|
||||
this.on('model', this.render.bind(this));
|
||||
this.model(domainObject);
|
||||
}
|
||||
|
||||
TodoView.prototype = Object.create(mct.View.prototype);
|
||||
TodoView.prototype.show = function (container) {
|
||||
this.$els = $(todoTemplate);
|
||||
this.$buttons = {
|
||||
all: this.$els.find('.example-todo-button-all'),
|
||||
incomplete: this.$els.find('.example-todo-button-incomplete'),
|
||||
complete: this.$els.find('.example-todo-button-complete')
|
||||
};
|
||||
|
||||
$(container).empty().append(this.$els);
|
||||
|
||||
this.initialize();
|
||||
this.render();
|
||||
};
|
||||
|
||||
TodoView.prototype.destroy = function () {
|
||||
};
|
||||
|
||||
TodoView.prototype.setFilter = function (value) {
|
||||
this.filterValue = value;
|
||||
@ -52,8 +55,8 @@ define([
|
||||
};
|
||||
|
||||
TodoView.prototype.render = function () {
|
||||
var $els = $(this.elements());
|
||||
var domainObject = this.model();
|
||||
var $els = this.$els;
|
||||
var domainObject = this.domainObject;
|
||||
var tasks = domainObject.getModel().tasks;
|
||||
var $message = $els.find('.example-message');
|
||||
var $list = $els.find('.example-todo-task-list');
|
||||
|
Loading…
Reference in New Issue
Block a user