From 7abf44c6a37f54f0a1bdd33e87849116b594dbc0 Mon Sep 17 00:00:00 2001 From: nathangray Date: Mon, 22 Aug 2016 09:39:09 -0600 Subject: [PATCH] Add actions (Add) for blank parts of planner view --- api/js/egw_action/egw_action_popup.js | 87 ++++++++++++++------------- calendar/js/et2_widget_planner.js | 26 +++++++- 2 files changed, 68 insertions(+), 45 deletions(-) diff --git a/api/js/egw_action/egw_action_popup.js b/api/js/egw_action/egw_action_popup.js index 39e34cc6f8..1c9e7cd0bb 100644 --- a/api/js/egw_action/egw_action_popup.js +++ b/api/js/egw_action/egw_action_popup.js @@ -848,51 +848,54 @@ function egwPopupActionImplementation() } // Add into links so it's included in menu - if(typeof _links[paste_action.id] == 'undefined') + if(paste_action && paste_action.enabled.exec()) { - _links[paste_action.id] = { - "actionObj": paste_action, - "enabled": false, - "visible": clipboard != null, - "cnt": 0 - }; - } - while(paste_action.children.length > 0) - { - paste_action.children[0].remove(); - } - - // If nothing [valid] in the clipboard, don't bother with children - if(clipboard == null || typeof clipboard.type != 'object') - { - return; - } - - // Add in actual actions as children - for(var k in drop) - { - // Add some choices - need to be a copy, or they interfere with - // the original - var drop_clone = jQuery.extend({},drop[k].actionObj); - drop_clone.parent = paste_action; - drop_clone.onExecute = new egwFnct(this, null, []); - drop_clone.set_onExecute(paste_exec); - paste_action.children.push(drop_clone); - paste_action.allowOnMultiple = paste_action.allowOnMultiple && drop_clone.allowOnMultiple; - _links[k] = jQuery.extend({},drop[k]); - _links[k].actionObj = drop_clone; - - // Drop is allowed if clipboard types intersect drop types - _links[k].enabled = false; - _links[k].visible = false; - for (var i = 0; i < drop_clone.acceptedTypes.length; i++) + if(typeof _links[paste_action.id] == 'undefined') { - if (clipboard.type.indexOf(drop_clone.acceptedTypes[i]) != -1) + _links[paste_action.id] = { + "actionObj": paste_action, + "enabled": false, + "visible": clipboard != null, + "cnt": 0 + }; + } + while(paste_action.children.length > 0) + { + paste_action.children[0].remove(); + } + + // If nothing [valid] in the clipboard, don't bother with children + if(clipboard == null || typeof clipboard.type != 'object') + { + return; + } + + // Add in actual actions as children + for(var k in drop) + { + // Add some choices - need to be a copy, or they interfere with + // the original + var drop_clone = jQuery.extend({},drop[k].actionObj); + drop_clone.parent = paste_action; + drop_clone.onExecute = new egwFnct(this, null, []); + drop_clone.set_onExecute(paste_exec); + paste_action.children.push(drop_clone); + paste_action.allowOnMultiple = paste_action.allowOnMultiple && drop_clone.allowOnMultiple; + _links[k] = jQuery.extend({},drop[k]); + _links[k].actionObj = drop_clone; + + // Drop is allowed if clipboard types intersect drop types + _links[k].enabled = false; + _links[k].visible = false; + for (var i = 0; i < drop_clone.acceptedTypes.length; i++) { - _links[paste_action.id].enabled = true; - _links[k].enabled = true; - _links[k].visible = true; - break; + if (clipboard.type.indexOf(drop_clone.acceptedTypes[i]) != -1) + { + _links[paste_action.id].enabled = true; + _links[k].enabled = true; + _links[k].visible = true; + break; + } } } } diff --git a/calendar/js/et2_widget_planner.js b/calendar/js/et2_widget_planner.js index f6d5c448ca..b60c508972 100644 --- a/calendar/js/et2_widget_planner.js +++ b/calendar/js/et2_widget_planner.js @@ -1389,7 +1389,7 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e this._init_links_dnd(widget_object.manager, action_links); - //widget_object.updateActionLinks(action_links); + widget_object.updateActionLinks(action_links); this._actionObject = widget_object; }, @@ -1409,6 +1409,14 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e var drop_change_participant = mgr.getActionById('change_participant'); var drop_invite = mgr.getActionById('invite'); var drag_action = mgr.getActionById('egw_link_drag'); + var paste_action = mgr.getActionById('egw_paste'); + + // Disable paste action + if(paste_action == null) + { + paste_action = mgr.addAction('popup', 'egw_paste', egw.lang('Paste'), egw.image('editpaste'), function(){},true); + } + paste_action.set_enabled(false); // Check if this app supports linking if(!egw.link_get_registry(this.dataStorePrefix || 'calendar', 'query') || @@ -1583,15 +1591,24 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e _get_action_links: function(actions) { var action_links = []; - // TODO: determine which actions are allowed without an action (empty actions) + + // Only these actions are allowed without a selection (empty actions) + var empty_actions = ['add']; + for(var i in actions) { var action = actions[i]; - if(action.type === 'drop') + if(empty_actions.indexOf(action.id) !== -1 || action.type === 'drop') { action_links.push(typeof action.id !== 'undefined' ? action.id : i); } } + // Disable automatic paste action, it doesn't have what is needed to work + action_links.push({ + "actionObj": 'egw_paste', + "enabled": false, + "visible": false + }); return action_links; }, @@ -2129,6 +2146,9 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e */ _mouse_down: function(event) { + // Only left mouse button + if(event.which !== 1) return; + // Ignore headers if(this.headers.has(event.target).length !== 0) return false;