diff options
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Exceptions/messages.txt | 1 | ||||
-rw-r--r-- | framework/Web/UI/ActiveControls/TActiveRatingList.php | 40 | ||||
-rw-r--r-- | framework/Web/UI/TClientScriptManager.php | 139 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TClientScriptLoader.php | 73 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TColorPicker.php | 51 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TDatePicker.php | 48 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TRatingList.php | 34 |
7 files changed, 179 insertions, 207 deletions
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt index 3ca019d4..9072cbc3 100644 --- a/framework/Exceptions/messages.txt +++ b/framework/Exceptions/messages.txt @@ -189,6 +189,7 @@ page_head_duplicated = A page can contain at most one THead. page_statepersister_invalid = Page state persister must implement IPageStatePersister interface.
csmanager_pradoscript_invalid = Unknown Prado script library name '{0}'.
+csmanager_invalid_packages = Unkownn packages '{1}' for javascript packages defined in '{0}'. Valid packages are '{2}'.
contentplaceholder_id_required = TContentPlaceHolder must have an ID.
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.
*/
@@ -262,18 +264,25 @@ class TActiveRatingList extends TActiveRadioButtonList }
/**
+ * @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
*/
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);
}
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index a319595d..4fded17b 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -4,7 +4,7 @@ * * @author Qiang Xue <qiang.xue@gmail.com> * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005 PradoSoft + * @copyright Copyright © 2005-2007 PradoSoft * @license http://www.pradosoft.com/license/ * @version $Id$ * @package System.Web.UI @@ -25,11 +25,11 @@ class TClientScriptManager extends TApplicationComponent /** * directory containing Prado javascript files */ - const SCRIPT_PATH='Web/Javascripts/js'; + const SCRIPT_PATH='Web/Javascripts/source'; /** * the PHP script for loading Prado javascript files */ - const SCRIPT_LOADER='clientscripts.php'; + const SCRIPT_LOADER='Web/Javascripts/clientscripts.php'; /** * @var TPage page who owns this manager @@ -72,22 +72,10 @@ class TClientScriptManager extends TApplicationComponent */ private $_registeredPradoScripts=array(); /** - * @var array published PRADO script files - */ - private $_publishedPradoFiles=array(); - /** - * Client-side javascript library dependencies + * Client-side javascript library dependencies, loads from SCRIPT_PATH.'/packages.php'; * @var array */ - private static $_pradoScripts=array( - 'prado' => array('prado'), - 'effects' => array('prado', 'effects'), - 'validator' => array('prado', 'validator'), - 'logger' => array('prado', 'logger'), - 'datepicker' => array('prado', 'datepicker'), - 'colorpicker' => array('prado', 'colorpicker'), - 'ajax' => array('prado', 'effects', 'ajax') - ); + private static $_pradoScripts; /** * Constructor. @@ -99,23 +87,13 @@ class TClientScriptManager extends TApplicationComponent } /** - * Registers Prado scripts by library name. - * Each library may include one or several script files. - * Currently, the following libraries are available: - * - prado : basic prado js framework - * - effects : - * - ajax : ajax related js - * - validator : validator js - * - logger : js logger - * - datepicker : datepicker js - * - colorpicker : colorpicker js - * The script files registered will be published. + * Registers Prado javascript by library name. See "Web/Javascripts/source/packages.php" + * for library names. * @param string script library name. */ public function registerPradoScript($name) { $this->registerPradoScriptInternal($name); - $params=func_get_args(); $this->_page->registerCachingAction('Page.ClientScript','registerPradoScript',$params); } @@ -127,32 +105,28 @@ class TClientScriptManager extends TApplicationComponent { if(!isset($this->_registeredPradoScripts[$name])) { + if(is_null(self::$_pradoScripts)) + { + $packageFile = Prado::getFrameworkPath().'/'.self::SCRIPT_PATH.'/packages.php'; + list($packages,$deps)= include($packageFile); + self::$_pradoScripts = $deps; + } + if(isset(self::$_pradoScripts[$name])) $this->_registeredPradoScripts[$name]=true; else throw new TInvalidOperationException('csmanager_pradoscript_invalid',$name); - $basePath=$this->getPradoScriptBasePath(); - foreach(self::$_pradoScripts[$name] as $script) - { - if(!isset($this->_publishedPradoFiles[$script])) - { - $this->publishFilePath($basePath.'/'.$script.'.js'); - $this->_publishedPradoFiles[$script]=true; - } - } } } /** - * @return string the directory containing the PRADO js script files + * @return string Prado javascript library base asset url. */ - protected function getPradoScriptBasePath() + public function getPradoScriptAssetUrl() { - $basePath = Prado::getFrameworkPath().'/'.self::SCRIPT_PATH; - if($this->getApplication()->getMode()===TApplicationMode::Debug) - return $basePath.'/debug'; - else - return $basePath.'/compressed'; + $base = Prado::getFrameworkPath().'/'.self::SCRIPT_PATH; + $assets = Prado::getApplication()->getAssetManager(); + return $assets->getPublishedUrl($base); } /** @@ -161,19 +135,80 @@ class TClientScriptManager extends TApplicationComponent */ protected function renderPradoScripts($writer) { - $files=implode(',',array_keys($this->_publishedPradoFiles)); - if($files!=='') + $files=array_keys($this->_registeredPradoScripts); + if(count($files) > 0) { - $basePath=$this->getPradoScriptBasePath(); - $scriptLoader=$basePath.'/'.self::SCRIPT_LOADER; - $url=$this->publishFilePath($scriptLoader).'?js='.trim($files,','); - if($this->getApplication()->getMode()===TApplicationMode::Debug) - $url.='&mode=debug'; + $base = Prado::getFrameworkPath().'/'.self::SCRIPT_PATH; + $url = $this->registerJavascriptPackages($base, $files); $writer->write(TJavaScript::renderScriptFile($url)); } } /** + * Publishes a javascript library path and register packages to be loaded. + * See TClientScriptLoader for component that enables users to register custom javascript libraries. + * @param string javascript library base path + * @param array list of packages or javascript files (without .js extension) to be loaded. + * @param boolean true to enable keep comments in javascript files loaded, null to use application configuration. + * @param boolean true to gzip the javascript code if browsers and php supports it. + * @return string javascript src url + * @since 3.1 + */ + public function registerJavascriptPackages($base, $packages, $debug=null, $gzip=true) + { + list($path,$url) = $this->getPackagePathUrl($base); + $scriptLoaderPath = $path.'/'.basename(self::SCRIPT_LOADER); + $scriptLoaderSrc = Prado::getFrameworkPath().'/'.self::SCRIPT_LOADER; + if(!is_file($scriptLoaderPath)) + copy($scriptLoaderSrc, $scriptLoaderPath); + $url .= '/'.basename(self::SCRIPT_LOADER).'?js='.implode(',', $packages); + if($debug!==false && $this->getApplication()->getMode()===TApplicationMode::Debug) + { + $this->verifyJavascriptPackages($base,$path,$packages); + $url.='&mode=debug'; + } + if($gzip===false) + $url.='&gzip=false'; + return $url; + } + + /** + * @throws TConfigurationException when javascript packages mismatch. + */ + protected function verifyJavascriptPackages($base,$path,$scripts) + { + $file = $path.'/packages.php'; + if(is_file($file)) + { + list($packs,$deps) = include($file); + if(count($missing = array_diff($scripts, array_keys($deps))) > 0) + { + throw new TConfigurationException('csmanager_invalid_packages', + $base.'/packages.php',implode(', ', $missing), implode(', ', array_keys($deps))); + } + } + } + + /** + * @param string javascript package path. + * @return array tuple($path,$url). + */ + protected function getPackagePathUrl($base) + { + $assets = Prado::getApplication()->getAssetManager(); + if(strpos($base, $assets->getBaseUrl())===false) + { + if(!is_null($dir = Prado::getPathOfNameSpace($base))) + $base = $dir; + return array($assets->getPublishedPath($base), $assets->publishFilePath($base)); + } + else + { + return array($assets->getBasePath().str_replace($assets->getBaseUrl(),'',$base), $base); + } + } + + /** * Returns javascript statement that create a new callback request object. * @param ICallbackEventHandler callback response handler * @param array additional callback options diff --git a/framework/Web/UI/WebControls/TClientScriptLoader.php b/framework/Web/UI/WebControls/TClientScriptLoader.php index 1c5b9d29..f59a9ba4 100644 --- a/framework/Web/UI/WebControls/TClientScriptLoader.php +++ b/framework/Web/UI/WebControls/TClientScriptLoader.php @@ -11,7 +11,7 @@ */
/**
- * The TClientScriptLoader publish a collection of javascript files as assets.
+ * The TClientScriptLoader publish a collection of javascript files as assets.
* The {@link PackagePath setPackagePath} property can be an existing asset directory
* or a namespace path to the directory containing javascript files. E.g.
* <code>
@@ -20,7 +20,7 @@ * </code>
*
* When the files in the {@link PackagePath setPackagePath} are published as assets, a script loader
- * php file corresponding to TClientScriptLoader::SCRIPT_LOADER is also copied to that asset directory.
+ * php file corresponding to TClientScriptManager::SCRIPT_LOADER is also copied to that asset directory.
*
* The script loader, combines multiple javascript files and serve up as gzip if possible.
* Allowable scripts and script dependencies can be specified in a "packages.php" file
@@ -54,12 +54,12 @@ * removes comments and whitespaces from the published javascript files. If
* the DebugMode property is not set, the debug mode is determined from the application mode.
*
- * The {@link setEnableGzip EnableGzip} property (default is true) enables the
- * published javascripts to be served as zipped if the browser and php server allows it.
-
+ * The {@link setEnableGzip EnableGzip} property (default is true) enables the
+ * published javascripts to be served as zipped if the browser and php server allows it.
+
* If the DebugMode is false either explicitly or when the application mode is non-debug,
* then cache headers are also sent to inform the browser and proxies to cache the file.
- * Moreover, the post-processed (comments removed and zipped) are saved in the assets
+ * Moreover, the post-processed (comments removed and zipped) are saved in the assets
* directory for the next requests. That is, in non-debug mode the scripts are cached
* in the assets directory until they are deleted.
*
@@ -70,8 +70,6 @@ */
class TClientScriptLoader extends TWebControl
{
- const SCRIPT_LOADER = 'Web/Javascripts/clientscripts.php';
-
/**
* @return string tag name of the script element
*/
@@ -79,7 +77,7 @@ class TClientScriptLoader extends TWebControl {
return 'script';
}
-
+
/**
* Adds attribute name-value pairs to renderer.
* This overrides the parent implementation with additional button specific attributes.
@@ -97,58 +95,13 @@ class TClientScriptLoader extends TWebControl */
protected function getClientScriptUrl()
{
- $baseUrl = $this->publishScriptLoader();
- $scripts = split('/\s*[, ]+\s*/', $this->getPackageScripts());
- $url = $baseUrl . '?js=' . implode(',', $scripts);
- if($this->getDebugMode()!==false && $this->getApplication()->getMode()===TApplicationMode::Debug)
- $url.='&mode=debug';
- if($this->getEnableGzip()===false)
- $url.='&gzip=false';
- return $url;
- }
-
- /**
- * Copies the client script loader php file to the asset directory if appropriate.
- * @return string clientscript.php url
- * @throws TConfigurationException if error in publishing the package path.
- */
- protected function publishScriptLoader()
- {
- list($path, $url) = $this->getPublishedPackagePath();
- if(is_dir($path))
- {
- $scriptLoader = Prado::getFrameworkPath().'/'.self::SCRIPT_LOADER;
- $scriptLoaderFile = basename($scriptLoader);
- $dest = $path.'/'.$scriptLoaderFile;
- if(!is_file($dest))
- copy($scriptLoader,$dest);
- return $url.'/'.$scriptLoaderFile;
- }
- else
- throw new TConfigurationException('clientscript_invalid_package_path',
- $this->getPackagePath(), $this->getUniqueID());
+ $scripts = split('\s*[, ]+\s*', $this->getPackageScripts());
+ $cs = $this->getPage()->getClientScript();
+ return $cs->registerJavascriptPackages($this->getPackagePath(),
+ $scripts, $this->getDebugMode(), $this->getEnableGzip());
}
/**
- * Publishes the package path assets, tries path as namespace first.
- * @return array tuple ($path, $url).
- */
- protected function getPublishedPackagePath()
- {
- $assets = $this->getApplication()->getAssetManager();
- //assumes dot path first
- $dir = Prado::getPathOfNameSpace($this->getPackagePath());
- if(!is_null($dir))
- {
- $url = $assets->publishFilePath($dir); //show throw an excemption if invalid
- return array($dir, $url);
- }
- $url = $this->getPackagePath();
- $packageDir = str_replace($assets->getBaseUrl(), '', $url);
- return array($assets->getBasePath().$packageDir,$url);
- }
-
- /**
* @param string custom javascript library directory.
*/
public function setPackagePath($value)
@@ -165,7 +118,7 @@ class TClientScriptLoader extends TWebControl }
/**
- * @param string load specific packages from the javascript library in the PackagePath,
+ * @param string load specific packages from the javascript library in the PackagePath,
* comma delimited package names. A maximum of 25 packages is allowed.
*/
public function setPackageScripts($value)
@@ -198,7 +151,7 @@ class TClientScriptLoader extends TWebControl }
/**
- * @return boolean javascript comments stripped in non-debug mode.
+ * @return boolean javascript comments stripped in non-debug mode.
* Debug mode will depend on the application mode if null.
*/
public function getDebugMode()
diff --git a/framework/Web/UI/WebControls/TColorPicker.php b/framework/Web/UI/WebControls/TColorPicker.php index 64345dcd..efdcbeb4 100644 --- a/framework/Web/UI/WebControls/TColorPicker.php +++ b/framework/Web/UI/WebControls/TColorPicker.php @@ -22,6 +22,8 @@ */
class TColorPicker extends TTextBox
{
+ const SCRIPT_PATH = 'prado/colorpicker';
+
/**
* @return boolean whether the color picker should pop up when the button is clicked.
*/
@@ -128,6 +130,16 @@ class TColorPicker extends TTextBox }
/**
+ * @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;
+ }
+
+ /**
* Publish the color picker Css asset files.
*/
public function onPreRender($param)
@@ -143,47 +155,24 @@ class TColorPicker extends TTextBox protected function publishColorPickerStyle()
{
$cs = $this->getPage()->getClientScript();
- $style = 'System.Web.Javascripts.prado.colorpicker.'.$this->getColorPickerStyle();
- if(($cssFile=Prado::getPathOfNamespace($style,'.css'))!==null)
- {
- $url = $this->publishFilePath($cssFile);
- if(!$cs->isStyleSheetFileRegistered($style))
- $cs->registerStyleSheetFile($style, $url);
- return $url;
- }
- else
- throw new TConfigurationException('colorpicker_style_invalid',$style);
+ $url = $this->getAssetUrl($this->getColorPickerStyle().'.css');
+ if(!$cs->isStyleSheetFileRegistered($url))
+ $cs->registerStyleSheetFile($url, $url);
+ return $url;
}
/**
* Publish the color picker image assets.
- * @return array list of image URLs
*/
protected function publishColorPickerImageAssets()
{
$cs = $this->getPage()->getClientScript();
$key = "prado:".get_class($this);
-
- $images = array('button' => '.gif', 'target_black' => '.gif',
- 'target_white' => '.gif', 'background' => '.png',
- 'slider' => '.gif', 'hue' => '.gif');
-
- $list = array();
-
- foreach($images as $filename => $ext)
- {
- $image = 'System.Web.Javascripts.prado.colorpicker.'.$filename;
- if(($file = Prado::getPathOfNamespace($image, $ext))!==null)
- $list[$filename.$ext] = $this->publishFilePath($file);
- else
- throw new TConfigurationException('colorpicker_image_invalid',$image);
- }
- $imgs['button.gif'] = $list['button.gif'];
- $imgs['background.png'] = $list['background.png'];
+ $imgs['button.gif'] = $this->getAssetUrl('button.gif');
+ $imgs['background.png'] = $this->getAssetUrl('background.png');
$options = TJavaScript::encode($imgs);
$code = "Prado.WebUI.TColorPicker.UIImages = {$options};";
$cs->registerEndScript($key, $code);
- return $list;
}
/**
@@ -214,14 +203,14 @@ class TColorPicker extends TTextBox {
parent::render($writer);
- $images = $this->publishColorPickerImageAssets();
$color = $this->getText();
+ $this->publishColorPickerImageAssets();
$writer->addAttribute('class', 'TColorPicker_button');
$writer->renderBeginTag('span');
$writer->addAttribute('id', $this->getClientID().'_button');
- $writer->addAttribute('src', $images['button.gif']);
+ $writer->addAttribute('src', $this->getAssetUrl('button.gif'));
if($color !== '')
$writer->addAttribute('style', "background-color:{$color};");
$writer->addAttribute('width', '20');
diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php index 3e85ffb9..dd922431 100644 --- a/framework/Web/UI/WebControls/TDatePicker.php +++ b/framework/Web/UI/WebControls/TDatePicker.php @@ -67,6 +67,11 @@ Prado::using('System.Web.UI.WebControls.TTextBox'); class TDatePicker extends TTextBox
{
/**
+ * Script path relative to the TClientScriptManager::SCRIPT_PATH
+ */
+ const SCRIPT_PATH = 'prado/datepicker';
+
+ /**
* @var TDatePickerClientScript validator client-script options.
*/
private $_clientScript;
@@ -735,7 +740,7 @@ class TDatePicker extends TTextBox protected function renderImageButtonDatePicker($writer)
{
$url = $this->getButtonImageUrl();
- $url = empty($url) ? $this->publishDefaultButtonImage() : $url;
+ $url = empty($url) ? $this->getAssetUrl('calendar.png') : $url;
$writer->addAttribute('id', $this->getDatePickerButtonID());
$writer->addAttribute('src', $url);
$writer->addAttribute('alt', ' ');
@@ -747,16 +752,13 @@ class TDatePicker extends TTextBox }
/**
- * Publish the default button image asset file.
- * @return string image file url.
+ * @param string date picker asset file in the self::SCRIPT_PATH directory.
+ * @return string date picker asset url.
*/
- protected function publishDefaultButtonImage()
+ protected function getAssetUrl($file='')
{
- $image = 'System.Web.Javascripts.prado.datepicker.calendar';
- if(($file = Prado::getPathOfNamespace($image, '.png'))!==null)
- return $this->publishFilePath($file);
- else
- throw new TConfigurationException('datepicker_defaultbuttonimage_invalid',$image);
+ $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl();
+ return $base.'/'.self::SCRIPT_PATH.'/'.$file;
}
/**
@@ -765,29 +767,11 @@ class TDatePicker extends TTextBox */
protected function publishCalendarStyle()
{
+ $url = $this->getAssetUrl($this->getCalendarStyle().'.css');
$cs = $this->getPage()->getClientScript();
- $style = 'System.Web.Javascripts.prado.datepicker.'.$this->getCalendarStyle();
- if(($cssFile=Prado::getPathOfNamespace($style,'.css'))!==null)
- {
- $url = $this->publishFilePath($cssFile);
- if(!$cs->isStyleSheetFileRegistered($style))
- $cs->registerStyleSheetFile($style, $url);
- return $url;
- }
- else
- throw new TConfigurationException('datepicker_calendarstyle_invalid',$style);
- }
-
- /**
- * Publish the spacer.gif for IE iframe source.
- * @return string the URL for the spacer.gif.
- */
- protected function publishIFrameSpacer()
- {
- $cs = $this->getPage()->getClientScript();
- $spacer = 'System.Web.Javascripts.prado.datepicker.spacer';
- if(($file = Prado::getPathOfNamespace($spacer,'.gif')) != null)
- return $this->publishFilePath($file);
+ if(!$cs->isStyleSheetFileRegistered($url))
+ $cs->registerStyleSheetFile($url, $url);
+ return $url;
}
/**
@@ -814,7 +798,7 @@ class TDatePicker extends TTextBox if(!$cs->isEndScriptRegistered('TDatePicker.spacer'))
{
- $spacer = $this->publishIFrameSpacer();
+ $spacer = $this->getAssetUrl('spacer.gif');
$code = "Prado.WebUI.TDatePicker.spacer = '$spacer';";
$cs->registerEndScript('TDatePicker.spacer', $code);
}
diff --git a/framework/Web/UI/WebControls/TRatingList.php b/framework/Web/UI/WebControls/TRatingList.php index 36febe7b..e50e3fad 100644 --- a/framework/Web/UI/WebControls/TRatingList.php +++ b/framework/Web/UI/WebControls/TRatingList.php @@ -27,6 +27,8 @@ Prado::using('System.Web.UI.WebControls.TRadioButtonList'); */
class TRatingList extends TRadioButtonList
{
+ const SCRIPT_PATH='prado/ratings';
+
private $_ratingImages = array();
public function __construct()
@@ -105,6 +107,16 @@ class TRatingList extends TRadioButtonList return $this->getViewState('HalfRating', array(0.3, 0.7));
}
+ /**
+ * @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;
+ }
+
public function getRatingClientOptions()
{
$options['cssClass'] = 'TRatingList_'.$this->getRatingStyle();
@@ -118,28 +130,18 @@ class TRatingList extends TRadioButtonList protected function publishRatingListStyle($style)
{
$cs = $this->getPage()->getClientScript();
- $stylesheet = 'System.Web.Javascripts.ratings.'.$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;
}
protected function publishRatingListImages($style, $fileExt='.gif')
{
- $images['blank'] = "System.Web.Javascripts.ratings.{$style}_blank";
- $images['hover'] = "System.Web.Javascripts.ratings.{$style}_hover";
- $images['selected'] = "System.Web.Javascripts.ratings.{$style}_selected";
- $images['half'] = "System.Web.Javascripts.ratings.{$style}_half";
+ $images = array('blank', 'hover', 'selected', 'half');
$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($images as $type)
+ $files[$type] = $this->getAssetUrl("{$style}_{$type}{$fileExt}");
return $files;
}
|