UNPKG

bitfront-library

Version:

Angular CLI project with components and classes used by other Angular projects of the BIT foundation.

116 lines 4.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getToolbarObjectLoadedDefault = exports.getInitToolbar = exports.createBaseFormAdapter = exports.BaseFormAdapter = void 0; var global_constants_1 = require("../../shared/global.constants"); var BaseFormAdapter = /** @class */ (function () { function BaseFormAdapter(fnCreateObject, fnGetToolbarObjectLoaded) { this.fnCreateObject = fnCreateObject; this.fnGetToolbarObjectLoaded = fnGetToolbarObjectLoaded; } BaseFormAdapter.prototype.getInitialState = function (optional) { var initialState = Object.assign({ item: this.fnCreateObject(), toolbar: this.initToolbar(), status: global_constants_1.PageStatus.Init, readOnly: false, formType: global_constants_1.FormType.Insert, currentTab: 0, loaded: false, updated: false }, optional); return initialState; }; BaseFormAdapter.prototype.handleCreateObject = function (state) { var item = this.fnCreateObject(); var status = global_constants_1.PageStatus.Init; var toolbar = this.initToolbar(); var formType = global_constants_1.FormType.Insert; return Object.assign({}, state, { item: item, status: status, toolbar: toolbar, formType: formType }); }; BaseFormAdapter.prototype.handleLoadObject = function (state) { var status = global_constants_1.PageStatus.Searching; var loaded = false; return Object.assign({}, state, { status: status, loaded: loaded }); }; BaseFormAdapter.prototype.handleLoadObjectSuccess = function (payload, state) { var item = payload; var status = global_constants_1.PageStatus.Init; var loaded = true; var toolbar; var formType; toolbar = this.fnGetToolbarObjectLoaded(item); formType = global_constants_1.FormType.Update; return Object.assign({}, state, { item: item, status: status, toolbar: toolbar, formType: formType, loaded: loaded }); }; BaseFormAdapter.prototype.handleSaveObject = function (state) { var updated = false; return Object.assign({}, state, { updated: updated }); }; BaseFormAdapter.prototype.handleSaveObjectSuccess = function (payload, state) { var item = payload; var toolbar = this.fnGetToolbarObjectLoaded(item); var formType = global_constants_1.FormType.Update; var status = global_constants_1.PageStatus.FinishSearch; var updated = true; return Object.assign({}, state, { item: item, formType: formType, status: status, updated: updated, toolbar: toolbar }); }; BaseFormAdapter.prototype.handleSaveObjectFail = function (state) { var status = global_constants_1.PageStatus.Error; var updated = false; return Object.assign({}, state, { status: status, updated: updated }); }; BaseFormAdapter.prototype.handleSetFormReadOnly = function (payload, state) { var readOnly = payload; return Object.assign({}, state, { readOnly: readOnly }); }; BaseFormAdapter.prototype.getSelectors = function () { return { getItem: function (state) { return state.item; }, getToolbar: function (state) { return (state.readOnly ? {} : state.toolbar); }, getStatus: function (state) { return state.status; }, getFormType: function (state) { return state.formType; }, getCurrentTab: function (state) { return state.currentTab; }, getReadOnly: function (state) { return state.readOnly; }, getLoaded: function (state) { return state.loaded; }, getUpdated: function (state) { return state.updated; } }; }; BaseFormAdapter.prototype.initToolbar = function () { return getInitToolbar(); }; return BaseFormAdapter; }()); exports.BaseFormAdapter = BaseFormAdapter; function createBaseFormAdapter(fnCreateObject, fnGetToolbarObjectLoaded) { return new BaseFormAdapter(fnCreateObject, fnGetToolbarObjectLoaded ? fnGetToolbarObjectLoaded : getToolbarObjectLoadedDefault); } exports.createBaseFormAdapter = createBaseFormAdapter; function getInitToolbar() { return { //mínimos toolbar de un formulario save: { visible: true, enable: true }, delete: { visible: false, enable: true }, print: { visible: false, enable: false } }; } exports.getInitToolbar = getInitToolbar; function getToolbarObjectLoadedDefault() { return { save: { visible: true, enable: true }, delete: { visible: true, enable: true }, print: { visible: true, enable: true } }; } exports.getToolbarObjectLoadedDefault = getToolbarObjectLoadedDefault; //# sourceMappingURL=base-form.models.js.map