2013-10-04 09:29:38 +02:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - JS toolbar object
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright Nathan Gray 2013
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
2016-06-06 17:38:20 +02:00
|
|
|
/vendor/bower-asset/jquery/dist/jquery.js;
|
|
|
|
/vendor/bower-asset/jquery-ui/jquery-ui.js;
|
2013-10-04 09:29:38 +02:00
|
|
|
et2_DOMWidget;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This toolbar gets its contents from its actions
|
2014-01-06 17:45:54 +01:00
|
|
|
*
|
2013-10-04 09:29:38 +02:00
|
|
|
* @augments et2_valueWidget
|
2014-01-06 17:45:54 +01:00
|
|
|
*/
|
2016-02-29 21:40:43 +01:00
|
|
|
var et2_toolbar = (function(){ "use strict"; return et2_DOMWidget.extend([et2_IInput],
|
2013-10-04 09:29:38 +02:00
|
|
|
{
|
|
|
|
attributes: {
|
2014-02-05 17:04:58 +01:00
|
|
|
"view_range": {
|
|
|
|
"name": "View range",
|
|
|
|
"type": "string",
|
2014-02-10 15:10:17 +01:00
|
|
|
"default": "5",
|
2014-02-05 17:04:58 +01:00
|
|
|
"description": "Define minimum action view range to show actions by both icons and caption"
|
2014-02-13 11:40:39 +01:00
|
|
|
},
|
|
|
|
"flat_list": {
|
|
|
|
"name": "Flat list",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": true,
|
|
|
|
"description": "Define whether the actions with children should be shown as dropdown or flat list"
|
2014-02-07 11:33:05 +01:00
|
|
|
}
|
2013-10-04 09:29:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default buttons, so there is something for the widget browser / editor to show
|
|
|
|
*/
|
|
|
|
default_toolbar: {
|
2014-02-10 16:43:51 +01:00
|
|
|
view: {caption:'View', icons: {primary: 'ui-icon-check'}, group:1, toolbarDefault:true},
|
|
|
|
edit: {caption:'Edit', group:1, toolbarDefault:true},
|
|
|
|
save: {caption:'Save', group:2, toolbarDefault:true}
|
2013-10-04 09:29:38 +02:00
|
|
|
},
|
|
|
|
|
2014-03-10 22:14:02 +01:00
|
|
|
/**
|
|
|
|
* id of last action executed / value of toolbar if submitted
|
|
|
|
*/
|
|
|
|
value: null,
|
|
|
|
|
2013-10-04 09:29:38 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
2014-01-06 17:45:54 +01:00
|
|
|
*
|
2013-10-04 09:29:38 +02:00
|
|
|
* @memberOf et2_dropdown_button
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2016-06-02 16:51:15 +02:00
|
|
|
this.div = jQuery(document.createElement('div'))
|
2013-10-04 09:29:38 +02:00
|
|
|
.addClass('et2_toolbar ui-widget-header ui-corner-all');
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2015-01-08 15:02:21 +01:00
|
|
|
// Set proper id and dom_id for the widget
|
|
|
|
this.set_id(this.id);
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2014-01-13 11:26:20 +01:00
|
|
|
//actionbox is the div for stored actions
|
2016-06-02 16:51:15 +02:00
|
|
|
this.actionbox = jQuery(document.createElement('div'))
|
2016-01-11 20:38:03 +01:00
|
|
|
.addClass("et2_toolbar_more")
|
2014-01-13 11:26:20 +01:00
|
|
|
.attr('id',this.id +'-'+ 'actionbox');
|
|
|
|
//actionlist is div for active actions
|
2016-06-02 16:51:15 +02:00
|
|
|
this.actionlist = jQuery(document.createElement('div'))
|
2014-02-06 12:25:56 +01:00
|
|
|
.addClass("et2_toolbar_actionlist")
|
|
|
|
.attr('id',this.id +'-'+ 'actionlist');
|
2014-01-13 11:26:20 +01:00
|
|
|
|
2014-02-05 17:04:58 +01:00
|
|
|
this.countActions = 0;
|
2013-10-04 09:29:38 +02:00
|
|
|
this.dropdowns = {};
|
2014-01-13 11:26:20 +01:00
|
|
|
this.preference = {};
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2015-09-18 15:32:51 +02:00
|
|
|
this._build_menu(this.default_toolbar, true);
|
2013-10-04 09:29:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
// Destroy widget
|
|
|
|
if(this.div && this.div.data('ui-menu')) this.menu.menu("destroy");
|
|
|
|
|
|
|
|
// Null children
|
|
|
|
|
|
|
|
// Remove
|
|
|
|
this.div.empty().remove();
|
2014-01-13 11:26:20 +01:00
|
|
|
this.actionbox.empty().remove();
|
|
|
|
this.actionlist.empty().remove();
|
2013-10-04 09:29:38 +02:00
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2015-09-18 15:32:51 +02:00
|
|
|
/**
|
|
|
|
* Fix function in order to fix toolbar preferences with the new preference structure
|
|
|
|
* @param {action object} _action
|
|
|
|
* @todo ** SEE IMPORTANT TODO **
|
|
|
|
*/
|
|
|
|
_fix_preference: function (_action)
|
|
|
|
{
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2015-09-18 15:32:51 +02:00
|
|
|
// ** IMPORTANT TODO: This switch case should be removed for new release **
|
|
|
|
// This is an ugly hack but we need to add this switch becuase to update and fix
|
|
|
|
// current users toolbar preferences with the new structure which is:
|
|
|
|
// - All actions should be stored in preference
|
|
|
|
// - Actions inside menu set as true
|
|
|
|
// - Actions outside menu set as false
|
|
|
|
// - if an action gets added to toolbar it would be undefined in
|
|
|
|
// the preference which we need to consider to add it to the preference
|
|
|
|
// according to its toolbarDefault option.
|
|
|
|
if (this.dom_id === 'mail-display_displayToolbar' || this.dom_id === 'mail-index_toolbar')
|
|
|
|
{
|
|
|
|
switch (_action.id)
|
|
|
|
{
|
|
|
|
// Actions newly added to mail index and display toolbar
|
|
|
|
case 'read':
|
|
|
|
case 'label1':
|
|
|
|
case 'label2':
|
|
|
|
case 'label3':
|
|
|
|
case 'label4':
|
2016-02-29 21:40:43 +01:00
|
|
|
case 'label5':
|
2015-09-18 15:32:51 +02:00
|
|
|
this.set_prefered(_action.id, !_action.toolbarDefault);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Fix structure and add the actions not the preference
|
|
|
|
// into the preference with value false, as they're already
|
|
|
|
// outside of the menu.
|
|
|
|
this.set_prefered(_action.id, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-09 11:03:12 +01:00
|
|
|
// ** IMPORTANT TODO: This line needs to stay and be fixed with !toolbarDefault after the if condition
|
2015-09-18 15:32:51 +02:00
|
|
|
// has been removed.
|
|
|
|
this.set_prefered(_action.id, false/*!toolbarDefault*/);
|
|
|
|
}
|
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2013-10-04 09:29:38 +02:00
|
|
|
/**
|
|
|
|
* Go through actions and build buttons for the toolbar
|
2014-01-20 19:19:04 +01:00
|
|
|
*
|
|
|
|
* @param {Object} actions egw-actions to build menu from
|
2015-09-18 15:32:51 +02:00
|
|
|
* @param {boolean} isDefault setting isDefault with true will
|
|
|
|
* avoid actions get into the preferences, for instandce, first
|
|
|
|
* time toolbar_default actions initialization.
|
2013-10-04 09:29:38 +02:00
|
|
|
*/
|
2015-09-18 15:32:51 +02:00
|
|
|
_build_menu: function(actions, isDefault)
|
2013-10-04 09:29:38 +02:00
|
|
|
{
|
|
|
|
// Clear existing
|
|
|
|
this.div.empty();
|
2014-01-13 11:26:20 +01:00
|
|
|
this.actionbox.empty();
|
|
|
|
this.actionlist.empty();
|
2014-02-06 14:43:11 +01:00
|
|
|
this.actionbox.append('<h class="ui-toolbar-menulistHeader">'+egw.lang('more')+' ...'+'</h>');
|
2014-01-13 11:26:20 +01:00
|
|
|
this.actionbox.append('<div id="' + this.id + '-menulist' +'" class="ui-toolbar-menulist" ></div>');
|
2014-02-13 15:33:48 +01:00
|
|
|
var that = this;
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2016-01-21 11:15:34 +01:00
|
|
|
var pref = (!egwIsMobile())? egw.preference(this.dom_id,this.egw().getAppName()): undefined;
|
2014-02-07 11:33:05 +01:00
|
|
|
if (pref && !jQuery.isArray(pref)) this.preference = pref;
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2014-02-10 16:43:51 +01:00
|
|
|
//Set the default actions for the first time
|
2015-09-18 15:32:51 +02:00
|
|
|
if (typeof pref === 'undefined' && !isDefault)
|
|
|
|
{
|
|
|
|
for (var name in actions)
|
|
|
|
{
|
|
|
|
if ((typeof actions[name].children === 'undefined' || !this.options.flat_list) && actions[name].id)
|
|
|
|
{
|
|
|
|
this.set_prefered(actions[name].id,!actions[name].toolbarDefault);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!isDefault)
|
2014-02-10 16:43:51 +01:00
|
|
|
{
|
|
|
|
for (var name in actions)
|
|
|
|
{
|
2015-09-18 15:32:51 +02:00
|
|
|
// Check if the action is not in the preference, means it's an new added action
|
|
|
|
// therefore it needs to be added to the preference with taking its toolbarDefault
|
|
|
|
// option into account.
|
|
|
|
if ((typeof actions[name].children === 'undefined' || !this.options.flat_list)
|
|
|
|
&& typeof pref[name] === 'undefined')
|
|
|
|
{
|
|
|
|
this._fix_preference(actions[name]);
|
|
|
|
}
|
2014-02-10 16:43:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 15:33:48 +01:00
|
|
|
//Count number of actions including their children
|
|
|
|
var countActions = function (actions)
|
|
|
|
{
|
|
|
|
var totalCount = 0;
|
|
|
|
var childCounter = function (action, count)
|
|
|
|
{
|
|
|
|
var children = action.children || 0,
|
|
|
|
returnCounter = count || 0;
|
|
|
|
if (children)
|
|
|
|
{
|
|
|
|
returnCounter -= 1;
|
|
|
|
for (var nChild in children)
|
|
|
|
returnCounter += 1;
|
|
|
|
returnCounter = childCounter (children[nChild], returnCounter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
returnCounter = count;
|
|
|
|
}
|
|
|
|
return returnCounter;
|
2014-02-20 19:04:04 +01:00
|
|
|
};
|
2014-02-13 15:33:48 +01:00
|
|
|
for (var nAction in actions)
|
|
|
|
{
|
2016-05-30 17:12:55 +02:00
|
|
|
if (that.options.flat_list)
|
2014-02-13 15:33:48 +01:00
|
|
|
{
|
|
|
|
totalCount += childCounter(actions[nAction],1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
totalCount ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return totalCount;
|
2014-02-20 19:04:04 +01:00
|
|
|
};
|
2015-09-18 15:32:51 +02:00
|
|
|
var menuLen = 0;
|
|
|
|
for (var key in this.preference)
|
|
|
|
{
|
|
|
|
if (this.preference[key]) menuLen++;
|
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2015-09-18 15:32:51 +02:00
|
|
|
this.countActions = countActions(actions) - menuLen;
|
2014-02-27 18:45:25 +01:00
|
|
|
|
2013-10-04 09:29:38 +02:00
|
|
|
var last_group = false;
|
2014-01-17 14:24:18 +01:00
|
|
|
var last_group_id = false;
|
2013-10-04 09:29:38 +02:00
|
|
|
for(var name in actions)
|
|
|
|
{
|
|
|
|
var action = actions[name];
|
2014-03-06 19:38:02 +01:00
|
|
|
if (typeof action == 'string') action = {id: name, caption: action};
|
2014-01-06 17:45:54 +01:00
|
|
|
|
2013-10-04 09:29:38 +02:00
|
|
|
// Add in divider
|
2014-01-17 14:24:18 +01:00
|
|
|
if(last_group_id != action.group)
|
2013-10-04 09:29:38 +02:00
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
last_group = jQuery('[data-group="' + action.group + '"]',this.actionlist);
|
2014-01-17 14:24:18 +01:00
|
|
|
if(last_group.length == 0)
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('<span data-group="'+action.group+'">').appendTo(this.actionlist);
|
2014-02-10 14:03:17 +01:00
|
|
|
}
|
2014-01-17 14:24:18 +01:00
|
|
|
last_group_id = action.group;
|
2013-10-04 09:29:38 +02:00
|
|
|
}
|
2014-01-06 17:45:54 +01:00
|
|
|
|
2013-10-04 09:29:38 +02:00
|
|
|
// Make sure there's something to display
|
|
|
|
if(!action.caption && !action.icon && !action.iconUrl) continue;
|
2014-01-06 17:45:54 +01:00
|
|
|
|
2013-10-04 09:29:38 +02:00
|
|
|
if(action.children)
|
|
|
|
{
|
|
|
|
var children = {};
|
|
|
|
var add_children = function(root, children) {
|
|
|
|
for(var id in root.children)
|
|
|
|
{
|
|
|
|
var info = {
|
|
|
|
id: id || root.children[id].id,
|
|
|
|
label: root.children[id].caption
|
|
|
|
};
|
2014-02-13 11:40:39 +01:00
|
|
|
var childaction = {};
|
2013-10-04 09:29:38 +02:00
|
|
|
if(root.children[id].iconUrl)
|
|
|
|
{
|
|
|
|
info.icon = root.children[id].iconUrl;
|
|
|
|
}
|
|
|
|
if(root.children[id].children)
|
|
|
|
{
|
|
|
|
add_children(root.children[id], info);
|
|
|
|
}
|
|
|
|
children[id] = info;
|
2014-02-13 11:40:39 +01:00
|
|
|
|
2016-05-30 17:12:55 +02:00
|
|
|
if (that.options.flat_list)
|
2014-02-13 11:40:39 +01:00
|
|
|
{
|
|
|
|
childaction = root.children[id];
|
2015-09-18 15:32:51 +02:00
|
|
|
if (typeof pref === 'undefined' && !isDefault)
|
2014-02-20 19:04:04 +01:00
|
|
|
{
|
|
|
|
if (!childaction.toolbarDefault)
|
|
|
|
{
|
2015-09-18 15:32:51 +02:00
|
|
|
that.set_prefered(childaction.id,true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
that.set_prefered(childaction.id,false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!isDefault)
|
|
|
|
{
|
|
|
|
if (typeof pref[childaction.id] === 'undefined')
|
|
|
|
{
|
|
|
|
that._fix_preference(childaction);
|
2014-02-20 19:04:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (typeof root.children[id].group !== 'undefined' &&
|
|
|
|
typeof root.group !== 'undefined')
|
2014-02-13 11:40:39 +01:00
|
|
|
{
|
|
|
|
childaction.group = root.group;
|
|
|
|
}
|
2014-02-19 18:52:31 +01:00
|
|
|
that._make_button (childaction);
|
2014-02-13 11:40:39 +01:00
|
|
|
}
|
2013-10-04 09:29:38 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
add_children(action, children);
|
2016-05-30 17:12:55 +02:00
|
|
|
if (this.options.flat_list && children)
|
2014-02-13 11:40:39 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-27 18:45:25 +01:00
|
|
|
|
2013-10-04 09:29:38 +02:00
|
|
|
var dropdown = et2_createWidget("dropdown_button", {
|
2014-02-19 18:52:31 +01:00
|
|
|
id: action.id
|
2013-10-04 09:29:38 +02:00
|
|
|
},this);
|
2016-01-09 01:54:02 +01:00
|
|
|
|
2013-10-04 09:29:38 +02:00
|
|
|
dropdown.set_select_options(children);
|
2014-02-19 18:52:31 +01:00
|
|
|
dropdown.set_label (action.caption);
|
2015-01-13 13:16:04 +01:00
|
|
|
//Set default selected action
|
|
|
|
if (typeof action.children !='undefined')
|
|
|
|
{
|
|
|
|
for (var child in action.children)
|
|
|
|
{
|
|
|
|
if(action.children[child].default)
|
|
|
|
{
|
|
|
|
dropdown.set_label(action.children[child].caption);
|
|
|
|
}
|
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
}
|
2014-12-23 15:24:25 +01:00
|
|
|
dropdown.set_image (action.iconUrl||'');
|
2013-10-04 09:29:38 +02:00
|
|
|
dropdown.onchange = jQuery.proxy(function(selected, dropdown)
|
|
|
|
{
|
2014-02-19 18:52:31 +01:00
|
|
|
var action = that._actionManager.getActionById(selected.attr('data-id'));
|
2015-01-09 15:45:39 +01:00
|
|
|
dropdown.set_label(action.caption);
|
2013-10-04 09:29:38 +02:00
|
|
|
if(action)
|
|
|
|
{
|
2014-03-10 22:14:02 +01:00
|
|
|
this.value = action.id;
|
|
|
|
action.execute([]);
|
2013-10-04 09:29:38 +02:00
|
|
|
}
|
2014-03-10 22:14:02 +01:00
|
|
|
//console.debug(selected, this, action);
|
2013-10-04 09:29:38 +02:00
|
|
|
},action);
|
|
|
|
dropdown.onclick = jQuery.proxy(function(selected, dropdown)
|
|
|
|
{
|
2014-02-19 18:52:31 +01:00
|
|
|
var action = that._actionManager.getActionById(this.getValue());
|
2013-10-04 09:29:38 +02:00
|
|
|
if(action)
|
|
|
|
{
|
2014-03-10 22:14:02 +01:00
|
|
|
this.value = action.id;
|
|
|
|
action.execute([]);
|
2013-10-04 09:29:38 +02:00
|
|
|
}
|
2014-03-10 22:14:02 +01:00
|
|
|
//console.debug(selected, this, action);
|
2013-10-04 09:29:38 +02:00
|
|
|
},dropdown);
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(dropdown.getDOMNode())
|
2014-02-19 18:52:31 +01:00
|
|
|
.attr('id',this.id + '-' + dropdown.id)
|
|
|
|
.addClass(this.preference[action.id]?'et2_toolbar-dropdown et2_toolbar-dropdown-menulist':'et2_toolbar-dropdown')
|
2016-06-02 16:51:15 +02:00
|
|
|
.appendTo(this.preference[action.id]?this.actionbox.children()[1]:jQuery('[data-group='+action.group+']',this.actionlist));
|
2013-10-04 09:29:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._make_button(action);
|
|
|
|
}
|
|
|
|
}
|
2014-01-13 11:26:20 +01:00
|
|
|
|
|
|
|
// ************** Drag and Drop feature for toolbar *****
|
2016-01-09 01:54:02 +01:00
|
|
|
this.actionlist.find('span[data-group]').sort( function (lg,g){
|
2014-07-11 12:38:36 +02:00
|
|
|
return +lg.getAttribute('data-group') - +g.getAttribute('data-group');
|
2014-02-10 14:03:17 +01:00
|
|
|
}).appendTo(this.actionlist);
|
2014-02-13 11:40:39 +01:00
|
|
|
|
2014-01-13 11:26:20 +01:00
|
|
|
this.actionlist.appendTo(this.div);
|
|
|
|
this.actionbox.appendTo(this.div);
|
2014-03-06 19:38:02 +01:00
|
|
|
|
2016-01-09 01:54:02 +01:00
|
|
|
var toolbar = this.actionlist.find('span[data-group]').children(),
|
2014-02-27 18:45:25 +01:00
|
|
|
toolbox = this.actionbox,
|
2014-02-27 19:15:08 +01:00
|
|
|
menulist = jQuery(this.actionbox.children()[1]);
|
2014-02-27 18:45:25 +01:00
|
|
|
|
2014-01-13 11:26:20 +01:00
|
|
|
toolbar.draggable({
|
|
|
|
cancel:true,
|
2014-02-11 15:18:30 +01:00
|
|
|
zIndex: 1000,
|
2015-02-26 10:21:24 +01:00
|
|
|
delay: 500,
|
2014-01-13 11:26:20 +01:00
|
|
|
//revert:"invalid",
|
|
|
|
containment: "document",
|
|
|
|
cursor: "move",
|
2014-02-05 17:04:58 +01:00
|
|
|
helper: "clone",
|
2014-02-06 12:25:56 +01:00
|
|
|
appendTo:'body',
|
2014-02-05 17:04:58 +01:00
|
|
|
stop: function(event, ui){
|
|
|
|
that._build_menu(actions);
|
|
|
|
}
|
2014-01-13 11:26:20 +01:00
|
|
|
});
|
|
|
|
menulist.children().draggable({
|
|
|
|
cancel:true,
|
|
|
|
containment:"document",
|
|
|
|
helper:"clone",
|
2014-02-06 12:25:56 +01:00
|
|
|
appendTo:'body',
|
2014-02-11 15:18:30 +01:00
|
|
|
zIndex: 1000,
|
2014-09-25 13:12:04 +02:00
|
|
|
cursor:"move",
|
|
|
|
start: function()
|
|
|
|
{
|
|
|
|
jQuery(that.actionlist).addClass('et2_toolbarDropArea');
|
|
|
|
},
|
|
|
|
stop: function()
|
|
|
|
{
|
|
|
|
jQuery(that.actionlist).removeClass('et2_toolbarDropArea');
|
2016-02-29 21:40:43 +01:00
|
|
|
}
|
2014-01-13 11:26:20 +01:00
|
|
|
});
|
2014-02-06 12:25:56 +01:00
|
|
|
toolbox.children().droppable({
|
2014-01-13 11:26:20 +01:00
|
|
|
accept:toolbar,
|
|
|
|
drop:function (event, ui) {
|
2015-09-18 15:32:51 +02:00
|
|
|
that.set_prefered(ui.draggable.attr('id').replace(that.id+'-',''),true);
|
2014-01-13 11:26:20 +01:00
|
|
|
ui.draggable.appendTo(menulist);
|
2014-02-11 17:06:02 +01:00
|
|
|
if (that.actionlist.find(".ui-draggable").length == 0)
|
2014-01-21 14:52:32 +01:00
|
|
|
{
|
2014-02-05 17:04:58 +01:00
|
|
|
that.preference = {};
|
2015-01-08 15:02:21 +01:00
|
|
|
egw.set_preference(that.egw().getAppName(),that.dom_id,that.preference);
|
2014-01-21 14:52:32 +01:00
|
|
|
}
|
2014-01-13 11:26:20 +01:00
|
|
|
},
|
2014-02-06 12:25:56 +01:00
|
|
|
tolerance:"touch"
|
2014-01-20 19:19:04 +01:00
|
|
|
});
|
2014-01-13 11:26:20 +01:00
|
|
|
|
2014-02-27 19:15:08 +01:00
|
|
|
this.actionlist.droppable({
|
2014-01-13 11:26:20 +01:00
|
|
|
tolerance:"pointer",
|
|
|
|
drop:function (event,ui) {
|
2015-09-18 15:32:51 +02:00
|
|
|
that.set_prefered(ui.draggable.attr('id').replace(that.id+'-',''),false);
|
2014-02-27 19:15:08 +01:00
|
|
|
ui.draggable.appendTo(that.actionlist);
|
2014-02-05 17:04:58 +01:00
|
|
|
that._build_menu(actions);
|
2014-01-13 11:26:20 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
toolbox.accordion({
|
2014-01-17 14:24:18 +01:00
|
|
|
heightStyle:"fill",
|
|
|
|
collapsible: true,
|
2014-03-04 12:03:03 +01:00
|
|
|
active:'none',
|
|
|
|
activate: function (event, ui) {
|
|
|
|
var menubox = event.target;
|
|
|
|
if (ui.oldHeader.length == 0)
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('html').on('click.outsideOfMenu', function (event){
|
|
|
|
jQuery(menubox).accordion( "option", "active", 2);
|
|
|
|
jQuery(this).unbind(event);
|
2016-01-25 22:20:28 +01:00
|
|
|
// Remove the focus class, user clicked elsewhere
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(menubox).children().removeClass('ui-state-focus');
|
2014-03-04 12:03:03 +01:00
|
|
|
});
|
|
|
|
}
|
2014-03-06 19:38:02 +01:00
|
|
|
},
|
2014-03-04 12:03:03 +01:00
|
|
|
create: function (event, ui) {
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('html').unbind('click.outsideOfMenu');
|
2015-05-15 10:45:48 +02:00
|
|
|
},
|
|
|
|
beforeActivate: function ()
|
|
|
|
{
|
2016-05-27 16:32:56 +02:00
|
|
|
if (egwIsMobile())
|
|
|
|
{
|
|
|
|
menulist.height(screen.availHeight - 50);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
menulist.css({height:'inherit'})
|
|
|
|
}
|
2015-05-15 10:45:48 +02:00
|
|
|
// Nothing to show in menulist
|
|
|
|
if (menulist.children().length == 0) return false;
|
2014-03-04 12:03:03 +01:00
|
|
|
}
|
2014-01-17 14:24:18 +01:00
|
|
|
});
|
2014-01-13 11:26:20 +01:00
|
|
|
},
|
2014-03-06 19:38:02 +01:00
|
|
|
|
2014-01-13 11:26:20 +01:00
|
|
|
/**
|
|
|
|
* Add/Or remove an action from prefence
|
|
|
|
*
|
|
|
|
* @param {string} _action name of the action which needs to be stored in pereference
|
2015-09-18 15:32:51 +02:00
|
|
|
* @param {boolean} _state if set to true action will be set to actionbox, false will set it to actionlist
|
2014-01-13 11:26:20 +01:00
|
|
|
*
|
|
|
|
*/
|
2015-09-18 15:32:51 +02:00
|
|
|
set_prefered: function(_action,_state)
|
2014-01-13 11:26:20 +01:00
|
|
|
{
|
2015-09-18 15:32:51 +02:00
|
|
|
this.preference[_action] = _state;
|
2016-01-21 11:15:34 +01:00
|
|
|
if (egwIsMobile()) return;
|
2015-09-18 15:32:51 +02:00
|
|
|
egw.set_preference(this.egw().getAppName(),this.dom_id,this.preference);
|
2013-10-04 09:29:38 +02:00
|
|
|
},
|
2014-01-06 17:45:54 +01:00
|
|
|
|
2013-10-04 09:29:38 +02:00
|
|
|
/**
|
|
|
|
* Make a button based on the given action
|
2014-01-20 19:19:04 +01:00
|
|
|
*
|
|
|
|
* @param {Object} action action object with attributes icon, caption, ...
|
2013-10-04 09:29:38 +02:00
|
|
|
*/
|
|
|
|
_make_button: function(action)
|
|
|
|
{
|
|
|
|
var button_options = {
|
|
|
|
};
|
2016-06-02 16:51:15 +02:00
|
|
|
var button = jQuery(document.createElement('button'))
|
2014-02-05 17:04:58 +01:00
|
|
|
.addClass("et2_button et2_button_text et2_button_with_image")
|
2014-01-06 17:45:54 +01:00
|
|
|
.attr('id', this.id+'-'+action.id)
|
2017-09-26 00:11:22 +02:00
|
|
|
.attr('title', (action.hint ? action.hint : action.caption) + (action.shortcut ? ' ('+action.shortcut.caption+')' : ''))
|
2015-03-05 15:54:47 +01:00
|
|
|
.attr('type', 'button')
|
2016-06-02 16:51:15 +02:00
|
|
|
.appendTo(this.preference[action.id]?this.actionbox.children()[1]:jQuery('[data-group='+action.group+']',this.actionlist));
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2014-12-23 15:24:25 +01:00
|
|
|
if (action && action.checkbox)
|
|
|
|
{
|
2016-01-09 01:54:02 +01:00
|
|
|
if (action.data.toggle_on || action.data.toggle_off)
|
|
|
|
{
|
|
|
|
var toggle = et2_createWidget('checkbox', {
|
|
|
|
id: this.id+'-'+action.id,
|
|
|
|
toggle_on: action.data.toggle_on,
|
|
|
|
toggle_off: action.data.toggle_off
|
|
|
|
}, this);
|
|
|
|
toggle.doLoadingFinished();
|
|
|
|
toggle.set_value(action.checked);
|
|
|
|
action.data.widget = toggle;
|
|
|
|
toggle =toggle.toggle;
|
|
|
|
toggle.appendTo(button.parent())
|
|
|
|
.attr('id', this.id+'-'+action.id);
|
|
|
|
button.remove();
|
|
|
|
button = toggle;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this.checkbox(action.id)) button.addClass('toolbar_toggled'+ (typeof action.toggledClass != 'undefined'?" "+action.toggledClass:''));
|
|
|
|
}
|
|
|
|
}
|
2014-02-06 15:01:37 +01:00
|
|
|
if ( action.iconUrl)
|
2014-02-05 17:04:58 +01:00
|
|
|
{
|
|
|
|
button.attr('style','background-image:url(' + action.iconUrl + ')');
|
|
|
|
}
|
2014-02-06 15:01:37 +01:00
|
|
|
if (action.caption)
|
2013-10-04 09:29:38 +02:00
|
|
|
{
|
2016-01-12 11:22:40 +01:00
|
|
|
if ((this.countActions <= parseInt(this.options.view_range) ||
|
2016-01-26 14:43:00 +01:00
|
|
|
this.preference[action.id] || !action.iconUrl) &&
|
2016-01-12 11:22:40 +01:00
|
|
|
typeof button[0] !== 'undefined' &&
|
2016-02-29 21:40:43 +01:00
|
|
|
!(action.checkbox && action.data && (action.data.toggle_on || action.data.toggle_off))) // no caption for slideswitch checkboxes
|
2014-02-05 17:04:58 +01:00
|
|
|
{
|
2016-01-26 14:43:00 +01:00
|
|
|
button.addClass(action.iconUrl?'et2_toolbar_hasCaption':'et2_toolbar_onlyCaption');
|
2014-02-11 09:50:19 +01:00
|
|
|
button[0].textContent = action.caption;
|
2014-02-05 17:04:58 +01:00
|
|
|
}
|
2013-10-04 09:29:38 +02:00
|
|
|
}
|
|
|
|
if(action.icon)
|
|
|
|
{
|
2014-01-20 19:19:04 +01:00
|
|
|
button_options.icon = action.icon;
|
2013-10-04 09:29:38 +02:00
|
|
|
}
|
2014-02-05 17:04:58 +01:00
|
|
|
if (!jQuery.isEmptyObject(button_options))
|
|
|
|
{
|
|
|
|
button.button(button_options);
|
|
|
|
}
|
2015-05-20 17:18:00 +02:00
|
|
|
var self = this;
|
2013-10-04 09:29:38 +02:00
|
|
|
// Set up the click action
|
2014-03-10 22:14:02 +01:00
|
|
|
var click = function(e)
|
|
|
|
{
|
2013-10-04 09:29:38 +02:00
|
|
|
var action = this._actionManager.getActionById(e.data);
|
2015-01-13 16:51:30 +01:00
|
|
|
if(action)
|
2013-10-04 09:29:38 +02:00
|
|
|
{
|
2015-01-13 16:51:30 +01:00
|
|
|
if (action.checkbox)
|
|
|
|
{
|
2015-05-20 17:18:00 +02:00
|
|
|
self.checkbox(action.id, !action.checked);
|
2015-01-13 16:51:30 +01:00
|
|
|
}
|
2014-03-10 22:14:02 +01:00
|
|
|
this.value = action.id;
|
2013-10-04 09:29:38 +02:00
|
|
|
action.data.event = e;
|
2014-03-06 19:38:02 +01:00
|
|
|
action.execute([]);
|
2013-10-04 09:29:38 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
button.click(action.id, jQuery.proxy(click, this));
|
|
|
|
},
|
2013-10-11 15:34:17 +02:00
|
|
|
|
|
|
|
/**
|
2013-10-04 09:29:38 +02:00
|
|
|
* Link the actions to the DOM nodes / widget bits.
|
|
|
|
*
|
2014-01-20 19:19:04 +01:00
|
|
|
* @param {Object} actions egw-actions to build menu from
|
2013-10-04 09:29:38 +02:00
|
|
|
*/
|
|
|
|
_link_actions: function(actions)
|
|
|
|
{
|
|
|
|
this._build_menu(actions);
|
2017-09-26 00:11:22 +02:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var gom = egw_getObjectManager(this.egw().appName,true,1);
|
|
|
|
if(this._objectManager == null)
|
|
|
|
{
|
|
|
|
this._objectManager = gom.addObject(
|
|
|
|
new egwActionObjectManager(this.id, this._actionManager));
|
|
|
|
|
|
|
|
this._objectManager.handleKeyPress = function(_keyCode, _shift, _ctrl, _alt) {
|
|
|
|
for(var i = 0; i < self._actionManager.children.length; i++)
|
|
|
|
{
|
|
|
|
var action = self._actionManager.children[i];
|
|
|
|
if(typeof action.shortcut === 'object' &&
|
|
|
|
action.shortcut &&
|
|
|
|
_keyCode == action.shortcut.keyCode &&
|
|
|
|
_ctrl == action.shortcut.ctrl &&
|
|
|
|
_alt == action.shortcut.alt &&
|
|
|
|
_shift == action.shortcut.shift
|
|
|
|
)
|
|
|
|
{
|
|
|
|
self.value = action.id;
|
|
|
|
action.execute([]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return egwActionObject.prototype.handleKeyPress.call(this, _keyCode,_shift,_ctrl,_alt);
|
|
|
|
}
|
2018-05-02 22:08:16 +02:00
|
|
|
this._objectManager.parent.updateFocusedChild(this._objectManager, true);
|
2017-09-26 00:11:22 +02:00
|
|
|
}
|
2013-10-04 09:29:38 +02:00
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2015-05-20 17:18:00 +02:00
|
|
|
/**
|
|
|
|
* Set/Get the checkbox toolbar action
|
2016-02-29 21:40:43 +01:00
|
|
|
*
|
2015-05-20 17:18:00 +02:00
|
|
|
* @param {string} _action action name of the selected toolbar
|
|
|
|
* @param {boolean} _value value that needs to be set for the action true|false
|
|
|
|
* - if no value means checkbox value returns the current value
|
2016-02-29 21:40:43 +01:00
|
|
|
*
|
2015-05-20 17:18:00 +02:00
|
|
|
* @returns {boolean} returns boolean result of get checkbox value
|
|
|
|
* or returns undefined as Set result or failure
|
|
|
|
*/
|
|
|
|
checkbox: function (_action, _value)
|
|
|
|
{
|
|
|
|
if (!_action || typeof this._actionManager == 'undefined') return undefined;
|
|
|
|
var action_event = this._actionManager.getActionById(_action);
|
2016-01-09 01:54:02 +01:00
|
|
|
|
2015-05-20 17:18:00 +02:00
|
|
|
if (action_event && typeof _value !='undefined')
|
|
|
|
{
|
2016-01-09 01:54:02 +01:00
|
|
|
action_event.set_checked(_value);
|
2015-05-20 17:18:00 +02:00
|
|
|
var btn = jQuery('#'+this.id+'-'+_action);
|
2016-01-09 01:54:02 +01:00
|
|
|
if(action_event.data && action_event.data.widget)
|
|
|
|
{
|
|
|
|
action_event.data.widget.set_value(_value);
|
|
|
|
}
|
|
|
|
else if (btn.length > 0)
|
2015-05-20 17:18:00 +02:00
|
|
|
{
|
2017-09-01 16:17:01 +02:00
|
|
|
btn.toggleClass('toolbar_toggled'+ (typeof action_event.data.toggledClass != 'undefined'?" "+action_event.data.toggledClass:''), _value);
|
2015-05-20 17:18:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (action_event)
|
|
|
|
{
|
|
|
|
return action_event.checked;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2013-10-04 09:29:38 +02:00
|
|
|
getDOMNode: function(asker)
|
|
|
|
{
|
|
|
|
return this.div[0];
|
2014-03-10 22:14:02 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getValue has to return the value of the input widget
|
|
|
|
*/
|
|
|
|
getValue: function()
|
|
|
|
{
|
|
|
|
return this.value;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is dirty returns true if the value of the widget has changed since it
|
|
|
|
* was loaded.
|
|
|
|
*/
|
|
|
|
isDirty: function()
|
|
|
|
{
|
|
|
|
return this.value != null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Causes the dirty flag to be reseted.
|
|
|
|
*/
|
|
|
|
resetDirty: function()
|
|
|
|
{
|
|
|
|
this.value = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks the data to see if it is valid, as far as the client side can tell.
|
|
|
|
* Return true if it's not possible to tell on the client side, because the server
|
|
|
|
* will have the chance to validate also.
|
|
|
|
*
|
|
|
|
* The messages array is to be populated with everything wrong with the data,
|
|
|
|
* so don't stop checking after the first problem unless it really makes sense
|
|
|
|
* to ignore other problems.
|
|
|
|
*
|
|
|
|
* @param {String[]} messages List of messages explaining the failure(s).
|
|
|
|
* messages should be fairly short, and already translated.
|
|
|
|
*
|
|
|
|
* @return {boolean} True if the value is valid (enough), false to fail
|
|
|
|
*/
|
|
|
|
isValid: function(messages)
|
|
|
|
{
|
|
|
|
return true;
|
2015-01-07 18:08:21 +01:00
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2015-01-07 18:08:21 +01:00
|
|
|
/**
|
|
|
|
* Attach the container node of the widget to DOM-Tree
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
doLoadingFinished: function ()
|
|
|
|
{
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
return false;
|
2013-10-04 09:29:38 +02:00
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
});}).call(this);
|
2013-10-04 09:29:38 +02:00
|
|
|
et2_register_widget(et2_toolbar, ["toolbar"]);
|