]> git.pld-linux.org Git - packages/eventum.git/blob - eventum-order.patch
- bring it up to date
[packages/eventum.git] / eventum-order.patch
1 --- eventum-2.2/htdocs/ajax/order.php   1970-01-01 02:00:00.000000000 +0200
2 +++ eventum-2.2-order/htdocs/ajax/order.php     2009-10-12 22:10:36.429185594 +0300
3 @@ -0,0 +1,69 @@
4 +<?
5 +require_once dirname(__FILE__) . '/../../init.php';
6 +
7 +// check login
8 +if (!Auth::hasValidCookie(APP_COOKIE)) {
9 +       exit;
10 +}
11 +
12 +
13 +if (!isset($_POST['before']) || !isset($_POST['after'])) {
14 +       exit;
15 +}
16 +
17 +parse_str($_POST['before'], $before);
18 +parse_str($_POST['after'], $after);
19 +
20 +$before = $before['issue_list_table'];
21 +$after = $after['issue_list_table'];
22 +
23 +
24 +$before = array_slice($before, 2, count($before)-3);
25 +$after = array_slice($after, 2, count($after)-3);
26 +
27 +if (count($before) != count($after) or count($before) < 1) {
28 +       exit;
29 +}
30 +
31 +$usr_id = Auth::getUserID();
32 +
33 +$order = Issue::getIssueOrderByUser($usr_id);
34 +
35 +if (!count($order)) {
36 +    // no prev order list
37 +    exit;
38 +}
39 +
40 +$after_filterd = array();
41 +$before_filterd = array();
42 +
43 +// remove issues that are not assigned to me
44 +foreach ($after as $id) {
45 +    if (isset($order[$id])) {
46 +        $after_filterd[] = $id;
47 +    }
48 +}
49 +foreach ($before as $id) {
50 +    if (isset($order[$id])) {
51 +        $before_filterd[] = $id;
52 +    }
53 +}
54 +
55 +foreach ($after_filterd as $key => $nID) {
56 +    if ($nID != $before_filterd[$key]) {
57 +        if ($nID) {
58 +            $stmt = "UPDATE
59 +                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
60 +                     SET
61 +                        isu_order = " . $order[$before_filterd[$key]] . "
62 +                     WHERE
63 +                        isu_iss_id = $nID AND
64 +                        isu_usr_id = $usr_id";
65 +            $res = DB_Helper::getInstance()->query($stmt);
66 +            if (PEAR::isError($res)) {
67 +                Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
68 +                die('update failed');
69 +            }
70 +        }
71 +    }
72 +}
73 --- eventum-2.2/htdocs/css/style.css~   2009-10-12 22:27:13.000000000 +0300
74 +++ eventum-2.2/htdocs/css/style.css    2009-10-12 22:28:31.402712101 +0300
75 @@ -176,3 +176,22 @@
76  .custom_field {
77      cursor: pointer;
78  }
79 +
80 +.tDnD_whileDrag td {
81 +    background-color: #ffffdd;
82 +}
83 +.tDnD_whileDrag td {
84 +    border: 1px solid red;
85 +}
86 +.inline_date_pick {
87 +    cursor: pointer;
88 +}
89 +.custom_field {
90 +    cursor: pointer;
91 +}
92 +.showDragHandle {
93 +    cursor: move;
94 +       background-image: url(../images/updown2.gif);
95 +    background-repeat: no-repeat;
96 +    background-position: center center;
97 +}
98 --- eventum-2.2/htdocs/js/jquery/jquery.tablednd.js     1970-01-01 02:00:00.000000000 +0200
99 +++ eventum-2.2-order/htdocs/js/jquery/jquery.tablednd.js       2009-10-12 22:10:36.435851675 +0300
100 @@ -0,0 +1,382 @@
101 +/**
102 + * TableDnD plug-in for JQuery, allows you to drag and drop table rows
103 + * You can set up various options to control how the system will work
104 + * Copyright (c) Denis Howlett <denish@isocra.com>
105 + * Licensed like jQuery, see http://docs.jquery.com/License.
106 + *
107 + * Configuration options:
108 + * 
109 + * onDragStyle
110 + *     This is the style that is assigned to the row during drag. There are limitations to the styles that can be
111 + *     associated with a row (such as you can't assign a border--well you can, but it won't be
112 + *     displayed). (So instead consider using onDragClass.) The CSS style to apply is specified as
113 + *     a map (as used in the jQuery css(...) function).
114 + * onDropStyle
115 + *     This is the style that is assigned to the row when it is dropped. As for onDragStyle, there are limitations
116 + *     to what you can do. Also this replaces the original style, so again consider using onDragClass which
117 + *     is simply added and then removed on drop.
118 + * onDragClass
119 + *     This class is added for the duration of the drag and then removed when the row is dropped. It is more
120 + *     flexible than using onDragStyle since it can be inherited by the row cells and other content. The default
121 + *     is class is tDnD_whileDrag. So to use the default, simply customise this CSS class in your
122 + *     stylesheet.
123 + * onDrop
124 + *     Pass a function that will be called when the row is dropped. The function takes 2 parameters: the table
125 + *     and the row that was dropped. You can work out the new order of the rows by using
126 + *     table.rows.
127 + * onDragStart
128 + *     Pass a function that will be called when the user starts dragging. The function takes 2 parameters: the
129 + *     table and the row which the user has started to drag.
130 + * onAllowDrop
131 + *     Pass a function that will be called as a row is over another row. If the function returns true, allow 
132 + *     dropping on that row, otherwise not. The function takes 2 parameters: the dragged row and the row under
133 + *     the cursor. It returns a boolean: true allows the drop, false doesn't allow it.
134 + * scrollAmount
135 + *     This is the number of pixels to scroll if the user moves the mouse cursor to the top or bottom of the
136 + *     window. The page should automatically scroll up or down as appropriate (tested in IE6, IE7, Safari, FF2,
137 + *     FF3 beta
138 + * dragHandle
139 + *     This is the name of a class that you assign to one or more cells in each row that is draggable. If you
140 + *     specify this class, then you are responsible for setting cursor: move in the CSS and only these cells
141 + *     will have the drag behaviour. If you do not specify a dragHandle, then you get the old behaviour where
142 + *     the whole row is draggable.
143 + * 
144 + * Other ways to control behaviour:
145 + *
146 + * Add class="nodrop" to any rows for which you don't want to allow dropping, and class="nodrag" to any rows
147 + * that you don't want to be draggable.
148 + *
149 + * Inside the onDrop method you can also call $.tableDnD.serialize() this returns a string of the form
150 + * <tableID>[]=<rowID1>&<tableID>[]=<rowID2> so that you can send this back to the server. The table must have
151 + * an ID as must all the rows.
152 + *
153 + * Other methods:
154 + *
155 + * $("...").tableDnDUpdate() 
156 + * Will update all the matching tables, that is it will reapply the mousedown method to the rows (or handle cells).
157 + * This is useful if you have updated the table rows using Ajax and you want to make the table draggable again.
158 + * The table maintains the original configuration (so you don't have to specify it again).
159 + *
160 + * $("...").tableDnDSerialize()
161 + * Will serialize and return the serialized string as above, but for each of the matching tables--so it can be
162 + * called from anywhere and isn't dependent on the currentTable being set up correctly before calling
163 + *
164 + * Known problems:
165 + * - Auto-scoll has some problems with IE7  (it scrolls even when it shouldn't), work-around: set scrollAmount to 0
166 + * 
167 + * Version 0.2: 2008-02-20 First public version
168 + * Version 0.3: 2008-02-07 Added onDragStart option
169 + *                         Made the scroll amount configurable (default is 5 as before)
170 + * Version 0.4: 2008-03-15 Changed the noDrag/noDrop attributes to nodrag/nodrop classes
171 + *                         Added onAllowDrop to control dropping
172 + *                         Fixed a bug which meant that you couldn't set the scroll amount in both directions
173 + *                         Added serialize method
174 + * Version 0.5: 2008-05-16 Changed so that if you specify a dragHandle class it doesn't make the whole row
175 + *                         draggable
176 + *                         Improved the serialize method to use a default (and settable) regular expression.
177 + *                         Added tableDnDupate() and tableDnDSerialize() to be called when you are outside the table
178 + */
179 +jQuery.tableDnD = {
180 +    /** Keep hold of the current table being dragged */
181 +    currentTable : null,
182 +    /** Keep hold of the current drag object if any */
183 +    dragObject: null,
184 +    /** The current mouse offset */
185 +    mouseOffset: null,
186 +    /** Remember the old value of Y so that we don't do too much processing */
187 +    oldY: 0,
188 +
189 +    /** Actually build the structure */
190 +    build: function(options) {
191 +        // Set up the defaults if any
192 +
193 +        this.each(function() {
194 +            // This is bound to each matching table, set up the defaults and override with user options
195 +            this.tableDnDConfig = jQuery.extend({
196 +                onDragStyle: null,
197 +                onDropStyle: null,
198 +                               // Add in the default class for whileDragging
199 +                               onDragClass: "tDnD_whileDrag",
200 +                onDrop: null,
201 +                onDragStart: null,
202 +                scrollAmount: 5,
203 +                               serializeRegexp: /[^\-]*$/, // The regular expression to use to trim row IDs
204 +                               serializeParamName: null, // If you want to specify another parameter name instead of the table ID
205 +                dragHandle: null // If you give the name of a class here, then only Cells with this class will be draggable
206 +            }, options || {});
207 +            // Now make the rows draggable
208 +            jQuery.tableDnD.makeDraggable(this);
209 +        });
210 +
211 +        // Now we need to capture the mouse up and mouse move event
212 +        // We can use bind so that we don't interfere with other event handlers
213 +        jQuery(document)
214 +            .bind('mousemove', jQuery.tableDnD.mousemove)
215 +            .bind('mouseup', jQuery.tableDnD.mouseup);
216 +
217 +        // Don't break the chain
218 +        return this;
219 +    },
220 +
221 +    /** This function makes all the rows on the table draggable apart from those marked as "NoDrag" */
222 +    makeDraggable: function(table) {
223 +        var config = table.tableDnDConfig;
224 +               if (table.tableDnDConfig.dragHandle) {
225 +                       // We only need to add the event to the specified cells
226 +                       var cells = jQuery("td."+table.tableDnDConfig.dragHandle, table);
227 +                       cells.each(function() {
228 +                               // The cell is bound to "this"
229 +                jQuery(this).mousedown(function(ev) {
230 +                    jQuery.tableDnD.dragObject = this.parentNode;
231 +                    jQuery.tableDnD.currentTable = table;
232 +                    jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
233 +                    if (config.onDragStart) {
234 +                        // Call the onDrop method if there is one
235 +                        config.onDragStart(table, this);
236 +                    }
237 +                    return false;
238 +                });
239 +                       })
240 +               } else {
241 +                       // For backwards compatibility, we add the event to the whole row
242 +               var rows = jQuery("tr", table); // get all the rows as a wrapped set
243 +               rows.each(function() {
244 +                               // Iterate through each row, the row is bound to "this"
245 +                               var row = jQuery(this);
246 +                               if (! row.hasClass("nodrag")) {
247 +                       row.mousedown(function(ev) {
248 +                           if (ev.target.tagName == "TD") {
249 +                               jQuery.tableDnD.dragObject = this;
250 +                               jQuery.tableDnD.currentTable = table;
251 +                               jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
252 +                               if (config.onDragStart) {
253 +                                   // Call the onDrop method if there is one
254 +                                   config.onDragStart(table, this);
255 +                               }
256 +                               return false;
257 +                           }
258 +                       }).css("cursor", "move"); // Store the tableDnD object
259 +                               }
260 +                       });
261 +               }
262 +       },
263 +
264 +       updateTables: function() {
265 +               this.each(function() {
266 +                       // this is now bound to each matching table
267 +                       if (this.tableDnDConfig) {
268 +                               jQuery.tableDnD.makeDraggable(this);
269 +                       }
270 +               })
271 +       },
272 +
273 +    /** Get the mouse coordinates from the event (allowing for browser differences) */
274 +    mouseCoords: function(ev){
275 +        if(ev.pageX || ev.pageY){
276 +            return {x:ev.pageX, y:ev.pageY};
277 +        }
278 +        return {
279 +            x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
280 +            y:ev.clientY + document.body.scrollTop  - document.body.clientTop
281 +        };
282 +    },
283 +
284 +    /** Given a target element and a mouse event, get the mouse offset from that element.
285 +        To do this we need the element's position and the mouse position */
286 +    getMouseOffset: function(target, ev) {
287 +        ev = ev || window.event;
288 +
289 +        var docPos    = this.getPosition(target);
290 +        var mousePos  = this.mouseCoords(ev);
291 +        return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
292 +    },
293 +
294 +    /** Get the position of an element by going up the DOM tree and adding up all the offsets */
295 +    getPosition: function(e){
296 +        var left = 0;
297 +        var top  = 0;
298 +        /** Safari fix -- thanks to Luis Chato for this! */
299 +        if (e.offsetHeight == 0) {
300 +            /** Safari 2 doesn't correctly grab the offsetTop of a table row
301 +            this is detailed here:
302 +            http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari/
303 +            the solution is likewise noted there, grab the offset of a table cell in the row - the firstChild.
304 +            note that firefox will return a text node as a first child, so designing a more thorough
305 +            solution may need to take that into account, for now this seems to work in firefox, safari, ie */
306 +            e = e.firstChild; // a table cell
307 +        }
308 +
309 +        while (e.offsetParent){
310 +            left += e.offsetLeft;
311 +            top  += e.offsetTop;
312 +            e     = e.offsetParent;
313 +        }
314 +
315 +        left += e.offsetLeft;
316 +        top  += e.offsetTop;
317 +
318 +        return {x:left, y:top};
319 +    },
320 +
321 +    mousemove: function(ev) {
322 +        if (jQuery.tableDnD.dragObject == null) {
323 +            return;
324 +        }
325 +
326 +        var dragObj = jQuery(jQuery.tableDnD.dragObject);
327 +        var config = jQuery.tableDnD.currentTable.tableDnDConfig;
328 +        var mousePos = jQuery.tableDnD.mouseCoords(ev);
329 +        var y = mousePos.y - jQuery.tableDnD.mouseOffset.y;
330 +        //auto scroll the window
331 +           var yOffset = window.pageYOffset;
332 +               if (document.all) {
333 +               // Windows version
334 +               //yOffset=document.body.scrollTop;
335 +               if (typeof document.compatMode != 'undefined' &&
336 +                    document.compatMode != 'BackCompat') {
337 +                  yOffset = document.documentElement.scrollTop;
338 +               }
339 +               else if (typeof document.body != 'undefined') {
340 +                  yOffset=document.body.scrollTop;
341 +               }
342 +
343 +           }
344 +                   
345 +               if (mousePos.y-yOffset < config.scrollAmount) {
346 +               window.scrollBy(0, -config.scrollAmount);
347 +           } else {
348 +            var windowHeight = window.innerHeight ? window.innerHeight
349 +                    : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
350 +            if (windowHeight-(mousePos.y-yOffset) < config.scrollAmount) {
351 +                window.scrollBy(0, config.scrollAmount);
352 +            }
353 +        }
354 +
355 +
356 +        if (y != jQuery.tableDnD.oldY) {
357 +            // work out if we're going up or down...
358 +            var movingDown = y > jQuery.tableDnD.oldY;
359 +            // update the old value
360 +            jQuery.tableDnD.oldY = y;
361 +            // update the style to show we're dragging
362 +                       if (config.onDragClass) {
363 +                               dragObj.addClass(config.onDragClass);
364 +                       } else {
365 +                   dragObj.css(config.onDragStyle);
366 +                       }
367 +            // If we're over a row then move the dragged row to there so that the user sees the
368 +            // effect dynamically
369 +            var currentRow = jQuery.tableDnD.findDropTargetRow(dragObj, y);
370 +            if (currentRow) {
371 +                // TODO worry about what happens when there are multiple TBODIES
372 +                if (movingDown && jQuery.tableDnD.dragObject != currentRow) {
373 +                    jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow.nextSibling);
374 +                } else if (! movingDown && jQuery.tableDnD.dragObject != currentRow) {
375 +                    jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow);
376 +                }
377 +            }
378 +        }
379 +
380 +        return false;
381 +    },
382 +
383 +    /** We're only worried about the y position really, because we can only move rows up and down */
384 +    findDropTargetRow: function(draggedRow, y) {
385 +        var rows = jQuery.tableDnD.currentTable.rows;
386 +        for (var i=0; i<rows.length; i++) {
387 +            var row = rows[i];
388 +            var rowY    = this.getPosition(row).y;
389 +            var rowHeight = parseInt(row.offsetHeight)/2;
390 +            if (row.offsetHeight == 0) {
391 +                rowY = this.getPosition(row.firstChild).y;
392 +                rowHeight = parseInt(row.firstChild.offsetHeight)/2;
393 +            }
394 +            // Because we always have to insert before, we need to offset the height a bit
395 +            if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {
396 +                // that's the row we're over
397 +                               // If it's the same as the current row, ignore it
398 +                               if (row == draggedRow) {return null;}
399 +                var config = jQuery.tableDnD.currentTable.tableDnDConfig;
400 +                if (config.onAllowDrop) {
401 +                    if (config.onAllowDrop(draggedRow, row)) {
402 +                        return row;
403 +                    } else {
404 +                        return null;
405 +                    }
406 +                } else {
407 +                                       // If a row has nodrop class, then don't allow dropping (inspired by John Tarr and Famic)
408 +                    var nodrop = jQuery(row).hasClass("nodrop");
409 +                    if (! nodrop) {
410 +                        return row;
411 +                    } else {
412 +                        return null;
413 +                    }
414 +                }
415 +                return row;
416 +            }
417 +        }
418 +        return null;
419 +    },
420 +
421 +    mouseup: function(e) {
422 +        if (jQuery.tableDnD.currentTable && jQuery.tableDnD.dragObject) {
423 +            var droppedRow = jQuery.tableDnD.dragObject;
424 +            var config = jQuery.tableDnD.currentTable.tableDnDConfig;
425 +            // If we have a dragObject, then we need to release it,
426 +            // The row will already have been moved to the right place so we just reset stuff
427 +                       if (config.onDragClass) {
428 +                   jQuery(droppedRow).removeClass(config.onDragClass);
429 +                       } else {
430 +                   jQuery(droppedRow).css(config.onDropStyle);
431 +                       }
432 +            jQuery.tableDnD.dragObject   = null;
433 +            if (config.onDrop) {
434 +                // Call the onDrop method if there is one
435 +                config.onDrop(jQuery.tableDnD.currentTable, droppedRow);
436 +            }
437 +            jQuery.tableDnD.currentTable = null; // let go of the table too
438 +        }
439 +    },
440 +
441 +    serialize: function() {
442 +        if (jQuery.tableDnD.currentTable) {
443 +            return jQuery.tableDnD.serializeTable(jQuery.tableDnD.currentTable);
444 +        } else {
445 +            return "Error: No Table id set, you need to set an id on your table and every row";
446 +        }
447 +    },
448 +
449 +       serializeTable: function(table) {
450 +        var result = "";
451 +        var tableId = table.id;
452 +        var rows = table.rows;
453 +        for (var i=0; i<rows.length; i++) {
454 +            if (result.length > 0) result += "&";
455 +            var rowId = rows[i].id;
456 +            if (rowId && rowId && table.tableDnDConfig && table.tableDnDConfig.serializeRegexp) {
457 +                rowId = rowId.match(table.tableDnDConfig.serializeRegexp)[0];
458 +            }
459 +
460 +            result += tableId + '[]=' + rowId;
461 +        }
462 +        return result;
463 +       },
464 +
465 +       serializeTables: function() {
466 +        var result = "";
467 +        this.each(function() {
468 +                       // this is now bound to each matching table
469 +                       result += jQuery.tableDnD.serializeTable(this);
470 +               });
471 +        return result;
472 +    }
473 +
474 +}
475 +
476 +jQuery.fn.extend(
477 +       {
478 +               tableDnD : jQuery.tableDnD.build,
479 +               tableDnDUpdate : jQuery.tableDnD.updateTables,
480 +               tableDnDSerialize: jQuery.tableDnD.serializeTables
481 +       }
482 +);
483 \ No newline at end of file
484 --- eventum-2.2/htdocs/list.php 2009-09-14 18:07:55.000000000 +0300
485 +++ eventum-2.2-order/htdocs/list.php   2009-10-12 22:10:36.435851675 +0300
486 @@ -53,6 +53,11 @@
487              $profile['sort_by'] . "&sort_order=" . $profile['sort_order']);
488  }
489  
490 +@$reorder_usr_id = $_REQUEST["reorder_user"];
491 +@$reorder_issue_id = $_REQUEST["reorder_source"];
492 +@$reorder_neworder = $_REQUEST["reorder_neworder"];
493 +Issue::reorderUserIssues($reorder_usr_id, $reorder_issue_id, $reorder_neworder);
494 +
495  $options = Issue::saveSearchParams();
496  $tpl->assign("options", $options);
497  $tpl->assign("sorting", Issue::getSortingInfo($options));
498 @@ -78,6 +83,21 @@
499  }
500  $assign_options += $users;
501  
502 +// get the isu_order (assignated users) ordering user
503 +if (!empty($options["users"])) {
504 +    if ($options["users"] == -2) {
505 +        $isu_order_user = $usr_id;
506 +    } else
507 +    if ($options["users"] > 0) {
508 +        $isu_order_user = $options["users"];
509 +    } else {
510 +        unset($isu_order_user);
511 +    }
512 +} else {
513 +    unset($isu_order_user);
514 +}
515 +$tpl->assign("isu_order_user", $isu_order_user);
516 +
517  $list = Issue::getListing($prj_id, $options, $pagerRow, $rows);
518  $tpl->assign("list", $list["list"]);
519  $tpl->assign("list_info", $list["info"]);
520 --- eventum-2.2/lib/eventum/class.display_column.php    2009-09-14 18:07:55.000000000 +0300
521 +++ eventum-2.2-order/lib/eventum/class.display_column.php      2009-10-12 22:10:36.429185594 +0300
522 @@ -230,7 +230,10 @@
523                  ),
524                  "iss_expected_resolution_date"  =>  array(
525                      "title" =>  ev_gettext("Expected Resolution Date")
526 -                )
527 +                ),
528 +                "isu_order" => array(
529 +                    "title" => ev_gettext("Order")
530 +                ),
531              )
532          );
533          return $columns[$page];
534 --- eventum-2.2/lib/eventum/class.issue.php     2009-09-14 18:07:55.000000000 +0300
535 +++ eventum-2.2-order/lib/eventum/class.issue.php       2009-10-12 22:10:36.445851670 +0300
536 @@ -1333,6 +1333,7 @@
537              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
538              return -1;
539          } else {
540 +            self::moveOrderForAllUsers($issue_id, 1000);
541              $prj_id = self::getProjectID($issue_id);
542  
543              // record the change
544 @@ -1800,16 +1801,33 @@
545      {
546          $issue_id = Misc::escapeInteger($issue_id);
547          $assignee_usr_id = Misc::escapeInteger($assignee_usr_id);
548 +        $order = 1;
549 +        // move all orders down to free "order space" for this new association
550 +        $stmt = "UPDATE 
551 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
552 +                 SET
553 +                    isu_order = isu_order + 1
554 +                 WHERE
555 +                    isu_usr_id = $assignee_usr_id AND
556 +                    isu_order >= $order";
557 +        $res = DB_Helper::getInstance()->query($stmt);
558 +        if (PEAR::isError($res)) {
559 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
560 +            return -1;
561 +        }
562 +        // insert the new association
563          $stmt = "INSERT INTO
564                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
565                   (
566                      isu_iss_id,
567                      isu_usr_id,
568 -                    isu_assigned_date
569 +                    isu_assigned_date,
570 +                    isu_order
571                   ) VALUES (
572                      $issue_id,
573                      $assignee_usr_id,
574 -                    '" . Date_Helper::getCurrentDateGMT() . "'
575 +                    '" . Date_Helper::getCurrentDateGMT() . "',
576 +                    $order
577                   )";
578          $res = DB_Helper::getInstance()->query($stmt);
579          if (PEAR::isError($res)) {
580 @@ -1824,6 +1842,78 @@
581          }
582      }
583  
584 +    /**
585 +     * Method used to get the order list to be rearranged
586 +     * 
587 +     * @access  private
588 +     * @param   string $issue_id The issue ID or a comma seperated list of IDs already prepared for giving to mysql
589 +     * @param   string $usr_id The user to remove. When not specified, all users are taken as to be removed for that issue
590 +     * @return  mixed delete order list to be rearranged. Used as a parameter to the method of rearranging the order.
591 +     */
592 +    function getDeleteUserAssociationOrderList($issue_id, $usr_id = "")
593 +    {
594 +        // find all affected associantion orders
595 +        $stmt = "SELECT isu_usr_id, isu_order FROM
596 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
597 +                 WHERE
598 +                 isu_iss_id IN ($issue_id)";
599 +        if (!empty($usr_id)) {
600 +            $stmt.= " AND isu_usr_id IN ($usr_id)";
601 +        }
602 +        $stmt.= "ORDER BY isu_order";
603 +        $res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC);
604 +        if (PEAR::isError($res)) {
605 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
606 +            return -1;
607 +        } else {
608 +            $deleted_orders = array();
609 +            foreach ($res as $row) {
610 +                if (empty($deleted_orders[$row['isu_usr_id']])) {
611 +                    $deleted_orders[$row['isu_usr_id']] = array();
612 +                }
613 +                $deleted_orders[$row['isu_usr_id']] [] = $row['isu_order'];
614 +            }
615 +            return $deleted_orders;
616 +        }
617 +    }
618 +
619 +    /**
620 +     *
621 +     * Method used to rearrange order list in the db according to known deleted records
622 +     *
623 +     * @access  private
624 +     * @param   mixed  deleteorder list
625 +     * @return void
626 +     */
627 +    function rearrangeDeleteUserAssociationOrderList($delete_order_list)
628 +    {
629 +        if (empty($delete_order_list) || (!is_array($delete_order_list))) {
630 +            return -1;
631 +        }
632 +        foreach ($delete_order_list as $isu_usr_id => $orders) {
633 +            for ($i = 0; $i < count($orders); $i++) { // traverse all deleted orders
634 +                // move the orders after them up to take the "order space" of the deleted records
635 +                $stmt = "UPDATE
636 +                            " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
637 +                         SET
638 +                            isu_order = isu_order - " . ($i+1) . "
639 +                         WHERE
640 +                            isu_usr_id = $isu_usr_id AND
641 +                            isu_order > " . $orders[$i];
642 +                if ($i < count($orders) - 1) {
643 +                    $stmt.=  " AND
644 +                            isu_order < " . $orders[$i+1];
645 +                }
646 +                $res = DB_Helper::getInstance()->query($stmt);
647 +                if (PEAR::isError($res)) {
648 +                    Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
649 +                    return -1;
650 +                }
651 +            }
652 +        }
653 +        return 1;
654 +    }
655 +
656  
657      /**
658       * Method used to delete all user assignments for a specific issue.
659 @@ -1839,6 +1929,7 @@
660          if (is_array($issue_id)) {
661              $issue_id = implode(", ", $issue_id);
662          }
663 +        $deleted_order_list = self::getDeleteUserAssociationOrderList($issue_id);
664          $stmt = "DELETE FROM
665                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
666                   WHERE
667 @@ -1869,6 +1960,7 @@
668      {
669          $issue_id = Misc::escapeInteger($issue_id);
670          $usr_id = Misc::escapeInteger($usr_id);
671 +        $delete_order_list = self::getDeleteUserAssociationOrderList($issue_id, $usr_id);
672          $stmt = "DELETE FROM
673                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
674                   WHERE
675 @@ -1883,6 +1975,7 @@
676                  History::add($issue_id, Auth::getUserID(), History::getTypeID('user_unassociated'),
677                      User::getFullName($usr_id) . ' removed from issue by ' . User::getFullName(Auth::getUserID()));
678              }
679 +            self::rearrangeDeleteUserAssociationOrderList($delete_order_list);
680              return 1;
681          }
682      }
683 @@ -2342,6 +2435,11 @@
684      {
685          $sort_by = self::getParam('sort_by');
686          $sort_order = self::getParam('sort_order');
687 +        $users = self::getParam('users');
688 +        if (empty($users) && ($sort_by == 'isu_order')) { // Sorting by isu_order is impossible when no user specified
689 +            unset($sort_by);
690 +            unset($sort_order);
691 +        }
692          $rows = self::getParam('rows');
693          $hide_closed = self::getParam('hide_closed');
694          if ($hide_closed === '') {
695 @@ -2448,6 +2546,7 @@
696              "iss_expected_resolution_date" => "desc",
697              "pre_title" => "asc",
698              "assigned" => "asc",
699 +            "isu_order" => "desc",
700          );
701  
702          foreach ($custom_fields as $fld_id => $fld_name) {
703 @@ -3253,6 +3352,8 @@
704          $ids = implode(", ", $ids);
705          $stmt = "SELECT
706                      isu_iss_id,
707 +                    isu_order,
708 +                    isu_usr_id,
709                      usr_full_name
710                   FROM
711                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,
712 @@ -3264,6 +3365,7 @@
713          if (PEAR::isError($res)) {
714              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
715          } else {
716 +            // gather names of the users assigned to each issue
717              $t = array();
718              for ($i = 0; $i < count($res); $i++) {
719                  if (!empty($t[$res[$i]['isu_iss_id']])) {
720 @@ -3272,9 +3374,18 @@
721                      $t[$res[$i]['isu_iss_id']] = $res[$i]['usr_full_name'];
722                  }
723              }
724 +            // gather orders
725 +            $o = array();
726 +            for ($i = 0; $i < count($res); $i++) {
727 +                if (empty($o[$res[$i]['isu_iss_id']])) {
728 +                    $o[$res[$i]['isu_iss_id']] = array();
729 +                }
730 +                $o[$res[$i]['isu_iss_id']][$res[$i]['isu_usr_id']] = $res[$i]['isu_order'];
731 +            }
732              // now populate the $result variable again
733              for ($i = 0; $i < count($result); $i++) {
734                  @$result[$i]['assigned_users'] = $t[$result[$i]['iss_id']];
735 +                @$result[$i]['assigned_users_order'] = $o[$result[$i]['iss_id']];
736              }
737          }
738      }
739 @@ -4247,6 +4358,7 @@
740              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
741              return -1;
742          }
743 +        self::moveOrderForAllUsers($issue_id, 1);
744      }
745  
746  
747 @@ -4346,4 +4458,120 @@
748          History::add($issue_id, Auth::getUserID(), History::getTypeID('user_associated'),
749                          "Issue assignment to changed (" . History::formatChanges(join(', ', $old_assignee_names), join(', ', $assignee_names)) . ") by " . User::getFullName(Auth::getUserID()));
750      }
751 +
752 +    /**
753 +     * Reorders user's issues as requested by user
754 +     * @access public
755 +     * @param $usr_id User to be reordered
756 +     * @param $issue_id Issue or array of issues to be moved
757 +     * @param $neworder The new order of the issues
758 +     * @return void
759 +     */
760 +    function reorderUserIssues($usr_id, $issue_id, $neworder)
761 +    {
762 +        if (!isset($usr_id) || !isset($issue_id) || !isset($neworder)) {
763 +            return false;
764 +        }
765 +        if (!is_numeric($usr_id) || !is_numeric($neworder)) {
766 +            return false;
767 +        }
768 +        $usr_id = Misc::escapeInteger($usr_id);
769 +        $issue_id = Misc::escapeInteger($issue_id);
770 +        $neworder = Misc::escapeInteger($neworder);
771 +        if (is_array($issue_id)) {
772 +            $issue_count = count($issue_id);
773 +            $issue_id_str = implode(", ", $issue_id);
774 +        } else {
775 +            $issue_count = 1;
776 +            $issue_id_str = $issue_id;
777 +            $issue_id = array($issue_id);
778 +        }
779 +        // do a nasty pretending to be deleting stuff so that reordering happens as if these elements were deleted
780 +        $orderlist = self::getDeleteUserAssociationOrderList($issue_id_str, $usr_id);
781 +        self::rearrangeDeleteUserAssociationOrderList($orderlist);
782 +        // move down the orders to free the "order space" needed
783 +        $stmt = "UPDATE 
784 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
785 +                 SET
786 +                    isu_order = isu_order + $issue_count
787 +                 WHERE
788 +                    isu_usr_id = $usr_id AND
789 +                    isu_order >= $neworder";
790 +        $res = DB_Helper::getInstance()->query($stmt);
791 +        if (PEAR::isError($res)) {
792 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
793 +            return -1;
794 +        }
795 +        //update the order for the issues being moved
796 +        $i = 0;
797 +        foreach ($issue_id as $iss_id) {
798 +            $stmt = "UPDATE
799 +                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
800 +                     SET
801 +                        isu_order = " . ($neworder + $i) . "
802 +                     WHERE
803 +                        isu_usr_id = $usr_id AND
804 +                        isu_iss_id = $iss_id";
805 +            $res = DB_Helper::getInstance()->query($stmt);
806 +            if (PEAR::isError($res)) {
807 +                Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
808 +                return -1;
809 +            }
810 +            $i++;
811 +        }
812 +    }
813 +
814 +
815 +    /**
816 +     * Get users issue order list
817 +     * @access public
818 +     * @param $user_id User
819 +     * @param $order_list Order of the issues
820 +     * @return void
821 +     */
822 +    function getIssueOrderByUser($usr_id) {
823 +
824 +        if (!is_numeric($usr_id)) {
825 +            return false;
826 +        }
827 +
828 +        $stmt = "SELECT
829 +                    isu_iss_id, isu_order
830 +                FROM
831 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
832 +                WHERE
833 +                    isu_usr_id = " . $usr_id ;
834 +
835 +        $order_list = array();
836 +
837 +        $res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC);
838 +
839 +        if (PEAR::isError($res)) {
840 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
841 +            return array();
842 +        } else {
843 +            foreach ($res as $row) {
844 +                $order_list[$row["isu_iss_id"]] = $row["isu_order"];
845 +            }
846 +        }
847 +        return $order_list;
848 +    }
849 +
850 +    function moveOrderForAllUsers($issue_id, $neworder)
851 +    {
852 +        // Move the issue to the top priority for the ppl it's assigned to
853 +        $stmt = "SELECT isu_usr_id FROM
854 +                    "  . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
855 +                 WHERE
856 +                    isu_iss_id = " . Misc::escapeInteger($issue_id);
857 +        $res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC);
858 +        if (PEAR::isError($res)) {
859 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
860 +            return -1;
861 +        }
862 +        foreach ($res as $row) {
863 +            self::reorderUserIssues($row["isu_usr_id"], $issue_id, $neworder);
864 +        }
865 +    }
866 +    
867  }
868 --- eventum-2.2/templates/header.tpl.html       2009-09-14 18:07:55.000000000 +0300
869 +++ eventum-2.2-order/templates/header.tpl.html 2009-10-12 22:10:36.435851675 +0300
870 @@ -8,6 +8,7 @@
871  <script type="text/javascript" src="{$rel_url}js/jquery/form.js?c=9984"></script>
872  <script type="text/javascript" src="{$rel_url}js/jquery/blockui.js?c=eb13"></script>
873  <script type="text/javascript" src="{$rel_url}js/jquery/ui.datepicker.js?c=a911"></script>
874 +<script type="text/javascript" src="{$rel_url}js/jquery/jquery.tablednd.js"></script>
875  <link rel="stylesheet" href="{$rel_url}js/jquery/ui.datepicker.css?c=5096">
876  <script type="text/javascript">
877  <!--
878 --- eventum-2.2/templates/list.tpl.html 2009-09-14 18:07:55.000000000 +0300
879 +++ eventum-2.2-order/templates/list.tpl.html   2009-10-12 22:10:36.439185157 +0300
880 @@ -92,6 +92,28 @@
881      f.target = '_popup';
882      f.submit();
883  }
884 +function reorderBulk(order_user, neworder)
885 +{
886 +    url = page_url + "?";
887 +    url += "reorder_user=" + order_user;
888 +
889 +    items = document.getElementsByName("item[]");
890 +    checkedcount = 0;
891 +    for (var i = 0; i < items.length; i++) {
892 +      if (items[i].checked) {
893 +        url += "&reorder_source[" + checkedcount + "]=" + items[i].value;
894 +        checkedcount++;
895 +      }
896 +    }
897 +    if (checkedcount == 0) {
898 +        alert('{/literal}{t escape=js}Please choose which issues to move to the new place.{/t}{literal}');
899 +        return false;
900 +    }
901 +
902 +    url += "&reorder_neworder=" + neworder;
903 +    
904 +    window.location.href = url;
905 +}
906  function hideClosed(f)
907  {
908      if (f.hide_closed.checked) {
909 @@ -153,6 +175,13 @@
910          f.go.disabled = true;
911      }
912  }
913 +function updateCustomFields(issue_id)
914 +{
915 +    var features = 'width=560,height=460,top=30,left=30,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no';
916 +    var customWin = window.open('custom_fields.php?issue_id=' + issue_id, '_custom_fields', features);
917 +    customWin.focus();
918 +    return false;
919 +}
920  //-->
921  </script>
922  {/literal}
923 @@ -169,11 +198,11 @@
924    <input type="hidden" name="cat" value="bulk_update">
925    <tr>
926      <td>
927 -      <table bgcolor="#FFFFFF" width="100%" cellspacing="1" cellpadding="2" border="0">
928 -        <tr>
929 +      <table bgcolor="#FFFFFF" width="100%" cellspacing="1" cellpadding="2" border="0" id="issue_list_table">
930 +        <tr class="nodrag">
931            <td colspan="{$col_count}" class="default">
932              <table width="100%" cellspacing="0" cellpadding="0" border="0">
933 -              <tr>
934 +              <tr class="nodrag">
935                  <td class="default">
936                    <b>{t}Search Results{/t} ({$list_info.total_rows} {t}issues found{/t}{if $list_info.end_offset > 0}, {math equation="x + 1" x=$list_info.start_offset} - {$list_info.end_offset} {t}shown{/t}{/if})</b>
937                    {include file="help_link.tpl.html" topic="list"}
938 @@ -193,7 +222,7 @@
939              </table>
940            </td>
941          </tr>
942 -        <tr bgcolor="{$cell_color}">
943 +        <tr bgcolor="{$cell_color}" class="nodrag">
944            {if $current_role > $roles.developer}
945            <td width="1%">
946              <input type="button" value="{t}All{/t}" class="shortcut" onClick="javascript:toggleSelectAll(this.form, 'item[]');toggleBulkUpdate();">
947 @@ -208,7 +237,7 @@
948                    {if $sorting.images[$fld_name_id] != ""}<a title="{t}sort by{/t} {$fld_title|escape:"html"}" href="{$sorting.links[$fld_name_id]}" class="white_link"><img border="0" src="{$sorting.images[$fld_name_id]}"></a>{/if}
949                  </td>
950                {/foreach}
951 -          {else}
952 +          {elseif $field_name != 'isu_order' || $isu_order_user}
953            <td align="{$column.align|default:'center'}" class="default_white" nowrap {if $column.width != ''}width="{$column.width}"{/if}>
954              {if $field_name == 'iss_summary'}
955              <table cellspacing="0" cellpadding="1" width="100%">
956 @@ -268,8 +268,9 @@
957            {/if}
958            {/foreach}
959          </tr>
960 +        <tbody>
961          {section name="i" loop=$list}
962 -        <tr {if $current_role >= $roles.developer AND $list[i].iqu_status > 0}style="text-decoration: line-through;"{/if}>
963 +        <tr {if $current_role >= $roles.developer AND $list[i].iqu_status > 0}style="text-decoration: line-through;"{/if} id="{$list[i].iss_id}" {if !$list[i].assigned_users_order[$current_user_id]}class="nodrag"{/if}>
964            {if $current_role > $roles.developer}
965            <td bgcolor="{$list[i].status_color}" width="1%" class="default" align="center"><input type="checkbox" name="item[]" value="{$list[i].iss_id}" onchange="toggleBulkUpdate();"></td>
966            {/if}
967 @@ -280,8 +281,8 @@
968                    {$fld_value|formatCustomValue:$fld_id:$list[i].iss_id}
969                  </td>
970                {/foreach}
971 -          {else}
972 -          <td bgcolor="{$list[i].status_color}" align="{$column.align|default:'center'}" class="default">
973 +          {elseif $field_name != 'isu_order' || $isu_order_user}
974 +          <td bgcolor="{$list[i].status_color}" align="{$column.align|default:'center'}" class="default{if $field_name == 'isu_order'} dragHandle{/if}">
975              {if $field_name == 'iss_id'}
976                <a href="view.php?id={$list[i].iss_id}" class="link" title="{t}view issue details{/t}">{$list[i].iss_id}</a>
977              {elseif $field_name == 'pri_rank'}
978 @@ -288,6 +318,8 @@
979                {if $list[i].iss_private == 1}
980                    <b>[Private]</b>
981                {/if}
982 +            {elseif $field_name == 'isu_order'}
983 +              {if $options.sort_by == "isu_order" and $current_user_id == $isu_order_user}&nbsp;{/if}
984              {/if}
985            </td>
986            {/if}
987 @@ -300,10 +332,11 @@
988            </td>
989          </tr>
990          {/section}
991 -        <tr bgcolor="{$cell_color}">
992 +        </tbody>
993 +        <tr bgcolor="{$cell_color}" class="nodrag">
994            <td colspan="{$col_count}">
995              <table width="100%" cellspacing="0" cellpadding="0">
996 -              <tr>
997 +              <tr class="nodrag">
998                  <td width="30%" nowrap>
999                    {if $current_role > $roles.developer}
1000                    <input type="button" value="{t}All{/t}" class="shortcut" onClick="javascript:toggleSelectAll(this.form, 'item[]');">
1001 @@ -355,6 +388,35 @@
1002    </form>
1003  </table>
1004  <br />
1005 -
1006 +<script type="text/javascript">
1007 +{*
1008 + * Order issues by drag and drop:
1009 + * only if sorted by order and viewing your own issues
1010 + *}
1011 +{if $options.sort_by == "isu_order" and $current_user_id == $isu_order_user}
1012 +{literal}
1013 +var before = ''; // make it global variable
1014 +$('#issue_list_table').tableDnD({
1015 +    onDragClass: "tDnD_whileDrag",
1016 +    onDragStart: function(table, row) {
1017 +        before = $.tableDnD.serialize('id');
1018 +    },
1019 +    onDrop: function(table, row) {
1020 +        $.post("/ajax/order.php", {before: before, after: $.tableDnD.serialize('id')}, function(data) {
1021 +                if (data.length > 0) {
1022 +                alert(data);
1023 +            }
1024 +        }, "text");
1025 +    },
1026 +       dragHandle: "dragHandle"
1027 +});
1028 +$("#issue_list_table tr").hover(function() {
1029 +    $('#' + this.id + ' .dragHandle').addClass('showDragHandle');
1030 +}, function() {
1031 +    $('#' + this.id + ' .dragHandle').removeClass('showDragHandle');
1032 +});
1033 +{/literal}
1034 +{/if}
1035 +</script>
1036  {include file="app_info.tpl.html"}
1037  {include file="footer.tpl.html"}
This page took 0.339328 seconds and 4 git commands to generate.