Ctrl-Click not working with Organize [with a partial investigation]

mikeage
mikeage's picture

Joined: 2005-01-23
Posts: 138
Posted: Tue, 2013-01-08 14:45

As has been reported in several threads (e.g., http://gallery.menalto.com/node/108422 and http://gallery.menalto.com/node/108101; there was also http://gallery.menalto.com/node/93508, though that was a different bug that was actually fixed (but predates, as near as I can tell from git's history, the offending line I highlight below), the organize module supports shift-clicking to extend the selection, but not ctrl-clicking to add a single item.

Having looked at it in Chrome's debugger, I can see exactly why, but I'm not sure I know how to fix it.

I added a console.error message to

Ext.DataView = Ext.extend(Ext.BoxComponent, {selectedClass: "x-view-selected",emptyText: "",deferEmptyText: true,trackOver: false,blockRefresh: false,last: false,initComponent: function() {
    ...
    },onItemClick: function(item, index, e) {
        if (this.fireEvent("beforeclick", this, index, item, e) === false) {
            return false;
        }
        if (this.multiSelect) {
===>        console.error("doMultiSelection"); <===
            this.doMultiSelection(item, index, e);
            e.preventDefault();

I see that this function is called twice on control click with the following call stacks (the lines are from the pretty printed version):

doMultiSelection ext-organize-bundle.js:12814
Ext.DataView.Ext.extend.onItemClick ext-organize-bundle.js:12814
Ext.DataView.Ext.extend.onClick ext-organize-bundle.js:12772
v.dragZone.Ext.dd.DragZone.getDragData 8:170
Ext.extend.handleMouseDown ext-organize-bundle.js:20108
h ext-organize-bundle.js:4246

And

doMultiSelection ext-organize-bundle.js:12814
Ext.DataView.Ext.extend.onItemClick ext-organize-bundle.js:12814
Ext.DataView.Ext.extend.onClick ext-organize-bundle.js:12772
h ext-organize-bundle.js:4246

The two calls to doMultiSelection contain the following:

    },doMultiSelection: function(item, index, e) {
        if (e.shiftKey && this.last !== false) {
            var last = this.last;
            this.selectRange(last, index, e.ctrlKey);
            this.last = last;
        } else {
            if ((e.ctrlKey || this.simpleSelect) && this.isSelected(index)) {
                this.deselect(index);
            } else {
                this.select(index, e.ctrlKey || e.shiftKey || this.simpleSelect);
            }
        }
    },getSelectionCount: function() {

The first one fails this.isSelected(index) and calls this.select; the second passes and so it calls this.deselect(). This is also clear in the UI, where while holding down the mouse the image is highlighted, but once the button is released, the highlight disappears.

The second call (which actually occurs on mouse up) is due to views/organize_frame.html.php:170, which reads


if (!v.isSelected(target)) {
    v.onClick(e);
}

If I comment out the call to v.onClick(e), Ctrl works to highlight multiple images!

However, it breaks drag and drop rearranging; I get the following in my log file, and the page returns a 500:

2013-01-08 13:59:54 +02:00 --- error: ORM_Validation_Exception [ 44 ]: ORM Validation has failed for items model
/var/www/testing/gallery3/system/libraries/ORM_Validation_Exception.php [ 20 ]
#0 /var/www/testing/gallery3/system/libraries/ORM.php(755): ORM_Validation_Exception_Core::handle_validation('items', Object(Validation))
#1 /var/www/testing/gallery3-contrib/3.0/modules/videos/models/item.php(740): ORM_Core->validate(NULL)
#2 /var/www/testing/gallery3/system/libraries/ORM.php(778): Item_Model_Core->validate()
#3 /var/www/testing/gallery3/modules/gallery/libraries/MY_ORM.php(34): ORM_Core->save()
#4 /var/www/testing/gallery3/modules/gallery/libraries/ORM_MPTT.php(76): ORM->save()
#5 /var/www/testing/gallery3-contrib/3.0/modules/videos/models/item.php(369): ORM_MPTT_Core->save()
#6 /var/www/testing/gallery3/modules/organize/controllers/organize.php(163): Item_Model_Core->save()
#7 [internal function]: Organize_Controller->rearrange()
#8 /var/www/testing/gallery3/system/core/Kohana.php(331): ReflectionMethod->invokeArgs(Object(Organize_Controller), Array)
#9 [internal function]: Kohana_Core::instance(NULL)
#10 /var/www/testing/gallery3/system/core/Event.php(208): call_user_func_array(Array, Array)
#11 /var/www/testing/gallery3/application/Bootstrap.php(67): Event_Core::run('system.execute')
#12 /var/www/testing/gallery3/index.php(116): require('/var/www/testin...')
#13 {main}
2013-01-08 13:59:54 +02:00 --- error: Validation errors: Array
(
    [name] => required
    [title] => required
    [type] => invalid
)

This is as far as I can go right now; I don't really understand why this call is there or how the whole drag-and-drop logic fits together.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sat, 2013-02-02 21:52
 
mikeage
mikeage's picture

Joined: 2005-01-23
Posts: 138
Posted: Sun, 2013-02-03 04:04

Thanks, I saw! https://sourceforge.net/mailarchive/message.php?msg_id=30429264

I meant to come back and comment here as well, as it seems others were affected by this also. Oops.