Commit 19f261ca14bdf4fee94b2ee9e1e0ed11ab2ec280

Authored by Conrad Vermeulen
1 parent 11d49c4e

KTS-3169

"Provide some actions for portlets that allow javascript to be called rather than requiring the action framework"
Implemented.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8263 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/actions/documentaction.inc.php
... ... @@ -5,32 +5,32 @@
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
8   - *
  8 + *
9 9 * This program is free software; you can redistribute it and/or modify it under
10 10 * the terms of the GNU General Public License version 3 as published by the
11 11 * Free Software Foundation.
12   - *
  12 + *
13 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 16 * details.
17   - *
  17 + *
18 18 * You should have received a copy of the GNU General Public License
19 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20   - *
  20 + *
21 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23   - *
  23 + *
24 24 * The interactive user interfaces in modified source and object code versions
25 25 * of this program must display Appropriate Legal Notices, as required under
26 26 * Section 5 of the GNU General Public License version 3.
27   - *
  27 + *
28 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32   - * must display the words "Powered by KnowledgeTree" and retain the original
33   - * copyright notice.
  32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 34 * Contributor( s): ______________________________________
35 35 *
36 36 */
... ... @@ -203,6 +203,121 @@ class KTDocumentAction extends KTStandardDispatcher {
203 203 }
204 204 }
205 205  
  206 +class JavascriptDocumentAction extends KTDocumentAction
  207 +{
  208 + /**
  209 + * This is an array of js files to be included for this action
  210 + *
  211 + * @var array
  212 + */
  213 + var $js_paths = array();
  214 + /**
  215 + * This is custom javascript that should be included
  216 + *
  217 + * @var array
  218 + */
  219 + var $js = array();
  220 + /**
  221 + * Indicates if a custom function should be provided, or if the function is part of an existing js file.
  222 + * If true
  223 + *
  224 + * @var boolean
  225 + */
  226 + var $function_provided_by_action = true;
  227 +
  228 + /**
  229 + * Set the function name if you have a custom name you want to provide.
  230 + *
  231 + * @var string
  232 + */
  233 + var $function_name = null;
  234 +
  235 + function JavascriptDocumentAction($oDocument = null, $oUser = null, $oPlugin = null)
  236 + {
  237 + parent::KTDocumentAction($oDocument, $oUser, $oPlugin);
  238 + $this->js_initialise();
  239 + }
  240 +
  241 + function js_initialise()
  242 + {
  243 + // this will be overridden
  244 + }
  245 +
  246 + function js_include($js)
  247 + {
  248 + $this->js[] = $js;
  249 + }
  250 +
  251 + function js_include_file($path)
  252 + {
  253 + global $AjaxDocumentJSPaths;
  254 +
  255 + if (!isset($AjaxDocumentJSPaths))
  256 + {
  257 + $AjaxDocumentJSPaths = array();
  258 + }
  259 +
  260 + if (!in_array($AjaxDocumentJSPaths))
  261 + {
  262 + $AjaxDocumentJSPaths[] = $path;
  263 + $this->js_paths [] = $path;
  264 + }
  265 + }
  266 +
  267 + function customiseInfo($aInfo)
  268 + {
  269 + $js = '';
  270 + foreach($this->js_paths as $path)
  271 + {
  272 + $js .= "<script language=\"javascript\" src=\"$path\"></script>\n";
  273 + }
  274 +
  275 + $js .= '<script language="javascript">'. "\n";
  276 + foreach($this->js as $js2)
  277 + {
  278 + $js .= $js2 . "\n";
  279 + }
  280 +
  281 + $js .= $this->getScript() . '</script>'. "\n";
  282 +
  283 + $js .= '<div onclick="' . $this->getScriptActivation() . '"><a>' . $this->getDisplayName() . '</a></div>'. "\n";
  284 +
  285 +
  286 + $aInfo['js'] = $js;
  287 +
  288 + return $aInfo;
  289 + }
  290 +
  291 + function getScript()
  292 + {
  293 + if ($this->function_provided_by_action === false)
  294 + {
  295 + return '';
  296 + }
  297 + return "function " . $this->getScriptActivation() . '{'.$this->getFunctionScript().'}';
  298 + }
  299 +
  300 + function getFunctionScript()
  301 + {
  302 + return 'alert(\''. $this->getDisplayName() .' not implemented!\');';
  303 + }
  304 +
  305 + function getScriptActivation()
  306 + {
  307 + if (!is_null($this->function_name))
  308 + {
  309 + return $this->function_name;
  310 + }
  311 +
  312 + global $AjaxDocumentActions;
  313 + $class = get_class($this);
  314 + return 'js' . $class. 'Dispatcher()';
  315 + }
  316 +
  317 +
  318 +
  319 +}
  320 +
206 321 class KTDocumentActionUtil {
207 322 function getDocumentActionInfo($slot = 'documentaction') {
208 323 $oRegistry =& KTActionRegistry::getSingleton();
... ...
lib/actions/folderaction.inc.php
... ... @@ -5,32 +5,32 @@
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
8   - *
  8 + *
9 9 * This program is free software; you can redistribute it and/or modify it under
10 10 * the terms of the GNU General Public License version 3 as published by the
11 11 * Free Software Foundation.
12   - *
  12 + *
13 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 16 * details.
17   - *
  17 + *
18 18 * You should have received a copy of the GNU General Public License
19 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20   - *
  20 + *
21 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23   - *
  23 + *
24 24 * The interactive user interfaces in modified source and object code versions
25 25 * of this program must display Appropriate Legal Notices, as required under
26 26 * Section 5 of the GNU General Public License version 3.
27   - *
  27 + *
28 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32   - * must display the words "Powered by KnowledgeTree" and retain the original
33   - * copyright notice.
  32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 34 * Contributor( s): ______________________________________
35 35 *
36 36 */
... ... @@ -177,6 +177,122 @@ class KTFolderAction extends KTStandardDispatcher {
177 177  
178 178 }
179 179  
  180 +class JavascriptFolderAction extends KTFolderAction
  181 +{
  182 + /**
  183 + * This is an array of js files to be included for this action
  184 + *
  185 + * @var array
  186 + */
  187 + var $js_paths = array();
  188 + /**
  189 + * This is custom javascript that should be included
  190 + *
  191 + * @var array
  192 + */
  193 + var $js = array();
  194 + /**
  195 + * Indicates if a custom function should be provided, or if the function is part of an existing js file.
  196 + * If true
  197 + *
  198 + * @var boolean
  199 + */
  200 + var $function_provided_by_action = true;
  201 +
  202 + /**
  203 + * Set the function name if you have a custom name you want to provide.
  204 + *
  205 + * @var string
  206 + */
  207 + var $function_name = null;
  208 +
  209 + function JavascriptFolderAction($oFolder = null, $oUser = null, $oPlugin = null)
  210 + {
  211 + parent::KTFolderAction($oFolder, $oUser, $oPlugin);
  212 + $this->js_initialise();
  213 + }
  214 +
  215 + function js_initialise()
  216 + {
  217 + // this will be overridden
  218 + }
  219 +
  220 + function js_include($js)
  221 + {
  222 + $this->js[] = $js;
  223 + }
  224 +
  225 + function js_include_file($path)
  226 + {
  227 + global $AjaxDocumentJSPaths;
  228 +
  229 + if (!isset($AjaxDocumentJSPaths))
  230 + {
  231 + $AjaxDocumentJSPaths = array();
  232 + }
  233 +
  234 + if (!in_array($AjaxDocumentJSPaths))
  235 + {
  236 + $AjaxDocumentJSPaths[] = $path;
  237 + $this->js_paths [] = $path;
  238 + }
  239 + }
  240 +
  241 + function customiseInfo($aInfo)
  242 + {
  243 + $js = '';
  244 + foreach($this->js_paths as $path)
  245 + {
  246 + $js .= "<script language=\"javascript\" src=\"$path\"></script>\n";
  247 + }
  248 +
  249 + $js .= '<script language="javascript">'. "\n";
  250 + foreach($this->js as $js2)
  251 + {
  252 + $js .= $js2 . "\n";
  253 + }
  254 +
  255 + $js .= $this->getScript() . '</script>'. "\n";
  256 +
  257 + $js .= '<div onclick="' . $this->getScriptActivation() . '"><a>' . $this->getDisplayName() . '</a></div>'. "\n";
  258 +
  259 +
  260 + $aInfo['js'] = $js;
  261 +
  262 + return $aInfo;
  263 + }
  264 +
  265 + function getScript()
  266 + {
  267 + if ($this->function_provided_by_action === false)
  268 + {
  269 + return '';
  270 + }
  271 + return "function " . $this->getScriptActivation() . '{'.$this->getFunctionScript().'}';
  272 + }
  273 +
  274 + function getFunctionScript()
  275 + {
  276 + return 'alert(\''. $this->getDisplayName() .' not implemented!\');';
  277 + }
  278 +
  279 + function getScriptActivation()
  280 + {
  281 + if (!is_null($this->function_name))
  282 + {
  283 + return $this->function_name;
  284 + }
  285 +
  286 + global $AjaxDocumentActions;
  287 + $class = get_class($this);
  288 + return 'js' . $class. 'Dispatcher()';
  289 + }
  290 +
  291 +
  292 +
  293 +}
  294 +
  295 +
180 296 class KTFolderActionUtil {
181 297 function getFolderActions() {
182 298 $oRegistry =& KTActionRegistry::getSingleton();
... ...
templates/kt3/portlets/actions_portlet.smarty
... ... @@ -2,6 +2,9 @@
2 2 {foreach item=action from=$context->actions }
3 3 {if $action != null}
4 4 <li {if $action.active}class="active"{/if}>
  5 +{if $action.js}
  6 + {$action.js}
  7 +{else}
5 8 {if ($action.url)}
6 9 <a href="{$action.url}" {if $action.description}title="{$action.description}"{/if}>
7 10 {$action.name}
... ... @@ -10,5 +13,6 @@
10 13 {$action.name}
11 14 {/if}</li>
12 15 {/if}
  16 +{/if}
13 17 {/foreach}
14 18 </ul>
... ...
templates/ktcore/forms/widgets/string.smarty
1   - <input type="text" name="{$name}" {if $has_id}id="{$id}"{/if} {if $has_value}value="{$value|sanitize_input}"{/if}{if ($options.autocomplete === false)}autocomplete="off"{/if} {if $options.width}size="{$options.width}"{/if} />
  1 + <input type="text" name="{$name}" {if $has_id}id="{$id}"{/if} {if $has_value}value="{$value|sanitize_input}"{/if}{if ($options.autocomplete === false)}autocomplete="off"{/if} {if $options.width}size="{$options.width}"{/if} {if $options.onchange}onchange="{$options.onchange}" {/if}/>
... ...