2 /*********************************************************************************
3 * SugarCRM is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
42 function contextMenu() {
43 $this->menuItems = array();
46 function getScript() {
48 return "SUGAR.contextMenu.registerObjectType('{$this->objectName}', " . $json->encode($this->menuItems) . ");\n";
52 * adds a menu item to the current contextMenu
54 * @param string $text text of the item
55 * @param string $action function or pointer to the javascript function to call
56 * @param array $params other parameters includes:
57 * url - The URL for the MenuItem's anchor's "href" attribute.
58 * target - The value to be used for the MenuItem's anchor's "target" attribute.
59 * helptext - Additional instructional text to accompany the text for a MenuItem. Example: If the text is
60 * "Copy" you might want to add the help text "Ctrl + C" to inform the user there is a keyboard
61 * shortcut for the item.
62 * emphasis - If set to true the text for the MenuItem will be rendered with emphasis (using <em>).
63 * strongemphasis - If set to true the text for the MenuItem will be rendered with strong emphasis (using <strong>).
64 * disabled - If set to true the MenuItem will be dimmed and will not respond to user input or fire events.
65 * selected - If set to true the MenuItem will be highlighted.
66 * submenu - Appends / removes a menu (and it's associated DOM elements) to / from the MenuItem.
67 * checked - If set to true the MenuItem will be rendered with a checkmark.
69 function addMenuItem($text, $action, $module = null, $aclAction = null, $params = null) {
70 // check ACLs if module and aclAction set otherwise no ACL check
71 if(((!empty($module) && !empty($aclAction)) && ACLController::checkAccess($module, $aclAction)) || (empty($module) || empty($aclAction))) {
72 $item = array('text' => translate($text),
74 foreach(array('url', 'target', 'helptext', 'emphasis', 'strongemphasis', 'disabled', 'selected', 'submenu', 'checked') as $param) {
75 if(!empty($params[$param])) $item[$param] = $params[$param];
77 array_push($this->menuItems, $item);
82 * Loads up menu items from files located in include/contextMenus/menuDefs
83 * @param string $name name of the object
85 function loadFromFile($name) {
87 clean_string($name, 'FILE');
88 require_once('include/contextMenus/menuDefs/' . $name . '.php');
89 $this->loadFromDef($name, $menuDef[$name]);
93 * Loads up menu items from def
94 * @param string $name name of the object type
95 * @param array $defs menu item definitions
97 function loadFromDef($name, $defs) {
98 $this->objectName = $name;
99 foreach($defs as $def) {
100 $this->addMenuItem($def['text'], $def['action'],
101 (empty($def['module']) ? null : $def['module']),
102 (empty($def['aclAction']) ? null : $def['aclAction']),
103 (empty($def['params']) ? null : $def['params']));