Skip to content

Commit

Permalink
Load custom JS for all backends/auth mechanisms
Browse files Browse the repository at this point in the history
Loading custom JS on a per-backend basis added needless complexity and
made dealing with async required. Now all backends/auth mechanisms load
custom JS in PHP
  • Loading branch information
Robin McCorkell committed Aug 17, 2015
1 parent 81365ec commit 496165c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
3 changes: 0 additions & 3 deletions apps/files_external/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,9 +731,6 @@ MountConfigListView.prototype = {

var priorityEl = $('<input type="hidden" class="priority" value="' + backendConfiguration['priority'] + '" />');
$tr.append(priorityEl);
if (backendConfiguration['custom'] && $el.find('tbody tr.'+backend.replace(/\\/g, '\\\\')).length === 1) {
OC.addScript('files_external', backendConfiguration['custom']);
}
$td.children().not('[type=hidden]').first().focus();

$tr.find('td').last().attr('class', 'remove');
Expand Down
17 changes: 15 additions & 2 deletions apps/files_external/personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@
OCP\Util::addScript('files_external', 'settings');
OCP\Util::addStyle('files_external', 'settings');

$backends = $backendService->getBackendsVisibleFor(BackendService::VISIBILITY_PERSONAL);
$authMechanisms = $backendService->getAuthMechanismsVisibleFor(BackendService::VISIBILITY_PERSONAL);
foreach ($backends as $backend) {
if ($backend->getCustomJs()) {
\OCP\Util::addScript('files_external', $backend->getCustomJs());
}
}
foreach ($authMechanisms as $authMechanism) {
if ($authMechanism->getCustomJs()) {
\OCP\Util::addScript('files_external', $authMechanism->getCustomJs());
}
}

$tmpl = new OCP\Template('files_external', 'settings');
$tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
$tmpl->assign('isAdminPage', false);
$tmpl->assign('storages', $userStoragesService->getAllStorages());
$tmpl->assign('dependencies', OC_Mount_Config::dependencyMessage($backendService->getBackends()));
$tmpl->assign('backends', $backendService->getBackendsVisibleFor(BackendService::VISIBILITY_PERSONAL));
$tmpl->assign('authMechanisms', $backendService->getAuthMechanisms());
$tmpl->assign('backends', $backends);
$tmpl->assign('authMechanisms', $authMechanisms);
return $tmpl->fetchPage();
17 changes: 15 additions & 2 deletions apps/files_external/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,25 @@
\OC_Util::addVendorScript('select2/select2');
\OC_Util::addVendorStyle('select2/select2');

$backends = $backendService->getBackendsVisibleFor(BackendService::VISIBILITY_ADMIN);
$authMechanisms = $backendService->getAuthMechanismsVisibleFor(BackendService::VISIBILITY_ADMIN);
foreach ($backends as $backend) {
if ($backend->getCustomJs()) {
\OCP\Util::addScript('files_external', $backend->getCustomJs());
}
}
foreach ($authMechanisms as $authMechanism) {
if ($authMechanism->getCustomJs()) {
\OCP\Util::addScript('files_external', $authMechanism->getCustomJs());
}
}

$tmpl = new OCP\Template('files_external', 'settings');
$tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
$tmpl->assign('isAdminPage', true);
$tmpl->assign('storages', $globalStoragesService->getAllStorages());
$tmpl->assign('backends', $backendService->getBackendsVisibleFor(BackendService::VISIBILITY_ADMIN));
$tmpl->assign('authMechanisms', $backendService->getAuthMechanisms());
$tmpl->assign('backends', $backends);
$tmpl->assign('authMechanisms', $authMechanisms);
$tmpl->assign('userBackends', $backendService->getBackendsAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL));
$tmpl->assign('dependencies', OC_Mount_Config::dependencyMessage($backendService->getBackends()));
$tmpl->assign('allowUserMounting', $backendService->isUserMountingAllowed());
Expand Down
9 changes: 0 additions & 9 deletions apps/files_external/templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,6 @@ function writeParameterInput($parameter, $options, $classes = []) {
foreach ($storage->getAuthMechanism()->getParameters() as $parameter) {
writeParameterInput($parameter, $options, ['auth-param']);
}

$customJs = $storage->getBackend()->getCustomJs();
if (isset($customJs)) {
\OCP\Util::addScript('files_external', $customJs);
}
$customJsAuth = $storage->getAuthMechanism()->getCustomJs();
if (isset($customJsAuth)) {
\OCP\Util::addScript('files_external', $customJsAuth);
}
?>
</td>
<?php if ($_['isAdminPage']): ?>
Expand Down

0 comments on commit 496165c

Please sign in to comment.