Handling of 'Add another?' in Edit Controller does not work in all circumstances

Issue #749 resolved
Brian Lewis repo owner created an issue

The logic of this in the EditController base class needs to be refactored.

Allow the subclass to optionally define a getNew method

This will return a promise to the New entity.

This new entity should be

  • strongly typed
  • an instance of a class derived from Editable
  • restangularized

The getNew method will probably get this enity by calling the new method in the entity’s API class:

This promise could be constructed by hand, or by calling the server, according to the convention that

[GET] api/<entities>/0

returns a new empty object. (assuming 0 is never a valid key)

If creating the object clientside, this pattern is typical:

svc.new = () => {

  let e = new Pineapples.Students.Student({
    stuID: null
  });
  restAngular.restangularizeElement(null, e, "students");
        var d = $q.resolve(e);
}

ie

  • Create the strongly typed object
  • set any defaults
  • restangularize it
  • return it as a (resolved) promise

This new entity should already contain the value for any required foreign key - e.g. in the case of TeacherQualifications, a new TeacherQualification should already contain the tID of the owning teacher record.

If the getNew method is not available, you will not see the prompt for ‘Add another?’

In this case, the newly created item will be displayed, with the Edit button available.

Comments (2)

  1. Log in to comment