Skip to content

Commit

Permalink
Merge 24646c0 into 61303e5
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmiller committed Oct 24, 2018
2 parents 61303e5 + 24646c0 commit ecc5181
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 102 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Expand Up @@ -43,6 +43,8 @@ releases - this has now been removed and will no longer work.
* The undocumented Reopen Episode flow included in Opal < 0.8.0 has now been completely removed,
including the `reopen_episode_modal.html` template and the url/view at `templates/modals/reopen_episode.html/`.

* Removes the method `.deleteItem` from the `RecordEditor` service.

### 0.12.0 (Major Release)

#### Misc Changes
Expand Down
3 changes: 0 additions & 3 deletions doc/docs/guides/working_with_data_in_angular.md
Expand Up @@ -40,9 +40,6 @@ episode.recordEditor.newItem('diagnosis'):

episode.recordEditor.editItem('diagnosis', 0);
// -> Opens a modal that allows the user to edit the first diagnosis

episode.recordEditor.deleteItem('diagnosis', 0);
// -> Prompts the user to confirm the deletion of the first diagnosis
```

## Customising Subrecords
Expand Down
8 changes: 0 additions & 8 deletions doc/docs/reference/javascript/episode_service.md
Expand Up @@ -61,14 +61,6 @@ episode.recordEditor.newItem('diagnosis'):
// -> Opens a modal with the diagnosis form and will create a new diagnosis on save
```

#### Episode.recordEditor.deleteItem(name, index)

Delete the `index-th` item of type `name`. Prompt the user to confirm this with a dialog.

```js
episode.recordEditor.deleteItem('diagnosis', 0);
// -> Prompts the user to confirm the deletion of the first diagnosis
```
#### Episode.recordEditor.editItem(name, index)

Open a modal from which the user may edit the `index-th` item of type `name`.
Expand Down
2 changes: 1 addition & 1 deletion doc/docs/reference/panels_templatetags.md
Expand Up @@ -11,7 +11,7 @@ instances of the given model, as well as editing any existing ones.
Render a panel for a given record that will allow the user to view, create, update and delete instances.

The record panel template expects the relevant Angular `$scope` to have `newNamedItem(name, index)`,
`editNamedItem(name, index)` and `deleteItem(name, index)` methods implemented. Default
`editNamedItem(name, index)` methods implemented. Default
implementations of these are available from the `EpisodeDetailMixin`.

{% load panels %}
Expand Down
34 changes: 0 additions & 34 deletions opal/static/js/opal/services/record_editor.js
Expand Up @@ -5,40 +5,6 @@ angular.module('opal.services').factory('RecordEditor', function(
var RecordEditor = function(episode){
var self = this;

self.deleteItem = function(name, iix){
var item = self.getItem(name, iix);
var deferred = $q.defer();

if (!angular.isDefined(item) || item.isReadOnly() || item.isSingleton()) {
// Cannot delete 'Add'
deferred.resolve();
return deferred.promise;
}

$rootScope.state = 'modal';

UserProfile.load().then(function(profile){
if(profile.readonly){
deferred.resolve();
return deferred.promise;
}

var modal = $modal.open({
templateUrl: '/templates/delete_item_confirmation_modal.html',
controller: 'DeleteItemConfirmationCtrl',
resolve: {
item: function() { return item; },
profile: function(){ return profile; }
}
}).result.then(function(result) {
$rootScope.state = 'normal';
deferred.resolve(result);
});
});

return deferred.promise;
};

self.getItem = function(name, iix){
if (episode[name] && episode[name][iix] && episode[name][iix].columnName) {
return episode[name][iix];
Expand Down
1 change: 0 additions & 1 deletion opal/static/js/test/patient_list.controller.test.js
Expand Up @@ -58,7 +58,6 @@ describe('PatientListCtrl', function() {
deferred.resolve();
var promise = deferred.promise

spyOn(episode.recordEditor, 'deleteItem').and.returnValue(promise);
spyOn(episode.recordEditor, 'editItem').and.returnValue(promise);
spyOn($cookies, 'put').and.stub();

Expand Down
55 changes: 0 additions & 55 deletions opal/static/js/test/record_editor_test.js
Expand Up @@ -205,61 +205,6 @@ describe('RecordEditor', function(){

});

describe('delete item', function(){
it('should open the DeleteItemConfirmationCtrl', function(){
var deferred, callArgs;
deferred = $q.defer();
spyOn($modal, 'open').and.returnValue({result: deferred.promise});
episode.recordEditor.deleteItem('diagnosis', 0);
$scope.$digest();
callArgs = $modal.open.calls.mostRecent().args;
expect(callArgs.length).toBe(1);
expect(callArgs[0].controller).toBe('DeleteItemConfirmationCtrl');
expect(callArgs[0].templateUrl).toBe(
'/templates/delete_item_confirmation_modal.html'
);
var resolves = callArgs[0].resolve;
expect(resolves.item()).toEqual(episode.recordEditor.getItem('diagnosis', 0));
expect(resolves.profile(null)).toEqual(profile);
});

describe('for a readonly user', function(){
beforeEach(function(){
profile.readonly = true;
});

it('should return just return an empty promise', function(){
var deferred, callArgs;
deferred = $q.defer();
spyOn($modal, 'open').and.returnValue({result: deferred.promise});
episode.recordEditor.deleteItem('diagnosis', 0);
$scope.$digest();
expect($modal.open.calls.count()).toBe(0);
});

afterEach(function(){
profile.readonly = false;
});
});

it('should change state to "normal" when the modal is closed', function() {
var deferred;
deferred = $q.defer();
spyOn($modal, 'open').and.returnValue({result: deferred.promise});
episode.recordEditor.deleteItem('diagnosis', 0);
deferred.resolve('save');
$scope.$digest();
});

it('should not delete singletons', function(){
var deferred, callArgs;
deferred = $q.defer();
spyOn($modal, 'open').and.returnValue({result: deferred.promise});
episode.recordEditor.deleteItem('demographics', 0);
$scope.$digest();
expect($modal.open.calls.count()).toBe(0);
});
});
});

describe("get item", function(){
Expand Down

0 comments on commit ecc5181

Please sign in to comment.