Add javascript autoloading

the js/modules/%modulename%/%file% is now mapped to the module
path (if existing). To prevent name clashing, the modules folder
has been renamed to components.
This commit is contained in:
Jannis Moßhammer 2013-06-21 11:36:12 +02:00
parent c40c1dabc7
commit e759911b09
6 changed files with 23 additions and 13 deletions

View File

@ -9,6 +9,7 @@ use Icinga\Web\ActionController;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
use Zend_Controller_Action_Exception as ActionException; use Zend_Controller_Action_Exception as ActionException;
use Icinga\Application\Benchmark;
/** /**
* Class StaticController * Class StaticController
* @package Icinga\Web\Form * @package Icinga\Web\Form
@ -69,7 +70,7 @@ class StaticController extends ActionController
*/ */
public function javascriptAction() public function javascriptAction()
{ {
$module = $this->_getParam('moduleName'); $module = $this->_getParam('module_name');
$file = $this->_getParam('file'); $file = $this->_getParam('file');
$basedir = Icinga::app()->getModule($module)->getBaseDir(); $basedir = Icinga::app()->getModule($module)->getBaseDir();
@ -96,15 +97,16 @@ class StaticController extends ActionController
) . ' GMT' ) . ' GMT'
); );
$hash = md5_file($filePath);
if ($hash === $this->getRequest()->getHeader('If-None-Match')) { if ($hash === $this->getRequest()->getHeader('If-None-Match')) {
$response->setHttpResponseCode(304); $response->setHttpResponseCode(304);
return; return;
} else { } else {
readfile($filePath); readfile($filePath);
} }
// TODO: get rid of exit: return;
exit;
} }
} }
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd

View File

@ -60,6 +60,17 @@ class Web extends ApplicationBootstrap
) )
) )
); );
$this->frontController->getRouter()->addRoute(
'module_javascript',
new Route(
'js/modules/:module_name/:file',
array(
'controller' => 'static',
'action' => 'javascript'
)
)
);
return $this; return $this;
} }
@ -173,6 +184,7 @@ class Web extends ApplicationBootstrap
*/ */
protected function configurePagination() protected function configurePagination()
{ {
Paginator::addScrollingStylePrefixPath( Paginator::addScrollingStylePrefixPath(
'Icinga_Web_Paginator_ScrollingStyle', 'Icinga_Web_Paginator_ScrollingStyle',
'Icinga/Web/Paginator/ScrollingStyle' 'Icinga/Web/Paginator/ScrollingStyle'

View File

@ -5,7 +5,7 @@
var containerMgrInstance = null; var containerMgrInstance = null;
var async; var async;
var ContainerMgr = function($,log,Widgets,SubTable,holder) { var ContainerMgr = function($,log,Widgets,SubTable) {
var enhanceDetachLinks = function() { var enhanceDetachLinks = function() {
@ -34,14 +34,12 @@
} }
target.focus(); target.focus();
this.initializeContainers(target); this.initializeContainers(target);
holder.run();
}; };
this.updateControlTargets = function(ctrl, req) { this.updateControlTargets = function(ctrl, req) {
$('a',ctrl).each(function() { $('a',ctrl).each(function() {
$(this).attr("href",req.url); $(this).attr("href",req.url);
}); });
holder.run();
}; };
this.initControlBehaviour = function(root) { this.initControlBehaviour = function(root) {
@ -86,7 +84,6 @@
this.initExpandables(root); this.initExpandables(root);
this.drawImplicitWidgets(root); this.drawImplicitWidgets(root);
this.loadAsyncContainers(root); this.loadAsyncContainers(root);
holder.run();
}; };
this.createPopupContainer = function(content,req) { this.createPopupContainer = function(content,req) {
@ -96,7 +93,6 @@
.append($("<div>").addClass('modal-body').html(content)).appendTo(document.body); .append($("<div>").addClass('modal-body').html(content)).appendTo(document.body);
closeButton.on("click",function() {container.remove();}); closeButton.on("click",function() {container.remove();});
holder.run();
}; };
this.getContainer = function(id) { this.getContainer = function(id) {
@ -107,9 +103,9 @@
}; };
}; };
define(['jquery','logging','icinga/widgets/checkIcons','icinga/widgets/subTable','Holder'],function($,log,widgets,subTable,holder) { define(['jquery','logging','icinga/widgets/checkIcons','icinga/widgets/subTable'],function($,log,widgets,subTable) {
if (containerMgrInstance === null) { if (containerMgrInstance === null) {
containerMgrInstance = new ContainerMgr($,log,widgets,subTable,holder); containerMgrInstance = new ContainerMgr($,log,widgets,subTable);
} }
return containerMgrInstance; return containerMgrInstance;

View File

@ -13,7 +13,7 @@ define([
* Icinga prototype * Icinga prototype
*/ */
var Icinga = function() { var Icinga = function() {
var internalModules = ['icinga/modules/actionTable','icinga/modules/mainDetail']; var internalModules = ['icinga/components/actionTable','icinga/components/mainDetail'];
this.modules = {}; this.modules = {};
var failedModules = []; var failedModules = [];
@ -37,7 +37,7 @@ define([
}; };
var loadModuleScript = function(name) { var loadModuleScript = function(name) {
moduleMgr.enableModule("modules/"+name, function(error) { moduleMgr.enableModule("modules/"+name+"/"+name, function(error) {
failedModules.push({ failedModules.push({
name: name, name: name,
errorMessage: error errorMessage: error