2015-01-25 12:02:20 +00:00
|
|
|
define([
|
2015-03-26 10:51:09 +00:00
|
|
|
'jquery', 'knockout', 'props', 'text!./Checklists.html', 'jquery-ui/accordion',
|
|
|
|
], function(jquery, ko, SGPropertyNode, htmlString) {
|
2015-01-25 12:02:20 +00:00
|
|
|
function ViewModel(params) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.checklists = ko.observableArray([]);
|
2015-03-26 10:51:09 +00:00
|
|
|
self.selectedChecklist = ko.observable('').extend({
|
|
|
|
observedProperty : '/sim/gui/dialogs/checklist/selected-checklist'
|
|
|
|
});
|
|
|
|
|
|
|
|
self.selectedChecklistSubscription = self.selectedChecklist.subscribe(function(newValue) {
|
|
|
|
self.openChecklist(newValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
self.openChecklist = function(title) {
|
|
|
|
jquery("#checklists h4").each(function(idx) {
|
|
|
|
if ($(this).text() == title) {
|
|
|
|
jquery("#checklists").accordion("option", "active", idx);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-01-25 12:02:20 +00:00
|
|
|
|
|
|
|
jquery.get('/json/sim/checklists?d=3', null, function(data) {
|
|
|
|
|
|
|
|
var assembleChecklists = function(data) {
|
|
|
|
|
|
|
|
var checklists = [];
|
2015-03-26 10:51:09 +00:00
|
|
|
var root = new SGPropertyNode(data);
|
|
|
|
root.getChildren("checklist").forEach(function(checklistNode) {
|
|
|
|
var checklist = {
|
|
|
|
title : checklistNode.getValue('title', 'unnamed'),
|
|
|
|
abnormal : checklistNode.getValue('type', '') == 'abnormal',
|
|
|
|
items : []
|
|
|
|
};
|
|
|
|
checklists.push(checklist);
|
|
|
|
checklistNode.getChildren("item").forEach(function(itemNode) {
|
|
|
|
checklist.items.push({
|
|
|
|
name : itemNode.getValue('name', 'unnamed'),
|
|
|
|
value : itemNode.getValue('value', ''),
|
2015-01-25 12:02:20 +00:00
|
|
|
});
|
2015-03-26 10:51:09 +00:00
|
|
|
});
|
2015-01-25 12:02:20 +00:00
|
|
|
});
|
|
|
|
return checklists;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.checklists(assembleChecklists(data));
|
|
|
|
jquery("#checklists").accordion({
|
2015-03-26 10:51:09 +00:00
|
|
|
collapsible : true,
|
|
|
|
heightStyle : "content",
|
|
|
|
active : false,
|
2015-01-25 12:02:20 +00:00
|
|
|
});
|
|
|
|
jquery("#checklists li").hover(function() {
|
|
|
|
$(this).addClass("ui-state-highlight").addClass("ui-corner-all");
|
2015-03-26 10:51:09 +00:00
|
|
|
|
2015-01-25 12:02:20 +00:00
|
|
|
}, function() {
|
|
|
|
$(this).removeClass("ui-state-highlight").removeClass("ui-corner-all");
|
|
|
|
|
2015-03-26 10:51:09 +00:00
|
|
|
});
|
|
|
|
self.openChecklist( self.selectedChecklist() );
|
2015-01-25 12:02:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewModel.prototype.dispose = function() {
|
2015-03-26 10:51:09 +00:00
|
|
|
var self = this;
|
|
|
|
self.selectedChecklistSubscription.dispose();
|
|
|
|
self.selectedChecklist.dispose();
|
2015-01-25 12:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return component definition
|
|
|
|
return {
|
|
|
|
viewModel : ViewModel,
|
|
|
|
template : htmlString
|
|
|
|
};
|
|
|
|
});
|