From fe6a7457f73db86c4223332f79ad4e83ae3e9312 Mon Sep 17 00:00:00 2001 From: Alexei Peters Date: Tue, 9 Jul 2019 15:52:24 -0700 Subject: [PATCH 1/2] get grouping card to work with workflow steps, refactor card components to control the save method, re #4907 --- .../app/media/js/viewmodels/card-component.js | 26 +++++++++++++- .../js/views/components/cards/grouping.js | 7 ++++ .../workflows/new-multi-tile-step.js | 36 +++++-------------- .../components/workflows/new-tile-step.js | 33 +++++------------ .../app/media/js/views/resource/new-editor.js | 5 --- .../views/components/cards/default.htm | 4 +-- .../templates/views/components/map-editor.htm | 8 ++--- .../components/workflows/new-tile-step.htm | 3 +- 8 files changed, 55 insertions(+), 67 deletions(-) diff --git a/arches/app/media/js/viewmodels/card-component.js b/arches/app/media/js/viewmodels/card-component.js index 5aa3fdc6117..d16fa83f5ee 100644 --- a/arches/app/media/js/viewmodels/card-component.js +++ b/arches/app/media/js/viewmodels/card-component.js @@ -1,8 +1,9 @@ define([ 'knockout', 'underscore', + 'viewmodels/alert', 'bindings/scrollTo' -], function(ko, _) { +], function(ko, _, AlertViewModel) { return function(params) { var self = this; var getTiles = function(tile, tiles) { @@ -73,5 +74,28 @@ define([ } return tiles; }, this); + this.saveTile = function() { + self.loading(true); + self.tile.save(function(response) { + self.loading(false); + params.pageVm.alert( + new AlertViewModel( + 'ep-alert-red', + response.responseJSON.message[0], + response.responseJSON.message[1], + null, + function(){} + ) + ); + if (params.form.onSaveError) { + params.form.onSaveError(self.tile); + } + }, function() { + self.loading(false); + if (params.form.onSaveSuccess) { + params.form.onSaveSuccess(self.tile); + } + }); + }; }; }); diff --git a/arches/app/media/js/views/components/cards/grouping.js b/arches/app/media/js/views/components/cards/grouping.js index 8f958a511ed..d78d3e0bf14 100644 --- a/arches/app/media/js/views/components/cards/grouping.js +++ b/arches/app/media/js/views/components/cards/grouping.js @@ -151,6 +151,10 @@ define([ self.saving = false; self.groupedCardIds.valueHasMutated(); self.selectGroupCard(); + if (params.form.onSaveSuccess) { + params.form.onSaveSuccess(self.tile); + } + self.loading(false); }); }); errors.subscribe(function(errors){ @@ -161,6 +165,9 @@ define([ message.push(response.responseJSON.message[1]); }); params.pageVm.alert(new AlertViewModel('ep-alert-red', title.join(), message.join(), null, function(){})); + if (params.form.onSaveError) { + params.form.onSaveError(self.tile); + } }); }; diff --git a/arches/app/media/js/views/components/workflows/new-multi-tile-step.js b/arches/app/media/js/views/components/workflows/new-multi-tile-step.js index 5cc752e8d30..6566031e07d 100644 --- a/arches/app/media/js/views/components/workflows/new-multi-tile-step.js +++ b/arches/app/media/js/views/components/workflows/new-multi-tile-step.js @@ -29,34 +29,16 @@ define([ self.tile(tile); }; - self.saveTile = function(tile, callback) { - self.loading(true); - tile.save(function(response) { - self.loading(false); - self.alert( - new AlertViewModel( - 'ep-alert-red', - response.responseJSON.message[0], - response.responseJSON.message[1], - null, - function(){ return; } - ) - ); - }, function(tile) { - params.resourceid(tile.resourceinstance_id); - params.tileid(tile.tileid); - self.resourceId(tile.resourceinstance_id); - self.complete(true); - if (typeof callback === 'function') { - callback.apply(null, arguments); - } - self.tile(self.card().getNewTile()); + self.onSaveSuccess = function(tile) { + params.resourceid(tile.resourceinstance_id); + params.tileid(tile.tileid); + self.resourceId(tile.resourceinstance_id); + self.complete(true); + self.tile(self.card().getNewTile()); + self.tile().reset(); + setTimeout(function() { self.tile().reset(); - setTimeout(function() { - self.tile().reset(); - }, 1); - self.loading(false); - }); + }, 1); }; var updateTileOnInit = self.tile.subscribe(function() { diff --git a/arches/app/media/js/views/components/workflows/new-tile-step.js b/arches/app/media/js/views/components/workflows/new-tile-step.js index 451fd8ab6f7..aced26af174 100644 --- a/arches/app/media/js/views/components/workflows/new-tile-step.js +++ b/arches/app/media/js/views/components/workflows/new-tile-step.js @@ -140,32 +140,15 @@ define([ }; }; - self.saveTile = function(tile, callback) { - self.loading(true); - tile.save(function(response) { - self.loading(false); - self.alert( - new AlertViewModel( - 'ep-alert-red', - response.responseJSON.message[0], - response.responseJSON.message[1], - null, - function(){ return; } - ) - ); - }, function(tile) { - params.resourceid(tile.resourceinstance_id); - params.tileid(tile.tileid); - self.resourceId(tile.resourceinstance_id); - if (self.completeOnSave === true) { - self.complete(true); - } - if (typeof callback === 'function') { - callback.apply(null, arguments); - } - self.loading(false); - }); + self.onSaveSuccess = function(tile) { + params.resourceid(tile.resourceinstance_id); + params.tileid(tile.tileid); + self.resourceId(tile.resourceinstance_id); + if (self.completeOnSave === true) { + self.complete(true); + } }; + } ko.components.register('new-tile-step', { viewModel: viewModel, diff --git a/arches/app/media/js/views/resource/new-editor.js b/arches/app/media/js/views/resource/new-editor.js index 78f0d00d089..03a4d5cebe3 100644 --- a/arches/app/media/js/views/resource/new-editor.js +++ b/arches/app/media/js/views/resource/new-editor.js @@ -235,11 +235,6 @@ define([ vm.alert(new AlertViewModel('ep-alert-red', response.responseJSON.message[0], response.responseJSON.message[1], null, function(){})); }); }, - saveTile: function(tile, callback) { - tile.save(function(response) { - vm.alert(new AlertViewModel('ep-alert-red', response.responseJSON.message[0], response.responseJSON.message[1], null, function(){})); - }, callback); - }, viewEditHistory: function() { if (resourceId()) { vm.menuActive(false); diff --git a/arches/app/templates/views/components/cards/default.htm b/arches/app/templates/views/components/cards/default.htm index f0803dea143..4e0ab7f5aac 100644 --- a/arches/app/templates/views/components/cards/default.htm +++ b/arches/app/templates/views/components/cards/default.htm @@ -363,11 +363,11 @@

- + - + {% endblock form_buttons %} diff --git a/arches/app/templates/views/components/map-editor.htm b/arches/app/templates/views/components/map-editor.htm index 1ca8746d577..5d83be6e7e5 100644 --- a/arches/app/templates/views/components/map-editor.htm +++ b/arches/app/templates/views/components/map-editor.htm @@ -196,18 +196,14 @@

- - diff --git a/arches/app/templates/views/components/workflows/new-tile-step.htm b/arches/app/templates/views/components/workflows/new-tile-step.htm index 10ef7b0ad9c..30e824edfbd 100644 --- a/arches/app/templates/views/components/workflows/new-tile-step.htm +++ b/arches/app/templates/views/components/workflows/new-tile-step.htm @@ -7,7 +7,8 @@ provisionalTileViewModel: provisionalTileViewModel, reviewer: reviewer, loading: loading, - form: $data + form: $data, + pageVm: $root } } --> From 087db885ef1e85e3de9dbb380b3fb5593c272918 Mon Sep 17 00:00:00 2001 From: Alexei Peters Date: Tue, 9 Jul 2019 17:09:44 -0700 Subject: [PATCH 2/2] refactor card component to manage tile deletion, re #4907 --- .../app/media/js/viewmodels/card-component.js | 23 +++++++++++++++++++ .../app/media/js/views/resource/new-editor.js | 5 ---- .../views/components/cards/default.htm | 4 ++-- .../views/components/cards/grouping.htm | 2 +- .../templates/views/components/map-editor.htm | 6 ++--- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/arches/app/media/js/viewmodels/card-component.js b/arches/app/media/js/viewmodels/card-component.js index d16fa83f5ee..2e70a637650 100644 --- a/arches/app/media/js/viewmodels/card-component.js +++ b/arches/app/media/js/viewmodels/card-component.js @@ -97,5 +97,28 @@ define([ } }); }; + this.deleteTile = function() { + self.loading(true); + self.tile.deleteTile(function(response) { + self.loading(false); + params.pageVm.alert( + new AlertViewModel( + 'ep-alert-red', + response.responseJSON.message[0], + response.responseJSON.message[1], + null, + function(){} + ) + ); + if (params.form.onDeleteError) { + params.form.onDeleteError(self.tile); + } + }, function() { + self.loading(false); + if (params.form.onDeleteSuccess) { + params.form.onDeleteSuccess(self.tile); + } + }); + }; }; }); diff --git a/arches/app/media/js/views/resource/new-editor.js b/arches/app/media/js/views/resource/new-editor.js index 03a4d5cebe3..e7174923818 100644 --- a/arches/app/media/js/views/resource/new-editor.js +++ b/arches/app/media/js/views/resource/new-editor.js @@ -230,11 +230,6 @@ define([ })); } }, - deleteTile: function(tile) { - tile.deleteTile(function(response) { - vm.alert(new AlertViewModel('ep-alert-red', response.responseJSON.message[0], response.responseJSON.message[1], null, function(){})); - }); - }, viewEditHistory: function() { if (resourceId()) { vm.menuActive(false); diff --git a/arches/app/templates/views/components/cards/default.htm b/arches/app/templates/views/components/cards/default.htm index 4e0ab7f5aac..f0433579058 100644 --- a/arches/app/templates/views/components/cards/default.htm +++ b/arches/app/templates/views/components/cards/default.htm @@ -355,8 +355,8 @@

{% block form_buttons %}
- - + + diff --git a/arches/app/templates/views/components/cards/grouping.htm b/arches/app/templates/views/components/cards/grouping.htm index 73fca856664..97c8e8936fa 100644 --- a/arches/app/templates/views/components/cards/grouping.htm +++ b/arches/app/templates/views/components/cards/grouping.htm @@ -267,7 +267,7 @@

{% block form_buttons %}
- + diff --git a/arches/app/templates/views/components/map-editor.htm b/arches/app/templates/views/components/map-editor.htm index 5d83be6e7e5..7295ff6cbf6 100644 --- a/arches/app/templates/views/components/map-editor.htm +++ b/arches/app/templates/views/components/map-editor.htm @@ -183,10 +183,8 @@
{% block form_buttons %}
- -