|
1
|
|
|
/** |
|
2
|
|
|
* EGroupware eTemplate2 - Class which contains a the data model for nextmatch widgets |
|
3
|
|
|
* |
|
4
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
|
5
|
|
|
* @package etemplate |
|
6
|
|
|
* @subpackage api |
|
7
|
|
|
* @link http://www.egroupware.org |
|
8
|
|
|
* @author Andreas Stöckel |
|
9
|
|
|
* @copyright Stylite 2012 |
|
10
|
|
|
* @version $Id$ |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/*egw:uses |
|
14
|
|
|
et2_core_common; |
|
15
|
|
|
et2_core_inheritance; |
|
16
|
|
|
|
|
17
|
|
|
et2_dataview_view_row; |
|
18
|
|
|
et2_dataview_controller; |
|
19
|
|
|
et2_dataview_interfaces; |
|
20
|
|
|
et2_dataview_view_tile; |
|
21
|
|
|
|
|
22
|
|
|
et2_extension_nextmatch_actions; // Contains nm_action |
|
23
|
|
|
|
|
24
|
|
|
egw_data; |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @augments et2_dataview_controller |
|
29
|
|
|
*/ |
|
30
|
|
|
var et2_nextmatch_controller = (function(){ "use strict"; return et2_dataview_controller.extend(et2_IDataProvider, |
|
31
|
|
|
{ |
|
32
|
|
|
// Display constants |
|
33
|
|
|
VIEW_ROW: 'row', |
|
34
|
|
|
VIEW_TILE: 'tile', |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Initializes the nextmatch controller. |
|
38
|
|
|
* |
|
39
|
|
|
* @param _parentController is the parent nextmatch controller instance |
|
40
|
|
|
* @param _egw is the api instance |
|
41
|
|
|
* @param _execId is the execId of the etemplate |
|
42
|
|
|
* @param _widget is the nextmatch-widget we are fetching data for. |
|
43
|
|
|
* @param _grid is the grid the grid controller will be controlling |
|
44
|
|
|
* @param _rowProvider is the nextmatch row provider instance. |
|
45
|
|
|
* @param _objectManager is the parent object manager (if null, the object |
|
46
|
|
|
* manager) will be created using |
|
47
|
|
|
* @param _actionLinks contains the action links |
|
48
|
|
|
* @param _actions contains the actions, may be null if an object manager |
|
49
|
|
|
* is given. |
|
50
|
|
|
* @memberOf et2_nextmatch_controller |
|
51
|
|
|
*/ |
|
52
|
|
|
init: function (_parentController, _egw, _execId, _widget, _parentId, |
|
53
|
|
|
_grid, _rowProvider, _actionLinks, _objectManager, _actions) { |
|
54
|
|
|
|
|
55
|
|
|
// Copy the egw reference |
|
56
|
|
|
this.egw = _egw; |
|
57
|
|
|
|
|
58
|
|
|
// Keep a reference to the widget |
|
59
|
|
|
this._widget = _widget; |
|
60
|
|
|
|
|
61
|
|
|
// Copy the given parameters |
|
62
|
|
|
this._actionLinks = _actionLinks; |
|
63
|
|
|
this._execId = _execId; |
|
64
|
|
|
this._widgetId = _widget.id; |
|
65
|
|
|
this._parentId = _parentId; |
|
66
|
|
|
this._rowProvider = _rowProvider; |
|
67
|
|
|
|
|
68
|
|
|
// Initialize the action and the object manager |
|
69
|
|
|
// _initActions calls _init_link_dnd, which uses this._actionLinks, |
|
70
|
|
|
// so this must happen after the above parameter copying |
|
71
|
|
|
if (!_objectManager) |
|
72
|
|
|
{ |
|
73
|
|
|
this._initActions(_actions); |
|
74
|
|
|
} |
|
75
|
|
|
else |
|
76
|
|
|
{ |
|
77
|
|
|
this._actionManager = null; |
|
78
|
|
|
this._objectManager = _objectManager; |
|
79
|
|
|
} |
|
80
|
|
|
// Add our selection callback to selection manager |
|
81
|
|
|
var self = this; |
|
82
|
|
|
this._objectManager.setSelectedCallback = function() {self._selectCallback.apply(self,[this,arguments]);}; |
|
83
|
|
|
|
|
84
|
|
|
// Call the parent et2_dataview_controller constructor |
|
85
|
|
|
this._super(_parentController, _grid, this, this._rowCallback, |
|
86
|
|
|
this._linkCallback, this, this._objectManager); |
|
87
|
|
|
|
|
88
|
|
|
// We start with no filters |
|
89
|
|
|
this._filters = {}; |
|
90
|
|
|
|
|
91
|
|
|
// Keep selection across filter changes |
|
92
|
|
|
this.kept_selection = null; |
|
93
|
|
|
this.kept_focus = null; |
|
94
|
|
|
this.kept_expansion = []; |
|
95
|
|
|
|
|
96
|
|
|
// Directly use the API-Implementation of dataRegisterUID and |
|
97
|
|
|
// dataUnregisterUID |
|
98
|
|
|
this.dataUnregisterUID = _egw.dataUnregisterUID; |
|
99
|
|
|
|
|
100
|
|
|
// Default to rows |
|
101
|
|
|
this._view = et2_nextmatch_controller.prototype.VIEW_ROW; |
|
102
|
|
|
}, |
|
103
|
|
|
|
|
104
|
|
|
destroy: function () { |
|
105
|
|
|
// If the actionManager variable is set, the object- and actionManager |
|
106
|
|
|
// were created by this instance -- clear them |
|
107
|
|
|
if (this._actionManager) |
|
108
|
|
|
{ |
|
109
|
|
|
this._objectManager.remove(); |
|
110
|
|
|
this._actionManager.remove(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
this._super(); |
|
114
|
|
|
}, |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Updates the filter instance. |
|
118
|
|
|
*/ |
|
119
|
|
|
setFilters: function (_filters) { |
|
120
|
|
|
// Update the filters |
|
121
|
|
|
this._filters = _filters; |
|
122
|
|
|
}, |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Keep the selection, if possible, across a data fetch and restore it |
|
126
|
|
|
* after |
|
127
|
|
|
*/ |
|
128
|
|
|
keepSelection: function() { |
|
129
|
|
|
this.kept_selection = this._selectionMgr ? this._selectionMgr.getSelected() : null; |
|
130
|
|
|
this.kept_focus = this._selectionMgr && this._selectionMgr._focusedEntry ? |
|
131
|
|
|
this._selectionMgr._focusedEntry.uid || null : null; |
|
132
|
|
|
|
|
133
|
|
|
// Find expanded rows |
|
134
|
|
|
var nm = this._widget; |
|
135
|
|
|
var controller = this; |
|
136
|
|
|
jQuery('.arrow.opened',this._widget.getDOMNode(this._widget)).each(function() { |
|
137
|
|
|
var entry = controller.getRowByNode(this); |
|
138
|
|
|
if(entry && entry.uid) |
|
139
|
|
|
{ |
|
140
|
|
|
controller.kept_expansion.push(entry.uid); |
|
141
|
|
|
} |
|
142
|
|
|
}); |
|
143
|
|
|
}, |
|
144
|
|
|
|
|
145
|
|
|
getObjectManager: function () { |
|
146
|
|
|
return this._objectManager; |
|
147
|
|
|
}, |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Deletes a row from the grid |
|
151
|
|
|
* |
|
152
|
|
|
* @param {string} uid |
|
153
|
|
|
*/ |
|
154
|
|
|
deleteRow: function(uid) { |
|
155
|
|
|
var entry = this._selectionMgr._getRegisteredRowsEntry(uid); |
|
156
|
|
|
|
|
157
|
|
|
// Unselect |
|
158
|
|
|
this._selectionMgr.setSelected(uid,false); |
|
159
|
|
|
|
|
160
|
|
|
if(entry && entry.idx !== null) |
|
161
|
|
|
{ |
|
162
|
|
|
// This will remove the row, but add an empty to the end. |
|
163
|
|
|
// That's OK, because it will be removed when we update the row count |
|
164
|
|
|
this._grid.deleteRow(entry.idx); |
|
165
|
|
|
|
|
166
|
|
|
// Trigger controller to remove from internals |
|
167
|
|
|
this.egw.dataStoreUID(uid,null); |
|
168
|
|
|
// Stop caring about this ID |
|
169
|
|
|
this.egw.dataDeleteUID(uid); |
|
170
|
|
|
// Remove from internal map |
|
171
|
|
|
delete this._indexMap[entry.idx]; |
|
172
|
|
|
|
|
173
|
|
|
// Update the indices of all elements after the current one |
|
174
|
|
|
for(var mapIndex = entry.idx + 1; typeof this._indexMap[mapIndex] !== 'undefined'; mapIndex++) |
|
175
|
|
|
{ |
|
176
|
|
|
var entry = this._indexMap[mapIndex]; |
|
177
|
|
|
entry.idx = mapIndex-1; |
|
178
|
|
|
this._indexMap[mapIndex-1] = entry; |
|
179
|
|
|
|
|
180
|
|
|
// Update selection mgr too |
|
181
|
|
|
if(entry.uid && typeof this._selectionMgr._registeredRows[entry.uid] !== 'undefined') |
|
182
|
|
|
{ |
|
183
|
|
|
var reg = this._selectionMgr._getRegisteredRowsEntry(entry.uid); |
|
184
|
|
|
reg.idx = entry.idx; |
|
185
|
|
|
if(reg.ao && reg.ao._index) reg.ao._index = entry.idx; |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
// Remove last one, it was moved to mapIndex-1 before increment |
|
189
|
|
|
delete this._indexMap[mapIndex-1]; |
|
190
|
|
|
|
|
191
|
|
|
// Not needed, they share by reference |
|
192
|
|
|
// this._selectionMgr.setIndexMap(this._indexMap); |
|
193
|
|
|
} |
|
194
|
|
|
}, |
|
195
|
|
|
|
|
196
|
|
|
/** -- PRIVATE FUNCTIONS -- **/ |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Create a new row, either normal or tiled |
|
200
|
|
|
* |
|
201
|
|
|
* @param {type} ctx |
|
202
|
|
|
* @returns {et2_dataview_container} |
|
203
|
|
|
*/ |
|
204
|
|
|
_createRow: function(ctx) { |
|
205
|
|
|
switch(this._view) |
|
206
|
|
|
{ |
|
207
|
|
|
case et2_nextmatch_controller.prototype.VIEW_TILE: |
|
208
|
|
|
var row = new et2_dataview_tile(this._grid); |
|
209
|
|
|
// Try to overcome chrome rendering issue where float is not |
|
210
|
|
|
// applied properly, leading to incomplete rows |
|
211
|
|
|
window.setTimeout(function() { |
|
212
|
|
|
if(!row.tr) return; |
|
213
|
|
|
row.tr.css('float','none'); |
|
214
|
|
|
window.setTimeout(function() { |
|
215
|
|
|
if(!row.tr) return; |
|
216
|
|
|
row.tr.css('float','left'); |
|
217
|
|
|
},50); |
|
218
|
|
|
},100); |
|
219
|
|
|
return row; |
|
220
|
|
|
case et2_nextmatch_controller.prototype.VIEW_ROW: |
|
221
|
|
|
default: |
|
222
|
|
|
return new et2_dataview_row(this._grid); |
|
223
|
|
|
} |
|
224
|
|
|
}, |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Initializes the action and the object manager. |
|
228
|
|
|
*/ |
|
229
|
|
|
_initActions: function (_actions) { |
|
230
|
|
|
// Generate a uid for the action and object manager |
|
231
|
|
|
var uid = this._widget.id||this.egw.uid(); |
|
232
|
|
|
|
|
233
|
|
|
if(_actions == null) _actions = []; |
|
234
|
|
|
|
|
235
|
|
|
// Initialize the action manager and add some actions to it |
|
236
|
|
|
// Only look 1 level deep |
|
237
|
|
|
var gam = egw_getActionManager(this.egw.appName,true,1); |
|
238
|
|
|
if(this._actionManager == null) |
|
239
|
|
|
{ |
|
240
|
|
|
this._actionManager = gam.addAction("actionManager", uid); |
|
241
|
|
|
} |
|
242
|
|
|
this._actionManager.updateActions(_actions, this.egw.appName); |
|
243
|
|
|
var data = this._actionManager.data; |
|
244
|
|
|
if (data == 'undefined' || !data) |
|
245
|
|
|
{ |
|
246
|
|
|
data = {}; |
|
247
|
|
|
} |
|
248
|
|
|
data.nextmatch = this._widget; |
|
249
|
|
|
this._actionManager.set_data(data); |
|
250
|
|
|
|
|
251
|
|
|
// Set the default execute handler |
|
252
|
|
|
var self = this; |
|
253
|
|
|
this._actionManager.setDefaultExecute(function (_action, _senders, _target) { |
|
254
|
|
|
// Get the selected ids descriptor object |
|
255
|
|
|
var ids = self._selectionMgr.getSelected(); |
|
256
|
|
|
|
|
257
|
|
|
// Pass a reference to the actual widget |
|
258
|
|
|
if (typeof _action.data == 'undefined' || !_action.data) _action.data = {}; |
|
259
|
|
|
_action.data.nextmatch = self._widget; |
|
260
|
|
|
|
|
261
|
|
|
// Call the nm_action function with the ids |
|
262
|
|
|
nm_action(_action, _senders, _target, ids); |
|
263
|
|
|
}); |
|
264
|
|
|
|
|
265
|
|
|
// Set the 'Select All' handler |
|
266
|
|
|
var select_all = this._actionManager.getActionById('select_all'); |
|
267
|
|
|
if(select_all) |
|
268
|
|
|
{ |
|
269
|
|
|
select_all.set_onExecute(jQuery.proxy(function(action, selected) { |
|
270
|
|
|
this._selectionMgr.selectAll(); |
|
271
|
|
|
}, this)); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
// Initialize the object manager - look for application |
|
275
|
|
|
// object manager 1 level deep |
|
276
|
|
|
var gom = egw_getObjectManager(this.egw.appName,true,1); |
|
277
|
|
|
if(this._objectManager == null) |
|
278
|
|
|
{ |
|
279
|
|
|
this._objectManager = gom.addObject( |
|
280
|
|
|
new egwActionObjectManager(uid, this._actionManager)); |
|
281
|
|
|
|
|
282
|
|
|
this._objectManager.handleKeyPress = function(_keyCode, _shift, _ctrl, _alt) { |
|
283
|
|
|
for(var i = 0; i < self._actionManager.children.length; i++) |
|
284
|
|
|
{ |
|
285
|
|
|
if(typeof self._actionManager.children[i].shortcut === 'object' && |
|
286
|
|
|
self._actionManager.children[i].shortcut && |
|
287
|
|
|
_keyCode == self._actionManager.children[i].shortcut.keyCode) |
|
288
|
|
|
{ |
|
289
|
|
|
return this.executeActionImplementation( |
|
290
|
|
|
{ |
|
291
|
|
|
"keyEvent": { |
|
292
|
|
|
"keyCode": _keyCode, |
|
293
|
|
|
"shift": _shift, |
|
294
|
|
|
"ctrl": _ctrl, |
|
295
|
|
|
"alt": _alt |
|
296
|
|
|
} |
|
297
|
|
|
}, "popup", EGW_AO_EXEC_SELECTED); |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
return egwActionObject.prototype.handleKeyPress.call(this, _keyCode,_shift,_ctrl,_alt); |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
} |
|
304
|
|
|
this._objectManager.flags = this._objectManager.flags |
|
305
|
|
|
| EGW_AO_FLAG_DEFAULT_FOCUS | EGW_AO_FLAG_IS_CONTAINER; |
|
306
|
|
|
|
|
307
|
|
|
this._init_links_dnd(this._actionManager); |
|
308
|
|
|
|
|
309
|
|
|
if(this._selectionMgr) |
|
310
|
|
|
{ |
|
311
|
|
|
// Need to update the action links for every registered row too |
|
312
|
|
|
for (var uid in this._selectionMgr._registeredRows) |
|
313
|
|
|
{ |
|
314
|
|
|
// Get the corresponding entry from the registered rows array |
|
315
|
|
|
var entry = this._selectionMgr._getRegisteredRowsEntry(uid); |
|
316
|
|
|
if(entry.ao) |
|
317
|
|
|
{ |
|
318
|
|
|
entry.ao.updateActionLinks(this._actionLinks); |
|
319
|
|
|
} |
|
320
|
|
|
} |
|
321
|
|
|
} |
|
322
|
|
|
}, |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* Automatically add dnd support for linking |
|
326
|
|
|
*/ |
|
327
|
|
|
_init_links_dnd: function() { |
|
328
|
|
|
var mgr = this._actionManager; |
|
329
|
|
|
var self = this; |
|
330
|
|
|
|
|
331
|
|
|
var drop_action = mgr.getActionById('egw_link_drop'); |
|
332
|
|
|
var drag_action = mgr.getActionById('egw_link_drag'); |
|
333
|
|
|
var drop_cancel = mgr.getActionById('egw_cancel_drop'); |
|
334
|
|
|
|
|
335
|
|
|
if(!this._actionLinks) |
|
336
|
|
|
{ |
|
337
|
|
|
this._actionLinks = []; |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
if (!drop_cancel) |
|
341
|
|
|
{ |
|
342
|
|
|
// Create a generic cancel action in order to cancel drop action |
|
343
|
|
|
// applied for all apps plus file and link action. |
|
344
|
|
|
drop_cancel = mgr.addAction('drop', 'egw_cancel_drop', this.egw.lang('Cancel'), egw.image('cancel'), function(){},true); |
|
345
|
|
|
drop_cancel.set_group('99'); |
|
346
|
|
|
drop_cancel.acceptedTypes = drop_cancel.acceptedTypes.concat(Object.keys(egw.user('apps')).concat(['link', 'file'])); |
|
347
|
|
|
this._actionLinks.push (drop_cancel.id); |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
// Check if this app supports linking |
|
351
|
|
|
if(!egw.link_get_registry(this.dataStorePrefix || this.egw.appName, 'query') || |
|
352
|
|
|
egw.link_get_registry(this.dataStorePrefix || this.egw.appName, 'title')) |
|
353
|
|
|
{ |
|
354
|
|
|
if(drop_action) |
|
355
|
|
|
{ |
|
356
|
|
|
drop_action.remove(); |
|
357
|
|
|
if(this._actionLinks.indexOf(drop_action.id) >= 0) |
|
358
|
|
|
{ |
|
359
|
|
|
this._actionLinks.splice(this._actionLinks.indexOf(drop_action.id),1); |
|
360
|
|
|
} |
|
361
|
|
|
} |
|
362
|
|
|
if(drag_action) |
|
363
|
|
|
{ |
|
364
|
|
|
drag_action.remove(); |
|
365
|
|
|
if(this._actionLinks.indexOf(drag_action.id) >= 0) |
|
366
|
|
|
{ |
|
367
|
|
|
this._actionLinks.splice(this._actionLinks.indexOf(drag_action.id),1); |
|
368
|
|
|
} |
|
369
|
|
|
} |
|
370
|
|
|
return; |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
// Don't re-add |
|
374
|
|
|
if(drop_action == null) |
|
375
|
|
|
{ |
|
376
|
|
|
// Create the drop action that links entries |
|
377
|
|
|
drop_action = mgr.addAction('drop', 'egw_link_drop', this.egw.lang('Create link'), egw.image('link'), function(action, source, dropped) { |
|
378
|
|
|
// Extract link IDs |
|
379
|
|
|
var links = []; |
|
380
|
|
|
var id = ''; |
|
381
|
|
|
for(var i = 0; i < source.length; i++) |
|
382
|
|
|
{ |
|
383
|
|
|
if(!source[i].id) continue; |
|
384
|
|
|
id = source[i].id.split('::'); |
|
385
|
|
|
links.push({app: id[0] == 'filemanager' ? 'link' : id[0], id: id[1]}); |
|
386
|
|
|
} |
|
387
|
|
|
if(!links.length) |
|
388
|
|
|
{ |
|
389
|
|
|
return; |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
// Link the entries |
|
393
|
|
|
self.egw.json("EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link", |
|
394
|
|
|
dropped.id.split('::').concat([links]), |
|
395
|
|
|
function(result) { |
|
396
|
|
|
if(result) |
|
397
|
|
|
{ |
|
398
|
|
|
for (var i=0; i < this._objectManager.selectedChildren.length; i++) |
|
399
|
|
|
{ |
|
400
|
|
|
this._widget.refresh(this._objectManager.selectedChildren[i].id,'update'); |
|
401
|
|
|
} |
|
402
|
|
|
this._widget.egw().message('Linked'); |
|
403
|
|
|
// Update the target to show the liks |
|
404
|
|
|
this._widget.refresh(dropped.id,'update'); |
|
405
|
|
|
} |
|
406
|
|
|
}, |
|
407
|
|
|
self, |
|
408
|
|
|
true, |
|
409
|
|
|
self |
|
410
|
|
|
).sendRequest(); |
|
411
|
|
|
|
|
412
|
|
|
},true); |
|
413
|
|
|
} |
|
414
|
|
|
if(this._actionLinks.indexOf(drop_action.id) < 0) |
|
415
|
|
|
{ |
|
416
|
|
|
this._actionLinks.push(drop_action.id); |
|
417
|
|
|
} |
|
418
|
|
|
// Accept other links, and files dragged from the filemanager |
|
419
|
|
|
// This does not handle files dragged from the desktop. They are |
|
420
|
|
|
// handled by et2_nextmatch, since it needs DOM stuff |
|
421
|
|
|
if(drop_action.acceptedTypes.indexOf('link') == -1) |
|
422
|
|
|
{ |
|
423
|
|
|
drop_action.acceptedTypes.push('link'); |
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
|
// Don't re-add |
|
427
|
|
|
if(drag_action == null) |
|
428
|
|
|
{ |
|
429
|
|
|
// Create drag action that allows linking |
|
430
|
|
|
drag_action = mgr.addAction('drag', 'egw_link_drag', this.egw.lang('link'), 'link', function(action, selected) { |
|
431
|
|
|
// Drag helper - list titles. Arbitrarily limited to 10. |
|
432
|
|
|
var helper = jQuery(document.createElement("div")); |
|
433
|
|
|
for(var i = 0; i < selected.length && i < 10; i++) |
|
434
|
|
|
{ |
|
435
|
|
|
var id = selected[i].id.split('::'); |
|
436
|
|
|
var span = jQuery(document.createElement('span')).appendTo(helper); |
|
437
|
|
|
self.egw.link_title(id[0],id[1], function(title) { |
|
438
|
|
|
this.append(title); |
|
439
|
|
|
this.append('<br />'); |
|
440
|
|
|
}, span); |
|
441
|
|
|
} |
|
442
|
|
|
// As we wanted to have a general defaul helper interface, we return null here and not using customize helper for links |
|
443
|
|
|
// TODO: Need to decide if we need to create a customized helper interface for links anyway |
|
444
|
|
|
//return helper; |
|
445
|
|
|
return null; |
|
446
|
|
|
},true); |
|
447
|
|
|
} |
|
448
|
|
|
if(this._actionLinks.indexOf(drag_action.id) < 0) |
|
449
|
|
|
{ |
|
450
|
|
|
this._actionLinks.push(drag_action.id); |
|
451
|
|
|
} |
|
452
|
|
|
drag_action.set_dragType('link'); |
|
453
|
|
|
}, |
|
454
|
|
|
|
|
455
|
|
|
/** |
|
456
|
|
|
* Set the data cache prefix |
|
457
|
|
|
* Overridden from the parent to re-check automatically the added link dnd |
|
458
|
|
|
* since the prefix is used in support detection. |
|
459
|
|
|
*/ |
|
460
|
|
|
setPrefix: function(prefix) { |
|
461
|
|
|
this._super.apply(this, arguments) |
|
462
|
|
|
|
|
463
|
|
|
this._init_links_dnd(this._actionManager); |
|
464
|
|
|
}, |
|
465
|
|
|
|
|
466
|
|
|
/** |
|
467
|
|
|
* Overwrites the inherited _destroyCallback function in order to be able |
|
468
|
|
|
* to free the "rowWidget". |
|
469
|
|
|
*/ |
|
470
|
|
|
_destroyCallback: function (_row) { |
|
471
|
|
|
// Destroy any widget associated to the row |
|
472
|
|
|
if (this.entry.widget) |
|
473
|
|
|
{ |
|
474
|
|
|
this.entry.widget.free(); |
|
475
|
|
|
this.entry.widget = null; |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
// Call the inherited function |
|
479
|
|
|
this._super.apply(this, arguments); |
|
480
|
|
|
}, |
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* Creates the actual data row. |
|
484
|
|
|
* |
|
485
|
|
|
* @param _data is an array containing the row data |
|
486
|
|
|
* @param _tr is the tr into which the data will be inserted |
|
487
|
|
|
* @param _idx is the index of the row |
|
488
|
|
|
* @param _entry is the internal row datastructure of the controller, in |
|
489
|
|
|
* this special case used to store the rowWidget reference, so that it can |
|
490
|
|
|
* be properly freed. |
|
491
|
|
|
*/ |
|
492
|
|
|
_rowCallback: function (_data, _tr, _idx, _entry) { |
|
493
|
|
|
// Let the row provider fill in the data row -- store the returned |
|
494
|
|
|
// rowWidget inside the _entry |
|
495
|
|
|
_entry.widget = this._rowProvider.getDataRow( |
|
496
|
|
|
{ "content": _data }, _tr, _idx, this); |
|
497
|
|
|
}, |
|
498
|
|
|
|
|
499
|
|
|
/** |
|
500
|
|
|
* Returns the names of action links for a given data row -- currently these are |
|
501
|
|
|
* always the same links, as we controll enabled/disabled over the row |
|
502
|
|
|
* classes, unless the row UID is "", then it's an 'empty' row. |
|
503
|
|
|
* |
|
504
|
|
|
* The empty row placeholder can still have actions, but nothing that requires |
|
505
|
|
|
* an actual UID. |
|
506
|
|
|
* |
|
507
|
|
|
* @TODO: Currently empty row is just add, need to actually filter somehow. Here |
|
508
|
|
|
* might not be the right place. |
|
509
|
|
|
* |
|
510
|
|
|
* @param _data Object The data for the row |
|
511
|
|
|
* @param _idx int The row index |
|
512
|
|
|
* @param _uid String The row's ID |
|
513
|
|
|
* |
|
514
|
|
|
* @return Array List of action names that valid for the row |
|
515
|
|
|
*/ |
|
516
|
|
|
_linkCallback: function (_data, _idx, _uid) { |
|
517
|
|
|
if(_uid.trim() != "") |
|
518
|
|
|
{ |
|
519
|
|
|
return this._actionLinks; |
|
520
|
|
|
} |
|
521
|
|
|
|
|
522
|
|
|
// No UID, so return a filtered list of actions that doesn't need a UID |
|
523
|
|
|
var links = []; |
|
524
|
|
|
try { |
|
525
|
|
|
links = typeof this._widget.options.settings.placeholder_actions != 'undefined' ? |
|
526
|
|
|
this._widget.options.settings.placeholder_actions : (this._widget.options.add ? ["add"] : []); |
|
527
|
|
|
// Make sure that placeholder actions are defined and existed in client-side, |
|
528
|
|
|
// otherwise do not set them as placeholder. for instance actions with |
|
529
|
|
|
// attribute hideOnMobile do not get sent to client-side. |
|
530
|
|
|
if (links.length > 0) |
|
531
|
|
|
{ |
|
532
|
|
|
for (var i=links.length-1; i >= 0; i--) |
|
533
|
|
|
{ |
|
534
|
|
|
if (typeof this._widget.options.actions[links[i]] == 'undefined') links.splice(i,1); |
|
535
|
|
|
} |
|
536
|
|
|
} |
|
537
|
|
|
} catch (e) { |
|
|
|
|
|
|
538
|
|
|
} |
|
539
|
|
|
|
|
540
|
|
|
return links; |
|
541
|
|
|
}, |
|
542
|
|
|
|
|
543
|
|
|
|
|
544
|
|
|
/** |
|
545
|
|
|
* Overridden from the parent to also process any additional data that |
|
546
|
|
|
* the data source adds, such as readonlys and additonal content. |
|
547
|
|
|
* For example, non-numeric IDs in rows are added to the content manager |
|
548
|
|
|
*/ |
|
549
|
|
|
_fetchCallback: function (_response) { |
|
550
|
|
|
var nm = this.self._widget; |
|
551
|
|
|
if(!nm) |
|
552
|
|
|
{ |
|
553
|
|
|
// Nextmatch either not connected, or it tried to destroy this |
|
554
|
|
|
// but the server returned something |
|
555
|
|
|
return; |
|
556
|
|
|
} |
|
557
|
|
|
// Readonlys |
|
558
|
|
|
// Other stuff |
|
559
|
|
|
for(var i in _response.rows) |
|
560
|
|
|
{ |
|
561
|
|
|
if(jQuery.isNumeric(i)) continue; |
|
562
|
|
|
if(i == 'sel_options') |
|
563
|
|
|
{ |
|
564
|
|
|
var mgr = nm.getArrayMgr(i); |
|
565
|
|
|
for(var id in _response.rows.sel_options) |
|
566
|
|
|
{ |
|
567
|
|
|
mgr.data[id] = _response.rows.sel_options[id]; |
|
568
|
|
|
var select = nm.getWidgetById(id); |
|
569
|
|
|
if(select && select.set_select_options) |
|
570
|
|
|
{ |
|
571
|
|
|
select.set_select_options(_response.rows.sel_options[id]); |
|
572
|
|
|
} |
|
573
|
|
|
// Clear rowProvider internal cache so it uses new values |
|
574
|
|
|
if(id == 'cat_id') |
|
575
|
|
|
{ |
|
576
|
|
|
this.self._rowProvider.categories = null; |
|
577
|
|
|
} |
|
578
|
|
|
// update array mgr so select widgets in row also get refreshed options |
|
579
|
|
|
nm.getParent().getArrayMgr('sel_options').data[id] = _response.rows.sel_options[id]; |
|
580
|
|
|
} |
|
581
|
|
|
} |
|
582
|
|
|
else |
|
583
|
|
|
{ |
|
584
|
|
|
var mgr = nm.getArrayMgr('content'); |
|
585
|
|
|
mgr.data[i] = _response.rows[i]; |
|
586
|
|
|
|
|
587
|
|
|
// It's not enough to just update the data, the widgets need to |
|
588
|
|
|
// be updated too, if there are matching widgets. |
|
589
|
|
|
var widget = nm.getWidgetById(i); |
|
590
|
|
|
if(widget && widget.set_value) |
|
591
|
|
|
{ |
|
592
|
|
|
widget.set_value(mgr.getEntry(i)); |
|
593
|
|
|
} |
|
594
|
|
|
} |
|
595
|
|
|
} |
|
596
|
|
|
// Might be trying to disable a column |
|
597
|
|
|
var col_refresh = false; |
|
598
|
|
|
for(var column_index = 0; column_index < nm.columns.length; column_index++) |
|
599
|
|
|
{ |
|
600
|
|
|
if(typeof nm.columns[column_index].disabled === 'string' && |
|
601
|
|
|
nm.columns[column_index].disabled[0] === '@') |
|
602
|
|
|
{ |
|
603
|
|
|
col_refresh = true; |
|
604
|
|
|
nm.dataview.columnMgr.getColumnById('col_'+column_index) |
|
605
|
|
|
.set_visibility( |
|
606
|
|
|
nm.getArrayMgr('content').parseBoolExpression(nm.columns[column_index].disabled) ? |
|
607
|
|
|
ET2_COL_VISIBILITY_DISABLED : |
|
608
|
|
|
nm.columns[column_index].visible |
|
609
|
|
|
); |
|
610
|
|
|
} |
|
611
|
|
|
} |
|
612
|
|
|
if(col_refresh) |
|
613
|
|
|
{ |
|
614
|
|
|
nm.dataview.columnMgr.updated = true; |
|
615
|
|
|
nm.dataview._updateColumns(); |
|
616
|
|
|
} |
|
617
|
|
|
|
|
618
|
|
|
// If we're doing an autorefresh and the count decreases, preserve the |
|
619
|
|
|
// selection or it will be lost when the grid rows are shuffled. Increases |
|
620
|
|
|
// are fine though. |
|
621
|
|
|
if(this.self && this.self.kept_selection == null && |
|
622
|
|
|
!this.refresh && this.self._grid.getTotalCount() > _response.total) |
|
623
|
|
|
{ |
|
624
|
|
|
this.self.keepSelection(); |
|
625
|
|
|
} |
|
626
|
|
|
|
|
627
|
|
|
// Call the inherited function |
|
628
|
|
|
this._super.apply(this, arguments); |
|
629
|
|
|
|
|
630
|
|
|
// Restore selection, if passed |
|
631
|
|
|
if(this.self && this.self.kept_selection && this.self._selectionMgr) |
|
632
|
|
|
{ |
|
633
|
|
|
if(this.self.kept_selection.all) |
|
634
|
|
|
{ |
|
635
|
|
|
this.self._selectionMgr.selectAll(); |
|
636
|
|
|
} |
|
637
|
|
|
for(var i = (this.self.kept_selection.ids.length || 1)-1; i >= 0; i--) |
|
638
|
|
|
{ |
|
639
|
|
|
// Only keep the selected if they came back in the fetch |
|
640
|
|
|
if(_response.order.indexOf(this.self.kept_selection.ids[i]) >= 0) |
|
641
|
|
|
{ |
|
642
|
|
|
this.self._selectionMgr.setSelected(this.self.kept_selection.ids[i],true); |
|
643
|
|
|
this.self.kept_selection.ids.splice(i,1); |
|
644
|
|
|
} |
|
645
|
|
|
else |
|
646
|
|
|
{ |
|
647
|
|
|
this.self.kept_selection.ids.splice(i,1); |
|
648
|
|
|
} |
|
649
|
|
|
} |
|
650
|
|
|
if(this.self.kept_focus && _response.order.indexOf(this.self.kept_focus) >= 0) |
|
651
|
|
|
{ |
|
652
|
|
|
this.self._selectionMgr.setFocused(this.self.kept_focus,true); |
|
653
|
|
|
} |
|
654
|
|
|
// Re-expanding rows handled in et2_extension_nextmatch_rowProvider |
|
655
|
|
|
// Expansions might still be valid, so we don't clear them |
|
656
|
|
|
if(this.self.kept_selection != null && typeof this.self.kept_selection.ids != 'undefined' && this.self.kept_selection.ids.length == 0) |
|
657
|
|
|
{ |
|
658
|
|
|
this.self.kept_selection = null; |
|
659
|
|
|
} |
|
660
|
|
|
this.self.kept_focus = null; |
|
661
|
|
|
} |
|
662
|
|
|
}, |
|
663
|
|
|
|
|
664
|
|
|
/** |
|
665
|
|
|
* Execute the select callback when the row selection changes |
|
666
|
|
|
*/ |
|
667
|
|
|
_selectCallback: function(action,senders) |
|
668
|
|
|
{ |
|
669
|
|
|
if(typeof senders == "undefined") |
|
670
|
|
|
{ |
|
671
|
|
|
senders = []; |
|
672
|
|
|
} |
|
673
|
|
|
if(!this._widget) return; |
|
674
|
|
|
|
|
675
|
|
|
// inform mobile framework about nm selections, need to update status of header objects on selection |
|
676
|
|
|
if (egwIsMobile()) framework.nm_onselect_ctrl(this._widget, action, senders); |
|
677
|
|
|
|
|
678
|
|
|
this._widget.onselect.call(this._widget, action,senders); |
|
679
|
|
|
}, |
|
680
|
|
|
|
|
681
|
|
|
/** -- Implementation of et2_IDataProvider -- **/ |
|
682
|
|
|
|
|
683
|
|
|
|
|
684
|
|
|
dataFetch: function (_queriedRange, _callback, _context) { |
|
685
|
|
|
|
|
686
|
|
|
// Merge the parent id into the _queriedRange if it is set |
|
687
|
|
|
if (this._parentId !== null) |
|
688
|
|
|
{ |
|
689
|
|
|
_queriedRange["parent_id"] = this._parentId; |
|
690
|
|
|
} |
|
691
|
|
|
|
|
692
|
|
|
// sub-levels dont have there own _filters object, need to use the one from parent (or it's parents parent) |
|
693
|
|
|
var obj = this; |
|
694
|
|
|
while((typeof obj._filters == 'undefined' || jQuery.isEmptyObject(obj._filters)) && obj._parentController) |
|
695
|
|
|
{ |
|
696
|
|
|
obj = obj._parentController; |
|
697
|
|
|
} |
|
698
|
|
|
|
|
699
|
|
|
// Pass the fetch call to the API, multiplex the data about the |
|
700
|
|
|
// nextmatch instance into the call. |
|
701
|
|
|
this.egw.dataFetch( |
|
702
|
|
|
this._widget.getInstanceManager().etemplate_exec_id || this._execId, |
|
703
|
|
|
_queriedRange, |
|
704
|
|
|
obj._filters, |
|
705
|
|
|
this._widgetId, |
|
706
|
|
|
_callback, |
|
707
|
|
|
_context); |
|
708
|
|
|
}, |
|
709
|
|
|
|
|
710
|
|
|
dataRegisterUID: function (_uid, _callback, _context) { |
|
711
|
|
|
this.egw.dataRegisterUID(_uid, _callback, _context, |
|
712
|
|
|
this._widget.getInstanceManager().etemplate_exec_id || this._execId, |
|
713
|
|
|
this._widgetId |
|
714
|
|
|
); |
|
715
|
|
|
}, |
|
716
|
|
|
|
|
717
|
|
|
dataUnregisterUID: function () { |
|
718
|
|
|
// Overwritten in the constructor |
|
719
|
|
|
} |
|
720
|
|
|
|
|
721
|
|
|
});}).call(this); |
|
722
|
|
|
|
|
723
|
|
|
|
|
724
|
|
|
|