1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00

Merge branch 'master' into redesign-2015

This commit is contained in:
epriestley 2015-06-15 14:06:48 -07:00
commit 6af1c02f06
14 changed files with 351 additions and 84 deletions

View file

@ -443,7 +443,7 @@ return array(
'rsrc/js/core/behavior-device.js' => 'a205cf28', 'rsrc/js/core/behavior-device.js' => 'a205cf28',
'rsrc/js/core/behavior-drag-and-drop-textarea.js' => '6d49590e', 'rsrc/js/core/behavior-drag-and-drop-textarea.js' => '6d49590e',
'rsrc/js/core/behavior-error-log.js' => '6882e80a', 'rsrc/js/core/behavior-error-log.js' => '6882e80a',
'rsrc/js/core/behavior-fancy-datepicker.js' => '510b5809', 'rsrc/js/core/behavior-fancy-datepicker.js' => 'ea5cec5d',
'rsrc/js/core/behavior-file-tree.js' => '88236f00', 'rsrc/js/core/behavior-file-tree.js' => '88236f00',
'rsrc/js/core/behavior-form.js' => '5c54cbf3', 'rsrc/js/core/behavior-form.js' => '5c54cbf3',
'rsrc/js/core/behavior-gesture.js' => '3ab51e2c', 'rsrc/js/core/behavior-gesture.js' => '3ab51e2c',
@ -467,7 +467,7 @@ return array(
'rsrc/js/core/behavior-scrollbar.js' => '834a1173', 'rsrc/js/core/behavior-scrollbar.js' => '834a1173',
'rsrc/js/core/behavior-search-typeahead.js' => '048330fa', 'rsrc/js/core/behavior-search-typeahead.js' => '048330fa',
'rsrc/js/core/behavior-select-on-click.js' => '4e3e79a6', 'rsrc/js/core/behavior-select-on-click.js' => '4e3e79a6',
'rsrc/js/core/behavior-time-typeahead.js' => '8bfbb401', 'rsrc/js/core/behavior-time-typeahead.js' => 'f80d6bf0',
'rsrc/js/core/behavior-toggle-class.js' => '5d7c9f33', 'rsrc/js/core/behavior-toggle-class.js' => '5d7c9f33',
'rsrc/js/core/behavior-tokenizer.js' => 'b3a4b884', 'rsrc/js/core/behavior-tokenizer.js' => 'b3a4b884',
'rsrc/js/core/behavior-tooltip.js' => '3ee3408b', 'rsrc/js/core/behavior-tooltip.js' => '3ee3408b',
@ -575,7 +575,7 @@ return array(
'javelin-behavior-durable-column' => 'c72aa091', 'javelin-behavior-durable-column' => 'c72aa091',
'javelin-behavior-error-log' => '6882e80a', 'javelin-behavior-error-log' => '6882e80a',
'javelin-behavior-event-all-day' => '38dcf3c8', 'javelin-behavior-event-all-day' => '38dcf3c8',
'javelin-behavior-fancy-datepicker' => '510b5809', 'javelin-behavior-fancy-datepicker' => 'ea5cec5d',
'javelin-behavior-global-drag-and-drop' => 'c8e57404', 'javelin-behavior-global-drag-and-drop' => 'c8e57404',
'javelin-behavior-herald-rule-editor' => '7ebaeed3', 'javelin-behavior-herald-rule-editor' => '7ebaeed3',
'javelin-behavior-high-security-warning' => 'a464fe03', 'javelin-behavior-high-security-warning' => 'a464fe03',
@ -643,7 +643,7 @@ return array(
'javelin-behavior-slowvote-embed' => '887ad43f', 'javelin-behavior-slowvote-embed' => '887ad43f',
'javelin-behavior-stripe-payment-form' => '3f5d6dbf', 'javelin-behavior-stripe-payment-form' => '3f5d6dbf',
'javelin-behavior-test-payment-form' => 'fc91ab6c', 'javelin-behavior-test-payment-form' => 'fc91ab6c',
'javelin-behavior-time-typeahead' => '8bfbb401', 'javelin-behavior-time-typeahead' => 'f80d6bf0',
'javelin-behavior-toggle-class' => '5d7c9f33', 'javelin-behavior-toggle-class' => '5d7c9f33',
'javelin-behavior-typeahead-browse' => '635de1ec', 'javelin-behavior-typeahead-browse' => '635de1ec',
'javelin-behavior-typeahead-search' => '93d0c9e3', 'javelin-behavior-typeahead-search' => '93d0c9e3',
@ -1172,13 +1172,6 @@ return array(
'javelin-typeahead-source', 'javelin-typeahead-source',
'javelin-util', 'javelin-util',
), ),
'510b5809' => array(
'javelin-behavior',
'javelin-util',
'javelin-dom',
'javelin-stratcom',
'javelin-vector',
),
'519705ea' => array( '519705ea' => array(
'javelin-install', 'javelin-install',
'javelin-dom', 'javelin-dom',
@ -1518,14 +1511,6 @@ return array(
'javelin-request', 'javelin-request',
'javelin-typeahead-source', 'javelin-typeahead-source',
), ),
'8bfbb401' => array(
'javelin-behavior',
'javelin-util',
'javelin-dom',
'javelin-stratcom',
'javelin-vector',
'javelin-typeahead-static-source',
),
'8ce821c5' => array( '8ce821c5' => array(
'phabricator-notification', 'phabricator-notification',
'javelin-stratcom', 'javelin-stratcom',
@ -1953,6 +1938,13 @@ return array(
'javelin-dom', 'javelin-dom',
'phabricator-draggable-list', 'phabricator-draggable-list',
), ),
'ea5cec5d' => array(
'javelin-behavior',
'javelin-util',
'javelin-dom',
'javelin-stratcom',
'javelin-vector',
),
'ea681761' => array( 'ea681761' => array(
'javelin-behavior', 'javelin-behavior',
'javelin-aphlict', 'javelin-aphlict',
@ -1998,6 +1990,14 @@ return array(
'javelin-typeahead-ondemand-source', 'javelin-typeahead-ondemand-source',
'javelin-util', 'javelin-util',
), ),
'f80d6bf0' => array(
'javelin-behavior',
'javelin-util',
'javelin-dom',
'javelin-stratcom',
'javelin-vector',
'javelin-typeahead-static-source',
),
'f829edb3' => array( 'f829edb3' => array(
'javelin-view', 'javelin-view',
'javelin-install', 'javelin-install',

View file

@ -191,7 +191,7 @@ final class PhabricatorCalendarEventEditController
PhabricatorCalendarEventTransaction::TYPE_NAME) PhabricatorCalendarEventTransaction::TYPE_NAME)
->setNewValue($name); ->setNewValue($name);
if ($is_parent && $this->isCreate()) { if ($is_recurring && $this->isCreate()) {
$xactions[] = id(new PhabricatorCalendarEventTransaction()) $xactions[] = id(new PhabricatorCalendarEventTransaction())
->setTransactionType( ->setTransactionType(
PhabricatorCalendarEventTransaction::TYPE_RECURRING) PhabricatorCalendarEventTransaction::TYPE_RECURRING)
@ -210,7 +210,7 @@ final class PhabricatorCalendarEventEditController
} }
} }
if (($is_parent && $this->isCreate()) || !$is_parent) { if (($is_recurring && $this->isCreate()) || !$is_parent) {
$xactions[] = id(new PhabricatorCalendarEventTransaction()) $xactions[] = id(new PhabricatorCalendarEventTransaction())
->setTransactionType( ->setTransactionType(
PhabricatorCalendarEventTransaction::TYPE_ALL_DAY) PhabricatorCalendarEventTransaction::TYPE_ALL_DAY)

View file

@ -315,8 +315,14 @@ final class ConpherenceWidgetController extends ConpherenceController {
$user, $user,
$time_str); $time_str);
$secondary_info = pht('%s, %s', if (isset($handles[$status->getUserPHID()])) {
$handles[$status->getUserPHID()]->getName(), $epoch_range); $secondary_info = pht(
'%s, %s',
$handles[$status->getUserPHID()]->getName(),
$epoch_range);
} else {
$secondary_info = $epoch_range;
}
$content[] = phutil_tag( $content[] = phutil_tag(
'div', 'div',

View file

@ -179,6 +179,7 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
$xatoms = id(new DivinerAtomQuery()) $xatoms = id(new DivinerAtomQuery())
->setViewer($this->getViewer()) ->setViewer($this->getViewer())
->withNames($names) ->withNames($names)
->withGhosts(false)
->needExtends(true) ->needExtends(true)
->needAtoms(true) ->needAtoms(true)
->needChildren($this->needChildren) ->needChildren($this->needChildren)

View file

@ -10,6 +10,10 @@ final class DivinerAtomSearchIndexer extends PhabricatorSearchDocumentIndexer {
$atom = $this->loadDocumentByPHID($phid); $atom = $this->loadDocumentByPHID($phid);
$book = $atom->getBook(); $book = $atom->getBook();
if (!$atom->getIsDocumentable()) {
return null;
}
$doc = $this->newDocument($phid) $doc = $this->newDocument($phid)
->setDocumentTitle($atom->getTitle()) ->setDocumentTitle($atom->getTitle())
->setDocumentCreated($book->getDateCreated()) ->setDocumentCreated($book->getDateCreated())

View file

@ -2,6 +2,8 @@
abstract class HarbormasterBuildStepImplementation extends Phobject { abstract class HarbormasterBuildStepImplementation extends Phobject {
private $settings;
public static function getImplementations() { public static function getImplementations() {
return id(new PhutilSymbolLoader()) return id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__) ->setAncestorClass(__CLASS__)

View file

@ -19,6 +19,7 @@ final class PhabricatorDateTimeSettingsPanel extends PhabricatorSettingsPanel {
$username = $user->getUsername(); $username = $user->getUsername();
$pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT; $pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
$pref_date = PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT;
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY; $pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
$preferences = $user->loadPreferences(); $preferences = $user->loadPreferences();
@ -31,12 +32,16 @@ final class PhabricatorDateTimeSettingsPanel extends PhabricatorSettingsPanel {
$errors[] = pht('The selected timezone is not a valid timezone.'); $errors[] = pht('The selected timezone is not a valid timezone.');
} }
$preferences->setPreference( $preferences
$pref_time, ->setPreference(
$request->getStr($pref_time)); $pref_time,
$preferences->setPreference( $request->getStr($pref_time))
$pref_week_start, ->setPreference(
$request->getStr($pref_week_start)); $pref_date,
$request->getStr($pref_date))
->setPreference(
$pref_week_start,
$request->getStr($pref_week_start));
if (!$errors) { if (!$errors) {
$preferences->save(); $preferences->save();
@ -69,6 +74,18 @@ final class PhabricatorDateTimeSettingsPanel extends PhabricatorSettingsPanel {
->setCaption( ->setCaption(
pht('Format used when rendering a time of day.')) pht('Format used when rendering a time of day.'))
->setValue($preferences->getPreference($pref_time))) ->setValue($preferences->getPreference($pref_time)))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Date Format'))
->setName($pref_date)
->setOptions(array(
'Y-m-d' => pht('ISO 8601 (2000-02-28)'),
'n/j/Y' => pht('US (2/28/2000)'),
'd-m-Y' => pht('European (28-02-2000)'),
))
->setCaption(
pht('Format used when rendering a date.'))
->setValue($preferences->getPreference($pref_date)))
->appendChild( ->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
->setLabel(pht('Week Starts On')) ->setLabel(pht('Week Starts On'))

View file

@ -8,6 +8,7 @@ final class PhabricatorUserPreferences extends PhabricatorUserDAO {
const PREFERENCE_MULTIEDIT = 'multiedit'; const PREFERENCE_MULTIEDIT = 'multiedit';
const PREFERENCE_TITLES = 'titles'; const PREFERENCE_TITLES = 'titles';
const PREFERENCE_MONOSPACED_TEXTAREAS = 'monospaced-textareas'; const PREFERENCE_MONOSPACED_TEXTAREAS = 'monospaced-textareas';
const PREFERENCE_DATE_FORMAT = 'date-format';
const PREFERENCE_TIME_FORMAT = 'time-format'; const PREFERENCE_TIME_FORMAT = 'time-format';
const PREFERENCE_WEEK_START_DAY = 'week-start-day'; const PREFERENCE_WEEK_START_DAY = 'week-start-day';

View file

@ -15,6 +15,7 @@ final class PhabricatorBot extends PhabricatorDaemon {
private $conduit; private $conduit;
private $config; private $config;
private $pollFrequency; private $pollFrequency;
private $protocolAdapter;
protected function run() { protected function run() {
$argv = $this->getArgv(); $argv = $this->getArgv();

View file

@ -127,7 +127,29 @@ final class AphrontFormDateControl extends AphrontFormControl {
} }
private function getDateInputValue() { private function getDateInputValue() {
return $this->valueDate; $date_format = $this->getDateFormat();
$timezone = $this->getTimezone();
$datetime = new DateTime($this->valueDate, $timezone);
$date = $datetime->format($date_format);
return $date;
}
private function getTimeFormat() {
$viewer = $this->getUser();
$preferences = $viewer->loadPreferences();
$pref_time_format = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
return $preferences->getPreference($pref_time_format, 'g:i A');
}
private function getDateFormat() {
$viewer = $this->getUser();
$preferences = $viewer->loadPreferences();
$pref_date_format = PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT;
return $preferences->getPreference($pref_date_format, 'Y-m-d');
} }
private function getTimeInputValue() { private function getTimeInputValue() {
@ -219,6 +241,7 @@ final class AphrontFormDateControl extends AphrontFormControl {
'startTimeID' => $time_id, 'startTimeID' => $time_id,
'endTimeID' => $this->endDateID, 'endTimeID' => $this->endDateID,
'timeValues' => $values, 'timeValues' => $values,
'format' => $this->getTimeFormat(),
)); ));
@ -242,7 +265,9 @@ final class AphrontFormDateControl extends AphrontFormControl {
), ),
$time_sel); $time_sel);
Javelin::initBehavior('fancy-datepicker', array()); Javelin::initBehavior('fancy-datepicker', array(
'format' => $this->getDateFormat(),
));
$classes = array(); $classes = array();
$classes[] = 'aphront-form-date-container'; $classes[] = 'aphront-form-date-container';
@ -319,20 +344,31 @@ final class AphrontFormDateControl extends AphrontFormControl {
} }
private function getTimeTypeaheadValues() { private function getTimeTypeaheadValues() {
$time_format = $this->getTimeFormat();
$times = array(); $times = array();
$am_pm_list = array('AM', 'PM');
foreach ($am_pm_list as $am_pm) { if ($time_format == 'g:i A') {
for ($hour = 0; $hour < 12; $hour++) { $am_pm_list = array('AM', 'PM');
$actual_hour = ($hour == 0) ? 12 : $hour;
$times[] = $actual_hour.':00 '.$am_pm; foreach ($am_pm_list as $am_pm) {
$times[] = $actual_hour.':30 '.$am_pm; for ($hour = 0; $hour < 12; $hour++) {
$actual_hour = ($hour == 0) ? 12 : $hour;
$times[] = $actual_hour.':00 '.$am_pm;
$times[] = $actual_hour.':30 '.$am_pm;
}
}
} else if ($time_format == 'H:i') {
for ($hour = 0; $hour < 24; $hour++) {
$written_hour = ($hour > 9) ? $hour : '0'.$hour;
$times[] = $written_hour.':00';
$times[] = $written_hour.':30';
} }
} }
foreach ($times as $key => $time) { foreach ($times as $key => $time) {
$times[$key] = array($key, $time); $times[$key] = array($key, $time);
} }
return $times; return $times;
} }

View file

@ -10,6 +10,7 @@ final class AphrontFormDateControlValue extends Phobject {
private $zone; private $zone;
private $optional; private $optional;
public function getValueDate() { public function getValueDate() {
return $this->valueDate; return $this->valueDate;
} }
@ -65,8 +66,13 @@ final class AphrontFormDateControlValue extends Phobject {
$value = new AphrontFormDateControlValue(); $value = new AphrontFormDateControlValue();
$value->viewer = $viewer; $value->viewer = $viewer;
$value->valueDate = $month.'/'.$day.'/'.$year; list($value->valueDate, $value->valueTime) =
$value->valueTime = coalesce($time, '12:00 AM'); $value->getFormattedDateFromParts(
$year,
$month,
$day,
coalesce($time, '12:00 AM'),
$value);
$value->valueEnabled = $enabled; $value->valueEnabled = $enabled;
return $value; return $value;
@ -75,10 +81,14 @@ final class AphrontFormDateControlValue extends Phobject {
public static function newFromRequest(AphrontRequest $request, $key) { public static function newFromRequest(AphrontRequest $request, $key) {
$value = new AphrontFormDateControlValue(); $value = new AphrontFormDateControlValue();
$value->viewer = $request->getViewer(); $value->viewer = $request->getViewer();
$value->valueDate = $request->getStr($key.'_d');
$value->valueTime = $request->getStr($key.'_t');
$value->valueEnabled = $request->getStr($key.'_e');
list($value->valueDate, $value->valueTime) =
$value->getFormattedDateFromDate(
$request->getStr($key.'_d'),
$request->getStr($key.'_t'),
$value);
$value->valueEnabled = $request->getStr($key.'_e');
return $value; return $value;
} }
@ -91,10 +101,15 @@ final class AphrontFormDateControlValue extends Phobject {
$year = $readable[0]; $year = $readable[0];
$month = $readable[1]; $month = $readable[1];
$day = $readable[2]; $day = $readable[2];
$time = $readable[3];
$value->valueDate = $month.'/'.$day.'/'.$year; list($value->valueDate, $value->valueTime) =
$value->valueTime = $readable[3]; $value->getFormattedDateFromParts(
$year,
$month,
$day,
$time,
$value);
return $value; return $value;
} }
@ -105,8 +120,12 @@ final class AphrontFormDateControlValue extends Phobject {
$value = new AphrontFormDateControlValue(); $value = new AphrontFormDateControlValue();
$value->viewer = $viewer; $value->viewer = $viewer;
$value->valueDate = idx($dictionary, 'd'); list($value->valueDate, $value->valueTime) =
$value->valueTime = idx($dictionary, 't'); $value->getFormattedDateFromDate(
idx($dictionary, 'd'),
idx($dictionary, 't'),
$value);
$value->valueEnabled = idx($dictionary, 'e'); $value->valueEnabled = idx($dictionary, 'e');
return $value; return $value;
@ -185,6 +204,67 @@ final class AphrontFormDateControlValue extends Phobject {
return $value; return $value;
} }
private function getTimeFormat() {
$preferences = $this->viewer->loadPreferences();
$pref_time_format = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
return $preferences->getPreference($pref_time_format, 'g:i A');
}
private function getDateFormat() {
$preferences = $this->viewer->loadPreferences();
$pref_date_format = PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT;
return $preferences->getPreference($pref_date_format, 'Y-m-d');
}
private function getFormattedDateFromDate($date, $time, $value) {
$original_input = $date;
$zone = $value->getTimezone();
$separator = $value->getFormatSeparator();
$parts = preg_split('@[,./:-]@', $date);
$date = implode($separator, $parts);
$date = id(new DateTime($date, $zone));
if ($date) {
$date = $date->format($value->getDateFormat());
} else {
$date = $original_input;
}
$date = id(new DateTime("{$date} {$time}", $zone));
return array(
$date->format($value->getDateFormat()),
$date->format($value->getTimeFormat()),
);
}
private function getFormattedDateFromParts(
$year,
$month,
$day,
$time,
$value) {
$zone = $value->getTimezone();
$date_time = id(new DateTime("{$year}-{$month}-{$day} {$time}", $zone));
return array(
$date_time->format($value->getDateFormat()),
$date_time->format($value->getTimeFormat()),
);
}
private function getFormatSeparator() {
$format = $this->getDateFormat();
switch ($format) {
case 'n/j/Y':
return '/';
default:
return '-';
}
}
public function getDateTime() { public function getDateTime() {
$epoch = $this->getEpoch(); $epoch = $this->getEpoch();
$date = null; $date = null;

View file

@ -141,6 +141,12 @@ final class PHUICalendarListView extends AphrontTagView {
} }
private function getEventTooltip(AphrontCalendarEventView $event) { private function getEventTooltip(AphrontCalendarEventView $event) {
$viewer = $this->getUser();
$preferences = $viewer->loadPreferences();
$time_pref = $preferences->getPreference(
PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT,
'g:i A');
Javelin::initBehavior('phabricator-tooltips'); Javelin::initBehavior('phabricator-tooltips');
$start = id(AphrontFormDateControlValue::newFromEpoch( $start = id(AphrontFormDateControlValue::newFromEpoch(
@ -166,13 +172,13 @@ final class PHUICalendarListView extends AphrontTagView {
if ($start->getValueDate() == $end->getValueDate()) { if ($start->getValueDate() == $end->getValueDate()) {
$tip = pht( $tip = pht(
'%s - %s', '%s - %s',
$start->getValueAsFormat('g:i A'), $start->getValueAsFormat($time_pref),
$end->getValueAsFormat('g:i A')); $end->getValueAsFormat($time_pref));
} else { } else {
$tip = pht( $tip = pht(
'%s - %s', '%s - %s',
$start->getValueAsFormat('M j, Y, g:i A'), $start->getValueAsFormat('M j, Y, '.$time_pref),
$end->getValueAsFormat('M j, Y, g:i A')); $end->getValueAsFormat('M j, Y, '.$time_pref));
} }
} }
return $tip; return $tip;

View file

@ -7,7 +7,11 @@
* javelin-vector * javelin-vector
*/ */
JX.behavior('fancy-datepicker', function() { JX.behavior('fancy-datepicker', function(config, statics) {
if (statics.initialized) {
return;
}
statics.initialized = true;
var picker; var picker;
var root; var root;
@ -16,6 +20,32 @@ JX.behavior('fancy-datepicker', function() {
var value_m; var value_m;
var value_d; var value_d;
var get_format_separator = function() {
var format = get_format();
switch (format.toLowerCase()) {
case 'n/j/y':
return '/';
default:
return '-';
}
};
var get_key_maps = function() {
var format = get_format();
var regex = new RegExp('[./ -]');
return format.split(regex);
};
var get_format = function() {
var format = config.format;
if (format === null) {
format = 'Y-m-d';
}
return format;
};
var onopen = function(e) { var onopen = function(e) {
e.kill(); e.kill();
@ -85,18 +115,76 @@ JX.behavior('fancy-datepicker', function() {
}; };
}; };
var read_date = function() { var read_date = function(){
var i = get_inputs(); var inputs = get_inputs();
var date = i.d.value; var date = inputs.d.value;
var parts = date.split('/'); var regex = new RegExp('[./ -]');
value_y = +parts[2]; var date_parts = date.split(regex);
value_m = +parts[0]; var map = get_key_maps();
value_d = +parts[1];
for (var i=0; i < date_parts.length; i++) {
var key = map[i].toLowerCase();
switch (key) {
case 'y':
value_y = date_parts[i];
break;
case 'm':
value_m = date_parts[i];
break;
case 'd':
value_d = date_parts[i];
break;
}
}
}; };
var write_date = function() { var write_date = function() {
var i = get_inputs(); var inputs = get_inputs();
i.d.value = value_m + '/' + value_d + '/' + value_y; var map = get_key_maps();
var arr_values = [];
for(var i=0; i < map.length; i++) {
switch (map[i].toLowerCase()) {
case 'y':
arr_values[i] = value_y;
break;
case 'm':
arr_values[i] = value_m;
break;
case 'n':
arr_values[i] = value_m;
break;
case 'd':
arr_values[i] = value_d;
break;
case 'j':
arr_values[i] = value_d;
break;
}
}
var text_value = '';
var separator = get_format_separator();
for(var j=0; j < arr_values.length; j++) {
var element = arr_values[j];
var format = get_format();
if ((format.toLowerCase() === 'd-m-y' ||
format.toLowerCase() === 'y-m-d') &&
element < 10) {
element = '0' + element;
}
if (text_value.length === 0) {
text_value += element;
} else {
text_value = text_value + separator + element;
}
}
inputs.d.value = text_value;
}; };
var render = function() { var render = function() {

View file

@ -11,6 +11,7 @@
JX.behavior('time-typeahead', function(config) { JX.behavior('time-typeahead', function(config) {
var start_date_control = JX.$(config.startTimeID); var start_date_control = JX.$(config.startTimeID);
var end_date_control = config.endTimeID ? JX.$(config.endTimeID) : null; var end_date_control = config.endTimeID ? JX.$(config.endTimeID) : null;
var format = config.format;
var end_date_tampered = false; var end_date_tampered = false;
@ -79,7 +80,7 @@ JX.behavior('time-typeahead', function(config) {
function getNewValue(time) { function getNewValue(time) {
var regex = /^([01]?\d)(?::([0-5]\d))?\s*((am|pm))?$/i; var regex = /^([0-2]?\d)(?::([0-5]\d))?\s*((am|pm))?$/i;
if (!regex.test(time)) { if (!regex.test(time)) {
return null; return null;
@ -90,32 +91,56 @@ JX.behavior('time-typeahead', function(config) {
var minutes = parseInt(results[2], 10) ? parseInt(results[2], 10) : 0; var minutes = parseInt(results[2], 10) ? parseInt(results[2], 10) : 0;
var real_time = 0; var real_time = 0;
var end_value = '';
if (/pm/i.test(results[3])) { var end_hours;
real_time = 12*60; var end_minutes;
} else if (/am/i.test(results[3]) && hours == 12) {
hours = 0; if (format === 'H:i' && hours < 23) {
end_hours = hours + 1;
if (end_hours > 9) {
end_hours = end_hours.toString();
} else {
end_hours = '0' + end_hours.toString();
}
if (minutes > 9) {
end_minutes = minutes.toString();
} else {
end_minutes = '0' + minutes.toString();
}
end_value = end_hours + ':' + end_minutes;
} else if (format === 'g:i A') {
if (/pm/i.test(results[3])) {
real_time = 12*60;
} else if (/am/i.test(results[3]) && hours == 12) {
hours = 0;
}
real_time = real_time + (hours * 60) + minutes;
var end_time = real_time + 60;
var end_meridian = 'AM';
end_hours = Math.floor(end_time / 60);
if (end_hours == 12) {
end_meridian = 'PM';
} else if (end_hours > 12 && end_hours < 24) {
end_hours = end_hours - 12;
end_meridian = 'PM';
} else if (end_hours == 24) {
end_hours = end_hours - 12;
}
end_minutes = end_time%60;
end_minutes = (end_minutes < 9) ? end_minutes : ('0' + end_minutes);
end_value = end_hours + ':' + end_minutes + ' ' + end_meridian;
} }
real_time = real_time + (hours * 60) + minutes;
var end_time = real_time + 60;
var end_meridian = 'AM';
var end_hours = Math.floor(end_time / 60);
if (end_hours == 12) {
end_meridian = 'PM';
} else if (end_hours > 12 && end_hours < 24) {
end_hours = end_hours - 12;
end_meridian = 'PM';
} else if (end_hours == 24) {
end_hours = end_hours - 12;
}
var end_minutes = end_time%60;
end_minutes = (end_minutes > 9) ? end_minutes : ('0' + end_minutes);
var end_value = end_hours + ':' + end_minutes + ' ' + end_meridian;
return end_value; return end_value;
} }