| 3 | | use_helper('Javascript'); |
|---|
| 4 | | |
|---|
| 5 | | /* |
|---|
| 6 | | * This file is part of the symfony package. |
|---|
| 7 | | * (c) 2004-2006 Dustin Whittle <dustin.whittle@symfony-project.com> |
|---|
| 8 | | * |
|---|
| 9 | | * For the full copyright and license information, please view the LICENSE |
|---|
| 10 | | * file that was distributed with this source code. |
|---|
| 11 | | */ |
|---|
| 12 | | |
|---|
| 13 | | /** |
|---|
| 14 | | * @package symfony.runtime.addon |
|---|
| 15 | | * @author Dustin Whittle <dustin.whittle@symfony-project.com> |
|---|
| 16 | | * @version SVN: $Id$ |
|---|
| 17 | | */ |
|---|
| | 3 | /* |
|---|
| | 4 | * This file is part of the symfony package. |
|---|
| | 5 | * (c) 2004-2006 Dustin Whittle <dustin.whittle@symfony-project.com> |
|---|
| | 6 | * |
|---|
| | 7 | * For the full copyright and license information, please view the LICENSE |
|---|
| | 8 | * file that was distributed with this source code. |
|---|
| | 9 | */ |
|---|
| | 10 | |
|---|
| | 11 | /** |
|---|
| | 12 | * @package symfony.runtime.addon |
|---|
| | 13 | * @author Dustin Whittle <dustin.whittle@symfony-project.com> |
|---|
| | 14 | * @version SVN: $Id$ |
|---|
| | 15 | */ |
|---|
| | 16 | |
|---|
| | 17 | use_helper('Javascript'); |
|---|
| | 18 | |
|---|
| | 19 | /** |
|---|
| | 20 | * javascript_for_prototype_dialog gernerates javacript for a dialog box using prototype. |
|---|
| | 21 | * |
|---|
| | 22 | * |
|---|
| | 23 | * Example: |
|---|
| | 24 | * <code> |
|---|
| | 25 | * <?php use_helper('Window'); ?> |
|---|
| | 26 | * <?php if(sfConfig::get('sf_debug')) { echo link_to_function('open debug window', 'showDebug()'); } ?> |
|---|
| | 27 | * <?php echo javascript_for_prototype_dialog('hello', 'hello world', 'alert', array('className' => 'alphacube')); ?> |
|---|
| | 28 | * </code> |
|---|
| | 29 | * |
|---|
| | 30 | * @link http://prototype-window.xilinus.com/documentation.html#initialize |
|---|
| | 31 | * |
|---|
| | 32 | * @param string $name |
|---|
| | 33 | * @param string $content |
|---|
| | 34 | * @param string $dialog_type 'alert' (default), 'confirm' or 'info' (info dialogs should be destroyed with a javascript function call 'win.destroy') |
|---|
| | 35 | * @param array $options for this helper depending the dialog_kind: http://prototype-window.xilinus.com/documentation.html#alert (#confirm or #info) |
|---|
| | 36 | * @return string |
|---|
| | 37 | */ |
|---|
| | 38 | function javascript_for_prototype_dialog($name, $content, $dialog_type = 'alert', $window_options = array(), $options = array()) |
|---|
| | 39 | { |
|---|
| | 40 | |
|---|
| | 41 | $request = sfContext::getInstance()->getResponse(); |
|---|
| | 42 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| | 43 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/scriptaculous'); |
|---|
| | 44 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/effects'); |
|---|
| | 45 | $request->addJavascript('/sfPrototypeWindowPlugin/js/window'); |
|---|
| | 46 | $request->addJavascript('/sfPrototypeWindowPlugin/js/window_ext'); |
|---|
| | 47 | |
|---|
| | 48 | $request->addStylesheet('/sfPrototypeWindowPlugin/themes/default.css'); |
|---|
| | 49 | |
|---|
| | 50 | if(isset($window_options['className']) && ($window_options['className'] != 'default')) |
|---|
| | 51 | { |
|---|
| | 52 | $request->addStylesheet('/sfPrototypeWindowPlugin/themes/'.$window_options['className'].'.css'); |
|---|
| | 53 | } |
|---|
| | 54 | |
|---|
| | 55 | if(sfConfig::get('sf_debug')) |
|---|
| | 56 | { |
|---|
| | 57 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/debug'); |
|---|
| | 58 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/extended_debug'); |
|---|
| | 59 | } |
|---|
| | 60 | |
|---|
| | 61 | $window_options = array_merge(array('title' => 'New Dialog', 'className' => 'dialog', 'width' => '200', 'height' => '100', 'zIndex' => '100', 'draggable' => 'true', 'resizable' => 'true', 'opacity' => 1, 'showEffect' => 'Effect.BlindDown', 'hideEffect' => 'Effect.SwitchOff'), _parse_attributes($window_options)); |
|---|
| | 62 | |
|---|
| | 63 | if (isset($window_options['title'])) { $window_options['title'] = _method_option_to_s($window_options['title']); } |
|---|
| | 64 | if (isset($window_options['className'])) { $window_options['className'] = _method_option_to_s($window_options['className']); } |
|---|
| | 65 | |
|---|
| | 66 | $window_options = _options_for_javascript($window_options); |
|---|
| | 67 | $default_options = array('windowParameters' => $window_options); |
|---|
| | 68 | $options = _options_for_javascript(array_merge($default_options, _parse_attributes($options))); |
|---|
| | 69 | |
|---|
| | 70 | $js_code = 'Dialog.'.$dialog_type.'('._method_option_to_s($content).', '.$options.');'; |
|---|
| | 71 | |
|---|
| | 72 | return $js_code; |
|---|
| | 73 | } |
|---|
| | 74 | |
|---|
| 42 | | |
|---|
| 43 | | $request = sfContext::getInstance()->getResponse(); |
|---|
| 44 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/prototype'); |
|---|
| 45 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/scriptaculous'); |
|---|
| 46 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/effects'); |
|---|
| 47 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/window'); |
|---|
| 48 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/window_ext'); |
|---|
| 49 | | |
|---|
| 50 | | $request->addStylesheet(sfConfig::get('sf_prototype_web_dir').'/themes/default.css'); |
|---|
| 51 | | |
|---|
| 52 | | if(isset($window_options['className']) && ($window_options['className'] != 'default')) |
|---|
| 53 | | { |
|---|
| 54 | | $request->addStylesheet(sfConfig::get('sf_prototype_web_dir').'/themes/'.$window_options['className'].'.css'); |
|---|
| 55 | | } |
|---|
| 56 | | |
|---|
| 57 | | if(sfConfig::get('sf_debug')) |
|---|
| 58 | | { |
|---|
| 59 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/debug'); |
|---|
| 60 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/extended_debug'); |
|---|
| 61 | | } |
|---|
| 62 | | |
|---|
| 63 | | $window_options = array_merge(array('title' => 'New Dialog', 'className' => 'dialog', 'width' => '200', 'height' => '100', 'zIndex' => '100', 'draggable' => 'true', 'resizable' => 'true', 'opacity' => 1, 'showEffect' => 'Effect.BlindDown', 'hideEffect' => 'Effect.SwitchOff'), _parse_attributes($window_options)); |
|---|
| 64 | | |
|---|
| 65 | | if (isset($window_options['title'])) { $window_options['title'] = _method_option_to_s($window_options['title']); } |
|---|
| 66 | | if (isset($window_options['className'])) { $window_options['className'] = _method_option_to_s($window_options['className']); } |
|---|
| 67 | | |
|---|
| 68 | | $window_options = _options_for_javascript($window_options); |
|---|
| 69 | | $default_options = array('windowParameters' => $window_options); |
|---|
| 70 | | $options = _options_for_javascript(array_merge($default_options, _parse_attributes($options))); |
|---|
| 71 | | |
|---|
| 72 | | $js_code = 'Dialog.'.$dialog_type.'('._method_option_to_s($content).', '.$options.');'; |
|---|
| | 98 | $js_code = javascript_for_prototype_dialog($name, $content, $dialog_type, $window_options, $options); |
|---|
| | 107 | |
|---|
| | 108 | /** |
|---|
| | 109 | * javascript_for_prototype_window generates javacript for a window using prototype. |
|---|
| | 110 | * |
|---|
| | 111 | * Example: |
|---|
| | 112 | * <code> |
|---|
| | 113 | * <?php use_helper('Window'); ?> |
|---|
| | 114 | * <?php if(sfConfig::get('sf_debug')) { echo link_to_function('open debug window', 'showDebug()'); } ?> |
|---|
| | 115 | * <?php echo javascript_for_prototype_window('Google', 'google', array('title' => 'Google', 'url' => 'http://google.com', 'width' => '520', 'height' => '350', 'center' => 'true', 'className' => 'alphacube'), array('absolute' => true)); ?> |
|---|
| | 116 | * <?php echo javascript_for_prototype_window('DW', 'dw', array('title' => 'DW', 'url' => '@homepage', 'width' => '520', 'height' => '350', 'center' => 'true', 'className' => 'alphacube')); ?> |
|---|
| | 117 | * </code> |
|---|
| | 118 | * |
|---|
| | 119 | * @link http://prototype-window.xilinus.com/documentation.html#initialize |
|---|
| | 120 | * |
|---|
| | 121 | * @param string $name |
|---|
| | 122 | * @param string $window_id must be unique and it's destroyed on window close. |
|---|
| | 123 | * @param array $options options for this helper: http://prototype-window.xilinus.com/documentation.html#initialize |
|---|
| | 124 | * @return string |
|---|
| | 125 | */ |
|---|
| | 126 | function javascript_for_prototype_window($name, $window_id, $options) |
|---|
| | 127 | { |
|---|
| | 128 | $request = sfContext::getInstance()->getResponse(); |
|---|
| | 129 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| | 130 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/scriptaculous'); |
|---|
| | 131 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/effects'); |
|---|
| | 132 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/window'); |
|---|
| | 133 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/window_ext'); |
|---|
| | 134 | |
|---|
| | 135 | $request->addStylesheet('/sfPrototypeWindowPlugin/themes/default.css'); |
|---|
| | 136 | |
|---|
| | 137 | if(isset($window_options['className']) && ($window_options['className'] != 'default')) |
|---|
| | 138 | { |
|---|
| | 139 | $request->addStylesheet('/sfPrototypeWindowPlugin/themes/'.$window_options['className'].'.css'); |
|---|
| | 140 | } |
|---|
| | 141 | |
|---|
| | 142 | if(sfConfig::get('sf_debug')) |
|---|
| | 143 | { |
|---|
| | 144 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/debug'); |
|---|
| | 145 | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/extended_debug'); |
|---|
| | 146 | } |
|---|
| | 147 | |
|---|
| | 148 | $options = array_merge(array('title' => 'New Window', 'className' => 'dialog', 'width' => '600', 'height' => '450', 'zIndex' => '100', 'draggable' => 'true', 'resizable' => 'true', 'opacity' => 1, 'showEffect' => 'Effect.BlindDown', 'hideEffect' => 'Effect.SwitchOff'), _parse_attributes($options)); |
|---|
| | 149 | |
|---|
| | 150 | if (isset($options['title'])) { $options['title'] = _method_option_to_s($options['title']); } |
|---|
| | 151 | if (isset($options['className'])) { $options['className'] = _method_option_to_s($options['className']); } |
|---|
| | 152 | |
|---|
| | 153 | $absolute = isset($options_html['absolute']) ? true : false; |
|---|
| | 154 | unset($options_html['absolute']); |
|---|
| | 155 | |
|---|
| | 156 | if (isset($options['url'])) { $options['url'] = _method_option_to_s(url_for($options['url'], $absolute)); } |
|---|
| | 157 | |
|---|
| | 158 | $front = isset($options['front']) ? $window_id.'.toFront();' : ''; |
|---|
| | 159 | unset($options['front']); |
|---|
| | 160 | |
|---|
| | 161 | $status = isset($options['status']) ? $window_id.'.setStatusBar('.$options['status'].');' : ''; |
|---|
| | 162 | unset($options['status']); |
|---|
| | 163 | |
|---|
| | 164 | $show = isset($options['center']) ? $window_id.'.showCenter();' : $window_id.'.show();'; |
|---|
| | 165 | unset($options['center']); |
|---|
| | 166 | |
|---|
| | 167 | $options = _options_for_javascript($options); |
|---|
| | 168 | |
|---|
| | 169 | $js_code = 'var ' . $window_id . ' = new Window('.$window_id.', '.$options.');'.$front.$status.$show.$window_id.'.setDestroyOnClose();'; |
|---|
| | 170 | |
|---|
| | 171 | return $js_code; |
|---|
| | 172 | } |
|---|
| | 173 | |
|---|
| 104 | | $request = sfContext::getInstance()->getResponse(); |
|---|
| 105 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/prototype'); |
|---|
| 106 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/scriptaculous'); |
|---|
| 107 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/effects'); |
|---|
| 108 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/window'); |
|---|
| 109 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/window_ext'); |
|---|
| 110 | | |
|---|
| 111 | | $request->addStylesheet(sfConfig::get('sf_prototype_web_dir').'/themes/default.css'); |
|---|
| 112 | | |
|---|
| 113 | | if(isset($options['className']) && ($options['className'] != 'default')) |
|---|
| 114 | | { |
|---|
| 115 | | $request->addStylesheet(sfConfig::get('sf_prototype_web_dir').'/themes/'.$options['className'].'.css'); |
|---|
| 116 | | } |
|---|
| 117 | | |
|---|
| 118 | | if(sfConfig::get('sf_debug')) |
|---|
| 119 | | { |
|---|
| 120 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/debug'); |
|---|
| 121 | | $request->addJavascript(sfConfig::get('sf_prototype_web_dir').'/extended_debug'); |
|---|
| 122 | | } |
|---|
| 123 | | |
|---|
| 124 | | $options = array_merge(array('title' => 'New Window', 'className' => 'dialog', 'width' => '600', 'height' => '450', 'zIndex' => '100', 'draggable' => 'true', 'resizable' => 'true', 'opacity' => 1, 'showEffect' => 'Effect.BlindDown', 'hideEffect' => 'Effect.SwitchOff'), _parse_attributes($options)); |
|---|
| 125 | | |
|---|
| 126 | | if (isset($options['title'])) { $options['title'] = _method_option_to_s($options['title']); } |
|---|
| 127 | | if (isset($options['className'])) { $options['className'] = _method_option_to_s($options['className']); } |
|---|
| 128 | | |
|---|
| 129 | | $absolute = isset($options_html['absolute']) ? true : false; |
|---|
| 130 | | unset($options_html['absolute']); |
|---|
| 131 | | |
|---|
| 132 | | if (isset($options['url'])) { $options['url'] = _method_option_to_s(url_for($options['url'], $absolute)); } |
|---|
| 133 | | |
|---|
| 134 | | $front = isset($options['front']) ? $window_id.'.toFront();' : ''; |
|---|
| 135 | | unset($options['front']); |
|---|
| 136 | | |
|---|
| 137 | | $status = isset($options['status']) ? $window_id.'.setStatusBar('.$options['status'].');' : ''; |
|---|
| 138 | | unset($options['status']); |
|---|
| 139 | | |
|---|
| 140 | | $show = isset($options['center']) ? $window_id.'.showCenter();' : $window_id.'.show();'; |
|---|
| 141 | | unset($options['center']); |
|---|
| 142 | | |
|---|
| 143 | | $options = _options_for_javascript($options); |
|---|
| | 196 | $js_code = javascript_for_prototype_window($name, $window_id, $options); |
|---|
| | 197 | |
|---|