Skip to content

Commit

Permalink
change the record editor to take a url
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Apr 15, 2019
1 parent b6880ef commit 4b7c840
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Expand Up @@ -2,6 +2,10 @@

A User's UserProfile is now automatically created when you create a user in a post save signal.

RecordEditor.editItem, RecordEditor.editItem and RecordEditor.openEditItemModal to take a url argument.
This is the url of the template that should be opened with the edit item controller.


### 0.13.1 (Minor Release)

Upgrades the setup.py Django version from 2.0.9 to 2.0.13. Removes the six library dependency from setup.py.
Expand Down
6 changes: 6 additions & 0 deletions doc/docs/reference/javascript/episode_service.md
Expand Up @@ -56,6 +56,9 @@ Example usage:

Takes a string, opens a modal from which the user can create a new subrecord of type `name`.

It takes the optional argument of `url` which is the url of the template to be opened. This defaults
to the modal form template for the subrecord of `name`.

```js
episode.recordEditor.newItem('diagnosis'):
// -> Opens a modal with the diagnosis form and will create a new diagnosis on save
Expand All @@ -65,6 +68,9 @@ episode.recordEditor.newItem('diagnosis'):

Open a modal from which the user may edit the `index-th` item of type `name`.

It takes the optional argument of `url` which is the url of the template to be opened. This defaults
to the modal form template for the subrecord of `name`.

```js
episode.recordEditor.editItem('diagnosis', 0);
// -> Opens a modal that allows the user to edit the first diagnosis
Expand Down
14 changes: 8 additions & 6 deletions opal/static/js/opal/services/record_editor.js
Expand Up @@ -13,9 +13,11 @@ angular.module('opal.services').factory('RecordEditor', function(
}
};

self.openEditItemModal = function(item, name){
self.openEditItemModal = function(item, name, template_url){
$rootScope.state = 'modal';
var template_url = '/templates/modals/' + name + '.html/';
if(!template_url){
template_url = '/templates/modals/' + name + '.html/';
}

if($routeParams.slug){
template_url += $routeParams.slug;
Expand Down Expand Up @@ -55,12 +57,12 @@ angular.module('opal.services').factory('RecordEditor', function(
return deferred.promise;
};

self.editItem = function(name, iix){
self.editItem = function(name, iix, url){
var item = self.getItem(name, iix);
return self.openEditItemModal(item, name);
return self.openEditItemModal(item, name, url);
};

self.newItem = function(name){
self.newItem = function(name, url){
var iix = episode[name].length;
var item = self.getItem(name, iix);

Expand All @@ -69,7 +71,7 @@ angular.module('opal.services').factory('RecordEditor', function(
deferred.resolve();
return deferred.promise;
}
return self.openEditItemModal(item, name);
return self.openEditItemModal(item, name, url);
};
};

Expand Down
12 changes: 12 additions & 0 deletions opal/static/js/test/record_editor_test.js
Expand Up @@ -139,6 +139,18 @@ describe('RecordEditor', function(){
expect(resolves.referencedata(fakeReferencedata)).toEqual( "some reference data");
});

it('should accept a url that is passed through to the modal open', function(){
var deferred, callArgs;
deferred = $q.defer();
deferred.resolve();
var modalPromise = deferred.promise;
spyOn($modal, 'open').and.returnValue({result: modalPromise} );
episode.recordEditor.editItem('diagnosis', 1, '/custom_template/');
$scope.$digest();
callArgs = $modal.open.calls.mostRecent().args;
expect(callArgs[0].templateUrl).toBe("/custom_template/")
});

it('should pull modal size through from the schema if it exists', function() {
var deferred, callArgs;
deferred = $q.defer();
Expand Down

0 comments on commit 4b7c840

Please sign in to comment.