Changeset 953
- Timestamp:
- 03/07/06 12:22:23 (3 years ago)
- Files:
-
- trunk/CHANGELOG (modified) (1 diff)
- trunk/data/web/sf/js/prototype/controls.js (modified) (9 diffs)
- trunk/data/web/sf/js/prototype/dragdrop.js (modified) (13 diffs)
- trunk/data/web/sf/js/prototype/effects.js (modified) (8 diffs)
- trunk/data/web/sf/js/prototype/scriptaculous.js (modified) (1 diff)
- trunk/data/web/sf/js/prototype/slider.js (modified) (1 diff)
- trunk/lib/helper/FormHelper.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/CHANGELOG
r847 r953 5 5 ------------- 6 6 7 * [fabien] lot of bugs fixes 8 * [faiben] updated scriptaculous to 1.5.3 9 * [fabien] added a new sfFileValidator validator 10 * [fabien] lots of bug fixes and new features in the admin generator (file upload, credentials, ...) 7 11 * [fabien] stylesheets, javascripts, ... are now part of the sfWebResponse object 8 12 DEPRECATED methods: trunk/data/web/sf/js/prototype/controls.js
r500 r953 153 153 }, 154 154 155 activate: function() { 156 this.changed = false; 157 this.hasFocus = true; 158 this.getUpdatedChoices(); 159 }, 160 155 161 onHover: function(event) { 156 162 var element = Event.findElement(event, 'LI'); … … 311 317 Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), { 312 318 initialize: function(element, update, url, options) { 313 this.baseInitialize(element, update, options);319 this.baseInitialize(element, update, options); 314 320 this.options.asynchronous = true; 315 321 this.options.onComplete = this.onComplete.bind(this); … … 478 484 highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor, 479 485 highlightendcolor: "#FFFFFF", 480 externalControl: null,486 externalControl: null, 481 487 submitOnBlur: false, 482 ajaxOptions: {} 488 ajaxOptions: {}, 489 evalScripts: false 483 490 }, options || {}); 484 491 … … 549 556 okButton.type = "submit"; 550 557 okButton.value = this.options.okText; 558 okButton.className = 'editor_ok_button'; 551 559 this.form.appendChild(okButton); 552 560 } … … 557 565 cancelLink.appendChild(document.createTextNode(this.options.cancelText)); 558 566 cancelLink.onclick = this.onclickCancel.bind(this); 567 cancelLink.className = 'editor_cancel'; 559 568 this.form.appendChild(cancelLink); 560 569 } … … 585 594 textField.value = text; 586 595 textField.style.backgroundColor = this.options.highlightcolor; 596 textField.className = 'editor_field'; 587 597 var size = this.options.size || this.options.cols || 0; 588 598 if (size != 0) textField.size = size; … … 598 608 textArea.rows = this.options.rows; 599 609 textArea.cols = this.options.cols || 40; 610 textArea.className = 'editor_field'; 600 611 if (this.options.submitOnBlur) 601 612 textArea.onblur = this.onSubmit.bind(this); … … 650 661 this.onLoading(); 651 662 652 new Ajax.Updater( 653 { 654 success: this.element, 655 // don't update on failure (this could be an option) 656 failure: null 657 }, 658 this.url, 659 Object.extend({ 660 parameters: this.options.callback(form, value), 661 onComplete: this.onComplete.bind(this), 662 onFailure: this.onFailure.bind(this) 663 }, this.options.ajaxOptions) 664 ); 663 if (this.options.evalScripts) { 664 new Ajax.Request( 665 this.url, Object.extend({ 666 parameters: this.options.callback(form, value), 667 onComplete: this.onComplete.bind(this), 668 onFailure: this.onFailure.bind(this), 669 asynchronous:true, 670 evalScripts:true 671 }, this.options.ajaxOptions)); 672 } else { 673 new Ajax.Updater( 674 { success: this.element, 675 // don't update on failure (this could be an option) 676 failure: null }, 677 this.url, Object.extend({ 678 parameters: this.options.callback(form, value), 679 onComplete: this.onComplete.bind(this), 680 onFailure: this.onFailure.bind(this) 681 }, this.options.ajaxOptions)); 682 } 665 683 // stop the event to avoid a page refresh in Safari 666 684 if (arguments.length > 1) { … … 743 761 } 744 762 }; 763 764 Ajax.InPlaceCollectionEditor = Class.create(); 765 Object.extend(Ajax.InPlaceCollectionEditor.prototype, Ajax.InPlaceEditor.prototype); 766 Object.extend(Ajax.InPlaceCollectionEditor.prototype, { 767 createEditField: function() { 768 if (!this.cached_selectTag) { 769 var selectTag = document.createElement("select"); 770 var collection = this.options.collection || []; 771 var optionTag; 772 collection.each(function(e,i) { 773 optionTag = document.createElement("option"); 774 optionTag.value = (e instanceof Array) ? e[0] : e; 775 if(this.options.value==optionTag.value) optionTag.selected = true; 776 optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e)); 777 selectTag.appendChild(optionTag); 778 }.bind(this)); 779 this.cached_selectTag = selectTag; 780 } 781 782 this.editField = this.cached_selectTag; 783 if(this.options.loadTextURL) this.loadExternalText(); 784 this.form.appendChild(this.editField); 785 this.options.callback = function(form, value) { 786 return "value=" + encodeURIComponent(value); 787 } 788 } 789 }); 745 790 746 791 // Delayed observer, like Form.Element.Observer, trunk/data/web/sf/js/prototype/dragdrop.js
r500 r953 129 129 }, 130 130 131 deactivate: function( draggbale) {131 deactivate: function() { 132 132 this.activeDraggable = null; 133 133 }, … … 200 200 zindex: 1000, 201 201 revert: false, 202 scroll: false, 203 scrollSensitivity: 20, 204 scrollSpeed: 15, 202 205 snap: false // false, or xy or [x,y] or function(x,y){ return [x,y] } 203 206 }, arguments[1] || {}); … … 209 212 if(!this.handle) this.handle = $(options.handle); 210 213 if(!this.handle) this.handle = this.element; 214 215 if(options.scroll) options.scroll = $(options.scroll); 211 216 212 217 Element.makePositioned(this.element); // fix IE … … 240 245 src.tagName=='INPUT' || 241 246 src.tagName=='SELECT' || 247 src.tagName=='OPTION' || 242 248 src.tagName=='BUTTON' || 243 249 src.tagName=='TEXTAREA')) return; … … 271 277 } 272 278 279 if(this.options.scroll) { 280 this.originalScrollLeft = this.options.scroll.scrollLeft; 281 this.originalScrollTop = this.options.scroll.scrollTop; 282 } 283 273 284 Draggables.notify('onStart', this, event); 274 285 if(this.options.starteffect) this.options.starteffect(this.element); … … 283 294 if(this.options.change) this.options.change(this); 284 295 296 if(this.options.scroll) { 297 //if(this.scrollInterval) this.scroll(); 298 this.stopScrolling(); 299 var p = Position.page(this.options.scroll); 300 p[0] += this.options.scroll.scrollLeft; 301 p[1] += this.options.scroll.scrollTop; 302 p.push(p[0]+this.options.scroll.offsetWidth); 303 p.push(p[1]+this.options.scroll.offsetHeight); 304 var speed = [0,0]; 305 if(pointer[0] < (p[0]+this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[0]+this.options.scrollSensitivity); 306 if(pointer[1] < (p[1]+this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[1]+this.options.scrollSensitivity); 307 if(pointer[0] > (p[2]-this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[2]-this.options.scrollSensitivity); 308 if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity); 309 this.startScrolling(speed); 310 } 311 285 312 // fix AppleWebKit rendering 286 313 if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0); 314 287 315 Event.stop(event); 288 316 }, … … 322 350 323 351 keyPress: function(event) { 324 if( !event.keyCode==Event.KEY_ESC) return;352 if(event.keyCode!=Event.KEY_ESC) return; 325 353 this.finishDrag(event, false); 326 354 Event.stop(event); … … 329 357 endDrag: function(event) { 330 358 if(!this.dragging) return; 359 this.stopScrolling(); 331 360 this.finishDrag(event, true); 332 361 Event.stop(event); … … 338 367 pos[0] -= d[0]; pos[1] -= d[1]; 339 368 340 var p = [0,1].map(function(i){ return (point[i]-pos[i]-this.offset[i]) }.bind(this)); 369 if(this.options.scroll) { 370 pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft; 371 pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop; 372 } 373 374 var p = [0,1].map(function(i){ 375 return (point[i]-pos[i]-this.offset[i]) 376 }.bind(this)); 341 377 342 378 if(this.options.snap) { … … 359 395 style.top = p[1] + "px"; 360 396 if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering 397 }, 398 399 stopScrolling: function() { 400 if(this.scrollInterval) { 401 clearInterval(this.scrollInterval); 402 this.scrollInterval = null; 403 } 404 }, 405 406 startScrolling: function(speed) { 407 this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed]; 408 this.lastScrolled = new Date(); 409 this.scrollInterval = setInterval(this.scroll.bind(this), 10); 410 }, 411 412 scroll: function() { 413 var current = new Date(); 414 var delta = current - this.lastScrolled; 415 this.lastScrolled = current; 416 this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000; 417 this.options.scroll.scrollTop += this.scrollSpeed[1] * delta / 1000; 418 419 Position.prepare(); 420 Droppables.show(Draggables._lastPointer, this.element); 421 Draggables.notify('onDrag', this); 422 this.draw(Draggables._lastPointer); 423 424 if(this.options.change) this.options.change(this); 361 425 } 362 426 } … … 415 479 hoverclass: null, 416 480 ghosting: false, 417 format: null, 481 scroll: false, 482 format: /^[^_]*_(.*)$/, 418 483 onChange: Prototype.emptyFunction, 419 484 onUpdate: Prototype.emptyFunction … … 426 491 var options_for_draggable = { 427 492 revert: true, 493 scroll: options.scroll, 428 494 ghosting: options.ghosting, 429 495 constraint: options.constraint, … … 569 635 }, 570 636 637 sequence: function(element) { 638 element = $(element); 639 var options = Object.extend(this.options(element), arguments[1] || {}); 640 641 return $(this.findElements(element, options) || []).map( function(item) { 642 return item.id.match(options.format) ? item.id.match(options.format)[1] : ''; 643 }); 644 }, 645 646 setSequence: function(element, new_sequence) { 647 element = $(element); 648 var options = Object.extend(this.options(element), arguments[2] || {}); 649 650 var nodeMap = {}; 651 this.findElements(element, options).each( function(n) { 652 if (n.id.match(options.format)) 653 nodeMap[n.id.match(options.format)[1]] = [n, n.parentNode]; 654 n.parentNode.removeChild(n); 655 }); 656 657 new_sequence.each(function(ident) { 658 var n = nodeMap[ident]; 659 if (n) { 660 n[1].appendChild(n[0]); 661 delete nodeMap[ident]; 662 } 663 }); 664 }, 665 571 666 serialize: function(element) { 572 667 element = $(element); 573 var sortableOptions = this.options(element); 574 var options = Object.extend({ 575 tag: sortableOptions.tag, 576 only: sortableOptions.only, 577 name: element.id, 578 format: sortableOptions.format || /^[^_]*_(.*)$/ 579 }, arguments[1] || {}); 580 return $(this.findElements(element, options) || []).map( function(item) { 581 return (encodeURIComponent(options.name) + "[]=" + 582 encodeURIComponent(item.id.match(options.format) ? item.id.match(options.format)[1] : '')); 583 }).join("&"); 668 var name = encodeURIComponent( 669 (arguments[1] && arguments[1].name) ? arguments[1].name : element.id); 670 return Sortable.sequence(element, arguments[1]).map( function(item) { 671 return name + "[]=" + encodeURIComponent(item); 672 }).join('&'); 584 673 } 585 674 } trunk/data/web/sf/js/prototype/effects.js
r500 r953 36 36 return (node.nodeType==3 ? node.nodeValue : 37 37 ((node.hasChildNodes() && !Element.hasClassName(node,className)) ? 38 Element.collectTextNodes (node) : ''));38 Element.collectTextNodesIgnoreClass(node, className) : '')); 39 39 }).flatten().join(''); 40 40 } … … 138 138 effect = (effect || 'appear').toLowerCase(); 139 139 var options = Object.extend({ 140 queue: { position:'end', scope:(element.id || 'global') }140 queue: { position:'end', scope:(element.id || 'global'), limit: 1 } 141 141 }, arguments[2] || {}); 142 142 Effect[Element.visible(element) ? … … 210 210 effect.startOn += timestamp; 211 211 effect.finishOn += timestamp; 212 this.effects.push(effect); 212 213 if(!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit)) 214 this.effects.push(effect); 215 213 216 if(!this.interval) 214 217 this.interval = setInterval(this.loop.bind(this), 40); … … 582 585 Effect.BlindDown = function(element) { 583 586 element = $(element); 584 var oldHeight = Element.getStyle(element, 'height');585 587 var elementDimensions = Element.getDimensions(element); 586 588 return new Effect.Scale(element, 100, … … 595 597 show(effect.element); 596 598 }}, 597 afterFinishInternal: function(effect) { with(Element) { 598 undoClipping(effect.element); 599 setStyle(effect.element, {height: oldHeight}); 600 }} 599 afterFinishInternal: function(effect) { 600 Element.undoClipping(effect.element); 601 } 601 602 }, arguments[1] || {}) 602 603 ); … … 691 692 afterFinishInternal: function(effect) { with(Element) { 692 693 undoClipping(effect.element); 693 undoPositioned(effect.element.firstChild); 694 undoPositioned(effect.element); 694 // IE will crash if child is undoPositioned first 695 if(/MSIE/.test(navigator.userAgent)){ 696 undoPositioned(effect.element); 697 undoPositioned(effect.element.firstChild); 698 }else{ 699 undoPositioned(effect.element.firstChild); 700 undoPositioned(effect.element); 701 } 695 702 setStyle(effect.element.firstChild, {bottom: oldInnerBottom}); }} 696 703 }, arguments[1] || {}) … … 742 749 var options = Object.extend({ 743 750 direction: 'center', 744 moveTransi stion: Effect.Transitions.sinoidal,751 moveTransition: Effect.Transitions.sinoidal, 745 752 scaleTransition: Effect.Transitions.sinoidal, 746 753 opacityTransition: Effect.Transitions.full … … 818 825 var options = Object.extend({ 819 826 direction: 'center', 820 moveTransi stion: Effect.Transitions.sinoidal,827 moveTransition: Effect.Transitions.sinoidal, 821 828 scaleTransition: Effect.Transitions.sinoidal, 822 829 opacityTransition: Effect.Transitions.none trunk/data/web/sf/js/prototype/scriptaculous.js
r500 r953 21 21 22 22 var Scriptaculous = { 23 Version: '1.5. 1',23 Version: '1.5.3', 24 24 require: function(libraryName) { 25 25 // inserting via DOM fails in Safari 2.0, so brute force approach trunk/data/web/sf/js/prototype/slider.js
r500 r953 201 201 if(this.isVertical()) { 202 202 span.style.top = this.translateToPx(range.start); 203 span.style.height = this.translateToPx(range.end - range.start );203 span.style.height = this.translateToPx(range.end - range.start + this.range.start); 204 204 } else { 205 205 span.style.left = this.translateToPx(range.start); 206 span.style.width = this.translateToPx(range.end - range.start );206 span.style.width = this.translateToPx(range.end - range.start + this.range.start); 207 207 } 208 208 }, trunk/lib/helper/FormHelper.php
r911 r953 537 537 } 538 538 539 function select_day_tag($name, $value, $options = array(), $html_options = array()) 540 { 541 $select_options = array(); 542 543 if (_get_option($options, 'include_blank')) 544 { 545 $select_options[''] = ''; 546 } 547 else if ($include_custom = _get_option($options, 'include_custom')) 548 { 549 $select_options[''] = $include_custom; 550 } 551 552 for ($x = 1; $x < 32; $x++) 553 { 554 $select_options[$x] = _add_zeros($x, 2); 555 } 556 557 $option_tags = options_for_select($select_options, $value); 558 559 return select_tag($name, $option_tags, $html_options); 560 } 561 562 function select_month_tag($name, $value, $options = array(), $html_options = array()) 563 { 564 565 $culture = _get_option($options, 'culture', sfContext::getInstance()->getUser()->getCulture()); 566 567 $I18n_arr = _get_I18n_date_locales($culture); 568 569 $select_options = array(); 570 571 if (_get_option($options, 'include_blank')) 572 { 573 $select_options[''] = ''; 574 } 575 else if ($include_custom = _get_option($options, 'include_custom')) 576 { 577 $select_options[''] = $include_custom; 578 } 579 580 if (_get_option($options, 'use_month_numbers')) 581 { 582 for ($k = 1; $k < 13; $k++) 583 { 584 $select_options[$k] = _add_zeros($k, 2); 585 } 586 } 587 else 588 { 589 if (_get_option($options, 'use_short_month')) 590 { 591 $month_names = $I18n_arr['dateFormatInfo']->getAbbreviatedMonthNames(); 592 } 593 else 594 { 595 $month_names = $I18n_arr['dateFormatInfo']->getMonthNames(); 596 } 597 598 $add_month_numbers = _get_option($options, 'add_month_numbers'); 599 foreach ($month_names as $k => $v) 600 { 601 $select_options[$k + 1] = ($add_month_numbers) ? ($k + 1 . ' - ' . $v) : $v; 602 } 603 } 604 605 $option_tags = options_for_select($select_options, $value); 606 607 return select_tag($name, $option_tags, $html_options); 608 } 609 610 function select_year_tag($name, $value, $options = array(), $html_options = array()) 611 { 612 $select_options = array(); 613 614 if (_get_option($options, 'include_blank')) 615 { 616 $select_options[''] = ''; 617 } 618 else if ($include_custom = _get_option($options, 'include_custom')) 619 { 620 $select_options[''] = $include_custom; 621 } 622 623 if (strlen($value) > 0 && is_numeric($value)) 624 { 625 $year_origin = $value; 626 } 627 else 628 { 629 $year_origin = date('Y'); 630 } 631 632 $year_start = _get_option($options, 'year_start', $year_origin - 5); 633 $year_end = _get_option($options, 'year_end', $year_origin + 5); 634 635 $ascending = ($year_start < $year_end); 636 $until_year = ($ascending) ? $year_end + 1 : $year_end - 1; 637 638 for ($x = $year_start; $x != $until_year; ($ascending) ? $x++ : $x--) 639 { 640 $select_options[$x] = $x; 641 } 642 643 $option_tags = options_for_select($select_options, $value); 644 645 return select_tag($name, $option_tags, $html_options); 646 } 647 648 /** 649 * Enter description here... 650 * 651 * @param string $name 652 * @param string $value (proper date format: array('year'=>2005, 'month'=>1, 'day'=1) or timestamp or english date text) 653 * @param array $options 654 * @return string 655 */ 656 function select_date_tag($name, $value, $options = array(), $html_options = array()) 657 { 658 $html_options = _parse_attributes($html_options); 659 $options = _parse_attributes($options); 660 661 $culture = _get_option($options, 'culture', sfContext::getInstance()->getUser()->getCulture()); 662 //set it back for month tag 663 $option['culture'] = $culture; 664 665 $I18n_arr = _get_I18n_date_locales($culture); 666 667 $date_seperator = _get_option($options, 'date_seperator', $I18n_arr['date_seperator']); 668 669 $discard_month = _get_option($options, 'discard_month'); 670 $discard_day = _get_option($options, 'discard_day'); 671 $discard_year = _get_option($options, 'discard_year'); 672 673 //discarding month automatically discards day 674 if ($discard_month) 675 $discard_day = true; 676 677 $order = _get_option($options, 'order'); 678 679 $tags = array(); 680 681 if (is_array($order) && count($order) == 3) 682 { 683 foreach ($order as $k => $v) 684 { 685 $tags[] = $v[0]; //'day' => 'd' | 'month' => 'm' 686 } 687 } 688 else 689 { 690 $tags = $I18n_arr['date_order']; 691 } 692 693 if ($include_custom = _get_option($options, 'include_custom')) 694 { 695 $include_custom_month = (is_array($include_custom)) 696 ? ((isset($include_custom['month'])) ? array('include_custom'=>$include_custom['month']) : array()) 697 : array('include_custom'=>$include_custom); 698 699 $include_custom_day = (is_array($include_custom)) 700 ? ((isset($include_custom['day'])) ? array('include_custom'=>$include_custom['day']) : array()) 701 : array('include_custom'=>$include_custom); 702 703 $include_custom_year = (is_array($include_custom)) 704 ? ((isset($include_custom['year'])) ? array('include_custom'=>$include_custom['year']) : array()) 705 : array('include_custom'=>$include_custom); 706 } 707 else 708 { 709 $include_custom_month = array(); 710 $include_custom_day = array(); 711 $include_custom_year = array(); 712 } 713 714 $html_options['id'] = $name . '_month'; 715 $m = ($discard_month != true) ? select_month_tag($name . '[month]', _parse_value_for_date($value, 'month', 'm'), $options + $include_custom_month, $html_options) : ''; 716 717 $html_options['id'] = $name . '_day'; 718 $d = ($discard_day != true) ? select_day_tag($name . '[day]', _parse_value_for_date($value, 'day', 'd'), $options + $include_custom_day, $html_options) : ''; 719 720 $html_options['id'] = $name . '_year'; 721 $y = ($discard_year != true) ? select_year_tag($name . '[year]', _parse_value_for_date($value, 'year', 'Y'), $options + $include_custom_year, $html_options) : ''; 722 723 //we have $tags = array ('m','d','y') 724 foreach ($tags as $k => $v) 725 { 726 $tags[$k] = $$v; 727 } 728 729 return implode($date_seperator, $tags); 730 } 731 732 function select_second_tag($name, $value, $options = array(), $html_options = array()) 733 { 734 $select_options = array(); 735 736 if (_get_option($options, 'include_blank')) 737 { 738 $select_options[''] = ''; 739 } 740 else if ($include_custom = _get_option($options, 'include_custom')) 741 { 742 $select_options[''] = $include_custom; 743 } 744 745 $second_step = _get_option($options, 'second_step', 1); 746 for ($x = 0; $x < 60; $x += $second_step) 747 { 748 $select_options[$x] = _add_zeros($x, 2); 749 } 750 751 $option_tags = options_for_select($select_options, $value); 752 753 return select_tag($name, $option_tags, $html_options); 754 } 755 756 function select_minute_tag($name, $value, $options = array(), $html_options = array()) 757 { 758 $select_options = array(); 759 760 if (_get_option($options, 'include_blank')) 761 { 762 $select_options[''] = ''; 763 } 764 else if ($include_custom = _get_option($options, 'include_custom')) 765 { 766 $select_options[''] = $include_custom; 767 } 768 769 $minute_step = _get_option($options, 'minute_step', 1); 770 for ($x = 0; $x < 60; $x += $minute_step) 771 { 772 $select_options[$x] = _add_zeros($x, 2); 773 } 774 775 $option_tags = options_for_select($select_options, $value); 776 777 return select_tag($name, $option_tags, $html_options); 778 } 779 780 function select_hour_tag($name, $value, $options = array(), $html_options = array()) 781 { 782 $select_options = array(); 783 784 if (_get_option($options, 'include_blank')) 785 { 786 $select_options[''] = ''; 787 } 788 else if ($include_custom = _get_option($options, 'include_custom')) 789 { 790 $select_options[''] = $include_custom; 791 } 792 793 $_12hour_time = _get_option($options, '12hour_time'); 794 795 $start_hour = ($_12hour_time) ? 1 : 0; 796 $end_hour = ($_12hour_time) ? 12 : 23; 797 798 for ($x = $start_hour; $x <= $end_hour; $x++) 799 { 800 $select_options[$x] = _add_zeros($x, 2); 801 } 802 803 $option_tags = options_for_select($select_options, $value); 804 805 return select_tag($name, $option_tags, $html_options); 806 } 807 808 function select_ampm_tag($name, $value, $options = array(), $html_options = array()) 809 { 810 $select_options = array(); 811 812 if (_get_option($options, 'include_blank')) 813 { 814 $select_options[''] = ''; 815 } 816 else if ($include_custom = _get_option($options, 'include_custom')) 817 { 818 $select_options[''] = $include_custom; 819 } 820 821 $select_options['AM'] = 'AM'; 822 $select_options['PM'] = 'PM'; 823 824 $option_tags = options_for_select($select_options, $value); 825 826 return select_tag($name, $option_tags, $html_options); 827 } 828 829 /** 830 * Enter description here... 831 * 832 * @param string $name 833 * @param string $value (proper time format: array('hour'=>0, 'minute'=>0, 'second'=0) or timestamp or english date text) 834 * @param array $options 835 * @return string 836 */ 837 function select_time_tag($name, $value, $options = array(), $html_options = array()) 838 { 839 $html_options = _parse_attributes($html_options); 840 $options = _parse_attributes($options); 841 842 $time_seperator = _get_option($options, 'time_seperator', ':'); 843 $ampm_seperator = _get_option($options, 'ampm_seperator', ''); 844 $include_second = _get_option($options, 'include_second'); 845 $_12hour_time = _get_option($options, '12hour_time'); 846 847 $options['12hour_time'] = $_12hour_time; //set it back. hour tag needs it. 848 849 if ($include_custom = _get_option($options, 'include_custom')) 850 { 851 $include_custom_hour = (is_array($include_custom)) 852 ? ((isset($include_custom['hour'])) ? array('include_custom'=>$include_custom['hour']) : array()) 853 : array('include_custom'=>$include_custom); 854 855 $include_custom_minute = (is_array($include_custom)) 856 ? ((isset($include_custom['minute'])) ? array('include_custom'=>$include_custom['minute']) : array()) 857 : array('include_custom'=>$include_custom); 858 859 $include_custom_second = (is_array($include_custom)) 860 ? ((isset($include_custom['second'])) ? array('include_custom'=>$include_custom['second']) : array()) 861 : array('include_custom'=>$include_custom); 862 863 $include_custom_ampm = (is_array($include_custom)) 864 ? ((isset($include_custom['ampm'])) ? array('include_custom'=>$include_custom['ampm']) : array()) 865 : array('include_custom'=>$include_custom); 866 } 867 else 868 { 869 $include_custom_hour = array(); 870 $include_custom_minute = array(); 871 $include_custom_second = array(); 872 $include_custom_ampm = array(); 873 } 874 875 $tags = array(); 876 877 $html_options['id'] = $name . '_hour'; 878 $tags[] = select_hour_tag($name . '[hour]', _parse_value_for_date($value, 'hour', ($_12hour_time) ? 'h' : 'H'), $options + $include_custom_hour, $html_options); 879 880 $html_options['id'] = $name . '_minute'; 881 $tags[] = select_minute_tag($name . '[minute]', _parse_value_for_date($value, 'minute', 'i'), $options + $include_custom_minute, $html_options); 882 883 if ($include_second) 884 { 885 $html_options['id'] = $name . '_second'; 886 $tags[] = select_second_tag($name . "[second]" , _parse_value_for_date($value, 'second', 's'), $options + $include_custom_second, $html_options); 887 } 888 889 $time = implode($time_seperator, $tags); 890 891 if ($_12hour_time) 892 { 893 $html_options['id'] = $name . '_ampm'; 894 $time .= $ampm_seperator . select_ampm_tag($name . "[ampm]" , _parse_value_for_date($value, 'ampm', 'A'), $options + $include_custom_ampm, $html_options); 895 } 896 897 return $time; 898 } 899 900 /** 901 * Enter description here... 902 * 903 * @param string $name 904 * @param string $value (proper datetime format YYYY-MM-DD HH:MM:SS) 905 * @param array $options 906 * @return string 907 */ 908 function select_datetime_tag($name, $value, $options = array(), $html_options = array()) 909 { 910 $options = _parse_attributes($options); 911 $datetime_seperator = _get_option($options, 'datetime_seperator', ''); 912 913 $date = select_date_tag($name, $value, $options, $html_options); 914 $time = select_time_tag($name, $value, $options, $html_options); 915 916 return $date.$datetime_seperator.$time; 917 } 918 919 function _add_zeros($string, $strlen) 920 { 921 if ($strlen > strlen($string)) 922 { 923 for ($x = strlen($string); $x < $strlen; $x++) 924 { 925 $string = '0'.$string; 926 } 927 } 928 929 return $string; 930 } 931 932 function _get_I18n_date_locales($culture = '') 933 { 934 if (empty($culture)) 935 { 936 $culture = sfContext::getInstance()->getUser()->getCulture(); 937 } 938 939 $ret_val = array(); 940 $ret_val['culture'] = $culture; 941 942 $dateFormatInfo = sfDateTimeFormatInfo::getInstance($culture); 943 $date_format = strtolower($dateFormatInfo->getShortDatePattern()); 944 945 $ret_val['dateFormatInfo'] = $dateFormatInfo; 946 947 $match_pattern = "/([dmy]+)(.*?)([dmy]+)(.*?)([dmy]+)/"; 948 if (!preg_match($match_pattern, $date_format, $match_arr)) 949 { 950 //if matching fails use en shortdate 951 preg_match($match_pattern, 'm/d/yy', $match_arr); 952 } 953 954 $ret_val['date_seperator'] = $match_arr[2]; 955 956 //unset all but [dmy]+ 957 unset($match_arr[0], $match_arr[2], $match_arr[4]); 958 959 $cnt = 0; 960 foreach ($match_arr as $k => $v) 961 { 962 $ret_val['date_order'][$cnt++] = $v[0]; //$arr[date_order][0] = 'm'; [1] = 'd'; [2] = 'y'; 963 } 964 965 return $ret_val; 966 } 967 968 /** 969 * _parse_value_for_date function can parse any date field from $value given as: 970 * - an array('year'=>2000, 'month'=> 1, .. 971 * - a timestamp 972 * - english text presentation of date (i.e '14:23', '03:30 AM', '2005-12-25' Refer to strtotime function in PHP manual) 973 */ 974 function _parse_value_for_date($value, $name, $format_char) 975 { 976 if (is_array($value)) 977 { 978 return (isset($value[$name])) ? $value[$name] : ''; 979 } 980 else if (is_numeric($value)) 981 { 982 return date($format_char, $value); 983 } 984 else if ($value == '' || ($name == 'ampm' && ($value == 'AM' || $value == 'PM'))) 985 { 986 return $value; 987 } 988 989 return date($format_char, strtotime($value)); 990 } 991 539 992 function _convert_options($options) 540 993 {