BUG 0000 - Javascript Registry for plugins was added
- using inside the plugin class:
registerJavascript('core_folder/core_js', 'my_plugin/my_js');
This commit is contained in:
@@ -409,7 +409,11 @@ class headPublisher {
|
|||||||
* later, when we use the includeExtJs function, all the files in this array will be included in the output
|
* later, when we use the includeExtJs function, all the files in this array will be included in the output
|
||||||
* if the second argument is true, the file will not be minified, this is useful for debug purposes.
|
* if the second argument is true, the file will not be minified, this is useful for debug purposes.
|
||||||
*
|
*
|
||||||
|
* Feature added - <erik@colosa.com>
|
||||||
|
* - Hook to find javascript registered from plugins and load them
|
||||||
|
*
|
||||||
* @author Fernando Ontiveros <fernando@colosa.com>
|
* @author Fernando Ontiveros <fernando@colosa.com>
|
||||||
|
* @author Erik Amaru Ortiz <erik@colosa.com>
|
||||||
* @access public
|
* @access public
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -456,6 +460,45 @@ class headPublisher {
|
|||||||
file_put_contents ( $cacheFilename, $content );
|
file_put_contents ( $cacheFilename, $content );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//hook for registered javascripts from plugins
|
||||||
|
$oPluginRegistry = & PMPluginRegistry::getSingleton();
|
||||||
|
$pluginJavascripts = $oPluginRegistry->getRegisteredJavascriptBy($filename);
|
||||||
|
if (count($pluginJavascripts) > 0) {
|
||||||
|
if ($debug) {
|
||||||
|
foreach ($pluginJavascripts as $pluginJsFile) {
|
||||||
|
if (substr($pluginJsFile, -3) != '.js') {
|
||||||
|
$pluginJsFile .= '.js';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_exists(PATH_PLUGINS . $pluginJsFile)) {
|
||||||
|
$jsPluginCacheName = str_replace ( '/', '_', str_replace('.js', '', $pluginJsFile) );
|
||||||
|
$cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $jsPluginCacheName;
|
||||||
|
file_put_contents ( $cacheFilename, file_get_contents ( PATH_PLUGINS . $pluginJsFile ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foreach ($pluginJavascripts as $pluginJsFile) {
|
||||||
|
if (substr($pluginJsFile, -3) !== '.js') {
|
||||||
|
$pluginJsFile .= '.js';
|
||||||
|
}
|
||||||
|
if (file_exists(PATH_PLUGINS . $pluginJsFile)) {
|
||||||
|
$mtime = filemtime ( PATH_PLUGINS . $pluginJsFile );
|
||||||
|
$jsPluginCacheName = md5 ( $mtime . $pluginJsFile );
|
||||||
|
$cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $jsPluginCacheName . '.js';
|
||||||
|
|
||||||
|
if (! file_exists ( $cacheFilename )) {
|
||||||
|
require_once (PATH_THIRDPARTY . 'jsmin/jsmin.php');
|
||||||
|
$content = JSMin::minify ( file_get_contents ( PATH_PLUGINS . $pluginJsFile ) );
|
||||||
|
file_put_contents ( $cacheFilename, $content );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->extJsScript [] = '/extjs/' . $jsPluginCacheName;
|
||||||
|
}
|
||||||
|
//end hook for registered javascripts from plugins
|
||||||
|
|
||||||
$this->extJsScript [] = '/extjs/' . $cacheName;
|
$this->extJsScript [] = '/extjs/' . $cacheName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -572,7 +572,7 @@ class PMPlugin {
|
|||||||
$oPluginRegistry =& PMPluginRegistry::getSingleton();
|
$oPluginRegistry =& PMPluginRegistry::getSingleton();
|
||||||
$oPluginRegistry->registerCaseSchedulerPlugin( $this->sNamespace, $sActionId, $sActionForm, $sActionSave, $sActionExecute, $sActionGetFields );
|
$oPluginRegistry->registerCaseSchedulerPlugin( $this->sNamespace, $sActionId, $sActionForm, $sActionSave, $sActionExecute, $sActionGetFields );
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* With this function we can register a Dashboard Page for Cases Dashboard
|
* With this function we can register a Dashboard Page for Cases Dashboard
|
||||||
* @param string $sPage
|
* @param string $sPage
|
||||||
* @return void
|
* @return void
|
||||||
@@ -581,4 +581,26 @@ class PMPlugin {
|
|||||||
$oPluginRegistry =& PMPluginRegistry::getSingleton();
|
$oPluginRegistry =& PMPluginRegistry::getSingleton();
|
||||||
$oPluginRegistry->registerTaskExtendedProperty ( $this->sNamespace, $sPage, $sName, $sIcon );
|
$oPluginRegistry->registerTaskExtendedProperty ( $this->sNamespace, $sPage, $sName, $sIcon );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a plugin javascript to run with core js script at same runtime
|
||||||
|
* @param string $coreJsFile
|
||||||
|
* @param array/string $pluginJsFile
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function registerJavascript($sCoreJsFile, $pluginJsFile) {
|
||||||
|
$oPluginRegistry =& PMPluginRegistry::getSingleton();
|
||||||
|
$oPluginRegistry->registerJavascript($this->sNamespace, $sCoreJsFile, $pluginJsFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregister a plugin javascript
|
||||||
|
* @param string $coreJsFile
|
||||||
|
* @param array/string $pluginJsFile
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function unregisterJavascript($sCoreJsFile, $pluginJsFile) {
|
||||||
|
$oPluginRegistry =& PMPluginRegistry::getSingleton();
|
||||||
|
$oPluginRegistry->unregisterJavascript($this->sNamespace, $sCoreJsFile, $pluginJsFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -90,6 +90,11 @@ class PMPluginRegistry {
|
|||||||
private $_aCaseSchedulerPlugin = array();
|
private $_aCaseSchedulerPlugin = array();
|
||||||
private $_aTaskExtendedProperties = array();
|
private $_aTaskExtendedProperties = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registry a plugin javascript to include with js core at same runtime
|
||||||
|
*/
|
||||||
|
private $_aJavascripts = array();
|
||||||
|
|
||||||
static private $instance = NULL;
|
static private $instance = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,7 +233,7 @@ class PMPluginRegistry {
|
|||||||
*
|
*
|
||||||
* @param unknown_type $sNamespace
|
* @param unknown_type $sNamespace
|
||||||
*/
|
*/
|
||||||
function disablePlugin($sNamespace )
|
function disablePlugin($sNamespace)
|
||||||
{
|
{
|
||||||
$found = false;
|
$found = false;
|
||||||
foreach ( $this->_aPluginDetails as $namespace=>$detail ) {
|
foreach ( $this->_aPluginDetails as $namespace=>$detail ) {
|
||||||
@@ -305,7 +310,8 @@ class PMPluginRegistry {
|
|||||||
unset ( $this->_aTaskExtendedProperties[ $key ] );
|
unset ( $this->_aTaskExtendedProperties[ $key ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//unregistering javascripts from this plugin
|
||||||
|
$this->unregisterJavascripts($sNamespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -537,6 +543,108 @@ class PMPluginRegistry {
|
|||||||
return $this->_aCSSStyleSheets;
|
return $this->_aCSSStyleSheets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a plugin javascript to run with core js script at same runtime
|
||||||
|
*
|
||||||
|
* @param string $sNamespace
|
||||||
|
* @param string $coreJsFile
|
||||||
|
* @param array/string $pluginJsFile
|
||||||
|
*/
|
||||||
|
function registerJavascript($sNamespace, $sCoreJsFile, $pluginJsFile) {
|
||||||
|
|
||||||
|
foreach ($this->_aJavascripts as $i=>$js) {
|
||||||
|
if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) {
|
||||||
|
if (is_string($pluginJsFile)) {
|
||||||
|
if (!in_array($pluginJsFile, $this->_aJavascripts[$i]->pluginJsFile)) {
|
||||||
|
$this->_aJavascripts[$i]->pluginJsFile[] = $pluginJsFile;
|
||||||
|
}
|
||||||
|
} else if (is_array($pluginJsFile)) {
|
||||||
|
$this->_aJavascripts[$i]->pluginJsFile = array_unique(array_merge($pluginJsFile, $this->_aJavascripts[$i]->pluginJsFile));
|
||||||
|
} else {
|
||||||
|
throw new Exception('Invalid third param, $pluginJsFile should be a string or array - '. gettype($pluginJsFile). ' given.');
|
||||||
|
}
|
||||||
|
return $this->_aJavascripts[$i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$js = new StdClass();
|
||||||
|
$js->sNamespace = $sNamespace;
|
||||||
|
$js->sCoreJsFile = $sCoreJsFile;
|
||||||
|
$js->pluginJsFile = Array();
|
||||||
|
|
||||||
|
if (is_string($pluginJsFile)) {
|
||||||
|
$js->pluginJsFile[] = $pluginJsFile;
|
||||||
|
} else if (is_array($pluginJsFile)){
|
||||||
|
$js->pluginJsFile = array_merge($js->pluginJsFile, $pluginJsFile);
|
||||||
|
} else {
|
||||||
|
throw new Exception('Invalid third param, $pluginJsFile should be a string or array - '. gettype($pluginJsFile). ' given.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_aJavascripts[] = $js;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return all plugin javascripts
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function getRegisteredJavascript() {
|
||||||
|
return $this->_aJavascripts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return all plugin javascripts
|
||||||
|
* @param string $sCoreJsFile
|
||||||
|
* @param string $sNamespace
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function getRegisteredJavascriptBy($sCoreJsFile, $sNamespace='') {
|
||||||
|
$scripts = array();
|
||||||
|
|
||||||
|
if ($sNamespace == '') {
|
||||||
|
foreach ($this->_aJavascripts as $i=>$js) {
|
||||||
|
if ($sCoreJsFile == $js->sCoreJsFile) {
|
||||||
|
$scripts = array_merge($scripts, $this->_aJavascripts[$i]->pluginJsFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($this->_aJavascripts as $i=>$js) {
|
||||||
|
if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) {
|
||||||
|
$scripts = array_merge($scripts, $this->_aJavascripts[$i]->pluginJsFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $scripts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return all dashboard pages
|
||||||
|
* @param string $sNamespace
|
||||||
|
* @param string $sCoreJsFile
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function unregisterJavascripts($sNamespace, $sCoreJsFile='') {
|
||||||
|
if ($sCoreJsFile == '') { // if $sCoreJsFile=='' unregister all js from this namespace
|
||||||
|
foreach ($this->_aJavascripts as $i=>$js) {
|
||||||
|
if ($sNamespace == $js->sNamespace) {
|
||||||
|
unset($this->_aJavascripts[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Re-index when all js were unregistered
|
||||||
|
$this->_aJavascripts = array_values($this->_aJavascripts);
|
||||||
|
} else {
|
||||||
|
foreach ($this->_aJavascripts as $i=>$js) {
|
||||||
|
if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) {
|
||||||
|
unset($this->_aJavascripts[$i]);
|
||||||
|
// Re-index for each js that was unregistered
|
||||||
|
$this->_aJavascripts = array_values($this->_aJavascripts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a reports class in the singleton
|
* Register a reports class in the singleton
|
||||||
|
|||||||
Reference in New Issue
Block a user