From 34772099513df0734d3149e7b6d2d011f1f5e5e7 Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 6 Apr 2007 04:28:46 +0000 Subject: refactor client scripts. --- .../Web/UI/ActiveControls/TActiveRatingList.php | 40 +++++++++++++--------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'framework/Web/UI/ActiveControls/TActiveRatingList.php') diff --git a/framework/Web/UI/ActiveControls/TActiveRatingList.php b/framework/Web/UI/ActiveControls/TActiveRatingList.php index 5f0a24ff..c1404814 100644 --- a/framework/Web/UI/ActiveControls/TActiveRatingList.php +++ b/framework/Web/UI/ActiveControls/TActiveRatingList.php @@ -22,6 +22,8 @@ */ class TActiveRatingList extends TActiveRadioButtonList { + const SCRIPT_PATH = 'prado/activeratings'; + /** * @var array list of published rating images. */ @@ -261,6 +263,16 @@ class TActiveRatingList extends TActiveRadioButtonList return ''; } + /** + * @param string asset file in the self::SCRIPT_PATH directory. + * @return string asset file url. + */ + protected function getAssetUrl($file='') + { + $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl(); + return $base.'/'.self::SCRIPT_PATH.'/'.$file; + } + /** * @param string rating style name * @return string URL of the css style file @@ -268,12 +280,9 @@ class TActiveRatingList extends TActiveRadioButtonList protected function publishRatingListStyle($style) { $cs = $this->getPage()->getClientScript(); - $stylesheet = 'System.Web.Javascripts.prado.activeratings.'.$style; - if(($cssFile=Prado::getPathOfNamespace($stylesheet,'.css'))===null) - throw new TConfigurationException('ratinglist_stylesheet_not_found',$style); - $url = $this->publishFilePath($cssFile); - if(!$cs->isStyleSheetFileRegistered($style)) - $cs->registerStyleSheetFile($style, $url); + $url = $this->getAssetUrl($style.'.css'); + if(!$cs->isStyleSheetFileRegistered($url)) + $cs->registerStyleSheetFile($url, $url); return $url; } @@ -284,17 +293,10 @@ class TActiveRatingList extends TActiveRadioButtonList */ protected function publishRatingListImages($style, $fileExt='.gif') { - $images['blank'] = "System.Web.Javascripts.prado.activeratings.{$style}_blank"; - $images['selected'] = "System.Web.Javascripts.prado.activeratings.{$style}_selected"; - $images['half'] = "System.Web.Javascripts.prado.activeratings.{$style}_half"; - $images['combined'] = "System.Web.Javascripts.prado.activeratings.{$style}_combined"; + $types = array('blank', 'selected', 'half', 'combined'); $files = array(); - foreach($images as $type => $image) - { - if(($file=Prado::getPathOfNamespace($image, $fileExt))===null) - throw TConfigurationException('ratinglist_image_not_found',$image); - $files[$type] = $this->publishFilePath($file); - } + foreach($types as $type) + $files[$type] = $this->getAssetUrl("{$style}_{$type}{$fileExt}"); return $files; } @@ -308,6 +310,12 @@ class TActiveRatingList extends TActiveRadioButtonList { if($this->getReadOnly()) $writer->addAttribute('class', $this->getRatingStyleCssClass()); + else + { + $writer->addAttribute('id',$this->getClientID()); + $this->getActiveControl()->registerCallbackClientScript( + $this->getClientClassName(), $this->getPostBackOptions()); + } parent::render($writer); } -- cgit v1.2.3