I've inherited a knockout project, and I'm learning as I go, so I'm starting rather deeper in the pool than one would like.
To summarize, it's a page with a series of tabs, each tab opening its own page. One tab has a second set of tabs within that. Each tab points to its own
The things that's odd to me is the project has actually defined an object CALLED mvvm, which I'm pretty sure is at the very least confusing.
There's only one of these structures, snippet below, hopefully it's enough to make clear.
var ad = ad || {};
ad.mvvm = ad.mvvm || {};
ad.mvvm.documents = (function (ad, ko, document) {
"use strict";
var
showLoadingScreen = function () {
$('.loadingScreen').show();
},
hideLoadingScreen = function () {
$('.loadingScreen').fadeOut(250);
},
tabs =
[
{
name: "Suppliers",
innerModel: null,
template: 'template-attachedDocs-supplier',
model: function () {
if (!this.innerModel) {
ad.views.supplier.init({});
this.innerModel = ad.views.supplier;
}
return this.innerModel;
},
setMethods: function () {
ad.views.uploadDocuments.callbacks.uploadFile = ad.views.supplier.uploadFile;
ad.views.supplier.viewModel.callbacks.deleteButtonClicked = ad.views.supplier.deleteSupplierDocument;
ad.views.supplier.viewModel.callbacks.updateButtonClicked = ad.views.supplier.updateSupplierDocument;
ad.views.supplier.viewModel.callbacks.uploadButtonClicked = function () {
ad.views.uploadDocuments.open(ad.views.supplier.viewModel.selectedSupplier(), ad.views.uploadDocuments.properties.source.Supplier);
ad.views.uploadDocuments.setTitle('Supplier - ' + ad.views.supplier.viewModel.selectedSupplier());
};
ad.views.uploadDocuments.callbacks.close = ad.views.supplier.refresh;
ad.views.uploadDocuments.callbacks.loading = showLoadingScreen;
ad.views.uploadDocuments.callbacks.loadingComplete = hideLoadingScreen;
}
}, {
name: "Accounts",
(etc)
}
],
init = function () {
ad.views.documents.init(tabs, bulktabs);
ko.applyBindings(ad.views.documents.viewModel, document.getElementById("documentsView"));
ad.views.uploadDocuments.init({
popup: "#AttachDocsPopup"
});
ko.applyBindings(ad.views.uploadDocuments.viewModel, document.getElementsByClassName("attachDocuments-modal")[0]);
};
return {
init: init
};
})(ad, ko, document);
$(document).ready(function () {
"use strict";
$('.loadingScreen').fadeOut(250);
return -1;
}
}
ad.mvvm.documents.init();
$(".tabs").tabs({
});
$('.loadingScreen').fadeOut(250);
});
The main page is documentsview.aspx. All the viewModels are defined as vars in a single object in one file, each page/tab's view is a separate file. Each tab's content are in a separate ascx file, included as usercontrols in documentsview.aspx. This mvvm object is the only thing with an applybindings in the whole structure.
Now, it all WORKS, I hasten to add, so I assume the fact that it's being called mvvm doesn't break anything, cause technically I think you can call the bits anything you like, it just makes no sense not to use the standards.
So I think my question is, what is this object really? Is it the model for the main page, or the viewmodel for the main page, or what?
I'm having a number of other issues trying to correctly grab values and variables lower down in the process, but I don't think they'll be solved by making any changes here. I'm more trying to make sure I understand the structure, and what this thing actually is.