-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
DragInfo.js
186 lines (162 loc) · 5.18 KB
/
DragInfo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*!
* ${copyright}
*/
sap.ui.define(["./DragDropBase"],
function(DragDropBase) {
"use strict";
/**
* Constructor for a new DragInfo.
*
* @param {string} [sId] ID for the new DragInfo, generated automatically if no ID is given
* @param {object} [mSettings] Initial settings for the DragInfo
*
* @class
* Provides the configuration for drag operations.
*
* <b>Note:</b> This configuration might be ignored due to control {@link sap.ui.core.Element.extend metadata} restrictions.
*
* @extends sap.ui.core.dnd.DragDropBase
*
* @author SAP SE
* @version ${version}
*
* @public
* @since 1.56
* @alias sap.ui.core.dnd.DragInfo
*/
var DragInfo = DragDropBase.extend("sap.ui.core.dnd.DragInfo", /** @lends sap.ui.core.dnd.DragInfo.prototype */ { metadata: {
library: "sap.ui.core",
interfaces: [
"sap.ui.core.dnd.IDragInfo"
],
properties: {
/**
* The name of the aggregation from which all children can be dragged. If undefined, the control itself can be dragged.
*/
sourceAggregation: {type: "string", defaultValue: null}
},
events: {
/**
* This event is fired when the user starts dragging an element.
*
* @name sap.ui.core.dnd.DragInfo#dragStart
* @event
* @param {sap.ui.base.Event} oControlEvent
* @param {sap.ui.base.EventProvider} oControlEvent.getSource
* @param {object} oControlEvent.getParameters
* @param {sap.ui.core.Element} oControlEvent.getParameters.target The target element that will be dragged
* @param {sap.ui.core.dnd.DragSession} oControlEvent.getParameters.dragSession The UI5 <code>dragSession</code> object that exists only during drag and drop
* @param {Event} oControlEvent.getParameters.browserEvent The underlying browser event
* @public
*/
dragStart: {
allowPreventDefault: true
},
/**
* This event is fired when a drag operation is being ended.
*
* @name sap.ui.core.dnd.DragInfo#dragEnd
* @event
* @param {sap.ui.base.Event} oControlEvent
* @param {sap.ui.base.EventProvider} oControlEvent.getSource
* @param {object} oControlEvent.getParameters
* @param {sap.ui.core.Element} oControlEvent.getParameters.target The target element that is being dragged
* @param {sap.ui.core.dnd.DragSession} oControlEvent.getParameters.dragSession The UI5 <code>dragSession</code> object that exists only during drag and drop
* @param {Event} oControlEvent.getParameters.browserEvent The underlying browser event
* @public
* @since 1.56
*/
dragEnd: {
}
}
}});
/**
* Provides DragInfo mixin for the subclasses that need DragInfo functionalities.
*
* @private
* @mixin
* @since 1.87
*/
DragInfo.Mixin = function() {
this.isDraggable = function(oControl) {
if (!this.getEnabled()) {
return false;
}
var oDragSource = this.getParent();
if (!oDragSource) {
return false;
}
// metadata restrictions
var sSourceAggregation = this.getSourceAggregation();
if (!this.checkMetadata(oDragSource, sSourceAggregation, "draggable")) {
return false;
}
// control itself is the drag source or
// control is in the aggregation of the drag source
if ((oDragSource === oControl && !sSourceAggregation) ||
(oControl.getParent() === oDragSource && sSourceAggregation === oControl.sParentAggregationName)) {
return oControl.isDragAllowed && !oControl.isDragAllowed(this) ? false : true;
}
return false;
};
this.fireDragStart = function(oEvent) {
if (!oEvent || !oEvent.dragSession) {
return;
}
var oDragSession = oEvent.dragSession;
return this.fireEvent("dragStart", {
dragSession: oDragSession,
browserEvent: oEvent.originalEvent,
target: oDragSession.getDragControl()
}, true);
};
this.fireDragEnd = function(oEvent) {
if (!oEvent || !oEvent.dragSession) {
return;
}
var oDragSession = oEvent.dragSession;
return this.fireEvent("dragEnd", {
dragSession: oDragSession,
browserEvent: oEvent.originalEvent,
target: oDragSession.getDragControl()
});
};
this.setEnabled = function(bEnabled) {
this.setProperty("enabled", bEnabled, false);
this.invalidateDraggables();
return this;
};
this.setParent = function() {
DragDropBase.prototype.setParent.apply(this, arguments);
this.invalidateDraggables();
return this;
};
this.setSourceAggregation = function(sSourceAggregation) {
var sOldSourceAggregation = this.getSourceAggregation();
if (sOldSourceAggregation == sSourceAggregation) {
return this;
}
sOldSourceAggregation && this.invalidateDraggables();
this.setProperty("sourceAggregation", sSourceAggregation, false);
this.invalidateDraggables();
return this;
};
this.invalidateDraggables = function() {
var oParent = this.getParent();
if (oParent && oParent.bOutput == true) {
var sSourceAggregation = this.getSourceAggregation();
if (sSourceAggregation) {
[].concat(oParent.getAggregation(sSourceAggregation)).forEach(function(oAggregation) {
if (oAggregation && oAggregation.bOutput == true) {
oAggregation.invalidate();
}
});
} else {
oParent.invalidate();
}
}
};
};
DragInfo.Mixin.apply(DragInfo.prototype);
return DragInfo;
});