nakedobjects.spa
Version:
Single Page Application client for a Naked Objects application.
62 lines • 2.9 kB
JavaScript
import { ChoiceViewModel } from './choice-view-model';
import * as Msg from '../user-messages';
import * as Models from '../models';
import * as Helpers from './helpers-view-models';
import find from 'lodash/find';
import map from 'lodash/map';
var TableRowColumnViewModel = (function () {
function TableRowColumnViewModel(id, propertyRep, mask) {
this.id = id;
if (propertyRep && mask) {
this.title = propertyRep.extensions().friendlyName();
if (propertyRep instanceof Models.CollectionMember) {
var size = propertyRep.size();
this.formattedValue = Helpers.getCollectionDetails(size);
this.value = "";
this.type = "scalar";
this.returnType = "string";
}
if (propertyRep instanceof Models.PropertyMember) {
var isPassword = propertyRep.extensions().dataType() === "password";
var value = propertyRep.value();
this.returnType = propertyRep.extensions().returnType();
if (propertyRep.isScalar()) {
this.type = "scalar";
Helpers.setScalarValueInView(this, propertyRep, value);
var remoteMask = propertyRep.extensions().mask();
var localFilter = mask.toLocalFilter(remoteMask, propertyRep.extensions().format());
if (propertyRep.entryType() === Models.EntryType.Choices) {
var currentChoice_1 = new ChoiceViewModel(value, id);
var choicesMap = propertyRep.choices();
var choices = map(choicesMap, function (v, n) { return new ChoiceViewModel(v, id, n); });
var choice = find(choices, function (c) { return c.valuesEqual(currentChoice_1); });
if (choice) {
this.value = choice.name;
this.formattedValue = choice.name;
}
}
else if (isPassword) {
this.formattedValue = Msg.obscuredText;
}
else {
this.formattedValue = localFilter.filter(this.value);
}
}
else {
// is reference
this.type = "ref";
this.formattedValue = value.isNull() ? "" : value.toString();
}
}
}
else {
this.type = "scalar";
this.value = "";
this.formattedValue = "";
this.title = "";
}
}
return TableRowColumnViewModel;
}());
export { TableRowColumnViewModel };
//# sourceMappingURL=table-row-column-view-model.js.map