Permalink
Browse files

ENHANCEMENT: Implemented jQuery UI timepicker widget, heading and int…

…ro-text suggestions made in issue #47

MINOR: Changed legacy ref's from DataObjectSet as necessary in inline comments
MINOR: Changed ->Count() = DataObjectSet to ->count() = ArrayList
  • Loading branch information...
1 parent 375277f commit 418f87691aaed15b7a3873039c94ae62abbe0b77 Russell Michell committed Nov 20, 2012
Showing with 3,723 additions and 6 deletions.
  1. +1 −1 code/dataobjects/WorkflowActionInstance.php
  2. +1 −1 code/dataobjects/WorkflowInstance.php
  3. +50 −2 code/extensions/WorkflowEmbargoExpiryExtension.php
  4. +2 −2 code/services/WorkflowService.php
  5. +11 −0 css/WorkflowFieldTimePicker.css
  6. +27 −0 javascript/WorkflowField.js
  7. +5 −0 lang/en.yml
  8. +41 −0 scss/WorkflowFieldTimePicker.scss
  9. +7 −0 templates/Includes/embargoIntro.ss
  10. +20 −0 thirdparty/javascript/jquery-ui/timepicker/README.md
  11. +937 −0 thirdparty/javascript/jquery-ui/timepicker/index.html
  12. +89 −0 thirdparty/javascript/jquery-ui/timepicker/jquery-ui-sliderAccess.js
  13. +10 −0 thirdparty/javascript/jquery-ui/timepicker/jquery-ui-timepicker-addon.css
  14. +1,882 −0 thirdparty/javascript/jquery-ui/timepicker/jquery-ui-timepicker-addon.js
  15. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-af.js
  16. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-bg.js
  17. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-ca.js
  18. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-cs.js
  19. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-de.js
  20. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-el.js
  21. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-es.js
  22. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-et.js
  23. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-fi.js
  24. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-fr.js
  25. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-gl.js
  26. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-he.js
  27. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-hu.js
  28. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-id.js
  29. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-it.js
  30. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-ja.js
  31. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-ko.js
  32. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-lt.js
  33. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-nl.js
  34. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-no.js
  35. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-pl.js
  36. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-pt-BR.js
  37. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-pt.js
  38. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-ro.js
  39. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-ru.js
  40. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-sk.js
  41. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-sv.js
  42. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-tr.js
  43. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-uk.js
  44. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-vi.js
  45. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-zh-CN.js
  46. +20 −0 thirdparty/javascript/jquery-ui/timepicker/localization/jquery-ui-timepicker-zh-TW.js
@@ -137,7 +137,7 @@ public function getTitle() {
* If this action returns only one valid transition it will be immediately
* followed; otherwise the user will decide which transition to follow.
*
- * @return DataObjectSet
+ * @return ArrayList
*/
public function getValidTransitions() {
$available = $this->BaseAction()->Transitions();
@@ -272,7 +272,7 @@ protected function checkTransitions(WorkflowActionInstance $action) {
$transitions = $action->getValidTransitions();
// if there's JUST ONE transition, then we need should
// immediately follow it.
- if ($transitions && $transitions->Count() == 1) {
+ if ($transitions && $transitions->count() == 1) {
return $transitions->First();
}
}
@@ -24,6 +24,8 @@ class WorkflowEmbargoExpiryExtension extends DataExtension {
'workflowService' => '%$WorkflowService',
);
+ public static $showTimePicker = true;
+
/**
* @var WorkflowService
*/
@@ -33,12 +35,24 @@ class WorkflowEmbargoExpiryExtension extends DataExtension {
* @param FieldList $fields
*/
public function updateCMSFields(FieldList $fields) {
+
+ // Add timepicker functionality
+ // @see https://github.com/trentrichardson/jQuery-Timepicker-Addon
+ Requirements::css(ADVANCED_WORKFLOW_DIR . '/thirdparty/javascript/jquery-ui/timepicker/jquery-ui-timepicker-addon.css');
+ Requirements::css(ADVANCED_WORKFLOW_DIR . '/css/WorkflowFieldTimePicker.css');
+ Requirements::javascript(ADVANCED_WORKFLOW_DIR . '/thirdparty/javascript/jquery-ui/timepicker/jquery-ui-sliderAccess.js');
+ Requirements::javascript(ADVANCED_WORKFLOW_DIR . '/thirdparty/javascript/jquery-ui/timepicker/jquery-ui-timepicker-addon.js');
+ Requirements::javascript(ADVANCED_WORKFLOW_DIR . '/javascript/WorkflowField.js');
+
+
// if there is a workflow applied, we can't set the publishing date directly, only the 'desired'
// publishing date
$effective = $this->workflowService->getDefinitionFor($this->owner);
if ($effective) {
$fields->addFieldsToTab('Root.PublishingSchedule', array(
+ new HeaderField('PublishDateHeader', _t('REQUESTED_PUBLISH_DATE_H3', 'Expiry and Embargo'), 3),
+ new LiteralField('PublishDateIntro', $this->getIntroMessage('PublishDateIntro')),
$dt = new Datetimefield('DesiredPublishDate', _t('AdvancedWorkflow.REQUESTED_PUBLISH_DATE', 'Requested publish date and time')),
$ut = new Datetimefield('DesiredUnPublishDate', _t('AdvancedWorkflow.REQUESTED_UNPUBLISH_DATE', 'Requested un-publish date and time')),
Datetimefield::create('PublishOnDate', _t('AdvancedWorkflow.PUBLISH_ON', 'Publish date and time'))->setDisabled(true),
@@ -52,9 +66,13 @@ public function updateCMSFields(FieldList $fields) {
}
$dt->getDateField()->setConfig('showcalendar', true);
- $dt->getTimeField()->setConfig('showdropdown', true);
$ut->getDateField()->setConfig('showcalendar', true);
- $ut->getTimeField()->setConfig('showdropdown', true);
+
+ // Enable a jQuery-UI timepicker widget
+ if(self::$showTimePicker) {
+ $dt->getTimeField()->addExtraClass('hasTimePicker');
+ $ut->getTimeField()->addExtraClass('hasTimePicker');
+ }
}
public function onBeforeWrite() {
@@ -108,4 +126,34 @@ public function onBeforeWrite() {
}
}
}
+
+ /*
+ * Define an array of message-parts for use by {@link getIntroMessage()}
+ *
+ * @param string $key
+ * @return array
+ */
+ public function getIntroMessageParts($key) {
+ $parts = array(
+ 'PublishDateIntro' => array(
+ 'INTRO'=>_t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO','Enter a date and/or time to specify embargo and expiry dates.'),
+ 'BULLET_1'=>_t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO_BULLET_1','These settings won\'t take effect until any approval actions are run'),
+ 'BULLET_2'=>_t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO_BULLET_2','If an embargo is already set, adding a new one prior to that date\'s passing will overwrite it')
+ )
+ );
+ return $parts[$key];
+ }
+
+ /*
+ * Display some messages to the user, a little more complex that a simple one-liner
+ *
+ * @param string $key
+ * @return string
+ */
+ public function getIntroMessage($key) {
+ $msg = $this->getIntroMessageParts($key);
+ $curr = Controller::curr();
+ $msg = $curr->customise($msg)->renderWith('embargoIntro');
+ return $msg;
+ }
}
@@ -76,7 +76,7 @@ public function getWorkflowHistoryFor($item, $limit = null){
/**
* Get all the available workflow definitions
*
- * @return DataObjectSet
+ * @return DataList
*/
public function getDefinitions() {
return DataList::create('WorkflowDefinition');
@@ -139,7 +139,7 @@ public function startWorkflow(DataObject $object) {
* @param Member $user
* The user to get workflows for
*
- * @return DataObjectSet
+ * @return ArrayList
* The list of workflow instances this user owns
*/
public function usersWorkflows(Member $user) {
@@ -0,0 +1,11 @@
+/** CSS for timepicker widget See: http://trentrichardson.com/examples/timepicker/
+*/
+.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
+.ui-timepicker-div dl { text-align: left; }
+.ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }
+.ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }
+.ui-timepicker-div td { font-size: 90%; }
+.ui-timepicker-div .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }
+.ui-timepicker-div .ui-timepicker-rtl { direction: rtl; }
+.ui-timepicker-div .ui-timepicker-rtl dl { text-align: right; }
+.ui-timepicker-div .ui-timepicker-rtl dl dd { margin: 0 65px 10px 10px; }
@@ -146,4 +146,31 @@ jQuery.entwine("workflow", function($) {
return false;
}
});
+
+ /*
+ * Simple implementation of very feature-heave jQuery-UI timepicker widget
+ * @see: http://trentrichardson.com/examples/timepicker/ for more config options
+ *
+ * This will need some more work when it comes to implementing i18n functionality. Fortunately, the library handles these as option-settings quite well.
+ */
+ $("#Root_PublishingSchedule").entwine({
+ onclick: function() {
+ if(typeof $.fn.timepicker() !== 'object') {
+ return false;
+ }
+ var field = $('input.hasTimePicker');
+ var defaultTime = function() {
+ var date = new Date();
+ return date.getHours()+':'+date.getMinutes();
+ }
+ var pickerOpts = {
+ useLocalTimezone: true,
+ defaultValue: defaultTime,
+ controlType: 'select',
+ timeFormat: 'HH:mm'
+ };
+ field.timepicker(pickerOpts);
+ return false;
+ }
+ });
});
View
@@ -24,3 +24,8 @@ en:
GridFieldTitleSubmittedAll: All submitted items
GridFieldTitleAssignedYour: Your pending items
GridFieldTitleSubmittedYour: Your submitted items
+ WorkflowEmbargoExpiryExtension:
+ REQUESTED_PUBLISH_DATE_H3: Expiry and Embargo
+ REQUESTED_PUBLISH_DATE_INTRO: Enter a date and/or time to specify embargo and expiry dates.
+ WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO_BULLET_1: These settings won't take effect until any approval actions are run
+ WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO_BULLET_2: If an embargo is already set, adding a new one prior to that date's passing will overwrite it
@@ -0,0 +1,41 @@
+/**
+ * CSS for timepicker widget
+ * See: http://trentrichardson.com/examples/timepicker/
+*/
+.ui-timepicker-div {
+ .ui-widget-header {
+ margin-bottom: 8px;
+ }
+ dl {
+ text-align: left;
+ }
+ dl dt {
+ height: 25px;
+ margin-bottom: -25px;
+ }
+ dl dd {
+ margin: 0 10px 10px 65px;
+ }
+ td {
+ font-size: 90%;
+ }
+
+ & .ui-tpicker-grid-label {
+ background: none;
+ border: none;
+ margin: 0;
+ padding: 0;
+ }
+
+ & .ui-timepicker-rtl {
+ direction: rtl;
+ }
+
+ & .ui-timepicker-rtl dl {
+ text-align: right;
+ }
+
+ & .ui-timepicker-rtl dl dd {
+ margin: 0 65px 10px 10px;
+ }
+}
@@ -0,0 +1,7 @@
+
+<p>$INTRO</p>
+<ul>
+ <li>$BULLET_1</li>
+ <li>$BULLET_2</li>
+</ul>
+<br/>
@@ -0,0 +1,20 @@
+jQuery Timepicker Addon
+=======================
+
+About
+-----
+- Author: [Trent Richardson](http://trentrichardson.com)
+- Documentation: [http://trentrichardson.com/examples/timepicker/](http://trentrichardson.com/examples/timepicker/)
+- Twitter: [@practicalweb](http://twitter.com/practicalweb)
+
+Use
+---
+- To use this plugin you must include jQuery and jQuery UI with datepicker and slider
+- Include timepicker-addon script
+- now use timepicker with $('#selector').datetimepicker() or $('#selector').timepicker()
+
+Contributing Code - Please Read!
+--------------------------------
+- All code contributions and bug reports are much appreciated.
+- Please be sure to apply your fixes to the "dev" branch.
+- Also note tabs are appreciated over spaces.
Oops, something went wrong.

0 comments on commit 418f876

Please sign in to comment.