Exemple #1
0
 /**
  * Generate HTML containing a Javascript <script> tag for creating a calendar instance implemented
  * using the jQuery datepicker.
  *
  * @return string
  */
 protected function _toHtml()
 {
     $displayFormat = Magento_Date_Jquery_Calendar::convertToDateTimeFormat($this->getFormat(), true, (bool) $this->getTime());
     $html = '<input type="text" name="' . $this->getName() . '" id="' . $this->getId() . '" ';
     $html .= 'value="' . $this->escapeHtml($this->getValue()) . '" class="' . $this->getClass() . '" ' . $this->getExtraParams() . '/> ';
     $yearRange = "c-10:c+10";
     /* Default the range to the current year + or - 10 years. */
     $calendarYearsRange = $this->getYearsRange();
     if ($calendarYearsRange) {
         /* Convert to the year range format that the jQuery datepicker understands. */
         sscanf($calendarYearsRange, "[%[0-9], %[0-9]]", $yearStart, $yearEnd);
         $yearRange = "{$yearStart}:{$yearEnd}";
     }
     /* First include jquery-ui. */
     $jsFiles = '"' . $this->getSkinUrl("jquery/ui/jquery-ui.js") . '", ';
     /* There are a small handful of localized files that use the 5 character locale. */
     $locale = str_replace('_', '-', Mage::app()->getLocale()->getLocaleCode());
     $localizedJsFilePath = $this->_getUrlPathByLocale($locale);
     if ($localizedJsFilePath == null) {
         /* Most localized files use the 2 character locale. */
         $locale = substr($locale, 0, 2);
         $localizedJsFilePath = $this->_getUrlPathByLocale($locale);
         if ($localizedJsFilePath == null) {
             /* Localized Javascript file doesn't exist. Default locale to empty string (English). */
             $locale = '';
         } else {
             /* Include the regional localized Javascript file. */
             $jsFiles .= '"' . $localizedJsFilePath . '", ';
         }
     } else {
         /* Include the regional localized Javascript file. */
         $jsFiles .= '"' . $localizedJsFilePath . '", ';
     }
     $jsFiles .= '"' . $this->getSkinUrl("mage/calendar/calendar.js") . '"';
     /* Lastly, the datepicker. */
     $cssFile = '"' . $this->getSkinUrl("mage/calendar/css/calendar.css") . '"';
     $html .= '
         <script type="text/javascript">
             //<![CDATA[
             (function($) {
                 $.mage.event.observe("mage.calendar.initialize", function (event, initData) {
                     var datepicker = {
                         inputSelector: "#' . $this->getId() . '",
                         locale: "' . $locale . '",
                         options: {
                             buttonImage: "' . $this->getImage() . '",
                             buttonText: "' . $this->helper("Mage_Core_Helper_Data")->__("Select Date") . '",
                             dateFormat: "' . $displayFormat . '",
                             yearRange: "' . $yearRange . '"
                         }
                     };
                     initData.datepicker.push(datepicker);
                 });
                 $.mage.load.css( ' . $cssFile . ' );
                 $.mage.load.jsSync(' . $jsFiles . ');
             })(jQuery);
             //]]>
         </script>';
     return $html;
 }
Exemple #2
0
 /**
  * Test conversions from old calendar date/time formats to jQuery datepicker compatible formats.
  *
  * @param string  $expected
  * @param string  $formatString - Date and/or time string to convert
  * @param boolean $formatDate - Whether to convert date (true) or not (false)
  * @param boolean $formatTime - Whether to convert time (true) or not (false)
  *
  * @dataProvider convertToDateTimeFormatDataProvider
  */
 public function testConvertToDateTimeFormat($expected, $formatString, $formatDate, $formatTime)
 {
     $this->assertEquals($expected, Magento_Date_Jquery_Calendar::convertToDateTimeFormat($formatString, $formatDate, $formatTime));
 }