From 6316994cc4ba3bdfef3d6187a20ee80632e5f6c3 Mon Sep 17 00:00:00 2001 From: Jaime Freire Date: Wed, 24 Aug 2016 15:03:20 +0200 Subject: [PATCH] Template function to delete document(s). --- .../browse_collection/browse_collection.js | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/client/views/pages/browse_collection/browse_collection.js b/client/views/pages/browse_collection/browse_collection.js index aca1ab4..08ba60e 100644 --- a/client/views/pages/browse_collection/browse_collection.js +++ b/client/views/pages/browse_collection/browse_collection.js @@ -54,6 +54,11 @@ Template.browseCollection.events({ Template.browseCollection.saveEditor(); }, + 'click #btnDelFindFindOne': function (e) { + e.preventDefault(); + Template.browseCollection.deleteDocument(); + }, + 'click #btnShowQueryHistories': function () { $('#queryHistoriesModal').modal('show'); }, @@ -438,3 +443,53 @@ Template.browseCollection.saveEditor = function () { }; + +Template.browseCollection.deleteDocument = function () { + var convertedDocs; + try { + convertedDocs = Template.convertAndCheckJSONAsArray(Template.browseCollection.getActiveEditorValue()); + } + catch (e) { + toastr.error('Syntax error, can not save document(s): ' + e); + return; + } + + swal({ + title: "Are you sure ?", + text: convertedDocs.length + ' document(s) will be deleted, are you sure ?', + type: "info", + showCancelButton: true, + confirmButtonColor: "#DD6B55", + confirmButtonText: "Yes!", + cancelButtonText: "No" + }, function (isConfirm) { + if (isConfirm) { + + var l = Ladda.create(document.querySelector('#btnDelFindFindOne')); + l.start(); + + var selectedCollection = Session.get(Template.strSessionSelectedCollection); + var convertIds = $('#aConvertObjectIds').iCheck('update')[0].checked; + var convertDates = $('#aConvertIsoDates').iCheck('update')[0].checked; + var i = 0; + _.each(convertedDocs, function (doc) { + if (doc._id) { + Meteor.call("delete", selectedCollection, {_id: doc._id}, convertIds, convertDates, function (err, result) { + if (err || result.error) { + Template.showMeteorFuncError(err, result, "Couldn't delete one of the documents"); + Ladda.stopAll(); + } else { + if ((i++) == (convertedDocs.length - 1)) { + // last time + toastr.success('Successfully deleted document(s)'); + Ladda.stopAll(); + } + } + }); + } + }); + } + }); + +}; + -- GitLab