document positioning

This commit is contained in:
Etienne Roudeix
2013-12-16 10:55:18 +01:00
parent 0e30ce2760
commit 583cbe95b6
14 changed files with 161 additions and 27 deletions

View File

@@ -6,9 +6,10 @@ $(function($){
// Remove image on click
// Remove document on click
$.documentUploadManager.initDocumentDropZone = function() {
$.documentUploadManager.onClickDeleteDocument();
$.documentUploadManager.sortDocument();
var documentDropzone = new Dropzone("#documents-dropzone", {
dictDefaultMessage : $('.btn-browse').html(),
@@ -39,6 +40,7 @@ $(function($){
documentDropzone.removeFile(file);
$.documentUploadManager.updateDocumentListAjax();
$.documentUploadManager.onClickDeleteDocument();
$.documentUploadManager.sortDocument();
});
@@ -67,7 +69,7 @@ $(function($){
});
};
// Remove image on click
// Remove document on click
$.documentUploadManager.onClickDeleteDocument = function() {
$('.document-manager .document-delete-btn').on('click', function (e) {
e.preventDefault();
@@ -97,4 +99,52 @@ $(function($){
return false;
});
};
$.documentUploadManager.sortDocument = function() {
$( "#js-sort-document" ).sortable({
placeholder: "ui-sortable-placeholder col-sm-6 col-md-3",
change: function( event, ui ) {
/* refresh position */
var pickedElement = ui.item;
var position = 0;
$( "#js-sort-document").children('li').each(function(k, element) {
if($(element).data('sort-id') == pickedElement.data('sort-id')) {
return true;
}
position++;
if($(element).is('.ui-sortable-placeholder')) {
pickedElement.find('.js-sorted-position').html(position);
} else {
$(element).find('.js-sorted-position').html(position);
}
});
},
stop: function( event, ui ) {
/* update */
var newPosition = ui.item.find('.js-sorted-position').html();
var documentId = ui.item.data('sort-id');
$.ajax({
type: "POST",
url: documentReorder,
data: {
document_id: documentId,
position: newPosition
},
statusCode: {
404: function() {
$(".document-manager .message").html(
documentReorderErrorMessage
);
}
}
}).done(function(data) {
$(".document-manager .message").html(
data
);
});
}
});
$( "#js-sort-document" ).disableSelection();
};
});

View File

@@ -428,4 +428,17 @@ table {
}
}
}
}
// document list style
ul.document-list {
> li {
padding: @table-condensed-cell-padding;
line-height: @line-height-base;
border-top: 1px solid @table-border-color;
&:nth-child(odd) {
background-color: @table-bg-accent;
}
}
}

View File

@@ -32,5 +32,7 @@ Parameters:
<script>
var documentDropZoneUrl = "{url path="/admin/document/type/$documentType/$parentId/save-ajax"}";
var documentListUrl = "{url path="/admin/document/type/$documentType/$parentId/list-ajax"}";
var documentReorder = "{url path="/admin/document/type/$documentType/$parentId/update-position"}";
var documentListErrorMessage = "{intl l='Can\'t load documents, please refresh this page.'}";
var documentReorderErrorMessage = "{intl l='Can\'t reorder documents, please refresh this page.'}";
</script>

View File

@@ -7,29 +7,27 @@ Parameters:
parentId = Document parent id, ex: category id
*}
{ifloop rel="document"}
<table class="table table-striped table-condensed table-left-aligned">
<ul id="js-sort-document" class="list-unstyled document-list">
{loop type="document" name="document" source="{$documentType}" order="manual" source_id="{$parentId}"}
<tr>
<td>
<a href="{$DOCUMENT_PATH}" title="{$TITLE}" class="" target="_blank">{$TITLE}</a>
</td>
<td>
<div class="btn-group">
<a class="image-update-btn btn btn-default btn-xs disabled js-sorted-position" href="#">{$POSITION}</a>
<a class="document-update-btn btn btn-default btn-xs" href="{url path="/admin/document/type/$documentType/$ID/update"}" data-error-message="{intl l='Please retry'}">
<span class="glyphicon glyphicon-edit"></span>
</a>
<a class="document-delete-btn btn btn-default btn-xs" href="{url path="/admin/document/type/$documentType/delete/$ID"}" data-error-message="{intl l='Please retry'}">
<span class="glyphicon glyphicon-trash"></span>
</a>
</div>
<td>
</tr>
<li class="clearfix ui-state-default" data-sort-id="{$ID}">
<a href="{$DOCUMENT_PATH}" title="{$TITLE}" class="pull-left" target="_blank">{$TITLE}</a>
<div class="btn-group pull-right">
<a class="image-update-btn btn btn-default btn-xs disabled js-sorted-position" href="#">{$POSITION}</a>
<a class="document-update-btn btn btn-default btn-xs" href="{url path="/admin/document/type/$documentType/$ID/update"}" data-error-message="{intl l='Please retry'}">
<span class="glyphicon glyphicon-edit"></span>
</a>
<a class="document-delete-btn btn btn-default btn-xs" href="{url path="/admin/document/type/$documentType/delete/$ID"}" data-error-message="{intl l='Please retry'}">
<span class="glyphicon glyphicon-trash"></span>
</a>
</div>
</li>
{/loop}
</table>
</ul>
{/ifloop}
{elseloop rel="document"}
<div class="alert alert-info">{intl l='There is no documents attached to this %type.' type=$documentType}</div>
{/elseloop}