Skip to content

Commit

Permalink
Merge pull request #4991 from archesproject/4907_grouping_card_component
Browse files Browse the repository at this point in the history
4907 grouping card component
  • Loading branch information
apeters authored Jul 10, 2019
2 parents 290790b + 05c18a0 commit 33c56b8
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 79 deletions.
49 changes: 48 additions & 1 deletion arches/app/media/js/viewmodels/card-component.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -73,5 +74,51 @@ 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);
}
});
};
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);
}
});
};
};
});
7 changes: 7 additions & 0 deletions arches/app/media/js/views/components/cards/grouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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);
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
33 changes: 8 additions & 25 deletions arches/app/media/js/views/components/workflows/new-tile-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions arches/app/media/js/views/resource/new-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +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(){}));
});
},
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);
Expand Down
8 changes: 4 additions & 4 deletions arches/app/templates/views/components/cards/default.htm
Original file line number Diff line number Diff line change
Expand Up @@ -355,19 +355,19 @@ <h4 class="card-summary-name">
<!-- /ko -->
{% block form_buttons %}
<div class="install-buttons">
<!-- ko if: tile.tileid && self.form.deleteTile -->
<button class="btn btn-shim btn-labeled btn-lg fa fa-trash" data-bind="click: function () { self.form.deleteTile(tile); }, css: {disabled: (!card.isWritable && !self.preview), 'btn-warning': card.isWritable }">{% trans 'Delete this record' %}</button>
<!-- ko if: tile.tileid && self.deleteTile -->
<button class="btn btn-shim btn-labeled btn-lg fa fa-trash" data-bind="click: self.deleteTile, css: {disabled: (!card.isWritable && !self.preview), 'btn-warning': card.isWritable }">{% trans 'Delete this record' %}</button>
<!-- /ko -->
<!-- ko if: tile.dirty() -->
<!-- ko if: provisionalTileViewModel && !provisionalTileViewModel.tileIsFullyProvisional() && card.isWritable -->
<button class="btn btn-shim btn-danger btn-labeled btn-lg fa fa-times" data-bind="click: tile.reset">{% trans 'Cancel edit' %}</button>
<!-- /ko -->
<!-- ko if: tile.tileid -->
<button class="btn btn-shim btn-labeled btn-lg fa fa-plus" data-bind="click: function () { self.form.saveTile(tile); }, css: {disabled: (!card.isWritable && !self.preview), 'btn-mint': card.isWritable }">{% trans 'Save edit' %}</button>
<button class="btn btn-shim btn-labeled btn-lg fa fa-plus" data-bind="click: self.saveTile, css: {disabled: (!card.isWritable && !self.preview), 'btn-mint': card.isWritable }">{% trans 'Save edit' %}</button>
<!-- /ko -->
<!-- /ko -->
<!-- ko if: !tile.tileid -->
<button class="btn btn-shim btn-labeled btn-lg fa fa-plus" data-bind="click: function () { self.form.saveTile(tile); }, css: {disabled: (!card.isWritable && !self.preview), 'btn-mint': card.isWritable }">{% trans 'Add' %}</button>
<button class="btn btn-shim btn-labeled btn-lg fa fa-plus" data-bind="click: self.saveTile, css: {disabled: (!card.isWritable && !self.preview), 'btn-mint': card.isWritable }">{% trans 'Add' %}</button>
<!-- /ko -->
</div>
{% endblock form_buttons %}
Expand Down
2 changes: 1 addition & 1 deletion arches/app/templates/views/components/cards/grouping.htm
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ <h4 class="card-summary-name">
<!-- /ko -->
{% block form_buttons %}
<div class="install-buttons">
<!-- ko if: previouslySaved() && self.form.deleteTile -->
<!-- ko if: previouslySaved() && self.deleteTiles -->
<button class="btn btn-shim btn-labeled btn-lg fa fa-trash" data-bind="click: deleteTiles, css: {disabled: (!card.isWritable && !self.preview), 'btn-warning': card.isWritable }">{% trans 'Delete this record' %}</button>
<!-- /ko -->
<!-- ko if: dirty() -->
Expand Down
14 changes: 4 additions & 10 deletions arches/app/templates/views/components/map-editor.htm
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,8 @@ <h5 data-bind="text: card.model.instructions"></h5>
<!-- /ko -->
{% block form_buttons %}
<div class="install-buttons">
<!-- ko if: tile.tileid && self.form.deleteTile -->
<button class="btn btn-shim btn-labeled btn-lg fa fa-trash" data-bind="click: function () {
self.form.deleteTile(tile);
}, css: {
<!-- ko if: tile.tileid && self.deleteTile -->
<button class="btn btn-shim btn-labeled btn-lg fa fa-trash" data-bind="click: self.deleteTile, css: {
disabled: (!card.isWritable && !self.preview),
'btn-warning': card.isWritable
}">{% trans 'Delete this record' %}</button>
Expand All @@ -196,18 +194,14 @@ <h5 data-bind="text: card.model.instructions"></h5>
<button class="btn btn-shim btn-danger btn-labeled btn-lg fa fa-times" data-bind="click: tile.reset">{% trans 'Cancel edit' %}</button>
<!-- /ko -->
<!-- ko if: tile.tileid -->
<button class="btn btn-shim btn-labeled btn-lg fa fa-plus" data-bind="click: function () {
self.form.saveTile(tile);
}, css: {
<button class="btn btn-shim btn-labeled btn-lg fa fa-plus" data-bind="click: self.saveTile, css: {
disabled: (!card.isWritable && !self.preview),
'btn-mint': card.isWritable
}">{% trans 'Save edit' %}</button>
<!-- /ko -->
<!-- /ko -->
<!-- ko if: !tile.tileid -->
<button class="btn btn-shim btn-labeled btn-lg fa fa-plus" data-bind="click: function () {
self.form.saveTile(tile);
}, css: {
<button class="btn btn-shim btn-labeled btn-lg fa fa-plus" data-bind="click: self.saveTile, css: {
disabled: (!card.isWritable && !self.preview),
'btn-mint': card.isWritable
}">{% trans 'Add' %}</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
provisionalTileViewModel: provisionalTileViewModel,
reviewer: reviewer,
loading: loading,
form: $data
form: $data,
pageVm: $root
}
} --><!-- /ko -->
<!-- /ko -->

0 comments on commit 33c56b8

Please sign in to comment.