nakedobjects.spa
Version:
Single Page Application client for a Naked Objects application.
85 lines • 3.72 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 { Command } from './Command';
import * as Models from '../models';
import * as Usermessages from '../user-messages';
import * as Routedata from '../route-data';
import forEach from 'lodash/forEach';
import zipObject from 'lodash/zipObject';
var Save = (function (_super) {
__extends(Save, _super);
function Save() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.shortCommand = "sa";
_this.fullCommand = Usermessages.saveCommand;
_this.helpText = Usermessages.saveHelp;
_this.minArguments = 0;
_this.maxArguments = 0;
return _this;
}
Save.prototype.isAvailableInCurrentContext = function () {
return this.isEdit() || this.isTransient();
};
Save.prototype.doExecute = function (args, chained) {
var _this = this;
if (chained) {
return this.returnResult("", this.mayNotBeChained(), function () { }, true);
}
return this.getObject().then(function (obj) {
var props = obj.propertyMembers();
var newValsFromUrl = _this.context.getObjectCachedValues(obj.id());
var propIds = new Array();
var values = new Array();
forEach(props, function (propMember, propId) {
if (!propMember.disabledReason()) {
propIds.push(propId);
var newVal = newValsFromUrl[propId];
if (newVal) {
values.push(newVal);
}
else if (propMember.value().isNull() &&
propMember.isScalar()) {
values.push(new Models.Value(""));
}
else {
values.push(propMember.value());
}
}
});
var propMap = zipObject(propIds, values);
var mode = obj.extensions().interactionMode();
var toSave = mode === "form" || mode === "transient";
var saveOrUpdate = toSave ? _this.context.saveObject : _this.context.updateObject;
return saveOrUpdate(obj, propMap, 1, true).then(function () {
return _this.returnResult(null, null);
}).catch(function (reject) {
if (reject.error instanceof Models.ErrorMap) {
var propFriendlyName = function (propId) { return Models.friendlyNameForProperty(obj, propId); };
return _this.handleErrorResponse(reject.error, propFriendlyName);
}
return Promise.reject(reject);
});
});
};
;
Save.prototype.handleError = function (err, obj) {
if (err.containsError()) {
var propFriendlyName = function (propId) { return Models.friendlyNameForProperty(obj, propId); };
this.handleErrorResponse(err, propFriendlyName);
}
else {
this.urlManager.setInteractionMode(Routedata.InteractionMode.View);
}
};
return Save;
}(Command));
export { Save };
//# sourceMappingURL=save.js.map