Skip to content

Commit

Permalink
#67 Countdown timer in editing form
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlaefer committed Jul 28, 2012
1 parent f9b1601 commit 8ec11f8
Show file tree
Hide file tree
Showing 4 changed files with 830 additions and 1 deletion.
33 changes: 32 additions & 1 deletion app/View/Entries/add.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ $this->Form->submit(__('Einfügen'),
if ( !$this->request->is('ajax') || (isset($lastAction) && ( $lastAction === 'mix' || $lastAction === 'view' || $lastAction === 'add' ) ) ) {
echo $this->Form->submit(__('submit_button'),
array(
'id' => 'btn-submit',
'class' => 'btn btn-submit',
'tabindex' => 4,
'onclick' => "this.disabled=true; this.form.submit();",
Expand All @@ -262,6 +263,7 @@ $this->Form->submit(__('Einfügen'),
'action' => 'add',
$this->request->data['Entry']['id'],
),
'id' => 'btn-submit',
'beforeSubmit' => "$('.btn.btn-submit').attr('disabled', 'disabled');",
'class' => 'btn btn-submit',
'tabindex' => 4,
Expand Down Expand Up @@ -305,4 +307,33 @@ $this->Form->submit(__('Einfügen'),
// set cursor to category or subject field after load ###
echo $this->Js->buffer('$("#EntrySubject").focus();');
echo ($this->request->is('ajax')) ? $this->Js->writeBuffer() : '';
?>
?>

<?php if ($this->request->action === 'edit'): ?>
<span id="submit-countdown" class="countdown" style="display: none;"></span>
<?php
echo $this->Html->script('lib/countdown/jquery.countdown.min');
$sbl = __('submit_button');
$st = (Configure::read('Saito.Settings.edit_period') * 60 ) - (time() - (strtotime($this->request->data['Entry']['time'])));
$this->Js->buffer(<<<EOF
$('#submit-countdown').countdown({
until: +$st,
compact: true,
format: 'MS',
onTick: function(periods) {
if (periods[5] > 1 || (periods[5] == 1 && periods[6] > 30)) {
periods[5] = periods[5] + 1;
$('#btn-submit').attr('value', '$sbl' + ' (' + periods[5] + ' min)');
} else if (periods[5] == 1) {
$('#btn-submit').attr('value', '$sbl' + ' (' + periods[5] + ' min ' + periods[6] + ' s)');
} else {
$('#btn-submit').attr('value', '$sbl' + ' (' + periods[6] + ' s)');
}
},
onExpiry: function() {
$('#btn-submit').attr('disabled', 'disabled');
}
});
EOF
);
endif; ?>
14 changes: 14 additions & 0 deletions app/webroot/js/lib/countdown/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
jQuery Countdown
================

This plugin sets a div or span to show a countdown to a given time.

* Standard or compact formats, or create your own layout.
* Decide which periods to show.
* Count up from a date/time instead.
* Cater for timezone differences and synchronise with server time.
* Over 45 localisations.

Have a look at the plugin Web site, http://keith-wood.name/countdown.html, for demonstrations of its abilities.

For documentation on the functionality see http://keith-wood.name/countdownRef.html.
Loading

0 comments on commit 8ec11f8

Please sign in to comment.