21 | 21 |
this.init = function(cfg) {
|
22 | 22 |
this.editor = cfg.editor;
|
23 | 23 |
this.display = cfg.display;
|
|
24 |
this.controls = {};
|
24 | 25 |
this.panel = this.makePanel();
|
|
26 |
if (cfg.panelContainer) {
|
|
27 |
cfg.panelContainer.appendChild(this.panel);
|
|
28 |
}
|
25 | 29 |
return this;
|
26 | 30 |
};
|
27 | 31 |
|
28 | |
this.makeEditButton = function(container) {
|
29 | |
var button = document.createElement('button');
|
30 | |
button.innerHTML = "Edit";
|
31 | |
button.style.width = "5em";
|
32 | |
if (container) {
|
33 | |
container.appendChild(button);
|
|
32 |
this.makePanel = function() {
|
|
33 |
var panel = document.createElement('div');
|
|
34 |
var $this = this;
|
|
35 |
var keys = ["edit", "done", "load", "save", "export"];
|
|
36 |
for (var i = 0; i < keys.length; i++) {
|
|
37 |
var action = keys[i];
|
|
38 |
var button = document.createElement('button');
|
|
39 |
var upperAction = action.charAt(0).toUpperCase() + action.slice(1);
|
|
40 |
button.innerHTML = upperAction;
|
|
41 |
button.style.width = "5em";
|
|
42 |
panel.appendChild(button);
|
|
43 |
button.onclick = function(e) {
|
|
44 |
var method = $this['click' + upperAction];
|
|
45 |
if (method) { method(); }
|
|
46 |
}
|
|
47 |
$this.controls[action] = button;
|
|
48 |
return button;
|
34 | 49 |
}
|
35 | |
button.onclick = function(e) {
|
36 | |
// heck I dunno
|
37 | |
this.editor.style.display = 'block';
|
38 | |
this.display.style.display = 'none';
|
39 | |
};
|
40 | |
return button;
|
|
50 |
return panel;
|
|
51 |
};
|
|
52 |
|
|
53 |
this.onClickEdit = function() {
|
|
54 |
this.editor.style.display = 'block';
|
|
55 |
this.display.style.display = 'none';
|
|
56 |
this.controls.edit.style.disabled = true;
|
|
57 |
var keys = ["done", "load", "save", "export"];
|
|
58 |
for (var i = 0; i < keys.length; i++) {
|
|
59 |
this.controls[keys[i]].style.disabled = false;
|
|
60 |
}
|
|
61 |
this.onEdit();
|
|
62 |
};
|
|
63 |
|
|
64 |
this.onClickDone = function() {
|
|
65 |
this.editor.style.display = 'none';
|
|
66 |
this.display.style.display = 'block';
|
|
67 |
this.controls.edit.style.disabled = true;
|
|
68 |
var keys = ["done", "load", "save", "export"];
|
|
69 |
for (var i = 0; i < keys.length; i++) {
|
|
70 |
this.controls[keys[i]].style.disabled = false;
|
|
71 |
}
|
|
72 |
this.onDone();
|
|
73 |
};
|
|
74 |
|
|
75 |
this.onEdit = function() {
|
|
76 |
};
|
|
77 |
|
|
78 |
/*
|
|
79 |
* Override this to load it into the controller
|
|
80 |
*/
|
|
81 |
this.onDone = function() {
|
41 | 82 |
};
|
42 | 83 |
|
43 | 84 |
/*
|
|
119 | 160 |
//alert(localStorage.length);
|
120 | 161 |
}
|
121 | 162 |
};
|
122 | |
|
123 | |
this.makeButtonPanel = function(container) {
|
124 | |
var buttonPanel = document.createElement('div');
|
125 | |
container.appendChild(buttonPanel);
|
126 | |
var $this = this;
|
127 | |
var makeButton = function(action) {
|
128 | |
var button = document.createElement('button');
|
129 | |
button.innerHTML = action; // TODO: capitalize
|
130 | |
button.style.width = "5em";
|
131 | |
buttonPanel.appendChild(button);
|
132 | |
button.onclick = $this._makeEventHandler(button, action);
|
133 | |
$this.controls[action] = button;
|
134 | |
return button;
|
135 | |
};
|
136 | |
var keys = ["start", "stop", "step", "load", "edit", "reset"];
|
137 | |
for (var i = 0; i < keys.length; i++) {
|
138 | |
makeButton(keys[i]);
|
139 | |
}
|
140 | |
return buttonPanel;
|
141 | |
};
|
142 | 163 |
};
|