2011-02-23 19:24:16 +01:00
|
|
|
/**
|
|
|
|
* eGroupWare egw_action framework - JS Menu abstraction
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Andreas Stöckel <as@stylite.de>
|
|
|
|
* @copyright 2011 by Andreas Stöckel
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package egw_action
|
2011-02-23 21:18:56 +01:00
|
|
|
* @version $Id$
|
2011-02-23 19:24:16 +01:00
|
|
|
*/
|
|
|
|
|
2011-08-03 16:04:30 +02:00
|
|
|
/*egw:uses
|
|
|
|
egw_menu;
|
2014-03-04 10:10:58 +01:00
|
|
|
/phpgwapi/js/dhtmlxtree/dhtmlxTenu/sources/dhtmlxcommon.js;
|
|
|
|
/phpgwapi/js/dhtmlxtree/dhtmlxMenu/sources/dhtmlxmenu.js;
|
|
|
|
/phpgwapi/js/dhtmlxtree/dhtmlxMenu/sources/ext/dhtmlxmenu_ext.js;
|
2011-08-03 16:04:30 +02:00
|
|
|
*/
|
|
|
|
|
2012-06-19 20:55:03 +02:00
|
|
|
// Need CSS, or it doesn't really work
|
|
|
|
if(typeof egw != 'undefined') egw(window).includeCSS(egw.webserverUrl + "/phpgwapi/js/egw_action/test/skins/dhtmlxmenu_egw.css");
|
2011-02-23 19:24:16 +01:00
|
|
|
function egwMenuImpl(_structure)
|
|
|
|
{
|
|
|
|
//Create a new dhtmlxmenu object
|
|
|
|
this.dhtmlxmenu = new dhtmlXMenuObject();
|
|
|
|
this.dhtmlxmenu.setSkin("egw");
|
|
|
|
this.dhtmlxmenu.renderAsContextMenu();
|
2013-04-09 18:13:10 +02:00
|
|
|
// TODO: Keyboard navigation of the menu
|
2011-02-23 19:24:16 +01:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
//Attach the simple click handler
|
|
|
|
this.dhtmlxmenu.attachEvent("onClick", function(id) {
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
var elem = self.dhtmlxmenu.getUserData(id, 'egw_menu');
|
2011-04-17 19:42:04 +02:00
|
|
|
|
2011-02-23 19:24:16 +01:00
|
|
|
if (elem && elem.onClick)
|
|
|
|
{
|
2011-04-17 19:42:04 +02:00
|
|
|
if (elem.checkbox)
|
|
|
|
{
|
|
|
|
self.dhtmlxmenu.setContextMenuHideAllMode(false);
|
|
|
|
}
|
|
|
|
|
2011-04-17 19:51:50 +02:00
|
|
|
var res = elem.onClick(elem);
|
2011-04-17 19:42:04 +02:00
|
|
|
|
2011-04-17 19:51:50 +02:00
|
|
|
if (elem.checkbox && (res === false || res === true))
|
2011-04-17 19:42:04 +02:00
|
|
|
{
|
2011-04-17 19:51:50 +02:00
|
|
|
var checked = res;
|
2011-04-17 19:46:09 +02:00
|
|
|
if (elem.groupIndex != 0)
|
2011-04-17 19:42:04 +02:00
|
|
|
{
|
2011-04-17 19:46:09 +02:00
|
|
|
self.dhtmlxmenu.setRadioChecked(id, checked);
|
2011-04-17 19:42:04 +02:00
|
|
|
}
|
2011-04-17 19:46:09 +02:00
|
|
|
else
|
2011-04-17 19:42:04 +02:00
|
|
|
{
|
2011-04-17 19:46:09 +02:00
|
|
|
self.dhtmlxmenu.setCheckboxState(id, checked);
|
2011-04-17 19:42:04 +02:00
|
|
|
}
|
|
|
|
}
|
2011-02-23 19:24:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//Attach the radiobutton click handler
|
|
|
|
this.dhtmlxmenu.attachEvent("onRadioClick", function(group, idChecked, idClicked, zoneId, casState) {
|
|
|
|
if (idClicked)
|
|
|
|
{
|
|
|
|
var elem = self.dhtmlxmenu.getUserData(idClicked, 'egw_menu');
|
|
|
|
if (elem)
|
|
|
|
{
|
|
|
|
elem.set_checked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
//Attach the radiobutton click handler
|
|
|
|
this.dhtmlxmenu.attachEvent("onCheckboxClick", function(id, state, zoneId, casState) {
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
var elem = self.dhtmlxmenu.getUserData(id, 'egw_menu');
|
|
|
|
if (elem)
|
|
|
|
{
|
|
|
|
elem.set_checked(!state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//Translate the given structure to the dhtmlx object structure
|
|
|
|
this._translateStructure(_structure, this.dhtmlxmenu.topId, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
egwMenuImpl.prototype._translateStructure = function(_structure, _parentId, _idCnt)
|
|
|
|
{
|
|
|
|
//Initialize the counter which we will use to generate unique id's for all
|
|
|
|
//dhtmlx menu objects
|
|
|
|
var counter = 0;
|
|
|
|
var last_id = null;
|
|
|
|
|
|
|
|
for (var i = 0; i < _structure.length; i++)
|
|
|
|
{
|
|
|
|
var id = 'elem_' + (_idCnt + counter);
|
|
|
|
var elem = _structure[i];
|
|
|
|
|
|
|
|
counter++;
|
|
|
|
|
|
|
|
//Check whether this element is a seperator
|
|
|
|
if (elem.caption == '-' && last_id != null)
|
|
|
|
{
|
|
|
|
//Add the separator next to last_id with the id "id"
|
|
|
|
this.dhtmlxmenu.addNewSeparator(last_id, id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (elem.checkbox && elem.groupIndex === 0)
|
|
|
|
{
|
|
|
|
//Add checkbox
|
|
|
|
this.dhtmlxmenu.addCheckbox("child", _parentId, i, id,
|
|
|
|
elem.caption, elem.checked, !elem.enabled);
|
|
|
|
}
|
|
|
|
else if (elem.checkbox && elem.groupIndex > 0)
|
|
|
|
{
|
|
|
|
//Add radiobox
|
|
|
|
elem._dhtmlx_grpid = "grp_" + _idCnt + '_' + elem.groupIndex;
|
|
|
|
this.dhtmlxmenu.addRadioButton("child", _parentId, i, id,
|
|
|
|
elem.caption, elem._dhtmlx_grpid, elem.checked, !elem.enabled);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var caption = elem.caption;
|
2011-02-26 19:04:28 +01:00
|
|
|
if (elem["default"])
|
2011-03-14 21:11:08 +01:00
|
|
|
caption = "<b>" + caption + "</b>";
|
2011-02-23 19:24:16 +01:00
|
|
|
this.dhtmlxmenu.addNewChild(_parentId, i, id, caption, !elem.enabled,
|
|
|
|
elem.iconUrl, elem.iconUrl);
|
|
|
|
}
|
|
|
|
|
2011-06-19 12:48:51 +02:00
|
|
|
if (elem.shortcutCaption != null)
|
|
|
|
{
|
|
|
|
this.dhtmlxmenu.setHotKey(id, elem.shortcutCaption);
|
|
|
|
}
|
|
|
|
|
2011-02-23 19:24:16 +01:00
|
|
|
if (elem.children.length > 0)
|
|
|
|
{
|
|
|
|
counter += this._translateStructure(elem.children, id, (_idCnt + counter));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Set the actual egw menu as user data element
|
|
|
|
this.dhtmlxmenu.setUserData(id, 'egw_menu', elem);
|
|
|
|
|
Fixed problems with executeActionImplementation when called from a container object, fixed problem with popup menu which did not open in some cases, added the ability to use the 'enabled' property of an action as an callback function (actionObject is passed as parameter), introduced egwFnct-class which consistently handles 'javaScript:fnct' strings, added 'allowOnMultiple':'only' setting, added 'hint', 'checkbox', 'checked', 'radioGroup' properties to popup actions, added 'setDefaultExecute' function to egwAction objects, which applies an handler to all objects which don't have a handler yet
2011-04-17 17:38:46 +02:00
|
|
|
// Set the tooltip if one has been set
|
|
|
|
if (elem.hint)
|
|
|
|
{
|
|
|
|
this.dhtmlxmenu.setTooltip(id, elem.hint);
|
|
|
|
}
|
|
|
|
|
2011-02-23 19:24:16 +01:00
|
|
|
var last_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
egwMenuImpl.prototype.showAt = function(_x, _y, _onHide)
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if (_onHide)
|
|
|
|
{
|
|
|
|
this.dhtmlxmenu.attachEvent("onHide", function(id) {
|
|
|
|
if (id === null)
|
|
|
|
{
|
|
|
|
_onHide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
Fixed problems with executeActionImplementation when called from a container object, fixed problem with popup menu which did not open in some cases, added the ability to use the 'enabled' property of an action as an callback function (actionObject is passed as parameter), introduced egwFnct-class which consistently handles 'javaScript:fnct' strings, added 'allowOnMultiple':'only' setting, added 'hint', 'checkbox', 'checked', 'radioGroup' properties to popup actions, added 'setDefaultExecute' function to egwAction objects, which applies an handler to all objects which don't have a handler yet
2011-04-17 17:38:46 +02:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
window.setTimeout(function() {
|
|
|
|
self.dhtmlxmenu.showContextMenu(_x, _y);
|
2013-04-09 18:13:10 +02:00
|
|
|
// TODO: Get keybard focus
|
Fixed problems with executeActionImplementation when called from a container object, fixed problem with popup menu which did not open in some cases, added the ability to use the 'enabled' property of an action as an callback function (actionObject is passed as parameter), introduced egwFnct-class which consistently handles 'javaScript:fnct' strings, added 'allowOnMultiple':'only' setting, added 'hint', 'checkbox', 'checked', 'radioGroup' properties to popup actions, added 'setDefaultExecute' function to egwAction objects, which applies an handler to all objects which don't have a handler yet
2011-04-17 17:38:46 +02:00
|
|
|
}, 0);
|
2011-02-23 19:24:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
egwMenuImpl.prototype.hide = function()
|
|
|
|
{
|
|
|
|
this.dhtmlxmenu.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|