]> git.pld-linux.org Git - packages/eventum.git/blob - eventum-order.patch
- updated (2011-04-20)
[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.3.1/htdocs/list.php~      2011-04-20 17:37:25.000000000 +0300
485 +++ eventum-2.3.1/htdocs/list.php       2011-04-20 17:40:51.675898467 +0300
486 @@ -67,6 +67,11 @@
487      }
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 = Search::saveSearchParams();
496  $tpl->assign("options", $options);
497  $tpl->assign("sorting", Search::getSortingInfo($options));
498 @@ -92,6 +97,24 @@
499  }
500  $assign_options += $users;
501  
502 +// get the isu_order (assigned 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 +
516 +if (isset($isu_order_user)) {
517 +    $tpl->assign("isu_order_user", $isu_order_user);
518 +}
519 +
520  $list = Search::getListing($prj_id, $options, $pagerRow, $rows);
521  $tpl->assign("list", $list["list"]);
522  $tpl->assign("list_info", $list["info"]);
523 --- eventum-2.2/lib/eventum/class.display_column.php    2009-09-14 18:07:55.000000000 +0300
524 +++ eventum-2.2-order/lib/eventum/class.display_column.php      2009-10-12 22:10:36.429185594 +0300
525 @@ -230,7 +230,10 @@
526                  ),
527                  "iss_expected_resolution_date"  =>  array(
528                      "title" =>  ev_gettext("Expected Resolution Date")
529 -                )
530 +                ),
531 +                "isu_order" => array(
532 +                    "title" => ev_gettext("Order")
533 +                ),
534              )
535          );
536          return $columns[$page];
537 --- eventum-2.2/lib/eventum/class.issue.php     2009-09-14 18:07:55.000000000 +0300
538 +++ eventum-2.2-order/lib/eventum/class.issue.php       2009-10-12 22:10:36.445851670 +0300
539 @@ -1333,6 +1333,7 @@
540              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
541              return -1;
542          } else {
543 +            self::moveOrderForAllUsers($issue_id, 1000);
544              $prj_id = self::getProjectID($issue_id);
545  
546              // record the change
547 @@ -1800,16 +1801,33 @@
548      {
549          $issue_id = Misc::escapeInteger($issue_id);
550          $assignee_usr_id = Misc::escapeInteger($assignee_usr_id);
551 +        $order = 1;
552 +        // move all orders down to free "order space" for this new association
553 +        $stmt = "UPDATE 
554 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
555 +                 SET
556 +                    isu_order = isu_order + 1
557 +                 WHERE
558 +                    isu_usr_id = $assignee_usr_id AND
559 +                    isu_order >= $order";
560 +        $res = DB_Helper::getInstance()->query($stmt);
561 +        if (PEAR::isError($res)) {
562 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
563 +            return -1;
564 +        }
565 +        // insert the new association
566          $stmt = "INSERT INTO
567                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
568                   (
569                      isu_iss_id,
570                      isu_usr_id,
571 -                    isu_assigned_date
572 +                    isu_assigned_date,
573 +                    isu_order
574                   ) VALUES (
575                      $issue_id,
576                      $assignee_usr_id,
577 -                    '" . Date_Helper::getCurrentDateGMT() . "'
578 +                    '" . Date_Helper::getCurrentDateGMT() . "',
579 +                    $order
580                   )";
581          $res = DB_Helper::getInstance()->query($stmt);
582          if (PEAR::isError($res)) {
583 @@ -1824,6 +1842,78 @@
584          }
585      }
586  
587 +    /**
588 +     * Method used to get the order list to be rearranged
589 +     * 
590 +     * @access  private
591 +     * @param   string $issue_id The issue ID or a comma seperated list of IDs already prepared for giving to mysql
592 +     * @param   string $usr_id The user to remove. When not specified, all users are taken as to be removed for that issue
593 +     * @return  mixed delete order list to be rearranged. Used as a parameter to the method of rearranging the order.
594 +     */
595 +    function getDeleteUserAssociationOrderList($issue_id, $usr_id = "")
596 +    {
597 +        // find all affected associantion orders
598 +        $stmt = "SELECT isu_usr_id, isu_order FROM
599 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
600 +                 WHERE
601 +                 isu_iss_id IN ($issue_id)";
602 +        if (!empty($usr_id)) {
603 +            $stmt.= " AND isu_usr_id IN ($usr_id)";
604 +        }
605 +        $stmt.= "ORDER BY isu_order";
606 +        $res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC);
607 +        if (PEAR::isError($res)) {
608 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
609 +            return -1;
610 +        } else {
611 +            $deleted_orders = array();
612 +            foreach ($res as $row) {
613 +                if (empty($deleted_orders[$row['isu_usr_id']])) {
614 +                    $deleted_orders[$row['isu_usr_id']] = array();
615 +                }
616 +                $deleted_orders[$row['isu_usr_id']] [] = $row['isu_order'];
617 +            }
618 +            return $deleted_orders;
619 +        }
620 +    }
621 +
622 +    /**
623 +     *
624 +     * Method used to rearrange order list in the db according to known deleted records
625 +     *
626 +     * @access  private
627 +     * @param   mixed  deleteorder list
628 +     * @return void
629 +     */
630 +    function rearrangeDeleteUserAssociationOrderList($delete_order_list)
631 +    {
632 +        if (empty($delete_order_list) || (!is_array($delete_order_list))) {
633 +            return -1;
634 +        }
635 +        foreach ($delete_order_list as $isu_usr_id => $orders) {
636 +            for ($i = 0; $i < count($orders); $i++) { // traverse all deleted orders
637 +                // move the orders after them up to take the "order space" of the deleted records
638 +                $stmt = "UPDATE
639 +                            " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
640 +                         SET
641 +                            isu_order = isu_order - " . ($i+1) . "
642 +                         WHERE
643 +                            isu_usr_id = $isu_usr_id AND
644 +                            isu_order > " . $orders[$i];
645 +                if ($i < count($orders) - 1) {
646 +                    $stmt.=  " AND
647 +                            isu_order < " . $orders[$i+1];
648 +                }
649 +                $res = DB_Helper::getInstance()->query($stmt);
650 +                if (PEAR::isError($res)) {
651 +                    Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
652 +                    return -1;
653 +                }
654 +            }
655 +        }
656 +        return 1;
657 +    }
658 +
659  
660      /**
661       * Method used to delete all user assignments for a specific issue.
662 @@ -1839,6 +1929,7 @@
663          if (is_array($issue_id)) {
664              $issue_id = implode(", ", $issue_id);
665          }
666 +        $deleted_order_list = self::getDeleteUserAssociationOrderList($issue_id);
667          $stmt = "DELETE FROM
668                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
669                   WHERE
670 @@ -1869,6 +1960,7 @@
671      {
672          $issue_id = Misc::escapeInteger($issue_id);
673          $usr_id = Misc::escapeInteger($usr_id);
674 +        $delete_order_list = self::getDeleteUserAssociationOrderList($issue_id, $usr_id);
675          $stmt = "DELETE FROM
676                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
677                   WHERE
678 @@ -1883,6 +1975,7 @@
679                  History::add($issue_id, Auth::getUserID(), History::getTypeID('user_unassociated'),
680                      User::getFullName($usr_id) . ' removed from issue by ' . User::getFullName(Auth::getUserID()));
681              }
682 +            self::rearrangeDeleteUserAssociationOrderList($delete_order_list);
683              return 1;
684          }
685      }
686 @@ -3253,6 +3352,8 @@
687          $ids = implode(", ", $ids);
688          $stmt = "SELECT
689                      isu_iss_id,
690 +                    isu_order,
691 +                    isu_usr_id,
692                      usr_full_name
693                   FROM
694                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,
695 @@ -3264,6 +3365,7 @@
696          if (PEAR::isError($res)) {
697              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
698          } else {
699 +            // gather names of the users assigned to each issue
700              $t = array();
701              for ($i = 0; $i < count($res); $i++) {
702                  if (!empty($t[$res[$i]['isu_iss_id']])) {
703 @@ -3272,9 +3374,18 @@
704                      $t[$res[$i]['isu_iss_id']] = $res[$i]['usr_full_name'];
705                  }
706              }
707 +            // gather orders
708 +            $o = array();
709 +            for ($i = 0; $i < count($res); $i++) {
710 +                if (empty($o[$res[$i]['isu_iss_id']])) {
711 +                    $o[$res[$i]['isu_iss_id']] = array();
712 +                }
713 +                $o[$res[$i]['isu_iss_id']][$res[$i]['isu_usr_id']] = $res[$i]['isu_order'];
714 +            }
715              // now populate the $result variable again
716              for ($i = 0; $i < count($result); $i++) {
717                  @$result[$i]['assigned_users'] = $t[$result[$i]['iss_id']];
718 +                @$result[$i]['assigned_users_order'] = $o[$result[$i]['iss_id']];
719              }
720          }
721      }
722 @@ -4247,6 +4358,7 @@
723              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
724              return -1;
725          }
726 +        self::moveOrderForAllUsers($issue_id, 1);
727      }
728  
729  
730 @@ -4346,4 +4458,120 @@
731          History::add($issue_id, Auth::getUserID(), History::getTypeID('user_associated'),
732                          "Issue assignment to changed (" . History::formatChanges(join(', ', $old_assignee_names), join(', ', $assignee_names)) . ") by " . User::getFullName(Auth::getUserID()));
733      }
734 +
735 +    /**
736 +     * Reorders user's issues as requested by user
737 +     * @access public
738 +     * @param $usr_id User to be reordered
739 +     * @param $issue_id Issue or array of issues to be moved
740 +     * @param $neworder The new order of the issues
741 +     * @return void
742 +     */
743 +    function reorderUserIssues($usr_id, $issue_id, $neworder)
744 +    {
745 +        if (!isset($usr_id) || !isset($issue_id) || !isset($neworder)) {
746 +            return false;
747 +        }
748 +        if (!is_numeric($usr_id) || !is_numeric($neworder)) {
749 +            return false;
750 +        }
751 +        $usr_id = Misc::escapeInteger($usr_id);
752 +        $issue_id = Misc::escapeInteger($issue_id);
753 +        $neworder = Misc::escapeInteger($neworder);
754 +        if (is_array($issue_id)) {
755 +            $issue_count = count($issue_id);
756 +            $issue_id_str = implode(", ", $issue_id);
757 +        } else {
758 +            $issue_count = 1;
759 +            $issue_id_str = $issue_id;
760 +            $issue_id = array($issue_id);
761 +        }
762 +        // do a nasty pretending to be deleting stuff so that reordering happens as if these elements were deleted
763 +        $orderlist = self::getDeleteUserAssociationOrderList($issue_id_str, $usr_id);
764 +        self::rearrangeDeleteUserAssociationOrderList($orderlist);
765 +        // move down the orders to free the "order space" needed
766 +        $stmt = "UPDATE 
767 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
768 +                 SET
769 +                    isu_order = isu_order + $issue_count
770 +                 WHERE
771 +                    isu_usr_id = $usr_id AND
772 +                    isu_order >= $neworder";
773 +        $res = DB_Helper::getInstance()->query($stmt);
774 +        if (PEAR::isError($res)) {
775 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
776 +            return -1;
777 +        }
778 +        //update the order for the issues being moved
779 +        $i = 0;
780 +        foreach ($issue_id as $iss_id) {
781 +            $stmt = "UPDATE
782 +                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
783 +                     SET
784 +                        isu_order = " . ($neworder + $i) . "
785 +                     WHERE
786 +                        isu_usr_id = $usr_id AND
787 +                        isu_iss_id = $iss_id";
788 +            $res = DB_Helper::getInstance()->query($stmt);
789 +            if (PEAR::isError($res)) {
790 +                Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
791 +                return -1;
792 +            }
793 +            $i++;
794 +        }
795 +    }
796 +
797 +
798 +    /**
799 +     * Get users issue order list
800 +     * @access public
801 +     * @param $user_id User
802 +     * @param $order_list Order of the issues
803 +     * @return void
804 +     */
805 +    function getIssueOrderByUser($usr_id) {
806 +
807 +        if (!is_numeric($usr_id)) {
808 +            return false;
809 +        }
810 +
811 +        $stmt = "SELECT
812 +                    isu_iss_id, isu_order
813 +                FROM
814 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
815 +                WHERE
816 +                    isu_usr_id = " . $usr_id ;
817 +
818 +        $order_list = array();
819 +
820 +        $res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC);
821 +
822 +        if (PEAR::isError($res)) {
823 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
824 +            return array();
825 +        } else {
826 +            foreach ($res as $row) {
827 +                $order_list[$row["isu_iss_id"]] = $row["isu_order"];
828 +            }
829 +        }
830 +        return $order_list;
831 +    }
832 +
833 +    function moveOrderForAllUsers($issue_id, $neworder)
834 +    {
835 +        // Move the issue to the top priority for the ppl it's assigned to
836 +        $stmt = "SELECT isu_usr_id FROM
837 +                    "  . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
838 +                 WHERE
839 +                    isu_iss_id = " . Misc::escapeInteger($issue_id);
840 +        $res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC);
841 +        if (PEAR::isError($res)) {
842 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
843 +            return -1;
844 +        }
845 +        foreach ($res as $row) {
846 +            self::reorderUserIssues($row["isu_usr_id"], $issue_id, $neworder);
847 +        }
848 +    }
849 +    
850  }
851 --- eventum-2.3.1/lib/eventum/class.search.php~ 2011-04-20 17:22:15.000000000 +0300
852 +++ eventum-2.3.1/lib/eventum/class.search.php  2011-04-20 17:44:34.498519260 +0300
853 @@ -63,6 +63,12 @@
854      {
855          $sort_by = self::getParam('sort_by');
856          $sort_order = self::getParam('sort_order');
857 +        $users = self::getParam('users');
858 +        if (empty($users) && $sort_by === 'isu_order') {
859 +            // Sorting by isu_order is impossible when no user specified
860 +            unset($sort_by);
861 +            unset($sort_order);
862 +        }
863          $rows = self::getParam('rows');
864          $hide_closed = self::getParam('hide_closed');
865          if ($hide_closed === '') {
866 @@ -174,6 +174,7 @@
867              "iss_expected_resolution_date" => "desc",
868              "pre_title" => "asc",
869              "assigned" => "asc",
870 +            "isu_order" => "desc",
871          );
872  
873          foreach ($custom_fields as $fld_id => $fld_name) {
874 --- eventum-2.3/templates/header.tpl.html~      2010-09-27 18:12:42.000000000 +0300
875 +++ eventum-2.3/templates/header.tpl.html       2010-09-27 18:13:08.884494665 +0300
876 @@ -18,6 +18,7 @@
877  <script type="text/javascript" src="{$rel_url}js/jquery/form.js?c=9984"></script>
878  <script type="text/javascript" src="{$rel_url}js/jquery/blockui.js?c=eb13"></script>
879  <script type="text/javascript" src="{$rel_url}js/jquery/ui.datepicker.js?c=a911"></script>
880 +<script type="text/javascript" src="{$rel_url}js/jquery/jquery.tablednd.js"></script>
881  <script type="text/javascript" src="{$rel_url}js/validation.js?c=9775"></script>
882  <script type="text/javascript" src="{$rel_url}js/browserSniffer.js?c=c046"></script>
883  <script type="text/javascript" src="{$rel_url}js/global.js?c=5297"></script>
884 --- eventum-2.2/templates/list.tpl.html 2009-09-14 18:07:55.000000000 +0300
885 +++ eventum-2.2-order/templates/list.tpl.html   2009-10-12 22:10:36.439185157 +0300
886 @@ -92,6 +92,28 @@
887      f.target = '_popup';
888      f.submit();
889  }
890 +function reorderBulk(order_user, neworder)
891 +{
892 +    url = page_url + "?";
893 +    url += "reorder_user=" + order_user;
894 +
895 +    items = document.getElementsByName("item[]");
896 +    checkedcount = 0;
897 +    for (var i = 0; i < items.length; i++) {
898 +      if (items[i].checked) {
899 +        url += "&reorder_source[" + checkedcount + "]=" + items[i].value;
900 +        checkedcount++;
901 +      }
902 +    }
903 +    if (checkedcount == 0) {
904 +        alert('{/literal}{t escape=js}Please choose which issues to move to the new place.{/t}{literal}');
905 +        return false;
906 +    }
907 +
908 +    url += "&reorder_neworder=" + neworder;
909 +    
910 +    window.location.href = url;
911 +}
912  function hideClosed(f)
913  {
914      if (f.hide_closed.checked) {
915 @@ -153,6 +175,13 @@
916          f.go.disabled = true;
917      }
918  }
919 +function updateCustomFields(issue_id)
920 +{
921 +    var features = 'width=560,height=460,top=30,left=30,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no';
922 +    var customWin = window.open('custom_fields.php?issue_id=' + issue_id, '_custom_fields', features);
923 +    customWin.focus();
924 +    return false;
925 +}
926  //-->
927  </script>
928  {/literal}
929 @@ -169,11 +198,11 @@
930    <input type="hidden" name="cat" value="bulk_update">
931    <tr>
932      <td>
933 -      <table bgcolor="#FFFFFF" width="100%" cellspacing="1" cellpadding="2" border="0">
934 -        <tr>
935 +      <table bgcolor="#FFFFFF" width="100%" cellspacing="1" cellpadding="2" border="0" id="issue_list_table">
936 +        <tr class="nodrag">
937            <td colspan="{$col_count}" class="default">
938              <table width="100%" cellspacing="0" cellpadding="0" border="0">
939 -              <tr>
940 +              <tr class="nodrag">
941                  <td class="default">
942                    <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>
943                    {include file="help_link.tpl.html" topic="list"}
944 @@ -193,7 +222,7 @@
945              </table>
946            </td>
947          </tr>
948 -        <tr bgcolor="{$cell_color}">
949 +        <tr bgcolor="{$cell_color}" class="nodrag">
950            {if $current_role > $roles.developer}
951            <td width="1%">
952              <input type="button" value="{t}All{/t}" class="shortcut" onClick="javascript:toggleSelectAll(this.form, 'item[]');toggleBulkUpdate();">
953 @@ -208,7 +237,7 @@
954                    {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}
955                  </td>
956                {/foreach}
957 -          {else}
958 +          {elseif $field_name != 'isu_order' || $isu_order_user}
959            <td align="{$column.align|default:'center'}" class="default_white" nowrap {if $column.width != ''}width="{$column.width}"{/if}>
960              {if $field_name == 'iss_summary'}
961              <table cellspacing="0" cellpadding="1" width="100%">
962 @@ -268,8 +268,9 @@
963            {/if}
964            {/foreach}
965          </tr>
966 +        <tbody>
967          {section name="i" loop=$list}
968 -        <tr {if $current_role >= $roles.developer AND $list[i].iqu_status > 0}style="text-decoration: line-through;"{/if}>
969 +        <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}>
970            {if $current_role > $roles.developer}
971            <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>
972            {/if}
973 @@ -280,8 +281,8 @@
974                    {$fld_value|formatCustomValue:$fld_id:$list[i].iss_id}
975                  </td>
976                {/foreach}
977 -          {else}
978 -          <td bgcolor="{$list[i].status_color}" align="{$column.align|default:'center'}" class="default">
979 +          {elseif $field_name != 'isu_order' || $isu_order_user}
980 +          <td bgcolor="{$list[i].status_color}" align="{$column.align|default:'center'}" class="default{if $field_name == 'isu_order'} dragHandle{/if}">
981              {if $field_name == 'iss_id'}
982                <a href="view.php?id={$list[i].iss_id}" class="link" title="{t}view issue details{/t}">{$list[i].iss_id}</a>
983              {elseif $field_name == 'pri_rank'}
984 @@ -288,6 +318,8 @@
985                {if $list[i].iss_private == 1}
986                    <b>[Private]</b>
987                {/if}
988 +            {elseif $field_name == 'isu_order'}
989 +              {if $options.sort_by == "isu_order" and $current_user_id == $isu_order_user}&nbsp;{/if}
990              {/if}
991            </td>
992            {/if}
993 @@ -300,10 +332,11 @@
994            </td>
995          </tr>
996          {/section}
997 -        <tr bgcolor="{$cell_color}">
998 +        </tbody>
999 +        <tr bgcolor="{$cell_color}" class="nodrag">
1000            <td colspan="{$col_count}">
1001              <table width="100%" cellspacing="0" cellpadding="0">
1002 -              <tr>
1003 +              <tr class="nodrag">
1004                  <td width="30%" nowrap>
1005                    {if $current_role > $roles.developer}
1006                    <input type="button" value="{t}All{/t}" class="shortcut" onClick="javascript:toggleSelectAll(this.form, 'item[]');">
1007 @@ -355,6 +388,35 @@
1008    </form>
1009  </table>
1010  <br />
1011 -
1012 +<script type="text/javascript">
1013 +{*
1014 + * Order issues by drag and drop:
1015 + * only if sorted by order and viewing your own issues
1016 + *}
1017 +{if $options.sort_by == "isu_order" and $current_user_id == $isu_order_user}
1018 +{literal}
1019 +var before = ''; // make it global variable
1020 +$('#issue_list_table').tableDnD({
1021 +    onDragClass: "tDnD_whileDrag",
1022 +    onDragStart: function(table, row) {
1023 +        before = $.tableDnD.serialize('id');
1024 +    },
1025 +    onDrop: function(table, row) {
1026 +        $.post("/ajax/order.php", {before: before, after: $.tableDnD.serialize('id')}, function(data) {
1027 +                if (data.length > 0) {
1028 +                alert(data);
1029 +            }
1030 +        }, "text");
1031 +    },
1032 +       dragHandle: "dragHandle"
1033 +});
1034 +$("#issue_list_table tr").hover(function() {
1035 +    $('#' + this.id + ' .dragHandle').addClass('showDragHandle');
1036 +}, function() {
1037 +    $('#' + this.id + ' .dragHandle').removeClass('showDragHandle');
1038 +});
1039 +{/literal}
1040 +{/if}
1041 +</script>
1042  {include file="app_info.tpl.html"}
1043  {include file="footer.tpl.html"}
This page took 0.1825 seconds and 4 git commands to generate.