Skip to content

Commit

Permalink
#25 - select multiple content to mark for deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
vabarbosa committed Nov 23, 2016
1 parent a7ee889 commit 2d95440
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 4 deletions.
23 changes: 23 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,29 @@ app.post('/submitprovisional', function(req,res) {
});
});

app.post('/markdeleted', function(req, res) {
var ids = JSON.parse(req.body.ids)
if (ids && ids.length > 0) {
db.fetch({keys: ids, reduce: false}, function(err, data) {
if (!err && data.rows.length > 0) {
var docs = data.rows.map(function(row) {
var doc = row.doc
doc.status = 'Deleted'
return doc
})
db.bulk({docs: docs}, function(err, data) {
res.send({"ok":(err==null), "error": err, "reply": data});
})
} else {
res.send({"ok":(err==null), "error": err, "reply": data});
}
})
}
else {
res.send({"ok":"true", "error": null, "reply": []});
}
})

app.post('/submitdoc', function(req,res) {


Expand Down
6 changes: 6 additions & 0 deletions public/css/devcenter.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ li.active {
visibility: hidden;
}

#deletebutton {
position: absolute;
right: 0;
top: 25px;
}

.search_button {
height: 2rem;
}
Expand Down
29 changes: 28 additions & 1 deletion public/js/devcenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,34 @@ var submitDoc = function() {
});

return false;

}

var deleteDocs = function(docIds) {
$('#deletebutton').prop('disabled', true);
$('#deletebutton').text('Updating...')
var ids = []
if (docIds) {
ids = docIds
} else {
$('.select_checkbox:checked')
.each(function() {
ids.push(this.id)
})
}
var req = {
url: "markdeleted",
method: "post",
data: {"ids": JSON.stringify(ids)},
dataType: "json"
};
$.ajax(req)
.always(function() {
$('#deletebutton').text('Delete')
$('#deletebutton').prop('disabled', false)
$('#searchbutton').click()
})

return false;
}


Expand Down
9 changes: 7 additions & 2 deletions views/docsearch.jade
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ body.capped-layout
div.grid_column.six
h3.type_subhead.type_mark Documents
p.type_copy.search_count
button#deletebutton.button_primary Delete
div.table_container
table.table_basic
thead
tr
th  
th Status
th Date
th Name
Expand All @@ -50,8 +52,8 @@ body.capped-layout

script(type="text/javascript").
$(document).ready(function() {
$('div.searchfacet > h4.type_subhead').hover(
function() {
$('div.searchfacet > h4.type_subhead')
.hover(function() {
if (!$(this).hasClass('active')) {
$('div.searchfacet > h4.type_subhead.active')
.removeClass('active')
Expand All @@ -65,6 +67,9 @@ body.capped-layout
$('#morebutton').click(function() {
searchDocs(null, $(this).data('bookmark'));
});
$('#deletebutton').click(function() {
deleteDocs();
});
$('#searchinput').val('');
searchDocs('');
});
35 changes: 34 additions & 1 deletion views/tablerows.jade
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
each d, index in docs.rows
- if (index == docs.rows.length - 1) {
tr.docrow(data-bookmark="#{docs.bookmark}",data-total-rows="#{docs.total_rows}")
td
- if (d.status && d.status.toLowerCase() !== "deleted") {
input.input_checkbox.select_checkbox(type="checkbox", id="#{d.id}", name="#{d.id}")
- }
- else {
input.input_checkbox.select_checkbox(type="checkbox", disabled="true", id="#{d.id}", name="#{d.id}")
- }
label.input_checkbox-handle(for="#{d.id}")
td #{d.status}
td #{d.date}
td
Expand All @@ -18,6 +26,14 @@
- }
- else {
tr.docrow
td
- if (d.status && d.status.toLowerCase() !== "deleted") {
input.input_checkbox.select_checkbox(type="checkbox", id="#{d.id}", name="#{d.id}")
- }
- else {
input.input_checkbox.select_checkbox(type="checkbox", disabled="true", id="#{d.id}", name="#{d.id}")
- }
label.input_checkbox-handle(for="#{d.id}")
td #{d.status}
td #{d.date}
td
Expand All @@ -27,4 +43,21 @@
span.muted #{d.url}
- }
- }
- }
- }

script(type="text/javascript").
$(document).ready(function() {
var checked = 0;
$('.select_checkbox')
.each(function() {
$(this).change(function() {
if($(this).is(":checked")) {
checked++;
} else {
checked--;
}
$('#deletebutton').prop('disabled', checked === 0);
});
});
$('#deletebutton').prop('disabled', checked === 0);
});

0 comments on commit 2d95440

Please sign in to comment.