Skip to content

Commit

Permalink
Request: 10361 Display confirmation before deleting time slices.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Jan 18, 2014
1 parent 318c6e3 commit 8ba0774
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
38 changes: 26 additions & 12 deletions hermes/js/hermes.js
Expand Up @@ -31,6 +31,7 @@ HermesCore = {
fromSearch: false,
wrongFormat: $H(),
inTimerForm: false,
pendingDeletes: [],

onException: function(parentfunc, r, e)
{
Expand Down Expand Up @@ -359,6 +360,12 @@ HermesCore = {
this.doStopTimer(this.temp_timer, true);
this.temp_timer = null;
return;

case 'hermesDeleteYes':
this.deleteSlice(this.pendingDeletes);
case 'hermesDeleteNo':
this.pendingDeletes = [];
this.closeRedBox();
}

switch (elt.className) {
Expand All @@ -384,7 +391,8 @@ HermesCore = {
e.stop();
return;
} else if (elt.hasClassName('sliceDelete')) {
this.deleteSlice(elt.up().up());
this.pendingDeletes.push(elt.up().up());
RedBox.showHtml($('hermesDeleteDiv').show());
e.stop();
return;
} else if (elt.hasClassName('sliceEdit')) {
Expand Down Expand Up @@ -557,31 +565,37 @@ HermesCore = {
/**
* Permanently delete a time slice
*
* @param slice The DOM element of the slice in the slice list to remove.
* @param slices The DOM elements of the slices in the slice list to remove.
*/
deleteSlice: function(slice)
deleteSlice: function(slices)
{
var sid = slice.retrieve('sid');
var sid = [];
slices.each(function(s) {
sid.push(s.retrieve('sid'));
});
$('hermesLoadingTime').show();
HordeCore.doAction('deleteSlice',
{ 'id': sid },
{ 'callback': this.deletesliceCallback.curry(slice).bind(this) }
{ 'callback': this.deletesliceCallback.curry(slices).bind(this) }
);
},

/**
* Callback for the deleteSlice action. Hides the spinner, removes the
* slice's DOM element from the UI and updates time summary.
*/
deletesliceCallback: function(elt)
deletesliceCallback: function(elts)
{
$('hermesLoadingTime').hide();
this.removeSliceFromUI(elt);
this.updateTimeSummary();
if (this.view == 'search') {
this.removeSliceFromCache(elt.retrieve('sid'), 'search');
this.updateSearchTotal();
}
elts.each(function(elt) {
this.removeSliceFromUI(elt);
this.updateTimeSummary();
if (this.view == 'search') {
this.removeSliceFromCache(elt.retrieve('sid'), 'search');
this.updateSearchTotal();
}
}.bind(this));
this.pendingDeletes = [];
},

/**
Expand Down
10 changes: 7 additions & 3 deletions hermes/lib/Ajax/Application/Handler.php
Expand Up @@ -128,17 +128,21 @@ public function deleteJobType()

/**
* Remove a slice. Expects the following in $this->vars:
* - id: The slice id
* - id: The slice ids
*
* @return boolean
*/
public function deleteSlice()
{
$sid = array('id' => $this->vars->id, 'delete' => true);
$slices = array();
$ids = !is_array($this->vars->id) ? array($this->vars->id) : $this->vars->id;
foreach ($ids as $id) {
$slices[] = array('id' => $id, 'delete' => true);
}
try {
$result = $GLOBALS['injector']
->getInstance('Hermes_Driver')
->updateTime(array($sid));
->updateTime($slices);
$GLOBALS['notification']->push(
_("Your time entry was successfully deleted."), 'horde.success');

Expand Down
10 changes: 9 additions & 1 deletion hermes/templates/dynamic/slices.inc
Expand Up @@ -109,4 +109,12 @@
<!-- End of Time Slice Grid -->

</div>
<!-- End of Time View Container -->
<!-- End of Time View Container -->

<div id="hermesDeleteDiv" class="hermesDialog" style="display:none">
<p><?php echo _("Delete the time slice?") ?></p>
<div class="hermesFormActions">
<input id="hermesDeleteYes" type="button" value="<?php echo _("Yes") ?>" class="horde-default" />
<input id="hermesDeleteNo" type="button" value="<?php echo _("No") ?>" />
</div>
</div>

0 comments on commit 8ba0774

Please sign in to comment.