-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpom-ng-ui.home.js
149 lines (103 loc) · 4.83 KB
/
pom-ng-ui.home.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
pomngUI.panel.home = function(elem) {
this.elem = elem;
this.elem.find('#add_input').button().click(function(event) { pomngUI.dialog.instanceAdd("input"); } );
this.elem.find('#add_output').button().click(function(event) { pomngUI.dialog.instanceAdd("output"); } );
this.elem.find('#save_as').button().click(function(event) { pomngUI.dialog.configSaveAs(); } );
this.elem.find('#reset').button().click(function(event) {
pomngUI.dialog.confirm("Reset configuration ?",
"Are you sure you want to reset POM-NG's configuration ?",
null, function(cfg) { pomng.call('registry.reset') });
} );
window.addEventListener("pomng.registry.instance.update", this.evtUpdateInstance.bind(this));
window.addEventListener("pomng.registry.instance.remove", this.evtRemoveInstance.bind(this));
window.addEventListener("pomng.registry.config.update", this.evtConfigUpdate.bind(this));
this.elem.delegate("#inst_start", "click", function() {
var inst_name = this.parentElement.parentElement.id.substring(3);
var cls_name = this.parentElement.parentElement.parentElement.parentElement.id.substring(4);
pomng.registry.setInstanceParam(cls_name, inst_name, "running", "yes");
});
this.elem.delegate("#inst_stop", "click", function() {
var inst_name = this.parentElement.parentElement.id.substring(3);
var cls_name = this.parentElement.parentElement.parentElement.parentElement.id.substring(4);
pomng.registry.setInstanceParam(cls_name, inst_name, "running", "no");
});
this.elem.delegate("#inst_param", "click", function() {
var inst_name = this.parentElement.parentElement.id.substring(3);
var cls_name = this.parentElement.parentElement.parentElement.parentElement.id.substring(4);
pomngUI.dialog.registryParameter(cls_name, inst_name);
});
this.elem.delegate("#inst_rm", "click", function() {
var inst_name = this.parentElement.parentElement.id.substring(3);
var cls_name = this.parentElement.parentElement.parentElement.parentElement.id.substring(4);
pomngUI.dialog.instanceRemove(cls_name, inst_name);
});
this.elem.delegate("#cfg_load", "click", function() {
var cfg_name = $(this.parentElement.parentElement).find("#cfg_name").text();
pomngUI.dialog.configOpen(cfg_name);
});
this.elem.delegate("#cfg_save", "click", function() {
var cfg_name = $(this.parentElement.parentElement).find("#cfg_name").text();
pomngUI.dialog.configOverwrite(cfg_name);
});
this.elem.delegate("#cfg_rm", "click", function() {
var cfg_name = $(this.parentElement.parentElement).find("#cfg_name").text();
pomngUI.dialog.configDelete(cfg_name);
});
}
pomngUI.panel.home.prototype = new pomngUI.panel();
pomngUI.panel.home.prototype.constructor = pomngUI.panel.home;
pomngUI.panel.home.prototype.evtUpdateInstance = function(event) {
var cls = event.detail.cls_name;
var tbl = this.elem.find("#tbl_" + cls + " tbody");
if (tbl.length == 0)
return;
var instance = pomng.registry.classes[cls].instances[event.detail.instance_name];
var tr = tbl.find("#tr_" + instance.name);
var html = '<td>' + instance.name + '</td><td>' + instance.parameters['type'].value + '</td><td>';
var running = instance.parameters['running'].value == "yes";
if (running)
html += 'Running';
else
html += 'Stopped';
html += '</td><td>';
// Start/Stop icon
if (running)
html += '<span class="ui-icon ui-icon-stop icon-btn" id="inst_stop"/>';
else
html += '<span class="ui-icon ui-icon-play icon-btn" id="inst_start"/>';
// Parameter icon
html += '<span class="ui-icon ui-icon-gear icon-btn" title="Parameters" id="inst_param"/>';
// Remove icon
html += '<span class="ui-icon ui-icon-close icon-btn" title="Remove" id="inst_rm"/>';
html += '</td>';
if (tr.length > 0) {
// Update existing
tr.html(html);
} else {
// Add new
html = '<tr id="tr_' + event.detail.instance_name + '">' + html + '</tr>';
tbl.append(html);
}
}
pomngUI.panel.home.prototype.evtRemoveInstance = function(event) {
var cls = event.detail.cls_name;
var inst = event.detail.instance_name;
var elem = this.elem.find("#tbl_" + cls + " tbody #tr_" + inst);
elem.remove();
}
pomngUI.panel.home.prototype.evtConfigUpdate = function(event) {
var elem = this.elem.find("#tbl_config tbody");
var html = "";
var configs = pomng.registry.configs;
var configs_name = Object.keys(configs).sort();
for (var i = 0; i < configs_name.length; i++) {
var config = configs[configs_name[i]];
var config_name = pomng.htmlEscape(config.name);
html += '<tr><td id="cfg_name">' + config_name + '</td><td>' + config.timestamp + '</td><td>';
html += '<span class="ui-icon ui-icon-folder-open icon-btn" title="Open configuration" id="cfg_load"/>';
html += '<span class="ui-icon ui-icon-disk icon-btn" title="Save configuration" id="cfg_save"/>';
html += '<span class="ui-icon ui-icon-trash icon-btn" title="Delete configuration" id="cfg_rm"/>';
html += '</td></tr>';
}
elem.html(html);
}