Feature #36559 ยป progressbar.patch

Nicole Cordes, 2012-04-25 15:11

View differences:

Classes/ViewHelpers/Widget/Controller/ProgressbarController.php (revision )
1
<?php
2
namespace TYPO3\Fluid\ViewHelpers\Widget\Controller;
3

  
4
/*                                                                        *
5
 * This script belongs to the FLOW3 package "Fluid".                      *
6
 *                                                                        *
7
 * It is free software; you can redistribute it and/or modify it under    *
8
 * the terms of the GNU Lesser General Public License, either version 3   *
9
 *  of the License, or (at your option) any later version.                *
10
 *                                                                        *
11
 * The TYPO3 project - inspiring people to share!                         *
12
 *                                                                        */
13

  
14
/**
15
 */
16
class ProgressbarController extends \TYPO3\Fluid\Core\Widget\AbstractWidgetController {
17

  
18
	/**
19
	 * @return void
20
	 */
21
	public function indexAction() {
22
			// Check if an action is set
23
		if (empty($this->widgetConfiguration['action'])) {
24
			throw new \InvalidArgumentException('The action is not allowed to be empty.', 1334941924);
25
		}
26

  
27
			// Get request settings
28
		if (empty($this->widgetConfiguration['package'])) {
29
			$this->widgetConfiguration['package'] = $this->request->getParentRequest()->getControllerPackageKey();
30
		}
31
		if (empty($this->widgetConfiguration['subpackage'])) {
32
			$this->widgetConfiguration['subpackage'] = $this->request->getParentRequest()->getControllerSubpackageKey();
33
		}
34
		if (empty($this->widgetConfiguration['controller'])) {
35
			$this->widgetConfiguration['controller'] = $this->request->getParentRequest()->getControllerName();
36
		}
37

  
38
			// Store new widget configuration to add it to links
39
		/** @var $widgetContext \TYPO3\Fluid\Core\Widget\WidgetContext */
40
		$widgetContext = $this->request->getInternalArgument('__widgetContext');
41
		$widgetContext->setAjaxWidgetConfiguration($this->widgetConfiguration);
42
		$this->request->setArgument('__widgetContext', $widgetContext);
43

  
44
			// Get uniqu id if not set
45
		$id = $this->widgetConfiguration['id'];
46
		if (empty($id)) {
47
			$id = uniqid('progressbar');
48
		}
49

  
50
			// Assign all fluid variables
51
		$this->view->assign('id', $id);
52
		$this->view->assign('message', $this->widgetConfiguration['message']);
53
		$this->view->assign('messageText', $this->widgetConfiguration['messageText']);
54
	}
55

  
56
	/**
57
	 * @return string
58
	 */
59
	public function ajaxRequestAction() {
60
			// Generate new request from widget configuration
61
		$actionRequest = new \TYPO3\FLOW3\Mvc\ActionRequest($this->request);
62
		$actionRequest->setControllerPackageKey($this->widgetConfiguration['package']);
63
		$actionRequest->setControllerSubpackageKey($this->widgetConfiguration['subpackage']);
64
		$actionRequest->setControllerName($this->widgetConfiguration['controller']);
65
		$actionRequest->setControllerActionName($this->widgetConfiguration['action']);
66
		$actionRequest->setArguments($this->widgetConfiguration['arguments']);
67
		$actionRequest->setArgument('progressBarCounter', $this->request->getArgument('progressBarCounter'));
68

  
69
			// Call new action and return response
70
		/** @var \TYPO3\FLOW3\Mvc\Dispatcher $dispatcher */
71
		$dispatcher = $this->objectManager->get('TYPO3\FLOW3\Mvc\Dispatcher');
72
		$dispatcher->dispatch($actionRequest, $this->response);
73

  
74
		return '';
75
	}
76
}
77
?>
Classes/ViewHelpers/Widget/ProgressbarViewHelper.php (revision )
1
<?php
2
namespace TYPO3\Fluid\ViewHelpers\Widget;
3

  
4
/*                                                                        *
5
 * This script belongs to the FLOW3 package "Fluid".                      *
6
 *                                                                        *
7
 * It is free software; you can redistribute it and/or modify it under    *
8
 * the terms of the GNU Lesser General Public License, either version 3   *
9
 *  of the License, or (at your option) any later version.                *
10
 *                                                                        *
11
 * The TYPO3 project - inspiring people to share!                         *
12
 *                                                                        */
13

  
14
use TYPO3\FLOW3\Annotations as FLOW3;
15

  
16
/**
17
 * Usage:
18
 * <f:input id="name" ... />
19
 * <f:widget.progressbar id="progressbar" action="ajax" arguments="{itemsToLoad: 10}" />
20
 *
21
 * Make sure to include jQuery and jQuery UI in the HTML, like that:
22
 *    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
23
 *    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script>
24
 *    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/base/jquery-ui.css" type="text/css" media="all" />
25
 *    <link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" />
26
 *
27
 * @api
28
 */
29
class ProgressbarViewHelper extends \TYPO3\Fluid\Core\Widget\AbstractWidgetViewHelper {
30

  
31
	/**
32
	 * @var bool
33
	 */
34
	protected $ajaxWidget = TRUE;
35

  
36
	/**
37
	 * @FLOW3\Inject
38
	 * @var \TYPO3\Fluid\ViewHelpers\Widget\Controller\ProgressbarController
39
	 */
40
	protected $controller;
41

  
42
	/**
43
	 * This widget won't store it's configuration in session data but adds an serialized array to the action link.
44
	 *
45
	 * @var boolean
46
	 */
47
	protected $storeConfigurationInSession = FALSE;
48

  
49
	/**
50
	 *
51
	 * @param string $action
52
	 * @param mixed $id
53
	 * @param boolean $message
54
	 * @param string $messageText
55
	 * @param mixed $arguments
56
	 * @param mixed $controller
57
	 * @param mixed $package
58
	 * @param mixed $subpackage
59
	 * @return string
60
	 */
61
	public function render(
62
		$action, $id = NULL, $message = TRUE, $messageText = '', array $arguments = array(), $controller = NULL, $package = NULL, $subpackage = NULL
63
	) {
64
		return $this->initiateSubRequest();
65
	}
66
}
67
?>
Resources/Private/Templates/ViewHelpers/Widget/Progressbar/index.html (revision )
1
<div id="{id}"></div>
2
<f:if condition="{message}"><f:then><div id="message_{id}">{messageText}</div></f:then></f:if>
3

  
4
<script type="text/javascript">
5
	jQuery.noConflict();
6
	jQuery(document).ready(function() <![CDATA[{]]>
7
		jQuery('#{id}').progressbar(<![CDATA[{]]>
8
			value: 0
9
		});
10

  
11
		process_{id}(1);
12

  
13
		function process_{id}(progressBarCounter) <![CDATA[{]]>
14
			jQuery.ajax(<![CDATA[{]]>
15
				url: "{f:uri.widget(action: 'ajaxRequest', ajax: 1, includeWidgetContext: 1)}",
16
				data: <![CDATA[{]]>
17
					'progressBarCounter': progressBarCounter
18
				},
19
				dataType: 'json',
20
				success: function(data) <![CDATA[{]]>
21
					jQuery('#{id}').progressbar("value", data.value);
22
					<f:if condition="{message}"><f:then>jQuery('#message_{id}').html(data.messageText);</f:then></f:if>
23
					if (data.value < 100) <![CDATA[{]]>
24
						process_{id}(progressBarCounter+1);
25
					}
26
				}
27
			})
28
		}
29
	});
30
</script>
    (1-1/1)