]> git.pld-linux.org Git - packages/eventum.git/blob - eventum-order.patch
- up to bzr 4155
[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,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 = Issue::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 @@ -2342,6 +2435,11 @@
687      {
688          $sort_by = self::getParam('sort_by');
689          $sort_order = self::getParam('sort_order');
690 +        $users = self::getParam('users');
691 +        if (empty($users) && ($sort_by == 'isu_order')) { // Sorting by isu_order is impossible when no user specified
692 +            unset($sort_by);
693 +            unset($sort_order);
694 +        }
695          $rows = self::getParam('rows');
696          $hide_closed = self::getParam('hide_closed');
697          if ($hide_closed === '') {
698 @@ -2448,6 +2546,7 @@
699              "iss_expected_resolution_date" => "desc",
700              "pre_title" => "asc",
701              "assigned" => "asc",
702 +            "isu_order" => "desc",
703          );
704  
705          foreach ($custom_fields as $fld_id => $fld_name) {
706 @@ -3253,6 +3352,8 @@
707          $ids = implode(", ", $ids);
708          $stmt = "SELECT
709                      isu_iss_id,
710 +                    isu_order,
711 +                    isu_usr_id,
712                      usr_full_name
713                   FROM
714                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,
715 @@ -3264,6 +3365,7 @@
716          if (PEAR::isError($res)) {
717              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
718          } else {
719 +            // gather names of the users assigned to each issue
720              $t = array();
721              for ($i = 0; $i < count($res); $i++) {
722                  if (!empty($t[$res[$i]['isu_iss_id']])) {
723 @@ -3272,9 +3374,18 @@
724                      $t[$res[$i]['isu_iss_id']] = $res[$i]['usr_full_name'];
725                  }
726              }
727 +            // gather orders
728 +            $o = array();
729 +            for ($i = 0; $i < count($res); $i++) {
730 +                if (empty($o[$res[$i]['isu_iss_id']])) {
731 +                    $o[$res[$i]['isu_iss_id']] = array();
732 +                }
733 +                $o[$res[$i]['isu_iss_id']][$res[$i]['isu_usr_id']] = $res[$i]['isu_order'];
734 +            }
735              // now populate the $result variable again
736              for ($i = 0; $i < count($result); $i++) {
737                  @$result[$i]['assigned_users'] = $t[$result[$i]['iss_id']];
738 +                @$result[$i]['assigned_users_order'] = $o[$result[$i]['iss_id']];
739              }
740          }
741      }
742 @@ -4247,6 +4358,7 @@
743              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
744              return -1;
745          }
746 +        self::moveOrderForAllUsers($issue_id, 1);
747      }
748  
749  
750 @@ -4346,4 +4458,120 @@
751          History::add($issue_id, Auth::getUserID(), History::getTypeID('user_associated'),
752                          "Issue assignment to changed (" . History::formatChanges(join(', ', $old_assignee_names), join(', ', $assignee_names)) . ") by " . User::getFullName(Auth::getUserID()));
753      }
754 +
755 +    /**
756 +     * Reorders user's issues as requested by user
757 +     * @access public
758 +     * @param $usr_id User to be reordered
759 +     * @param $issue_id Issue or array of issues to be moved
760 +     * @param $neworder The new order of the issues
761 +     * @return void
762 +     */
763 +    function reorderUserIssues($usr_id, $issue_id, $neworder)
764 +    {
765 +        if (!isset($usr_id) || !isset($issue_id) || !isset($neworder)) {
766 +            return false;
767 +        }
768 +        if (!is_numeric($usr_id) || !is_numeric($neworder)) {
769 +            return false;
770 +        }
771 +        $usr_id = Misc::escapeInteger($usr_id);
772 +        $issue_id = Misc::escapeInteger($issue_id);
773 +        $neworder = Misc::escapeInteger($neworder);
774 +        if (is_array($issue_id)) {
775 +            $issue_count = count($issue_id);
776 +            $issue_id_str = implode(", ", $issue_id);
777 +        } else {
778 +            $issue_count = 1;
779 +            $issue_id_str = $issue_id;
780 +            $issue_id = array($issue_id);
781 +        }
782 +        // do a nasty pretending to be deleting stuff so that reordering happens as if these elements were deleted
783 +        $orderlist = self::getDeleteUserAssociationOrderList($issue_id_str, $usr_id);
784 +        self::rearrangeDeleteUserAssociationOrderList($orderlist);
785 +        // move down the orders to free the "order space" needed
786 +        $stmt = "UPDATE 
787 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
788 +                 SET
789 +                    isu_order = isu_order + $issue_count
790 +                 WHERE
791 +                    isu_usr_id = $usr_id AND
792 +                    isu_order >= $neworder";
793 +        $res = DB_Helper::getInstance()->query($stmt);
794 +        if (PEAR::isError($res)) {
795 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
796 +            return -1;
797 +        }
798 +        //update the order for the issues being moved
799 +        $i = 0;
800 +        foreach ($issue_id as $iss_id) {
801 +            $stmt = "UPDATE
802 +                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
803 +                     SET
804 +                        isu_order = " . ($neworder + $i) . "
805 +                     WHERE
806 +                        isu_usr_id = $usr_id AND
807 +                        isu_iss_id = $iss_id";
808 +            $res = DB_Helper::getInstance()->query($stmt);
809 +            if (PEAR::isError($res)) {
810 +                Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
811 +                return -1;
812 +            }
813 +            $i++;
814 +        }
815 +    }
816 +
817 +
818 +    /**
819 +     * Get users issue order list
820 +     * @access public
821 +     * @param $user_id User
822 +     * @param $order_list Order of the issues
823 +     * @return void
824 +     */
825 +    function getIssueOrderByUser($usr_id) {
826 +
827 +        if (!is_numeric($usr_id)) {
828 +            return false;
829 +        }
830 +
831 +        $stmt = "SELECT
832 +                    isu_iss_id, isu_order
833 +                FROM
834 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
835 +                WHERE
836 +                    isu_usr_id = " . $usr_id ;
837 +
838 +        $order_list = array();
839 +
840 +        $res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC);
841 +
842 +        if (PEAR::isError($res)) {
843 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
844 +            return array();
845 +        } else {
846 +            foreach ($res as $row) {
847 +                $order_list[$row["isu_iss_id"]] = $row["isu_order"];
848 +            }
849 +        }
850 +        return $order_list;
851 +    }
852 +
853 +    function moveOrderForAllUsers($issue_id, $neworder)
854 +    {
855 +        // Move the issue to the top priority for the ppl it's assigned to
856 +        $stmt = "SELECT isu_usr_id FROM
857 +                    "  . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
858 +                 WHERE
859 +                    isu_iss_id = " . Misc::escapeInteger($issue_id);
860 +        $res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC);
861 +        if (PEAR::isError($res)) {
862 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
863 +            return -1;
864 +        }
865 +        foreach ($res as $row) {
866 +            self::reorderUserIssues($row["isu_usr_id"], $issue_id, $neworder);
867 +        }
868 +    }
869 +    
870  }
871 --- eventum-2.3/templates/header.tpl.html~      2010-09-27 18:12:42.000000000 +0300
872 +++ eventum-2.3/templates/header.tpl.html       2010-09-27 18:13:08.884494665 +0300
873 @@ -18,6 +18,7 @@
874  <script type="text/javascript" src="{$rel_url}js/jquery/form.js?c=9984"></script>
875  <script type="text/javascript" src="{$rel_url}js/jquery/blockui.js?c=eb13"></script>
876  <script type="text/javascript" src="{$rel_url}js/jquery/ui.datepicker.js?c=a911"></script>
877 +<script type="text/javascript" src="{$rel_url}js/jquery/jquery.tablednd.js"></script>
878  <script type="text/javascript" src="{$rel_url}js/validation.js?c=9775"></script>
879  <script type="text/javascript" src="{$rel_url}js/browserSniffer.js?c=c046"></script>
880  <script type="text/javascript" src="{$rel_url}js/global.js?c=5297"></script>
881 --- eventum-2.2/templates/list.tpl.html 2009-09-14 18:07:55.000000000 +0300
882 +++ eventum-2.2-order/templates/list.tpl.html   2009-10-12 22:10:36.439185157 +0300
883 @@ -92,6 +92,28 @@
884      f.target = '_popup';
885      f.submit();
886  }
887 +function reorderBulk(order_user, neworder)
888 +{
889 +    url = page_url + "?";
890 +    url += "reorder_user=" + order_user;
891 +
892 +    items = document.getElementsByName("item[]");
893 +    checkedcount = 0;
894 +    for (var i = 0; i < items.length; i++) {
895 +      if (items[i].checked) {
896 +        url += "&reorder_source[" + checkedcount + "]=" + items[i].value;
897 +        checkedcount++;
898 +      }
899 +    }
900 +    if (checkedcount == 0) {
901 +        alert('{/literal}{t escape=js}Please choose which issues to move to the new place.{/t}{literal}');
902 +        return false;
903 +    }
904 +
905 +    url += "&reorder_neworder=" + neworder;
906 +    
907 +    window.location.href = url;
908 +}
909  function hideClosed(f)
910  {
911      if (f.hide_closed.checked) {
912 @@ -153,6 +175,13 @@
913          f.go.disabled = true;
914      }
915  }
916 +function updateCustomFields(issue_id)
917 +{
918 +    var features = 'width=560,height=460,top=30,left=30,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no';
919 +    var customWin = window.open('custom_fields.php?issue_id=' + issue_id, '_custom_fields', features);
920 +    customWin.focus();
921 +    return false;
922 +}
923  //-->
924  </script>
925  {/literal}
926 @@ -169,11 +198,11 @@
927    <input type="hidden" name="cat" value="bulk_update">
928    <tr>
929      <td>
930 -      <table bgcolor="#FFFFFF" width="100%" cellspacing="1" cellpadding="2" border="0">
931 -        <tr>
932 +      <table bgcolor="#FFFFFF" width="100%" cellspacing="1" cellpadding="2" border="0" id="issue_list_table">
933 +        <tr class="nodrag">
934            <td colspan="{$col_count}" class="default">
935              <table width="100%" cellspacing="0" cellpadding="0" border="0">
936 -              <tr>
937 +              <tr class="nodrag">
938                  <td class="default">
939                    <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>
940                    {include file="help_link.tpl.html" topic="list"}
941 @@ -193,7 +222,7 @@
942              </table>
943            </td>
944          </tr>
945 -        <tr bgcolor="{$cell_color}">
946 +        <tr bgcolor="{$cell_color}" class="nodrag">
947            {if $current_role > $roles.developer}
948            <td width="1%">
949              <input type="button" value="{t}All{/t}" class="shortcut" onClick="javascript:toggleSelectAll(this.form, 'item[]');toggleBulkUpdate();">
950 @@ -208,7 +237,7 @@
951                    {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}
952                  </td>
953                {/foreach}
954 -          {else}
955 +          {elseif $field_name != 'isu_order' || $isu_order_user}
956            <td align="{$column.align|default:'center'}" class="default_white" nowrap {if $column.width != ''}width="{$column.width}"{/if}>
957              {if $field_name == 'iss_summary'}
958              <table cellspacing="0" cellpadding="1" width="100%">
959 @@ -268,8 +268,9 @@
960            {/if}
961            {/foreach}
962          </tr>
963 +        <tbody>
964          {section name="i" loop=$list}
965 -        <tr {if $current_role >= $roles.developer AND $list[i].iqu_status > 0}style="text-decoration: line-through;"{/if}>
966 +        <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}>
967            {if $current_role > $roles.developer}
968            <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>
969            {/if}
970 @@ -280,8 +281,8 @@
971                    {$fld_value|formatCustomValue:$fld_id:$list[i].iss_id}
972                  </td>
973                {/foreach}
974 -          {else}
975 -          <td bgcolor="{$list[i].status_color}" align="{$column.align|default:'center'}" class="default">
976 +          {elseif $field_name != 'isu_order' || $isu_order_user}
977 +          <td bgcolor="{$list[i].status_color}" align="{$column.align|default:'center'}" class="default{if $field_name == 'isu_order'} dragHandle{/if}">
978              {if $field_name == 'iss_id'}
979                <a href="view.php?id={$list[i].iss_id}" class="link" title="{t}view issue details{/t}">{$list[i].iss_id}</a>
980              {elseif $field_name == 'pri_rank'}
981 @@ -288,6 +318,8 @@
982                {if $list[i].iss_private == 1}
983                    <b>[Private]</b>
984                {/if}
985 +            {elseif $field_name == 'isu_order'}
986 +              {if $options.sort_by == "isu_order" and $current_user_id == $isu_order_user}&nbsp;{/if}
987              {/if}
988            </td>
989            {/if}
990 @@ -300,10 +332,11 @@
991            </td>
992          </tr>
993          {/section}
994 -        <tr bgcolor="{$cell_color}">
995 +        </tbody>
996 +        <tr bgcolor="{$cell_color}" class="nodrag">
997            <td colspan="{$col_count}">
998              <table width="100%" cellspacing="0" cellpadding="0">
999 -              <tr>
1000 +              <tr class="nodrag">
1001                  <td width="30%" nowrap>
1002                    {if $current_role > $roles.developer}
1003                    <input type="button" value="{t}All{/t}" class="shortcut" onClick="javascript:toggleSelectAll(this.form, 'item[]');">
1004 @@ -355,6 +388,35 @@
1005    </form>
1006  </table>
1007  <br />
1008 -
1009 +<script type="text/javascript">
1010 +{*
1011 + * Order issues by drag and drop:
1012 + * only if sorted by order and viewing your own issues
1013 + *}
1014 +{if $options.sort_by == "isu_order" and $current_user_id == $isu_order_user}
1015 +{literal}
1016 +var before = ''; // make it global variable
1017 +$('#issue_list_table').tableDnD({
1018 +    onDragClass: "tDnD_whileDrag",
1019 +    onDragStart: function(table, row) {
1020 +        before = $.tableDnD.serialize('id');
1021 +    },
1022 +    onDrop: function(table, row) {
1023 +        $.post("/ajax/order.php", {before: before, after: $.tableDnD.serialize('id')}, function(data) {
1024 +                if (data.length > 0) {
1025 +                alert(data);
1026 +            }
1027 +        }, "text");
1028 +    },
1029 +       dragHandle: "dragHandle"
1030 +});
1031 +$("#issue_list_table tr").hover(function() {
1032 +    $('#' + this.id + ' .dragHandle').addClass('showDragHandle');
1033 +}, function() {
1034 +    $('#' + this.id + ' .dragHandle').removeClass('showDragHandle');
1035 +});
1036 +{/literal}
1037 +{/if}
1038 +</script>
1039  {include file="app_info.tpl.html"}
1040  {include file="footer.tpl.html"}
This page took 0.225087 seconds and 4 git commands to generate.