adva 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/adva.gemspec +0 -1
  3. data/app/assets/javascripts/adva_cms/table_tree.js +517 -0
  4. data/app/assets/javascripts/adva_cms.js +1 -1
  5. data/app/assets/stylesheets/adva_cms/admin/tooltip.scss +10 -0
  6. data/app/assets/stylesheets/adva_cms/admin.scss +1 -1
  7. data/app/controllers/admin/sections_controller.rb +1 -1
  8. data/lib/adva/version.rb +1 -1
  9. data/lib/adva.rb +0 -1
  10. metadata +4 -32
  11. data/app/assets/javascripts/adva_cms/jquery.table_tree.js +0 -704
  12. data/app/assets/stylesheets/adva_cms/jquery/alternate/jquery.tooltip.scss +0 -13
  13. data/app/assets/stylesheets/adva_cms/jquery/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  14. data/app/assets/stylesheets/adva_cms/jquery/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  15. data/app/assets/stylesheets/adva_cms/jquery/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  16. data/app/assets/stylesheets/adva_cms/jquery/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  17. data/app/assets/stylesheets/adva_cms/jquery/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  18. data/app/assets/stylesheets/adva_cms/jquery/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  19. data/app/assets/stylesheets/adva_cms/jquery/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  20. data/app/assets/stylesheets/adva_cms/jquery/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  21. data/app/assets/stylesheets/adva_cms/jquery/images/ui-icons_222222_256x240.png +0 -0
  22. data/app/assets/stylesheets/adva_cms/jquery/images/ui-icons_2e83ff_256x240.png +0 -0
  23. data/app/assets/stylesheets/adva_cms/jquery/images/ui-icons_454545_256x240.png +0 -0
  24. data/app/assets/stylesheets/adva_cms/jquery/images/ui-icons_888888_256x240.png +0 -0
  25. data/app/assets/stylesheets/adva_cms/jquery/images/ui-icons_cd0a0a_256x240.png +0 -0
  26. data/app/assets/stylesheets/adva_cms/jquery/jquery.tooltip.scss +0 -10
@@ -1,704 +0,0 @@
1
- //= require jquery
2
-
3
- $(function() {
4
- $('a.reorder').click(function(event) {
5
- event.preventDefault();
6
- $(this).parent().toggleClass('active');
7
- TableTree.toggle($('table.list'), this.id.replace('reorder_', ''), this.href);
8
- });
9
- });
10
-
11
- // adva_cms/jquery/jquery.tablednd_0_5
12
- /**
13
- * TableDnD plug-in for JQuery, allows you to drag and drop table rows
14
- * You can set up various options to control how the system will work
15
- * Copyright (c) Denis Howlett <denish@isocra.com>
16
- * Licensed like jQuery, see http://docs.jquery.com/License.
17
- *
18
- * Configuration options:
19
- *
20
- * onDragStyle
21
- * This is the style that is assigned to the row during drag. There are limitations to the styles that can be
22
- * associated with a row (such as you can't assign a border--well you can, but it won't be
23
- * displayed). (So instead consider using onDragClass.) The CSS style to apply is specified as
24
- * a map (as used in the jQuery css(...) function).
25
- * onDropStyle
26
- * This is the style that is assigned to the row when it is dropped. As for onDragStyle, there are limitations
27
- * to what you can do. Also this replaces the original style, so again consider using onDragClass which
28
- * is simply added and then removed on drop.
29
- * onDragClass
30
- * This class is added for the duration of the drag and then removed when the row is dropped. It is more
31
- * flexible than using onDragStyle since it can be inherited by the row cells and other content. The default
32
- * is class is tDnD_whileDrag. So to use the default, simply customise this CSS class in your
33
- * stylesheet.
34
- * onDrop
35
- * Pass a function that will be called when the row is dropped. The function takes 2 parameters: the table
36
- * and the row that was dropped. You can work out the new order of the rows by using
37
- * table.rows.
38
- * onDragStart
39
- * Pass a function that will be called when the user starts dragging. The function takes 2 parameters: the
40
- * table and the row which the user has started to drag.
41
- * onAllowDrop
42
- * Pass a function that will be called as a row is over another row. If the function returns true, allow
43
- * dropping on that row, otherwise not. The function takes 2 parameters: the dragged row and the row under
44
- * the cursor. It returns a boolean: true allows the drop, false doesn't allow it.
45
- * scrollAmount
46
- * This is the number of pixels to scroll if the user moves the mouse cursor to the top or bottom of the
47
- * window. The page should automatically scroll up or down as appropriate (tested in IE6, IE7, Safari, FF2,
48
- * FF3 beta
49
- * dragHandle
50
- * This is the name of a class that you assign to one or more cells in each row that is draggable. If you
51
- * specify this class, then you are responsible for setting cursor: move in the CSS and only these cells
52
- * will have the drag behaviour. If you do not specify a dragHandle, then you get the old behaviour where
53
- * the whole row is draggable.
54
- *
55
- * Other ways to control behaviour:
56
- *
57
- * Add class="nodrop" to any rows for which you don't want to allow dropping, and class="nodrag" to any rows
58
- * that you don't want to be draggable.
59
- *
60
- * Inside the onDrop method you can also call $.tableDnD.serialize() this returns a string of the form
61
- * <tableID>[]=<rowID1>&<tableID>[]=<rowID2> so that you can send this back to the server. The table must have
62
- * an ID as must all the rows.
63
- *
64
- * Other methods:
65
- *
66
- * $("...").tableDnDUpdate()
67
- * Will update all the matching tables, that is it will reapply the mousedown method to the rows (or handle cells).
68
- * This is useful if you have updated the table rows using Ajax and you want to make the table draggable again.
69
- * The table maintains the original configuration (so you don't have to specify it again).
70
- *
71
- * $("...").tableDnDSerialize()
72
- * Will serialize and return the serialized string as above, but for each of the matching tables--so it can be
73
- * called from anywhere and isn't dependent on the currentTable being set up correctly before calling
74
- *
75
- * Known problems:
76
- * - Auto-scoll has some problems with IE7 (it scrolls even when it shouldn't), work-around: set scrollAmount to 0
77
- *
78
- * Version 0.2: 2008-02-20 First public version
79
- * Version 0.3: 2008-02-07 Added onDragStart option
80
- * Made the scroll amount configurable (default is 5 as before)
81
- * Version 0.4: 2008-03-15 Changed the noDrag/noDrop attributes to nodrag/nodrop classes
82
- * Added onAllowDrop to control dropping
83
- * Fixed a bug which meant that you couldn't set the scroll amount in both directions
84
- * Added serialize method
85
- * Version 0.5: 2008-05-16 Changed so that if you specify a dragHandle class it doesn't make the whole row
86
- * draggable
87
- * Improved the serialize method to use a default (and settable) regular expression.
88
- * Added tableDnDupate() and tableDnDSerialize() to be called when you are outside the table
89
- */
90
- jQuery.tableDnD = {
91
- /** Keep hold of the current table being dragged */
92
- currentTable : null,
93
- /** Keep hold of the current drag object if any */
94
- dragObject: null,
95
- /** The current mouse offset */
96
- mouseOffset: null,
97
- /** Remember the old value of Y so that we don't do too much processing */
98
- oldY: 0,
99
-
100
- /** Actually build the structure */
101
- build: function(options) {
102
- // Set up the defaults if any
103
-
104
- this.each(function() {
105
- // This is bound to each matching table, set up the defaults and override with user options
106
- this.tableDnDConfig = $.extend({
107
- onDragStyle: null,
108
- onDropStyle: null,
109
- // Add in the default class for whileDragging
110
- onDragClass: "tDnD_whileDrag",
111
- onDrop: null,
112
- onDrag: null, // ADDED
113
- onDragStart: null,
114
- scrollAmount: 5,
115
- serializeRegexp: /[^\-]*$/, // The regular expression to use to trim row IDs
116
- serializeParamName: null, // If you want to specify another parameter name instead of the table ID
117
- dragHandle: null // If you give the name of a class here, then only Cells with this class will be draggable
118
- }, options || {});
119
- // Now make the rows draggable
120
- jQuery.tableDnD.makeDraggable(this);
121
- });
122
-
123
- // Now we need to capture the mouse up and mouse move event
124
- // We can use bind so that we don't interfere with other event handlers
125
- jQuery(document)
126
- .bind('mousemove', jQuery.tableDnD.mousemove)
127
- .bind('mouseup', jQuery.tableDnD.mouseup);
128
-
129
- // Don't break the chain
130
- return this;
131
- },
132
-
133
- /** This function makes all the rows on the table draggable apart from those marked as "NoDrag" */
134
- makeDraggable: function(table) {
135
- var config = table.tableDnDConfig;
136
- if (table.tableDnDConfig.dragHandle) {
137
- // We only need to add the event to the specified cells
138
- var cells = $("td."+table.tableDnDConfig.dragHandle, table);
139
- cells.each(function() {
140
- // The cell is bound to "this"
141
- jQuery(this).mousedown(function(ev) {
142
- jQuery.tableDnD.dragObject = this.parentNode;
143
- jQuery.tableDnD.currentTable = table;
144
- jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
145
- if (config.onDragStart) {
146
- // Call the onDrop method if there is one
147
- config.onDragStart(table, this);
148
- }
149
- return false;
150
- });
151
- })
152
- } else {
153
- // For backwards compatibility, we add the event to the whole row
154
- var rows = jQuery("tr", table); // get all the rows as a wrapped set
155
- rows.each(function() {
156
- // Iterate through each row, the row is bound to "this"
157
- var row = $(this);
158
- if (! row.hasClass("nodrag")) {
159
- row.mousedown(function(ev) {
160
- if (ev.target.tagName == "TD") {
161
- jQuery.tableDnD.dragObject = this;
162
- jQuery.tableDnD.currentTable = table;
163
- jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
164
- if (config.onDragStart) {
165
- // Call the onDrop method if there is one
166
- config.onDragStart(table, this);
167
- }
168
- return false;
169
- }
170
- }).css("cursor", "move"); // Store the tableDnD object
171
- }
172
- });
173
- }
174
- },
175
-
176
- updateTables: function() {
177
- this.each(function() {
178
- // this is now bound to each matching table
179
- if (this.tableDnDConfig) {
180
- jQuery.tableDnD.makeDraggable(this);
181
- }
182
- })
183
- },
184
-
185
- /** Get the mouse coordinates from the event (allowing for browser differences) */
186
- mouseCoords: function(ev){
187
- if(ev.pageX || ev.pageY){
188
- return {x:ev.pageX, y:ev.pageY};
189
- }
190
- return {
191
- x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
192
- y:ev.clientY + document.body.scrollTop - document.body.clientTop
193
- };
194
- },
195
-
196
- /** Given a target element and a mouse event, get the mouse offset from that element.
197
- To do this we need the element's position and the mouse position */
198
- getMouseOffset: function(target, ev) {
199
- ev = ev || window.event;
200
-
201
- var docPos = this.getPosition(target);
202
- var mousePos = this.mouseCoords(ev);
203
- return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
204
- },
205
-
206
- /** Get the position of an element by going up the DOM tree and adding up all the offsets */
207
- getPosition: function(e){
208
- var left = 0;
209
- var top = 0;
210
- /** Safari fix -- thanks to Luis Chato for this! */
211
- if (e.offsetHeight == 0) {
212
- /** Safari 2 doesn't correctly grab the offsetTop of a table row
213
- this is detailed here:
214
- http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari/
215
- the solution is likewise noted there, grab the offset of a table cell in the row - the firstChild.
216
- note that firefox will return a text node as a first child, so designing a more thorough
217
- solution may need to take that into account, for now this seems to work in firefox, safari, ie */
218
- e = e.firstChild; // a table cell
219
- }
220
-
221
- while (e.offsetParent){
222
- left += e.offsetLeft;
223
- top += e.offsetTop;
224
- e = e.offsetParent;
225
- }
226
-
227
- left += e.offsetLeft;
228
- top += e.offsetTop;
229
-
230
- return {x:left, y:top};
231
- },
232
-
233
- mousemove: function(ev) {
234
- if (jQuery.tableDnD.dragObject == null) {
235
- return;
236
- }
237
-
238
- var dragObj = jQuery(jQuery.tableDnD.dragObject);
239
- var config = jQuery.tableDnD.currentTable.tableDnDConfig;
240
- var mousePos = jQuery.tableDnD.mouseCoords(ev);
241
- var y = mousePos.y - jQuery.tableDnD.mouseOffset.y;
242
- //auto scroll the window
243
- var yOffset = window.pageYOffset;
244
- if (document.all) {
245
- // Windows version
246
- //yOffset=document.body.scrollTop;
247
- if (typeof document.compatMode != 'undefined' &&
248
- document.compatMode != 'BackCompat') {
249
- yOffset = document.documentElement.scrollTop;
250
- }
251
- else if (typeof document.body != 'undefined') {
252
- yOffset=document.body.scrollTop;
253
- }
254
-
255
- }
256
-
257
- if (mousePos.y-yOffset < config.scrollAmount) {
258
- window.scrollBy(0, -config.scrollAmount);
259
- } else {
260
- var windowHeight = window.innerHeight ? window.innerHeight
261
- : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
262
- if (windowHeight-(mousePos.y-yOffset) < config.scrollAmount) {
263
- window.scrollBy(0, config.scrollAmount);
264
- }
265
- }
266
-
267
-
268
- if (y != jQuery.tableDnD.oldY) {
269
- // work out if we're going up or down...
270
- var movingDown = y > jQuery.tableDnD.oldY;
271
- // update the old value
272
- jQuery.tableDnD.oldY = y;
273
- // update the style to show we're dragging
274
- if (config.onDragClass) {
275
- dragObj.addClass(config.onDragClass);
276
- } else {
277
- dragObj.css(config.onDragStyle);
278
- }
279
- // If we're over a row then move the dragged row to there so that the user sees the
280
- // effect dynamically
281
- var currentRow = jQuery.tableDnD.findDropTargetRow(dragObj, y, movingDown);
282
- if (currentRow) {
283
- // TODO worry about what happens when there are multiple TBODIES
284
- if (movingDown && jQuery.tableDnD.dragObject != currentRow) {
285
- jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow.nextSibling);
286
- } else if (! movingDown && jQuery.tableDnD.dragObject != currentRow) {
287
- jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow);
288
- }
289
- if (config.onDrag) {
290
- config.onDrag(jQuery.tableDnD.currentTable, jQuery.tableDnD.dragObject);
291
- }
292
- }
293
- }
294
-
295
- return false;
296
- },
297
-
298
- /** We're only worried about the y position really, because we can only move rows up and down */
299
- findDropTargetRow: function(draggedRow, y, movingDown) {
300
- var rows = jQuery.tableDnD.currentTable.rows;
301
- for (var i=0; i<rows.length; i++) {
302
- var row = rows[i];
303
- var rowY = this.getPosition(row).y;
304
- var rowHeight = parseInt(row.offsetHeight)/2;
305
- if (row.offsetHeight == 0) {
306
- rowY = this.getPosition(row.firstChild).y;
307
- rowHeight = parseInt(row.firstChild.offsetHeight)/2;
308
- }
309
- // Because we always have to insert before, we need to offset the height a bit
310
- if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {
311
- // that's the row we're over
312
- // If it's the same as the current row, ignore it
313
- if (row == draggedRow.get(0)) {return null;}
314
- var config = jQuery.tableDnD.currentTable.tableDnDConfig;
315
- if (config.onAllowDrop) {
316
- if (config.onAllowDrop(draggedRow, row, movingDown)) {
317
- return row;
318
- } else {
319
- return null;
320
- }
321
- } else {
322
- // If a row has nodrop class, then don't allow dropping (inspired by John Tarr and Famic)
323
- var nodrop = $(row).hasClass("nodrop");
324
- if (! nodrop) {
325
- return row;
326
- } else {
327
- return null;
328
- }
329
- }
330
- return row;
331
- }
332
- }
333
- return null;
334
- },
335
-
336
- mouseup: function(e) {
337
- if (jQuery.tableDnD.currentTable && jQuery.tableDnD.dragObject) {
338
- var droppedRow = jQuery.tableDnD.dragObject;
339
- var config = jQuery.tableDnD.currentTable.tableDnDConfig;
340
- // If we have a dragObject, then we need to release it,
341
- // The row will already have been moved to the right place so we just reset stuff
342
- if (config.onDragClass) {
343
- jQuery(droppedRow).removeClass(config.onDragClass);
344
- } else {
345
- jQuery(droppedRow).css(config.onDropStyle);
346
- }
347
- jQuery.tableDnD.dragObject = null;
348
- if (config.onDrop) {
349
- // Call the onDrop method if there is one
350
- config.onDrop(jQuery.tableDnD.currentTable, droppedRow);
351
- }
352
- jQuery.tableDnD.currentTable = null; // let go of the table too
353
- }
354
- },
355
-
356
- serialize: function() {
357
- if (jQuery.tableDnD.currentTable) {
358
- return jQuery.tableDnD.serializeTable(jQuery.tableDnD.currentTable);
359
- } else {
360
- return "Error: No Table id set, you need to set an id on your table and every row";
361
- }
362
- },
363
-
364
- serializeTable: function(table) {
365
- var result = "";
366
- var tableId = table.id;
367
- var rows = table.rows;
368
- for (var i=0; i<rows.length; i++) {
369
- if (result.length > 0) result += "&";
370
- var rowId = rows[i].id;
371
- if (rowId && rowId && table.tableDnDConfig && table.tableDnDConfig.serializeRegexp) {
372
- rowId = rowId.match(table.tableDnDConfig.serializeRegexp)[0];
373
- }
374
-
375
- result += tableId + '[]=' + rows[i].id;
376
- }
377
- return result;
378
- },
379
-
380
- serializeTables: function() {
381
- var result = "";
382
- this.each(function() {
383
- // this is now bound to each matching table
384
- result += jQuery.tableDnD.serializeTable(this);
385
- });
386
- return result;
387
- }
388
-
389
- }
390
-
391
- jQuery.fn.extend(
392
- {
393
- tableDnD : jQuery.tableDnD.build,
394
- tableDnDUpdate : jQuery.tableDnD.updateTables,
395
- tableDnDSerialize: jQuery.tableDnD.serializeTables
396
- }
397
- );
398
-
399
-
400
-
401
-
402
-
403
-
404
-
405
-
406
-
407
-
408
- // adva_cms/jquery/jquery.table_tree
409
- TableTree = {
410
- tableDnDOptions: {
411
- onDragClass: 'drag',
412
- onDragStart: function(table, row) {
413
- TableTree.startOffset = jQuery.tableDnD.mouseOffset.x;
414
- $(row).mousemove(TableTree.mousemove);
415
- if (node = $(row).ttnode()) node.dragStart();
416
- },
417
- onDrag: function(table, row) {
418
- TableTree.current_table.dirty = true;
419
- if (node = $(row).ttnode()) node.update_children();
420
- },
421
- onDrop: function(table, row) {
422
- $(row).unbind('mousemove', TableTree.mousemove);
423
- if (node = $(row).ttnode()) node.drop();
424
- TableTree.current_table.rebuild();
425
- TableTree.current_table.update_remote(row);
426
- },
427
- onAllowDrop: function(draggedRow, row, movingDown) {
428
- var node = $(row).ttnode();
429
- next = movingDown ? $(node.next_row_sibling()).ttnode() : node;
430
- if (next && (next.parent.level >= $(draggedRow).ttnode().level)) return false;
431
- return $(row).ttnode() ? true : false;
432
- }
433
- },
434
- toggle: function(table, type, collection_url) {
435
- TableTree.current_table ? TableTree.teardown(table) : TableTree.setup(table, type, collection_url);
436
- },
437
- setup: function(table, type, collection_url) {
438
- $('tbody', table).tableDnD(TableTree.tableDnDOptions);
439
- TableTree.current_table = new TableTree.Table($(table).get(0), type, collection_url);
440
- TableTree.current_table.setSortable();
441
- },
442
- teardown: function(table) {
443
- // TableTree.current_table.update_remote();
444
- jQuery.tableDnD.teardown(table);
445
- TableTree.current_table.setUnsortable();
446
- TableTree.current_table = null;
447
- },
448
- level: function(element) {
449
- var match = element.className.match(/level_([\d]+)/);
450
- return match ? parseInt(match[1]) : 0;
451
- },
452
- mousemove: function(event) {
453
- if (!TableTree.current_table.is_tree) return;
454
-
455
- var offset = jQuery.tableDnD.getMouseOffset(this, event).x - TableTree.startOffset;
456
- if(offset > 25) {
457
- TableTree.current_table.dirty = true;
458
- $(this).ttnode().increment_level(event);
459
- } else if(offset < -25) {
460
- TableTree.current_table.dirty = true;
461
- $(this).ttnode().decrement_level(event);
462
- }
463
- },
464
- Base: function() {},
465
- Table: function(table, type, collection_url) {
466
- this.is_tree = $(table).hasClass('tree')
467
- this.table = table; //$('tbody', table)
468
- this.type = type;
469
- this.level = -1;
470
- this.collection_url = collection_url;
471
- this.rebuild();
472
- },
473
- Node: function(parent, element, level) {
474
- var _this = this;
475
- this.parent = parent;
476
- this.element = element;
477
- this.level = level;
478
-
479
- this.children = this.find_children().map(function() {
480
- var level = TableTree.level(this);
481
- if(level == _this.level + 1) { return new TableTree.Node(_this, this, level); }
482
- });
483
- }
484
- }
485
-
486
- TableTree.Base.prototype = {
487
- find_node: function(element) {
488
- for (var i = 0; i < this.children.length; i++) {
489
- var child = this.children[i];
490
- if (this.children[i].element == element) {
491
- return this.children[i];
492
- } else {
493
- var result = this.children[i].find_node(element);
494
- if (result) return result;
495
- }
496
- }
497
- }
498
- }
499
- TableTree.Table.prototype = jQuery.extend(new TableTree.Base(), {
500
- rebuild: function() {
501
- var _this = this;
502
- this.children = $('tr', this.table).map(function() {
503
- if(TableTree.level(this) == 0) { return new TableTree.Node(_this, this, TableTree.level(this)); }
504
- });
505
- },
506
- setSortable: function() {
507
- $('tr', this.table).each(function() {
508
- // thead
509
- cells = $('th', this);
510
- cells.each(function(ix) {
511
- if(ix == 0) {
512
- this.setAttribute('colspan', cells.length);
513
- } else {
514
- $(this).hide();
515
- }
516
- });
517
-
518
- // tbody
519
- cells = $('td', this);
520
- cells.each(function(ix) {
521
- if (ix == 0) {
522
- element = this;
523
- this.setAttribute('colspan', cells.length);
524
- $('a', this).each(function() {
525
- $(this).hide();
526
- element.appendChild(document.createTextNode($(this).text()))
527
- });
528
- } else {
529
- $(this).hide();
530
- }
531
- });
532
- });
533
- },
534
- setUnsortable: function() {
535
- $('tr', this.table).each(function(ix) {
536
- // thead
537
- cells = $('th', this);
538
- cells.each(function(ix) {
539
- if(ix == 0) {
540
- this.setAttribute('colspan', 1);
541
- } else {
542
- $(this).show();
543
- }
544
- });
545
-
546
- // tbody
547
- $('td', this).each(function(ix) {
548
- if(ix == 0) {
549
- $('a', this).each(function() {
550
- $(this).show();
551
- });
552
- $('img.spinner', this).remove();
553
- this.removeChild(this.lastChild);
554
- this.setAttribute('colspan', 1);
555
- } else {
556
- $(this).show();
557
- }
558
- });
559
- });
560
- },
561
- update_remote: function(row) {
562
- if(!this.dirty) return;
563
- this.dirty = false;
564
- _this = this;
565
-
566
- this.show_spinner(row);
567
-
568
- $.ajax({
569
- type: "POST",
570
- url: this.collection_url,
571
- beforeSend: function(xhr) {
572
- xhr.setRequestHeader("Accept", "text/javascript, text/html, application/xml, text/xml, */*");
573
- },
574
- data: jQuery.extend(this.serialize(row), { authenticity_token: window._auth_token, '_method': 'put' }),
575
- success: function(msg) { _this.hide_spinner(row); },
576
- error: function(msg) { _this.hide_spinner(row); }
577
- });
578
- },
579
- serialize: function(row) {
580
- row = $(row).ttnode();
581
- data = {};
582
- data[this.type + '[' + row.id() + '][parent_id]'] = row.parent_id();
583
- data[this.type +'[' + row.id() + '][left_id]'] = row.left_id();
584
- return data;
585
- },
586
- show_spinner: function(row) {
587
- img = document.createElement('img');
588
- img.src = 'data:image/gif;base64,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';
589
- img.className = 'spinner';
590
- $('td', row)[0].appendChild(img);
591
- },
592
- hide_spinner: function(row) {
593
- cell = $('td', row)[0];
594
- cell.removeChild(cell.lastChild);
595
- }
596
- });
597
-
598
- TableTree.Node.prototype = jQuery.extend(new TableTree.Base(), {
599
- find_children: function() {
600
- var lvl = this.level;
601
- var stop = false;
602
- return this.row_siblings().slice(this.row_index() + 1).filter(function() {
603
- var level = TableTree.level(this);
604
- if(lvl == level) stop = true; // how to break from a jquery iterator?
605
- return !stop && lvl + 1 == level;
606
- });
607
- },
608
- depth: function() {
609
- if (this.children.length > 0) {
610
- return Math.max.apply(Math, this.children.map(function() { return this.depth() }).get());
611
- } else {
612
- return this.level;
613
- }
614
- },
615
- siblings: function() {
616
- return this.parent.children;
617
- },
618
- id: function() {
619
- return this.element ? this.to_int(this.element.id) : 'null';
620
- },
621
- parent_id: function() {
622
- return this.parent.element ? this.to_int(this.parent.element.id) : 'null';
623
- },
624
- left_id: function() {
625
- left = this.left()
626
- return left ? this.to_int(left.element.id) : 'null';
627
- },
628
- left: function() {
629
- siblings = this.siblings().get();
630
- ix = siblings.indexOf(this) - 1;
631
- if(ix >= 0) return siblings[ix];
632
- },
633
- to_int: function(str) {
634
- if(str) return str.replace(/[\D]+/, '')
635
- },
636
- next_row_sibling: function () {
637
- return this.row_siblings()[this.row_index() + 1];
638
- },
639
- row_siblings: function() {
640
- if(!this._row_siblings) { this._row_siblings = $(this.element).parent().children(); }
641
- return this._row_siblings;
642
- },
643
- row_index: function() {
644
- return this.row_siblings().get().indexOf(this.element);
645
- },
646
- dragStart: function() {
647
- $(this.element).addClass('drag');
648
- this.children.each(function() { this.dragStart(); })
649
- },
650
- drop: function() {
651
- $(this.element).removeClass('drag');
652
- this.children.each(function() { this.drop(); })
653
- this.adjust_level();
654
- },
655
- increment_level: function(event) {
656
- var prev = $(this.element).prev().ttnode();
657
- if(!prev || prev.level < this.level || this.depth() >= 5) return;
658
- this.update_level(event, this.level + 1);
659
- },
660
- decrement_level: function(event) {
661
- if(this.level == 0) return;
662
- this.update_level(event, this.level - 1);
663
- },
664
- update_level: function(event, level) {
665
- if (event) TableTree.startOffset = jQuery.tableDnD.getMouseOffset(this.element, event).x;
666
-
667
- $(this.element).removeClass('level_' + this.level);
668
- $(this.element).addClass('level_' + level);
669
-
670
- this.level = level;
671
- this.children.each(function() { this.update_level(event, level + 1); });
672
- },
673
- adjust_level: function() {
674
- var prev = $(this.element).prev().ttnode();
675
- if(!prev) {
676
- this.update_level(null, 0);
677
- } else if(prev.level + 1 < this.level) {
678
- this.update_level(null, prev.level + 1);
679
- }
680
- },
681
- update_children: function() {
682
- this.children.each(function() { this.element.parentNode.removeChild(this.element); });
683
- var _this = this;
684
- var _next = _this.element.nextSibling;
685
- this.children.each(function() { _this.element.parentNode.insertBefore(this.element, _next); });
686
- this.children.each(function() { this.update_children() });
687
- }
688
- });
689
-
690
- jQuery.fn.extend({
691
- ttnode: function() {
692
- var subject = this.push ? this[0] : this;
693
- return TableTree.current_table.find_node(subject);
694
- }
695
- });
696
-
697
- jQuery.extend(jQuery.tableDnD, {
698
- teardown: function(table) {
699
- jQuery('tr', table).each(function() { $(this).unbind('mousedown'); }).css('cursor', 'auto');
700
- jQuery.tableDnD.dragObject = null;
701
- jQuery.tableDnD.currentTable = null;
702
- jQuery.tableDnD.mouseOffset = null;
703
- }
704
- });