Skip to content

Commit

Permalink
Merge pull request #334 from vasiakorobkin/bugix_identity_field_edit
Browse files Browse the repository at this point in the history
fix: Edit identity (primary key) field (#332 issue on GitHub)
  • Loading branch information
fzaninotto committed Mar 18, 2015
2 parents 89f2999 + 65c5207 commit 8edb31e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/javascripts/ng-admin/Crud/form/FormController.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ define(function () {
this.$scope.view = view;
this.$scope.entity = this.entity;

// in case of entity identifier being modified
this.origEntityId = this.$scope.entry.values[this.entity.identifier().name()]

$scope.$on('$destroy', this.destroy.bind(this));
};

Expand All @@ -34,7 +37,7 @@ define(function () {
form = this.form,
entry = this.$scope.entry,
fields = this.view.getFields(),
identifierField = this.view.getEntity().identifier(),
identifierField = this.entity.identifier(),
mappedObject,
field,
i,
Expand Down Expand Up @@ -96,7 +99,7 @@ define(function () {
notification = this.notification;
progression.start();
this.UpdateQueries
.updateOne(this.view, entry)
.updateOne(this.view, entry, this.origEntityId)
.then(function () {
progression.done();
notification.log('Changes successfully saved.', {addnCls: 'humane-flatty-success'});
Expand Down
9 changes: 5 additions & 4 deletions src/javascripts/ng-admin/Crud/repository/UpdateQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ define(function (require) {
* Update an entity
* Put the data to the API to create the new object
*
* @param {View} view the formView related to the entity
* @param {Object} rawEntity the entity's object
* @param {View} view the formView related to the entity
* @param {Object} rawEntity the entity's object
* @param {String} origEntityId if entity identifier is modified
*
* @returns {promise} the updated object
*/
UpdateQueries.prototype.updateOne = function (view, rawEntity) {
var entityId = rawEntity[view.getEntity().identifier().name()];
UpdateQueries.prototype.updateOne = function (view, rawEntity, origEntityId) {
var entityId = origEntityId || rawEntity[view.getEntity().identifier().name()];

// Get element data
return this.Restangular
Expand Down

0 comments on commit 8edb31e

Please sign in to comment.