From 50b922f58816e9ae7e270e7e04ca0aa5e6bad50d Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 20 Feb 2013 17:38:34 -0800 Subject: [PATCH] News datestamp now retains value when editing. Updated datetime picker. --- e107_admin/newspost.php | 14 +- e107_handlers/date_handler.php | 2 +- e107_web/js/core/all.jquery.js | 26 +- e107_web/js/jquery-ui-timepicker-addon.js | 3449 ++++++++++++--------- 4 files changed, 1954 insertions(+), 1537 deletions(-) diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index ad0524661..c833bdd5e 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -1974,6 +1974,14 @@ class admin_newspost else { // $text .= $frm->selectbox("cat_id",$this->news_category,$_POST['cat_id']); + $catopt = array(); + foreach ($this->news_categories as $row) + { + $catopt[$row['category_id']] = $tp->toHTML($row['category_name'], FALSE, "LINKTEXT"); + } + + $text .= $frm->selectbox("cat_id", $catopt, $_POST['cat_id']); + /* $text .= $frm->select_open('cat_id'); foreach ($this->news_categories as $row) @@ -1981,6 +1989,8 @@ class admin_newspost $text .= $frm->option($tp->toHTML($row['category_name'], FALSE, "LINKTEXT"), $row['category_id'], varset($_POST['cat_id']) == $row['category_id']); } $text .= ""; + */ + } $text .= " @@ -2012,7 +2022,7 @@ class admin_newspost "; //XXX multiple-selections at once. (comma separated) - working - $text .= $frm->selectbox('news_render_type', $this->news_renderTypes, vartrue($_POST['news_render_type']), "multiple=1",array(NWSLAN_74))." + $text .= $frm->selectbox('news_render_type', $this->news_renderTypes, vartrue($_POST['news_render_type']), "multiple=1")."
".NWSLAN_74."
@@ -2255,7 +2265,7 @@ class admin_newspost
"; - $text .= $frm->datepicker("news_datestamp",vartrue($_POST['news_datestamp']),"type=datetime"); + $text .= $frm->datepicker("news_datestamp",vartrue($_POST['news_datestamp']),"type=date"); //XXX should be 'datetime' when working correctly. $text .= "
"; /* diff --git a/e107_handlers/date_handler.php b/e107_handlers/date_handler.php index fd0b47d99..41f3ade2e 100644 --- a/e107_handlers/date_handler.php +++ b/e107_handlers/date_handler.php @@ -110,7 +110,7 @@ class convert function toMask($mask, $legacy = false) { $convert = array( - '%Y' => 'yy', + '%Y' => 'yyyy', // jquery-ui docs say 'yy' but yy produces '13' instead of '2013' '%d' => 'dd', '%m' => 'mm', '%B' => 'MM', // Full month name, based on the locale diff --git a/e107_web/js/core/all.jquery.js b/e107_web/js/core/all.jquery.js index 70a966d79..0067261c8 100644 --- a/e107_web/js/core/all.jquery.js +++ b/e107_web/js/core/all.jquery.js @@ -157,7 +157,17 @@ $(document).ready(function() // Dates -------------------------------------------------- - + /* + // http://tarruda.github.com/bootstrap-datetimepicker/ + // $('.e-datetime').datetimepicker(); + + $('.e-datetime').datetimepicker({ + language: 'en', + pick12HourFormat: true + }); + + */ + $("input.e-date").each(function() { $(this).datepicker({ dateFormat: $(this).attr("data-date-format"), @@ -168,15 +178,23 @@ $(document).ready(function() }); $("input.e-datetime").each(function() { + // var name = $(this).attr("name"); + // var val = $(this).val(); + + // alert(name + ': ' + val); + $(this).datetimepicker({ dateFormat: $(this).attr("data-date-format"), timeFormat: $(this).attr("data-time-format"), + defaultDate: $(this).val(), + defaultValue: $(this).val(), + setDate: $(this).val(), ampm: $(this).attr("data-date-ampm"), - firstDay: $(this).attr("data-date-firstday"), + // firstDay: $(this).attr("data-date-firstday"), showButtonPanel: true }); }); - + // Inline versions $("div.e-date").each(function() { var id = $(this).attr("id"); @@ -207,7 +225,7 @@ $(document).ready(function() $(this).datetimepicker('setDate', $("#"+newid).val()); }); - + // Tabs ----------------------------------------------------- diff --git a/e107_web/js/jquery-ui-timepicker-addon.js b/e107_web/js/jquery-ui-timepicker-addon.js index f21da0acd..f9b5faa2d 100644 --- a/e107_web/js/jquery-ui-timepicker-addon.js +++ b/e107_web/js/jquery-ui-timepicker-addon.js @@ -1,1530 +1,1919 @@ -/* -* jQuery timepicker addon -* By: Trent Richardson [http://trentrichardson.com] -* Version 1.0.1 -* Last Modified: 07/01/2012 -* -* Copyright 2012 Trent Richardson -* You may use this project under MIT or GPL licenses. -* http://trentrichardson.com/Impromptu/GPL-LICENSE.txt -* http://trentrichardson.com/Impromptu/MIT-LICENSE.txt -* -* HERES THE CSS: -* .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-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; } -*/ - -/*jslint evil: true, maxlen: 300, white: false, undef: false, nomen: false, onevar: false */ - -(function($) { - -// Prevent "Uncaught RangeError: Maximum call stack size exceeded" -$.ui.timepicker = $.ui.timepicker || {}; -if ($.ui.timepicker.version) { - return; -} - -$.extend($.ui, { timepicker: { version: "1.0.1" } }); - -/* Time picker manager. - Use the singleton instance of this class, $.timepicker, to interact with the time picker. - Settings for (groups of) time pickers are maintained in an instance object, - allowing multiple different settings on the same page. */ - -function Timepicker() { - this.regional = []; // Available regional settings, indexed by language code - this.regional[''] = { // Default regional settings - currentText: 'Now', - closeText: 'Done', - ampm: false, - amNames: ['AM', 'A'], - pmNames: ['PM', 'P'], - timeFormat: 'hh:mm tt', - timeSuffix: '', - timeOnlyTitle: 'Choose Time', - timeText: 'Time', - hourText: 'Hour', - minuteText: 'Minute', - secondText: 'Second', - millisecText: 'Millisecond', - timezoneText: 'Time Zone' - }; - this._defaults = { // Global defaults for all the datetime picker instances - showButtonPanel: true, - timeOnly: false, - showHour: true, - showMinute: true, - showSecond: false, - showMillisec: false, - showTimezone: false, - showTime: true, - stepHour: 1, - stepMinute: 1, - stepSecond: 1, - stepMillisec: 1, - hour: 0, - minute: 0, - second: 0, - millisec: 0, - timezone: null, - useLocalTimezone: false, - defaultTimezone: "+0000", - hourMin: 0, - minuteMin: 0, - secondMin: 0, - millisecMin: 0, - hourMax: 23, - minuteMax: 59, - secondMax: 59, - millisecMax: 999, - minDateTime: null, - maxDateTime: null, - onSelect: null, - hourGrid: 0, - minuteGrid: 0, - secondGrid: 0, - millisecGrid: 0, - alwaysSetTime: true, - separator: ' ', - altFieldTimeOnly: true, - showTimepicker: true, - timezoneIso8601: false, - timezoneList: null, - addSliderAccess: false, - sliderAccessArgs: null - }; - $.extend(this._defaults, this.regional['']); -} - -$.extend(Timepicker.prototype, { - $input: null, - $altInput: null, - $timeObj: null, - inst: null, - hour_slider: null, - minute_slider: null, - second_slider: null, - millisec_slider: null, - timezone_select: null, - hour: 0, - minute: 0, - second: 0, - millisec: 0, - timezone: null, - defaultTimezone: "+0000", - hourMinOriginal: null, - minuteMinOriginal: null, - secondMinOriginal: null, - millisecMinOriginal: null, - hourMaxOriginal: null, - minuteMaxOriginal: null, - secondMaxOriginal: null, - millisecMaxOriginal: null, - ampm: '', - formattedDate: '', - formattedTime: '', - formattedDateTime: '', - timezoneList: null, - - /* Override the default settings for all instances of the time picker. - @param settings object - the new settings to use as defaults (anonymous object) - @return the manager object */ - setDefaults: function(settings) { - extendRemove(this._defaults, settings || {}); - return this; - }, - - //######################################################################## - // Create a new Timepicker instance - //######################################################################## - _newInst: function($input, o) { - var tp_inst = new Timepicker(), - inlineSettings = {}; - - for (var attrName in this._defaults) { - var attrValue = $input.attr('time:' + attrName); - if (attrValue) { - try { - inlineSettings[attrName] = eval(attrValue); - } catch (err) { - inlineSettings[attrName] = attrValue; - } - } - } - tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, { - beforeShow: function(input, dp_inst) { - if ($.isFunction(o.beforeShow)) { - return o.beforeShow(input, dp_inst, tp_inst); - } - }, - onChangeMonthYear: function(year, month, dp_inst) { - // Update the time as well : this prevents the time from disappearing from the $input field. - tp_inst._updateDateTime(dp_inst); - if ($.isFunction(o.onChangeMonthYear)) { - o.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); - } - }, - onClose: function(dateText, dp_inst) { - if (tp_inst.timeDefined === true && $input.val() !== '') { - tp_inst._updateDateTime(dp_inst); - } - if ($.isFunction(o.onClose)) { - o.onClose.call($input[0], dateText, dp_inst, tp_inst); - } - }, - timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); - }); - tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { return val.toUpperCase(); }); - tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { return val.toUpperCase(); }); - - if (tp_inst._defaults.timezoneList === null) { - var timezoneList = []; - for (var i = -11; i <= 12; i++) { - timezoneList.push((i >= 0 ? '+' : '-') + ('0' + Math.abs(i).toString()).slice(-2) + '00'); - } - if (tp_inst._defaults.timezoneIso8601) { - timezoneList = $.map(timezoneList, function(val) { - return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3)); - }); - } - tp_inst._defaults.timezoneList = timezoneList; - } - - tp_inst.timezone = tp_inst._defaults.timezone; - tp_inst.hour = tp_inst._defaults.hour; - tp_inst.minute = tp_inst._defaults.minute; - tp_inst.second = tp_inst._defaults.second; - tp_inst.millisec = tp_inst._defaults.millisec; - tp_inst.ampm = ''; - tp_inst.$input = $input; - - if (o.altField) { - tp_inst.$altInput = $(o.altField) - .css({ cursor: 'pointer' }) - .focus(function(){ $input.trigger("focus"); }); - } - - if(tp_inst._defaults.minDate===0 || tp_inst._defaults.minDateTime===0) - { - tp_inst._defaults.minDate=new Date(); - } - if(tp_inst._defaults.maxDate===0 || tp_inst._defaults.maxDateTime===0) - { - tp_inst._defaults.maxDate=new Date(); - } - - // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime.. - if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) { - tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime()); - } - if(tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) { - tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime()); - } - if(tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) { - tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime()); - } - if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) { - tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime()); - } - return tp_inst; - }, - - //######################################################################## - // add our sliders to the calendar - //######################################################################## - _addTimePicker: function(dp_inst) { - var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? - this.$input.val() + ' ' + this.$altInput.val() : - this.$input.val(); - - this.timeDefined = this._parseTime(currDT); - this._limitMinMaxDateTime(dp_inst, false); - this._injectTimePicker(); - }, - - //######################################################################## - // parse the time string from input value or _setTime - //######################################################################## - _parseTime: function(timeString, withDate) { - if (!this.inst) { - this.inst = $.datepicker._getInst(this.$input[0]); - } - - if (withDate || !this._defaults.timeOnly) - { - var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat'); - try { - var parseRes = parseDateTimeInternal(dp_dateFormat, this._defaults.timeFormat, timeString, $.datepicker._getFormatConfig(this.inst), this._defaults); - if (!parseRes.timeObj) { return false; } - $.extend(this, parseRes.timeObj); - } catch (err) - { - return false; - } - return true; - } - else - { - var timeObj = $.datepicker.parseTime(this._defaults.timeFormat, timeString, this._defaults); - if(!timeObj) { return false; } - $.extend(this, timeObj); - return true; - } - }, - - //######################################################################## - // generate and inject html for timepicker into ui datepicker - //######################################################################## - _injectTimePicker: function() { - var $dp = this.inst.dpDiv, - o = this._defaults, - tp_inst = this, - // Added by Peter Medeiros: - // - Figure out what the hour/minute/second max should be based on the step values. - // - Example: if stepMinute is 15, then minMax is 45. - hourMax = parseInt((o.hourMax - ((o.hourMax - o.hourMin) % o.stepHour)) ,10), - minMax = parseInt((o.minuteMax - ((o.minuteMax - o.minuteMin) % o.stepMinute)) ,10), - secMax = parseInt((o.secondMax - ((o.secondMax - o.secondMin) % o.stepSecond)) ,10), - millisecMax = parseInt((o.millisecMax - ((o.millisecMax - o.millisecMin) % o.stepMillisec)) ,10), - dp_id = this.inst.id.toString().replace(/([^A-Za-z0-9_])/g, ''); - - // Prevent displaying twice - //if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) { - if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0 && o.showTimepicker) { - var noDisplay = ' style="display:none;"', - html = '
' + - '
' + o.timeText + '
' + - '
' + - '
' + o.hourText + '
', - hourGridSize = 0, - minuteGridSize = 0, - secondGridSize = 0, - millisecGridSize = 0, - size = null; - - // Hours - html += '
'; - if (o.showHour && o.hourGrid > 0) { - html += '
'; - - for (var h = o.hourMin; h <= hourMax; h += parseInt(o.hourGrid,10)) { - hourGridSize++; - var tmph = (o.ampm && h > 12) ? h-12 : h; - if (tmph < 10) { tmph = '0' + tmph; } - if (o.ampm) { - if (h === 0) { - tmph = 12 +'a'; - } else { - if (h < 12) { tmph += 'a'; } - else { tmph += 'p'; } - } - } - html += ''; - } - - html += '
' + tmph + '
'; - } - html += '
'; - - // Minutes - html += '
' + o.minuteText + '
'+ - '
'; - - if (o.showMinute && o.minuteGrid > 0) { - html += '
'; - - for (var m = o.minuteMin; m <= minMax; m += parseInt(o.minuteGrid,10)) { - minuteGridSize++; - html += ''; - } - - html += '
' + ((m < 10) ? '0' : '') + m + '
'; - } - html += '
'; - - // Seconds - html += '
' + o.secondText + '
'+ - '
'; - - if (o.showSecond && o.secondGrid > 0) { - html += '
'; - - for (var s = o.secondMin; s <= secMax; s += parseInt(o.secondGrid,10)) { - secondGridSize++; - html += ''; - } - - html += '
' + ((s < 10) ? '0' : '') + s + '
'; - } - html += '
'; - - // Milliseconds - html += '
' + o.millisecText + '
'+ - '
'; - - if (o.showMillisec && o.millisecGrid > 0) { - html += '
'; - - for (var l = o.millisecMin; l <= millisecMax; l += parseInt(o.millisecGrid,10)) { - millisecGridSize++; - html += ''; - } - - html += '
' + ((l < 10) ? '0' : '') + l + '
'; - } - html += '
'; - - // Timezone - html += '
' + o.timezoneText + '
'; - html += '
'; - - html += '
'; - var $tp = $(html); - - // if we only want time picker... - if (o.timeOnly === true) { - $tp.prepend( - '
' + - '
' + o.timeOnlyTitle + '
' + - '
'); - $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide(); - } - - this.hour_slider = $tp.find('#ui_tpicker_hour_'+ dp_id).slider({ - orientation: "horizontal", - value: this.hour, - min: o.hourMin, - max: hourMax, - step: o.stepHour, - slide: function(event, ui) { - tp_inst.hour_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); - } - }); - - - // Updated by Peter Medeiros: - // - Pass in Event and UI instance into slide function - this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({ - orientation: "horizontal", - value: this.minute, - min: o.minuteMin, - max: minMax, - step: o.stepMinute, - slide: function(event, ui) { - tp_inst.minute_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); - } - }); - - this.second_slider = $tp.find('#ui_tpicker_second_'+ dp_id).slider({ - orientation: "horizontal", - value: this.second, - min: o.secondMin, - max: secMax, - step: o.stepSecond, - slide: function(event, ui) { - tp_inst.second_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); - } - }); - - this.millisec_slider = $tp.find('#ui_tpicker_millisec_'+ dp_id).slider({ - orientation: "horizontal", - value: this.millisec, - min: o.millisecMin, - max: millisecMax, - step: o.stepMillisec, - slide: function(event, ui) { - tp_inst.millisec_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); - } - }); - - this.timezone_select = $tp.find('#ui_tpicker_timezone_'+ dp_id).append('').find("select"); - $.fn.append.apply(this.timezone_select, - $.map(o.timezoneList, function(val, idx) { - return $("