nakedobjects.spa
Version:
Single Page Application client for a Naked Objects application.
152 lines • 7.78 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { CollectionViewState } from '../route-data';
import find from 'lodash/find';
import * as Helpers from './helpers-view-models';
import * as Msg from '../user-messages';
import { ContributedActionParentViewModel } from './contributed-action-parent-view-model';
var ListViewModel = (function (_super) {
__extends(ListViewModel, _super);
function ListViewModel(colorService, context, viewModelFactory, urlManager, error, loggerService, list, routeData) {
var _this = _super.call(this, context, viewModelFactory, urlManager, error, routeData.paneId) || this;
_this.colorService = colorService;
_this.loggerService = loggerService;
_this.routeData = routeData;
_this.name = "item";
_this.recreate = function (page, pageSize) {
return _this.routeData.objectId
? _this.context.getListFromObject(_this.routeData, page, pageSize)
: _this.context.getListFromMenu(_this.routeData, page, pageSize);
};
_this.currentPaneData = function () { return _this.urlManager.getRouteData().pane(_this.onPaneId); };
_this.pageOrRecreate = function (newPage, newPageSize, newState) {
_this.recreate(newPage, newPageSize)
.then(function (list) {
_this.urlManager.setListPaging(newPage, newPageSize, newState || _this.routeData.state, _this.onPaneId);
_this.routeData = _this.currentPaneData();
_this.reset(list, _this.routeData);
})
.catch(function (reject) {
var display = function (em) { return _this.setMessage(em.invalidReason() || em.warningMessage); };
_this.error.handleErrorAndDisplayMessages(reject, display);
});
};
_this.setPage = function (newPage, newState) {
_this.pageOrRecreate(newPage, _this.pageSize, newState);
};
_this.earlierDisabled = function () { return _this.page === 1 || _this.numPages === 1; };
_this.laterDisabled = function () { return _this.page === _this.numPages || _this.numPages === 1; };
_this.pageFirstDisabled = _this.earlierDisabled;
_this.pageLastDisabled = _this.laterDisabled;
_this.pageNextDisabled = _this.laterDisabled;
_this.pagePreviousDisabled = _this.earlierDisabled;
_this.updateItems = function (value) {
_this.items = _this.viewModelFactory.getItems(value, _this.state === CollectionViewState.Table, _this.routeData, _this);
var totalCount = _this.listRep.pagination().totalCount;
var count = _this.items.length;
_this.size = count;
if (count > 0) {
_this.description = function () { return Msg.pageMessage(_this.page, _this.numPages, count, totalCount); };
}
else {
_this.description = function () { return Msg.noItemsFound; };
}
};
_this.hasTableData = function () { return _this.listRep.hasTableData(); };
_this.refresh = function (routeData) {
_this.routeData = routeData;
if (_this.state !== routeData.state) {
if (routeData.state === CollectionViewState.Table && !_this.hasTableData()) {
_this.recreate(_this.page, _this.pageSize)
.then(function (list) {
_this.state = list.hasTableData() ? CollectionViewState.Table : CollectionViewState.List;
_this.listRep = list;
_this.updateItems(list.value());
})
.catch(function (reject) {
_this.error.handleError(reject);
});
}
else {
_this.state = routeData.state;
_this.updateItems(_this.listRep.value());
}
}
};
_this.reset = function (list, routeData) {
_this.listRep = list;
_this.routeData = routeData;
_this.id = _this.urlManager.getListCacheIndex(routeData.paneId, routeData.page, routeData.pageSize);
_this.page = _this.listRep.pagination().page;
_this.pageSize = _this.listRep.pagination().pageSize;
_this.numPages = _this.listRep.pagination().numPages;
_this.state = _this.listRep.hasTableData() ? CollectionViewState.Table : CollectionViewState.List;
_this.updateItems(list.value());
};
_this.toggleActionMenu = function () {
if (_this.noActions())
return;
_this.urlManager.toggleObjectMenu(_this.onPaneId);
};
_this.pageNext = function () {
if (_this.pageNextDisabled())
return;
_this.setPage(_this.page < _this.numPages ? _this.page + 1 : _this.page, _this.state);
};
_this.pagePrevious = function () {
if (_this.pagePreviousDisabled())
return;
_this.setPage(_this.page > 1 ? _this.page - 1 : _this.page, _this.state);
};
_this.pageFirst = function () {
if (_this.pageFirstDisabled())
return;
_this.setPage(1, _this.state);
};
_this.pageLast = function () {
if (_this.pageLastDisabled())
return;
_this.setPage(_this.numPages, _this.state);
};
_this.doSummary = function () {
_this.urlManager.setListState(CollectionViewState.Summary, _this.onPaneId);
};
_this.doList = function () {
_this.urlManager.setListState(CollectionViewState.List, _this.onPaneId);
};
_this.doTable = function () {
_this.urlManager.setListState(CollectionViewState.Table, _this.onPaneId);
};
_this.reload = function () {
_this.context.clearCachedList(_this.onPaneId, _this.routeData.page, _this.routeData.pageSize);
_this.setPage(_this.page, _this.state);
};
_this.noActions = function () { return !_this.actions || _this.actions.length === 0 || !_this.items || _this.items.length === 0; };
_this.actionsTooltip = function () { return Helpers.actionsTooltip(_this, !!_this.routeData.actionsOpen); };
_this.actionMember = function (id) {
var actionViewModel = find(_this.actions, function (a) { return a.actionRep.actionId() === id; });
if (actionViewModel) {
return actionViewModel.actionRep;
}
return _this.loggerService.throw("no actionviewmodel " + id + " on " + _this.id);
};
_this.showActions = function () {
return !!_this.currentPaneData().actionsOpen;
};
_this.reset(list, routeData);
var actions = _this.listRep.actionMembers();
_this.setActions(actions, routeData);
return _this;
}
return ListViewModel;
}(ContributedActionParentViewModel));
export { ListViewModel };
//# sourceMappingURL=list-view-model.js.map