diff --git a/lib/actions/documentaction.inc.php b/lib/actions/documentaction.inc.php index 8f90846..e96cfd3 100644 --- a/lib/actions/documentaction.inc.php +++ b/lib/actions/documentaction.inc.php @@ -5,32 +5,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ @@ -203,6 +203,121 @@ class KTDocumentAction extends KTStandardDispatcher { } } +class JavascriptDocumentAction extends KTDocumentAction +{ + /** + * This is an array of js files to be included for this action + * + * @var array + */ + var $js_paths = array(); + /** + * This is custom javascript that should be included + * + * @var array + */ + var $js = array(); + /** + * Indicates if a custom function should be provided, or if the function is part of an existing js file. + * If true + * + * @var boolean + */ + var $function_provided_by_action = true; + + /** + * Set the function name if you have a custom name you want to provide. + * + * @var string + */ + var $function_name = null; + + function JavascriptDocumentAction($oDocument = null, $oUser = null, $oPlugin = null) + { + parent::KTDocumentAction($oDocument, $oUser, $oPlugin); + $this->js_initialise(); + } + + function js_initialise() + { + // this will be overridden + } + + function js_include($js) + { + $this->js[] = $js; + } + + function js_include_file($path) + { + global $AjaxDocumentJSPaths; + + if (!isset($AjaxDocumentJSPaths)) + { + $AjaxDocumentJSPaths = array(); + } + + if (!in_array($AjaxDocumentJSPaths)) + { + $AjaxDocumentJSPaths[] = $path; + $this->js_paths [] = $path; + } + } + + function customiseInfo($aInfo) + { + $js = ''; + foreach($this->js_paths as $path) + { + $js .= "\n"; + } + + $js .= ''. "\n"; + + $js .= '
' . $this->getDisplayName() . '
'. "\n"; + + + $aInfo['js'] = $js; + + return $aInfo; + } + + function getScript() + { + if ($this->function_provided_by_action === false) + { + return ''; + } + return "function " . $this->getScriptActivation() . '{'.$this->getFunctionScript().'}'; + } + + function getFunctionScript() + { + return 'alert(\''. $this->getDisplayName() .' not implemented!\');'; + } + + function getScriptActivation() + { + if (!is_null($this->function_name)) + { + return $this->function_name; + } + + global $AjaxDocumentActions; + $class = get_class($this); + return 'js' . $class. 'Dispatcher()'; + } + + + +} + class KTDocumentActionUtil { function getDocumentActionInfo($slot = 'documentaction') { $oRegistry =& KTActionRegistry::getSingleton(); diff --git a/lib/actions/folderaction.inc.php b/lib/actions/folderaction.inc.php index 11879af..d3090ba 100644 --- a/lib/actions/folderaction.inc.php +++ b/lib/actions/folderaction.inc.php @@ -5,32 +5,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ @@ -177,6 +177,122 @@ class KTFolderAction extends KTStandardDispatcher { } +class JavascriptFolderAction extends KTFolderAction +{ + /** + * This is an array of js files to be included for this action + * + * @var array + */ + var $js_paths = array(); + /** + * This is custom javascript that should be included + * + * @var array + */ + var $js = array(); + /** + * Indicates if a custom function should be provided, or if the function is part of an existing js file. + * If true + * + * @var boolean + */ + var $function_provided_by_action = true; + + /** + * Set the function name if you have a custom name you want to provide. + * + * @var string + */ + var $function_name = null; + + function JavascriptFolderAction($oFolder = null, $oUser = null, $oPlugin = null) + { + parent::KTFolderAction($oFolder, $oUser, $oPlugin); + $this->js_initialise(); + } + + function js_initialise() + { + // this will be overridden + } + + function js_include($js) + { + $this->js[] = $js; + } + + function js_include_file($path) + { + global $AjaxDocumentJSPaths; + + if (!isset($AjaxDocumentJSPaths)) + { + $AjaxDocumentJSPaths = array(); + } + + if (!in_array($AjaxDocumentJSPaths)) + { + $AjaxDocumentJSPaths[] = $path; + $this->js_paths [] = $path; + } + } + + function customiseInfo($aInfo) + { + $js = ''; + foreach($this->js_paths as $path) + { + $js .= "\n"; + } + + $js .= ''. "\n"; + + $js .= '
' . $this->getDisplayName() . '
'. "\n"; + + + $aInfo['js'] = $js; + + return $aInfo; + } + + function getScript() + { + if ($this->function_provided_by_action === false) + { + return ''; + } + return "function " . $this->getScriptActivation() . '{'.$this->getFunctionScript().'}'; + } + + function getFunctionScript() + { + return 'alert(\''. $this->getDisplayName() .' not implemented!\');'; + } + + function getScriptActivation() + { + if (!is_null($this->function_name)) + { + return $this->function_name; + } + + global $AjaxDocumentActions; + $class = get_class($this); + return 'js' . $class. 'Dispatcher()'; + } + + + +} + + class KTFolderActionUtil { function getFolderActions() { $oRegistry =& KTActionRegistry::getSingleton(); diff --git a/templates/kt3/portlets/actions_portlet.smarty b/templates/kt3/portlets/actions_portlet.smarty index 8739ab3..e271fc4 100644 --- a/templates/kt3/portlets/actions_portlet.smarty +++ b/templates/kt3/portlets/actions_portlet.smarty @@ -2,6 +2,9 @@ {foreach item=action from=$context->actions } {if $action != null}
  • +{if $action.js} + {$action.js} +{else} {if ($action.url)} {$action.name} @@ -10,5 +13,6 @@ {$action.name} {/if}
  • {/if} +{/if} {/foreach} diff --git a/templates/ktcore/forms/widgets/string.smarty b/templates/ktcore/forms/widgets/string.smarty index 1de962c..48814ed 100644 --- a/templates/ktcore/forms/widgets/string.smarty +++ b/templates/ktcore/forms/widgets/string.smarty @@ -1 +1 @@ - +