Load the timezones via select2
This commit is contained in:
parent
2734ff7d4e
commit
ea4c6bd285
6 changed files with 65 additions and 9 deletions
|
@ -25,5 +25,6 @@ return [
|
|||
['name' => 'flowOperations#addOperation', 'url' => '/operations', 'verb' => 'POST'],
|
||||
['name' => 'flowOperations#updateOperation', 'url' => '/operations/{id}', 'verb' => 'PUT'],
|
||||
['name' => 'flowOperations#deleteOperation', 'url' => '/operations/{id}', 'verb' => 'DELETE'],
|
||||
['name' => 'requestTime#getTimezones', 'url' => '/timezones', 'verb' => 'GET'],
|
||||
]
|
||||
];
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -30,6 +30,7 @@ class Application extends \OCP\AppFramework\App {
|
|||
parent::__construct('workflowengine');
|
||||
|
||||
$this->getContainer()->registerAlias('FlowOperationsController', 'OCA\WorkflowEngine\Controller\FlowOperations');
|
||||
$this->getContainer()->registerAlias('RequestTimeController', 'OCA\WorkflowEngine\Controller\RequestTime');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,6 +52,8 @@ class Application extends \OCP\AppFramework\App {
|
|||
'systemtags/systemtagscollection',
|
||||
]);
|
||||
|
||||
vendor_script('jsTimezoneDetect/jstz');
|
||||
|
||||
script('workflowengine', [
|
||||
'admin',
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ use OCP\WorkflowEngine\ICheck;
|
|||
class RequestTime implements ICheck {
|
||||
|
||||
const REGEX_TIME = '([0-1][0-9]|2[0-3]):([0-5][0-9])';
|
||||
const REGEX_TIMEZONE = '([a-zA-Z]+(?:\\\\\\/[a-zA-Z\-\_]+)+)';
|
||||
const REGEX_TIMEZONE = '([a-zA-Z]+(?:\\/[a-zA-Z\-\_]+)+)';
|
||||
|
||||
/** @var bool[] */
|
||||
protected $cachedResults;
|
||||
|
@ -110,16 +110,15 @@ class RequestTime implements ICheck {
|
|||
throw new \UnexpectedValueException('Invalid time limits', 2);
|
||||
}
|
||||
|
||||
try {
|
||||
new \DateTimeZone(stripslashes($matches[3]));
|
||||
} catch(\Exception $e) {
|
||||
throw new \UnexpectedValueException('Invalid timezone1', 3);
|
||||
$values = json_decode($value, true);
|
||||
$time1 = \DateTime::createFromFormat('H:i e', $values[0]);
|
||||
if ($time1 === false) {
|
||||
throw new \UnexpectedValueException('Invalid start time given', 3);
|
||||
}
|
||||
|
||||
try {
|
||||
new \DateTimeZone(stripslashes($matches[6]));
|
||||
} catch(\Exception $e) {
|
||||
throw new \UnexpectedValueException('Invalid timezone2', 3);
|
||||
$time2 = \DateTime::createFromFormat('H:i e', $values[1]);
|
||||
if ($time2 === false) {
|
||||
throw new \UnexpectedValueException('Invalid end time given', 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
53
apps/workflowengine/lib/Controller/RequestTime.php
Normal file
53
apps/workflowengine/lib/Controller/RequestTime.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\WorkflowEngine\Controller;
|
||||
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
class RequestTime extends Controller {
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param string $search
|
||||
* @return JSONResponse
|
||||
*/
|
||||
public function getTimezones($search = '') {
|
||||
$timezones = \DateTimeZone::listIdentifiers();
|
||||
|
||||
if ($search !== '') {
|
||||
$timezones = array_filter($timezones, function ($timezone) use ($search) {
|
||||
return strpos(strtolower($timezone), strtolower($search)) !== false;
|
||||
});
|
||||
}
|
||||
|
||||
$timezones = array_slice($timezones, 0, 10);
|
||||
|
||||
$response = [];
|
||||
foreach ($timezones as $timezone) {
|
||||
$response[$timezone] = $timezone;
|
||||
}
|
||||
return new JSONResponse($response);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue