]> git.ozlabs.org Git - patchwork/blob - htdocs/js/bundle.js
js: Add jquery and jquery tablednd plugins
[patchwork] / htdocs / js / bundle.js
1
2 var editing_order = false;
3 var dragging = false;
4
5 function order_button_click(node)
6 {
7     var rows, form;
8
9     form = $("#reorderform");
10     rows = $("#patchlist").get(0).tBodies[0].rows;
11
12     if (rows.length < 1)
13         return;
14
15     if (editing_order) {
16
17         /* disable the save button */
18         node.disabled = true;
19
20         /* add input elements as the sequence of patches */
21         for (var i = 0; i < rows.length; i++) {
22             form.append('<input type="hidden" name="neworder" value="' +
23                     row_to_patch_id(rows[i]) + '"/>');
24         }
25
26         form.get(0).submit();
27     } else {
28
29         /* store the first order value */
30         start_order = row_to_patch_id(rows[0]);
31         $("input[name='order_start']").attr("value", start_order);
32
33         /* update buttons */
34         node.setAttribute("value", "Save order");
35         $("#reorder\\-cancel").css("display", "inline");
36
37         /* show help text */
38         $("#reorderhelp").text('Drag & drop rows to reorder');
39
40         /* enable drag & drop on the patches list */
41         $("#patchlist").tableDnD({
42             onDragClass: 'dragging',
43             onDragStart: function() { dragging = true; },
44             onDrop: function() { dragging = false; }
45         });
46
47         /* replace zebra striping with hover */
48         $("#patchlist tbody tr").css("background", "inherit");
49         $("#patchlist tbody tr").hover(drag_hover_in, drag_hover_out);
50     }
51
52     editing_order = !editing_order;
53 }
54
55 function order_cancel_click(node)
56 {
57     node.form.submit();
58 }
59
60 /* dragging helper functions */
61 function drag_hover_in()
62 {
63     if (!dragging)
64         $(this).addClass("draghover");
65 }
66 function drag_hover_out()
67 {
68     $(this).removeClass("draghover");
69 }
70
71 function row_to_patch_id(node)
72 {
73     var id_str, i;
74
75     id_str = node.getAttribute("id");
76
77     i = id_str.indexOf(':');
78     if (i == -1)
79         return null;
80
81     return id_str.substring(i + 1);
82 }