| [ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TDatePicker class file. 4 * 5 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TDatePicker.php 1412 2006-09-14 00:47:58Z wei $ 10 * @package System.Web.UI.WebControls 11 */ 12 13 /** 14 * Includes TTextBox class 15 */ 16 Prado::using('System.Web.UI.WebControls.TTextBox'); 17 18 /** 19 * 20 * TDatePicker class. 21 * 22 * TDatePicker displays a text box for date input purpose. 23 * When the text box receives focus, a calendar will pop up and users can 24 * pick up from it a date that will be automatically entered into the text box. 25 * The format of the date string displayed in the text box is determined by 26 * the <b>DateFormat</b> property. Valid formats are the combination of the 27 * following tokens, 28 * 29 * <code> 30 * Character Format Pattern (en-US) 31 * ----------------------------------------- 32 * d day digit 33 * dd padded day digit e.g. 01, 02 34 * M month digit 35 * MM padded month digit 36 * MMMM localized month name, e.g. March, April 37 * yy 2 digit year 38 * yyyy 4 digit year 39 * ----------------------------------------- 40 * </code> 41 * 42 * TDatePicker has three <b>Mode</b> to show the date picker popup. 43 * 44 * # <b>Basic</b> -- Only shows a text input, focusing on the input shows the 45 * date picker. 46 * # <b>Button</b> -- Shows a button next to the text input, clicking on the 47 * button shows the date, button text can be by the 48 * <b>ButtonText</b> property 49 * # <b>ImageButton</b> -- Shows an image next to the text input, clicking on 50 * the image shows the date picker, image source can be 51 * change through the <b>ButtonImageUrl</b> property. 52 * 53 * The <b>CssClass</b> property can be used to override the css class name 54 * for the date picker panel. <b>CalendarStyle</b> property sets the packages 55 * styles available. E.g. <b>default</b>. 56 * 57 * The <b>InputMode</b> property can be set to "TextBox" or "DropDownList" with 58 * default as "TextBox". 59 * In <tt>DropDownList</tt> mode, in addition to the popup date picker, three 60 * drop down list (day, month and year) are presented to select the date . 61 * 62 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> 63 * @version $Id: TDatePicker.php 1412 2006-09-14 00:47:58Z wei $ 64 * @package System.Web.UI.WebControls 65 * @since 3.0 66 */ 67 class TDatePicker extends TTextBox 68 { 69 /** 70 * @var TDatePickerClientScript validator client-script options. 71 */ 72 private $_clientScript; 73 /** 74 * AutoPostBack is not supported. 75 */ 76 public function setAutoPostBack($value) 77 { 78 throw new TNotSupportedException('tdatepicker_autopostback_unsupported', 79 get_class($this)); 80 } 81 82 /** 83 * @return string the format of the date string 84 */ 85 public function getDateFormat() 86 { 87 return $this->getViewState('DateFormat','dd-MM-yyyy'); 88 } 89 90 /** 91 * Sets the format of the date string. 92 * @param string the format of the date string 93 */ 94 public function setDateFormat($value) 95 { 96 $this->setViewState('DateFormat',$value,'dd-MM-yyyy'); 97 } 98 99 /** 100 * @return boolean whether the calendar window should pop up when the control receives focus 101 */ 102 public function getShowCalendar() 103 { 104 return $this->getViewState('ShowCalendar',true); 105 } 106 107 /** 108 * Sets whether to pop up the calendar window when the control receives focus 109 * @param boolean whether to show the calendar window 110 */ 111 public function setShowCalendar($value) 112 { 113 $this->setViewState('ShowCalendar',TPropertyValue::ensureBoolean($value),true); 114 } 115 116 /** 117 * Gets the current culture. 118 * @return string current culture, e.g. en_AU. 119 */ 120 public function getCulture() 121 { 122 return $this->getViewState('Culture', ''); 123 } 124 125 /** 126 * Sets the culture/language for the date picker. 127 * @param string a culture string, e.g. en_AU. 128 */ 129 public function setCulture($value) 130 { 131 $this->setViewState('Culture', $value, ''); 132 } 133 134 /** 135 * @param TDatePickerInputMode input method of date values 136 */ 137 public function setInputMode($value) 138 { 139 $this->setViewState('InputMode', TPropertyValue::ensureEnum($value, 'TDatePickerInputMode'), TDatePickerInputMode::TextBox); 140 } 141 142 /** 143 * @return TDatePickerInputMode input method of date values. Defaults to TDatePickerInputMode::TextBox. 144 */ 145 public function getInputMode() 146 { 147 return $this->getViewState('InputMode', TDatePickerInputMode::TextBox); 148 } 149 150 /** 151 * @param TDatePickerMode calendar UI mode 152 */ 153 public function setMode($value) 154 { 155 $this->setViewState('Mode', TPropertyValue::ensureEnum($value, 'TDatePickerMode'), TDatePickerMode::Basic); 156 } 157 158 /** 159 * @return TDatePickerMode current calendar UI mode. 160 */ 161 public function getMode() 162 { 163 return $this->getViewState('Mode', TDatePickerMode::Basic); 164 } 165 /** 166 * @param string the image url for "Image" UI mode. 167 */ 168 public function setButtonImageUrl($value) 169 { 170 $this->setViewState('ImageUrl', $value, ''); 171 } 172 173 /** 174 * @return string the image url for "Image" UI mode. 175 */ 176 public function getButtonImageUrl() 177 { 178 return $this->getViewState('ImageUrl', ''); 179 } 180 181 /** 182 * @param string set the calendar style 183 */ 184 public function setCalendarStyle($value) 185 { 186 $this->setViewState('CalendarStyle', $value, 'default'); 187 } 188 189 /** 190 * @return string current calendar style 191 */ 192 public function getCalendarStyle() 193 { 194 return $this->getViewState('CalendarStyle', 'default'); 195 } 196 197 /** 198 * Set the first day of week, with 0 as Sunday, 1 as Monday, etc. 199 * @param integer 0 for Sunday, 1 for Monday, 2 for Tuesday, etc. 200 */ 201 public function setFirstDayOfWeek($value) 202 { 203 $this->setViewState('FirstDayOfWeek', TPropertyValue::ensureInteger($value), 1); 204 } 205 206 /** 207 * @return integer first day of the week 208 */ 209 public function getFirstDayOfWeek() 210 { 211 return $this->getViewState('FirstDayOfWeek', 1); 212 } 213 214 /** 215 * @return string text for the date picker button. Default is "...". 216 */ 217 public function getButtonText() 218 { 219 return $this->getViewState('ButtonText', '...'); 220 } 221 222 /** 223 * @param string text for the date picker button 224 */ 225 public function setButtonText($value) 226 { 227 $this->setViewState('ButtonText', $value, '...'); 228 } 229 230 /** 231 * @param integer date picker starting year, default is 2000. 232 */ 233 public function setFromYear($value) 234 { 235 $this->setViewState('FromYear', TPropertyValue::ensureInteger($value), intval(@date('Y'))-5); 236 } 237 238 /** 239 * @return integer date picker starting year, default is -5 years 240 */ 241 public function getFromYear() 242 { 243 return $this->getViewState('FromYear', intval(@date('Y'))-5); 244 } 245 246 /** 247 * @param integer date picker ending year, default +10 years 248 */ 249 public function setUpToYear($value) 250 { 251 $this->setViewState('UpToYear', TPropertyValue::ensureInteger($value), intval(@date('Y'))+10); 252 } 253 254 /** 255 * @return integer date picker ending year, default +10 years 256 */ 257 public function getUpToYear() 258 { 259 return $this->getViewState('UpToYear', intval(@date('Y'))+10); 260 } 261 262 /** 263 * @return integer current selected date from the date picker as timestamp. 264 */ 265 public function getTimeStamp() 266 { 267 return $this->getTimeStampFromText(); 268 } 269 270 /** 271 * Sets the date for the date picker using timestamp. 272 * @param float time stamp for the date picker 273 */ 274 public function setTimeStamp($value) 275 { 276 $date = TPropertyValue::ensureFloat($value); 277 $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', 278 $this->getDateFormat()); 279 $d =$formatter->format($date); 280 $this->setText($d); 281 } 282 283 /** 284 * @return string the date string. 285 */ 286 public function getDate() 287 { 288 return $this->getText(); 289 } 290 291 /** 292 * @param string date string 293 */ 294 public function setDate($value) 295 { 296 $this->setText($value); 297 } 298 299 /** 300 * Gets the TDatePickerClientScript to set the TDatePicker event handlers. 301 * 302 * The date picker on the client-side supports the following events. 303 * # <tt>OnDateChanged</tt> -- raised when the date is changed. 304 * 305 * You can attach custom javascript code to each of these events 306 * 307 * @return TDatePickerClientScript javascript validator event options. 308 */ 309 public function getClientSide() 310 { 311 if(is_null($this->_clientScript)) 312 $this->_clientScript = $this->createClientScript(); 313 return $this->_clientScript; 314 } 315 316 /** 317 * @return TDatePickerClientScript javascript validator event options. 318 */ 319 protected function createClientScript() 320 { 321 return new TDatePickerClientScript; 322 } 323 324 /** 325 * Returns the value to be validated. 326 * This methid is required by IValidatable interface. 327 * @return integer the interger timestamp if valid, otherwise the original text. 328 */ 329 public function getValidationPropertyValue() 330 { 331 if(($text = $this->getText()) === '') 332 return ''; 333 $date = $this->getTimeStamp(); 334 return $date == null ? $text : $date; 335 } 336 337 /** 338 * Publish the date picker Css asset files. 339 */ 340 public function onPreRender($param) 341 { 342 parent::onPreRender($param); 343 $this->publishCalendarStyle(); 344 } 345 346 /** 347 * Renders body content. 348 * This method overrides parent implementation by adding 349 * additional date picker button if Mode is Button or ImageButton. 350 * @param THtmlWriter writer 351 */ 352 public function render($writer) 353 { 354 if($this->getInputMode() == TDatePickerInputMode::TextBox) 355 { 356 parent::render($writer); 357 $this->renderDatePickerButtons($writer); 358 } 359 else 360 { 361 $this->renderDropDownListCalendar($writer); 362 if($this->hasDayPattern()) 363 { 364 $this->registerCalendarClientScript(); 365 $this->renderDatePickerButtons($writer); 366 } 367 } 368 } 369 370 /** 371 * Renders the date picker popup buttons. 372 */ 373 protected function renderDatePickerButtons($writer) 374 { 375 if($this->getShowCalendar() && $this->getEnabled(true)) 376 { 377 switch ($this->getMode()) 378 { 379 case TDatePickerMode::Button: $this->renderButtonDatePicker($writer); break; 380 case TDatePickerMode::ImageButton : $this->renderImageButtonDatePicker($writer); break; 381 } 382 } 383 } 384 385 /** 386 * Loads user input data. Override parent implementation, when InputMode 387 * is DropDownList call getDateFromPostData to get date data. 388 * This method is primarly used by framework developers. 389 * @param string the key that can be used to retrieve data from the input data collection 390 * @param array the input data collection 391 * @return boolean whether the data of the component has been changed 392 */ 393 public function loadPostData($key,$values) 394 { 395 if($this->getInputMode() == TDatePickerInputMode::TextBox) 396 return parent::loadPostData($key, $values); 397 $value = $this->getDateFromPostData($key, $values); 398 if(!$this->getReadOnly() && $this->getText()!==$value) 399 { 400 $this->setText($value); 401 return true; 402 } 403 else 404 return false; 405 } 406 407 /** 408 * Loads date from drop down list data. 409 * @param string the key that can be used to retrieve data from the input data collection 410 * @param array the input data collection 411 * @return array the date selected 412 */ 413 protected function getDateFromPostData($key, $values) 414 { 415 $date = @getdate(); 416 417 if(isset($values[$key.'$day'])) 418 $day = intval($values[$key.'$day']); 419 else 420 $day = 1; 421 422 if(isset($values[$key.'$month'])) 423 $month = intval($values[$key.'$month']) + 1; 424 else 425 $month = $date['mon']; 426 427 if(isset($values[$key.'$year'])) 428 $year = intval($values[$key.'$year']); 429 else 430 $year = $date['year']; 431 432 $s = Prado::createComponent('System.Util.TDateTimeStamp'); 433 $date = $s->getTimeStamp(0, 0, 0, $month, $day, $year); 434 //$date = @mktime(0, 0, 0, $month, $day, $year); 435 436 $pattern = $this->getDateFormat(); 437 $pattern = str_replace(array('MMMM', 'MMM'), array('MM','MM'), $pattern); 438 $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', $pattern); 439 return $formatter->format($date); 440 } 441 442 /** 443 * Get javascript date picker options. 444 * @return array date picker client-side options 445 */ 446 protected function getDatePickerOptions() 447 { 448 $options['ID'] = $this->getClientID(); 449 $options['InputMode'] = $this->getInputMode(); 450 $options['Format'] = $this->getDateFormat(); 451 $options['FirstDayOfWeek'] = $this->getFirstDayOfWeek(); 452 if(($cssClass=$this->getCssClass())!=='') 453 $options['ClassName'] = $cssClass; 454 $options['CalendarStyle'] = $this->getCalendarStyle(); 455 $options['FromYear'] = $this->getFromYear(); 456 $options['UpToYear'] = $this->getUpToYear(); 457 if($this->getMode()!==TDatePickerMode::Basic) 458 $options['Trigger'] = $this->getDatePickerButtonID(); 459 460 $options = array_merge($options, $this->getCulturalOptions()); 461 if(!is_null($this->_clientScript)) 462 $options = array_merge($options, 463 $this->_clientScript->getOptions()->toArray()); 464 return $options; 465 } 466 467 /** 468 * Get javascript localization options, e.g. month and weekday names. 469 * @return array localization options. 470 */ 471 protected function getCulturalOptions() 472 { 473 if($this->getCurrentCulture() == 'en') 474 return array(); 475 476 $date = $this->getLocalizedCalendarInfo(); 477 $options['MonthNames'] = TJavaScript::encode($date->getMonthNames(),false); 478 $options['AbbreviatedMonthNames'] = TJavaScript::encode($date->getAbbreviatedMonthNames(),false); 479 $options['ShortWeekDayNames'] = TJavaScript::encode($date->getAbbreviatedDayNames(),false); 480 481 return $options; 482 } 483 484 /** 485 * @return string the current culture, falls back to application if culture is not set. 486 */ 487 protected function getCurrentCulture() 488 { 489 $app = $this->getApplication()->getGlobalization(false); 490 return $this->getCulture() == '' ? 491 ($app ? $app->getCulture() : 'en') : $this->getCulture(); 492 } 493 494 /** 495 * @return DateTimeFormatInfo date time format information for the current culture. 496 */ 497 protected function getLocalizedCalendarInfo() 498 { 499 //expensive operations 500 $culture = $this->getCurrentCulture(); 501 Prado::using('System.I18N.core.DateTimeFormatInfo'); 502 $info = Prado::createComponent('System.I18N.core.CultureInfo', $culture); 503 return $info->getDateTimeFormat(); 504 } 505 506 /** 507 * Renders the drop down list date picker. 508 */ 509 protected function renderDropDownListCalendar($writer) 510 { 511 if($this->getMode() == TDatePickerMode::Basic) 512 $this->setMode(TDatePickerMode::ImageButton); 513 parent::addAttributesToRender($writer); 514 $writer->removeAttribute('name'); 515 $writer->removeAttribute('type'); 516 $writer->addAttribute('id', $this->getClientID()); 517 518 if(strlen($class = $this->getCssClass()) > 0) 519 $writer->addAttribute('class', $class); 520 $writer->renderBeginTag('span'); 521 522 $s = Prado::createComponent('System.Util.TDateTimeStamp'); 523 $date = $s->getDate($this->getTimeStampFromText()); 524 //$date = @getdate($this->getTimeStampFromText()); 525 526 $this->renderCalendarSelections($writer, $date); 527 528 //render a hidden input field 529 $writer->addAttribute('name', $this->getUniqueID()); 530 $writer->addAttribute('type', 'hidden'); 531 $writer->addAttribute('value', $this->getText()); 532 $writer->renderBeginTag('input'); 533 534 $writer->renderEndTag(); 535 $writer->renderEndTag(); 536 } 537 538 protected function hasDayPattern() 539 { 540 $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', 541 $this->getDateFormat()); 542 return !is_null($formatter->getDayPattern()); 543 } 544 545 /** 546 * Renders the calendar drop down list depending on the DateFormat pattern. 547 * @param THtmlWriter the Html writer to render the drop down lists. 548 * @param array the current selected date 549 */ 550 protected function renderCalendarSelections($writer, $date) 551 { 552 $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', 553 $this->getDateFormat()); 554 555 foreach($formatter->getDayMonthYearOrdering() as $type) 556 { 557 if($type == 'day') 558 $this->renderCalendarDayOptions($writer,$date['mday']); 559 elseif($type == 'month') 560 $this->renderCalendarMonthOptions($writer,$date['mon']); 561 elseif($type == 'year') 562 $this->renderCalendarYearOptions($writer,$date['year']); 563 } 564 } 565 566 /** 567 * Gets the date from the text input using TSimpleDateFormatter 568 * @return integer current selected date timestamp 569 */ 570 protected function getTimeStampFromText() 571 { 572 $pattern = $this->getDateFormat(); 573 $pattern = str_replace(array('MMMM', 'MMM'), array('MM','MM'), $pattern); 574 $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter',$pattern); 575 return $formatter->parse($this->getText()); 576 } 577 578 /** 579 * Renders a drop down lists. 580 * @param THtmlWriter the writer used for the rendering purpose 581 * @param array list of selection options 582 * @param mixed selected key. 583 */ 584 private function renderDropDownListOptions($writer,$options,$selected=null) 585 { 586 foreach($options as $k => $v) 587 { 588 $writer->addAttribute('value', $k); 589 if($k == $selected) 590 $writer->addAttribute('selected', 'selected'); 591 $writer->renderBeginTag('option'); 592 $writer->write($v); 593 $writer->renderEndTag(); 594 } 595 } 596 597 /** 598 * Renders the day drop down list options. 599 * @param THtmlWriter the writer used for the rendering purpose 600 * @param mixed selected day. 601 */ 602 protected function renderCalendarDayOptions($writer, $selected=null) 603 { 604 $days = $this->getDropDownDayOptions(); 605 $writer->addAttribute('id', $this->getClientID().'_day'); 606 $writer->addAttribute('name', $this->getUniqueID().'$day'); 607 $writer->addAttribute('class', 'datepicker_day_options'); 608 if($this->getReadOnly() || !$this->getEnabled(true)) 609 $writer->addAttribute('disabled', 'disabled'); 610 $writer->renderBeginTag('select'); 611 $this->renderDropDownListOptions($writer, $days, $selected); 612 $writer->renderEndTag(); 613 } 614 615 /** 616 * @return array list of day options for a drop down list. 617 */ 618 protected function getDropDownDayOptions() 619 { 620 $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', 621 $this->getDateFormat()); 622 $days = array(); 623 $requiresPadding = $formatter->getDayPattern() === 'dd'; 624 for($i=1;$i<=31;$i++) 625 { 626 $days[$i] = $requiresPadding ? str_pad($i, 2, '0', STR_PAD_LEFT) : $i; 627 } 628 return $days; 629 } 630 631 /** 632 * Renders the month drop down list options. 633 * @param THtmlWriter the writer used for the rendering purpose 634 * @param mixed selected month. 635 */ 636 protected function renderCalendarMonthOptions($writer, $selected=null) 637 { 638 $info = $this->getLocalizedCalendarInfo(); 639 $writer->addAttribute('id', $this->getClientID().'_month'); 640 $writer->addAttribute('name', $this->getUniqueID().'$month'); 641 $writer->addAttribute('class', 'datepicker_month_options'); 642 if($this->getReadOnly() || !$this->getEnabled(true)) 643 $writer->addAttribute('disabled', 'disabled'); 644 $writer->renderBeginTag('select'); 645 $this->renderDropDownListOptions($writer, 646 $this->getLocalizedMonthNames($info), $selected-1); 647 $writer->renderEndTag(); 648 } 649 650 /** 651 * Returns the localized month names that depends on the month format pattern. 652 * "MMMM" will return the month names, "MM" or "MMM" return abbr. month names 653 * and "M" return month digits. 654 * @param DateTimeFormatInfo localized date format information. 655 * @return array localized month names. 656 */ 657 protected function getLocalizedMonthNames($info) 658 { 659 $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', 660 $this->getDateFormat()); 661 switch($formatter->getMonthPattern()) 662 { 663 case 'MMM': return $info->getAbbreviatedMonthNames(); 664 case 'MM': 665 $array = array(); 666 for($i=1;$i<=12;$i++) 667 $array[$i-1] = $i < 10 ? '0'.$i : $i; 668 return $array; 669 case 'M': 670 $array = array(); for($i=1;$i<=12;$i++) $array[$i-1] = $i; 671 return $array; 672 default : return $info->getMonthNames(); 673 } 674 } 675 676 /** 677 * Renders the year drop down list options. 678 * @param THtmlWriter the writer used for the rendering purpose 679 * @param mixed selected year. 680 */ 681 protected function renderCalendarYearOptions($writer, $selected=null) 682 { 683 $years = array(); 684 for($i = $this->getFromYear(); $i <= $this->getUpToYear(); $i++) 685 $years[$i] = $i; 686 $writer->addAttribute('id', $this->getClientID().'_year'); 687 $writer->addAttribute('name', $this->getUniqueID().'$year'); 688 if($this->getReadOnly() || !$this->getEnabled(true)) 689 $writer->addAttribute('disabled', 'disabled'); 690 $writer->renderBeginTag('select'); 691 $writer->addAttribute('class', 'datepicker_year_options'); 692 $this->renderDropDownListOptions($writer, $years, $selected); 693 $writer->renderEndTag(); 694 } 695 696 /** 697 * Gets the ID for the date picker trigger button. 698 * @return string unique button ID 699 */ 700 protected function getDatePickerButtonID() 701 { 702 return $this->getClientID().'button'; 703 } 704 705 /** 706 * Adds an additional button such that when clicked it shows the date picker. 707 * @return THtmlWriter writer 708 */ 709 protected function renderButtonDatePicker($writer) 710 { 711 $writer->addAttribute('id', $this->getDatePickerButtonID()); 712 $writer->addAttribute('type', 'button'); 713 $writer->addAttribute('class', $this->getCssClass().' TDatePickerButton'); 714 $writer->addAttribute('value',$this->getButtonText()); 715 $writer->renderBeginTag("input"); 716 $writer->renderEndTag(); 717 } 718 719 /** 720 * Adds an additional image button such that when clicked it shows the date picker. 721 * @return THtmlWriter writer 722 */ 723 protected function renderImageButtonDatePicker($writer) 724 { 725 $url = $this->getButtonImageUrl(); 726 $url = empty($url) ? $this->publishDefaultButtonImage() : $url; 727 $writer->addAttribute('id', $this->getDatePickerButtonID()); 728 $writer->addAttribute('src', $url); 729 $writer->addAttribute('class', $this->getCssClass().' TDatePickerImageButton'); 730 $writer->renderBeginTag('img'); 731 $writer->renderEndTag(); 732 } 733 734 /** 735 * Publish the default button image asset file. 736 * @return string image file url. 737 */ 738 protected function publishDefaultButtonImage() 739 { 740 $image = 'System.Web.Javascripts.datepicker.calendar'; 741 if(($file = Prado::getPathOfNamespace($image, '.png'))!==null) 742 return $this->publishFilePath($file); 743 else 744 throw new TConfigurationException('datepicker_defaultbuttonimage_invalid',$image); 745 } 746 747 /** 748 * Publish the calendar style Css asset file. 749 * @return string Css file url. 750 */ 751 protected function publishCalendarStyle() 752 { 753 $cs = $this->getPage()->getClientScript(); 754 $style = 'System.Web.Javascripts.datepicker.'.$this->getCalendarStyle(); 755 if(($cssFile=Prado::getPathOfNamespace($style,'.css'))!==null) 756 { 757 $url = $this->publishFilePath($cssFile); 758 if(!$cs->isStyleSheetFileRegistered($style)) 759 $cs->registerStyleSheetFile($style, $url); 760 return $url; 761 } 762 else 763 throw new TConfigurationException('datepicker_calendarstyle_invalid',$style); 764 } 765 766 /** 767 * Publish the spacer.gif for IE iframe source. 768 * @return string the URL for the spacer.gif. 769 */ 770 protected function publishIFrameSpacer() 771 { 772 $cs = $this->getPage()->getClientScript(); 773 $spacer = 'System.Web.Javascripts.datepicker.spacer'; 774 if(($file = Prado::getPathOfNamespace($spacer,'.gif')) != null) 775 return $this->publishFilePath($file); 776 } 777 778 /** 779 * Add the client id to the input textbox, and register the client scripts. 780 * @param THtmlWriter writer 781 */ 782 protected function addAttributesToRender($writer) 783 { 784 parent::addAttributesToRender($writer); 785 $writer->addAttribute('id',$this->getClientID()); 786 $this->registerCalendarClientScript(); 787 } 788 789 790 /** 791 * Registers the javascript code to initialize the date picker. 792 */ 793 protected function registerCalendarClientScript() 794 { 795 if($this->getShowCalendar()) 796 { 797 $cs = $this->getPage()->getClientScript(); 798 $cs->registerPradoScript("datepicker"); 799 800 if(!$cs->isEndScriptRegistered('TDatePicker.spacer')) 801 { 802 $spacer = $this->publishIFrameSpacer(); 803 $code = "Prado.WebUI.TDatePicker.spacer = '$spacer';"; 804 $cs->registerEndScript('TDatePicker.spacer', $code); 805 } 806 807 $options = TJavaScript::encode($this->getDatePickerOptions()); 808 $code = "new Prado.WebUI.TDatePicker($options);"; 809 $cs->registerEndScript("prado:".$this->getClientID(), $code); 810 } 811 } 812 } 813 814 /** 815 * TDatePickerClientScript class. 816 * 817 * Client-side date picker event {@link setOnDateChanged OnDateChanged} 818 * can be modified through the {@link TDatePicker:: getClientSide ClientSide} 819 * property of a date picker. 820 * 821 * The <tt>OnDateChanged</tt> event is raise when the date picker's date 822 * is changed. 823 * 824 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> 825 * @version $Id: TDatePicker.php 1412 2006-09-14 00:47:58Z wei $ 826 * @package System.Web.UI.WebControls 827 * @since 3.0.4 828 */ 829 class TDatePickerClientScript extends TClientSideOptions 830 { 831 /** 832 * Javascript code to execute when the date picker's date is changed. 833 * @param string javascript code 834 */ 835 public function setOnDateChanged($javascript) 836 { 837 $this->setFunction('OnDateChanged', $javascript); 838 } 839 840 /** 841 * @return string javascript code to execute when the date picker's date is changed. 842 */ 843 public function getOnDateChanged() 844 { 845 return $this->getOption('OnDateChanged'); 846 } 847 } 848 849 850 /** 851 * TDatePickerInputMode class. 852 * TDatePickerInputMode defines the enumerable type for the possible datepicker input methods. 853 * 854 * The following enumerable values are defined: 855 * - TextBox: text boxes are used to input date values 856 * - DropDownList: dropdown lists are used to pick up date values 857 * 858 * @author Qiang Xue <qiang.xue@gmail.com> 859 * @version $Id: TDatePicker.php 1412 2006-09-14 00:47:58Z wei $ 860 * @package System.Web.UI.WebControls 861 * @since 3.0.4 862 */ 863 class TDatePickerInputMode extends TEnumerable 864 { 865 const TextBox='TextBox'; 866 const DropDownList='DropDownList'; 867 } 868 869 /** 870 * TDatePickerMode class. 871 * TDatePickerMode defines the enumerable type for the possible UI mode 872 * that a {@link TDatePicker} control can take. 873 * 874 * The following enumerable values are defined: 875 * - Basic: Only shows a text input, focusing on the input shows the date picker 876 * - Button: Shows a button next to the text input, clicking on the button shows the date, button text can be by the 877 * - ImageButton: Shows an image next to the text input, clicking on the image shows the date picker, 878 * 879 * @author Qiang Xue <qiang.xue@gmail.com> 880 * @version $Id: TDatePicker.php 1412 2006-09-14 00:47:58Z wei $ 881 * @package System.Web.UI.WebControls 882 * @since 3.0.4 883 */ 884 class TDatePickerMode extends TEnumerable 885 { 886 const Basic='Basic'; 887 const Button='Button'; 888 const ImageButton='ImageButton'; 889 } 890 891 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |