Changeset:
8a7f1c7a9707
https://sourceforge.net/p/mrbs/hg-code/ci/8a7f1c7a97079d3bbdc56a19b06d0ce658fd6b11
Author:
Campbell Morrison <[email protected]>
Date:
Thu Feb 11 14:12:00 2016 +0000
Log message:
Converted datepicker.js.php
diffstat:
web/js.inc | 3 +-
web/js/datepicker.js.inc | 160 ++++++++++++++++++++++++++++++++++++++++++++
web/js/datepicker.js.php | 170 -----------------------------------------------
web/js/functions.js.inc | 2 +-
4 files changed, 163 insertions(+), 172 deletions(-)
diffs (truncated from 368 to 300 lines):
diff -r f7ad408ef420 -r 8a7f1c7a9707 web/js.inc
--- a/web/js.inc Thu Feb 11 14:02:32 2016 +0000
+++ b/web/js.inc Thu Feb 11 14:12:00 2016 +0000
@@ -138,6 +138,7 @@
<?php
// All pages
require 'js/functions.js.inc';
+ require 'js/datepicker.js.inc';
?>
//]]>
</script>
@@ -146,7 +147,7 @@
// All pages
?>
-<script type="text/javascript" src="js/datepicker.js.php?<?php echo
$standard_query_string ?>"></script>
+
<script type="text/javascript" src="js/general.js.php?<?php echo
$standard_query_string ?>"></script>
diff -r f7ad408ef420 -r 8a7f1c7a9707 web/js/datepicker.js.inc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/web/js/datepicker.js.inc Thu Feb 11 14:12:00 2016 +0000
@@ -0,0 +1,160 @@
+<?php
+
+// $Id$
+
+// Set the default values for datepicker
+?>
+$(function() {
+
+ $.datepicker.setDefaults({
+ showOtherMonths: true,
+ selectOtherMonths: true,
+ changeMonth: true,
+ changeYear: true,
+ duration: 'fast',
+ showWeek: <?php echo ($view_week_number) ? 'true' : 'false' ?>,
+ firstDay: <?php echo $weekstarts ?>,
+ altFormat: 'yy-mm-dd',
+ onSelect: function(dateText, inst) {datepickerSelect(inst);}
+ });
+
+});
+
+
+<?php
+// Populate the three sub-fields associated with the alt input altID
+?>
+function populateAltComponents(altId)
+{
+ var date = $('#' + altId).val().split('-');
+
+ $('#' + altId + '_year').val(date[0]);
+ $('#' + altId + '_month').val(date[1]);
+ $('#' + altId + '_day').val(date[2]);
+}
+
+
+<?php
+// Writes out the day, month and year values to the three hidden inputs
+// created by the PHP function genDateSelector(). It gets the date values
+// from the _alt input, which is the alternate field populated by datepicker
+// and is populated by datepicker with a date in yy-mm-dd format.
+//
+// (datepicker can only have one alternate field, which is why we need to write
+// to the three fields ourselves).
+//
+// Blur the datepicker input field on select, so that the datepicker will
reappear
+// if you select it. (Not quite sure why you need this. It only seems
+// to be necessary when you are using Firefox and the datepicker is draggable).
+
+// If formId is defined, submit the form
+//
+// Finally, trigger a datePickerUpdated event so that it can be dealt with
elsewhere
+// by code that relies on having updated values in the alt fields
+?>
+function datepickerSelect(inst, formId)
+{
+ var id = inst.id,
+ datepickerInput = $('#' + id);
+
+ populateAltComponents(id + '_alt');
+ datepickerInput.blur();
+
+ if (formId)
+ {
+ $('#' + formId).submit();
+ }
+
+ datepickerInput.trigger('datePickerUpdated');
+}
+
+<?php
+//
=================================================================================
+
+// Extend the init() function
+?>
+
+var oldInitDatepicker = init;
+init = function() {
+ oldInitDatepicker.apply(this);
+
+ <?php
+ // Overwrite the date selectors with a datepicker
+ ?>
+ $('span.dateselector').each(function() {
+ var span = $(this);
+ var prefix = span.data('prefix'),
+ minYear = span.data('minYear'),
+ maxYear = span.data('maxYear'),
+ formId = span.data('formId');
+ var dateData = {day: parseInt(span.data('day'), 10),
+ month: parseInt(span.data('month'), 10),
+ year: parseInt(span.data('year'), 10)};
+ var unit;
+ var initialDate = new Date(dateData.year,
+ dateData.month - 1, <?php // JavaScript
months run from 0 to 11 ?>
+ dateData.day);
+ var disabled = span.find('select').first().is(':disabled'),
+ baseId = prefix + 'datepicker';
+
+ span.empty();
+
+ <?php
+ // The next input is disabled because we don't need to pass the value
through to
+ // the form and we don't want the value cluttering up the URL (if it's a
GET).
+ // It's just used as a holder for the date in a known format so that it
can
+ // then be used by datepickerSelect() to populate the following three
inputs.
+ ?>
+ $('<input>').attr('type', 'hidden')
+ .attr('id', baseId + '_alt')
+ .attr('name', prefix + '_alt')
+ .attr('disabled', 'disabled')
+ .val(dateData.year + '-' + dateData.month + '-' +
dateData.day)
+ .appendTo(span);
+ <?php
+ // These three inputs (day, week, month) we do want
+ ?>
+ for (unit in dateData)
+ {
+ if (dateData.hasOwnProperty(unit))
+ {
+ $('<input>').attr('type', 'hidden')
+ .attr('id', baseId + '_alt_' + unit)
+ .attr('name', prefix + unit)
+ .val(dateData[unit])
+ .appendTo(span);
+ }
+ }
+ <?php // Finally the main datepicker field ?>
+ $('<input>').attr('class', 'date')
+ .attr('type', 'text')
+ .attr('id', baseId)
+ .datepicker({altField: '#' + baseId + '_alt',
+ disabled: disabled,
+ yearRange: minYear + ':' + maxYear})
+ .datepicker('setDate', initialDate)
+ .change(function() {
+ <?php // Allow the input field to be updated manually ?>
+ $(this).datepicker('setDate', $(this).val());
+ populateAltComponents(baseId + '_alt');
+ $(this).trigger('datePickerUpdated');
+ })
+ .appendTo(span);
+
+ if (formId.length > 0)
+ {
+ $('#' + baseId).datepicker('option', 'onSelect', function(dateText,
inst) {
+ datepickerSelect(inst, formId);
+ });
+ }
+
+ <?php
+ // Set the visibility to 'inherit' rather than 'visible' because the
parent
+ // element may itself be hidden, eg if multiday booking is not allowed.
+ ?>
+ span.css('visibility', 'inherit');
+
+ $('.ui-datepicker').draggable();
+ });
+};
+
diff -r f7ad408ef420 -r 8a7f1c7a9707 web/js/datepicker.js.php
--- a/web/js/datepicker.js.php Thu Feb 11 14:02:32 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,170 +0,0 @@
-<?php
-
-// $Id$
-
-require "../defaultincludes.inc";
-
-header("Content-type: application/x-javascript");
-expires_header(60*30); // 30 minute expiry
-
-if ($use_strict)
-{
- echo "'use strict';\n";
-}
-
-// Set the default values for datepicker
-?>
-$(function() {
-
- $.datepicker.setDefaults({
- showOtherMonths: true,
- selectOtherMonths: true,
- changeMonth: true,
- changeYear: true,
- duration: 'fast',
- showWeek: <?php echo ($view_week_number) ? 'true' : 'false' ?>,
- firstDay: <?php echo $weekstarts ?>,
- altFormat: 'yy-mm-dd',
- onSelect: function(dateText, inst) {datepickerSelect(inst);}
- });
-
-});
-
-
-<?php
-// Populate the three sub-fields associated with the alt input altID
-?>
-function populateAltComponents(altId)
-{
- var date = $('#' + altId).val().split('-');
-
- $('#' + altId + '_year').val(date[0]);
- $('#' + altId + '_month').val(date[1]);
- $('#' + altId + '_day').val(date[2]);
-}
-
-
-<?php
-// Writes out the day, month and year values to the three hidden inputs
-// created by the PHP function genDateSelector(). It gets the date values
-// from the _alt input, which is the alternate field populated by datepicker
-// and is populated by datepicker with a date in yy-mm-dd format.
-//
-// (datepicker can only have one alternate field, which is why we need to write
-// to the three fields ourselves).
-//
-// Blur the datepicker input field on select, so that the datepicker will
reappear
-// if you select it. (Not quite sure why you need this. It only seems
-// to be necessary when you are using Firefox and the datepicker is draggable).
-
-// If formId is defined, submit the form
-//
-// Finally, trigger a datePickerUpdated event so that it can be dealt with
elsewhere
-// by code that relies on having updated values in the alt fields
-?>
-function datepickerSelect(inst, formId)
-{
- var id = inst.id,
- datepickerInput = $('#' + id);
-
- populateAltComponents(id + '_alt');
- datepickerInput.blur();
-
- if (formId)
- {
- $('#' + formId).submit();
- }
-
- datepickerInput.trigger('datePickerUpdated');
-}
-
-<?php
-//
=================================================================================
-
-// Extend the init() function
-?>
-
-var oldInitDatepicker = init;
-init = function() {
- oldInitDatepicker.apply(this);
-
- <?php
- // Overwrite the date selectors with a datepicker
- ?>
- $('span.dateselector').each(function() {
- var span = $(this);
- var prefix = span.data('prefix'),
- minYear = span.data('minYear'),
- maxYear = span.data('maxYear'),
- formId = span.data('formId');
- var dateData = {day: parseInt(span.data('day'), 10),
- month: parseInt(span.data('month'), 10),
- year: parseInt(span.data('year'), 10)};
- var unit;
- var initialDate = new Date(dateData.year,
- dateData.month - 1, <?php // JavaScript
months run from 0 to 11 ?>
- dateData.day);
- var disabled = span.find('select').first().is(':disabled'),
- baseId = prefix + 'datepicker';
-
- span.empty();
-
- <?php
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits