Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drag and drop priority sorting to Netgen Admin UI #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* $Id: admin2pp_dragndrop_children.js 79 2010-03-14 11:19:58Z dpobel $
* $HeadURL: http://svn.projects.ez.no/admin2pp/trunk/extension/admin2pp/design/admin2/javascript/admin2pp_dragndrop_children.js $
*
*/

function admin2ppDragNDropChildren() {
this.sortOrder = 1;
}

admin2ppDragNDropChildren.PRIORITY_OFFSET = 2;
admin2ppDragNDropChildren.TABLE_ID = 'content-sub-items-list > table';

admin2ppDragNDropChildren.prototype = {
init:function() {
var instance = this;
this.sortOrder = subItemsTable.get('sortedBy').dir === 'yui-dt-asc' ? 1 : -1;
jQuery('#' + admin2ppDragNDropChildren.TABLE_ID + ' .yui-dt-data').sortable( {
// Using a custom place holder, because the default one is pushing the table to the left.
placeholder: {
/**
* Function to create the placeholder
*/
element: function(currentItem) {
var tr = $('<tr class="yui-dt-even"><td colspan="' + currentItem.find('> :visible').length + '"><div class="yui-dt-liner">&nbsp;</div></td></tr>');

return tr;
},
update: function(container, p) {
return;
}
},
axis:'y',
opacity:0.8,
items:'> tr',
cursor:'move',
stop:function( evt, ui ) {
instance.fixBackgrounds();
instance.setPriorities();
}
} )
.css( 'cursor', 'move' );
jQuery('#' + admin2ppDragNDropChildren.TABLE_ID + ' .yui-dt-data').disableSelection();
},

setPriorities:function() {
var inputs = jQuery( '#' + admin2ppDragNDropChildren.TABLE_ID + ' .yui-dt0-col-priority > .yui-dt-liner' );
// Fetch the starting point
var start = +inputs.first().text();
var increments = admin2ppDragNDropChildren.PRIORITY_OFFSET * this.sortOrder;
var instance = this;
inputs.each(function() {
jQuery( this ).text( start );
var recordId = jQuery( this ).closest('tr').attr('id');
var record = subItemsTable.getRecordSet().getRecord(recordId);
instance.updatePriority(record, start);
start = start + increments;
});
},

updatePriority: function(record, priority) {
var sortedBy = subItemsTable.get('sortedBy'),
paginator = subItemsTable.get('paginator')
;
record.setData('priority', priority);

jQuery.ez('ezjscnode::updatepriority', {
ContentNodeID: record.getData('parent_node_id'),
ContentObjectID: record.getData('contentobject_id'),
PriorityID: [record.getData('node_id')],
Priority: [priority]
}, onSuccess);

var onSuccess = function(data) {
record.setData('priority', priority);
}
},

fixBackgrounds:function() {
var cssClass = 'yui-dt-odd';
jQuery('#' + admin2ppDragNDropChildren.TABLE_ID + ' tbody tr').each(function() {
var $this = jQuery( this );
$this.removeClass('yui-dt-odd yui-dt-even');
$this.addClass( cssClass );
if ( cssClass == 'yui-dt-odd' ) {
cssClass = 'yui-dt-even';
} else {
cssClass = 'yui-dt-odd';
}
});
}

};
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ var sortableSubitems = function () {

// Table options

// Triggering jQuery event, when the table is rendered
subItemsTable.subscribe("renderEvent", function (oArgs) {
window.subItemsTable = subItemsTable;
jQuery('#content-sub-items-list').trigger('datatable:rendered');
});

// Shows dialog, creating one when necessary
var colLayoutHasChanged = true;
var showTblOptsDialog = function(e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,8 @@ div.attribute-multioption li
padding: 0;
list-style-type: none;
}

/* This is necessary to prevent the dragged row elements collapse while is being dragged */
.ui-sortable-helper {
display: table!important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
$children_count = fetch( content, list_count, hash( 'parent_node_id', $node.node_id,
'objectname_filter', $view_parameters.namefilter ) )
$children = array()
$priority = and( eq( $node.sort_array[0][0], 'priority' ), $node.can_edit, $children_count ) }

$priority = and( eq( $node.sort_array[0][0], 'priority' ), $node.can_edit, $children_count )
$priority_dd = and( $priority, $admin_children_viewmode|ne( 'thumbnail' ), $view_parameters.offset|eq( 0 ) )
}

<!-- Children START -->

Expand Down Expand Up @@ -90,6 +91,19 @@
{ezscript_require( array('ezjsc::yui2', 'ezajaxsubitems_datatable.js') )}

<!-- Children END -->
{if $priority_dd}
<script type="text/javascript">
{literal}
jQuery(document).ready(function($)
{
$('#content-sub-items-list').on('datatable:rendered', function() {
var dnd = new admin2ppDragNDropChildren();
dnd.init();
});
}
{/literal});
</script>
{/if}

{undef $item_type $number_of_items $can_remove $can_move $can_edit $can_create $can_copy $current_path $admin_children_viewmode $children_count $children}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

[ExtensionSettings]
DesignExtensions[]=ngadminui

[JavaScriptSettings]
BackendJavaScriptList[]=ezjsc::jqueryUI
BackendJavaScriptList[]=admin2pp_dragndrop_children.js

*/ ?>