diff --git a/application/ajaxwebpage.class.inc.php b/application/ajaxwebpage.class.inc.php index 4c356bcaa3..8be77dbb25 100644 --- a/application/ajaxwebpage.class.inc.php +++ b/application/ajaxwebpage.class.inc.php @@ -202,32 +202,15 @@ EOF // Render the tabs in the page (if any) $this->s_content = $this->m_oTabs->RenderIntoContent($this->s_content, $this); - // Additional UI widgets to be activated inside the ajax fragment ?? - if (($this->sContentType == 'text/html') && (preg_match('/class="date-pick"/', $this->s_content) || preg_match('/class="datetime-pick"/', $this->s_content)) ) + // Additional UI widgets to be activated inside the ajax fragment + if ($this->sContentType == 'text/html') { $this->add_ready_script( <<ob_get_clean_safe(); if (($this->sContentType == 'text/html') && ($this->sContentDisposition == 'inline')) { diff --git a/application/itopwebpage.class.inc.php b/application/itopwebpage.class.inc.php index cb3dbf3245..1d4456c781 100644 --- a/application/itopwebpage.class.inc.php +++ b/application/itopwebpage.class.inc.php @@ -209,7 +209,39 @@ EOF; }"; $sJSDateTimePickerOptions = substr($sJSDateTimePickerOptions, 0, -1).$aMoreJSOptions; } - + $this->add_script( +<<< EOF + function PrepareWidgets() + { + // note: each action implemented here must be idempotent, + // because this helper function might be called several times on a given page + + $(".date-pick").datepicker($sJSDatePickerOptions); + + // Hack for the date and time picker addon issue on Chrome (see #1305) + // The workaround is to instantiate the widget on demand + // It relies on the same markup, thus reverting to the original implementation should be straightforward + $(".datetime-pick:not(.is-widget-ready)").each(function(){ + var oInput = this; + $(oInput).addClass('is-widget-ready'); + $('') + .insertAfter($(this)) + .on('click', function(){ + $(oInput) + .datetimepicker($sJSDateTimePickerOptions) + .datetimepicker('show') + .datetimepicker('option', 'onClose', function(dateText,inst){ + $(oInput).datetimepicker('destroy'); + }) + .on('click keypress', function(){ + $(oInput).datetimepicker('hide'); + }); + }); + }); + } +EOF + ); + $this->m_sInitScript = <<< EOF try @@ -445,29 +477,7 @@ EOF // End of Tabs handling - $(".date-pick").datepicker($sJSDatePickerOptions); - - // Hack for the date and time picker addon issue on Chrome (see #1305) - // The workaround is to instantiate the widget on demand - // It relies on the same markup, thus reverting to the original implementation should be straightforward - $(".datetime-pick").each(function(){ - var oInput = this; - $('') - .insertAfter($(this)) - .on('click', function(){ - $(oInput) - .datetimepicker($sJSDateTimePickerOptions) - .datetimepicker('show') - .datetimepicker('option', 'onClose', function(dateText,inst){ - $(oInput).datetimepicker('destroy'); - }) - .on('click keypress', function(){ - $(oInput).datetimepicker('hide'); - }); - }); - }); - - $(".datetime-pick-button") + PrepareWidgets(); // Make sortable, everything that claims to be sortable $('.sortable').sortable( {axis: 'y', cursor: 'move', handle: '.drag_handle', stop: function() diff --git a/application/ui.linkswidget.class.inc.php b/application/ui.linkswidget.class.inc.php index ce6545619d..cbb053c09e 100644 --- a/application/ui.linkswidget.class.inc.php +++ b/application/ui.linkswidget.class.inc.php @@ -163,38 +163,10 @@ class UILinksWidget $aFieldsMap[$sFieldCode] = $sSafeId; } $sState = ''; - $sJSDaysMin = json_encode(array(Dict::S('DayOfWeek-Sunday-Min'), Dict::S('DayOfWeek-Monday-Min'), Dict::S('DayOfWeek-Tuesday-Min'), Dict::S('DayOfWeek-Wednesday-Min'), - Dict::S('DayOfWeek-Thursday-Min'), Dict::S('DayOfWeek-Friday-Min'), Dict::S('DayOfWeek-Saturday-Min'))); - $sJSMonthsShort = json_encode(array(Dict::S('Month-01-Short'), Dict::S('Month-02-Short'), Dict::S('Month-03-Short'), Dict::S('Month-04-Short'), Dict::S('Month-05-Short'), Dict::S('Month-06-Short'), - Dict::S('Month-07-Short'), Dict::S('Month-08-Short'), Dict::S('Month-09-Short'), Dict::S('Month-10-Short'), Dict::S('Month-11-Short'), Dict::S('Month-12-Short'))); - $iFirstDayOfWeek = (int) Dict::S('Calendar-FirstDayOfWeek'); $oP->add_script( <<