Skip to content

Commit

Permalink
Add Destroy button when appropriate in bulk selection of items in lis…
Browse files Browse the repository at this point in the history
…t; include dialog box to ensure user understands meaning
  • Loading branch information
mikhuang committed Jul 2, 2013
1 parent 01c2dcc commit 8e38914
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
23 changes: 17 additions & 6 deletions deme_django/cms/templates/item/list_bare.html
Expand Up @@ -83,12 +83,23 @@ <h3 class="popup-title">Select {{item_type_name|an}} {{item_type_name}}</h3>
</select>
</div>
</div>
<label class="radio-inline">
<input type="radio" name="inactive" value="0"{% if not inactive %} checked="checked"{% endif %}> Active Items
</label>
<label class="radio-inline">
<input type="radio" name="inactive" value="1"{% if inactive %} checked="checked"{% endif %}> Deactivated Items
</label>
<div class="row">
<div class="col col-lg-9">
<label class="radio-inline">
<input type="radio" name="inactive" value="0"{% if not inactive %} checked="checked"{% endif %}> Active Items
</label>
<label class="radio-inline">
<input type="radio" name="inactive" value="1"{% if inactive %} checked="checked"{% endif %}> Deactivated Items
</label>
</div>
<div class="col col-lg-3">
<div class="pull-right">
<p>
<button type="submit" class="btn btn-info btn-small">Apply</button>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
38 changes: 33 additions & 5 deletions deme_django/cms/templates/templatetags/listgridbox.html
Expand Up @@ -3,14 +3,17 @@
<table id="jqgrid_list{{identifier}}"></table>
<div id="jqgrid_pager{{identifier}}"></div>
<div class="hide jqgrid_multitools" id="jqgrid_multitools{{identifier}}">
{% ifagentcanglobal "create Membership" %}
<button class="btn btn-info btn-small action-add-to-collection" title="Add selected to a Collection"><i class="glyphicon glyphicon-plus-sign"></i> Add to a Collection</button>
{% endifagentcanglobal %}
{% if collection_item %}
<button class="btn btn-warning btn-small action-remove-from-collection" title="Remove selected from this Collection"><i class="glyphicon glyphicon-remove"></i> Remove from Collection</button>
{% endif %}
{% if inactive %}
<button class="btn btn-success btn-small action-reactivate" title="Reactivate selected items"><i class="glyphicon glyphicon-refresh"></i> Reactivate</button>
<button class="btn btn-danger btn-small action-destroy" title="Destroy selected items"><i class="glyphicon glyphicon-trash"></i> Destroy</button>
{% else %}
<button class="btn btn-danger btn-small action-deactivate" title="Deactivate selected items"><i class="glyphicon glyphicon-trash"></i> Deactivate</button>
<button class="btn btn-warning btn-small action-deactivate" title="Deactivate selected items"><i class="glyphicon glyphicon-trash"></i> Deactivate</button>
{% endif %}
</div>
<script type="text/javascript">
Expand Down Expand Up @@ -99,25 +102,46 @@

multi.on('click', '.action-reactivate', function(e){
e.preventDefault();
var reason = prompt("Please give a reason for reactivating these items:");
if (reason != null) {
var reason = prompt("Please give a reason for reactivating these items:",' ');
if (reason != null && $.trim(reason) != '') {
var sel = jqgrid_list.jqGrid('getGridParam','selarrrow');
var form = $('#reactivatemultiform{{identifier}}');
form.find('[name="items"]').val(sel);
form.find('[name="action_summary"]').val(reason);
form.submit();
} else if (reason == ' ') {
alert('No reason was given so these items have NOT been reactivated.');
}
});

multi.on('click', '.action-deactivate', function(e){
e.preventDefault();
var reason = prompt("Please give a reason for deactivating these items:");
if (reason != null) {
var reason = prompt("Please give a reason for deactivating these items:",' ');
if (reason != null && $.trim(reason) != '') {
var sel = jqgrid_list.jqGrid('getGridParam','selarrrow');
var form = $('#deactivatemultiform{{identifier}}');
form.find('[name="items"]').val(sel);
form.find('[name="action_summary"]').val(reason);
form.submit();
} else if (reason == ' ') {
alert('No reason was given so these items have NOT been deactivated.');
}
});

multi.on('click', '.action-destroy', function(e){
e.preventDefault();
var confirm = prompt("THERE IS NO UNDO. If you really want to destroy these items, please type in DESTROY to confirm.");
if (confirm == 'DESTROY') {
var reason = prompt("Please give a reason for destroying these items:",' ');
if (reason != null && $.trim(reason) != '') {
var sel = jqgrid_list.jqGrid('getGridParam','selarrrow');
var form = $('#destroymultiform{{identifier}}');
form.find('[name="items"]').val(sel);
form.find('[name="action_summary"]').val(reason);
form.submit();
} else if (reason == ' ') {
alert('No reason was given so these items have NOT been destroyed.');
}
}
});

Expand Down Expand Up @@ -174,6 +198,10 @@
<input type="hidden" name="items" value="" />
<input type="hidden" name="action_summary" value="" />
</form>
<form id="destroymultiform{{identifier}}" method="post" enctype="multipart/form-data" action="{% url item_type_url viewer='item',action="destroymulti" %}?redirect={{ full_path|urlencode }}" class="item_form">
<input type="hidden" name="items" value="" />
<input type="hidden" name="action_summary" value="" />
</form>
{% else %}
<form id="deactivatemultiform{{identifier}}" method="post" enctype="multipart/form-data" action="{% url item_type_url viewer='item',action="deactivatemulti" %}?redirect={{ full_path|urlencode }}" class="item_form">
<input type="hidden" name="items" value="" />
Expand Down
22 changes: 21 additions & 1 deletion deme_django/cms/views.py
Expand Up @@ -678,7 +678,7 @@ def type_reactivatemulti_html(self):
try:
items = Item.objects.filter(pk__in=items_string)
except:
return self.render_error('Invalid URL', "You must specify the items you are deactivating")
return self.render_error('Invalid URL', "You must specify the items you are reactivating")

errors = []
for item in items:
Expand All @@ -701,6 +701,26 @@ def item_destroy_html(self):
redirect = self.request.GET.get('redirect', reverse('item_url', kwargs={'viewer': self.viewer_name, 'noun': self.item.pk, 'action': 'justdestroyed'}))
return HttpResponseRedirect(redirect)

@require_POST
def type_destroymulti_html(self):
items_string = self.request.POST.get('items').split(',')
try:
items = Item.objects.filter(pk__in=items_string)
except:
return self.render_error('Invalid URL', "You must specify the items you are destroying")

errors = []
for item in items:
item = item.downcast()
if not item.can_be_deleted():
errors.append('The item %s may not be deleted.' % (item))
self.require_ability('delete', item)
item.destroy(action_agent=self.cur_agent, action_summary=self.request.POST.get('action_summary'))
if errors:
return self.render_error('Errors', errors.join('<br><br>'))
redirect = self.request.GET.get('redirect', '/')
return HttpResponseRedirect(redirect)

def item_justdestroyed_html(self):
if not self.item.destroyed:
return self.render_error('Destroy error', "The item was not successfully destroyed due to an error in the application")
Expand Down

0 comments on commit 8e38914

Please sign in to comment.