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;
|
2016-04-07 12:38:05 +02:00
|
|
|
/api/js/dhtmlxtree/codebase/dhtmlxcommon.js;
|
|
|
|
/api/js/dhtmlxMenu/sources/dhtmlxmenu.js;
|
|
|
|
/api/js/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
|
2016-04-30 11:29:54 +02:00
|
|
|
//if(typeof egw == 'function') egw(window).includeCSS(egw.webserverUrl + "/api/js/egw_action/test/skins/dhtmlxmenu_egw.css");
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {type} _structure
|
|
|
|
*/
|
2021-06-10 13:59:12 +02:00
|
|
|
export function egwMenuImpl(_structure)
|
2011-02-23 19:24:16 +01:00
|
|
|
{
|
|
|
|
//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);
|
2018-11-27 11:50:23 +01:00
|
|
|
|
|
|
|
// Add disableIfNoEPL class to the relevant action's DOM
|
|
|
|
for(var i in this.dhtmlxmenu.idPull)
|
|
|
|
{
|
2018-12-13 15:29:31 +01:00
|
|
|
if (this.dhtmlxmenu.userData[i+'_egw_menu'] &&
|
|
|
|
this.dhtmlxmenu.userData[i+'_egw_menu']['data'] &&
|
|
|
|
this.dhtmlxmenu.userData[i+'_egw_menu']['data']['disableIfNoEPL'])
|
2018-11-27 11:50:23 +01:00
|
|
|
{
|
|
|
|
this.dhtmlxmenu.idPull[i].className += ' disableIfNoEPL';
|
|
|
|
}
|
|
|
|
}
|
2011-02-23 19:24:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 elem = _structure[i];
|
2014-12-16 17:27:33 +01:00
|
|
|
var id = elem.id || 'elem_' + (_idCnt + counter);
|
2011-02-23 19:24:16 +01:00
|
|
|
|
|
|
|
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;
|
2016-04-30 11:29:54 +02:00
|
|
|
};
|
2011-02-23 19:24:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
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);
|
2016-04-30 11:29:54 +02:00
|
|
|
};
|
2011-02-23 19:24:16 +01:00
|
|
|
|
|
|
|
egwMenuImpl.prototype.hide = function()
|
|
|
|
{
|
|
|
|
this.dhtmlxmenu.hide();
|
2016-04-30 11:29:54 +02:00
|
|
|
};
|